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-icetransport
22  * @short_description: RTCIceTransport object
23  * @title: GstWebRTCICETransport
24  * @see_also: #GstWebRTCRTPSender, #GstWebRTCRTPReceiver, #GstWebRTCDTLSTransport
25  *
26  * <ulink url="https://www.w3.org/TR/webrtc/#rtcicetransport">https://www.w3.org/TR/webrtc/#rtcicetransport</ulink>
27  */
28 
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32 
33 #include "icetransport.h"
34 #include "webrtc-enumtypes.h"
35 
36 #define GST_CAT_DEFAULT gst_webrtc_ice_transport_debug
37 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
38 
39 #define gst_webrtc_ice_transport_parent_class parent_class
40 /* We would inherit from GstBin however when combined with the dtls transport,
41  * this causes loops in the graph. */
42 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstWebRTCICETransport,
43     gst_webrtc_ice_transport, GST_TYPE_OBJECT,
44     GST_DEBUG_CATEGORY_INIT (gst_webrtc_ice_transport_debug,
45         "webrtcicetransport", 0, "webrtcicetransport"););
46 
47 enum
48 {
49   SIGNAL_0,
50   ON_SELECTED_CANDIDATE_PAIR_CHANGE_SIGNAL,
51   ON_NEW_CANDIDATE_SIGNAL,
52   LAST_SIGNAL,
53 };
54 
55 enum
56 {
57   PROP_0,
58   PROP_COMPONENT,
59   PROP_STATE,
60   PROP_GATHERING_STATE,
61 };
62 
63 static guint gst_webrtc_ice_transport_signals[LAST_SIGNAL] = { 0 };
64 
65 void
gst_webrtc_ice_transport_connection_state_change(GstWebRTCICETransport * ice,GstWebRTCICEConnectionState new_state)66 gst_webrtc_ice_transport_connection_state_change (GstWebRTCICETransport * ice,
67     GstWebRTCICEConnectionState new_state)
68 {
69   GST_OBJECT_LOCK (ice);
70   ice->state = new_state;
71   GST_OBJECT_UNLOCK (ice);
72   g_object_notify (G_OBJECT (ice), "state");
73 }
74 
75 void
gst_webrtc_ice_transport_gathering_state_change(GstWebRTCICETransport * ice,GstWebRTCICEGatheringState new_state)76 gst_webrtc_ice_transport_gathering_state_change (GstWebRTCICETransport * ice,
77     GstWebRTCICEGatheringState new_state)
78 {
79   GST_OBJECT_LOCK (ice);
80   ice->gathering_state = new_state;
81   GST_OBJECT_UNLOCK (ice);
82   g_object_notify (G_OBJECT (ice), "gathering-state");
83 }
84 
85 void
gst_webrtc_ice_transport_selected_pair_change(GstWebRTCICETransport * ice)86 gst_webrtc_ice_transport_selected_pair_change (GstWebRTCICETransport * ice)
87 {
88   g_signal_emit (ice,
89       gst_webrtc_ice_transport_signals
90       [ON_SELECTED_CANDIDATE_PAIR_CHANGE_SIGNAL], 0);
91 }
92 
93 void
gst_webrtc_ice_transport_new_candidate(GstWebRTCICETransport * ice,guint stream_id,GstWebRTCICEComponent component,gchar * attr)94 gst_webrtc_ice_transport_new_candidate (GstWebRTCICETransport * ice,
95     guint stream_id, GstWebRTCICEComponent component, gchar * attr)
96 {
97   g_signal_emit (ice, gst_webrtc_ice_transport_signals[ON_NEW_CANDIDATE_SIGNAL],
98       stream_id, component, attr);
99 }
100 
101 static void
gst_webrtc_ice_transport_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)102 gst_webrtc_ice_transport_set_property (GObject * object, guint prop_id,
103     const GValue * value, GParamSpec * pspec)
104 {
105   GstWebRTCICETransport *webrtc = GST_WEBRTC_ICE_TRANSPORT (object);
106 
107   switch (prop_id) {
108     case PROP_COMPONENT:
109       webrtc->component = g_value_get_enum (value);
110       break;
111     default:
112       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
113       break;
114   }
115 }
116 
117 static void
gst_webrtc_ice_transport_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)118 gst_webrtc_ice_transport_get_property (GObject * object, guint prop_id,
119     GValue * value, GParamSpec * pspec)
120 {
121   GstWebRTCICETransport *webrtc = GST_WEBRTC_ICE_TRANSPORT (object);
122 
123   switch (prop_id) {
124     case PROP_COMPONENT:
125       g_value_set_enum (value, webrtc->component);
126       break;
127     case PROP_STATE:
128       g_value_set_enum (value, webrtc->state);
129       break;
130     case PROP_GATHERING_STATE:
131       g_value_set_enum (value, webrtc->gathering_state);
132       break;
133     default:
134       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
135       break;
136   }
137 }
138 
139 static void
gst_webrtc_ice_transport_finalize(GObject * object)140 gst_webrtc_ice_transport_finalize (GObject * object)
141 {
142 //  GstWebRTCICETransport *webrtc = GST_WEBRTC_ICE_TRANSPORT (object);
143 
144   G_OBJECT_CLASS (parent_class)->finalize (object);
145 }
146 
147 static void
gst_webrtc_ice_transport_constructed(GObject * object)148 gst_webrtc_ice_transport_constructed (GObject * object)
149 {
150 //  GstWebRTCICETransport *webrtc = GST_WEBRTC_ICE_TRANSPORT (object);
151 
152   G_OBJECT_CLASS (parent_class)->constructed (object);
153 }
154 
155 static void
gst_webrtc_ice_transport_class_init(GstWebRTCICETransportClass * klass)156 gst_webrtc_ice_transport_class_init (GstWebRTCICETransportClass * klass)
157 {
158   GObjectClass *gobject_class = (GObjectClass *) klass;
159 
160   gobject_class->constructed = gst_webrtc_ice_transport_constructed;
161   gobject_class->get_property = gst_webrtc_ice_transport_get_property;
162   gobject_class->set_property = gst_webrtc_ice_transport_set_property;
163   gobject_class->finalize = gst_webrtc_ice_transport_finalize;
164 
165   g_object_class_install_property (gobject_class,
166       PROP_COMPONENT,
167       g_param_spec_enum ("component",
168           "ICE component", "The ICE component of this transport",
169           GST_TYPE_WEBRTC_ICE_COMPONENT, 0,
170           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
171 
172   g_object_class_install_property (gobject_class,
173       PROP_STATE,
174       g_param_spec_enum ("state",
175           "ICE connection state", "The ICE connection state of this transport",
176           GST_TYPE_WEBRTC_ICE_CONNECTION_STATE, 0,
177           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
178 
179   g_object_class_install_property (gobject_class,
180       PROP_GATHERING_STATE,
181       g_param_spec_enum ("gathering-state",
182           "ICE gathering state", "The ICE gathering state of this transport",
183           GST_TYPE_WEBRTC_ICE_GATHERING_STATE, 0,
184           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
185 
186   /**
187    * GstWebRTC::on-selected_candidate-pair-change:
188    * @object: the #GstWebRTCICETransport
189    */
190   gst_webrtc_ice_transport_signals[ON_SELECTED_CANDIDATE_PAIR_CHANGE_SIGNAL] =
191       g_signal_new ("on-selected-candidate-pair-change",
192       G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
193       g_cclosure_marshal_generic, G_TYPE_NONE, 0);
194 
195   /**
196    * GstWebRTC::on-new-candidate:
197    * @object: the #GstWebRTCICETransport
198    */
199   gst_webrtc_ice_transport_signals[ON_NEW_CANDIDATE_SIGNAL] =
200       g_signal_new ("on-new-candidate",
201       G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
202       g_cclosure_marshal_generic, G_TYPE_NONE, 1, G_TYPE_STRING);
203 }
204 
205 static void
gst_webrtc_ice_transport_init(GstWebRTCICETransport * webrtc)206 gst_webrtc_ice_transport_init (GstWebRTCICETransport * webrtc)
207 {
208 }
209