From: Olivier CrĂȘte Date: Fri, 20 Nov 2020 22:32:44 +0000 (-0500) Subject: webrtc: Make ssrc map into separate data structures X-Git-Tag: submit/tizen/20210824.072619^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6a45a513416f385bd53c97745022453822b06cba;p=platform%2Fupstream%2Fgst-plugins-bad.git webrtc: Make ssrc map into separate data structures They now contain a weak reference and that could be freed later causing strange crashes as GWeakRef are not movable. Change-Id: I3a5f4ee907bbaac48b25747f76f5d3abb7e3a1f6 Part-of: --- diff --git a/ext/webrtc/gstwebrtcbin.c b/ext/webrtc/gstwebrtcbin.c index 4ec503a0d..a3b08717b 100644 --- a/ext/webrtc/gstwebrtcbin.c +++ b/ext/webrtc/gstwebrtcbin.c @@ -4886,16 +4886,7 @@ _set_description_task (GstWebRTCBin * webrtc, struct set_description *sd) if (split[0] && sscanf (split[0], "%u", &ssrc) && split[1] && g_str_has_prefix (split[1], "cname:")) { - SsrcMapItem ssrc_item; - - 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_ptr_array_add (item->remote_ssrcmap, ssrcmap_item_new (ssrc, i)); } g_strfreev (split); } @@ -5527,8 +5518,7 @@ on_rtpbin_pad_added (GstElement * rtpbin, GstPad * new_pad, media_idx = session_id; for (i = 0; i < stream->remote_ssrcmap->len; i++) { - SsrcMapItem *item = - &g_array_index (stream->remote_ssrcmap, SsrcMapItem, i); + SsrcMapItem *item = g_ptr_array_index (stream->remote_ssrcmap, i); if (item->ssrc == ssrc) { media_idx = item->media_idx; found_ssrc = TRUE; @@ -5987,8 +5977,7 @@ on_rtpbin_new_jitterbuffer (GstElement * rtpbin, GstElement * jitterbuffer, 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); + SsrcMapItem *item = g_ptr_array_index (trans->stream->remote_ssrcmap, i); if (item->ssrc == ssrc) { g_weak_ref_set (&item->rtpjitterbuffer, jitterbuffer); diff --git a/ext/webrtc/gstwebrtcstats.c b/ext/webrtc/gstwebrtcstats.c index a901be20c..e42ded48a 100644 --- a/ext/webrtc/gstwebrtcstats.c +++ b/ext/webrtc/gstwebrtcstats.c @@ -318,8 +318,7 @@ _get_stats_from_rtp_source_stats (GstWebRTCBin * webrtc, gst_structure_get (source_stats, "have-sr", G_TYPE_BOOLEAN, &have_sr, NULL); for (i = 0; i < stream->remote_ssrcmap->len; i++) { - SsrcMapItem *item = - &g_array_index (stream->remote_ssrcmap, SsrcMapItem, i); + SsrcMapItem *item = g_ptr_array_index (stream->remote_ssrcmap, i); if (item->ssrc == ssrc) { GObject *jb = g_weak_ref_get (&item->rtpjitterbuffer); diff --git a/ext/webrtc/transportstream.c b/ext/webrtc/transportstream.c index 935275ab2..c08bfc056 100644 --- a/ext/webrtc/transportstream.c +++ b/ext/webrtc/transportstream.c @@ -190,7 +190,7 @@ transport_stream_finalize (GObject * object) TransportStream *stream = TRANSPORT_STREAM (object); g_array_free (stream->ptmap, TRUE); - g_array_free (stream->remote_ssrcmap, TRUE); + g_ptr_array_free (stream->remote_ssrcmap, TRUE); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -276,10 +276,24 @@ clear_ptmap_item (PtMapItem * item) if (item->caps) gst_caps_unref (item->caps); } + +SsrcMapItem * +ssrcmap_item_new (guint32 ssrc, guint media_idx) +{ + SsrcMapItem *ssrc_item = g_slice_new (SsrcMapItem); + + ssrc_item->media_idx = media_idx; + ssrc_item->ssrc = ssrc; + g_weak_ref_init (&ssrc_item->rtpjitterbuffer, NULL); + + return ssrc_item; +} + static void -clear_ssrcmap_item (SsrcMapItem * item) +ssrcmap_item_free (SsrcMapItem * item) { g_weak_ref_clear (&item->rtpjitterbuffer); + g_slice_free (SsrcMapItem, item); } static void @@ -287,9 +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); + stream->remote_ssrcmap = g_ptr_array_new_with_free_func ( + (GDestroyNotify) ssrcmap_item_free); } TransportStream * diff --git a/ext/webrtc/transportstream.h b/ext/webrtc/transportstream.h index d30943739..4642c9a73 100644 --- a/ext/webrtc/transportstream.h +++ b/ext/webrtc/transportstream.h @@ -44,6 +44,9 @@ typedef struct GWeakRef rtpjitterbuffer; /* for stats */ } SsrcMapItem; +SsrcMapItem * ssrcmap_item_new (guint32 ssrc, + guint media_idx); + struct _TransportStream { GstObject parent; @@ -58,7 +61,7 @@ struct _TransportStream GstWebRTCDTLSTransport *transport; GArray *ptmap; /* array of PtMapItem's */ - GArray *remote_ssrcmap; /* array of SsrcMapItem's */ + GPtrArray *remote_ssrcmap; /* array of SsrcMapItem's */ gboolean output_connected; /* whether receive bin is connected to rtpbin */ GstElement *rtxsend;