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.
21 * SECTION:gstwebrtc-dtlstransport
22 * @short_description: RTCDtlsTransport object
23 * @title: GstWebRTCDTLSTransport
24 * @see_also: #GstWebRTCRTPSender, #GstWebRTCRTPReceiver, #GstWebRTCICETransport
26 * - GstWebRTCDTLSTransport
28 * <https://www.w3.org/TR/webrtc/#rtcdtlstransport>
35 #include "dtlstransport.h"
37 #include "webrtc-priv.h"
39 #define GST_CAT_DEFAULT gst_webrtc_dtls_transport_debug
40 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
42 #define gst_webrtc_dtls_transport_parent_class parent_class
43 G_DEFINE_TYPE_WITH_CODE (GstWebRTCDTLSTransport, gst_webrtc_dtls_transport,
44 GST_TYPE_OBJECT, GST_DEBUG_CATEGORY_INIT (gst_webrtc_dtls_transport_debug,
45 "webrtcdtlstransport", 0, "webrtcdtlstransport");
62 PROP_REMOTE_CERTIFICATE
66 gst_webrtc_dtls_transport_set_transport (GstWebRTCDTLSTransport * transport,
67 GstWebRTCICETransport * ice)
69 gboolean notify = FALSE;
71 g_return_if_fail (GST_IS_WEBRTC_DTLS_TRANSPORT (transport));
72 g_return_if_fail (GST_IS_WEBRTC_ICE_TRANSPORT (ice));
74 GST_OBJECT_LOCK (transport);
76 gst_object_replace ((GstObject **) & transport->transport,
78 GST_OBJECT_UNLOCK (transport);
81 g_object_notify (G_OBJECT (transport), "transport");
85 gst_webrtc_dtls_transport_set_property (GObject * object, guint prop_id,
86 const GValue * value, GParamSpec * pspec)
88 GstWebRTCDTLSTransport *webrtc = GST_WEBRTC_DTLS_TRANSPORT (object);
92 webrtc->session_id = g_value_get_uint (value);
95 g_object_set_property (G_OBJECT (webrtc->dtlssrtpenc), "is-client",
98 case PROP_CERTIFICATE:
99 g_object_set_property (G_OBJECT (webrtc->dtlssrtpdec), "pem", value);
102 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
108 gst_webrtc_dtls_transport_get_property (GObject * object, guint prop_id,
109 GValue * value, GParamSpec * pspec)
111 GstWebRTCDTLSTransport *webrtc = GST_WEBRTC_DTLS_TRANSPORT (object);
114 case PROP_SESSION_ID:
115 g_value_set_uint (value, webrtc->session_id);
118 g_value_set_object (value, webrtc->transport);
121 g_value_set_enum (value, webrtc->state);
124 g_object_get_property (G_OBJECT (webrtc->dtlssrtpenc), "is-client",
127 case PROP_CERTIFICATE:
128 g_object_get_property (G_OBJECT (webrtc->dtlssrtpdec), "pem", value);
130 case PROP_REMOTE_CERTIFICATE:
131 g_object_get_property (G_OBJECT (webrtc->dtlssrtpdec), "peer-pem", value);
134 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
140 gst_webrtc_dtls_transport_finalize (GObject * object)
142 GstWebRTCDTLSTransport *webrtc = GST_WEBRTC_DTLS_TRANSPORT (object);
144 if (webrtc->transport) {
145 gst_object_unref (webrtc->transport);
147 webrtc->transport = NULL;
149 G_OBJECT_CLASS (parent_class)->finalize (object);
153 on_connection_state_changed (GObject * obj, GParamSpec * pspec,
156 GstWebRTCDTLSTransport *webrtc = GST_WEBRTC_DTLS_TRANSPORT (user_data);
159 g_object_get (obj, "connection-state", &state, NULL);
162 webrtc->state = GST_WEBRTC_DTLS_TRANSPORT_STATE_NEW;
165 webrtc->state = GST_WEBRTC_DTLS_TRANSPORT_STATE_CLOSED;
169 webrtc->state = GST_WEBRTC_DTLS_TRANSPORT_STATE_FAILED;
172 webrtc->state = GST_WEBRTC_DTLS_TRANSPORT_STATE_CONNECTING;
175 webrtc->state = GST_WEBRTC_DTLS_TRANSPORT_STATE_CONNECTED;
179 g_object_notify (G_OBJECT (webrtc), "state");
183 gst_webrtc_dtls_transport_constructed (GObject * object)
185 GstWebRTCDTLSTransport *webrtc = GST_WEBRTC_DTLS_TRANSPORT (object);
186 gchar *connection_id;
188 /* XXX: this may collide with another connection_id however this is only a
189 * problem if multiple dtls element sets are being used within the same
191 connection_id = g_strdup_printf ("rtp_%u_%u", webrtc->session_id,
194 webrtc->dtlssrtpenc = gst_element_factory_make ("dtlssrtpenc", NULL);
195 g_object_set (webrtc->dtlssrtpenc, "connection-id", connection_id,
196 "is-client", webrtc->client, "rtp-sync", FALSE, NULL);
198 webrtc->dtlssrtpdec = gst_element_factory_make ("dtlssrtpdec", NULL);
199 g_object_set (webrtc->dtlssrtpdec, "connection-id", connection_id, NULL);
200 g_free (connection_id);
202 g_signal_connect (webrtc->dtlssrtpenc, "notify::connection-state",
203 G_CALLBACK (on_connection_state_changed), webrtc);
205 G_OBJECT_CLASS (parent_class)->constructed (object);
209 gst_webrtc_dtls_transport_class_init (GstWebRTCDTLSTransportClass * klass)
211 GObjectClass *gobject_class = (GObjectClass *) klass;
213 gobject_class->constructed = gst_webrtc_dtls_transport_constructed;
214 gobject_class->get_property = gst_webrtc_dtls_transport_get_property;
215 gobject_class->set_property = gst_webrtc_dtls_transport_set_property;
216 gobject_class->finalize = gst_webrtc_dtls_transport_finalize;
218 g_object_class_install_property (gobject_class,
220 g_param_spec_uint ("session-id", "Session ID",
221 "Unique session ID", 0, G_MAXUINT, 0,
222 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
224 g_object_class_install_property (gobject_class,
226 g_param_spec_object ("transport", "ICE transport",
227 "ICE transport used by this dtls transport",
228 GST_TYPE_WEBRTC_ICE_TRANSPORT,
229 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
231 g_object_class_install_property (gobject_class,
233 g_param_spec_enum ("state", "DTLS state",
234 "State of the DTLS transport",
235 GST_TYPE_WEBRTC_DTLS_TRANSPORT_STATE,
236 GST_WEBRTC_DTLS_TRANSPORT_STATE_NEW,
237 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
239 g_object_class_install_property (gobject_class,
241 g_param_spec_boolean ("client", "DTLS client",
242 "Are we the client in the DTLS handshake?", FALSE,
243 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
245 g_object_class_install_property (gobject_class,
247 g_param_spec_string ("certificate", "DTLS certificate",
248 "DTLS certificate", NULL,
249 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
251 g_object_class_install_property (gobject_class,
252 PROP_REMOTE_CERTIFICATE,
253 g_param_spec_string ("remote-certificate", "Remote DTLS certificate",
254 "Remote DTLS certificate", NULL,
255 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
259 gst_webrtc_dtls_transport_init (GstWebRTCDTLSTransport * webrtc)
263 GstWebRTCDTLSTransport *
264 gst_webrtc_dtls_transport_new (guint session_id)
266 return g_object_new (GST_TYPE_WEBRTC_DTLS_TRANSPORT, "session-id", session_id,