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.
24 #include "icestream.h"
25 #include "nicetransport.h"
27 #define GST_CAT_DEFAULT gst_webrtc_ice_stream_debug
28 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
30 #define gst_webrtc_ice_stream_parent_class parent_class
31 G_DEFINE_TYPE_WITH_CODE (GstWebRTCICEStream, gst_webrtc_ice_stream,
33 GST_DEBUG_CATEGORY_INIT (gst_webrtc_ice_stream_debug,
34 "webrtcicestream", 0, "webrtcicestream"););
49 //static guint gst_webrtc_ice_stream_signals[LAST_SIGNAL] = { 0 };
51 struct _GstWebRTCICEStreamPrivate
58 gst_webrtc_ice_stream_set_property (GObject * object, guint prop_id,
59 const GValue * value, GParamSpec * pspec)
61 GstWebRTCICEStream *stream = GST_WEBRTC_ICE_STREAM (object);
65 /* XXX: weak-ref this? */
66 stream->ice = g_value_get_object (value);
69 stream->stream_id = g_value_get_uint (value);
72 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
78 gst_webrtc_ice_stream_get_property (GObject * object, guint prop_id,
79 GValue * value, GParamSpec * pspec)
81 GstWebRTCICEStream *stream = GST_WEBRTC_ICE_STREAM (object);
85 g_value_set_object (value, stream->ice);
88 g_value_set_uint (value, stream->stream_id);
91 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
97 gst_webrtc_ice_stream_finalize (GObject * object)
99 GstWebRTCICEStream *stream = GST_WEBRTC_ICE_STREAM (object);
101 g_list_free (stream->priv->transports);
102 stream->priv->transports = NULL;
104 G_OBJECT_CLASS (parent_class)->finalize (object);
108 _on_candidate_gathering_done (NiceAgent * agent, guint stream_id,
109 GstWebRTCICEStream * ice)
113 if (stream_id != ice->stream_id)
116 GST_DEBUG_OBJECT (ice, "%u gathering done", stream_id);
118 ice->priv->gathered = TRUE;
120 for (l = ice->priv->transports; l; l = l->next) {
121 GstWebRTCICETransport *ice = l->data;
123 gst_webrtc_ice_transport_gathering_state_change (ice,
124 GST_WEBRTC_ICE_GATHERING_STATE_COMPLETE);
128 GstWebRTCICETransport *
129 gst_webrtc_ice_stream_find_transport (GstWebRTCICEStream * stream,
130 GstWebRTCICEComponent component)
132 GstWebRTCICEComponent trans_comp;
133 GstWebRTCICETransport *ret;
136 g_return_val_if_fail (GST_IS_WEBRTC_ICE_STREAM (stream), NULL);
138 for (l = stream->priv->transports; l; l = l->next) {
139 GstWebRTCICETransport *trans = l->data;
140 g_object_get (trans, "component", &trans_comp, NULL);
142 if (component == trans_comp)
143 return gst_object_ref (trans);
147 GST_WEBRTC_ICE_TRANSPORT (gst_webrtc_nice_transport_new (stream,
149 stream->priv->transports = g_list_prepend (stream->priv->transports, ret);
155 gst_webrtc_ice_stream_constructed (GObject * object)
157 GstWebRTCICEStream *stream = GST_WEBRTC_ICE_STREAM (object);
160 g_object_get (stream->ice, "agent", &agent, NULL);
161 g_signal_connect (agent, "candidate-gathering-done",
162 G_CALLBACK (_on_candidate_gathering_done), stream);
164 g_object_unref (agent);
166 G_OBJECT_CLASS (parent_class)->constructed (object);
170 gst_webrtc_ice_stream_gather_candidates (GstWebRTCICEStream * stream)
175 g_return_val_if_fail (GST_IS_WEBRTC_ICE_STREAM (stream), FALSE);
177 GST_DEBUG_OBJECT (stream, "start gathering candidates");
179 if (stream->priv->gathered)
182 for (l = stream->priv->transports; l; l = l->next) {
183 GstWebRTCICETransport *trans = l->data;
185 gst_webrtc_ice_transport_gathering_state_change (trans,
186 GST_WEBRTC_ICE_GATHERING_STATE_GATHERING);
189 g_object_get (stream->ice, "agent", &agent, NULL);
190 if (!nice_agent_gather_candidates (agent, stream->stream_id)) {
191 g_object_unref (agent);
195 g_object_unref (agent);
200 gst_webrtc_ice_stream_class_init (GstWebRTCICEStreamClass * klass)
202 GObjectClass *gobject_class = (GObjectClass *) klass;
204 g_type_class_add_private (klass, sizeof (GstWebRTCICEStreamPrivate));
206 gobject_class->constructed = gst_webrtc_ice_stream_constructed;
207 gobject_class->get_property = gst_webrtc_ice_stream_get_property;
208 gobject_class->set_property = gst_webrtc_ice_stream_set_property;
209 gobject_class->finalize = gst_webrtc_ice_stream_finalize;
211 g_object_class_install_property (gobject_class,
213 g_param_spec_object ("ice",
214 "ICE", "ICE agent associated with this stream",
216 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
218 g_object_class_install_property (gobject_class,
220 g_param_spec_uint ("stream-id",
221 "ICE stream id", "ICE stream id associated with this stream",
223 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
227 gst_webrtc_ice_stream_init (GstWebRTCICEStream * ice)
230 G_TYPE_INSTANCE_GET_PRIVATE ((ice), GST_TYPE_WEBRTC_ICE_STREAM,
231 GstWebRTCICEStreamPrivate);
235 gst_webrtc_ice_stream_new (GstWebRTCICE * ice, guint stream_id)
237 return g_object_new (GST_TYPE_WEBRTC_ICE_STREAM, "ice", ice,
238 "stream-id", stream_id, NULL);