From 3fc8818824ffc10cc2cf10c35930a8c86c144325 Mon Sep 17 00:00:00 2001 From: Chris Ayoup Date: Thu, 16 Apr 2020 22:37:35 +0000 Subject: [PATCH] webrtc: Allow toggling TCP and UDP candidates Add some properties to allow TCP and UDP candidates to be toggled. This is useful in cases where someone is using this element in an environment where it is known in advance whether a given transport will work or not and will prevent wasting time generating and checking candidate pairs that will not succeed. Part-of: --- ext/webrtc/gstwebrtcbin.c | 18 ++++++++++++++++++ ext/webrtc/gstwebrtcice.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/ext/webrtc/gstwebrtcbin.c b/ext/webrtc/gstwebrtcbin.c index 9e190c4f9a..6c6d5e62df 100644 --- a/ext/webrtc/gstwebrtcbin.c +++ b/ext/webrtc/gstwebrtcbin.c @@ -369,6 +369,8 @@ enum PROP_TURN_SERVER, PROP_BUNDLE_POLICY, PROP_ICE_TRANSPORT_POLICY, + PROP_ICE_TCP, + PROP_ICE_UDP, }; static guint gst_webrtc_bin_signals[LAST_SIGNAL] = { 0 }; @@ -5838,6 +5840,8 @@ gst_webrtc_bin_set_property (GObject * object, guint prop_id, switch (prop_id) { case PROP_STUN_SERVER: case PROP_TURN_SERVER: + case PROP_ICE_TCP: + case PROP_ICE_UDP: g_object_set_property (G_OBJECT (webrtc->priv->ice), pspec->name, value); break; case PROP_BUNDLE_POLICY: @@ -5909,6 +5913,8 @@ gst_webrtc_bin_get_property (GObject * object, guint prop_id, break; case PROP_STUN_SERVER: case PROP_TURN_SERVER: + case PROP_ICE_TCP: + case PROP_ICE_UDP: g_object_get_property (G_OBJECT (webrtc->priv->ice), pspec->name, value); break; case PROP_BUNDLE_POLICY: @@ -6179,6 +6185,18 @@ gst_webrtc_bin_class_init (GstWebRTCBinClass * klass) GST_WEBRTC_ICE_TRANSPORT_POLICY_ALL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (gobject_class, + PROP_ICE_TCP, + g_param_spec_boolean ("ice-tcp", "ICE TCP", + "Whether the agent should use ICE-TCP when gathering candidates", + TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (gobject_class, + PROP_ICE_UDP, + g_param_spec_boolean ("ice-udp", "ICE UDP", + "Whether the agent should use ICE-UDP when gathering candidates", + TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + /** * GstWebRTCBin::create-offer: * @object: the #webrtcbin diff --git a/ext/webrtc/gstwebrtcice.c b/ext/webrtc/gstwebrtcice.c index f6628ba3d2..7d96a880f0 100644 --- a/ext/webrtc/gstwebrtcice.c +++ b/ext/webrtc/gstwebrtcice.c @@ -60,6 +60,8 @@ enum PROP_CONTROLLER, PROP_AGENT, PROP_FORCE_RELAY, + PROP_ICE_TCP, + PROP_ICE_UDP, }; static guint gst_webrtc_ice_signals[LAST_SIGNAL] = { 0 }; @@ -80,8 +82,8 @@ struct _GstWebRTCICEPrivate #define gst_webrtc_ice_parent_class parent_class G_DEFINE_TYPE_WITH_CODE (GstWebRTCICE, gst_webrtc_ice, GST_TYPE_OBJECT, G_ADD_PRIVATE (GstWebRTCICE) - GST_DEBUG_CATEGORY_INIT (gst_webrtc_ice_debug, "webrtcice", 0, - "webrtcice");); + GST_DEBUG_CATEGORY_INIT (gst_webrtc_ice_debug, "webrtcice", 0, "webrtcice"); + ); static gboolean _unlock_pc_thread (GMutex * lock) @@ -833,6 +835,14 @@ gst_webrtc_ice_set_property (GObject * object, guint prop_id, g_object_set_property (G_OBJECT (ice->priv->nice_agent), "force-relay", value); break; + case PROP_ICE_TCP: + g_object_set_property (G_OBJECT (ice->priv->nice_agent), + "ice-tcp", value); + break; + case PROP_ICE_UDP: + g_object_set_property (G_OBJECT (ice->priv->nice_agent), + "ice-udp", value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -869,6 +879,14 @@ gst_webrtc_ice_get_property (GObject * object, guint prop_id, g_object_get_property (G_OBJECT (ice->priv->nice_agent), "force-relay", value); break; + case PROP_ICE_TCP: + g_object_get_property (G_OBJECT (ice->priv->nice_agent), + "ice-tcp", value); + break; + case PROP_ICE_UDP: + g_object_get_property (G_OBJECT (ice->priv->nice_agent), + "ice-udp", value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -957,6 +975,18 @@ gst_webrtc_ice_class_init (GstWebRTCICEClass * klass) "Force all traffic to go through a relay.", FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (gobject_class, + PROP_ICE_TCP, + g_param_spec_boolean ("ice-tcp", "ICE TCP", + "Whether the agent should use ICE-TCP when gathering candidates", + TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (gobject_class, + PROP_ICE_UDP, + g_param_spec_boolean ("ice-udp", "ICE UDP", + "Whether the agent should use ICE-UDP when gathering candidates", + TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + /** * GstWebRTCICE::on-ice-candidate: * @object: the #GstWebRTCBin