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-sender
22  * @short_description: RTCRtpSender object
23  * @title: GstWebRTCRTPSender
24  * @see_also: #GstWebRTCRTPReceiver, #GstWebRTCRTPTransceiver
25  *
26  * <ulink url="https://www.w3.org/TR/webrtc/#rtcrtpsender-interface">https://www.w3.org/TR/webrtc/#rtcrtpsender-interface</ulink>
27  */
28 
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32 
33 #include "rtpsender.h"
34 #include "rtptransceiver.h"
35 
36 #define GST_CAT_DEFAULT gst_webrtc_rtp_sender_debug
37 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
38 
39 #define gst_webrtc_rtp_sender_parent_class parent_class
40 G_DEFINE_TYPE_WITH_CODE (GstWebRTCRTPSender, gst_webrtc_rtp_sender,
41     GST_TYPE_OBJECT, GST_DEBUG_CATEGORY_INIT (gst_webrtc_rtp_sender_debug,
42         "webrtcsender", 0, "webrtcsender");
43     );
44 
45 enum
46 {
47   SIGNAL_0,
48   LAST_SIGNAL,
49 };
50 
51 enum
52 {
53   PROP_0,
54   PROP_MID,
55   PROP_SENDER,
56   PROP_STOPPED,
57   PROP_DIRECTION,
58 };
59 
60 //static guint gst_webrtc_rtp_sender_signals[LAST_SIGNAL] = { 0 };
61 
62 void
gst_webrtc_rtp_sender_set_transport(GstWebRTCRTPSender * sender,GstWebRTCDTLSTransport * transport)63 gst_webrtc_rtp_sender_set_transport (GstWebRTCRTPSender * sender,
64     GstWebRTCDTLSTransport * transport)
65 {
66   g_return_if_fail (GST_IS_WEBRTC_RTP_SENDER (sender));
67   g_return_if_fail (GST_IS_WEBRTC_DTLS_TRANSPORT (transport));
68 
69   GST_OBJECT_LOCK (sender);
70   gst_object_replace ((GstObject **) & sender->transport,
71       GST_OBJECT (transport));
72   GST_OBJECT_UNLOCK (sender);
73 }
74 
75 void
gst_webrtc_rtp_sender_set_rtcp_transport(GstWebRTCRTPSender * sender,GstWebRTCDTLSTransport * transport)76 gst_webrtc_rtp_sender_set_rtcp_transport (GstWebRTCRTPSender * sender,
77     GstWebRTCDTLSTransport * transport)
78 {
79   g_return_if_fail (GST_IS_WEBRTC_RTP_SENDER (sender));
80   g_return_if_fail (GST_IS_WEBRTC_DTLS_TRANSPORT (transport));
81 
82   GST_OBJECT_LOCK (sender);
83   gst_object_replace ((GstObject **) & sender->rtcp_transport,
84       GST_OBJECT (transport));
85   GST_OBJECT_UNLOCK (sender);
86 }
87 
88 static void
gst_webrtc_rtp_sender_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)89 gst_webrtc_rtp_sender_set_property (GObject * object, guint prop_id,
90     const GValue * value, GParamSpec * pspec)
91 {
92   switch (prop_id) {
93     default:
94       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
95       break;
96   }
97 }
98 
99 static void
gst_webrtc_rtp_sender_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)100 gst_webrtc_rtp_sender_get_property (GObject * object, guint prop_id,
101     GValue * value, GParamSpec * pspec)
102 {
103   switch (prop_id) {
104     default:
105       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
106       break;
107   }
108 }
109 
110 static void
gst_webrtc_rtp_sender_finalize(GObject * object)111 gst_webrtc_rtp_sender_finalize (GObject * object)
112 {
113   GstWebRTCRTPSender *webrtc = GST_WEBRTC_RTP_SENDER (object);
114 
115   if (webrtc->transport)
116     gst_object_unref (webrtc->transport);
117   webrtc->transport = NULL;
118 
119   if (webrtc->rtcp_transport)
120     gst_object_unref (webrtc->rtcp_transport);
121   webrtc->rtcp_transport = NULL;
122 
123   G_OBJECT_CLASS (parent_class)->finalize (object);
124 }
125 
126 static void
gst_webrtc_rtp_sender_class_init(GstWebRTCRTPSenderClass * klass)127 gst_webrtc_rtp_sender_class_init (GstWebRTCRTPSenderClass * klass)
128 {
129   GObjectClass *gobject_class = (GObjectClass *) klass;
130 
131   gobject_class->get_property = gst_webrtc_rtp_sender_get_property;
132   gobject_class->set_property = gst_webrtc_rtp_sender_set_property;
133   gobject_class->finalize = gst_webrtc_rtp_sender_finalize;
134 }
135 
136 static void
gst_webrtc_rtp_sender_init(GstWebRTCRTPSender * webrtc)137 gst_webrtc_rtp_sender_init (GstWebRTCRTPSender * webrtc)
138 {
139 }
140 
141 GstWebRTCRTPSender *
gst_webrtc_rtp_sender_new(void)142 gst_webrtc_rtp_sender_new (void)
143 {
144   return g_object_new (GST_TYPE_WEBRTC_RTP_SENDER, NULL);
145 }
146