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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::{
    ffi, WebRTCICECandidateStats, WebRTCICEComponent, WebRTCICEStream, WebRTCICETransport,
};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    ///
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// ## Properties
    ///
    ///
    /// #### `max-rtp-port`
    ///  Maximum port for local rtp port range.
    /// min-rtp-port must be <= max-rtp-port
    ///
    /// Readable | Writeable | Construct
    ///
    ///
    /// #### `min-rtp-port`
    ///  Minimum port for local rtp port range.
    /// min-rtp-port must be <= max-rtp-port
    ///
    /// Readable | Writeable | Construct
    /// <details><summary><h4>Object</h4></summary>
    ///
    ///
    /// #### `name`
    ///  Readable | Writeable | Construct
    ///
    ///
    /// #### `parent`
    ///  The parent of the object. Please note, that when changing the 'parent'
    /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and `GstObject::deep-notify`
    /// signals due to locking issues. In some cases one can use
    /// `GstBin::element-added` or `GstBin::element-removed` signals on the parent to
    /// achieve a similar effect.
    ///
    /// Readable | Writeable
    /// </details>
    ///
    /// ## Signals
    ///
    ///
    /// #### `add-local-ip-address`
    ///  Add a local IP address to use for ICE candidate gathering. If none
    /// are supplied, they will be discovered automatically. Calling this signal
    /// stops automatic ICE gathering.
    ///
    /// Action
    /// <details><summary><h4>Object</h4></summary>
    ///
    ///
    /// #### `deep-notify`
    ///  The deep notify signal is used to be notified of property changes. It is
    /// typically attached to the toplevel bin to receive notifications from all
    /// the elements contained in that bin.
    ///
    /// Detailed
    /// </details>
    ///
    /// # Implements
    ///
    /// [`WebRTCICEExt`][trait@crate::prelude::WebRTCICEExt], [`trait@glib::ObjectExt`]
    #[doc(alias = "GstWebRTCICE")]
    pub struct WebRTCICE(Object<ffi::GstWebRTCICE, ffi::GstWebRTCICEClass>);

    match fn {
        type_ => || ffi::gst_webrtc_ice_get_type(),
    }
}

impl WebRTCICE {
    pub const NONE: Option<&'static WebRTCICE> = None;
}

unsafe impl Send for WebRTCICE {}
unsafe impl Sync for WebRTCICE {}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::WebRTCICE>> Sealed for T {}
}

