From 07a8ef9e256c70a3a5b15782add81dcad1e2ffc2 Mon Sep 17 00:00:00 2001 From: panlinlin <648540858@qq.com> Date: 星期五, 14 六月 2024 00:03:57 +0800 Subject: [PATCH] SIP只有一个监听时,直接返回 --- src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMServerFactory.java | 142 ++++++++--------------------------------------- 1 files changed, 25 insertions(+), 117 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMServerFactory.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMServerFactory.java old mode 100644 new mode 100755 index c81e00d..4191fe5 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMServerFactory.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMServerFactory.java @@ -5,7 +5,7 @@ import com.genersoft.iot.vmp.common.CommonCallback; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; -import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; +import com.genersoft.iot.vmp.media.bean.MediaServer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -17,16 +17,13 @@ @Component public class ZLMServerFactory { - private Logger logger = LoggerFactory.getLogger("ZLMRTPServerFactory"); + private Logger logger = LoggerFactory.getLogger("ZLMServerFactory"); @Autowired private ZLMRESTfulUtils zlmresTfulUtils; @Autowired private UserSetting userSetting; - - @Autowired - private ZlmHttpHookSubscribe hookSubscribe; @Autowired private SendRtpPortManager sendRtpPortManager; @@ -42,7 +39,7 @@ * @param tcpMode 0/null udp 妯″紡锛�1 tcp 琚姩妯″紡, 2 tcp 涓诲姩妯″紡銆� * @return */ - public int createRTPServer(MediaServerItem mediaServerItem, String streamId, int ssrc, Integer port, Boolean onlyAuto, Boolean reUsePort, Integer tcpMode) { + public int createRTPServer(MediaServer mediaServerItem, String streamId, long ssrc, Integer port, Boolean onlyAuto, Boolean reUsePort, Integer tcpMode) { int result = -1; // 鏌ヨ姝tp server 鏄惁宸茬粡瀛樺湪 JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaServerItem, streamId); @@ -86,10 +83,13 @@ }else { param.put("port", port); } - param.put("ssrc", ssrc); if (onlyAuto != null) { param.put("only_audio", onlyAuto?"1":"0"); } + if (ssrc != 0) { + param.put("ssrc", ssrc); + } + JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param); logger.info(JSONObject.toJSONString(openRtpServerResultJson)); if (openRtpServerResultJson != null) { @@ -105,7 +105,7 @@ return result; } - public boolean closeRtpServer(MediaServerItem serverItem, String streamId) { + public boolean closeRtpServer(MediaServer serverItem, String streamId) { boolean result = false; if (serverItem !=null){ Map<String, Object> param = new HashMap<>(); @@ -126,7 +126,7 @@ return result; } - public void closeRtpServer(MediaServerItem serverItem, String streamId, CommonCallback<Boolean> callback) { + public void closeRtpServer(MediaServer serverItem, String streamId, CommonCallback<Boolean> callback) { if (serverItem == null) { callback.run(false); return; @@ -153,111 +153,27 @@ /** - * 鍒涘缓涓�涓浗鏍囨帹娴� - * @param ip 鎺ㄦ祦ip - * @param port 鎺ㄦ祦绔彛 - * @param ssrc 鎺ㄦ祦鍞竴鏍囪瘑 - * @param platformId 骞冲彴id - * @param channelId 閫氶亾id - * @param tcp 鏄惁涓簍cp - * @return SendRtpItem - */ - public SendRtpItem createSendRtpItem(MediaServerItem serverItem, String ip, int port, String ssrc, String platformId, - String deviceId, String channelId, boolean tcp, boolean rtcp){ - - // 榛樿涓洪殢鏈虹鍙� - int localPort = 0; - if (userSetting.getGbSendStreamStrict()) { - localPort = sendRtpPortManager.getNextPort(serverItem.getId()); - if (localPort == 0) { - return null; - } - } - SendRtpItem sendRtpItem = new SendRtpItem(); - sendRtpItem.setIp(ip); - sendRtpItem.setPort(port); - sendRtpItem.setSsrc(ssrc); - sendRtpItem.setPlatformId(platformId); - sendRtpItem.setDeviceId(deviceId); - sendRtpItem.setChannelId(channelId); - sendRtpItem.setTcp(tcp); - sendRtpItem.setRtcp(rtcp); - sendRtpItem.setApp("rtp"); - sendRtpItem.setLocalPort(localPort); - sendRtpItem.setServerId(userSetting.getServerId()); - sendRtpItem.setMediaServerId(serverItem.getId()); - return sendRtpItem; - } - - /** - * 鍒涘缓涓�涓洿鎾帹娴� - * @param ip 鎺ㄦ祦ip - * @param port 鎺ㄦ祦绔彛 - * @param ssrc 鎺ㄦ祦鍞竴鏍囪瘑 - * @param platformId 骞冲彴id - * @param channelId 閫氶亾id - * @param tcp 鏄惁涓簍cp - * @return SendRtpItem - */ - public SendRtpItem createSendRtpItem(MediaServerItem serverItem, String ip, int port, String ssrc, String platformId, - String app, String stream, String channelId, boolean tcp, boolean rtcp){ - // 榛樿涓洪殢鏈虹鍙� - int localPort = 0; - if (userSetting.getGbSendStreamStrict()) { - localPort = sendRtpPortManager.getNextPort(serverItem.getId()); - if (localPort == 0) { - return null; - } - } - SendRtpItem sendRtpItem = new SendRtpItem(); - sendRtpItem.setIp(ip); - sendRtpItem.setPort(port); - sendRtpItem.setSsrc(ssrc); - sendRtpItem.setApp(app); - sendRtpItem.setStream(stream); - sendRtpItem.setPlatformId(platformId); - sendRtpItem.setChannelId(channelId); - sendRtpItem.setTcp(tcp); - sendRtpItem.setLocalPort(localPort); - sendRtpItem.setServerId(userSetting.getServerId()); - sendRtpItem.setMediaServerId(serverItem.getId()); - sendRtpItem.setRtcp(rtcp); - return sendRtpItem; - } - - /** * 璋冪敤zlm RESTFUL API 鈥斺�� startSendRtp */ - public JSONObject startSendRtpStream(MediaServerItem mediaServerItem, Map<String, Object>param) { + public JSONObject startSendRtpStream(MediaServer mediaServerItem, Map<String, Object>param) { return zlmresTfulUtils.startSendRtp(mediaServerItem, param); } /** * 璋冪敤zlm RESTFUL API 鈥斺�� startSendRtpPassive */ - public JSONObject startSendRtpPassive(MediaServerItem mediaServerItem, Map<String, Object>param) { + public JSONObject startSendRtpPassive(MediaServer mediaServerItem, Map<String, Object>param) { return zlmresTfulUtils.startSendRtpPassive(mediaServerItem, param); } - public JSONObject startSendRtpPassive(MediaServerItem mediaServerItem, Map<String, Object>param, ZLMRESTfulUtils.RequestCallback callback) { + public JSONObject startSendRtpPassive(MediaServer mediaServerItem, Map<String, Object>param, ZLMRESTfulUtils.RequestCallback callback) { return zlmresTfulUtils.startSendRtpPassive(mediaServerItem, param, callback); } /** * 鏌ヨ寰呰浆鎺ㄧ殑娴佹槸鍚﹀氨缁� */ - public Boolean isRtpReady(MediaServerItem mediaServerItem, String streamId) { - JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem,"rtp", "rtsp", streamId); - if (mediaInfo.getInteger("code") == -2) { - return null; - } - return (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")); - } - - /** - * 鏌ヨ寰呰浆鎺ㄧ殑娴佹槸鍚﹀氨缁� - */ - public Boolean isStreamReady(MediaServerItem mediaServerItem, String app, String streamId) { + public Boolean isStreamReady(MediaServer mediaServerItem, String app, String streamId) { JSONObject mediaInfo = zlmresTfulUtils.getMediaList(mediaServerItem, app, streamId); if (mediaInfo == null || (mediaInfo.getInteger("code") == -2)) { return null; @@ -272,7 +188,7 @@ * @param streamId * @return */ - public int totalReaderCount(MediaServerItem mediaServerItem, String app, String streamId) { + public int totalReaderCount(MediaServer mediaServerItem, String app, String streamId) { JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem, app, "rtsp", streamId); if (mediaInfo == null) { return 0; @@ -289,24 +205,7 @@ return mediaInfo.getInteger("totalReaderCount"); } - /** - * 璋冪敤zlm RESTful API 鈥斺�� stopSendRtp - */ - public Boolean stopSendRtpStream(MediaServerItem mediaServerItem, Map<String, Object>param) { - Boolean result = false; - JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(mediaServerItem, param); - if (jsonObject == null) { - logger.error("[鍋滄RTP鎺ㄦ祦] 澶辫触: 璇锋鏌LM鏈嶅姟"); - } else if (jsonObject.getInteger("code") == 0) { - result= true; - logger.info("[鍋滄RTP鎺ㄦ祦] 鎴愬姛"); - } else { - logger.warn("[鍋滄RTP鎺ㄦ祦] 澶辫触: {}, 鍙傛暟锛歿}->\r\n{}",jsonObject.getString("msg"), JSON.toJSON(param), jsonObject); - } - return result; - } - - public JSONObject startSendRtp(MediaServerItem mediaInfo, SendRtpItem sendRtpItem) { + public JSONObject startSendRtp(MediaServer mediaInfo, SendRtpItem sendRtpItem) { String is_Udp = sendRtpItem.isTcp() ? "0" : "1"; logger.info("rtp/{}寮�濮嬫帹娴�, 鐩爣={}:{}锛孲SRC={}", sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc()); Map<String, Object> param = new HashMap<>(12); @@ -351,7 +250,7 @@ return startSendRtpStreamResult; } - public Boolean updateRtpServerSSRC(MediaServerItem mediaServerItem, String streamId, String ssrc) { + public Boolean updateRtpServerSSRC(MediaServer mediaServerItem, String streamId, String ssrc) { boolean result = false; JSONObject jsonObject = zlmresTfulUtils.updateRtpServerSSRC(mediaServerItem, streamId, ssrc); if (jsonObject == null) { @@ -365,4 +264,13 @@ } return result; } + + public JSONObject stopSendRtpStream(MediaServer mediaServerItem, SendRtpItem sendRtpItem) { + Map<String, Object> param = new HashMap<>(); + param.put("vhost", "__defaultVhost__"); + param.put("app", sendRtpItem.getApp()); + param.put("stream", sendRtpItem.getStream()); + param.put("ssrc", sendRtpItem.getSsrc()); + return zlmresTfulUtils.stopSendRtp(mediaServerItem, param); + } } -- Gitblit v1.8.0