|  |  |  | 
|---|
|  |  |  | package com.genersoft.iot.vmp.conf; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import io.netty.util.internal.StringUtil; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.utils.DateUtil; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.context.annotation.Configuration; | 
|---|
|  |  |  | import org.springframework.util.StringUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.net.InetAddress; | 
|---|
|  |  |  | import java.net.UnknownHostException; | 
|---|
|  |  |  | import java.util.regex.Pattern; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Configuration("mediaConfig") | 
|---|
|  |  |  | public class MediaConfig { | 
|---|
|  |  |  | public class MediaConfig{ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 修改必须配置,不再支持自动获取 | 
|---|
|  |  |  | @Value("${media.id}") | 
|---|
|  |  |  | private String id; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.ip}") | 
|---|
|  |  |  | private String ip; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.hookIp:${sip.ip}}") | 
|---|
|  |  |  | @Value("${media.hook-ip:${sip.ip}}") | 
|---|
|  |  |  | private String hookIp; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.sdpIp:${media.ip}}") | 
|---|
|  |  |  | @Value("${sip.ip}") | 
|---|
|  |  |  | private String sipIp; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${sip.domain}") | 
|---|
|  |  |  | private String sipDomain; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.sdp-ip:${media.ip}}") | 
|---|
|  |  |  | private String sdpIp; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.streamIp:${media.ip}}") | 
|---|
|  |  |  | @Value("${media.stream-ip:${media.ip}}") | 
|---|
|  |  |  | private String streamIp; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.httpPort}") | 
|---|
|  |  |  | private String httpPort; | 
|---|
|  |  |  | @Value("${media.http-port}") | 
|---|
|  |  |  | private Integer httpPort; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.httpSSlPort:}") | 
|---|
|  |  |  | private String httpSSlPort; | 
|---|
|  |  |  | @Value("${media.http-ssl-port:0}") | 
|---|
|  |  |  | private Integer httpSSlPort = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.rtmpPort:}") | 
|---|
|  |  |  | private String rtmpPort; | 
|---|
|  |  |  | @Value("${media.rtmp-port:0}") | 
|---|
|  |  |  | private Integer rtmpPort = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.rtmpSSlPort:}") | 
|---|
|  |  |  | private String rtmpSSlPort; | 
|---|
|  |  |  | @Value("${media.rtmp-ssl-port:0}") | 
|---|
|  |  |  | private Integer rtmpSSlPort = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.rtpProxyPort:}") | 
|---|
|  |  |  | private String rtpProxyPort; | 
|---|
|  |  |  | @Value("${media.rtp-proxy-port:0}") | 
|---|
|  |  |  | private Integer rtpProxyPort = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.rtspPort:}") | 
|---|
|  |  |  | private String rtspPort; | 
|---|
|  |  |  | @Value("${media.rtsp-port:0}") | 
|---|
|  |  |  | private Integer rtspPort = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.rtspSSLPort:}") | 
|---|
|  |  |  | private String rtspSSLPort; | 
|---|
|  |  |  | @Value("${media.rtsp-ssl-port:0}") | 
|---|
|  |  |  | private Integer rtspSSLPort = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.autoConfig:true}") | 
|---|
|  |  |  | private boolean autoConfig; | 
|---|
|  |  |  | @Value("${media.auto-config:true}") | 
|---|
|  |  |  | private boolean autoConfig = true; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.secret}") | 
|---|
|  |  |  | private String secret; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.streamNoneReaderDelayMS:18000}") | 
|---|
|  |  |  | private String streamNoneReaderDelayMS; | 
|---|
|  |  |  | @Value("${media.stream-none-reader-delay-ms:10000}") | 
|---|
|  |  |  | private int streamNoneReaderDelayMS = 10000; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.rtp.enable}") | 
|---|
|  |  |  | private boolean rtpEnable; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.rtp.portRange}") | 
|---|
|  |  |  | @Value("${media.rtp.port-range}") | 
|---|
|  |  |  | private String rtpPortRange; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.recordAssistPort}") | 
|---|
|  |  |  | private int recordAssistPort; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.rtp.send-port-range}") | 
|---|
|  |  |  | private String sendRtpPortRange; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.record-assist-port:0}") | 
|---|
|  |  |  | private Integer recordAssistPort = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getId() { | 
|---|
|  |  |  | return id; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getIp() { | 
|---|
|  |  |  | return ip; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getHookIp() { | 
|---|
|  |  |  | return hookIp; | 
|---|
|  |  |  | if (StringUtils.isEmpty(hookIp)){ | 
|---|
|  |  |  | return sipIp; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return hookIp; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getSdpIp() { | 
|---|
|  |  |  | return sdpIp; | 
|---|
|  |  |  | public String getSipIp() { | 
|---|
|  |  |  | if (sipIp == null) { | 
|---|
|  |  |  | return this.ip; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return sipIp; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getStreamIp() { | 
|---|
|  |  |  | return streamIp; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getHttpPort() { | 
|---|
|  |  |  | public int getHttpPort() { | 
|---|
|  |  |  | return httpPort; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getHttpSSlPort() { | 
|---|
|  |  |  | public int getHttpSSlPort() { | 
|---|
|  |  |  | return httpSSlPort; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getRtmpPort() { | 
|---|
|  |  |  | public int getRtmpPort() { | 
|---|
|  |  |  | return rtmpPort; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getRtmpSSlPort() { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public int getRtmpSSlPort() { | 
|---|
|  |  |  | return rtmpSSlPort; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getRtpProxyPort() { | 
|---|
|  |  |  | return rtpProxyPort; | 
|---|
|  |  |  | public int getRtpProxyPort() { | 
|---|
|  |  |  | if (rtpProxyPort == null) { | 
|---|
|  |  |  | return 0; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return rtpProxyPort; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getRtspPort() { | 
|---|
|  |  |  | public int getRtspPort() { | 
|---|
|  |  |  | return rtspPort; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getRtspSSLPort() { | 
|---|
|  |  |  | public int getRtspSSLPort() { | 
|---|
|  |  |  | return rtspSSLPort; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | return secret; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getStreamNoneReaderDelayMS() { | 
|---|
|  |  |  | public int getStreamNoneReaderDelayMS() { | 
|---|
|  |  |  | return streamNoneReaderDelayMS; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | public String getRtpPortRange() { | 
|---|
|  |  |  | return rtpPortRange; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public int getRecordAssistPort() { | 
|---|
|  |  |  | return recordAssistPort; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getSdpIp() { | 
|---|
|  |  |  | if (StringUtils.isEmpty(sdpIp)){ | 
|---|
|  |  |  | return ip; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | if (isValidIPAddress(sdpIp)) { | 
|---|
|  |  |  | return sdpIp; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | // 按照域名解析 | 
|---|
|  |  |  | String hostAddress = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | hostAddress = InetAddress.getByName(sdpIp).getHostAddress(); | 
|---|
|  |  |  | } catch (UnknownHostException e) { | 
|---|
|  |  |  | throw new RuntimeException(e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return hostAddress; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getStreamIp() { | 
|---|
|  |  |  | if (StringUtils.isEmpty(streamIp)){ | 
|---|
|  |  |  | return ip; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return streamIp; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getSipDomain() { | 
|---|
|  |  |  | return sipDomain; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getSendRtpPortRange() { | 
|---|
|  |  |  | return sendRtpPortRange; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public MediaServerItem getMediaSerItem(){ | 
|---|
|  |  |  | MediaServerItem mediaServerItem = new MediaServerItem(); | 
|---|
|  |  |  | mediaServerItem.setId(id); | 
|---|
|  |  |  | mediaServerItem.setIp(ip); | 
|---|
|  |  |  | mediaServerItem.setDefaultServer(true); | 
|---|
|  |  |  | mediaServerItem.setHookIp(getHookIp()); | 
|---|
|  |  |  | mediaServerItem.setSdpIp(getSdpIp()); | 
|---|
|  |  |  | mediaServerItem.setStreamIp(getStreamIp()); | 
|---|
|  |  |  | mediaServerItem.setHttpPort(httpPort); | 
|---|
|  |  |  | mediaServerItem.setHttpSSlPort(httpSSlPort); | 
|---|
|  |  |  | mediaServerItem.setRtmpPort(rtmpPort); | 
|---|
|  |  |  | mediaServerItem.setRtmpSSlPort(rtmpSSlPort); | 
|---|
|  |  |  | mediaServerItem.setRtpProxyPort(getRtpProxyPort()); | 
|---|
|  |  |  | mediaServerItem.setRtspPort(rtspPort); | 
|---|
|  |  |  | mediaServerItem.setRtspSSLPort(rtspSSLPort); | 
|---|
|  |  |  | mediaServerItem.setAutoConfig(autoConfig); | 
|---|
|  |  |  | mediaServerItem.setSecret(secret); | 
|---|
|  |  |  | mediaServerItem.setStreamNoneReaderDelayMS(streamNoneReaderDelayMS); | 
|---|
|  |  |  | mediaServerItem.setRtpEnable(rtpEnable); | 
|---|
|  |  |  | mediaServerItem.setRtpPortRange(rtpPortRange); | 
|---|
|  |  |  | mediaServerItem.setSendRtpPortRange(sendRtpPortRange); | 
|---|
|  |  |  | mediaServerItem.setRecordAssistPort(recordAssistPort); | 
|---|
|  |  |  | mediaServerItem.setHookAliveInterval(120); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mediaServerItem.setCreateTime(DateUtil.getNow()); | 
|---|
|  |  |  | mediaServerItem.setUpdateTime(DateUtil.getNow()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return mediaServerItem; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private boolean isValidIPAddress(String ipAddress) { | 
|---|
|  |  |  | if ((ipAddress != null) && (!ipAddress.isEmpty())) { | 
|---|
|  |  |  | return Pattern.matches("^([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}$", ipAddress); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|