增加zlm代理的secret自动添加, 增加配置文件的默认值,缺少非关键参数不会无法启动,简化配置文件给新手带来的压力,前端使用wvp代理流。
This commit is contained in:
@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import springfox.documentation.oas.annotations.EnableOpenApi;
|
||||
|
||||
@@ -31,9 +31,5 @@ public class ApplicationCheckRunner implements CommandLineRunner {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
if (mediaConfig.getIp().equals("localhost") || (mediaConfig.getIp().equals("127.0.0.1") && mediaConfig.getWanIp() == null)) {
|
||||
logger.warn("mediaIp.ip使用 {} ,将无法收到网络内其他设备的推流!!!", mediaConfig.getIp() );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.genersoft.iot.vmp.conf;
|
||||
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@Configuration("mediaConfig")
|
||||
public class MediaConfig {
|
||||
@@ -9,40 +11,40 @@ public class MediaConfig {
|
||||
@Value("${media.ip}")
|
||||
private String ip;
|
||||
|
||||
@Value("${media.wanIp}")
|
||||
private String wanIp;
|
||||
|
||||
@Value("${media.hookIp}")
|
||||
@Value("${media.hookIp:${sip.ip}}")
|
||||
private String hookIp;
|
||||
|
||||
@Value("${media.sdpIp:${media.ip}}")
|
||||
private String sdpIp;
|
||||
|
||||
@Value("${media.httpPort}")
|
||||
private String httpPort;
|
||||
|
||||
@Value("${media.httpSSlPort}")
|
||||
@Value("${media.httpSSlPort:}")
|
||||
private String httpSSlPort;
|
||||
|
||||
@Value("${media.rtmpPort}")
|
||||
@Value("${media.rtmpPort:}")
|
||||
private String rtmpPort;
|
||||
|
||||
@Value("${media.rtmpSSlPort}")
|
||||
@Value("${media.rtmpSSlPort:}")
|
||||
private String rtmpSSlPort;
|
||||
|
||||
@Value("${media.rtpProxyPort}")
|
||||
@Value("${media.rtpProxyPort:}")
|
||||
private String rtpProxyPort;
|
||||
|
||||
@Value("${media.rtspPort}")
|
||||
@Value("${media.rtspPort:}")
|
||||
private String rtspPort;
|
||||
|
||||
@Value("${media.rtspSSLPort}")
|
||||
@Value("${media.rtspSSLPort:}")
|
||||
private String rtspSSLPort;
|
||||
|
||||
@Value("${media.autoConfig}")
|
||||
@Value("${media.autoConfig:true}")
|
||||
private boolean autoConfig;
|
||||
|
||||
@Value("${media.secret}")
|
||||
private String secret;
|
||||
|
||||
@Value("${media.streamNoneReaderDelayMS}")
|
||||
@Value("${media.streamNoneReaderDelayMS:18000}")
|
||||
private String streamNoneReaderDelayMS;
|
||||
|
||||
@Value("${media.rtp.enable}")
|
||||
@@ -62,14 +64,6 @@ public class MediaConfig {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public String getWanIp() {
|
||||
return wanIp;
|
||||
}
|
||||
|
||||
public void setWanIp(String wanIp) {
|
||||
this.wanIp = wanIp;
|
||||
}
|
||||
|
||||
public String getHookIp() {
|
||||
return hookIp;
|
||||
}
|
||||
@@ -185,4 +179,16 @@ public class MediaConfig {
|
||||
public void setRecordAssistPort(int recordAssistPort) {
|
||||
this.recordAssistPort = recordAssistPort;
|
||||
}
|
||||
|
||||
public String getSdpIp() {
|
||||
if (StringUtils.isEmpty(sdpIp)) {
|
||||
return ip;
|
||||
}else {
|
||||
return sdpIp;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSdpIp(String sdpIp) {
|
||||
this.sdpIp = sdpIp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.genersoft.iot.vmp.conf;
|
||||
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.mitre.dsmiley.httpproxy.ProxyServlet;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -12,9 +14,14 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Configuration
|
||||
@@ -27,10 +34,10 @@ public class ProxyServletConfig {
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean zlmServletRegistrationBean(){
|
||||
String ip = StringUtils.isEmpty(mediaConfig.getWanIp())? mediaConfig.getIp(): mediaConfig.getWanIp();
|
||||
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new ZLMProxySerlet(),"/zlm/*");
|
||||
servletRegistrationBean.setName("zlm_Proxy");
|
||||
servletRegistrationBean.addInitParameter("targetUri", String.format("http://%s:%s", ip, mediaConfig.getHttpPort()));
|
||||
servletRegistrationBean.addInitParameter("targetUri", String.format("http://%s:%s", mediaConfig.getIp(), mediaConfig.getHttpPort()));
|
||||
servletRegistrationBean.addUrlMappings();
|
||||
if (logger.isDebugEnabled()) {
|
||||
servletRegistrationBean.addInitParameter("log", "true");
|
||||
}
|
||||
@@ -38,6 +45,21 @@ public class ProxyServletConfig {
|
||||
}
|
||||
|
||||
class ZLMProxySerlet extends ProxyServlet{
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected String rewriteQueryStringFromRequest(HttpServletRequest servletRequest, String queryString) {
|
||||
String queryStr = super.rewriteQueryStringFromRequest(servletRequest, queryString);
|
||||
if (queryStr != null) {
|
||||
queryStr += "&";
|
||||
}else {
|
||||
queryStr = "?";
|
||||
}
|
||||
queryStr += "secret=" + mediaConfig.getSecret();
|
||||
return queryStr;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleRequestException(HttpRequest proxyRequest, HttpResponse proxyResonse, Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
|
||||
@@ -9,18 +9,32 @@ public class SipConfig {
|
||||
|
||||
@Value("${sip.ip}")
|
||||
private String sipIp;
|
||||
|
||||
/**
|
||||
* 默认使用sip.ip
|
||||
*/
|
||||
@Value("${sip.monitorIp:0.0.0.0}")
|
||||
private String monitorIp;
|
||||
|
||||
@Value("${sip.port}")
|
||||
private Integer sipPort;
|
||||
|
||||
@Value("${sip.domain}")
|
||||
private String sipDomain;
|
||||
|
||||
@Value("${sip.id}")
|
||||
private String sipId;
|
||||
|
||||
@Value("${sip.password}")
|
||||
private String sipPassword;
|
||||
|
||||
@Value("${sip.ptz.speed:50}")
|
||||
Integer speed;
|
||||
|
||||
public String getMonitorIp() {
|
||||
return monitorIp;
|
||||
}
|
||||
|
||||
public String getSipIp() {
|
||||
return sipIp;
|
||||
}
|
||||
|
||||
@@ -5,19 +5,19 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration("userSetup")
|
||||
public class UserSetup {
|
||||
@Value("${userSettings.savePositionHistory}")
|
||||
@Value("${userSettings.savePositionHistory:false}")
|
||||
boolean savePositionHistory;
|
||||
|
||||
@Value("${userSettings.autoApplyPlay}")
|
||||
private boolean autoApplyPlay;
|
||||
|
||||
@Value("${userSettings.seniorSdp}")
|
||||
@Value("${userSettings.seniorSdp:false}")
|
||||
private boolean seniorSdp;
|
||||
|
||||
@Value("${userSettings.playTimeout}")
|
||||
@Value("${userSettings.playTimeout:18000}")
|
||||
private long playTimeout;
|
||||
|
||||
@Value("${userSettings.waitTrack}")
|
||||
@Value("${userSettings.waitTrack:false}")
|
||||
private boolean waitTrack;
|
||||
|
||||
@Value("${userSettings.interfaceAuthentication}")
|
||||
|
||||
@@ -68,6 +68,12 @@ public class Device {
|
||||
*/
|
||||
private Long registerTimeMillis;
|
||||
|
||||
|
||||
/**
|
||||
* 心跳时间
|
||||
*/
|
||||
private Long KeepaliveTimeMillis;
|
||||
|
||||
/**
|
||||
* 通道个数
|
||||
*/
|
||||
@@ -176,4 +182,12 @@ public class Device {
|
||||
public void setRegisterTimeMillis(Long registerTimeMillis) {
|
||||
this.registerTimeMillis = registerTimeMillis;
|
||||
}
|
||||
|
||||
public Long getKeepaliveTimeMillis() {
|
||||
return KeepaliveTimeMillis;
|
||||
}
|
||||
|
||||
public void setKeepaliveTimeMillis(Long keepaliveTimeMillis) {
|
||||
KeepaliveTimeMillis = keepaliveTimeMillis;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,9 +379,9 @@ public class SIPCommander implements ISIPCommander {
|
||||
StringBuffer content = new StringBuffer(200);
|
||||
content.append("v=0\r\n");
|
||||
// content.append("o=" + sipConfig.getSipId() + " 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n");
|
||||
content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n");
|
||||
content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getSdpIp()+"\r\n");
|
||||
content.append("s=Play\r\n");
|
||||
content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
|
||||
content.append("c=IN IP4 "+mediaInfo.getSdpIp()+"\r\n");
|
||||
content.append("t=0 0\r\n");
|
||||
|
||||
if (userSetup.isSeniorSdp()) {
|
||||
@@ -482,7 +482,7 @@ public class SIPCommander implements ISIPCommander {
|
||||
content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n");
|
||||
content.append("s=Playback\r\n");
|
||||
content.append("u="+channelId+":0\r\n");
|
||||
content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
|
||||
content.append("c=IN IP4 "+mediaInfo.getSdpIp()+"\r\n");
|
||||
content.append("t="+DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime)+" "
|
||||
+DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime) +"\r\n");
|
||||
String mediaPort = null;
|
||||
|
||||
@@ -198,9 +198,9 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
|
||||
StringBuffer content = new StringBuffer(200);
|
||||
content.append("v=0\r\n");
|
||||
content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n");
|
||||
content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getSdpIp()+"\r\n");
|
||||
content.append("s=Play\r\n");
|
||||
content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
|
||||
content.append("c=IN IP4 "+mediaInfo.getSdpIp()+"\r\n");
|
||||
content.append("t=0 0\r\n");
|
||||
content.append("m=video "+ sendRtpItem.getLocalPort()+" RTP/AVP 96\r\n");
|
||||
content.append("a=sendonly\r\n");
|
||||
@@ -254,9 +254,9 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
|
||||
StringBuffer content = new StringBuffer(200);
|
||||
content.append("v=0\r\n");
|
||||
content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n");
|
||||
content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getSdpIp()+"\r\n");
|
||||
content.append("s=Play\r\n");
|
||||
content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
|
||||
content.append("c=IN IP4 "+mediaInfo.getSdpIp()+"\r\n");
|
||||
content.append("t=0 0\r\n");
|
||||
content.append("m=video "+ sendRtpItem.getLocalPort()+" RTP/AVP 96\r\n");
|
||||
content.append("a=sendonly\r\n");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.genersoft.iot.vmp.media.zlm;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class ZLMServerConfig {
|
||||
|
||||
@@ -34,9 +35,9 @@ public class ZLMServerConfig {
|
||||
@JSONField(name = "general.streamNoneReaderDelayMS")
|
||||
private String generalStreamNoneReaderDelayMS;
|
||||
|
||||
private String localIP;
|
||||
private String ip;
|
||||
|
||||
private String wanIp;
|
||||
private String sdpIp;
|
||||
|
||||
private long updateTime;
|
||||
|
||||
@@ -281,12 +282,12 @@ public class ZLMServerConfig {
|
||||
this.generalStreamNoneReaderDelayMS = generalStreamNoneReaderDelayMS;
|
||||
}
|
||||
|
||||
public String getLocalIP() {
|
||||
return localIP;
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setLocalIP(String localIP) {
|
||||
this.localIP = localIP;
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public String getHlsFileBufSize() {
|
||||
@@ -729,14 +730,6 @@ public class ZLMServerConfig {
|
||||
this.shellPhell = shellPhell;
|
||||
}
|
||||
|
||||
public String getWanIp() {
|
||||
return wanIp;
|
||||
}
|
||||
|
||||
public void setWanIp(String wanIp) {
|
||||
this.wanIp = wanIp;
|
||||
}
|
||||
|
||||
public long getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
@@ -760,4 +753,16 @@ public class ZLMServerConfig {
|
||||
public void setRtmpSslPort(String rtmpSslPort) {
|
||||
this.rtmpSslPort = rtmpSslPort;
|
||||
}
|
||||
|
||||
public String getSdpIp() {
|
||||
if (StringUtils.isEmpty(sdpIp)) {
|
||||
return ip;
|
||||
}else {
|
||||
return sdpIp;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSdpIp(String sdpIp) {
|
||||
this.sdpIp = sdpIp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ public class ZLMServerManger {
|
||||
|
||||
public void updateServerCatch(ZLMServerConfig zlmServerConfig) {
|
||||
|
||||
zlmServerConfig.setLocalIP(mediaConfig.getIp());
|
||||
zlmServerConfig.setWanIp(StringUtils.isEmpty(mediaConfig.getWanIp())? mediaConfig.getIp(): mediaConfig.getWanIp());
|
||||
zlmServerConfig.setIp(mediaConfig.getIp());
|
||||
zlmServerConfig.setSdpIp(mediaConfig.getSdpIp());
|
||||
zlmServerConfig.setHttpPort(mediaConfig.getHttpPort());
|
||||
|
||||
if(!StringUtils.isEmpty(mediaConfig.getHttpSSlPort()))
|
||||
|
||||
@@ -32,17 +32,17 @@ public class MediaServiceImpl implements IMediaService {
|
||||
StreamInfo streamInfoResult = new StreamInfo();
|
||||
streamInfoResult.setStreamId(stream);
|
||||
streamInfoResult.setApp(app);
|
||||
streamInfoResult.setRtmp(String.format("rtmp://%s:%s/%s/%s", mediaInfo.getWanIp(), mediaInfo.getRtmpPort(), app, stream));
|
||||
streamInfoResult.setRtsp(String.format("rtsp://%s:%s/%s/%s", mediaInfo.getWanIp(), mediaInfo.getRtspPort(), app, stream));
|
||||
streamInfoResult.setFlv(String.format("http://%s:%s/%s/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setWs_flv(String.format("ws://%s:%s/%s/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setHls(String.format("http://%s:%s/%s/%s/hls.m3u8", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setWs_hls(String.format("ws://%s:%s/%s/%s/hls.m3u8", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setFmp4(String.format("http://%s:%s/%s/%s.live.mp4", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setWs_fmp4(String.format("ws://%s:%s/%s/%s.live.mp4", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setTs(String.format("http://%s:%s/%s/%s.live.ts", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setWs_ts(String.format("ws://%s:%s/%s/%s.live.ts", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setRtc(String.format("http://%s:%s/index/api/webrtc?app=%s&stream=%s&type=play", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setRtmp(String.format("rtmp://%s:%s/%s/%s", mediaInfo.getIp(), mediaInfo.getRtmpPort(), app, stream));
|
||||
streamInfoResult.setRtsp(String.format("rtsp://%s:%s/%s/%s", mediaInfo.getIp(), mediaInfo.getRtspPort(), app, stream));
|
||||
streamInfoResult.setFlv(String.format("http://%s:%s/%s/%s.flv", mediaInfo.getIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setWs_flv(String.format("ws://%s:%s/%s/%s.flv", mediaInfo.getIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setHls(String.format("http://%s:%s/%s/%s/hls.m3u8", mediaInfo.getIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setWs_hls(String.format("ws://%s:%s/%s/%s/hls.m3u8", mediaInfo.getIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setFmp4(String.format("http://%s:%s/%s/%s.live.mp4", mediaInfo.getIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setWs_fmp4(String.format("ws://%s:%s/%s/%s.live.mp4", mediaInfo.getIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setTs(String.format("http://%s:%s/%s/%s.live.ts", mediaInfo.getIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setWs_ts(String.format("ws://%s:%s/%s/%s.live.ts", mediaInfo.getIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setRtc(String.format("http://%s:%s/index/api/webrtc?app=%s&stream=%s&type=play", mediaInfo.getIp(), mediaInfo.getHttpPort(), app, stream));
|
||||
streamInfoResult.setTracks(tracks);
|
||||
return streamInfoResult;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class RecoderProxyController {
|
||||
// 后续改为根据Id获取对应的ZLM
|
||||
ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
|
||||
String requestURI = String.format("http://%s:%s%s?%s",
|
||||
mediaInfo.getLocalIP(),
|
||||
mediaInfo.getSdpIp(),
|
||||
mediaConfig.getRecordAssistPort(),
|
||||
baseRequestURI.substring(baseRequestURI.indexOf(mediaId) + mediaId.length()),
|
||||
URLDecoder.decode(request.getQueryString())
|
||||
|
||||
Reference in New Issue
Block a user