2 * Copyright (C) 2017 Matthew Waters <matthew@centricular.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
25 #include "nicestream.h"
29 #define HTTP_PROXY_PORT_DEFAULT 3128
33 * - are locally generated remote candidates meant to be readded to libnice?
36 static GstUri *_validate_turn_server (GstWebRTCNice * ice, const gchar * s);
38 #define GST_CAT_DEFAULT gst_webrtc_nice_debug
39 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
51 struct _GstWebRTCNicePrivate
53 NiceAgent *nice_agent;
55 GArray *nice_stream_map;
58 GMainContext *main_context;
63 GstWebRTCICEOnCandidateFunc on_candidate;
64 gpointer on_candidate_data;
65 GDestroyNotify on_candidate_notify;
70 GHashTable *turn_servers;
75 #define gst_webrtc_nice_parent_class parent_class
76 G_DEFINE_TYPE_WITH_CODE (GstWebRTCNice, gst_webrtc_nice,
77 GST_TYPE_WEBRTC_ICE, G_ADD_PRIVATE (GstWebRTCNice)
78 GST_DEBUG_CATEGORY_INIT (gst_webrtc_nice_debug, "webrtcnice", 0,
82 _unlock_pc_thread (GMutex * lock)
84 g_mutex_unlock (lock);
85 return G_SOURCE_REMOVE;
89 _gst_nice_thread (GstWebRTCNice * ice)
91 g_mutex_lock (&ice->priv->lock);
92 ice->priv->main_context = g_main_context_new ();
93 ice->priv->loop = g_main_loop_new (ice->priv->main_context, FALSE);
95 g_cond_broadcast (&ice->priv->cond);
96 g_main_context_invoke (ice->priv->main_context,
97 (GSourceFunc) _unlock_pc_thread, &ice->priv->lock);
99 g_main_loop_run (ice->priv->loop);
101 g_mutex_lock (&ice->priv->lock);
102 g_main_context_unref (ice->priv->main_context);
103 ice->priv->main_context = NULL;
104 g_main_loop_unref (ice->priv->loop);
105 ice->priv->loop = NULL;
106 g_cond_broadcast (&ice->priv->cond);
107 g_mutex_unlock (&ice->priv->lock);
113 _start_thread (GstWebRTCNice * ice)
115 g_mutex_lock (&ice->priv->lock);
116 ice->priv->thread = g_thread_new (GST_OBJECT_NAME (ice),
117 (GThreadFunc) _gst_nice_thread, ice);
119 while (!ice->priv->loop)
120 g_cond_wait (&ice->priv->cond, &ice->priv->lock);
121 g_mutex_unlock (&ice->priv->lock);
125 _stop_thread (GstWebRTCNice * ice)
127 g_mutex_lock (&ice->priv->lock);
128 g_main_loop_quit (ice->priv->loop);
129 while (ice->priv->loop)
130 g_cond_wait (&ice->priv->cond, &ice->priv->lock);
131 g_mutex_unlock (&ice->priv->lock);
133 g_thread_unref (ice->priv->thread);
136 struct NiceStreamItem
139 guint nice_stream_id;
140 GstWebRTCICEStream *stream;
143 /* TRUE to continue, FALSE to stop */
144 typedef gboolean (*NiceStreamItemForeachFunc) (struct NiceStreamItem * item,
148 _nice_stream_item_foreach (GstWebRTCNice * ice, NiceStreamItemForeachFunc func,
153 len = ice->priv->nice_stream_map->len;
154 for (i = 0; i < len; i++) {
155 struct NiceStreamItem *item =
156 &g_array_index (ice->priv->nice_stream_map, struct NiceStreamItem,
159 if (!func (item, data))
164 /* TRUE for match, FALSE otherwise */
165 typedef gboolean (*NiceStreamItemFindFunc) (struct NiceStreamItem * item,
170 NiceStreamItemFindFunc func;
172 struct NiceStreamItem *ret;
176 _find_nice_item (struct NiceStreamItem *item, gpointer user_data)
178 struct nice_find *f = user_data;
179 if (f->func (item, f->data)) {
186 static struct NiceStreamItem *
187 _nice_stream_item_find (GstWebRTCNice * ice, NiceStreamItemFindFunc func,
196 _nice_stream_item_foreach (ice, _find_nice_item, &f);
201 #define NICE_MATCH_INIT { -1, -1, NULL }
204 _match (struct NiceStreamItem *item, struct NiceStreamItem *m)
206 if (m->session_id != -1 && m->session_id != item->session_id)
208 if (m->nice_stream_id != -1 && m->nice_stream_id != item->nice_stream_id)
210 if (m->stream != NULL && m->stream != item->stream)
216 static struct NiceStreamItem *
217 _find_item (GstWebRTCNice * ice, guint session_id, guint nice_stream_id,
218 GstWebRTCICEStream * stream)
220 struct NiceStreamItem m = NICE_MATCH_INIT;
222 m.session_id = session_id;
223 m.nice_stream_id = nice_stream_id;
226 return _nice_stream_item_find (ice, (NiceStreamItemFindFunc) _match, &m);
229 static struct NiceStreamItem *
230 _create_nice_stream_item (GstWebRTCNice * ice, guint session_id)
232 struct NiceStreamItem item;
234 item.session_id = session_id;
235 item.nice_stream_id = nice_agent_add_stream (ice->priv->nice_agent, 1);
237 GST_WEBRTC_ICE_STREAM (gst_webrtc_nice_stream_new (GST_WEBRTC_ICE (ice),
241 g_array_append_val (ice->priv->nice_stream_map, item);
243 return _find_item (ice, item.session_id, item.nice_stream_id, item.stream);
247 _parse_userinfo (const gchar * userinfo, gchar ** user, gchar ** pass)
257 colon = g_strstr_len (userinfo, -1, ":");
259 *user = g_uri_unescape_string (userinfo, NULL);
264 /* Check that the first occurence is also the last occurence */
265 if (colon != g_strrstr (userinfo, ":"))
266 GST_WARNING ("userinfo %s contains more than one ':', will assume that the "
267 "first ':' delineates user:pass. You should escape the user and pass "
268 "before adding to the URI.", userinfo);
270 *user = g_uri_unescape_segment (userinfo, colon, NULL);
271 *pass = g_uri_unescape_string (&colon[1], NULL);
274 struct resolve_host_data
278 gboolean main_context_handled;
280 GDestroyNotify notify;
284 on_resolve_host (GResolver * resolver, GAsyncResult * res, gpointer user_data)
286 GTask *task = user_data;
287 struct resolve_host_data *rh;
288 GError *error = NULL;
291 rh = g_task_get_task_data (task);
293 if (!(addresses = g_resolver_lookup_by_name_finish (resolver, res, &error))) {
294 GST_ERROR ("failed to resolve: %s", error->message);
295 g_task_return_error (task, error);
296 g_object_unref (task);
300 GST_DEBUG_OBJECT (rh->ice, "Resolved %d addresses for host %s with data %p",
301 g_list_length (addresses), rh->host, rh);
303 g_task_return_pointer (task, addresses,
304 (GDestroyNotify) g_resolver_free_addresses);
305 g_object_unref (task);
309 free_resolve_host_data (struct resolve_host_data *rh)
311 GST_TRACE_OBJECT (rh->ice, "Freeing data %p for resolving host %s", rh,
315 rh->notify (rh->user_data);
321 static struct resolve_host_data *
322 resolve_host_data_new (GstWebRTCNice * ice, const char *host)
324 struct resolve_host_data *rh = g_new0 (struct resolve_host_data, 1);
327 rh->host = g_strdup (host);
333 resolve_host_main_cb (gpointer user_data)
335 GResolver *resolver = g_resolver_get_default ();
336 GTask *task = user_data;
337 struct resolve_host_data *rh;
339 rh = g_task_get_task_data (task);
340 /* no need to error anymore if the main context disappears and this task is
342 rh->main_context_handled = TRUE;
344 GST_DEBUG_OBJECT (rh->ice, "Resolving host %s", rh->host);
345 g_resolver_lookup_by_name_async (resolver, rh->host, NULL,
346 (GAsyncReadyCallback) on_resolve_host, g_object_ref (task));
348 return G_SOURCE_REMOVE;
352 error_task_if_unhandled (GTask * task)
354 struct resolve_host_data *rh;
356 rh = g_task_get_task_data (task);
358 if (!rh->main_context_handled) {
359 GST_DEBUG_OBJECT (rh->ice, "host resolve for %s with data %p was never "
360 "executed, main context quit?", rh->host, rh);
361 g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_CANCELLED, "%s",
365 g_object_unref (task);
369 resolve_host_async (GstWebRTCNice * ice, const gchar * host,
370 GAsyncReadyCallback cb, gpointer user_data, GDestroyNotify notify)
372 struct resolve_host_data *rh = resolve_host_data_new (ice, host);
375 rh->user_data = user_data;
377 task = g_task_new (rh->ice, NULL, cb, user_data);
379 g_task_set_task_data (task, rh, (GDestroyNotify) free_resolve_host_data);
381 GST_TRACE_OBJECT (rh->ice, "invoking main context for resolving host %s "
382 "with data %p", host, rh);
383 g_main_context_invoke_full (ice->priv->main_context, G_PRIORITY_DEFAULT,
384 resolve_host_main_cb, task, (GDestroyNotify) error_task_if_unhandled);
388 resolve_host_finish (GstWebRTCNice * ice, GAsyncResult * res, GError ** error)
390 g_return_val_if_fail (g_task_is_valid (res, ice), NULL);
392 return g_task_propagate_pointer (G_TASK (res), error);
396 _add_turn_server (GstWebRTCNice * ice, struct NiceStreamItem *item,
397 GstUri * turn_server)
399 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
401 NiceRelayType relays[4] = { 0, };
403 const gchar *userinfo, *transport, *scheme;
406 host = gst_uri_get_host (turn_server);
408 GST_ERROR_OBJECT (ice, "Turn server has no host");
412 scheme = gst_uri_get_scheme (turn_server);
413 transport = gst_uri_get_query_value (turn_server, "transport");
414 userinfo = gst_uri_get_userinfo (turn_server);
415 _parse_userinfo (userinfo, &user, &pass);
417 if (g_strcmp0 (scheme, "turns") == 0) {
418 relays[relay_n++] = NICE_RELAY_TYPE_TURN_TLS;
419 } else if (g_strcmp0 (scheme, "turn") == 0) {
420 if (!transport || g_strcmp0 (transport, "udp") == 0)
421 relays[relay_n++] = NICE_RELAY_TYPE_TURN_UDP;
422 if (!transport || g_strcmp0 (transport, "tcp") == 0)
423 relays[relay_n++] = NICE_RELAY_TYPE_TURN_TCP;
425 g_assert (relay_n < G_N_ELEMENTS (relays));
427 for (i = 0; i < relay_n; i++) {
428 if (!nice_agent_set_relay_info (nice->priv->nice_agent,
429 item->nice_stream_id, NICE_COMPONENT_TYPE_RTP,
430 gst_uri_get_host (turn_server), gst_uri_get_port (turn_server),
431 user, pass, relays[i])) {
432 gchar *uri_str = gst_uri_to_string (turn_server);
433 GST_ERROR_OBJECT (ice, "Could not set TURN server %s on libnice",
447 struct NiceStreamItem *item;
451 _add_turn_server_func (const gchar * uri, GstUri * turn_server,
452 AddTurnServerData * data)
454 _add_turn_server (data->ice, data->item, turn_server);
458 _add_stun_server (GstWebRTCNice * ice, GstUri * stun_server)
460 const gchar *msg = "must be of the form stun://<host>:<port>";
465 s = gst_uri_to_string (stun_server);
466 GST_DEBUG_OBJECT (ice, "adding stun server, %s", s);
468 host = gst_uri_get_host (stun_server);
470 GST_ERROR_OBJECT (ice, "Stun server '%s' has no host, %s", s, msg);
474 port = gst_uri_get_port (stun_server);
475 if (port == GST_URI_NO_PORT) {
476 GST_INFO_OBJECT (ice, "Stun server '%s' has no port, assuming 3478", s);
478 gst_uri_set_port (stun_server, port);
481 g_object_set (ice->priv->nice_agent, "stun-server", host,
482 "stun-server-port", port, NULL);
488 static GstWebRTCICEStream *
489 gst_webrtc_nice_add_stream (GstWebRTCICE * ice, guint session_id)
491 struct NiceStreamItem m = NICE_MATCH_INIT;
492 struct NiceStreamItem *item;
493 AddTurnServerData add_data;
494 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
496 m.session_id = session_id;
497 item = _nice_stream_item_find (nice, (NiceStreamItemFindFunc) _match, &m);
499 GST_ERROR_OBJECT (nice, "stream already added with session_id=%u",
504 if (nice->priv->stun_server) {
505 _add_stun_server (nice, nice->priv->stun_server);
508 item = _create_nice_stream_item (nice, session_id);
510 if (nice->priv->turn_server) {
511 _add_turn_server (nice, item, nice->priv->turn_server);
515 add_data.item = item;
517 g_hash_table_foreach (nice->priv->turn_servers,
518 (GHFunc) _add_turn_server_func, &add_data);
524 _on_new_candidate (NiceAgent * agent, NiceCandidate * candidate,
527 struct NiceStreamItem *item;
530 item = _find_item (ice, -1, candidate->stream_id, NULL);
532 GST_WARNING_OBJECT (ice, "received signal for non-existent stream %u",
533 candidate->stream_id);
537 if (!candidate->username || !candidate->password) {
538 gboolean got_credentials;
539 gchar *ufrag, *password;
541 got_credentials = nice_agent_get_local_credentials (ice->priv->nice_agent,
542 candidate->stream_id, &ufrag, &password);
543 g_warn_if_fail (got_credentials);
545 if (!candidate->username)
546 candidate->username = ufrag;
550 if (!candidate->password)
551 candidate->password = password;
556 attr = nice_agent_generate_local_candidate_sdp (agent, candidate);
558 if (ice->priv->on_candidate)
559 ice->priv->on_candidate (GST_WEBRTC_ICE (ice), item->session_id, attr,
560 ice->priv->on_candidate_data);
565 static GstWebRTCICETransport *
566 gst_webrtc_nice_find_transport (GstWebRTCICE * ice, GstWebRTCICEStream * stream,
567 GstWebRTCICEComponent component)
569 struct NiceStreamItem *item;
570 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
572 item = _find_item (nice, -1, -1, stream);
573 g_return_val_if_fail (item != NULL, NULL);
575 return gst_webrtc_ice_stream_find_transport (item->stream, component);
579 /* TODO don't rely on libnice to (de)serialize candidates */
580 static NiceCandidateType
581 _candidate_type_from_string (const gchar * s)
583 if (g_strcmp0 (s, "host") == 0) {
584 return NICE_CANDIDATE_TYPE_HOST;
585 } else if (g_strcmp0 (s, "srflx") == 0) {
586 return NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE;
587 } else if (g_strcmp0 (s, "prflx") == 0) { /* FIXME: is the right string? */
588 return NICE_CANDIDATE_TYPE_PEER_REFLEXIVE;
589 } else if (g_strcmp0 (s, "relay") == 0) {
590 return NICE_CANDIDATE_TYPE_RELAY;
592 g_assert_not_reached ();
598 _candidate_type_to_string (NiceCandidateType type)
601 case NICE_CANDIDATE_TYPE_HOST:
603 case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE:
605 case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE:
607 case NICE_CANDIDATE_TYPE_RELAY:
610 g_assert_not_reached ();
615 static NiceCandidateTransport
616 _candidate_transport_from_string (const gchar * s)
618 if (g_strcmp0 (s, "UDP") == 0) {
619 return NICE_CANDIDATE_TRANSPORT_UDP;
620 } else if (g_strcmp0 (s, "TCP tcptype") == 0) {
621 return NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE;
622 } else if (g_strcmp0 (s, "tcp-passive") == 0) { /* FIXME: is the right string? */
623 return NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE;
624 } else if (g_strcmp0 (s, "tcp-so") == 0) {
625 return NICE_CANDIDATE_TRANSPORT_TCP_SO;
627 g_assert_not_reached ();
633 _candidate_type_to_string (NiceCandidateType type)
636 case NICE_CANDIDATE_TYPE_HOST:
638 case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE:
640 case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE:
642 case NICE_CANDIDATE_TYPE_RELAY:
645 g_assert_not_reached ();
651 /* parse the address for possible resolution */
653 get_candidate_address (const gchar * candidate, gchar ** prefix,
654 gchar ** address, gchar ** postfix)
656 char **tokens = NULL;
657 char *tmp_address = NULL;
659 if (!g_str_has_prefix (candidate, "a=candidate:")) {
660 GST_ERROR ("candidate \"%s\" does not start with \"a=candidate:\"",
665 if (!(tokens = g_strsplit (candidate, " ", 6))) {
666 GST_ERROR ("candidate \"%s\" could not be tokenized", candidate);
670 if (g_strv_length (tokens) < 6) {
671 GST_ERROR ("candidate \"%s\" tokenization resulted in not enough tokens",
676 tmp_address = tokens[4];
678 *address = g_strdup (tmp_address);
682 *prefix = g_strjoinv (" ", tokens);
684 *postfix = g_strdup (tokens[5]);
686 tokens[4] = tmp_address;
697 struct resolve_candidate_data
699 guint nice_stream_id;
705 free_resolve_candidate_data (struct resolve_candidate_data *rc)
708 g_free (rc->postfix);
713 add_ice_candidate_to_libnice (GstWebRTCICE * ice, guint nice_stream_id,
714 NiceCandidate * cand)
716 GSList *candidates = NULL;
717 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
719 if (cand->component_id == 2) {
720 /* we only support rtcp-mux so rtcp candidates are useless for us */
721 GST_INFO_OBJECT (ice, "Dropping RTCP candidate");
725 candidates = g_slist_append (candidates, cand);
727 nice_agent_set_remote_candidates (nice->priv->nice_agent, nice_stream_id,
728 cand->component_id, candidates);
730 g_slist_free (candidates);
734 on_candidate_resolved (GstWebRTCICE * ice, GAsyncResult * res,
737 struct resolve_candidate_data *rc = user_data;
738 GError *error = NULL;
740 char *new_candv[4] = { NULL, };
741 char *new_addr, *new_candidate;
743 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
745 if (!(addresses = resolve_host_finish (nice, res, &error))) {
746 GST_WARNING_OBJECT (ice, "Could not resolve candidate address: %s",
748 g_clear_error (&error);
752 new_addr = g_inet_address_to_string (addresses->data);
754 new_candv[0] = rc->prefix;
755 new_candv[1] = new_addr;
756 new_candv[2] = rc->postfix;
758 new_candidate = g_strjoinv (" ", new_candv);
760 GST_DEBUG_OBJECT (ice, "resolved to candidate %s", new_candidate);
763 nice_agent_parse_remote_candidate_sdp (nice->priv->nice_agent,
764 rc->nice_stream_id, new_candidate);
765 g_free (new_candidate);
767 GST_WARNING_OBJECT (ice, "Could not parse candidate \'%s\'", new_candidate);
773 add_ice_candidate_to_libnice (ice, rc->nice_stream_id, cand);
774 nice_candidate_free (cand);
777 /* candidate must start with "a=candidate:" or be NULL*/
779 gst_webrtc_nice_add_candidate (GstWebRTCICE * ice, GstWebRTCICEStream * stream,
780 const gchar * candidate)
782 struct NiceStreamItem *item;
784 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
786 item = _find_item (nice, -1, -1, stream);
787 g_return_if_fail (item != NULL);
789 if (candidate == NULL) {
790 nice_agent_peer_candidate_gathering_done (nice->priv->nice_agent,
791 item->nice_stream_id);
796 nice_agent_parse_remote_candidate_sdp (nice->priv->nice_agent,
797 item->nice_stream_id, candidate);
799 /* might be a .local candidate */
800 char *prefix = NULL, *address = NULL, *postfix = NULL;
801 struct resolve_candidate_data *rc;
803 if (!get_candidate_address (candidate, &prefix, &address, &postfix)) {
804 GST_WARNING_OBJECT (nice, "Failed to retrieve address from candidate %s",
809 if (!g_str_has_suffix (address, ".local")) {
810 GST_WARNING_OBJECT (nice, "candidate address \'%s\' does not end "
811 "with \'.local\'", address);
815 rc = g_new0 (struct resolve_candidate_data, 1);
816 rc->nice_stream_id = item->nice_stream_id;
818 rc->postfix = postfix;
819 resolve_host_async (nice, address,
820 (GAsyncReadyCallback) on_candidate_resolved, rc,
821 (GDestroyNotify) free_resolve_candidate_data);
827 g_clear_pointer (&address, g_free);
828 g_clear_pointer (&prefix, g_free);
829 g_clear_pointer (&postfix, g_free);
834 add_ice_candidate_to_libnice (ice, item->nice_stream_id, cand);
835 nice_candidate_free (cand);
839 gst_webrtc_nice_set_remote_credentials (GstWebRTCICE * ice,
840 GstWebRTCICEStream * stream, const gchar * ufrag, const gchar * pwd)
842 struct NiceStreamItem *item;
843 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
845 g_return_val_if_fail (ufrag != NULL, FALSE);
846 g_return_val_if_fail (pwd != NULL, FALSE);
847 item = _find_item (nice, -1, -1, stream);
848 g_return_val_if_fail (item != NULL, FALSE);
850 GST_DEBUG_OBJECT (nice, "Setting remote ICE credentials on "
851 "ICE stream %u ufrag:%s pwd:%s", item->nice_stream_id, ufrag, pwd);
853 nice_agent_set_remote_credentials (nice->priv->nice_agent,
854 item->nice_stream_id, ufrag, pwd);
863 } AddTurnServerToStreamData;
866 _add_turn_server_foreach_stream_func (struct NiceStreamItem *item,
869 AddTurnServerToStreamData *add_data = (AddTurnServerToStreamData *) data;
870 _add_turn_server (add_data->ice, item, add_data->turn_server);
875 gst_webrtc_nice_add_turn_server (GstWebRTCICE * ice, const gchar * uri)
877 gboolean ret = FALSE;
879 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
881 AddTurnServerToStreamData add_data;
883 if (!(valid_uri = _validate_turn_server (nice, uri)))
887 g_hash_table_insert (nice->priv->turn_servers, g_strdup (uri), valid_uri);
889 /* add the turn server to any streams that were already created */
892 add_data.turn_server = valid_uri;
893 _nice_stream_item_foreach (nice, _add_turn_server_foreach_stream_func,
904 gst_webrtc_nice_add_local_ip_address (GstWebRTCNice * ice,
905 const gchar * address)
907 gboolean ret = FALSE;
908 NiceAddress nice_addr;
910 nice_address_init (&nice_addr);
912 ret = nice_address_set_from_string (&nice_addr, address);
915 ret = nice_agent_add_local_address (ice->priv->nice_agent, &nice_addr);
917 GST_ERROR_OBJECT (ice, "Failed to add local address to NiceAgent");
920 GST_ERROR_OBJECT (ice, "Failed to initialize NiceAddress [%s]", address);
927 gst_webrtc_nice_set_local_credentials (GstWebRTCICE * ice,
928 GstWebRTCICEStream * stream, const gchar * ufrag, const gchar * pwd)
930 struct NiceStreamItem *item;
931 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
933 g_return_val_if_fail (ufrag != NULL, FALSE);
934 g_return_val_if_fail (pwd != NULL, FALSE);
935 item = _find_item (nice, -1, -1, stream);
936 g_return_val_if_fail (item != NULL, FALSE);
938 GST_DEBUG_OBJECT (nice, "Setting local ICE credentials on "
939 "ICE stream %u ufrag:%s pwd:%s", item->nice_stream_id, ufrag, pwd);
941 nice_agent_set_local_credentials (nice->priv->nice_agent,
942 item->nice_stream_id, ufrag, pwd);
948 gst_webrtc_nice_gather_candidates (GstWebRTCICE * ice,
949 GstWebRTCICEStream * stream)
951 struct NiceStreamItem *item;
952 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
954 item = _find_item (nice, -1, -1, stream);
955 g_return_val_if_fail (item != NULL, FALSE);
957 GST_DEBUG_OBJECT (nice, "gather candidates for stream %u",
958 item->nice_stream_id);
960 return gst_webrtc_ice_stream_gather_candidates (stream);
964 gst_webrtc_nice_set_is_controller (GstWebRTCICE * ice, gboolean controller)
966 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
967 g_object_set (G_OBJECT (nice->priv->nice_agent), "controlling-mode",
972 gst_webrtc_nice_get_is_controller (GstWebRTCICE * ice)
975 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
976 g_object_get (G_OBJECT (nice->priv->nice_agent), "controlling-mode",
982 gst_webrtc_nice_set_force_relay (GstWebRTCICE * ice, gboolean force_relay)
984 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
985 g_object_set (G_OBJECT (nice->priv->nice_agent), "force-relay", force_relay,
990 gst_webrtc_nice_set_on_ice_candidate (GstWebRTCICE * ice,
991 GstWebRTCICEOnCandidateFunc func, gpointer user_data, GDestroyNotify notify)
993 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
994 if (nice->priv->on_candidate_notify)
995 nice->priv->on_candidate_notify (nice->priv->on_candidate_data);
996 nice->priv->on_candidate = NULL;
998 nice->priv->on_candidate = func;
999 nice->priv->on_candidate_data = user_data;
1000 nice->priv->on_candidate_notify = notify;
1004 gst_webrtc_nice_set_tos (GstWebRTCICE * ice, GstWebRTCICEStream * stream,
1007 struct NiceStreamItem *item;
1008 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
1010 item = _find_item (nice, -1, -1, stream);
1011 g_return_if_fail (item != NULL);
1013 nice_agent_set_stream_tos (nice->priv->nice_agent, item->nice_stream_id, tos);
1016 static const gchar *
1017 _relay_type_to_string (GstUri * turn_server)
1019 const gchar *scheme;
1020 const gchar *transport;
1025 scheme = gst_uri_get_scheme (turn_server);
1026 transport = gst_uri_get_query_value (turn_server, "transport");
1028 if (g_strcmp0 (scheme, "turns") == 0) {
1030 } else if (g_strcmp0 (scheme, "turn") == 0) {
1031 if (!transport || g_strcmp0 (transport, "udp") == 0)
1033 if (!transport || g_strcmp0 (transport, "tcp") == 0)
1041 _get_server_url (GstWebRTCNice * ice, NiceCandidate * cand)
1043 switch (cand->type) {
1044 case NICE_CANDIDATE_TYPE_RELAYED:{
1046 gchar ipaddr[NICE_ADDRESS_STRING_LEN];
1047 nice_candidate_relay_address (cand, &addr);
1048 nice_address_to_string (&addr, ipaddr);
1049 return g_strdup (ipaddr);
1051 case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE:{
1053 gchar ipaddr[NICE_ADDRESS_STRING_LEN];
1054 if (nice_candidate_stun_server_address (cand, &addr)) {
1055 nice_address_to_string (&addr, ipaddr);
1056 return g_strdup (ipaddr);
1058 return g_strdup (gst_uri_get_host (ice->priv->stun_server));
1060 return g_strdup (gst_uri_get_host (ice->priv->stun_server));
1063 return g_strdup ("");
1067 /* TODO: replace it with nice_candidate_type_to_string()
1068 * when it's ready for use
1069 * https://libnice.freedesktop.org/libnice/NiceCandidate.html#nice-candidate-type-to-string
1071 static const gchar *
1072 _candidate_type_to_string (NiceCandidateType type)
1075 case NICE_CANDIDATE_TYPE_HOST:
1077 case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE:
1079 case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE:
1081 case NICE_CANDIDATE_TYPE_RELAYED:
1084 g_assert_not_reached ();
1090 _populate_candidate_stats (GstWebRTCNice * ice, NiceCandidate * cand,
1091 GstWebRTCICEStream * stream, GstWebRTCICECandidateStats * stats,
1094 gchar ipaddr[INET6_ADDRSTRLEN];
1096 g_assert (cand != NULL);
1098 nice_address_to_string (&cand->addr, ipaddr);
1099 stats->port = nice_address_get_port (&cand->addr);
1100 stats->ipaddr = g_strdup (ipaddr);
1101 stats->stream_id = stream->stream_id;
1102 stats->type = _candidate_type_to_string (cand->type);
1103 stats->prio = cand->priority;
1105 cand->transport == NICE_CANDIDATE_TRANSPORT_UDP ? "udp" : "tcp";
1107 if (cand->type == NICE_CANDIDATE_TYPE_RELAYED)
1108 stats->relay_proto = _relay_type_to_string (ice->priv->turn_server);
1109 stats->url = _get_server_url (ice, cand);
1114 _populate_candidate_list_stats (GstWebRTCNice * ice, GSList * cands,
1115 GstWebRTCICEStream * stream, GPtrArray * result, gboolean is_local)
1119 for (item = cands; item != NULL; item = item->next) {
1120 GstWebRTCICECandidateStats *stats =
1121 g_malloc0 (sizeof (GstWebRTCICECandidateStats));
1122 NiceCandidate *c = item->data;
1123 _populate_candidate_stats (ice, c, stream, stats, is_local);
1124 g_ptr_array_add (result, stats);
1127 g_ptr_array_add (result, NULL);
1130 static GstWebRTCICECandidateStats **
1131 gst_webrtc_nice_get_local_candidates (GstWebRTCICE * ice,
1132 GstWebRTCICEStream * stream)
1134 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
1135 GSList *cands = NULL;
1137 /* TODO: Use a g_ptr_array_new_null_terminated once when we depend on GLib 2.74 */
1138 GPtrArray *result = g_ptr_array_new ();
1140 cands = nice_agent_get_local_candidates (nice->priv->nice_agent,
1141 stream->stream_id, NICE_COMPONENT_TYPE_RTP);
1143 _populate_candidate_list_stats (nice, cands, stream, result, TRUE);
1144 g_slist_free_full (cands, (GDestroyNotify) nice_candidate_free);
1146 return (GstWebRTCICECandidateStats **) g_ptr_array_free (result, FALSE);
1149 static GstWebRTCICECandidateStats **
1150 gst_webrtc_nice_get_remote_candidates (GstWebRTCICE * ice,
1151 GstWebRTCICEStream * stream)
1153 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
1154 GSList *cands = NULL;
1156 /* TODO: Use a g_ptr_array_new_null_terminated once when we depend on GLib 2.74 */
1157 GPtrArray *result = g_ptr_array_new ();
1159 cands = nice_agent_get_remote_candidates (nice->priv->nice_agent,
1160 stream->stream_id, NICE_COMPONENT_TYPE_RTP);
1162 _populate_candidate_list_stats (nice, cands, stream, result, FALSE);
1163 g_slist_free_full (cands, (GDestroyNotify) nice_candidate_free);
1165 return (GstWebRTCICECandidateStats **) g_ptr_array_free (result, FALSE);
1169 gst_webrtc_nice_get_selected_pair (GstWebRTCICE * ice,
1170 GstWebRTCICEStream * stream, GstWebRTCICECandidateStats ** local_stats,
1171 GstWebRTCICECandidateStats ** remote_stats)
1173 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
1174 NiceCandidate *local_cand = NULL;
1175 NiceCandidate *remote_cand = NULL;
1179 if (nice_agent_get_selected_pair (nice->priv->nice_agent, stream->stream_id,
1180 NICE_COMPONENT_TYPE_RTP, &local_cand, &remote_cand)) {
1181 *local_stats = g_new0 (GstWebRTCICECandidateStats, 1);
1182 _populate_candidate_stats (nice, local_cand, stream, *local_stats, TRUE);
1184 *remote_stats = g_new0 (GstWebRTCICECandidateStats, 1);
1185 _populate_candidate_stats (nice, remote_cand, stream, *remote_stats,
1196 _clear_ice_stream (struct NiceStreamItem *item)
1198 GstWebRTCNice *ice = NULL;
1204 g_object_get (item->stream, "ice", &ice, NULL);
1207 g_signal_handlers_disconnect_by_data (ice->priv->nice_agent,
1209 gst_object_unref (ice);
1211 gst_object_unref (item->stream);
1216 _validate_turn_server (GstWebRTCNice * ice, const gchar * s)
1218 GstUri *uri = gst_uri_from_string_escaped (s);
1219 const gchar *userinfo, *scheme;
1220 GList *keys = NULL, *l;
1221 gchar *user = NULL, *pass = NULL;
1222 gboolean turn_tls = FALSE;
1225 GST_DEBUG_OBJECT (ice, "validating turn server, %s", s);
1228 GST_ERROR_OBJECT (ice, "Could not parse turn server '%s'", s);
1232 scheme = gst_uri_get_scheme (uri);
1233 if (g_strcmp0 (scheme, "turn") == 0) {
1234 } else if (g_strcmp0 (scheme, "turns") == 0) {
1237 GST_ERROR_OBJECT (ice, "unknown scheme '%s'", scheme);
1241 keys = gst_uri_get_query_keys (uri);
1242 for (l = keys; l; l = l->next) {
1243 gchar *key = l->data;
1245 if (g_strcmp0 (key, "transport") == 0) {
1246 const gchar *transport = gst_uri_get_query_value (uri, "transport");
1248 } else if (g_strcmp0 (transport, "udp") == 0) {
1249 } else if (g_strcmp0 (transport, "tcp") == 0) {
1251 GST_ERROR_OBJECT (ice, "unknown transport value, '%s'", transport);
1255 GST_ERROR_OBJECT (ice, "unknown query key, '%s'", key);
1260 /* TODO: Implement error checking similar to the stun server below */
1261 userinfo = gst_uri_get_userinfo (uri);
1262 _parse_userinfo (userinfo, &user, &pass);
1264 GST_ERROR_OBJECT (ice, "No username specified in '%s'", s);
1268 GST_ERROR_OBJECT (ice, "No password specified in '%s'", s);
1272 port = gst_uri_get_port (uri);
1274 if (port == GST_URI_NO_PORT) {
1276 gst_uri_set_port (uri, 5349);
1278 gst_uri_set_port (uri, 3478);
1292 gst_uri_unref (uri);
1298 on_http_proxy_resolved (GstWebRTCICE * ice, GAsyncResult * res,
1301 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
1302 GstUri *uri = user_data;
1304 GError *error = NULL;
1305 const gchar *userinfo;
1309 guint port = GST_URI_NO_PORT;
1311 if (!(addresses = resolve_host_finish (nice, res, &error))) {
1312 GST_WARNING_OBJECT (ice, "Failed to resolve http proxy: %s",
1314 g_clear_error (&error);
1318 /* XXX: only the first IP is used */
1319 ip = g_inet_address_to_string (addresses->data);
1322 GST_ERROR_OBJECT (ice, "failed to resolve host for proxy");
1323 gst_uri_unref (uri);
1327 port = gst_uri_get_port (uri);
1328 if (port == GST_URI_NO_PORT) {
1329 port = HTTP_PROXY_PORT_DEFAULT;
1330 GST_DEBUG_OBJECT (ice, "Proxy server has no port, assuming %u",
1331 HTTP_PROXY_PORT_DEFAULT);
1334 userinfo = gst_uri_get_userinfo (uri);
1335 _parse_userinfo (userinfo, &user, &pass);
1337 g_object_set (nice->priv->nice_agent,
1338 "proxy-ip", ip, "proxy-port", port, "proxy-type", NICE_PROXY_TYPE_HTTP,
1339 "proxy-username", user, "proxy-password", pass, NULL);
1347 _set_http_proxy (GstWebRTCICE * ice, const gchar * s)
1349 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
1350 GstUri *uri = gst_uri_from_string_escaped (s);
1352 "must be of the form http://[username:password@]<host>[:<port>]";
1353 const gchar *host = NULL;
1354 const gchar *userinfo;
1355 gchar *user = NULL, *pass = NULL;
1357 GST_DEBUG_OBJECT (ice, "setting http proxy %s", s);
1360 GST_ERROR_OBJECT (ice, "Couldn't parse http proxy uri '%s', %s", s, msg);
1364 if (g_strcmp0 (gst_uri_get_scheme (uri), "http") != 0) {
1365 GST_ERROR_OBJECT (ice,
1366 "Couldn't parse uri scheme for http proxy server '%s', %s", s, msg);
1367 gst_uri_unref (uri);
1371 host = gst_uri_get_host (uri);
1373 GST_ERROR_OBJECT (ice, "http proxy server '%s' has no host, %s", s, msg);
1374 gst_uri_unref (uri);
1378 userinfo = gst_uri_get_userinfo (uri);
1379 _parse_userinfo (userinfo, &user, &pass);
1380 if ((pass && pass[0] != '\0') && (!user || user[0] == '\0')) {
1381 GST_ERROR_OBJECT (ice,
1382 "Password specified without user for http proxy '%s', %s", s, msg);
1387 resolve_host_async (nice, host, (GAsyncReadyCallback) on_http_proxy_resolved,
1388 gst_uri_ref (uri), (GDestroyNotify) gst_uri_unref);
1398 gst_webrtc_nice_set_stun_server (GstWebRTCICE * ice, const gchar * uri_s)
1400 GstUri *uri = gst_uri_from_string_escaped (uri_s);
1401 const gchar *msg = "must be of the form stun://<host>:<port>";
1402 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
1404 GST_DEBUG_OBJECT (nice, "setting stun server, %s", uri_s);
1407 GST_ERROR_OBJECT (nice, "Couldn't parse stun server '%s', %s", uri_s, msg);
1411 if (nice->priv->stun_server)
1412 gst_uri_unref (nice->priv->stun_server);
1413 nice->priv->stun_server = uri;
1417 gst_webrtc_nice_get_stun_server (GstWebRTCICE * ice)
1419 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
1420 if (nice->priv->stun_server)
1421 return gst_uri_to_string (nice->priv->stun_server);
1427 gst_webrtc_nice_set_turn_server (GstWebRTCICE * ice, const gchar * uri_s)
1430 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
1431 uri = _validate_turn_server (nice, uri_s);
1434 if (nice->priv->turn_server)
1435 gst_uri_unref (nice->priv->turn_server);
1436 nice->priv->turn_server = uri;
1441 gst_webrtc_nice_get_turn_server (GstWebRTCICE * ice)
1443 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
1444 if (nice->priv->turn_server)
1445 return gst_uri_to_string (nice->priv->turn_server);
1451 gst_webrtc_nice_set_http_proxy (GstWebRTCICE * ice, const gchar * http_proxy)
1453 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
1454 GstUri *uri = _set_http_proxy (ice, http_proxy);
1457 if (nice->priv->http_proxy)
1458 gst_uri_unref (nice->priv->http_proxy);
1459 nice->priv->http_proxy = uri;
1464 gst_webrtc_nice_get_http_proxy (GstWebRTCICE * ice)
1466 GstWebRTCNice *nice = GST_WEBRTC_NICE (ice);
1468 if (nice->priv->http_proxy)
1469 return gst_uri_to_string (nice->priv->http_proxy);
1475 gst_webrtc_nice_set_property (GObject * object, guint prop_id,
1476 const GValue * value, GParamSpec * pspec)
1478 GstWebRTCICE *ice = GST_WEBRTC_ICE (object);
1479 GstWebRTCNice *nice = GST_WEBRTC_NICE (object);
1483 g_object_set_property (G_OBJECT (nice->priv->nice_agent),
1487 g_object_set_property (G_OBJECT (nice->priv->nice_agent),
1490 case PROP_MIN_RTP_PORT:
1491 ice->min_rtp_port = g_value_get_uint (value);
1492 if (ice->min_rtp_port > ice->max_rtp_port)
1493 g_warning ("Set min-rtp-port to %u which is larger than"
1494 " max-rtp-port %u", ice->min_rtp_port, ice->max_rtp_port);
1496 case PROP_MAX_RTP_PORT:
1497 ice->max_rtp_port = g_value_get_uint (value);
1498 if (ice->min_rtp_port > ice->max_rtp_port)
1499 g_warning ("Set max-rtp-port to %u which is smaller than"
1500 " min-rtp-port %u", ice->max_rtp_port, ice->min_rtp_port);
1503 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1509 gst_webrtc_nice_get_property (GObject * object, guint prop_id,
1510 GValue * value, GParamSpec * pspec)
1512 GstWebRTCICE *ice = GST_WEBRTC_ICE (object);
1513 GstWebRTCNice *nice = GST_WEBRTC_NICE (object);
1517 g_value_set_object (value, nice->priv->nice_agent);
1520 g_object_get_property (G_OBJECT (nice->priv->nice_agent),
1524 g_object_get_property (G_OBJECT (nice->priv->nice_agent),
1527 case PROP_MIN_RTP_PORT:
1528 g_value_set_uint (value, ice->min_rtp_port);
1530 case PROP_MAX_RTP_PORT:
1531 g_value_set_uint (value, ice->max_rtp_port);
1534 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1540 gst_webrtc_nice_finalize (GObject * object)
1542 GstWebRTCNice *ice = GST_WEBRTC_NICE (object);
1544 g_signal_handlers_disconnect_by_data (ice->priv->nice_agent, ice);
1548 if (ice->priv->on_candidate_notify)
1549 ice->priv->on_candidate_notify (ice->priv->on_candidate_data);
1550 ice->priv->on_candidate = NULL;
1551 ice->priv->on_candidate_notify = NULL;
1553 if (ice->priv->turn_server)
1554 gst_uri_unref (ice->priv->turn_server);
1555 if (ice->priv->stun_server)
1556 gst_uri_unref (ice->priv->stun_server);
1557 if (ice->priv->http_proxy)
1558 gst_uri_unref (ice->priv->http_proxy);
1560 g_mutex_clear (&ice->priv->lock);
1561 g_cond_clear (&ice->priv->cond);
1563 g_array_free (ice->priv->nice_stream_map, TRUE);
1565 g_object_unref (ice->priv->nice_agent);
1567 g_hash_table_unref (ice->priv->turn_servers);
1569 G_OBJECT_CLASS (parent_class)->finalize (object);
1573 gst_webrtc_nice_constructed (GObject * object)
1575 GstWebRTCNice *ice = GST_WEBRTC_NICE (object);
1576 NiceAgentOption options = 0;
1578 _start_thread (ice);
1580 options |= NICE_AGENT_OPTION_ICE_TRICKLE;
1581 options |= NICE_AGENT_OPTION_REGULAR_NOMINATION;
1583 ice->priv->nice_agent = nice_agent_new_full (ice->priv->main_context,
1584 NICE_COMPATIBILITY_RFC5245, options);
1585 g_signal_connect (ice->priv->nice_agent, "new-candidate-full",
1586 G_CALLBACK (_on_new_candidate), ice);
1588 G_OBJECT_CLASS (parent_class)->constructed (object);
1592 gst_webrtc_nice_class_init (GstWebRTCNiceClass * klass)
1594 GstWebRTCICEClass *gst_webrtc_ice_class = GST_WEBRTC_ICE_CLASS (klass);
1595 GObjectClass *gobject_class = (GObjectClass *) klass;
1597 // override virtual functions
1598 gst_webrtc_ice_class->add_candidate = gst_webrtc_nice_add_candidate;
1599 gst_webrtc_ice_class->add_stream = gst_webrtc_nice_add_stream;
1600 gst_webrtc_ice_class->add_turn_server = gst_webrtc_nice_add_turn_server;
1601 gst_webrtc_ice_class->find_transport = gst_webrtc_nice_find_transport;
1602 gst_webrtc_ice_class->gather_candidates = gst_webrtc_nice_gather_candidates;
1603 gst_webrtc_ice_class->get_is_controller = gst_webrtc_nice_get_is_controller;
1604 gst_webrtc_ice_class->get_stun_server = gst_webrtc_nice_get_stun_server;
1605 gst_webrtc_ice_class->get_turn_server = gst_webrtc_nice_get_turn_server;
1606 gst_webrtc_ice_class->get_http_proxy = gst_webrtc_nice_get_http_proxy;
1607 gst_webrtc_ice_class->set_force_relay = gst_webrtc_nice_set_force_relay;
1608 gst_webrtc_ice_class->set_is_controller = gst_webrtc_nice_set_is_controller;
1609 gst_webrtc_ice_class->set_local_credentials =
1610 gst_webrtc_nice_set_local_credentials;
1611 gst_webrtc_ice_class->set_remote_credentials =
1612 gst_webrtc_nice_set_remote_credentials;
1613 gst_webrtc_ice_class->set_stun_server = gst_webrtc_nice_set_stun_server;
1614 gst_webrtc_ice_class->set_tos = gst_webrtc_nice_set_tos;
1615 gst_webrtc_ice_class->set_turn_server = gst_webrtc_nice_set_turn_server;
1616 gst_webrtc_ice_class->set_http_proxy = gst_webrtc_nice_set_http_proxy;
1617 gst_webrtc_ice_class->set_on_ice_candidate =
1618 gst_webrtc_nice_set_on_ice_candidate;
1619 gst_webrtc_ice_class->get_local_candidates =
1620 gst_webrtc_nice_get_local_candidates;
1621 gst_webrtc_ice_class->get_remote_candidates =
1622 gst_webrtc_nice_get_remote_candidates;
1623 gst_webrtc_ice_class->get_selected_pair = gst_webrtc_nice_get_selected_pair;
1625 gobject_class->constructed = gst_webrtc_nice_constructed;
1626 gobject_class->get_property = gst_webrtc_nice_get_property;
1627 gobject_class->set_property = gst_webrtc_nice_set_property;
1628 gobject_class->finalize = gst_webrtc_nice_finalize;
1630 g_object_class_install_property (gobject_class,
1632 g_param_spec_object ("agent", "ICE agent",
1633 "ICE agent in use by this object. WARNING! Accessing this property "
1634 "may have disastrous consequences for the operation of webrtcbin. "
1635 "Other ICE implementations may not have the same interface.",
1636 NICE_TYPE_AGENT, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
1638 g_object_class_install_property (gobject_class,
1640 g_param_spec_boolean ("ice-tcp", "ICE TCP",
1641 "Whether the agent should use ICE-TCP when gathering candidates",
1642 TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1644 g_object_class_install_property (gobject_class,
1646 g_param_spec_boolean ("ice-udp", "ICE UDP",
1647 "Whether the agent should use ICE-UDP when gathering candidates",
1648 TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1650 g_signal_override_class_handler ("add-local-ip-address",
1651 G_TYPE_FROM_CLASS (klass),
1652 G_CALLBACK (gst_webrtc_nice_add_local_ip_address));
1656 gst_webrtc_nice_init (GstWebRTCNice * ice)
1658 ice->priv = gst_webrtc_nice_get_instance_private (ice);
1660 g_mutex_init (&ice->priv->lock);
1661 g_cond_init (&ice->priv->cond);
1663 ice->priv->turn_servers =
1664 g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
1665 (GDestroyNotify) gst_uri_unref);
1667 ice->priv->nice_stream_map =
1668 g_array_new (FALSE, TRUE, sizeof (struct NiceStreamItem));
1669 g_array_set_clear_func (ice->priv->nice_stream_map,
1670 (GDestroyNotify) _clear_ice_stream);
1674 gst_webrtc_nice_new (const gchar * name)
1676 return g_object_new (GST_TYPE_WEBRTC_NICE, "name", name, NULL);