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 * <ulink url="https://www.w3.org/TR/webrtc/#rtcdtlstransport">https://www.w3.org/TR/webrtc/#rtcdtlstransport</ulink>
33 #include "dtlstransport.h"
35 #define GST_CAT_DEFAULT gst_webrtc_dtls_transport_debug
36 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
38 #define gst_webrtc_dtls_transport_parent_class parent_class
39 G_DEFINE_TYPE_WITH_CODE (GstWebRTCDTLSTransport, gst_webrtc_dtls_transport,
40 GST_TYPE_OBJECT, GST_DEBUG_CATEGORY_INIT (gst_webrtc_dtls_transport_debug,
41 "dtlstransport", 0, "dtlstransport");
58 PROP_REMOTE_CERTIFICATE,
63 gst_webrtc_dtls_transport_set_transport (GstWebRTCDTLSTransport * transport,
64 GstWebRTCICETransport * ice)
66 g_return_if_fail (GST_IS_WEBRTC_DTLS_TRANSPORT (transport));
67 g_return_if_fail (GST_IS_WEBRTC_ICE_TRANSPORT (ice));
69 gst_object_replace ((GstObject **) & transport->transport, GST_OBJECT (ice));
73 gst_webrtc_dtls_transport_set_property (GObject * object, guint prop_id,
74 const GValue * value, GParamSpec * pspec)
76 GstWebRTCDTLSTransport *webrtc = GST_WEBRTC_DTLS_TRANSPORT (object);
80 webrtc->session_id = g_value_get_uint (value);
83 g_object_set_property (G_OBJECT (webrtc->dtlssrtpenc), "is-client",
85 gst_element_set_locked_state (webrtc->dtlssrtpenc, FALSE);
86 gst_element_sync_state_with_parent (webrtc->dtlssrtpenc);
88 case PROP_CERTIFICATE:
89 g_object_set_property (G_OBJECT (webrtc->dtlssrtpdec), "pem", value);
92 webrtc->is_rtcp = g_value_get_boolean (value);
95 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
101 gst_webrtc_dtls_transport_get_property (GObject * object, guint prop_id,
102 GValue * value, GParamSpec * pspec)
104 GstWebRTCDTLSTransport *webrtc = GST_WEBRTC_DTLS_TRANSPORT (object);
107 case PROP_SESSION_ID:
108 g_value_set_uint (value, webrtc->session_id);
111 g_value_set_object (value, webrtc->transport);
114 g_value_set_enum (value, webrtc->state);
117 g_object_get_property (G_OBJECT (webrtc->dtlssrtpenc), "is-client",
120 case PROP_CERTIFICATE:
121 g_object_get_property (G_OBJECT (webrtc->dtlssrtpdec), "pem", value);
123 case PROP_REMOTE_CERTIFICATE:
124 g_object_get_property (G_OBJECT (webrtc->dtlssrtpdec), "peer-pem", value);
127 g_value_set_boolean (value, webrtc->is_rtcp);
130 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
136 gst_webrtc_dtls_transport_finalize (GObject * object)
138 GstWebRTCDTLSTransport *webrtc = GST_WEBRTC_DTLS_TRANSPORT (object);
140 if (webrtc->transport) {
141 gst_object_unref (webrtc->transport);
143 webrtc->transport = NULL;
145 G_OBJECT_CLASS (parent_class)->finalize (object);
149 gst_webrtc_dtls_transport_constructed (GObject * object)
151 GstWebRTCDTLSTransport *webrtc = GST_WEBRTC_DTLS_TRANSPORT (object);
152 gchar *connection_id;
154 /* XXX: this may collide with another connection_id however this is only a
155 * problem if multiple dtls element sets are being used within the same
157 connection_id = g_strdup_printf ("%s_%u_%u", webrtc->is_rtcp ? "rtcp" : "rtp",
158 webrtc->session_id, g_random_int ());
160 webrtc->dtlssrtpenc = gst_element_factory_make ("dtlssrtpenc", NULL);
161 g_object_set (webrtc->dtlssrtpenc, "connection-id", connection_id,
162 "is-client", webrtc->client, NULL);
164 webrtc->dtlssrtpdec = gst_element_factory_make ("dtlssrtpdec", NULL);
165 g_object_set (webrtc->dtlssrtpdec, "connection-id", connection_id, NULL);
166 g_free (connection_id);
168 G_OBJECT_CLASS (parent_class)->constructed (object);
172 gst_webrtc_dtls_transport_class_init (GstWebRTCDTLSTransportClass * klass)
174 GObjectClass *gobject_class = (GObjectClass *) klass;
176 gobject_class->constructed = gst_webrtc_dtls_transport_constructed;
177 gobject_class->get_property = gst_webrtc_dtls_transport_get_property;
178 gobject_class->set_property = gst_webrtc_dtls_transport_set_property;
179 gobject_class->finalize = gst_webrtc_dtls_transport_finalize;
181 g_object_class_install_property (gobject_class,
183 g_param_spec_uint ("session-id", "Session ID",
184 "Unique session ID", 0, G_MAXUINT, 0,
185 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
187 g_object_class_install_property (gobject_class,
189 g_param_spec_object ("transport", "ICE transport",
190 "ICE transport used by this dtls transport",
191 GST_TYPE_WEBRTC_ICE_TRANSPORT,
192 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
194 /* FIXME: implement */
195 g_object_class_install_property (gobject_class,
197 g_param_spec_enum ("state", "DTLS state",
198 "State of the DTLS transport",
199 GST_TYPE_WEBRTC_DTLS_TRANSPORT_STATE,
200 GST_WEBRTC_DTLS_TRANSPORT_STATE_NEW,
201 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
203 g_object_class_install_property (gobject_class,
205 g_param_spec_boolean ("client", "DTLS client",
206 "Are we the client in the DTLS handshake?", FALSE,
207 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
209 g_object_class_install_property (gobject_class,
211 g_param_spec_string ("certificate", "DTLS certificate",
212 "DTLS certificate", NULL,
213 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
215 g_object_class_install_property (gobject_class,
216 PROP_REMOTE_CERTIFICATE,
217 g_param_spec_string ("remote-certificate", "Remote DTLS certificate",
218 "Remote DTLS certificate", NULL,
219 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
221 g_object_class_install_property (gobject_class,
223 g_param_spec_boolean ("rtcp", "RTCP",
224 "The transport is being used solely for RTCP", FALSE,
225 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
229 gst_webrtc_dtls_transport_init (GstWebRTCDTLSTransport * webrtc)
233 GstWebRTCDTLSTransport *
234 gst_webrtc_dtls_transport_new (guint session_id, gboolean is_rtcp)
236 return g_object_new (GST_TYPE_WEBRTC_DTLS_TRANSPORT, "session-id", session_id,
237 "rtcp", is_rtcp, NULL);