From c551164c89f70e664b498c3a09e615928261e01a Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期六, 01 七月 2023 18:33:42 +0800
Subject: [PATCH] 合并主线

---
 src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java |   63 ++++++++++++-------------------
 1 files changed, 24 insertions(+), 39 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
index c345770..71e9b65 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -16,16 +16,11 @@
 import com.genersoft.iot.vmp.gb28181.session.AudioBroadcastManager;
 import com.genersoft.iot.vmp.gb28181.session.SSRCFactory;
 import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
-import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
 import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
-import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils;
-import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
-import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
-import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
+import com.genersoft.iot.vmp.media.zlm.*;
 import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
-import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForRtpServerTimeout;
 import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange;
 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
 import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam;
@@ -95,7 +90,7 @@
     private IInviteStreamService inviteStreamService;
 
     @Autowired
-    private DeferredResultHolder resultHolder;
+    private SendRtpPortManager sendRtpPortManager;
 
     @Autowired
     private ZLMRESTfulUtils zlmresTfulUtils;
@@ -235,8 +230,8 @@
         sendRtpItem.setUsePs(false);
         sendRtpItem.setReceiveStream(stream + "_talk");
 
-
-        int port = zlmrtpServerFactory.keepPort(mediaServerItem, playSsrc, null);
+        String callId = SipUtils.getNewCallId();
+        int port = sendRtpPortManager.getNextPort(mediaServerItem.getId());
         //绔彛鑾峰彇澶辫触鐨剆srcInfo 娌℃湁蹇呰鍙戦�佺偣鎾寚浠�
         if (port <= 0) {
             logger.info("[璇煶瀵硅] 绔彛鍒嗛厤寮傚父锛宒eviceId={},channelId={}", device.getDeviceId(), channelId);
@@ -264,9 +259,6 @@
             }
         }, userSetting.getPlayTimeout());
 
-        String callId = SipUtils.getNewCallId();
-
-        zlmrtpServerFactory.releasePort(mediaServerItem, playSsrc);
         Map<String, Object> param = new HashMap<>(12);
         param.put("vhost","__defaultVhost__");
         param.put("app", sendRtpItem.getApp());
