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>
This commit is contained in:
Chris Ayoup 2020-04-17 18:00:59 +00:00 committed by GStreamer Merge Bot
parent 3fc8818824
commit ca754245e9
3 changed files with 54 additions and 5 deletions

View file

@ -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,
};
@ -5025,6 +5025,18 @@ gst_webrtc_bin_add_turn_server (GstWebRTCBin * webrtc, const gchar * uri)
return gst_webrtc_ice_add_turn_server (webrtc->priv->ice, 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)
{
@ -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

View file

@ -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)
@ -670,6 +670,28 @@ done:
return ret;
}
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)

View file

@ -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__ */