rtsp-server:wfd: Fix build error for gcc upgrade
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / ext / webrtc / webrtctransceiver.c
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 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #endif
23
24 #include "gstwebrtcbin.h"
25 #include "utils.h"
26 #include "webrtctransceiver.h"
27
28 #define GST_CAT_DEFAULT webrtc_transceiver_debug
29 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
30
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");
36     );
37
38 #define DEFAULT_FEC_TYPE GST_WEBRTC_FEC_TYPE_NONE
39 #define DEFAULT_DO_NACK FALSE
40 #define DEFAULT_FEC_PERCENTAGE 100
41
42 enum
43 {
44   PROP_0,
45   PROP_WEBRTC,
46   PROP_FEC_TYPE,
47   PROP_FEC_PERCENTAGE,
48   PROP_DO_NACK,
49 };
50
51 void
52 webrtc_transceiver_set_transport (WebRTCTransceiver * trans,
53     TransportStream * stream)
54 {
55   GstWebRTCRTPTransceiver *rtp_trans;
56
57   g_return_if_fail (WEBRTC_IS_TRANSCEIVER (trans));
58
59   rtp_trans = GST_WEBRTC_RTP_TRANSCEIVER (trans);
60
61   gst_object_replace ((GstObject **) & trans->stream, (GstObject *) stream);
62
63   if (rtp_trans->sender) {
64     gst_object_replace ((GstObject **) & rtp_trans->sender->transport,
65         (GstObject *) stream->transport);
66     g_object_notify (G_OBJECT (rtp_trans->sender), "transport");
67   }
68
69   if (rtp_trans->receiver) {
70     gst_object_replace ((GstObject **) & rtp_trans->receiver->transport,
71         (GstObject *) stream->transport);
72     g_object_notify (G_OBJECT (rtp_trans->receiver), "transport");
73   }
74 }
75
76 GstWebRTCDTLSTransport *
77 webrtc_transceiver_get_dtls_transport (GstWebRTCRTPTransceiver * trans)
78 {
79   g_return_val_if_fail (WEBRTC_IS_TRANSCEIVER (trans), NULL);
80
81   if (trans->sender) {
82     return trans->sender->transport;
83   } else if (trans->receiver) {
84     return trans->receiver->transport;
85   }
86
87   return NULL;
88 }
89
90 static void
91 webrtc_transceiver_set_property (GObject * object, guint prop_id,
92     const GValue * value, GParamSpec * pspec)
93 {
94   WebRTCTransceiver *trans = WEBRTC_TRANSCEIVER (object);
95
96   switch (prop_id) {
97     case PROP_WEBRTC:
98       gst_object_set_parent (GST_OBJECT (trans), g_value_get_object (value));
99       break;
100   }
101
102   GST_OBJECT_LOCK (trans);
103   switch (prop_id) {
104     case PROP_WEBRTC:
105       break;
106     case PROP_FEC_TYPE:
107       trans->fec_type = g_value_get_enum (value);
108       break;
109     case PROP_DO_NACK:
110       trans->do_nack = g_value_get_boolean (value);
111       break;
112     case PROP_FEC_PERCENTAGE:
113       trans->fec_percentage = g_value_get_uint (value);
114       break;
115     default:
116       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
117       break;
118   }
119   GST_OBJECT_UNLOCK (trans);
120 }
121
122 static void
123 webrtc_transceiver_get_property (GObject * object, guint prop_id,
124     GValue * value, GParamSpec * pspec)
125 {
126   WebRTCTransceiver *trans = WEBRTC_TRANSCEIVER (object);
127
128   GST_OBJECT_LOCK (trans);
129   switch (prop_id) {
130     case PROP_FEC_TYPE:
131       g_value_set_enum (value, trans->fec_type);
132       break;
133     case PROP_DO_NACK:
134       g_value_set_boolean (value, trans->do_nack);
135       break;
136     case PROP_FEC_PERCENTAGE:
137       g_value_set_uint (value, trans->fec_percentage);
138       break;
139     default:
140       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
141       break;
142   }
143   GST_OBJECT_UNLOCK (trans);
144 }
145
146 static void
147 webrtc_transceiver_finalize (GObject * object)
148 {
149   WebRTCTransceiver *trans = WEBRTC_TRANSCEIVER (object);
150
151   gst_clear_object (&trans->stream);
152   gst_clear_object (&trans->ulpfecdec);
153   gst_clear_object (&trans->ulpfecenc);
154   gst_clear_object (&trans->redenc);
155
156   if (trans->local_rtx_ssrc_map)
157     gst_structure_free (trans->local_rtx_ssrc_map);
158   trans->local_rtx_ssrc_map = NULL;
159
160   gst_caps_replace (&trans->last_retrieved_caps, NULL);
161   gst_caps_replace (&trans->last_send_configured_caps, NULL);
162
163   g_free (trans->pending_mid);
164
165   gst_event_replace (&trans->tos_event, NULL);
166
167   G_OBJECT_CLASS (parent_class)->finalize (object);
168 }
169
170 static void
171 webrtc_transceiver_class_init (WebRTCTransceiverClass * klass)
172 {
173   GObjectClass *gobject_class = (GObjectClass *) klass;
174
175   gobject_class->get_property = webrtc_transceiver_get_property;
176   gobject_class->set_property = webrtc_transceiver_set_property;
177   gobject_class->finalize = webrtc_transceiver_finalize;
178
179   /* some acrobatics are required to set the parent before _constructed()
180    * has been called */
181   g_object_class_install_property (gobject_class,
182       PROP_WEBRTC,
183       g_param_spec_object ("webrtc", "Parent webrtcbin",
184           "Parent webrtcbin",
185           GST_TYPE_WEBRTC_BIN,
186           G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
187
188   g_object_class_install_property (gobject_class,
189       PROP_FEC_TYPE,
190       g_param_spec_enum ("fec-type", "FEC type",
191           "The type of Forward Error Correction to use",
192           GST_TYPE_WEBRTC_FEC_TYPE,
193           DEFAULT_FEC_TYPE,
194           G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
195
196   g_object_class_install_property (gobject_class,
197       PROP_DO_NACK,
198       g_param_spec_boolean ("do-nack", "Do nack",
199           "Whether to send negative acknowledgements for feedback",
200           DEFAULT_DO_NACK,
201           G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
202
203   g_object_class_install_property (gobject_class,
204       PROP_FEC_PERCENTAGE,
205       g_param_spec_uint ("fec-percentage", "FEC percentage",
206           "The amount of Forward Error Correction to apply",
207           0, 100, DEFAULT_FEC_PERCENTAGE,
208           G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
209 }
210
211 static void
212 webrtc_transceiver_init (WebRTCTransceiver * trans)
213 {
214 }
215
216 WebRTCTransceiver *
217 webrtc_transceiver_new (GstWebRTCBin * webrtc, GstWebRTCRTPSender * sender,
218     GstWebRTCRTPReceiver * receiver)
219 {
220   WebRTCTransceiver *trans;
221
222   trans = g_object_new (webrtc_transceiver_get_type (), "sender", sender,
223       "receiver", receiver, "webrtc", webrtc, NULL);
224
225   return trans;
226 }