2 * This file is part of the Nice GLib ICE library.
4 * (C) 2006-2009 Collabora Ltd.
5 * Contact: Youness Alaoui
6 * (C) 2006-2009 Nokia Corporation. All rights reserved.
7 * Contact: Kai Vehmanen
9 * The contents of this file are subject to the Mozilla Public License Version
10 * 1.1 (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
12 * http://www.mozilla.org/MPL/
14 * Software distributed under the License is distributed on an "AS IS" basis,
15 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16 * for the specific language governing rights and limitations under the
19 * The Original Code is the Nice GLib ICE library.
21 * The Initial Developers of the Original Code are Collabora Ltd and Nokia
22 * Corporation. All Rights Reserved.
25 * Dafydd Harries, Collabora Ltd.
26 * Youness Alaoui, Collabora Ltd.
28 * Alternatively, the contents of this file may be used under the terms of the
29 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
30 * case the provisions of LGPL are applicable instead of those above. If you
31 * wish to allow use of your version of this file only under the terms of the
32 * LGPL and not to allow others to use your version of this file under the
33 * MPL, indicate your decision by deleting the provisions above and replace
34 * them with the notice and other provisions required by the LGPL. If you do
35 * not delete the provisions above, a recipient may use your version of this
36 * file under either the MPL or the LGPL.
46 /* Simple tracking for the number of alive streams. These must be accessed
48 static volatile unsigned int n_streams_created = 0;
49 static volatile unsigned int n_streams_destroyed = 0;
51 G_DEFINE_TYPE (NiceStream, nice_stream, G_TYPE_OBJECT);
54 nice_stream_finalize (GObject *obj);
58 * @brief ICE stream functionality
61 nice_stream_new (guint stream_id, guint n_components, NiceAgent *agent)
63 NiceStream *stream = NULL;
66 stream = g_object_new (NICE_TYPE_STREAM, NULL);
68 stream->id = stream_id;
70 /* Create the components. */
71 for (n = 0; n < n_components; n++) {
72 NiceComponent *component = NULL;
74 component = nice_component_new (n + 1, agent, stream);
75 stream->components = g_slist_append (stream->components, component);
78 stream->n_components = n_components;
80 stream->peer_gathering_done = !agent->use_ice_trickle;
86 nice_stream_close (NiceAgent *agent, NiceStream *stream)
90 for (i = stream->components; i; i = i->next) {
91 NiceComponent *component = i->data;
92 nice_component_close (agent, component);
97 nice_stream_find_component_by_id (NiceStream *stream, guint id)
101 for (i = stream->components; i; i = i->next) {
102 NiceComponent *component = i->data;
103 if (component && component->id == id)
111 * Initialized the local crendentials for the stream.
114 nice_stream_initialize_credentials (NiceStream *stream, NiceRNG *rng)
116 /* note: generate ufrag/pwd for the stream (see ICE 15.4.
117 * '"ice-ufrag" and "ice-pwd" Attributes', ID-19) */
118 nice_rng_generate_bytes_print (rng, NICE_STREAM_DEF_UFRAG - 1, stream->local_ufrag);
119 nice_rng_generate_bytes_print (rng, NICE_STREAM_DEF_PWD - 1, stream->local_password);
123 * Resets the stream state to that of a ICE restarted
127 nice_stream_restart (NiceStream *stream, NiceAgent *agent)
131 /* step: clean up all connectivity checks */
132 conn_check_prune_stream (agent, stream);
134 stream->initial_binding_request_received = FALSE;
136 nice_stream_initialize_credentials (stream, agent->rng);
138 for (i = stream->components; i; i = i->next) {
139 NiceComponent *component = i->data;
141 nice_component_restart (component);
146 nice_stream_class_init (NiceStreamClass *klass)
148 GObjectClass *object_class = G_OBJECT_CLASS (klass);
150 object_class->finalize = nice_stream_finalize;
154 nice_stream_init (NiceStream *stream)
156 g_atomic_int_inc (&n_streams_created);
157 nice_debug ("Created NiceStream (%u created, %u destroyed)",
158 n_streams_created, n_streams_destroyed);
160 stream->n_components = 0;
161 stream->initial_binding_request_received = FALSE;
164 /* Must be called with the agent lock released as it could dispose of
167 nice_stream_finalize (GObject *obj)
171 stream = NICE_STREAM (obj);
173 g_free (stream->name);
174 g_slist_free_full (stream->components, (GDestroyNotify) g_object_unref);
176 g_atomic_int_inc (&n_streams_destroyed);
177 nice_debug ("Destroyed NiceStream (%u created, %u destroyed)",
178 n_streams_created, n_streams_destroyed);
180 G_OBJECT_CLASS (nice_stream_parent_class)->finalize (obj);