1 /* GStreamer
2 * Copyright (C) 2017 Matthew Waters <matthew@centricular.com>
3 *
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.
8 *
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.
13 *
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.
18 */
19
20 /**
21 * SECTION:gstwebrtc-transceiver
22 * @short_description: RTCRtpTransceiver object
23 * @title: GstWebRTCRTPTransceiver
24 * @see_also: #GstWebRTCRTPSender, #GstWebRTCRTPReceiver
25 *
26 * <https://www.w3.org/TR/webrtc/#rtcrtptransceiver-interface>
27 */
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include "rtptransceiver.h"
34
35 #include "webrtc-priv.h"
36
37 #define GST_CAT_DEFAULT gst_webrtc_rtp_transceiver_debug
38 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
39
40 #define gst_webrtc_rtp_transceiver_parent_class parent_class
41 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstWebRTCRTPTransceiver,
42 gst_webrtc_rtp_transceiver, GST_TYPE_OBJECT,
43 GST_DEBUG_CATEGORY_INIT (gst_webrtc_rtp_transceiver_debug,
44 "webrtcrtptransceiver", 0, "webrtcrtptransceiver");
45 );
46
47 enum
48 {
49 SIGNAL_0,
50 LAST_SIGNAL,
51 };
52
53 enum
54 {
55 PROP_0,
56 PROP_SENDER,
57 PROP_RECEIVER,
58 PROP_DIRECTION,
59 PROP_MLINE,
60 PROP_MID,
61 PROP_CURRENT_DIRECTION,
62 PROP_KIND,
63 PROP_CODEC_PREFERENCES,
64 PROP_STOPPED, // FIXME
65 };
66
67 //static guint gst_webrtc_rtp_transceiver_signals[LAST_SIGNAL] = { 0 };
68
69 static void
gst_webrtc_rtp_transceiver_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)70 gst_webrtc_rtp_transceiver_set_property (GObject * object, guint prop_id,
71 const GValue * value, GParamSpec * pspec)
72 {
73 GstWebRTCRTPTransceiver *webrtc = GST_WEBRTC_RTP_TRANSCEIVER (object);
74
75 switch (prop_id) {
76 case PROP_SENDER:
77 webrtc->sender = g_value_dup_object (value);
78 break;
79 case PROP_RECEIVER:
80 webrtc->receiver = g_value_dup_object (value);
81 break;
82 case PROP_MLINE:
83 webrtc->mline = g_value_get_uint (value);
84 break;
85 case PROP_DIRECTION:
86 GST_OBJECT_LOCK (webrtc);
87 webrtc->direction = g_value_get_enum (value);
88 GST_OBJECT_UNLOCK (webrtc);
89 break;
90 case PROP_CODEC_PREFERENCES:
91 GST_OBJECT_LOCK (webrtc);
92 gst_caps_replace (&webrtc->codec_preferences, g_value_get_boxed (value));
93 GST_OBJECT_UNLOCK (webrtc);
94 break;
95 default:
96 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
97 break;
98 }
99 }
100
101 static void
gst_webrtc_rtp_transceiver_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)102 gst_webrtc_rtp_transceiver_get_property (GObject * object, guint prop_id,
103 GValue * value, GParamSpec * pspec)
104 {
105 GstWebRTCRTPTransceiver *webrtc = GST_WEBRTC_RTP_TRANSCEIVER (object);
106
107 switch (prop_id) {
108 case PROP_MID:
109 g_value_set_string (value, webrtc->mid);
110 break;
111 case PROP_SENDER:
112 g_value_set_object (value, webrtc->sender);
113 break;
114 case PROP_RECEIVER:
115 g_value_set_object (value, webrtc->receiver);
116 break;
117 case PROP_MLINE:
118 g_value_set_uint (value, webrtc->mline);
119 break;
120 case PROP_DIRECTION:
121 GST_OBJECT_LOCK (webrtc);
122 g_value_set_enum (value, webrtc->direction);
123 GST_OBJECT_UNLOCK (webrtc);
124 break;
125 case PROP_CURRENT_DIRECTION:
126 g_value_set_enum (value, webrtc->current_direction);
127 break;
128 case PROP_KIND:
129 g_value_set_enum (value, webrtc->kind);
130 break;
131 case PROP_CODEC_PREFERENCES:
132 GST_OBJECT_LOCK (webrtc);
133 gst_value_set_caps (value, webrtc->codec_preferences);
134 GST_OBJECT_UNLOCK (webrtc);
135 break;
136 default:
137 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
138 break;
139 }
140 }
141
142 static void
gst_webrtc_rtp_transceiver_constructed(GObject * object)143 gst_webrtc_rtp_transceiver_constructed (GObject * object)
144 {
145 GstWebRTCRTPTransceiver *webrtc = GST_WEBRTC_RTP_TRANSCEIVER (object);
146
147 gst_object_set_parent (GST_OBJECT (webrtc->sender), GST_OBJECT (webrtc));
148 gst_object_set_parent (GST_OBJECT (webrtc->receiver), GST_OBJECT (webrtc));
149
150 G_OBJECT_CLASS (parent_class)->constructed (object);
151 }
152
153 static void
gst_webrtc_rtp_transceiver_dispose(GObject * object)154 gst_webrtc_rtp_transceiver_dispose (GObject * object)
155 {
156 GstWebRTCRTPTransceiver *webrtc = GST_WEBRTC_RTP_TRANSCEIVER (object);
157
158 if (webrtc->sender) {
159 GST_OBJECT_PARENT (webrtc->sender) = NULL;
160 gst_object_unref (webrtc->sender);
161 }
162 webrtc->sender = NULL;
163 if (webrtc->receiver) {
164 GST_OBJECT_PARENT (webrtc->receiver) = NULL;
165 gst_object_unref (webrtc->receiver);
166 }
167 webrtc->receiver = NULL;
168
169 G_OBJECT_CLASS (parent_class)->dispose (object);
170 }
171
172 static void
gst_webrtc_rtp_transceiver_finalize(GObject * object)173 gst_webrtc_rtp_transceiver_finalize (GObject * object)
174 {
175 GstWebRTCRTPTransceiver *webrtc = GST_WEBRTC_RTP_TRANSCEIVER (object);
176
177 g_free (webrtc->mid);
178 if (webrtc->codec_preferences)
179 gst_caps_unref (webrtc->codec_preferences);
180
181 G_OBJECT_CLASS (parent_class)->finalize (object);
182 }
183
184 static void
gst_webrtc_rtp_transceiver_class_init(GstWebRTCRTPTransceiverClass * klass)185 gst_webrtc_rtp_transceiver_class_init (GstWebRTCRTPTransceiverClass * klass)
186 {
187 GObjectClass *gobject_class = (GObjectClass *) klass;
188
189 gobject_class->get_property = gst_webrtc_rtp_transceiver_get_property;
190 gobject_class->set_property = gst_webrtc_rtp_transceiver_set_property;
191 gobject_class->constructed = gst_webrtc_rtp_transceiver_constructed;
192 gobject_class->dispose = gst_webrtc_rtp_transceiver_dispose;
193 gobject_class->finalize = gst_webrtc_rtp_transceiver_finalize;
194
195 g_object_class_install_property (gobject_class,
196 PROP_SENDER,
197 g_param_spec_object ("sender", "Sender",
198 "The RTP sender for this transceiver",
199 GST_TYPE_WEBRTC_RTP_SENDER,
200 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
201
202 g_object_class_install_property (gobject_class,
203 PROP_RECEIVER,
204 g_param_spec_object ("receiver", "Receiver",
205 "The RTP receiver for this transceiver",
206 GST_TYPE_WEBRTC_RTP_RECEIVER,
207 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
208
209 g_object_class_install_property (gobject_class,
210 PROP_MLINE,
211 g_param_spec_uint ("mlineindex", "Media Line Index",
212 "Index in the SDP of the Media",
213 0, G_MAXUINT, 0,
214 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
215
216 /**
217 * GstWebRTCRTPTransceiver:direction:
218 *
219 * Direction of the transceiver.
220 *
221 * Since: 1.18
222 **/
223 g_object_class_install_property (gobject_class,
224 PROP_DIRECTION,
225 g_param_spec_enum ("direction", "Direction",
226 "Transceiver direction",
227 GST_TYPE_WEBRTC_RTP_TRANSCEIVER_DIRECTION,
228 GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_NONE,
229 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
230
231 /**
232 * GstWebRTCRTPTransceiver:mid:
233 *
234 * The media ID of the m-line associated with this transceiver. This
235 * association is established, when possible, whenever either a
236 * local or remote description is applied. This field is null if
237 * neither a local or remote description has been applied, or if its
238 * associated m-line is rejected by either a remote offer or any
239 * answer.
240 *
241 * Since: 1.20
242 */
243 g_object_class_install_property (gobject_class,
244 PROP_MID,
245 g_param_spec_string ("mid", "Media ID",
246 "The media ID of the m-line associated with this transceiver. This "
247 " association is established, when possible, whenever either a local"
248 " or remote description is applied. This field is null if neither a"
249 " local or remote description has been applied, or if its associated"
250 " m-line is rejected by either a remote offer or any answer.",
251 NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
252
253 /**
254 * GstWebRTCRTPTransceiver:current-direction:
255 *
256 * The transceiver's current directionality, or none if the
257 * transceiver is stopped or has never participated in an exchange
258 * of offers and answers. To change the transceiver's
259 * directionality, set the value of the direction property.
260 *
261 * Since: 1.20
262 **/
263 g_object_class_install_property (gobject_class,
264 PROP_DIRECTION,
265 g_param_spec_enum ("current-direction", "Current Direction",
266 "Transceiver current direction",
267 GST_TYPE_WEBRTC_RTP_TRANSCEIVER_DIRECTION,
268 GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_NONE,
269 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
270
271 /**
272 * GstWebRTCRTPTransceiver:kind:
273 *
274 * The kind of media this transceiver transports
275 *
276 * Since: 1.20
277 **/
278 g_object_class_install_property (gobject_class,
279 PROP_KIND,
280 g_param_spec_enum ("kind", "Media Kind",
281 "Kind of media this transceiver transports",
282 GST_TYPE_WEBRTC_KIND, GST_WEBRTC_KIND_UNKNOWN,
283 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
284
285 /**
286 * GstWebRTCRTPTransceiver:codec-preferences:
287 *
288 * Caps representing the codec preferences.
289 *
290 * Since: 1.20
291 **/
292 g_object_class_install_property (gobject_class,
293 PROP_CODEC_PREFERENCES,
294 g_param_spec_boxed ("codec-preferences", "Codec Preferences",
295 "Caps representing the codec preferences.",
296 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
297 }
298
299 static void
gst_webrtc_rtp_transceiver_init(GstWebRTCRTPTransceiver * webrtc)300 gst_webrtc_rtp_transceiver_init (GstWebRTCRTPTransceiver * webrtc)
301 {
302 webrtc->direction = GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_NONE;
303 }
304