Просмотр исходного кода

fix(video): 回收已创建端口并按原邀请快照删除

Kazerin 3 недель назад
Родитель
Сommit
bd80b6a447

+ 6 - 2
video-service/src/main/java/com/ruoyi/wvp/gb28181/service/impl/PlayServiceImpl.java

@@ -443,7 +443,10 @@ public class PlayServiceImpl implements IPlayService {
             if (!rtpClosed || (!refused && receipt.inviteSent && (expected == null || !sessionManager.isSipTerminated(expected)))) return false;
             SsrcTransaction now = sessionManager.getSsrcTransactionByStream("rtp", stream);
             if (now != null && !SipInviteSessionManager.sameDialog(expected, now)) return false;
-            inviteStreamService.removeInviteInfo(InviteSessionType.PLAY, channel.getId(), stream);
+            // Delete by the original Invite snapshot, not by name: a same-name replacement may
+            // have appeared between the check above and this removal.
+            InviteInfo closing = inviteStreamService.getInviteInfo(InviteSessionType.PLAY, channel.getId(), stream);
+            if (closing != null && !inviteStreamService.removeInviteInfoIfSame(closing)) return false;
             return true;
         } catch (RuntimeException ex) {
             log.warn("[Managed receipt] {}/{} remains pending: {}", node.getId(), stream, ex.getMessage());
@@ -573,7 +576,8 @@ public class PlayServiceImpl implements IPlayService {
             invite = inviteStreamService.getInviteInfo(InviteSessionType.PLAY, channel.getId(), stream);
             if (!closed || !sessionManager.isSipTerminated(owned.dialog)
                     || (current != null && !SipInviteSessionManager.sameDialog(owned.dialog, current))
-                    || (invite != null && !adoptedInvite(owned, invite))) return false;            if (invite != null) inviteStreamService.removeInviteInfo(InviteSessionType.PLAY, channel.getId(), stream);
+                    || (invite != null && !adoptedInvite(owned, invite))) return false;
+            if (invite != null && !inviteStreamService.removeInviteInfoIfSame(invite)) return false;
             return true;
         } catch (RuntimeException ex) {
             log.warn("[Adopted receipt] {}/{} remains pending: {}", node == null ? null : node.getId(), stream, ex.getMessage());

+ 1 - 1
video-service/src/main/java/com/ruoyi/wvp/gb28181/transmit/SIPProcessorObserver.java

@@ -151,7 +151,7 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
             // established; timeouts and lost replies are never recorded this way.
             if (sessionManager != null && javax.sip.message.Request.INVITE.equals(response.getCSeqHeader().getMethod())) {
                 try { sessionManager.rememberInviteRejection(response); }
-                catch (RuntimeException ignored) { /* Rejection evidence is optional; it never blocks transport. */ }
+                catch (RuntimeException ex) { log.warn("[INVITE rejection] evidence not durable: {}", ex.getMessage()); }
             }
         }
 

+ 13 - 4
video-service/src/main/java/com/ruoyi/wvp/service/impl/RtpServerServiceImpl.java

@@ -86,7 +86,6 @@ public class RtpServerServiceImpl implements IReceiveRtpServerService {
         private final SSRCInfo info;
         private HookSubscribe.Subscription owner;
         private final java.util.concurrent.atomic.AtomicBoolean terminal = new java.util.concurrent.atomic.AtomicBoolean();
-        private final java.util.concurrent.atomic.AtomicBoolean released = new java.util.concurrent.atomic.AtomicBoolean();
         private ManagedRtp(SSRCInfo info) { this.info = info; }
     }
 
@@ -219,7 +218,13 @@ public class RtpServerServiceImpl implements IReceiveRtpServerService {
                     0, false, param.isDisableAudio(), false, param.getTcpMode());
             entry.info.setPort(port);
             // Only the creator knows create returned. Restart during create remains CREATING.
-            if (!allocationState(node, entry.info, RtpState.CREATING, RtpState.OPEN)) return null;
+            if (!allocationState(node, entry.info, RtpState.CREATING, RtpState.OPEN)) {
+                // The port was already created above. A failed receipt transition must not leak it:
+                // close the exact allocation instead of returning silently.
+                closeManagedRTPServer(node, entry.info);
+                callback.run(InviteErrorCode.FAIL.getCode(), "Managed RTP receipt not acknowledged", null);
+                return null;
+            }
             if (port <= 0 || cancelled(stream) || entry.terminal.get()) {
                 closeManagedRTPServer(node, entry.info);
                 callback.run(InviteErrorCode.FAIL.getCode(), "Managed RTP allocation failed or was cancelled", null);
@@ -324,7 +329,6 @@ public class RtpServerServiceImpl implements IReceiveRtpServerService {
         private final SSRCInfo info;
         private HookSubscribe.Subscription owner;
         private final java.util.concurrent.atomic.AtomicBoolean terminal = new java.util.concurrent.atomic.AtomicBoolean();
-        private final java.util.concurrent.atomic.AtomicBoolean released = new java.util.concurrent.atomic.AtomicBoolean();
         private LegacyRtp(SSRCInfo info) { this.info = info; }
     }
 
@@ -419,7 +423,12 @@ public class RtpServerServiceImpl implements IReceiveRtpServerService {
             rtpServerPort = rtpServerParam.getMediaServerItem().getRtpProxyPort();
         }
         ssrcInfo.setPort(rtpServerPort);
-        if (!allocationState(rtpServerParam.getMediaServerItem(), ssrcInfo, RtpState.CREATING, RtpState.OPEN)) return null;
+        if (!allocationState(rtpServerParam.getMediaServerItem(), ssrcInfo, RtpState.CREATING, RtpState.OPEN)) {
+            // A created port must be closed even when the receipt transition did not commit.
+            closeAllocation(rtpServerParam.getMediaServerItem(), ssrcInfo);
+            callback.run(InviteErrorCode.FAIL.getCode(), "RTP receipt not acknowledged", null);
+            return null;
+        }
         if (rtpServerPort == 0) {
             callback.run(InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), "开启RTPServer失败", null);
             // 释放ssrc