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