diff options
author | Chris Ayoup <ayochris@amazon.com> | 2020-04-17 18:00:59 +0000 |
---|---|---|
committer | GStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org> | 2020-05-11 05:30:59 +0000 |
commit | ca754245e9952c492eac445f680eee4eb49c43d2 (patch) | |
tree | 4fe6bb3b4e4e821008727ef3b7b2b423be4acef2 /ext | |
parent | 3fc8818824ffc10cc2cf10c35930a8c86c144325 (diff) | |
download | gstreamer-plugins-bad-ca754245e9952c492eac445f680eee4eb49c43d2.tar.gz |
webrtc: allow setting local IP addresses
If a local IP address is specified, ICE gathering can be much faster
in environments where there are multiple IP addreses but only some are
usable (for example, if you are running docker on the machine).
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1223>
Diffstat (limited to 'ext')
-rw-r--r-- | ext/webrtc/gstwebrtcbin.c | 30 | ||||
-rw-r--r-- | ext/webrtc/gstwebrtcice.c | 26 | ||||
-rw-r--r-- | ext/webrtc/gstwebrtcice.h | 3 |
3 files changed, 54 insertions, 5 deletions
diff --git a/ext/webrtc/gstwebrtcbin.c b/ext/webrtc/gstwebrtcbin.c index 6c6d5e62d..02606baa1 100644 --- a/ext/webrtc/gstwebrtcbin.c +++ b/ext/webrtc/gstwebrtcbin.c @@ -325,8 +325,7 @@ gst_webrtc_bin_pad_new (const gchar * name, GstPadDirection direction) G_DEFINE_TYPE_WITH_CODE (GstWebRTCBin, gst_webrtc_bin, GST_TYPE_BIN, G_ADD_PRIVATE (GstWebRTCBin) GST_DEBUG_CATEGORY_INIT (gst_webrtc_bin_debug, "webrtcbin", 0, - "webrtcbin element"); - ); + "webrtcbin element");); static GstPad *_connect_input_stream (GstWebRTCBin * webrtc, GstWebRTCBinPad * pad); @@ -349,6 +348,7 @@ enum ADD_TURN_SERVER_SIGNAL, CREATE_DATA_CHANNEL_SIGNAL, ON_DATA_CHANNEL_SIGNAL, + ADD_LOCAL_IP_ADDRESS_SIGNAL, LAST_SIGNAL, }; @@ -5026,6 +5026,18 @@ gst_webrtc_bin_add_turn_server (GstWebRTCBin * webrtc, const gchar * uri) } static gboolean +gst_webrtc_bin_add_local_ip_address (GstWebRTCBin * webrtc, + const gchar * address) +{ + g_return_val_if_fail (GST_IS_WEBRTC_BIN (webrtc), FALSE); + g_return_val_if_fail (address != NULL, FALSE); + + GST_DEBUG_OBJECT (webrtc, "Adding local IP address: %s", address); + + return gst_webrtc_ice_add_local_ip_address (webrtc->priv->ice, address); +} + +static gboolean copy_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data) { GstPad *gpad = GST_PAD_CAST (user_data); @@ -6426,6 +6438,20 @@ gst_webrtc_bin_class_init (GstWebRTCBinClass * klass) G_CALLBACK (gst_webrtc_bin_add_turn_server), NULL, NULL, NULL, G_TYPE_BOOLEAN, 1, G_TYPE_STRING); + /** + * GstWebRTCBin::add-local-ip-address: + * @object: the #GstWebRtcBin + * @address: The local IP address + * + * Add a local IP address to use for ICE candidate gathering. If none + * are supplied, they will be discovered automatically + */ + gst_webrtc_bin_signals[ADD_LOCAL_IP_ADDRESS_SIGNAL] = + g_signal_new_class_handler ("add-local-ip-address", + G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_CALLBACK (gst_webrtc_bin_add_local_ip_address), NULL, NULL, + g_cclosure_marshal_generic, G_TYPE_BOOLEAN, 1, G_TYPE_STRING); + /* * GstWebRTCBin::create-data-channel: * @object: the #GstWebRTCBin diff --git a/ext/webrtc/gstwebrtcice.c b/ext/webrtc/gstwebrtcice.c index 7d96a880f..0b6da0d91 100644 --- a/ext/webrtc/gstwebrtcice.c +++ b/ext/webrtc/gstwebrtcice.c @@ -82,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) @@ -671,6 +671,28 @@ done: } gboolean +gst_webrtc_ice_add_local_ip_address (GstWebRTCICE * ice, const gchar * address) +{ + gboolean ret = FALSE; + NiceAddress nice_addr; + + nice_address_init (&nice_addr); + + ret = nice_address_set_from_string (&nice_addr, address); + + if (ret) { + ret = nice_agent_add_local_address (ice->priv->nice_agent, &nice_addr); + if (!ret) { + GST_ERROR_OBJECT (ice, "Failed to add local address to NiceAgent"); + } + } else { + GST_ERROR_OBJECT (ice, "Failed to initialize NiceAddress [%s]", address); + } + + return ret; +} + +gboolean gst_webrtc_ice_set_local_credentials (GstWebRTCICE * ice, GstWebRTCICEStream * stream, gchar * ufrag, gchar * pwd) { diff --git a/ext/webrtc/gstwebrtcice.h b/ext/webrtc/gstwebrtcice.h index 5551c51fd..4146b41c4 100644 --- a/ext/webrtc/gstwebrtcice.h +++ b/ext/webrtc/gstwebrtcice.h @@ -81,7 +81,8 @@ gboolean gst_webrtc_ice_set_remote_credentials (GstWebRTCIC gchar * pwd); gboolean gst_webrtc_ice_add_turn_server (GstWebRTCICE * ice, const gchar * uri); - +gboolean gst_webrtc_ice_add_local_ip_address (GstWebRTCICE * ice, + const gchar * address); G_END_DECLS #endif /* __GST_WEBRTC_ICE_H__ */ |