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 "gstwebrtcbin.h"
26 #include "webrtctransceiver.h"
28 #define GST_CAT_DEFAULT webrtc_transceiver_debug
29 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
31 #define webrtc_transceiver_parent_class parent_class
32 G_DEFINE_TYPE_WITH_CODE (WebRTCTransceiver, webrtc_transceiver,
33 GST_TYPE_WEBRTC_RTP_TRANSCEIVER,
34 GST_DEBUG_CATEGORY_INIT (webrtc_transceiver_debug,
35 "webrtctransceiver", 0, "webrtctransceiver"););
37 #define DEFAULT_FEC_TYPE GST_WEBRTC_FEC_TYPE_NONE
38 #define DEFAULT_DO_NACK FALSE
39 #define DEFAULT_FEC_PERCENTAGE 100
51 webrtc_transceiver_set_transport (WebRTCTransceiver * trans,
52 TransportStream * stream)
54 GstWebRTCRTPTransceiver *rtp_trans;
56 g_return_if_fail (WEBRTC_IS_TRANSCEIVER (trans));
58 rtp_trans = GST_WEBRTC_RTP_TRANSCEIVER (trans);
60 gst_object_replace ((GstObject **) & trans->stream, (GstObject *) stream);
62 if (rtp_trans->sender) {
63 gst_object_replace ((GstObject **) & rtp_trans->sender->transport,
64 (GstObject *) stream->transport);
65 g_object_notify (G_OBJECT (rtp_trans->sender), "transport");
68 if (rtp_trans->receiver) {
69 gst_object_replace ((GstObject **) & rtp_trans->receiver->transport,
70 (GstObject *) stream->transport);
71 g_object_notify (G_OBJECT (rtp_trans->receiver), "transport");
75 GstWebRTCDTLSTransport *
76 webrtc_transceiver_get_dtls_transport (GstWebRTCRTPTransceiver * trans)
78 g_return_val_if_fail (WEBRTC_IS_TRANSCEIVER (trans), NULL);
81 return trans->sender->transport;
82 } else if (trans->receiver) {
83 return trans->receiver->transport;
90 webrtc_transceiver_set_property (GObject * object, guint prop_id,
91 const GValue * value, GParamSpec * pspec)
93 WebRTCTransceiver *trans = WEBRTC_TRANSCEIVER (object);
97 gst_object_set_parent (GST_OBJECT (trans), g_value_get_object (value));
101 GST_OBJECT_LOCK (trans);
106 trans->fec_type = g_value_get_enum (value);
109 trans->do_nack = g_value_get_boolean (value);
111 case PROP_FEC_PERCENTAGE:
112 trans->fec_percentage = g_value_get_uint (value);
115 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
118 GST_OBJECT_UNLOCK (trans);
122 webrtc_transceiver_get_property (GObject * object, guint prop_id,
123 GValue * value, GParamSpec * pspec)
125 WebRTCTransceiver *trans = WEBRTC_TRANSCEIVER (object);
127 GST_OBJECT_LOCK (trans);
130 g_value_set_enum (value, trans->fec_type);
133 g_value_set_boolean (value, trans->do_nack);
135 case PROP_FEC_PERCENTAGE:
136 g_value_set_uint (value, trans->fec_percentage);
139 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
142 GST_OBJECT_UNLOCK (trans);
146 webrtc_transceiver_finalize (GObject * object)
148 WebRTCTransceiver *trans = WEBRTC_TRANSCEIVER (object);
151 gst_object_unref (trans->stream);
152 trans->stream = NULL;
154 if (trans->local_rtx_ssrc_map)
155 gst_structure_free (trans->local_rtx_ssrc_map);
156 trans->local_rtx_ssrc_map = NULL;
158 gst_caps_replace (&trans->last_configured_caps, NULL);
160 if (trans->ssrc_event)
161 gst_event_unref (trans->ssrc_event);
162 trans->ssrc_event = NULL;
164 G_OBJECT_CLASS (parent_class)->finalize (object);
168 webrtc_transceiver_class_init (WebRTCTransceiverClass * klass)
170 GObjectClass *gobject_class = (GObjectClass *) klass;
172 gobject_class->get_property = webrtc_transceiver_get_property;
173 gobject_class->set_property = webrtc_transceiver_set_property;
174 gobject_class->finalize = webrtc_transceiver_finalize;
176 /* some acrobatics are required to set the parent before _constructed()
178 g_object_class_install_property (gobject_class,
180 g_param_spec_object ("webrtc", "Parent webrtcbin",
183 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
185 g_object_class_install_property (gobject_class,
187 g_param_spec_enum ("fec-type", "FEC type",
188 "The type of Forward Error Correction to use",
189 GST_TYPE_WEBRTC_FEC_TYPE,
191 G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
193 g_object_class_install_property (gobject_class,
195 g_param_spec_boolean ("do-nack", "Do nack",
196 "Whether to send negative acknowledgements for feedback",
198 G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
200 g_object_class_install_property (gobject_class,
202 g_param_spec_uint ("fec-percentage", "FEC percentage",
203 "The amount of Forward Error Correction to apply",
204 0, 100, DEFAULT_FEC_PERCENTAGE,
205 G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
209 webrtc_transceiver_init (WebRTCTransceiver * trans)
214 webrtc_transceiver_new (GstWebRTCBin * webrtc, GstWebRTCRTPSender * sender,
215 GstWebRTCRTPReceiver * receiver)
217 WebRTCTransceiver *trans;
219 trans = g_object_new (webrtc_transceiver_get_type (), "sender", sender,
220 "receiver", receiver, "webrtc", webrtc, NULL);