From cf96d96f6a88683a5784b63ee8daa4857e72f655 Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Tue, 14 Feb 2023 16:25:15 +0000 Subject: [PATCH] webrtcbin: Add add-ice-candidate-full signal The signal triggers an asynchronous task on the PC thread but in some cases it can be useful for apps to be notified when the task completed. This method of the PeerConnection spec also returns a Promise so the interface is now more coherent with the spec. Part-of: --- .../docs/plugins/gst_plugins_cache.json | 19 +++++++++ .../gst-plugins-bad/ext/webrtc/gstwebrtcbin.c | 39 +++++++++++++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json b/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json index 72906b0468..e3b36faf57 100644 --- a/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json +++ b/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json @@ -237209,6 +237209,25 @@ "return-type": "void", "when": "last" }, + "add-ice-candidate-full": { + "action": true, + "args": [ + { + "name": "arg0", + "type": "guint" + }, + { + "name": "arg1", + "type": "gchararray" + }, + { + "name": "arg2", + "type": "GstPromise" + } + ], + "return-type": "void", + "when": "last" + }, "add-transceiver": { "action": true, "args": [ diff --git a/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c b/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c index 6a8f722364..fba63d1807 100644 --- a/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c +++ b/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c @@ -650,6 +650,7 @@ enum ON_DATA_CHANNEL_SIGNAL, PREPARE_DATA_CHANNEL_SIGNAL, REQUEST_AUX_SENDER, + ADD_ICE_CANDIDATE_FULL_SIGNAL, LAST_SIGNAL, }; @@ -6787,7 +6788,7 @@ _free_ice_candidate_item (IceCandidateItem * item) static void gst_webrtc_bin_add_ice_candidate (GstWebRTCBin * webrtc, guint mline, - const gchar * attr) + const gchar * attr, GstPromise * promise) { IceCandidateItem *item; @@ -6799,9 +6800,19 @@ gst_webrtc_bin_add_ice_candidate (GstWebRTCBin * webrtc, guint mline, else if (!g_ascii_strncasecmp (attr, "candidate:", 10)) item->candidate = g_strdup_printf ("a=%s", attr); } - gst_webrtc_bin_enqueue_task (webrtc, - (GstWebRTCBinFunc) _add_ice_candidate_task, item, - (GDestroyNotify) _free_ice_candidate_item, NULL); + if (!gst_webrtc_bin_enqueue_task (webrtc, + (GstWebRTCBinFunc) _add_ice_candidate_task, item, + (GDestroyNotify) _free_ice_candidate_item, promise)) { + GError *error = + g_error_new (GST_WEBRTC_ERROR, GST_WEBRTC_ERROR_INVALID_STATE, + "Could not add ICE candidate. webrtcbin is closed"); + GstStructure *s = gst_structure_new ("application/x-gst-promise", "error", + G_TYPE_ERROR, error, NULL); + + gst_promise_reply (promise, s); + + g_clear_error (&error); + } } static GstStructure * @@ -8710,6 +8721,26 @@ gst_webrtc_bin_class_init (GstWebRTCBinClass * klass) G_CALLBACK (gst_webrtc_bin_add_ice_candidate), NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING); + /** + * GstWebRTCBin::add-ice-candidate-full: + * @object: the #webrtcbin + * @mline_index: the index of the media description in the SDP + * @ice-candidate: an ice candidate or NULL/"" to mark that no more candidates + * will arrive + * @promise: (nullable): a #GstPromise to be notified when the task is + * complete + * + * Variant of the `add-ice-candidate` signal, allowing the call site to be + * notified using a #GstPromise when the task has completed. + * + * Since: 1.24 + */ + gst_webrtc_bin_signals[ADD_ICE_CANDIDATE_FULL_SIGNAL] = + g_signal_new_class_handler ("add-ice-candidate-full", + G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_CALLBACK (gst_webrtc_bin_add_ice_candidate), NULL, NULL, NULL, + G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, GST_TYPE_PROMISE); + /** * GstWebRTCBin::get-stats: * @object: the #webrtcbin