Welcome to mirror list, hosted at ThFree Co, Russian Federation.

iface.rs « signaller « src « webrtc « net - github.com/sdroege/gst-plugin-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 98f57d1d2372e18575e94420b1a9abab3aaf818b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
use gst::glib;
use gst::glib::once_cell::sync::Lazy;
use gst::glib::subclass::*;
use gst::prelude::*;
use gst::subclass::prelude::*;

#[derive(Copy, Clone)]
#[repr(C)]
pub struct Signallable {
    _parent: glib::gobject_ffi::GTypeInterface,
    pub start: fn(&super::Signallable),
    pub stop: fn(&super::Signallable),
    pub send_sdp: fn(&super::Signallable, &str, &gst_webrtc::WebRTCSessionDescription),
    pub add_ice: fn(&super::Signallable, &str, &str, u32, Option<String>),
    pub end_session: fn(&super::Signallable, &str),
}

impl Signallable {
    fn request_meta(_iface: &super::Signallable) -> Option<gst::Structure> {
        None
    }
    fn start(_iface: &super::Signallable) {}
    fn stop(_iface: &super::Signallable) {}
    fn send_sdp(
        _iface: &super::Signallable,
        _session_id: &str,
        _sdp: &gst_webrtc::WebRTCSessionDescription,
    ) {
    }
    fn add_ice(
        _iface: &super::Signallable,
        _session_id: &str,
        _candidate: &str,
        _sdp_m_line_index: u32,
        _sdp_mid: Option<String>,
    ) {
    }
    fn end_session(_iface: &super::Signallable, _session_id: &str) {}
}

#[glib::object_interface]
unsafe impl prelude::ObjectInterface for Signallable {
    const NAME: &'static ::std::primitive::str = "GstRSWebRTCSignallableIface";
    type Prerequisites = (glib::Object,);

    fn interface_init(&mut self) {
        self.start = Signallable::start;
        self.stop = Signallable::stop;
        self.send_sdp = Signallable::send_sdp;
        self.add_ice = Signallable::add_ice;
        self.end_session = Signallable::end_session;
    }

