webrtcbin: support adding TURN servers after pipeline start

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/issues/1680

When a TURN server is added for the first time, propagate
the change to all nice streams that already exist. This
lets us add servers after the pipeline has been started
(and streams have been added).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3217>
This commit is contained in:
Alba Mendez 2022-10-18 11:16:20 +02:00 committed by GStreamer Marge Bot
parent 698503f5a7
commit 4810008afa

View file

@ -932,17 +932,43 @@ gst_webrtc_nice_set_remote_credentials (GstWebRTCICE * ice,
return TRUE;
}
typedef struct
{
GstWebRTCNice *ice;
GstUri *turn_server;
} AddTurnServerToStreamData;
static gboolean
_add_turn_server_foreach_stream_func (struct NiceStreamItem *item,
gpointer data)
{
AddTurnServerToStreamData *add_data = (AddTurnServerToStreamData *) data;
_add_turn_server (add_data->ice, item, add_data->turn_server);
return TRUE;
}
static gboolean
gst_webrtc_nice_add_turn_server (GstWebRTCICE * ice, const gchar * uri)
{
gboolean ret = FALSE;
GstUri *valid_uri;
GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
gboolean inserted;
AddTurnServerToStreamData add_data;
if (!(valid_uri = _validate_turn_server (nice, uri)))
goto done;
g_hash_table_insert (nice->priv->turn_servers, g_strdup (uri), valid_uri);
inserted =
g_hash_table_insert (nice->priv->turn_servers, g_strdup (uri), valid_uri);
/* add the turn server to any streams that were already created */
if (inserted) {
add_data.ice = nice;
add_data.turn_server = valid_uri;
_nice_stream_item_foreach (nice, _add_turn_server_foreach_stream_func,
&add_data);
}
ret = TRUE;