|  |  |  | 
|---|
|  |  |  | package com.genersoft.iot.vmp.conf; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.utils.DateUtil; | 
|---|
|  |  |  | import org.slf4j.Logger; | 
|---|
|  |  |  | import org.slf4j.LoggerFactory; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.context.annotation.Configuration; | 
|---|
|  |  |  | import org.springframework.util.StringUtils; | 
|---|
|  |  |  | import org.springframework.core.annotation.Order; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.net.InetAddress; | 
|---|
|  |  |  | import java.net.UnknownHostException; | 
|---|
|  |  |  | import java.util.regex.Pattern; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Configuration("mediaConfig") | 
|---|
|  |  |  | @Order(0) | 
|---|
|  |  |  | public class MediaConfig{ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.id:}") | 
|---|
|  |  |  | private final static Logger logger = LoggerFactory.getLogger(MediaConfig.class); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 修改必须配置,不再支持自动获取 | 
|---|
|  |  |  | @Value("${media.id}") | 
|---|
|  |  |  | private String id; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.ip}") | 
|---|
|  |  |  | private String ip; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.hook-ip:${sip.ip}}") | 
|---|
|  |  |  | @Value("${media.hook-ip:}") | 
|---|
|  |  |  | private String hookIp; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${sip.ip}") | 
|---|
|  |  |  | 
|---|
|  |  |  | @Value("${media.secret}") | 
|---|
|  |  |  | private String secret; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.stream-none-reader-delay-ms:18000}") | 
|---|
|  |  |  | private String streamNoneReaderDelayMS = "18000"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.rtp.enable}") | 
|---|
|  |  |  | private boolean rtpEnable; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.rtp.port-range}") | 
|---|
|  |  |  | private String rtpPortRange; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.rtp.send-port-range}") | 
|---|
|  |  |  | private String sendRtpPortRange; | 
|---|
|  |  |  | private String rtpSendPortRange; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${media.record-assist-port:0}") | 
|---|
|  |  |  | private Integer recordAssistPort = 0; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getHookIp() { | 
|---|
|  |  |  | if (StringUtils.isEmpty(hookIp)){ | 
|---|
|  |  |  | return sipIp; | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(hookIp)){ | 
|---|
|  |  |  | return sipIp.split(",")[0]; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return hookIp; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return secret; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getStreamNoneReaderDelayMS() { | 
|---|
|  |  |  | return streamNoneReaderDelayMS; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public boolean isRtpEnable() { | 
|---|
|  |  |  | return rtpEnable; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getSdpIp() { | 
|---|
|  |  |  | if (StringUtils.isEmpty(sdpIp)){ | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(sdpIp)){ | 
|---|
|  |  |  | return ip; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return sdpIp; | 
|---|
|  |  |  | if (isValidIPAddress(sdpIp)) { | 
|---|
|  |  |  | return sdpIp; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | // 按照域名解析 | 
|---|
|  |  |  | String hostAddress = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | hostAddress = InetAddress.getByName(sdpIp).getHostAddress(); | 
|---|
|  |  |  | } catch (UnknownHostException e) { | 
|---|
|  |  |  | logger.error("[获取SDP IP]: 域名解析失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return hostAddress; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getStreamIp() { | 
|---|
|  |  |  | if (StringUtils.isEmpty(streamIp)){ | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(streamIp)){ | 
|---|
|  |  |  | return ip; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return streamIp; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getSipDomain() { | 
|---|
|  |  |  | return sipDomain; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getSendRtpPortRange() { | 
|---|
|  |  |  | return sendRtpPortRange; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public MediaServerItem getMediaSerItem(){ | 
|---|
|  |  |  | 
|---|
|  |  |  | mediaServerItem.setRtspSSLPort(rtspSSLPort); | 
|---|
|  |  |  | mediaServerItem.setAutoConfig(autoConfig); | 
|---|
|  |  |  | mediaServerItem.setSecret(secret); | 
|---|
|  |  |  | mediaServerItem.setStreamNoneReaderDelayMS(streamNoneReaderDelayMS); | 
|---|
|  |  |  | mediaServerItem.setRtpEnable(rtpEnable); | 
|---|
|  |  |  | mediaServerItem.setRtpPortRange(rtpPortRange); | 
|---|
|  |  |  | mediaServerItem.setSendRtpPortRange(sendRtpPortRange); | 
|---|
|  |  |  | mediaServerItem.setSendRtpPortRange(rtpSendPortRange); | 
|---|
|  |  |  | mediaServerItem.setRecordAssistPort(recordAssistPort); | 
|---|
|  |  |  | mediaServerItem.setHookAliveInterval(30.00f); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | mediaServerItem.setCreateTime(format.format(System.currentTimeMillis())); | 
|---|
|  |  |  | mediaServerItem.setUpdateTime(format.format(System.currentTimeMillis())); | 
|---|
|  |  |  | mediaServerItem.setCreateTime(DateUtil.getNow()); | 
|---|
|  |  |  | mediaServerItem.setUpdateTime(DateUtil.getNow()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return mediaServerItem; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getRtpSendPortRange() { | 
|---|
|  |  |  | return rtpSendPortRange; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void setRtpSendPortRange(String rtpSendPortRange) { | 
|---|
|  |  |  | this.rtpSendPortRange = rtpSendPortRange; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|