Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Add niceAgentIceTcp configuration option and API methods for it #26

Merged
merged 4 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/gst-plugins/webrtcendpoint/kmswebrtcbaseconnection.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,17 @@ kms_webrtc_base_connection_set_network_ifs_info (KmsWebRtcBaseConnection *
}
}

void
kms_webrtc_base_connection_set_ice_tcp (KmsWebRtcBaseConnection *self,
gboolean ice_tcp)
{
if (KMS_IS_ICE_NICE_AGENT (self->agent)) {
KmsIceNiceAgent *nice_agent = KMS_ICE_NICE_AGENT (self->agent);
g_object_set (
kms_ice_nice_agent_get_agent (nice_agent), "ice-tcp", ice_tcp, NULL);
}
}

void
kms_webrtc_base_connection_set_stun_server_info (KmsWebRtcBaseConnection * self,
const gchar * ip, guint port)
Expand Down
2 changes: 2 additions & 0 deletions src/gst-plugins/webrtcendpoint/kmswebrtcbaseconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ gchar *kms_webrtc_base_connection_get_certificate_pem (KmsWebRtcBaseConnection *
self);
void kms_webrtc_base_connection_set_network_ifs_info (KmsWebRtcBaseConnection *
self, const gchar * net_names);
void kms_webrtc_base_connection_set_ice_tcp (KmsWebRtcBaseConnection *self,
gboolean ice_tcp);
void kms_webrtc_base_connection_set_stun_server_info (KmsWebRtcBaseConnection * self,
const gchar * stun_server_ip, guint stun_server_port);
void kms_webrtc_base_connection_set_relay_info (KmsWebRtcBaseConnection * self,
Expand Down
22 changes: 21 additions & 1 deletion src/gst-plugins/webrtcendpoint/kmswebrtcendpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ G_DEFINE_TYPE (KmsWebrtcEndpoint, kms_webrtc_endpoint,
#define DEFAULT_EXTERNAL_ADDRESS NULL
#define DEFAULT_EXTERNAL_IPV4 NULL
#define DEFAULT_EXTERNAL_IPV6 NULL
#define DEFAULT_ICE_TCP TRUE

enum
{
Expand All @@ -70,6 +71,7 @@ enum
PROP_EXTERNAL_ADDRESS,
PROP_EXTERNAL_IPV4,
PROP_EXTERNAL_IPV6,
PROP_ICE_TCP,
N_PROPERTIES
};

Expand Down Expand Up @@ -105,6 +107,7 @@ struct _KmsWebrtcEndpointPrivate
gchar *external_address;
gchar *external_ipv4;
gchar *external_ipv6;
gboolean ice_tcp;
};

/* Internal session management begin */
Expand Down Expand Up @@ -339,6 +342,8 @@ kms_webrtc_endpoint_create_session_internal (KmsBaseSdpEndpoint * base_sdp,
webrtc_sess, "external-ipv4", G_BINDING_DEFAULT);
g_object_bind_property (self, "external-ipv6",
webrtc_sess, "external-ipv6", G_BINDING_DEFAULT);
g_object_bind_property (self, "ice-tcp",
webrtc_sess, "ice-tcp", G_BINDING_DEFAULT);

g_object_set (webrtc_sess, "stun-server", self->priv->stun_server_ip,
"stun-server-port", self->priv->stun_server_port,
Expand All @@ -347,7 +352,9 @@ kms_webrtc_endpoint_create_session_internal (KmsBaseSdpEndpoint * base_sdp,
"network-interfaces", self->priv->network_interfaces,
"external-address", self->priv->external_address,
"external-ipv4", self->priv->external_ipv4,
"external-ipv6", self->priv->external_ipv6, NULL);
"external-ipv6", self->priv->external_ipv6,
"ice-tcp", self->priv->ice_tcp,
NULL);

g_signal_connect (webrtc_sess, "on-ice-candidate",
G_CALLBACK (on_ice_candidate), self);
Expand Down Expand Up @@ -531,6 +538,9 @@ kms_webrtc_endpoint_set_property (GObject * object, guint prop_id,
g_free (self->priv->external_ipv6);
self->priv->external_ipv6 = g_value_dup_string (value);
break;
case PROP_ICE_TCP:
self->priv->ice_tcp = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
Expand Down Expand Up @@ -572,6 +582,9 @@ kms_webrtc_endpoint_get_property (GObject * object, guint prop_id,
case PROP_EXTERNAL_IPV6:
g_value_set_string (value, self->priv->external_ipv6);
break;
case PROP_ICE_TCP:
g_value_set_boolean (value, self->priv->ice_tcp);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
Expand Down Expand Up @@ -811,6 +824,12 @@ kms_webrtc_endpoint_class_init (KmsWebrtcEndpointClass * klass)
"External (public) IPv6 address of the media server",
DEFAULT_EXTERNAL_IPV6, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (gobject_class, PROP_ICE_TCP,
g_param_spec_boolean ("ice-tcp",
"iceTcp",
"Enable ICE-TCP candidate gathering",
DEFAULT_ICE_TCP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

/**
* KmsWebrtcEndpoint::on-ice-candidate:
* @self: the object which received the signal
Expand Down Expand Up @@ -947,6 +966,7 @@ kms_webrtc_endpoint_init (KmsWebrtcEndpoint * self)
self->priv->external_address = DEFAULT_EXTERNAL_ADDRESS;
self->priv->external_ipv4 = DEFAULT_EXTERNAL_IPV4;
self->priv->external_ipv6 = DEFAULT_EXTERNAL_IPV6;
self->priv->ice_tcp = DEFAULT_ICE_TCP;

self->priv->loop = kms_loop_new ();
g_object_get (self->priv->loop, "context", &self->priv->context, NULL);
Expand Down
23 changes: 23 additions & 0 deletions src/gst-plugins/webrtcendpoint/kmswebrtcsession.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ G_DEFINE_TYPE (KmsWebrtcSession, kms_webrtc_session, KMS_TYPE_BASE_RTP_SESSION);
#define DEFAULT_EXTERNAL_ADDRESS NULL
#define DEFAULT_EXTERNAL_IPV4 NULL
#define DEFAULT_EXTERNAL_IPV6 NULL
#define DEFAULT_ICE_TCP TRUE

#define IP_VERSION_6 6

Expand Down Expand Up @@ -94,6 +95,7 @@ enum
PROP_EXTERNAL_ADDRESS,
PROP_EXTERNAL_IPV4,
PROP_EXTERNAL_IPV6,
PROP_ICE_TCP,
N_PROPERTIES
};

Expand Down Expand Up @@ -807,6 +809,13 @@ kms_webrtc_session_set_network_ifs_info (KmsWebrtcSession * self,
self->network_interfaces);
}

static void
kms_webrtc_session_set_ice_tcp (KmsWebrtcSession *self,
KmsWebRtcBaseConnection *conn)
{
kms_webrtc_base_connection_set_ice_tcp (conn, self->ice_tcp);
}

static void
kms_webrtc_session_set_stun_server_info (KmsWebrtcSession * self,
KmsWebRtcBaseConnection * conn)
Expand Down Expand Up @@ -846,6 +855,7 @@ kms_webrtc_session_gather_candidates (KmsWebrtcSession * self)
KmsWebRtcBaseConnection *conn = KMS_WEBRTC_BASE_CONNECTION (v);

kms_webrtc_session_set_network_ifs_info (self, conn);
kms_webrtc_session_set_ice_tcp (self, conn);
kms_webrtc_session_set_stun_server_info (self, conn);
kms_webrtc_session_set_relay_info (self, conn);

Expand Down Expand Up @@ -1756,6 +1766,9 @@ kms_webrtc_session_set_property (GObject * object, guint prop_id,
g_free (self->external_ipv6);
self->external_ipv6 = g_value_dup_string (value);
break;
case PROP_ICE_TCP:
self->ice_tcp = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
Expand Down Expand Up @@ -1800,6 +1813,9 @@ kms_webrtc_session_get_property (GObject * object, guint prop_id,
case PROP_EXTERNAL_IPV6:
g_value_set_string (value, self->external_ipv6);
break;
case PROP_ICE_TCP:
g_value_set_boolean (value, self->ice_tcp);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
Expand Down Expand Up @@ -1940,6 +1956,7 @@ kms_webrtc_session_init (KmsWebrtcSession * self)
self->external_address = DEFAULT_EXTERNAL_ADDRESS;
self->external_ipv4= DEFAULT_EXTERNAL_IPV4;
self->external_ipv6 = DEFAULT_EXTERNAL_IPV6;
self->ice_tcp = DEFAULT_ICE_TCP;
self->gather_started = FALSE;

self->data_channels = g_hash_table_new_full (g_direct_hash,
Expand Down Expand Up @@ -2057,6 +2074,12 @@ kms_webrtc_session_class_init (KmsWebrtcSessionClass * klass)
"External (public) IPv6 address of the media server",
DEFAULT_EXTERNAL_IPV6, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (gobject_class, PROP_ICE_TCP,
g_param_spec_boolean ("ice-tcp",
"iceTcp",
"Enable ICE-TCP candidate gathering",
DEFAULT_ICE_TCP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (gobject_class, PROP_DATA_CHANNEL_SUPPORTED,
g_param_spec_boolean ("data-channel-supported",
"Data channel supported",
Expand Down
1 change: 1 addition & 0 deletions src/gst-plugins/webrtcendpoint/kmswebrtcsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct _KmsWebrtcSession
gchar *external_address;
gchar *external_ipv4;
gchar *external_ipv6;
gboolean ice_tcp;

guint16 min_port;
guint16 max_port;
Expand Down
13 changes: 13 additions & 0 deletions src/server/config/WebRtcEndpoint.conf.ini
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,16 @@
;;
;externalAddress=198.51.100.1
;externalAddress=2001:0db8:85a3:0000:0000:8a2e:0370:7334

;; Enable ICE-TCP candidate gathering.
;;
;; This setting enables or disables using TCP for ICE candidate gathering in
;; the underlying libnice library:
;; https://libnice.freedesktop.org/libnice/NiceAgent.html#NiceAgent--ice-tcp
;;
;; You might want to disable ICE-TCP to potentially speed up ICE gathering
;; by avoiding TCP candidates in scenarios where they are not needed.
;;
;; <iceTcp> is either 1 (ON) or 0 (OFF). Default: 1 (ON).
;;
;iceTcp=1
28 changes: 28 additions & 0 deletions src/server/implementation/objects/WebRtcEndpointImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
#define PARAM_EXTERNAL_IPV4 "externalIPv4"
#define PARAM_EXTERNAL_IPV6 "externalIPv6"
#define PARAM_NETWORK_INTERFACES "networkInterfaces"
#define PARAM_ICE_TCP "iceTcp"

#define PROP_EXTERNAL_ADDRESS "external-address"
#define PROP_EXTERNAL_IPV4 "external-ipv4"
#define PROP_EXTERNAL_IPV6 "external-ipv6"
#define PROP_NETWORK_INTERFACES "network-interfaces"
#define PROP_ICE_TCP "ice-tcp"

namespace kurento
{
Expand Down Expand Up @@ -558,6 +560,16 @@ WebRtcEndpointImpl::WebRtcEndpointImpl (const boost::property_tree::ptree &conf,
" you can set one or default to ICE automatic discovery");
}

gboolean iceTcp;
if (getConfigValue<gboolean, WebRtcEndpoint> (&iceTcp, PARAM_ICE_TCP)) {
GST_INFO ("ICE-TCP candidate gathering is %s",
iceTcp ? "ENABLED" : "DISABLED");
g_object_set (G_OBJECT (element), PROP_ICE_TCP, iceTcp, NULL);
} else {
GST_DEBUG ("ICE-TCP option not found in config;"
" you can set one or default to 1 (TRUE)");
}

uint stunPort = 0;

if (!getConfigValue <uint, WebRtcEndpoint> (&stunPort, "stunServerPort",
Expand Down Expand Up @@ -746,6 +758,22 @@ WebRtcEndpointImpl::setNetworkInterfaces (const std::string &networkInterfaces)
networkInterfaces.c_str(), NULL);
}

bool
WebRtcEndpointImpl::getIceTcp ()
{
bool ret;

g_object_get (G_OBJECT (element), "ice-tcp", &ret, NULL);

return ret;
}

void
WebRtcEndpointImpl::setIceTcp (bool iceTcp)
{
g_object_set (G_OBJECT (element), "ice-tcp", iceTcp, NULL);
}

std::string
WebRtcEndpointImpl::getStunServerAddress ()
{
Expand Down
3 changes: 3 additions & 0 deletions src/server/implementation/objects/WebRtcEndpointImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class WebRtcEndpointImpl : public BaseRtpEndpointImpl,
std::string getNetworkInterfaces () override;
void setNetworkInterfaces (const std::string &networkInterfaces) override;

bool getIceTcp () override;
void setIceTcp (bool iceTcp) override;

std::string getStunServerAddress () override;
void setStunServerAddress (const std::string &stunServerAddress) override;

Expand Down
16 changes: 16 additions & 0 deletions src/server/interface/elements.WebRtcEndpoint.kmd.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,22 @@
",
"type": "String"
},
{
"name": "iceTcp",
"doc": "Enable ICE-TCP candidate gathering.
<p>
This setting enables or disables using TCP for ICE candidate gathering in the
underlying libnice library:
https://libnice.freedesktop.org/libnice/NiceAgent.html#NiceAgent--ice-tcp
</p>
<p>
You might want to disable ICE-TCP to potentially speed up ICE gathering by
avoiding TCP candidates in scenarios where they are not needed.
</p>
<p><code>iceTcp</code> is either 1 (ON) or 0 (OFF). Default: 1 (ON).</p>
",
"type": "boolean"
},
{
"name": "stunServerAddress",
"doc": "STUN server IP address.
Expand Down