From 4bf62c788cf3e60848d0dd5903afb2f2b992db5f Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Sat, 30 Jul 2022 17:28:41 +0100 Subject: [PATCH] webrtc: nice: WeakRef access fixes The GstWebRTCNiceStream::ice property getter already hands-off a full reference, so there is no need to call g_weak_ref_get() in call sites. Fixes #1350 Part-of: --- .../gst-libs/gst/webrtc/nice/nice.c | 8 ++---- .../gst-libs/gst/webrtc/nice/nicestream.c | 12 +++++--- .../gst-libs/gst/webrtc/nice/nicetransport.c | 33 ++++++++++------------ 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nice.c b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nice.c index 4c90836..94b47ba 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nice.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nice.c @@ -1257,15 +1257,13 @@ gst_webrtc_nice_get_selected_pair (GstWebRTCICE * ice, static void _clear_ice_stream (struct NiceStreamItem *item) { - GWeakRef ice_weak; - GstWebRTCNice *ice; + GstWebRTCNice *ice = NULL; + if (!item) return; if (item->stream) { - g_object_get (GST_WEBRTC_NICE_STREAM (item->stream), "ice", &ice_weak, - NULL); - ice = g_weak_ref_get (&ice_weak); + g_object_get (item->stream, "ice", &ice, NULL); if (ice != NULL) { g_signal_handlers_disconnect_by_data (ice->priv->nice_agent, diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nicestream.c b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nicestream.c index b2bde31..a0dc51b 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nicestream.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nicestream.c @@ -179,9 +179,15 @@ weak_free (GWeakRef * weak) static void gst_webrtc_nice_stream_constructed (GObject * object) { - GstWebRTCNiceStream *stream = GST_WEBRTC_NICE_STREAM (object); + GstWebRTCNiceStream *stream; NiceAgent *agent; - GstWebRTCNice *ice = g_weak_ref_get (&stream->priv->ice_weak); + GstWebRTCNice *ice; + + G_OBJECT_CLASS (parent_class)->constructed (object); + + stream = GST_WEBRTC_NICE_STREAM (object); + ice = g_weak_ref_get (&stream->priv->ice_weak); + g_assert (ice != NULL); g_object_get (ice, "agent", &agent, NULL); @@ -191,8 +197,6 @@ gst_webrtc_nice_stream_constructed (GObject * object) g_object_unref (agent); gst_object_unref (ice); - - G_OBJECT_CLASS (parent_class)->constructed (object); } static gboolean diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nicetransport.c b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nicetransport.c index 300a3d0..13030d0 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nicetransport.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nicetransport.c @@ -163,11 +163,9 @@ gst_webrtc_nice_transport_finalize (GObject * object) { GstWebRTCNiceTransport *nice = GST_WEBRTC_NICE_TRANSPORT (object); NiceAgent *agent; - GstWebRTCNice *webrtc_ice; + GstWebRTCNice *webrtc_ice = NULL; - GWeakRef ice_weak; - g_object_get (GST_WEBRTC_NICE_STREAM (nice->stream), "ice", &ice_weak, NULL); - webrtc_ice = g_weak_ref_get (&ice_weak); + g_object_get (nice->stream, "ice", &webrtc_ice, NULL); if (webrtc_ice) { g_object_get (webrtc_ice, "agent", &agent, NULL); @@ -196,11 +194,9 @@ gst_webrtc_nice_transport_update_buffer_size (GstWebRTCNiceTransport * nice) NiceAgent *agent = NULL; GPtrArray *sockets; guint i; - GstWebRTCNice *webrtc_ice; + GstWebRTCNice *webrtc_ice = NULL; - GWeakRef ice_weak; - g_object_get (GST_WEBRTC_NICE_STREAM (nice->stream), "ice", &ice_weak, NULL); - webrtc_ice = g_weak_ref_get (&ice_weak); + g_object_get (nice->stream, "ice", &webrtc_ice, NULL); g_assert (webrtc_ice != NULL); @@ -322,20 +318,23 @@ weak_free (GWeakRef * weak) static void gst_webrtc_nice_transport_constructed (GObject * object) { - GstWebRTCNiceTransport *nice = GST_WEBRTC_NICE_TRANSPORT (object); - GstWebRTCICETransport *ice = GST_WEBRTC_ICE_TRANSPORT (object); - NiceComponentType component = _gst_component_to_nice (ice->component); + GstWebRTCNiceTransport *nice; + GstWebRTCICETransport *ice; + NiceComponentType component; gboolean controlling_mode; guint our_stream_id; NiceAgent *agent; - GstWebRTCNice *webrtc_ice; + GstWebRTCNice *webrtc_ice = NULL; + + G_OBJECT_CLASS (parent_class)->constructed (object); - GWeakRef ice_weak; - g_object_get (GST_WEBRTC_NICE_STREAM (nice->stream), "ice", &ice_weak, NULL); - webrtc_ice = g_weak_ref_get (&ice_weak); + nice = GST_WEBRTC_NICE_TRANSPORT (object); + ice = GST_WEBRTC_ICE_TRANSPORT (object); + component = _gst_component_to_nice (ice->component); + g_object_get (nice->stream, "ice", &webrtc_ice, "stream-id", &our_stream_id, + NULL); g_assert (webrtc_ice != NULL); - g_object_get (nice->stream, "stream-id", &our_stream_id, NULL); g_object_get (webrtc_ice, "agent", &agent, NULL); g_object_get (agent, "controlling-mode", &controlling_mode, NULL); @@ -364,8 +363,6 @@ gst_webrtc_nice_transport_constructed (GObject * object) g_object_unref (agent); gst_object_unref (webrtc_ice); - - G_OBJECT_CLASS (parent_class)->constructed (object); } static void -- 2.7.4