    fn signals() -> &'static [Signal] {
        static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
            vec![
                /**
                 * GstRSWebRTCSignallableIface::session-ended:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 * @session-id: The ID of the session that ended
                 *
                 * Notify the underlying webrtc object that a session has ended.
                 */
                Signal::builder("session-ended")
                    .param_types([str::static_type()])
                    .return_type::<bool>()
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::producer-added:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 * @producer_id: The ID of the available producer
                 * @meta: The metadata structure of the producer
                 * @new_connection: true if the producer has just connected to
                 *                  the signalling server or false if it was
                 *                  already running before starting the client
                 *
                 * Some producing peer is available to produce a WebRTC stream.
                 */
                Signal::builder("producer-added")
                    .param_types([
                        str::static_type(),
                        <Option<gst::Structure>>::static_type(),
                        bool::static_type(),
                    ])
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::producer-removed:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 * @producer_id: The ID of the producer that is not available
                 *               anymore
                 * @meta: The metadata structure of the producer
                 *
                 * Some producing peer has stopped producing streams.
                 */
                Signal::builder("producer-removed")
                    .param_types([str::static_type(), <Option<gst::Structure>>::static_type()])
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::session-started:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 *
                 * Notify the underlying webrtc object that a session has started.
                 */
                Signal::builder("session-started")
                    .param_types([str::static_type(), str::static_type()])
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::session-requested:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 * @session_id: The ID of the producer that was added
                 * @peer_id: The ID of the consumer peer who wants to initiate a
                 *           session
                 *
                 * Notify the underlying webrtc object that a session has been requested from the
                 * peer.
                 */
                Signal::builder("session-requested")
                    .param_types([
                        str::static_type(),
                        str::static_type(),
                        gst_webrtc::WebRTCSessionDescription::static_type(),
                    ])
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::error:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 * @error: The error message as a string
                 */
                Signal::builder("error")
                    .param_types([str::static_type()])
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::request-meta:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 *
                 * The signaller requests a meta about the peer using it
                 *
                 * Return: The metadata about the peer represented by the signaller
                 */
                Signal::builder("request-meta")
                    .return_type::<Option<gst::Structure>>()
                    .class_handler(|_token, args| {
                        let this = args[0usize]
                            .get::<&super::Signallable>()
                            .unwrap_or_else(|e| {
                                panic!("Wrong type for argument {}: {:?}", 0usize, e)
                            });
                        Some(Signallable::request_meta(this).to_value())
                    })
                    .accumulator(move |_hint, output, input| {
                        *output = input.clone();
                        false
                    })
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::handle-ice:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 * @session_id: Id of the session the ice information is about
                 * @sdp_m_line_index: The mlineindex of the ice candidate
                 * @sdp_mid: Media ID of the ice candidate
                 * @candidate: Information about the candidate
                 *
                 * Notify the underlying webrtc object of an ICE candidate.
                 */
                Signal::builder("handle-ice")
                    .flags(glib::SignalFlags::ACTION)
                    .param_types([
                        str::static_type(),
                        u32::static_type(),
                        <Option<String>>::static_type(),
                        str::static_type(),
                    ])
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::session-description:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 * @session_id: Id of the session being described
                 * @description: The WebRTC session description
                 *
                 * Notify the underlying webrtc object of a received session description
                 */
                Signal::builder("session-description")
                    .flags(glib::SignalFlags::ACTION)
                    .param_types([
                        str::static_type(),
                        gst_webrtc::WebRTCSessionDescription::static_type(),
                    ])
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::start:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 *
                 * Starts the signaller, connecting it to the signalling server.
                 */
                Signal::builder("start")
                    .run_last()
                    .return_type::<bool>()
                    .class_handler(|_token, args| {
                        let this = args[0usize]
                            .get::<&super::Signallable>()
                            .unwrap_or_else(|e| {
                                panic!("Wrong type for argument {}: {:?}", 0usize, e)
                            });
                        let vtable = this.interface::<super::Signallable>().unwrap();
                        let vtable = vtable.as_ref();
                        (vtable.start)(this);

                        Some(false.into())
                    })
                    .accumulator(move |_hint, output, input| {
                        *output = input.clone();
                        false
                    })
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::stop:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 *
                 * Stops the signaller, disconnecting it to the signalling server.
                 */
                Signal::builder("stop")
                    .run_last()
                    .return_type::<bool>()
                    .class_handler(|_tokens, args| {
                        let this = args[0usize]
                            .get::<&super::Signallable>()
                            .unwrap_or_else(|e| {
                                panic!("Wrong type for argument {}: {:?}", 0usize, e)
                            });
                        let vtable = this.interface::<super::Signallable>().unwrap();
                        let vtable = vtable.as_ref();
                        (vtable.stop)(this);

                        Some(false.into())
                    })
                    .accumulator(move |_hint, output, input| {
                        *output = input.clone();
                        false
                    })
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::shutdown:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 */
                Signal::builder("shutdown")
                    .flags(glib::SignalFlags::ACTION)
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::end-session:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 * @session-id: The ID of the session that should be ended
                 *
                 * Notify the signaller that a session should be ended.
                 */
                Signal::builder("end-session")
                    .run_last()
                    .param_types([str::static_type()])
                    .return_type::<bool>()
                    .class_handler(|_tokens, args| {
                        let this = args[0usize]
                            .get::<&super::Signallable>()
                            .unwrap_or_else(|e| {
                                panic!("Wrong type for argument {}: {:?}", 0usize, e)
                            });
                        let session_id = args[1usize].get::<&str>().unwrap_or_else(|e| {
                            panic!("Wrong type for argument {}: {:?}", 1usize, e)
                        });
                        let vtable = this.interface::<super::Signallable>().unwrap();
                        let vtable = vtable.as_ref();
                        (vtable.end_session)(this, session_id);

                        Some(false.into())
                    })
                    .accumulator(move |_hint, output, input| {
                        *output = input.clone();
                        false
                    })
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::consumer-added:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 * @peer_id: Id of the consumer
                 * @webrtcbin: The internal WebRTCBin element
                 *
                 * This signal can be used to tweak @webrtcbin, creating a data
                 * channel for example.
                 *
                 * Deprecated: 1.24: Use `webrtcbin-ready` instead
                 */
                Signal::builder("consumer-added")
                    .param_types([String::static_type(), gst::Element::static_type()])
                    .deprecated()
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::consumer-removed:
                 * @consumer_id: Identifier of the consumer that was removed
                 * @webrtcbin: The webrtcbin connected to the newly removed consumer
                 *
                 * This signal is emitted right after the connection with a consumer
                 * has been dropped.
                 */
                Signal::builder("consumer-removed")
                    .param_types([String::static_type(), gst::Element::static_type()])
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::send-session-description:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 * @session_id: Id of the session being described
                 * @description: The WebRTC session description to send to the peer
                 *
                 * Send @description to the peer.
                 */
                Signal::builder("send-session-description")
                    .run_last()
                    .param_types([
                        str::static_type(),
                        gst_webrtc::WebRTCSessionDescription::static_type(),
                    ])
                    .return_type::<bool>()
                    .class_handler(|_tokens, args| {
                        let this = args[0usize]
                            .get::<&super::Signallable>()
                            .unwrap_or_else(|e| {
                                panic!("Wrong type for argument {}: {:?}", 0usize, e)
                            });
                        let session_id = args[1usize].get::<&str>().unwrap_or_else(|e| {
                            panic!("Wrong type for argument {}: {:?}", 1usize, e)
                        });
                        let desc = args[2usize]
                            .get::<&gst_webrtc::WebRTCSessionDescription>()
                            .unwrap_or_else(|e| {
                                panic!("Wrong type for argument {}: {:?}", 2usize, e)
                            });
                        let vtable = this.interface::<super::Signallable>().unwrap();
                        let vtable = vtable.as_ref();
                        (vtable.send_sdp)(this, session_id, desc);

                        Some(false.into())
                    })
                    .accumulator(move |_hint, output, input| {
                        *output = input.clone();
                        false
                    })
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::send-ice:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 * @session_id: Id of the session being described
                 * @candidate: The ICE candidate description to send to the peer
                 * @sdp_m_line_index: The M-line of the session description this candidate applies to
                 * @sdp_mid: The MID this candidate applies to
                 *
                 * Send @candidate to the peer.
                 */
                Signal::builder("send-ice")
                    .param_types([
                        str::static_type(),
                        str::static_type(),
                        u32::static_type(),
                        String::static_type(),
                    ])
                    .return_type::<bool>()
                    .class_handler(|_tokens, args| {
                        let this = args[0usize]
                            .get::<&super::Signallable>()
                            .unwrap_or_else(|e| {
                                panic!("Wrong type for argument {}: {:?}", 0usize, e)
                            });
                        let session_id = args[1usize].get::<&str>().unwrap_or_else(|e| {
                            panic!("Wrong type for argument {}: {:?}", 1usize, e)
                        });
                        let candidate = args[2usize].get::<&str>().unwrap_or_else(|e| {
                            panic!("Wrong type for argument {}: {:?}", 2usize, e)
                        });
                        let sdp_m_line_index = args[3usize].get::<u32>().unwrap_or_else(|e| {
                            panic!("Wrong type for argument {}: {:?}", 2usize, e)
                        });
                        let sdp_mid = args[4usize].get::<Option<String>>().unwrap_or_else(|e| {
                            panic!("Wrong type for argument {}: {:?}", 2usize, e)
                        });
                        let vtable = this.interface::<super::Signallable>().unwrap();
                        let vtable = vtable.as_ref();
                        (vtable.add_ice)(this, session_id, candidate, sdp_m_line_index, sdp_mid);

                        Some(false.into())
                    })
                    .accumulator(move |_hint, output, input| {
                        *output = input.clone();
                        false
                    })
                    .build(),
                /**
                 * GstRSWebRTCSignallableIface::webrtcbin-ready:
                 * @self: The object implementing #GstRSWebRTCSignallableIface
                 * @peer_id: Id of the consumer/producer
                 * @webrtcbin: The internal WebRTCBin element
                 *
                 * This signal can be used to tweak @webrtcbin, creating a data
                 * channel for example.
                 */
                Signal::builder("webrtcbin-ready")
                    .param_types([String::static_type(), gst::Element::static_type()])
                    .build(),
            ]
        });
        SIGNALS.as_ref()
    }
}

