From 913383166b675c9d46d892d19075c6fcfe094789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Wed, 31 Mar 2021 11:56:10 -0400 Subject: [PATCH] webrtcbin: Take PC lock around all entry points All of those action signals change the internal state, so protect it by using the PC_LOCK Part-of: --- ext/webrtc/gstwebrtcbin.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ext/webrtc/gstwebrtcbin.c b/ext/webrtc/gstwebrtcbin.c index 927badc095..3041294652 100644 --- a/ext/webrtc/gstwebrtcbin.c +++ b/ext/webrtc/gstwebrtcbin.c @@ -5508,6 +5508,8 @@ gst_webrtc_bin_add_transceiver (GstWebRTCBin * webrtc, g_return_val_if_fail (direction != GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_NONE, NULL); + PC_LOCK (webrtc); + trans = _create_webrtc_transceiver (webrtc, direction, -1); GST_LOG_OBJECT (webrtc, "Created new unassociated transceiver %" GST_PTR_FORMAT, trans); @@ -5518,6 +5520,8 @@ gst_webrtc_bin_add_transceiver (GstWebRTCBin * webrtc, _update_transceiver_kind_from_caps (rtp_trans, caps); } + PC_UNLOCK (webrtc); + return gst_object_ref (trans); } @@ -5533,6 +5537,8 @@ gst_webrtc_bin_get_transceivers (GstWebRTCBin * webrtc) GArray *arr = g_array_new (FALSE, TRUE, sizeof (GstWebRTCRTPTransceiver *)); int i; + PC_LOCK (webrtc); + g_array_set_clear_func (arr, (GDestroyNotify) _deref_and_unref); for (i = 0; i < webrtc->priv->transceivers->len; i++) { @@ -5541,6 +5547,7 @@ gst_webrtc_bin_get_transceivers (GstWebRTCBin * webrtc) gst_object_ref (trans); g_array_append_val (arr, trans); } + PC_UNLOCK (webrtc); return arr; } @@ -5550,6 +5557,8 @@ gst_webrtc_bin_get_transceiver (GstWebRTCBin * webrtc, guint idx) { GstWebRTCRTPTransceiver *trans = NULL; + PC_LOCK (webrtc); + if (idx >= webrtc->priv->transceivers->len) { GST_ERROR_OBJECT (webrtc, "No transceiver for idx %d", idx); goto done; @@ -5559,18 +5568,25 @@ gst_webrtc_bin_get_transceiver (GstWebRTCBin * webrtc, guint idx) gst_object_ref (trans); done: + PC_UNLOCK (webrtc); return trans; } static gboolean gst_webrtc_bin_add_turn_server (GstWebRTCBin * webrtc, const gchar * uri) { + gboolean ret; + g_return_val_if_fail (GST_IS_WEBRTC_BIN (webrtc), FALSE); g_return_val_if_fail (uri != NULL, FALSE); GST_DEBUG_OBJECT (webrtc, "Adding turn server: %s", uri); - return gst_webrtc_ice_add_turn_server (webrtc->priv->ice, uri); + PC_LOCK (webrtc); + ret = gst_webrtc_ice_add_turn_server (webrtc->priv->ice, uri); + PC_UNLOCK (webrtc); + + return ret; } static gboolean