From 6fa5b37b962b05b3aa4b7bf019eb47c4cdbb5738 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期四, 05 一月 2023 11:07:06 +0800
Subject: [PATCH] Merge branch 'main' into main2

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java |   64 +++++++++++++++++++++++---------
 1 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
index 6e188a5..e314962 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
@@ -1,6 +1,7 @@
 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
 
 import com.alibaba.fastjson2.JSONObject;
+import com.genersoft.iot.vmp.common.VideoManagerConstants;
 import com.genersoft.iot.vmp.conf.DynamicTask;
 import com.genersoft.iot.vmp.conf.SipConfig;
 import com.genersoft.iot.vmp.conf.UserSetting;
@@ -439,18 +440,23 @@
 
                         try {
                             // 瓒呮椂鏈敹鍒癆ck搴旇鍥炲bye,褰撳墠绛夊緟鏃堕棿涓�10绉�
-                            dynamicTask.startDelay(callIdHeader.getCallId(), () -> {
-                                logger.info("Ack 绛夊緟瓒呮椂");
-                                mediaServerService.releaseSsrc(mediaServerItemInUSe.getId(), sendRtpItem.getSsrc());
-                                // 鍥炲bye
-                                try {
-                                    cmderFroPlatform.streamByeCmd(platform, callIdHeader.getCallId());
-                                } catch (SipException | InvalidArgumentException | ParseException e) {
-                                    logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�丅YE: {}", e.getMessage());
-                                }
-                            }, 60 * 1000);
-                            responseSdpAck(request, content.toString(), platform);
+                            if (userSetting.getPushStreamAfterAck()) {
+                                dynamicTask.startDelay(callIdHeader.getCallId(), () -> {
+                                    logger.info("Ack 绛夊緟瓒呮椂");
+                                    mediaServerService.releaseSsrc(mediaServerItemInUSe.getId(), sendRtpItem.getSsrc());
+                                    // 鍥炲bye
+                                    try {
+                                        cmderFroPlatform.streamByeCmd(platform, callIdHeader.getCallId());
+                                    } catch (SipException | InvalidArgumentException | ParseException e) {
+                                        logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�丅YE: {}", e.getMessage());
+                                    }
+                                }, 60 * 1000);
+                            }
 
+                            SIPResponse sipResponse = responseSdpAck(request, content.toString(), platform);
+                            if (!userSetting.getPushStreamAfterAck()) {
+                                playService.startPushStream(sendRtpItem, sipResponse, platform, request.getCallIdHeader());
+                            }
                         } catch (SipException e) {
                             e.printStackTrace();
                         } catch (InvalidArgumentException e) {
@@ -878,7 +884,11 @@
         content.append("f=\r\n");
 
         try {
-            return responseSdpAck(request, content.toString(), platform);
+            SIPResponse sipResponse = responseSdpAck(request, content.toString(), platform);
+            if (!userSetting.getPushStreamAfterAck()) {
+                playService.startPushStream(sendRtpItem, sipResponse, platform, request.getCallIdHeader());
+            }
+            return sipResponse;
         } catch (SipException e) {
             e.printStackTrace();
         } catch (InvalidArgumentException e) {
@@ -905,11 +915,14 @@
         }
         if (device != null) {
             logger.info("鏀跺埌璁惧" + requesterId + "鐨勮闊冲箍鎾璉nvite璇锋眰");
-
+            String key = VideoManagerConstants.BROADCAST_WAITE_INVITE +  device.getDeviceId() + audioBroadcastCatch.getChannelId();
+            dynamicTask.stop(key);
             try {
                 responseAck(request, Response.TRYING);
             } catch (SipException | InvalidArgumentException | ParseException e) {
                 logger.error("[鍛戒护鍙戦�佸け璐 invite BAD_REQUEST: {}", e.getMessage());
+                playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId());
+                return;
             }
             String contentString = new String(request.getRawContent());
             // jainSip涓嶆敮鎸亂=瀛楁锛� 绉婚櫎绉婚櫎浠ヨВ鏋愩��
@@ -964,11 +977,14 @@
                         responseAck(request, Response.UNSUPPORTED_MEDIA_TYPE); // 涓嶆敮鎸佺殑鏍煎紡锛屽彂415
                     } catch (SipException | InvalidArgumentException | ParseException e) {
                         logger.error("[鍛戒护鍙戦�佸け璐 invite 涓嶆敮鎸佺殑濯掍綋鏍煎紡: {}", e.getMessage());
+                        playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId());
+                        return;
                     }
                     return;
                 }
                 String addressStr = sdp.getOrigin().getAddress();