unsafe impl<Obj: SignallableImpl> types::IsImplementable<Obj> for super::Signallable
where
    <Obj as types::ObjectSubclass>::Type: glib::IsA<glib::Object>,
{
    fn interface_init(iface: &mut glib::Interface<Self>) {
        let iface = ::std::convert::AsMut::as_mut(iface);

        fn vstart_trampoline<Obj: types::ObjectSubclass + SignallableImpl>(
            obj: &super::Signallable,
        ) {
            let this = obj
                .dynamic_cast_ref::<<Obj as types::ObjectSubclass>::Type>()
                .unwrap()
                .imp();
            SignallableImpl::start(this)
        }
        iface.start = vstart_trampoline::<Obj>;

        fn vstop_trampoline<Obj: types::ObjectSubclass + SignallableImpl>(
            this: &super::Signallable,
        ) {
            let this = this
                .dynamic_cast_ref::<<Obj as types::ObjectSubclass>::Type>()
                .unwrap();
            SignallableImpl::stop(this.imp())
        }
        iface.stop = vstop_trampoline::<Obj>;

        fn send_sdp_trampoline<Obj: types::ObjectSubclass + SignallableImpl>(
            this: &super::Signallable,
            session_id: &str,
            sdp: &gst_webrtc::WebRTCSessionDescription,
        ) {
            let this = this
                .dynamic_cast_ref::<<Obj as types::ObjectSubclass>::Type>()
                .unwrap();
            SignallableImpl::send_sdp(this.imp(), session_id, sdp)
        }
        iface.send_sdp = send_sdp_trampoline::<Obj>;

        fn add_ice_trampoline<Obj: types::ObjectSubclass + SignallableImpl>(
            this: &super::Signallable,
            session_id: &str,
            candidate: &str,
            sdp_m_line_index: u32,
            sdp_mid: Option<String>,
        ) {
            let this = this
                .dynamic_cast_ref::<<Obj as types::ObjectSubclass>::Type>()
                .unwrap();
            SignallableImpl::add_ice(this.imp(), session_id, candidate, sdp_m_line_index, sdp_mid)
        }
        iface.add_ice = add_ice_trampoline::<Obj>;

        fn end_session_trampoline<Obj: types::ObjectSubclass + SignallableImpl>(
            this: &super::Signallable,
            session_id: &str,
        ) {
            let this = this
                .dynamic_cast_ref::<<Obj as types::ObjectSubclass>::Type>()
                .unwrap();
            SignallableImpl::end_session(this.imp(), session_id)
        }
        iface.end_session = end_session_trampoline::<Obj>;
    }
}

