国标28181-支持自动识别网卡监听,可以不再配置SIP.IP
This commit is contained in:
@@ -27,19 +27,19 @@ public class MediaConfig{
|
||||
@Value("${media.ip}")
|
||||
private String ip;
|
||||
|
||||
@Value("${media.hook-ip:}")
|
||||
private String hookIp;
|
||||
@Value("${media.wan_ip}")
|
||||
private String wanIp;
|
||||
|
||||
@Value("${sip.ip}")
|
||||
private String sipIp;
|
||||
@Value("${media.hook-ip:127.0.0.1}")
|
||||
private String hookIp;
|
||||
|
||||
@Value("${sip.domain}")
|
||||
private String sipDomain;
|
||||
|
||||
@Value("${media.sdp-ip:${media.ip}}")
|
||||
@Value("${media.sdp-ip:${media.wan_ip}}")
|
||||
private String sdpIp;
|
||||
|
||||
@Value("${media.stream-ip:${media.ip}}")
|
||||
@Value("${media.stream-ip:${media.wan_ip}}")
|
||||
private String streamIp;
|
||||
|
||||
@Value("${media.http-port:0}")
|
||||
@@ -111,20 +111,7 @@ public class MediaConfig{
|
||||
}
|
||||
|
||||
public String getHookIp() {
|
||||
if (ObjectUtils.isEmpty(hookIp)){
|
||||
return sipIp;
|
||||
}else {
|
||||
return hookIp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getSipIp() {
|
||||
if (sipIp == null) {
|
||||
return this.ip;
|
||||
}else {
|
||||
return sipIp;
|
||||
}
|
||||
return hookIp;
|
||||
}
|
||||
|
||||
public int getHttpPort() {
|
||||
|
||||
@@ -98,9 +98,6 @@ public class SipConfig {
|
||||
}
|
||||
|
||||
public String getShowIp() {
|
||||
if (this.showIp == null) {
|
||||
return this.ip;
|
||||
}
|
||||
return showIp;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ public class UserSetting {
|
||||
|
||||
private boolean registerKeepIntDialog = false;
|
||||
|
||||
private int gbDeviceOnline = 0;
|
||||
private int gbDeviceOnline = 1;
|
||||
|
||||
public Boolean getSavePositionHistory() {
|
||||
return savePositionHistory;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class WVPTimerTask {
|
||||
@Scheduled(fixedRate = 2 * 1000) //每3秒执行一次
|
||||
public void execute(){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("ip", sipConfig.getIp());
|
||||
jsonObject.put("ip", sipConfig.getShowIp());
|
||||
jsonObject.put("port", serverPort);
|
||||
redisCatchStorage.updateWVPInfo(jsonObject, 3);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import javax.sip.*;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -40,15 +43,46 @@ public class SipLayer implements CommandLineRunner {
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
List<String> monitorIps = new ArrayList<>();
|
||||
// 使用逗号分割多个ip
|
||||
String separator = ",";
|
||||
if (sipConfig.getIp().indexOf(separator) > 0) {
|
||||
String[] split = sipConfig.getIp().split(separator);
|
||||
monitorIps.addAll(Arrays.asList(split));
|
||||
if (ObjectUtils.isEmpty(sipConfig.getIp())) {
|
||||
try {
|
||||
// 获得本机的所有网络接口
|
||||
Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
|
||||
while (nifs.hasMoreElements()) {
|
||||
NetworkInterface nif = nifs.nextElement();
|
||||
// 获得与该网络接口绑定的 IP 地址,一般只有一个
|
||||
Enumeration<InetAddress> addresses = nif.getInetAddresses();
|
||||
while (addresses.hasMoreElements()) {
|
||||
InetAddress addr = addresses.nextElement();
|
||||
if (addr instanceof Inet4Address) {
|
||||
if (addr.getHostAddress().equals("127.0.0.1")){
|
||||
continue;
|
||||
}
|
||||
if (nif.getName().startsWith("docker")) {
|
||||
continue;
|
||||
}
|
||||
logger.error("[自动配置SIP监听网卡] 网卡接口地址: {}", addr.getHostAddress());// 只关心 IPv4 地址
|
||||
monitorIps.add(addr.getHostAddress());
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("[读取网卡信息失败]", e);
|
||||
}
|
||||
if (monitorIps.isEmpty()) {
|
||||
logger.error("[自动配置SIP监听网卡信息失败], 请手动配置SIP.IP后重新启动");
|
||||
System.exit(1);
|
||||
}
|
||||
}else {
|
||||
monitorIps.add(sipConfig.getIp());
|
||||
// 使用逗号分割多个ip
|
||||
String separator = ",";
|
||||
if (sipConfig.getIp().indexOf(separator) > 0) {
|
||||
String[] split = sipConfig.getIp().split(separator);
|
||||
monitorIps.addAll(Arrays.asList(split));
|
||||
}else {
|
||||
monitorIps.add(sipConfig.getIp());
|
||||
}
|
||||
}
|
||||
|
||||
sipConfig.setShowIp(String.join(",", monitorIps));
|
||||
SipFactory.getInstance().setPathName("gov.nist");
|
||||
if (monitorIps.size() > 0) {
|
||||
for (String monitorIp : monitorIps) {
|
||||
|
||||
@@ -351,38 +351,6 @@ public class SIPRequestHeaderProvider {
|
||||
|
||||
request.addHeader(SipUtils.createUserAgentHeader(gitUtil));
|
||||
|
||||
return request;
|
||||
}
|
||||
public Request createBroadcastMessageRequest(Device device, String channelId, String content, String viaTag, String fromTag, String toTag, CallIdHeader callIdHeader) throws ParseException, InvalidArgumentException, PeerUnavailableException {
|
||||
Request request = null;
|
||||
// sipuri
|
||||
SipURI requestURI = SipFactory.getInstance().createAddressFactory().createSipURI(channelId, device.getHostAddress());
|
||||
// via
|
||||
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
||||
ViaHeader viaHeader = SipFactory.getInstance().createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(), device.getTransport(), viaTag);
|
||||
viaHeader.setRPort();
|
||||
viaHeaders.add(viaHeader);
|
||||
// from
|
||||
SipURI fromSipURI = SipFactory.getInstance().createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getDomain());
|
||||
Address fromAddress = SipFactory.getInstance().createAddressFactory().createAddress(fromSipURI);
|
||||
FromHeader fromHeader = SipFactory.getInstance().createHeaderFactory().createFromHeader(fromAddress, fromTag);
|
||||
// to
|
||||
SipURI toSipURI = SipFactory.getInstance().createAddressFactory().createSipURI(channelId, device.getHostAddress());
|
||||
Address toAddress = SipFactory.getInstance().createAddressFactory().createAddress(toSipURI);
|
||||
ToHeader toHeader = SipFactory.getInstance().createHeaderFactory().createToHeader(toAddress, toTag);
|
||||
|
||||
// Forwards
|
||||
MaxForwardsHeader maxForwards = SipFactory.getInstance().createHeaderFactory().createMaxForwardsHeader(70);
|
||||
// ceq
|
||||
CSeqHeader cSeqHeader = SipFactory.getInstance().createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(), Request.MESSAGE);
|
||||
|
||||
ContentTypeHeader contentTypeHeader = SipFactory.getInstance().createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
||||
|
||||
request = SipFactory.getInstance().createMessageFactory().createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader,
|
||||
toHeader, viaHeaders, maxForwards, contentTypeHeader, content);
|
||||
|
||||
request.addHeader(SipUtils.createUserAgentHeader(gitUtil));
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.genersoft.iot.vmp.media;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.MediaConfig;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.media.event.mediaServer.MediaServerChangeEvent;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class MediaServer {
|
||||
private String ip;
|
||||
|
||||
@Schema(description = "hook使用的IP(zlm访问WVP使用的IP)")
|
||||
private String hookIp;
|
||||
private String hookIp = "127.0.0.1";
|
||||
|
||||
@Schema(description = "SDP IP")
|
||||
private String sdpIp;
|
||||
|
||||
@@ -190,7 +190,15 @@ public class ZLMHttpHookListener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* rtsp/rtmp流注册或注销时触发此事件;此事件对回复不敏感。
|
||||
*/
|
||||
// @ResponseBody
|
||||
// @PostMapping(value = "/on_stream_changed", produces = "application/json;charset=UTF-8")
|
||||
// public HookResult onStreamChanged(@RequestBody JSONObject param) {
|
||||
// System.out.println(11);
|
||||
// return HookResult.SUCCESS();
|
||||
// }
|
||||
/**
|
||||
* rtsp/rtmp流注册或注销时触发此事件;此事件对回复不敏感。
|
||||
*/
|
||||
|
||||
@@ -8,15 +8,14 @@ import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaInfo;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaNodeServerService;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaNodeServerService;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.ZLMServerConfig;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -36,9 +35,6 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
@Autowired
|
||||
private ZLMServerFactory zlmServerFactory;
|
||||
|
||||
@Value("${sip.ip}")
|
||||
private String sipIp;
|
||||
|
||||
@Override
|
||||
public int createRTPServer(MediaServer mediaServer, String streamId, long ssrc, Integer port, Boolean onlyAuto, Boolean disableAudio, Boolean reUsePort, Integer tcpMode) {
|
||||
return zlmServerFactory.createRTPServer(mediaServer, streamId, ssrc, port, onlyAuto, reUsePort, tcpMode);
|
||||
@@ -120,7 +116,7 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
mediaServer.setRtpProxyPort(zlmServerConfig.getRtpProxyPort());
|
||||
mediaServer.setStreamIp(ip);
|
||||
|
||||
mediaServer.setHookIp(sipIp.split(",")[0]);
|
||||
mediaServer.setHookIp("127.0.0.1");
|
||||
mediaServer.setSdpIp(ip);
|
||||
mediaServer.setType("zlm");
|
||||
return mediaServer;
|
||||
|
||||
@@ -96,7 +96,6 @@ public class ZLMRESTfulUtils {
|
||||
if (callback == null) {
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
ResponseBody responseBody = response.body();
|
||||
if (responseBody != null) {
|
||||
|
||||
@@ -89,7 +89,7 @@ public class PlatformController {
|
||||
@GetMapping("/server_config")
|
||||
public JSONObject serverConfig() {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("deviceIp", sipConfig.getIp());
|
||||
result.put("deviceIp", sipConfig.getShowIp());
|
||||
result.put("devicePort", sipConfig.getPort());
|
||||
result.put("username", sipConfig.getId());
|
||||
result.put("password", sipConfig.getPassword());
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ApiController {
|
||||
result.put("Server","");
|
||||
result.put("SIPSerial", sipConfig.getId());
|
||||
result.put("SIPRealm", sipConfig.getDomain());
|
||||
result.put("SIPHost", sipConfig.getIp());
|
||||
result.put("SIPHost", sipConfig.getShowIp());
|
||||
result.put("SIPPort", sipConfig.getPort());
|
||||
result.put("ChannelCount","1000");
|
||||
result.put("VersionType","");
|
||||
|
||||
@@ -139,12 +139,14 @@ media:
|
||||
id:
|
||||
# [必须修改] zlm服务器的内网IP
|
||||
ip: 192.168.0.100
|
||||
# [可选] 有公网IP就配置公网IP, 不可用域名
|
||||
wan_ip:
|
||||
# [可选] 返回流地址时的ip,置空使用 media.ip
|
||||
stream-ip:
|
||||
# [可选] wvp在国标信令中使用的ip,此ip为摄像机可以访问到的ip, 置空使用 media.ip
|
||||
sdp-ip:
|
||||
# [可选] zlm服务器的hook所使用的IP, 默认使用sip.ip
|
||||
hook-ip:
|
||||
# [可选] zlm服务器访问WVP所使用的IP, 默认使用127.0.0.1,zlm和wvp没有部署在同一台服务器时必须配置
|
||||
hook-ip: 172.19.128.50
|
||||
# [必须修改] zlm服务器的http.port
|
||||
http-port: 80
|
||||
# [可选] zlm服务器的http.sslport, 置空使用zlm配置文件配置
|
||||
@@ -249,7 +251,7 @@ user-settings:
|
||||
- http://192.168.1.3:8008
|
||||
# 国标设备离线后的上线策略,
|
||||
# 0: 国标标准实现,设备离线后不回复心跳,直到设备重新注册上线,
|
||||
# 1: 对于离线设备,收到心跳就把设备设置为上线,并更新注册时间为上次这次心跳的时间。防止过期时间判断异常
|
||||
# 1(默认): 对于离线设备,收到心跳就把设备设置为上线,并更新注册时间为上次这次心跳的时间。防止过期时间判断异常
|
||||
gb-device-online: 0
|
||||
|
||||
# 关闭在线文档(生产环境建议关闭)
|
||||
|
||||
@@ -58,11 +58,6 @@ server:
|
||||
|
||||
# 作为28181服务器的配置
|
||||
sip:
|
||||
# [必须修改] 本机的IP,对应你的网卡,监听什么ip就是使用什么网卡,
|
||||
# 如果要监听多张网卡,可以使用逗号分隔多个IP, 例如: 192.168.1.4,10.0.0.4
|
||||
# 如果不明白,就使用0.0.0.0,大部分情况都是可以的
|
||||
# 请不要使用127.0.0.1,任何包括localhost在内的域名都是不可以的。
|
||||
ip: 172.19.128.50
|
||||
# [可选] 28181服务监听的端口
|
||||
port: 8116
|
||||
# 根据国标6.1.2中规定,domain宜采用ID统一编码的前十位编码。国标附录D中定义前8位为中心编码(由省级、市级、区级、基层编号组成,参照GB/T 2260-2007)
|
||||
@@ -82,18 +77,14 @@ media:
|
||||
id: zlmediakit-local
|
||||
# [必须修改] zlm服务器的内网IP
|
||||
ip: 172.19.128.50
|
||||
# [可选] 有公网IP就配置公网IP, 不可用域名
|
||||
wan_ip:
|
||||
# [必须修改] zlm服务器的http.port
|
||||
http-port: 9092
|
||||
# [可选] 返回流地址时的ip,置空使用 media.ip
|
||||
stream-ip: 172.19.128.50
|
||||
# [可选] wvp在国标信令中使用的ip,此ip为摄像机可以访问到的ip, 置空使用 media.ip
|
||||
sdp-ip: 172.19.128.50
|
||||
# [可选] zlm服务器的hook所使用的IP, 默认使用sip.ip
|
||||
# [可选] zlm服务器访问WVP所使用的IP, 默认使用127.0.0.1,zlm和wvp没有部署在同一台服务器时必须配置
|
||||
hook-ip: 172.19.128.50
|
||||
# [可选] zlm服务器的http.sslport, 置空使用zlm配置文件配置
|
||||
http-ssl-port: 1443
|
||||
# [可选] zlm服务器的hook.admin_params=secret
|
||||
secret: 10000
|
||||
# [必选选] zlm服务器的hook.admin_params=secret
|
||||
secret: TWSYFgYJOQWB4ftgeYut8DW4wbs7pQnj
|
||||
# 启用多端口模式, 多端口模式使用端口区分每路流,兼容性更好。 单端口使用流的ssrc区分, 点播超时建议使用多端口测试
|
||||
rtp:
|
||||
# [可选] 是否启用多端口模式, 开启后会在portRange范围内选择端口用于媒体流传输
|
||||
@@ -102,14 +93,16 @@ media:
|
||||
port-range: 50000,50300 # 端口范围
|
||||
# [可选] 国标级联在此范围内选择端口发送媒体流,
|
||||
send-port-range: 50000,50300 # 端口范围
|
||||
# 录像辅助服务, 部署此服务可以实现zlm录像的管理与下载, 0 表示不使用
|
||||
record-assist-port: 18081
|
||||
# [根据业务需求配置]
|
||||
user-settings:
|
||||
# 点播/录像回放 等待超时时间,单位:毫秒
|
||||
play-timeout: 180000
|
||||
# [可选] 自动点播, 使用固定流地址进行播放时,如果未点播则自动进行点播, 需要rtp.enable=true
|
||||
auto-apply-play: true
|
||||
# 设备/通道状态变化时发送消息
|
||||
device-status-notify: true
|
||||
# 推流直播是否录制
|
||||
record-push-live: true
|
||||
# 国标是否录制
|
||||
record-sip: true
|
||||
# 国标点播 按需拉流, true:有人观看拉流,无人观看释放, false:拉起后不自动释放
|
||||
stream-on-demand: true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user