-                logger.info("璁惧{}璇锋眰璇煶娴侊紝鍦板潃锛歿}:{}锛宻src锛歿}", requesterId, addressStr, port, ssrc);
+                logger.info("璁惧{}璇锋眰璇煶娴侊紝鍦板潃锛歿}:{}锛宻src锛歿}, {}", requesterId, addressStr, port, ssrc,
+                        mediaTransmissionTCP ? (tcpActive? "TCP涓诲姩":"TCP琚姩") : "UDP");
 
                 MediaServerItem mediaServerItem = playService.getNewMediaServerItem(device);
                 if (mediaServerItem == null) {
@@ -977,6 +993,7 @@
                         responseAck(request, Response.BUSY_HERE);
                     } catch (SipException | InvalidArgumentException | ParseException e) {
                         logger.error("[鍛戒护鍙戦�佸け璐 invite 鏈壘鍒板彲鐢ㄧ殑zlm: {}", e.getMessage());
+                        playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId());
                     }
                     return;
                 }
@@ -990,13 +1007,12 @@
                         responseAck(request, Response.BUSY_HERE);
                     } catch (SipException | InvalidArgumentException | ParseException e) {
                         logger.error("[鍛戒护鍙戦�佸け璐 invite 鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�: {}", e.getMessage());
+                        playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId());
+                        return;
                     }
                     return;
                 }
-                sendRtpItem.setTcp(mediaTransmissionTCP);
-                if (tcpActive != null) {
-                    sendRtpItem.setTcpActive(tcpActive);
-                }
+
                 String app = "broadcast";
                 String stream = device.getDeviceId() + "_" + audioBroadcastCatch.getChannelId();
 
@@ -1011,6 +1027,11 @@
                 sendRtpItem.setUsePs(false);
                 sendRtpItem.setRtcp(false);
                 sendRtpItem.setOnlyAudio(true);
+                sendRtpItem.setTcp(mediaTransmissionTCP);
+                if (tcpActive != null) {
+                    sendRtpItem.setTcpActive(tcpActive);
+                }
+
                 redisCatchStorage.updateSendRTPSever(sendRtpItem);
 
 
@@ -1023,11 +1044,13 @@
                         responseAck(request, Response.GONE);
                     } catch (SipException | InvalidArgumentException | ParseException e) {
                         logger.error("[鍛戒护鍙戦�佸け璐 璇煶閫氳瘽 鍥炲410澶辫触锛� {}", e.getMessage());
+                        return;
                     }
                     playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId());
                 }
             } catch (SdpException e) {
                 logger.error("[SDP瑙f瀽寮傚父]", e);
+                playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId());
             }
         } else {
             logger.warn("鏉ヨ嚜鏃犳晥璁惧/骞冲彴鐨勮姹�");
@@ -1084,6 +1107,11 @@
             audioBroadcastCatch.setSipTransactionInfoByRequset(sipResponse);
             audioBroadcastManager.update(audioBroadcastCatch);
 
+            // 寮�鍚彂娴侊紝澶у崕鍦ㄦ敹鍒�200OK鍚庡氨浼氬紑濮嬪缓绔嬭繛鎺�
+            if (!userSetting.getPushStreamAfterAck()) {
+                playService.startPushStream(sendRtpItem, sipResponse, parentPlatform, request.getCallIdHeader());
+            }
+
         } catch (SipException | InvalidArgumentException | ParseException | SdpParseException e) {
             logger.error("[鍛戒护鍙戦�佸け璐 璇煶鍠婅瘽 鍥炲200OK锛圫DP锛�: {}", e.getMessage());
         }

--
Gitblit v1.8.0