@@ -293,12 +285,12 @@
 
         // 鏌ョ湅璁惧鏄惁宸茬粡鍦ㄦ帹娴�
         try {
-            cmder.talkStreamCmd(mediaServerItem, sendRtpItem, device, channelId, callId, (MediaServerItem mediaServerItemInuse, JSONObject response) -> {
-                logger.info("[璇煶瀵硅] 娴佸凡鐢熸垚锛� 寮�濮嬫帹娴侊細 " + response.toJSONString());
+            cmder.talkStreamCmd(mediaServerItem, sendRtpItem, device, channelId, callId, (mediaServerItemInuse, hookParam) -> {
+                logger.info("[璇煶瀵硅] 娴佸凡鐢熸垚锛� 寮�濮嬫帹娴侊細 " + hookParam);
                 dynamicTask.stop(timeOutTaskKey);
                 // TODO 鏆備笉鍋氬鐞�
-            }, (MediaServerItem mediaServerItemInuse, JSONObject json) -> {
-                logger.info("[璇煶瀵硅] 璁惧寮�濮嬫帹娴侊細 " + json.toJSONString());
+            }, (mediaServerItemInuse, hookParam) -> {
+                logger.info("[璇煶瀵硅] 璁惧寮�濮嬫帹娴侊細 " + hookParam);
                 dynamicTask.stop(timeOutTaskKey);
 
             }, (event) -> {
@@ -362,7 +354,7 @@
                     null);
             return;
         }
-        logger.info("[鐐规挱寮�濮媇 deviceId: {}, channelId: {},鐮佹祦绫诲瀷锛歿},鏀舵祦绔彛锛� {}, 鏀舵祦妯″紡锛歿}, SSRC: {}, SSRC鏍¢獙锛歿}",
+        logger.info("[鐐规挱寮�濮媇 deviceId: {}, channelId: {},鐮佹祦绫诲瀷锛歿}, 鏀舵祦绔彛锛� {}, 鏀舵祦妯″紡锛歿}, SSRC: {}, SSRC鏍¢獙锛歿}",
                 device.getDeviceId(), channelId, device.isSwitchPrimarySubStream() ? "杈呯爜娴�" : "涓荤爜娴�", ssrcInfo.getPort(),
                 device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());
         //绔彛鑾峰彇澶辫触鐨剆srcInfo 娌℃湁蹇呰鍙戦�佺偣鎾寚浠�
@@ -445,7 +437,7 @@
                         InviteErrorCode.SUCCESS.getCode(),
                         InviteErrorCode.SUCCESS.getMsg(),
                         streamInfo);
-                logger.info("[鐐规挱鎴愬姛] deviceId: {}, channelId: {},鐮佹祦绫诲瀷锛歿}", device.getDeviceId(),
+                logger.info("[鐐规挱鎴愬姛] deviceId: {}, channelId:{}, 鐮佹祦绫诲瀷锛歿}", device.getDeviceId(),
                         device.isSwitchPrimarySubStream() ? "杈呯爜娴�" : "涓荤爜娴�");
                 String streamUrl;
                 if (mediaServerItemInuse.getRtspPort() != 0) {
@@ -617,10 +609,10 @@
     }
 
     @Override
-    public StreamInfo onPublishHandlerForPlay(MediaServerItem mediaServerItem, JSONObject response, String deviceId, String channelId) {
-        StreamInfo streamInfo = onPublishHandler(mediaServerItem, response, deviceId, channelId);
+    public StreamInfo onPublishHandlerForPlay(MediaServerItem mediaServerItem, HookParam hookParam, String deviceId, String channelId) {
+        OnStreamChangedHookParam streamChangedHookParam = (OnStreamChangedHookParam) hookParam;
+        StreamInfo streamInfo = onPublishHandler(mediaServerItem, streamChangedHookParam, deviceId, channelId);
         Device device = redisCatchStorage.getDevice(deviceId);
-        OnStreamChangedHookParam streamChangedHookParam = (OnStreamChangedHookParam)hookParam;
         if (streamInfo != null) {
             DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId);
             if (deviceChannel != null) {
@@ -1434,14 +1426,10 @@
 
     @Override
     public void startPushStream(SendRtpItem sendRtpItem, SIPResponse sipResponse, ParentPlatform platform, CallIdHeader callIdHeader) {
-
         // 寮�濮嬪彂娴�
-        // 鍙栨秷璁剧疆鐨勮秴鏃朵换鍔�
-//			String channelId = request.getCallIdHeader().getCallId();
-
         String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
         MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
-        logger.info("鏀跺埌ACK锛宺tp/{}寮�濮嬫帹娴�, 鐩爣={}:{}锛孲SRC={}, RTCP={}", sendRtpItem.getStream(),
+        logger.info("[寮�濮嬫帹娴乚 rtp/{}, 鐩爣={}:{}锛孲SRC={}, RTCP={}", sendRtpItem.getStream(),
                 sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc(), sendRtpItem.isRtcp());
         Map<String, Object> param = new HashMap<>(12);
         param.put("vhost", "__defaultVhost__");
@@ -1467,19 +1455,15 @@
                 startSendRtpStreamHand(sendRtpItem, platform, json, param, callIdHeader);
             });
         } else {
-            // 濡傛灉鏄潪涓ユ牸妯″紡锛岄渶瑕佸叧闂鍙e崰鐢�
+            // 濡傛灉鏄弗鏍兼ā寮忥紝闇�瑕佸叧闂鍙e崰鐢�
             JSONObject startSendRtpStreamResult = null;
             if (sendRtpItem.getLocalPort() != 0) {
-                HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(sendRtpItem.getSsrc(), null, mediaInfo.getId());
-                hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout);
-                if (zlmrtpServerFactory.releasePort(mediaInfo, sendRtpItem.getSsrc())) {
-                    if (sendRtpItem.isTcpActive()) {
-                        startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param);
-                    } else {
-                        param.put("dst_url", sendRtpItem.getIp());
-                        param.put("dst_port", sendRtpItem.getPort());
-                        startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
-                    }
+                if (sendRtpItem.isTcpActive()) {
+                    startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param);
+                } else {
+                    param.put("dst_url", sendRtpItem.getIp());
+                    param.put("dst_port", sendRtpItem.getPort());
+                    startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
                 }
             } else {
                 if (sendRtpItem.isTcpActive()) {
@@ -1503,7 +1487,8 @@
             logger.error("RTP鎺ㄦ祦澶辫触: 璇锋鏌LM鏈嶅姟");
         } else if (jsonObject.getInteger("code") == 0) {
             logger.info("璋冪敤ZLM鎺ㄦ祦鎺ュ彛, 缁撴灉锛� {}", jsonObject);
-            logger.info("RTP鎺ㄦ祦鎴愬姛[ {}/{} ]锛寋}->{}:{}, ", param.get("app"), param.get("stream"), jsonObject.getString("local_port"), param.get("dst_url"), param.get("dst_port"));
+            logger.info("RTP鎺ㄦ祦鎴愬姛[ {}/{} ]锛寋}->{}, ", param.get("app"), param.get("stream"), jsonObject.getString("local_port"),
+                    sendRtpItem.isTcpActive()?"琚姩鍙戞祦": param.get("dst_url") + ":" + param.get("dst_port"));
         } else {
             logger.error("RTP鎺ㄦ祦澶辫触: {}, 鍙傛暟锛歿}", jsonObject.getString("msg"), JSONObject.toJSONString(param));
             if (sendRtpItem.isOnlyAudio()) {
@@ -1571,7 +1556,7 @@
             }
         }
 
-        talk(mediaServerItem, device, channelId, stream, (MediaServerItem mediaServerItem1, JSONObject response) -> {
+        talk(mediaServerItem, device, channelId, stream, (mediaServerItem1, hookParam) -> {
             logger.info("[璇煶瀵硅] 鏀跺埌璁惧鍙戞潵鐨勬祦");
         }, eventResult -> {
             logger.warn("[璇煶瀵硅] 澶辫触锛寋}/{}, 閿欒鐮� {} {}", device.getDeviceId(), channelId, eventResult.statusCode, eventResult.msg);

--
Gitblit v1.8.0