pub trait SignallableImpl: object::ObjectImpl + 'static {
    fn start(&self) {}
    fn stop(&self) {}
    fn send_sdp(&self, _session_id: &str, _sdp: &gst_webrtc::WebRTCSessionDescription) {}
    fn add_ice(
        &self,
        _session_id: &str,
        _candidate: &str,
        _sdp_m_line_index: u32,
        _sdp_mid: Option<String>,
    ) {
    }
    fn end_session(&self, _session_id: &str) {}
}

pub trait SignallableExt: 'static {
    fn start(&self);
    fn stop(&self);
    fn send_sdp(&self, session_id: &str, sdp: &gst_webrtc::WebRTCSessionDescription);
    fn add_ice(
        &self,
        session_id: &str,
        candidate: &str,
        sdp_m_line_index: u32,
        sdp_mid: Option<String>,
    );
    fn end_session(&self, session_id: &str);
}

impl<Obj: glib::IsA<super::Signallable>> SignallableExt for Obj {
    fn start(&self) {
        self.emit_by_name::<bool>("start", &[]);
    }

    fn stop(&self) {
        self.emit_by_name::<bool>("stop", &[]);
    }

    fn send_sdp(&self, session_id: &str, sdp: &gst_webrtc::WebRTCSessionDescription) {
        self.emit_by_name::<bool>("send-session-description", &[&session_id, sdp]);
    }

    fn add_ice(
        &self,
        session_id: &str,
        candidate: &str,
        sdp_m_line_index: u32,
        sdp_mid: Option<String>,
    ) {
        self.emit_by_name::<bool>(
            "send-ice",
            &[&session_id, &candidate, &sdp_m_line_index, &sdp_mid],
        );
    }

    fn end_session(&self, session_id: &str) {
        self.emit_by_name::<bool>("end-session", &[&session_id]);
    }
}