srtpdec: fix reseting RTP sequence number on ROC changes
authorMiguel Paris <mparisdiaz@gmail.com>
Tue, 29 May 2018 13:00:43 +0000 (15:00 +0200)
committerMiguel Paris <mparisdiaz@gmail.com>
Wed, 1 Apr 2020 14:49:44 +0000 (16:49 +0200)
Each srtp_stream_t is tied to an specific SSRC, so a
roc_changed flag should be kept per each SSRC in order to
properly reset RTP sequence number on ROC changes.

ext/srtp/gstsrtpdec.c
ext/srtp/gstsrtpdec.h

index 7323fe34c080b557d8899118180cd0fdf617180a..d93d0a85b052ff74bb8c6ae343c0ab4c332a1d25 100644 (file)
@@ -415,10 +415,6 @@ gst_srtp_dec_init (GstSrtpDec * filter)
   gst_element_add_pad (GST_ELEMENT (filter), filter->rtcp_srcpad);
 
   filter->first_session = TRUE;
-
-#ifndef HAVE_SRTP2
-  filter->roc_changed = FALSE;
-#endif
 }
 
 static GstStructure *
@@ -780,7 +776,7 @@ init_session_stream (GstSrtpDec * filter, guint32 ssrc,
       /* Here, we just set the ROC, but we also need to set the initial
        * RTP sequence number later, otherwise libsrtp will not be able
        * to get the right packet index. */
-      filter->roc_changed = TRUE;
+      g_hash_table_add (filter->streams_roc_changed, GUINT_TO_POINTER (ssrc));
     }
 #endif
 
@@ -1353,7 +1349,8 @@ unprotect:
 #ifndef HAVE_SRTP2
     /* If ROC has changed, we know we need to set the initial RTP
      * sequence number too. */
-    if (filter->roc_changed) {
+    if (g_hash_table_contains (filter->streams_roc_changed,
+            GUINT_TO_POINTER (ssrc))) {
       srtp_stream_t stream;
 
       stream = srtp_get_stream (filter->session, htonl (ssrc));
@@ -1373,7 +1370,8 @@ unprotect:
         stream->rtp_rdbx.index |= seqnum;
       }
 
-      filter->roc_changed = FALSE;
+      g_hash_table_remove (filter->streams_roc_changed,
+          GUINT_TO_POINTER (ssrc));
     }
 #endif
 
@@ -1527,6 +1525,12 @@ gst_srtp_dec_change_state (GstElement * element, GstStateChange transition)
     case GST_STATE_CHANGE_READY_TO_PAUSED:
       filter->streams = g_hash_table_new_full (g_direct_hash, g_direct_equal,
           NULL, (GDestroyNotify) free_stream);
+
+#ifndef HAVE_SRTP2
+      filter->streams_roc_changed =
+          g_hash_table_new (g_direct_hash, g_direct_equal);
+#endif
+
       filter->rtp_has_segment = FALSE;
       filter->rtcp_has_segment = FALSE;
       break;
@@ -1548,6 +1552,12 @@ gst_srtp_dec_change_state (GstElement * element, GstStateChange transition)
       gst_srtp_dec_clear_streams (filter);
       g_hash_table_unref (filter->streams);
       filter->streams = NULL;
+
+#ifndef HAVE_SRTP2
+      g_hash_table_unref (filter->streams_roc_changed);
+      filter->streams_roc_changed = NULL;
+#endif
+
       break;
     case GST_STATE_CHANGE_READY_TO_NULL:
       break;
index f26435a434cc2cfa3f5c8cc1f6807b440fb1ed76..ba8bcff58bcd497c21f45835482fb23a574a4b1f 100644 (file)
@@ -84,7 +84,7 @@ struct _GstSrtpDec
   gboolean rtcp_has_segment;
 
 #ifndef HAVE_SRTP2
-  gboolean roc_changed;
+  GHashTable *streams_roc_changed;
 #endif
 };