/// Trait containing all [`struct@WebRTCICE`] methods.
///
/// # Implementors
///
/// [`WebRTCICE`][struct@crate::WebRTCICE]
pub trait WebRTCICEExt: IsA<WebRTCICE> + sealed::Sealed + 'static {
    /// ## `session_id`
    /// The session id
    ///
    /// # Returns
    ///
    /// The [`WebRTCICEStream`][crate::WebRTCICEStream], or [`None`]
    #[doc(alias = "gst_webrtc_ice_add_stream")]
    fn add_stream(&self, session_id: u32) -> Option<WebRTCICEStream> {
        unsafe {
            from_glib_full(ffi::gst_webrtc_ice_add_stream(
                self.as_ref().to_glib_none().0,
                session_id,
            ))
        }
    }

    /// ## `uri`
    /// URI of the TURN server
    ///
    /// # Returns
    ///
    /// FALSE on error, TRUE otherwise
    #[doc(alias = "gst_webrtc_ice_add_turn_server")]
    fn add_turn_server(&self, uri: &str) -> bool {
        unsafe {
            from_glib(ffi::gst_webrtc_ice_add_turn_server(
                self.as_ref().to_glib_none().0,
                uri.to_glib_none().0,
            ))
        }
    }

    /// ## `stream`
    /// The [`WebRTCICEStream`][crate::WebRTCICEStream]
    /// ## `component`
    /// The [`WebRTCICEComponent`][crate::WebRTCICEComponent]
    ///
    /// # Returns
    ///
    /// The [`WebRTCICETransport`][crate::WebRTCICETransport], or [`None`]
    #[doc(alias = "gst_webrtc_ice_find_transport")]
    fn find_transport(
        &self,
        stream: &impl IsA<WebRTCICEStream>,
        component: WebRTCICEComponent,
    ) -> Option<WebRTCICETransport> {
        unsafe {
            from_glib_full(ffi::gst_webrtc_ice_find_transport(
                self.as_ref().to_glib_none().0,
                stream.as_ref().to_glib_none().0,
                component.into_glib(),
            ))
        }
    }

    /// ## `stream`
    /// The [`WebRTCICEStream`][crate::WebRTCICEStream]
    ///
    /// # Returns
    ///
    /// FALSE on error, TRUE otherwise
    #[doc(alias = "gst_webrtc_ice_gather_candidates")]
    fn gather_candidates(&self, stream: &impl IsA<WebRTCICEStream>) -> bool {
        unsafe {
            from_glib(ffi::gst_webrtc_ice_gather_candidates(
                self.as_ref().to_glib_none().0,
                stream.as_ref().to_glib_none().0,
            ))
        }
    }

    ///
    /// # Returns
    ///
    /// URI of the HTTP proxy of the form
    ///  http://[username:password@]hostname[:port][?alpn=`<alpn>`]
    ///
    /// Get HTTP Proxy to be used when connecting to TURN server.
    #[doc(alias = "gst_webrtc_ice_get_http_proxy")]
    #[doc(alias = "get_http_proxy")]
    fn http_proxy(&self) -> glib::GString {
        unsafe {
            from_glib_full(ffi::gst_webrtc_ice_get_http_proxy(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    ///
    /// # Returns
    ///
    /// TRUE if set as controller, FALSE otherwise
    #[doc(alias = "gst_webrtc_ice_get_is_controller")]
    #[doc(alias = "get_is_controller")]
    fn is_controller(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_webrtc_ice_get_is_controller(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// ## `stream`
    /// The [`WebRTCICEStream`][crate::WebRTCICEStream]
    ///
    /// # Returns
    ///
    /// List of local candidates
    #[doc(alias = "gst_webrtc_ice_get_local_candidates")]
    #[doc(alias = "get_local_candidates")]
    fn local_candidates(&self, stream: &impl IsA<WebRTCICEStream>) -> Vec<WebRTCICECandidateStats> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gst_webrtc_ice_get_local_candidates(
                self.as_ref().to_glib_none().0,
                stream.as_ref().to_glib_none().0,
            ))
        }
    }

    /// ## `stream`
    /// The [`WebRTCICEStream`][crate::WebRTCICEStream]
    ///
    /// # Returns
    ///
    /// List of remote candidates
    #[doc(alias = "gst_webrtc_ice_get_remote_candidates")]
    #[doc(alias = "get_remote_candidates")]
    fn remote_candidates(
        &self,
        stream: &impl IsA<WebRTCICEStream>,
    ) -> Vec<WebRTCICECandidateStats> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gst_webrtc_ice_get_remote_candidates(
                self.as_ref().to_glib_none().0,
                stream.as_ref().to_glib_none().0,
            ))
        }
    }

    /// ## `stream`
    /// The [`WebRTCICEStream`][crate::WebRTCICEStream]
    ///
    /// # Returns
    ///
    /// FALSE on failure, otherwise `local_stats` `remote_stats` will be set
    ///
    /// ## `local_stats`
    /// A pointer to [`WebRTCICECandidateStats`][crate::WebRTCICECandidateStats] for local candidate
    ///
    /// ## `remote_stats`
    /// pointer to [`WebRTCICECandidateStats`][crate::WebRTCICECandidateStats] for remote candidate
    #[doc(alias = "gst_webrtc_ice_get_selected_pair")]
    #[doc(alias = "get_selected_pair")]
    fn selected_pair(
        &self,
        stream: &impl IsA<WebRTCICEStream>,
    ) -> Option<(WebRTCICECandidateStats, WebRTCICECandidateStats)> {
        unsafe {
            let mut local_stats = std::ptr::null_mut();
            let mut remote_stats = std::ptr::null_mut();
            let ret = from_glib(ffi::gst_webrtc_ice_get_selected_pair(
                self.as_ref().to_glib_none().0,
                stream.as_ref().to_glib_none().0,
                &mut local_stats,
                &mut remote_stats,
            ));
            if ret {
                Some((from_glib_full(local_stats), from_glib_full(remote_stats)))
            } else {
                None
            }
        }
    }

    ///
    /// # Returns
    ///
    /// URI of the STUN sever
    #[doc(alias = "gst_webrtc_ice_get_stun_server")]
    #[doc(alias = "get_stun_server")]
    fn stun_server(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_full(ffi::gst_webrtc_ice_get_stun_server(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    ///
    /// # Returns
    ///
    /// URI of the TURN sever
    #[doc(alias = "gst_webrtc_ice_get_turn_server")]
    #[doc(alias = "get_turn_server")]
    fn turn_server(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_full(ffi::gst_webrtc_ice_get_turn_server(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// ## `force_relay`
    /// TRUE to enable force relay
    #[doc(alias = "gst_webrtc_ice_set_force_relay")]
    fn set_force_relay(&self, force_relay: bool) {
        unsafe {
            ffi::gst_webrtc_ice_set_force_relay(
                self.as_ref().to_glib_none().0,
                force_relay.into_glib(),
            );
        }
    }

    /// Set HTTP Proxy to be used when connecting to TURN server.
    /// ## `uri`
    /// URI of the HTTP proxy of the form
    ///  http://[username:password@]hostname[:port][?alpn=`<alpn>`]
    #[doc(alias = "gst_webrtc_ice_set_http_proxy")]
    fn set_http_proxy(&self, uri: &str) {
        unsafe {
            ffi::gst_webrtc_ice_set_http_proxy(
                self.as_ref().to_glib_none().0,
                uri.to_glib_none().0,
            );
        }
    }

    /// ## `controller`
    /// TRUE to set as controller
    #[doc(alias = "gst_webrtc_ice_set_is_controller")]
    fn set_is_controller(&self, controller: bool) {
        unsafe {
            ffi::gst_webrtc_ice_set_is_controller(
                self.as_ref().to_glib_none().0,
                controller.into_glib(),
            );
        }
    }

    /// ## `stream`
    /// The [`WebRTCICEStream`][crate::WebRTCICEStream]
    /// ## `ufrag`
    /// ICE username
    /// ## `pwd`
    /// ICE password
    ///
    /// # Returns
    ///
    /// FALSE on error, TRUE otherwise
    #[doc(alias = "gst_webrtc_ice_set_local_credentials")]
    fn set_local_credentials(
        &self,
        stream: &impl IsA<WebRTCICEStream>,
        ufrag: &str,
        pwd: &str,
    ) -> bool {
        unsafe {
            from_glib(ffi::gst_webrtc_ice_set_local_credentials(
                self.as_ref().to_glib_none().0,
                stream.as_ref().to_glib_none().0,
                ufrag.to_glib_none().0,
                pwd.to_glib_none().0,
            ))
        }
    }

    /// ## `func`
    /// The `GstWebRTCICEOnCandidateFunc` callback function
    /// ## `notify`
    /// a `GDestroyNotify` when the candidate is no longer needed
    #[doc(alias = "gst_webrtc_ice_set_on_ice_candidate")]
    fn set_on_ice_candidate<P: Fn(&WebRTCICE, u32, &str) + Send + Sync + 'static>(&self, func: P) {
        let func_data: Box_<P> = Box_::new(func);
        unsafe extern "C" fn func_func<P: Fn(&WebRTCICE, u32, &str) + Send + Sync + 'static>(
            ice: *mut ffi::GstWebRTCICE,
            stream_id: libc::c_uint,
            candidate: *const libc::c_char,
            user_data: glib::ffi::gpointer,
        ) {
            let ice = from_glib_borrow(ice);
            let candidate: Borrowed<glib::GString> = from_glib_borrow(candidate);
            let callback = &*(user_data as *mut P);
            (*callback)(&ice, stream_id, candidate.as_str())
        }
        let func = Some(func_func::<P> as _);
        unsafe extern "C" fn notify_func<P: Fn(&WebRTCICE, u32, &str) + Send + Sync + 'static>(
            data: glib::ffi::gpointer,
        ) {
            let _callback = Box_::from_raw(data as *mut P);
        }
        let destroy_call3 = Some(notify_func::<P> as _);
        let super_callback0: Box_<P> = func_data;
        unsafe {
            ffi::gst_webrtc_ice_set_on_ice_candidate(
                self.as_ref().to_glib_none().0,
                func,
                Box_::into_raw(super_callback0) as *mut _,
                destroy_call3,
            );
        }
    }

    /// ## `stream`
    /// The [`WebRTCICEStream`][crate::WebRTCICEStream]
    /// ## `ufrag`
    /// ICE username
    /// ## `pwd`
    /// ICE password
    ///
    /// # Returns
    ///
    /// FALSE on error, TRUE otherwise
    #[doc(alias = "gst_webrtc_ice_set_remote_credentials")]
    fn set_remote_credentials(
        &self,
        stream: &impl IsA<WebRTCICEStream>,
        ufrag: &str,
        pwd: &str,
    ) -> bool {
        unsafe {
            from_glib(ffi::gst_webrtc_ice_set_remote_credentials(
                self.as_ref().to_glib_none().0,
                stream.as_ref().to_glib_none().0,
                ufrag.to_glib_none().0,
                pwd.to_glib_none().0,
            ))
        }
    }

    /// ## `uri`
    /// URI of the STUN server
    #[doc(alias = "gst_webrtc_ice_set_stun_server")]
    fn set_stun_server(&self, uri: Option<&str>) {
        unsafe {
            ffi::gst_webrtc_ice_set_stun_server(
                self.as_ref().to_glib_none().0,
                uri.to_glib_none().0,
            );
        }
    }

    /// ## `stream`
    /// The [`WebRTCICEStream`][crate::WebRTCICEStream]
    /// ## `tos`
    /// ToS to be set
    #[doc(alias = "gst_webrtc_ice_set_tos")]
    fn set_tos(&self, stream: &impl IsA<WebRTCICEStream>, tos: u32) {
        unsafe {
            ffi::gst_webrtc_ice_set_tos(
                self.as_ref().to_glib_none().0,
                stream.as_ref().to_glib_none().0,
                tos,
            );
        }
    }

    /// ## `uri`
    /// URI of the TURN sever
    #[doc(alias = "gst_webrtc_ice_set_turn_server")]
    fn set_turn_server(&self, uri: Option<&str>) {
        unsafe {
            ffi::gst_webrtc_ice_set_turn_server(
                self.as_ref().to_glib_none().0,
                uri.to_glib_none().0,
            );
        }
    }

    /// Maximum port for local rtp port range.
    /// min-rtp-port must be <= max-rtp-port
    #[cfg(feature = "v1_20")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
    #[doc(alias = "max-rtp-port")]
    fn max_rtp_port(&self) -> u32 {
        ObjectExt::property(self.as_ref(), "max-rtp-port")
    }

    /// Maximum port for local rtp port range.
    /// min-rtp-port must be <= max-rtp-port
    #[cfg(feature = "v1_20")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
    #[doc(alias = "max-rtp-port")]
    fn set_max_rtp_port(&self, max_rtp_port: u32) {
        ObjectExt::set_property(self.as_ref(), "max-rtp-port", max_rtp_port)
    }

    /// Minimum port for local rtp port range.
    /// min-rtp-port must be <= max-rtp-port
    #[cfg(feature = "v1_20")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
    #[doc(alias = "min-rtp-port")]
    fn min_rtp_port(&self) -> u32 {
        ObjectExt::property(self.as_ref(), "min-rtp-port")
    }

    /// Minimum port for local rtp port range.
    /// min-rtp-port must be <= max-rtp-port
    #[cfg(feature = "v1_20")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
    #[doc(alias = "min-rtp-port")]
    fn set_min_rtp_port(&self, min_rtp_port: u32) {
        ObjectExt::set_property(self.as_ref(), "min-rtp-port", min_rtp_port)
    }

    /// Add a local IP address to use for ICE candidate gathering. If none
    /// are supplied, they will be discovered automatically. Calling this signal
    /// stops automatic ICE gathering.
    /// ## `address`
    /// The local IP address
    ///
    /// # Returns
    ///
    /// whether the address could be added.
    #[doc(alias = "add-local-ip-address")]
    fn connect_add_local_ip_address<F: Fn(&Self, &str) -> bool + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn add_local_ip_address_trampoline<
            P: IsA<WebRTCICE>,
            F: Fn(&P, &str) -> bool + Send + Sync + 'static,
        >(
            this: *mut ffi::GstWebRTCICE,
            address: *mut libc::c_char,
            f: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            let f: &F = &*(f as *const F);
            f(
                WebRTCICE::from_glib_borrow(this).unsafe_cast_ref(),
                &glib::GString::from_glib_borrow(address),
            )
            .into_glib()
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"add-local-ip-address\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    add_local_ip_address_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn emit_add_local_ip_address(&self, address: &str) -> bool {
        self.emit_by_name("add-local-ip-address", &[&address])
    }

    #[cfg(feature = "v1_20")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
    #[doc(alias = "max-rtp-port")]
    fn connect_max_rtp_port_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_max_rtp_port_trampoline<
            P: IsA<WebRTCICE>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GstWebRTCICE,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(WebRTCICE::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::max-rtp-port\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_max_rtp_port_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v1_20")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
    #[doc(alias = "min-rtp-port")]
    fn connect_min_rtp_port_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_min_rtp_port_trampoline<
            P: IsA<WebRTCICE>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GstWebRTCICE,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(WebRTCICE::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::min-rtp-port\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_min_rtp_port_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<WebRTCICE>> WebRTCICEExt for O {}