webrtcbin: Store the rtpjitterbuffer instances to extract stats from them
authorOlivier CrĂȘte <olivier.crete@collabora.com>
Fri, 9 Oct 2020 22:45:57 +0000 (18:45 -0400)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 24 Nov 2020 04:27:52 +0000 (04:27 +0000)
Store them as web refs to avoid having to worry about freeing later and because
the new-jitterbuffer is on a different thread

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1766>

ext/webrtc/gstwebrtcbin.c
ext/webrtc/transportstream.c
ext/webrtc/transportstream.h

index b5e53a1..3bb4ad4 100644 (file)
@@ -4888,6 +4888,11 @@ _set_description_task (GstWebRTCBin * webrtc, struct set_description *sd)
             ssrc_item.media_idx = i;
             ssrc_item.ssrc = ssrc;
             g_array_append_val (item->remote_ssrcmap, ssrc_item);
+
+            /* Must be done aftrer the value has been appended because
+             * a weak ref cannot be moved. */
+            g_weak_ref_init (&g_array_index (item->remote_ssrcmap, SsrcMapItem,
+                    item->remote_ssrcmap->len - 1).rtpjitterbuffer, NULL);
           }
           g_strfreev (split);
         }
@@ -5981,15 +5986,26 @@ static void
 on_rtpbin_new_jitterbuffer (GstElement * rtpbin, GstElement * jitterbuffer,
     guint session_id, guint ssrc, GstWebRTCBin * webrtc)
 {
-  GstWebRTCRTPTransceiver *trans;
+  WebRTCTransceiver *trans;
+  guint i;
 
-  trans = _find_transceiver (webrtc, &session_id,
+  trans = (WebRTCTransceiver *) _find_transceiver (webrtc, &session_id,
       (FindTransceiverFunc) transceiver_match_for_mline);
 
   if (trans) {
     /* We don't set do-retransmission on rtpbin as we want per-session control */
     g_object_set (jitterbuffer, "do-retransmission",
         WEBRTC_TRANSCEIVER (trans)->do_nack, NULL);
+
+    for (i = 0; i < trans->stream->remote_ssrcmap->len; i++) {
+      SsrcMapItem *item =
+          &g_array_index (trans->stream->remote_ssrcmap, SsrcMapItem, i);
+
+      if (item->ssrc == ssrc) {
+        g_weak_ref_set (&item->rtpjitterbuffer, jitterbuffer);
+        break;
+      }
+    }
   } else {
     g_assert_not_reached ();
   }
index 73a551d..67d4bee 100644 (file)
@@ -289,6 +289,11 @@ clear_ptmap_item (PtMapItem * item)
   if (item->caps)
     gst_caps_unref (item->caps);
 }
+static void
+clear_ssrcmap_item (SsrcMapItem * item)
+{
+  g_weak_ref_clear (&item->rtpjitterbuffer);
+}
 
 static void
 transport_stream_init (TransportStream * stream)
@@ -296,6 +301,8 @@ transport_stream_init (TransportStream * stream)
   stream->ptmap = g_array_new (FALSE, TRUE, sizeof (PtMapItem));
   g_array_set_clear_func (stream->ptmap, (GDestroyNotify) clear_ptmap_item);
   stream->remote_ssrcmap = g_array_new (FALSE, TRUE, sizeof (SsrcMapItem));
+  g_array_set_clear_func (stream->remote_ssrcmap,
+      (GDestroyNotify) clear_ssrcmap_item);
 }
 
 TransportStream *
index 939b6e8..f5cf8c2 100644 (file)
@@ -41,6 +41,7 @@ typedef struct
 {
   guint32 ssrc;
   guint media_idx;
+  GWeakRef rtpjitterbuffer; /* for stats */
 } SsrcMapItem;
 
 struct _TransportStream