7
7
#include < gst/sdp/sdp.h>
8
8
#include < gst/webrtc/webrtc.h>
9
9
10
- GstDataPipeline::GstDataPipeline () : GstBasePipeline(" DataPipeline" ) {
11
- }
12
-
10
+ GstDataPipeline::GstDataPipeline () : GstBasePipeline(" DataPipeline" ) {}
13
11
14
- void GstDataPipeline::CreatePipeline ()
12
+ void GstDataPipeline::CreatePipeline ()
15
13
{
16
14
Debug::Log (" GstDataPipeline create pipeline" , Level::Info);
17
15
GstBasePipeline::CreatePipeline ();
18
16
19
17
webrtcbin_ = add_webrtcbin ();
20
- auto state = gst_element_set_state (this ->pipeline_ , GstState::GST_STATE_READY);
18
+ auto state = gst_element_set_state (this ->pipeline_ , GstState::GST_STATE_READY);
21
19
22
20
CreateBusThread ();
23
21
}
24
22
25
23
void GstDataPipeline::DestroyPipeline ()
26
24
{
27
25
gst_webrtc_data_channel_close (channel_service_);
28
- gst_webrtc_data_channel_close (channel_command_);
26
+ gst_webrtc_data_channel_close (channel_command_reliable_);
27
+ gst_webrtc_data_channel_close (channel_command_lossy_);
29
28
gst_webrtc_data_channel_close (channel_audit_);
30
29
31
30
channel_service_ = nullptr ;
32
31
channel_audit_ = nullptr ;
33
- channel_command_ = nullptr ;
32
+ channel_command_reliable_ = nullptr ;
33
+ channel_command_lossy_ = nullptr ;
34
34
35
35
GstBasePipeline::DestroyPipeline ();
36
36
}
37
37
38
- void GstDataPipeline::SetOffer (const char * sdp_offer)
38
+ void GstDataPipeline::SetOffer (const char * sdp_offer)
39
39
{
40
40
Debug::Log (" SDP Offer: " + std::string (sdp_offer));
41
41
GstSDPMessage* sdpmsg = nullptr ;
@@ -44,20 +44,18 @@ void GstDataPipeline::SetOffer(const char* sdp_offer)
44
44
GstWebRTCSDPType sdp_type = GST_WEBRTC_SDP_TYPE_OFFER;
45
45
GstWebRTCSessionDescription* offer = gst_webrtc_session_description_new (sdp_type, sdpmsg);
46
46
47
-
48
- GstPromise* promise =
49
- gst_promise_new_with_change_func (on_offer_set, webrtcbin_, nullptr );
47
+ GstPromise* promise = gst_promise_new_with_change_func (on_offer_set, webrtcbin_, nullptr );
50
48
51
49
g_signal_emit_by_name (webrtcbin_, " set-remote-description" , offer, promise, nullptr );
52
50
53
- // gst_webrtc_session_description_free(offer); //raise breakpoint?
51
+ // gst_webrtc_session_description_free(offer); //raise breakpoint?
54
52
gst_sdp_message_free (sdpmsg);
55
53
gst_promise_unref (promise);
56
54
}
57
55
58
- void GstDataPipeline::SetICECandidate (const char * candidate, int mline_index)
56
+ void GstDataPipeline::SetICECandidate (const char * candidate, int mline_index)
59
57
{
60
- Debug::Log (" Add ICE Candidate: " + std::string (candidate) + " " + std::to_string (mline_index));
58
+ Debug::Log (" Add ICE Candidate: " + std::string (candidate) + " " + std::to_string (mline_index));
61
59
g_signal_emit_by_name (webrtcbin_, " add-ice-candidate" , mline_index, candidate);
62
60
}
63
61
@@ -72,7 +70,6 @@ void GstDataPipeline::on_offer_set(GstPromise* promise, gpointer user_data)
72
70
gst_promise_unref (promise);
73
71
}
74
72
75
-
76
73
void GstDataPipeline::on_answer_created (GstPromise* promise, gpointer user_data)
77
74
{
78
75
Debug::Log (" create answer" );
@@ -85,11 +82,10 @@ void GstDataPipeline::on_answer_created(GstPromise* promise, gpointer user_data)
85
82
gst_structure_get (reply, " answer" , GST_TYPE_WEBRTC_SESSION_DESCRIPTION, &answer, nullptr );
86
83
gst_promise_unref (promise);
87
84
88
- // promise = gst_promise_new_with_change_func(on_answer_set, webrtc, nullptr);
85
+ // promise = gst_promise_new_with_change_func(on_answer_set, webrtc, nullptr);
89
86
g_signal_emit_by_name (webrtc, " set-local-description" , answer, nullptr );
90
- // gst_promise_interrupt(promise);
91
- // gst_promise_unref(promise);
92
-
87
+ // gst_promise_interrupt(promise);
88
+ // gst_promise_unref(promise);
93
89
94
90
if (callbackICEInstance != nullptr )
95
91
{
@@ -115,7 +111,6 @@ void GstDataPipeline::on_ice_candidate(GstElement* webrtcbin, guint mline_index,
115
111
}
116
112
}
117
113
118
-
119
114
/* void GstDataPipeline::on_message_data(GstWebRTCDataChannel* channel, GBytes* data, gpointer user_data)
120
115
{
121
116
Debug::Log("Data channel message received", Level::Info);
@@ -142,7 +137,6 @@ void GstDataPipeline::on_ice_candidate(GstElement* webrtcbin, guint mline_index,
142
137
gst_structure_free(options);
143
138
}*/
144
139
145
-
146
140
void GstDataPipeline::on_ice_gathering_state_notify (GstElement* webrtcbin, GParamSpec* pspec, gpointer user_data)
147
141
{
148
142
GstWebRTCICEGatheringState ice_gather_state;
@@ -161,7 +155,7 @@ void GstDataPipeline::on_ice_gathering_state_notify(GstElement* webrtcbin, GPara
161
155
new_state = " complete" ;
162
156
break ;
163
157
}
164
- Debug::Log (" ICE gathering state changed to " + new_state);
158
+ Debug::Log (" ICE gathering state changed to " + new_state);
165
159
}
166
160
167
161
bool GstDataPipeline::starts_with (const std::string& str, const std::string& prefix)
@@ -186,36 +180,43 @@ void GstDataPipeline::on_data_channel(GstElement* webrtcbin, GstWebRTCDataChanne
186
180
187
181
if (label_str == CHANNEL_SERVICE)
188
182
{
189
- self->channel_service_ = channel;
183
+ self->channel_service_ = channel;
190
184
191
185
g_signal_connect (channel, " on-message-data" , G_CALLBACK (on_message_data_service), nullptr );
192
186
193
- if (callbackChannelServiceOpenInstance != nullptr )
194
- callbackChannelServiceOpenInstance ();
187
+ if (callbackChannelServiceOpenInstance != nullptr )
188
+ callbackChannelServiceOpenInstance ();
195
189
else
196
190
Debug::Log (" Fails to notify opening of service channel" , Level::Warning);
197
191
}
198
- else if (starts_with (label_str,CHANNEL_REACHY_STATE))
192
+ else if (starts_with (label_str, CHANNEL_REACHY_STATE))
199
193
{
200
194
g_signal_connect (channel, " on-message-data" , G_CALLBACK (on_message_data_state), nullptr );
201
195
}
202
196
else if (starts_with (label_str, CHANNEL_REACHY_AUDIT))
203
197
{
204
198
g_signal_connect (channel, " on-message-data" , G_CALLBACK (on_message_data_audit), nullptr );
205
199
}
206
- else if (starts_with (label_str, CHANNEL_REACHY_COMMAND))
200
+ else if (starts_with (label_str, CHANNEL_REACHY_COMMAND_RELIABLE))
201
+ {
202
+ self->channel_command_reliable_ = channel;
203
+ if (callbackChannelCommandReliableOpenInstance != nullptr )
204
+ callbackChannelCommandReliableOpenInstance ();
205
+ else
206
+ Debug::Log (" Fails to notify opening of reliable command channel" , Level::Warning);
207
+ }
208
+ else if (starts_with (label_str, CHANNEL_REACHY_COMMAND_LOSSY))
207
209
{
208
- self->channel_command_ = channel;
209
- if (callbackChannelCommandOpenInstance != nullptr )
210
- callbackChannelCommandOpenInstance ();
210
+ self->channel_command_lossy_ = channel;
211
+ if (callbackChannelCommandLossyOpenInstance != nullptr )
212
+ callbackChannelCommandLossyOpenInstance ();
211
213
else
212
- Debug::Log (" Fails to notify opening of command channel" , Level::Warning);
214
+ Debug::Log (" Fails to notify opening of lossy command channel" , Level::Warning);
213
215
}
214
216
else
215
217
{
216
218
Debug::Log (" unknown data channel : " + label_str, Level::Warning);
217
219
}
218
-
219
220
}
220
221
221
222
void GstDataPipeline::send_byte_array (GstWebRTCDataChannel* channel, const unsigned char * data, size_t size)
@@ -227,25 +228,33 @@ void GstDataPipeline::send_byte_array(GstWebRTCDataChannel* channel, const unsig
227
228
g_bytes_unref (bytes);
228
229
}
229
230
230
- void GstDataPipeline::send_byte_array_channel_service (const unsigned char * data, size_t size)
231
+ void GstDataPipeline::send_byte_array_channel_service (const unsigned char * data, size_t size)
231
232
{
232
233
if (channel_service_ != nullptr )
233
- send_byte_array (channel_service_, data, size);
234
+ send_byte_array (channel_service_, data, size);
234
235
else
235
236
Debug::Log (" channel service is not initialized " , Level::Warning);
236
237
}
237
238
238
- void GstDataPipeline::send_byte_array_channel_command (const unsigned char * data, size_t size)
239
+ void GstDataPipeline::send_byte_array_channel_command_reliable (const unsigned char * data, size_t size)
240
+ {
241
+ if (channel_command_reliable_ != nullptr )
242
+ send_byte_array (channel_command_reliable_, data, size);
243
+ else
244
+ Debug::Log (" channel reliable command is not initialized " , Level::Warning);
245
+ }
246
+
247
+ void GstDataPipeline::send_byte_array_channel_command_lossy (const unsigned char * data, size_t size)
239
248
{
240
- if (channel_command_ != nullptr )
241
- send_byte_array (channel_command_ , data, size);
249
+ if (channel_command_reliable_ != nullptr )
250
+ send_byte_array (channel_command_lossy_ , data, size);
242
251
else
243
- Debug::Log (" channel command is not initialized " , Level::Warning);
252
+ Debug::Log (" channel lossy command is not initialized " , Level::Warning);
244
253
}
245
254
246
255
void GstDataPipeline::on_message_data_service (GstWebRTCDataChannel* channel, GBytes* data, gpointer user_data)
247
256
{
248
- // Debug::Log("Data channel service message received", Level::Info);
257
+ // Debug::Log("Data channel service message received", Level::Info);
249
258
if (callbackChannelServiceDataInstance != nullptr )
250
259
{
251
260
gsize size = g_bytes_get_size (data);
@@ -256,7 +265,7 @@ void GstDataPipeline::on_message_data_service(GstWebRTCDataChannel* channel, GBy
256
265
257
266
void GstDataPipeline::on_message_data_state (GstWebRTCDataChannel* channel, GBytes* data, gpointer user_data)
258
267
{
259
- // Debug::Log("Data channel state message received", Level::Info);
268
+ // Debug::Log("Data channel state message received", Level::Info);
260
269
if (callbackChannelStateDataInstance != nullptr )
261
270
{
262
271
gsize size = g_bytes_get_size (data);
@@ -294,18 +303,19 @@ GstElement* GstDataPipeline::add_webrtcbin()
294
303
return webrtcbin;
295
304
}
296
305
297
-
298
306
// Create a callback delegate
299
307
void RegisterICECallback (FuncCallBackICE cb) { callbackICEInstance = cb; }
300
308
void RegisterSDPCallback (FuncCallBackSDP cb) { callbackSDPInstance = cb; }
301
- void RegisterChannelCommandOpenCallback (FuncCallBackChannelOpen cb) { callbackChannelCommandOpenInstance = cb; }
309
+ void RegisterChannelReliableCommandOpenCallback (FuncCallBackChannelOpen cb) { callbackChannelCommandReliableOpenInstance = cb; }
310
+ void RegisterChannelLossyCommandOpenCallback (FuncCallBackChannelOpen cb) { callbackChannelCommandLossyOpenInstance = cb; }
302
311
void RegisterChannelServiceOpenCallback (FuncCallBackChannelOpen cb) { callbackChannelServiceOpenInstance = cb; }
303
312
void RegisterChannelServiceDataCallback (FuncCallBackChannelData cb) { callbackChannelServiceDataInstance = cb; }
304
313
void RegisterChannelStateDataCallback (FuncCallBackChannelData cb) { callbackChannelStateDataInstance = cb; }
305
314
void RegisterChannelAuditDataCallback (FuncCallBackChannelData cb) { callbackChannelAuditDataInstance = cb; }
306
315
307
- // const
316
+ // const
308
317
const std::string GstDataPipeline::CHANNEL_SERVICE = " service" ;
309
318
const std::string GstDataPipeline::CHANNEL_REACHY_STATE = " reachy_state" ;
310
- const std::string GstDataPipeline::CHANNEL_REACHY_COMMAND = " reachy_command" ;
319
+ const std::string GstDataPipeline::CHANNEL_REACHY_COMMAND_RELIABLE = " reachy_command_reliable" ;
320
+ const std::string GstDataPipeline::CHANNEL_REACHY_COMMAND_LOSSY = " reachy_command_lossy" ;
311
321
const std::string GstDataPipeline::CHANNEL_REACHY_AUDIT = " reachy_audit" ;
0 commit comments