From fc0f6db85617effcb47ce85f152ed0b5a552e1b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Cr=C3=AAte?= Date: Fri, 9 Oct 2020 18:45:57 -0400 Subject: [PATCH] webrtcbin: Store the rtpjitterbuffer instances to extract stats from them 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: --- ext/webrtc/gstwebrtcbin.c | 20 ++++++++++++++++++-- ext/webrtc/transportstream.c | 7 +++++++ ext/webrtc/transportstream.h | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ext/webrtc/gstwebrtcbin.c b/ext/webrtc/gstwebrtcbin.c index b5e53a1..3bb4ad4 100644 --- a/ext/webrtc/gstwebrtcbin.c +++ b/ext/webrtc/gstwebrtcbin.c @@ -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 (); } diff --git a/ext/webrtc/transportstream.c b/ext/webrtc/transportstream.c index 73a551d..67d4bee 100644 --- a/ext/webrtc/transportstream.c +++ b/ext/webrtc/transportstream.c @@ -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 * diff --git a/ext/webrtc/transportstream.h b/ext/webrtc/transportstream.h index 939b6e8..f5cf8c2 100644 --- a/ext/webrtc/transportstream.h +++ b/ext/webrtc/transportstream.h @@ -41,6 +41,7 @@ typedef struct { guint32 ssrc; guint media_idx; + GWeakRef rtpjitterbuffer; /* for stats */ } SsrcMapItem; struct _TransportStream -- 2.7.4