Przeglądaj źródła

fix(video): 终拒证据先于回调且可真正收敛

Kazerin 3 tygodni temu
rodzic
commit
2b7ca8e021

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

@@ -438,8 +438,9 @@ public class PlayServiceImpl implements IPlayService {
             }
             // A definitive INVITE refusal establishes that no dialog exists for this attempt.
             // Timeouts, lost replies, 401/407 and unknown states stay pending.
-            boolean refused = !receipt.inviteSent || expected != null && sessionManager.isInviteRejected(
-                    node.getId(), "rtp", stream, retained.allocation == null ? stream : retained.allocation.token);
+            String allocationToken = retained.allocation == null ? stream : retained.allocation.token;
+            boolean refused = !receipt.inviteSent
+                    || sessionManager.isInviteRejected(node.getId(), "rtp", stream, allocationToken);
             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;

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

@@ -127,6 +127,12 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
 //            sipSubscribe.updateTimeout(response.getCallIdHeader().getCallId());
         } else {
             log.warn("接收到失败的response响应!status:" + status + ",message:" + response.getReasonPhrase());
+            // Persist a final INVITE refusal BEFORE the error callback runs: stopManaged may
+            // consult it immediately. 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 ex) { log.warn("[INVITE rejection] evidence not durable: {}", ex.getMessage()); }
+            }
             if (responseEvent.getResponse() != null && !sipSubscribe.isEmpty() ) {
                 CallIdHeader callIdHeader = response.getCallIdHeader();
                 CSeqHeader cSeqHeader = response.getCSeqHeader();
@@ -147,12 +153,6 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
                     && (sessionManager == null || !sessionManager.hasByeRequest(response))) {
                 responseEvent.getDialog().delete();
             }
-            // A final refusal of a managed INVITE is durable evidence that no dialog was
-            // 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 ex) { log.warn("[INVITE rejection] evidence not durable: {}", ex.getMessage()); }
-            }
         }
 
 

+ 16 - 2
video-service/src/test/java/com/zksy/video/lifecycle/VideoStopReceiptRestartTest.java

@@ -129,6 +129,21 @@ class VideoStopReceiptRestartTest {
         assertEquals(2, world.closeRequests.size());
     }
 
+    @Test void definitiveInviteRefusalLetsARealRtpCloseConvergeWithoutADialog() throws Exception {
+        External world = new External(); Instance instance = new Instance(world);
+        SSRCInfo allocation = instance.play.playManaged(world.node, "device", "channel", STREAM, (c, m, r) -> { });
+        assertNotNull(allocation);
+        Request invite = world.requests.get(world.requests.size() - 1);
+        // A final refusal means no dialog is ever established for this attempt. The real observer
+        // records the refusal before any error callback runs.
+        instance.response(invite, 486);
+        assertNull(instance.sessions.getSsrcTransactionByStream("rtp", STREAM));
+        // The exact RTP allocation is nonetheless real and must be reclaimable.
+        assertTrue(instance.rtp.closeManagedRTPServer(world.node, allocation));
+        assertTrue(new Instance(world).stopManaged(), "refused INVITE plus a positive RTP close must converge");
+        assertEquals(1, world.closeRequests.size());
+    }
+
     @Test void managedStopRecoversOriginalDialogAfterByeReceiptAndLiveDialogDeletion() throws Exception {
         External world = new External(); Instance first = new Instance(world);
         first.managed();
@@ -303,8 +318,7 @@ class VideoStopReceiptRestartTest {
             RTPServerParam param = new RTPServerParam(); param.setMediaServerItem(world.node); param.setStreamId(stream);
             return rtp.openRTPServer(param, (code, msg, result) -> { });
         }
-        void managed() throws Exception {
-            SSRCInfo info = play.playManaged(world.node, "device", "channel", STREAM, (c, m, r) -> { }); assertNotNull(info);
+        void managed() throws Exception {            SSRCInfo info = play.playManaged(world.node, "device", "channel", STREAM, (c, m, r) -> { }); assertNotNull(info);
             Request invite = world.requests.get(world.requests.size() - 1); assertEquals(Request.INVITE, invite.getMethod());
             SIPResponse reply = reply(invite, 200);
             reply.setContent("v=0\r\ns=Play\r\ny=" + info.getSsrc() + "\r\n",