1use crate::{
7 ffi, WebRTCICECandidateStats, WebRTCICEComponent, WebRTCICEStream, WebRTCICETransport,
8};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 #[doc(alias = "GstWebRTCICE")]
78 pub struct WebRTCICE(Object<ffi::GstWebRTCICE, ffi::GstWebRTCICEClass>);
79
80 match fn {
81 type_ => || ffi::gst_webrtc_ice_get_type(),
82 }
83}
84
85impl WebRTCICE {
86 pub const NONE: Option<&'static WebRTCICE> = None;
87}
88
89unsafe impl Send for WebRTCICE {}
90unsafe impl Sync for WebRTCICE {}
91
92mod sealed {
93 pub trait Sealed {}
94 impl<T: super::IsA<super::WebRTCICE>> Sealed for T {}
95}
96
97pub trait WebRTCICEExt: IsA<WebRTCICE> + sealed::Sealed + 'static {
103 #[doc(alias = "gst_webrtc_ice_add_stream")]
110 fn add_stream(&self, session_id: u32) -> Option<WebRTCICEStream> {
111 unsafe {
112 from_glib_full(ffi::gst_webrtc_ice_add_stream(
113 self.as_ref().to_glib_none().0,
114 session_id,
115 ))
116 }
117 }
118
119 #[doc(alias = "gst_webrtc_ice_add_turn_server")]
126 fn add_turn_server(&self, uri: &str) -> bool {
127 unsafe {
128 from_glib(ffi::gst_webrtc_ice_add_turn_server(
129 self.as_ref().to_glib_none().0,
130 uri.to_glib_none().0,
131 ))
132 }
133 }
134
135 #[doc(alias = "gst_webrtc_ice_find_transport")]
144 fn find_transport(
145 &self,
146 stream: &impl IsA<WebRTCICEStream>,
147 component: WebRTCICEComponent,
148 ) -> Option<WebRTCICETransport> {
149 unsafe {
150 from_glib_full(ffi::gst_webrtc_ice_find_transport(
151 self.as_ref().to_glib_none().0,
152 stream.as_ref().to_glib_none().0,
153 component.into_glib(),
154 ))
155 }
156 }
157
158 #[doc(alias = "gst_webrtc_ice_gather_candidates")]
165 fn gather_candidates(&self, stream: &impl IsA<WebRTCICEStream>) -> bool {
166 unsafe {
167 from_glib(ffi::gst_webrtc_ice_gather_candidates(
168 self.as_ref().to_glib_none().0,
169 stream.as_ref().to_glib_none().0,
170 ))
171 }
172 }
173
174 #[doc(alias = "gst_webrtc_ice_get_http_proxy")]
182 #[doc(alias = "get_http_proxy")]
183 fn http_proxy(&self) -> glib::GString {
184 unsafe {
185 from_glib_full(ffi::gst_webrtc_ice_get_http_proxy(
186 self.as_ref().to_glib_none().0,
187 ))
188 }
189 }
190
191 #[doc(alias = "gst_webrtc_ice_get_is_controller")]
196 #[doc(alias = "get_is_controller")]
197 fn is_controller(&self) -> bool {
198 unsafe {
199 from_glib(ffi::gst_webrtc_ice_get_is_controller(
200 self.as_ref().to_glib_none().0,
201 ))
202 }
203 }
204
205 #[doc(alias = "gst_webrtc_ice_get_local_candidates")]
212 #[doc(alias = "get_local_candidates")]
213 fn local_candidates(&self, stream: &impl IsA<WebRTCICEStream>) -> Vec<WebRTCICECandidateStats> {
214 unsafe {
215 FromGlibPtrContainer::from_glib_full(ffi::gst_webrtc_ice_get_local_candidates(
216 self.as_ref().to_glib_none().0,
217 stream.as_ref().to_glib_none().0,
218 ))
219 }
220 }
221
222 #[doc(alias = "gst_webrtc_ice_get_remote_candidates")]
229 #[doc(alias = "get_remote_candidates")]
230 fn remote_candidates(
231 &self,
232 stream: &impl IsA<WebRTCICEStream>,
233 ) -> Vec<WebRTCICECandidateStats> {
234 unsafe {
235 FromGlibPtrContainer::from_glib_full(ffi::gst_webrtc_ice_get_remote_candidates(
236 self.as_ref().to_glib_none().0,
237 stream.as_ref().to_glib_none().0,
238 ))
239 }
240 }
241
242 #[doc(alias = "gst_webrtc_ice_get_selected_pair")]
255 #[doc(alias = "get_selected_pair")]
256 fn selected_pair(
257 &self,
258 stream: &impl IsA<WebRTCICEStream>,
259 ) -> Option<(WebRTCICECandidateStats, WebRTCICECandidateStats)> {
260 unsafe {
261 let mut local_stats = std::ptr::null_mut();
262 let mut remote_stats = std::ptr::null_mut();
263 let ret = from_glib(ffi::gst_webrtc_ice_get_selected_pair(
264 self.as_ref().to_glib_none().0,
265 stream.as_ref().to_glib_none().0,
266 &mut local_stats,
267 &mut remote_stats,
268 ));
269 if ret {
270 Some((from_glib_full(local_stats), from_glib_full(remote_stats)))
271 } else {
272 None
273 }
274 }
275 }
276
277 #[doc(alias = "gst_webrtc_ice_get_stun_server")]
282 #[doc(alias = "get_stun_server")]
283 fn stun_server(&self) -> Option<glib::GString> {
284 unsafe {
285 from_glib_full(ffi::gst_webrtc_ice_get_stun_server(
286 self.as_ref().to_glib_none().0,
287 ))
288 }
289 }
290
291 #[doc(alias = "gst_webrtc_ice_get_turn_server")]
296 #[doc(alias = "get_turn_server")]
297 fn turn_server(&self) -> Option<glib::GString> {
298 unsafe {
299 from_glib_full(ffi::gst_webrtc_ice_get_turn_server(
300 self.as_ref().to_glib_none().0,
301 ))
302 }
303 }
304
305 #[doc(alias = "gst_webrtc_ice_set_force_relay")]
308 fn set_force_relay(&self, force_relay: bool) {
309 unsafe {
310 ffi::gst_webrtc_ice_set_force_relay(
311 self.as_ref().to_glib_none().0,
312 force_relay.into_glib(),
313 );
314 }
315 }
316
317 #[doc(alias = "gst_webrtc_ice_set_http_proxy")]
322 fn set_http_proxy(&self, uri: &str) {
323 unsafe {
324 ffi::gst_webrtc_ice_set_http_proxy(
325 self.as_ref().to_glib_none().0,
326 uri.to_glib_none().0,
327 );
328 }
329 }
330
331 #[doc(alias = "gst_webrtc_ice_set_is_controller")]
334 fn set_is_controller(&self, controller: bool) {
335 unsafe {
336 ffi::gst_webrtc_ice_set_is_controller(
337 self.as_ref().to_glib_none().0,
338 controller.into_glib(),
339 );
340 }
341 }
342
343 #[doc(alias = "gst_webrtc_ice_set_local_credentials")]
354 fn set_local_credentials(
355 &self,
356 stream: &impl IsA<WebRTCICEStream>,
357 ufrag: &str,
358 pwd: &str,
359 ) -> bool {
360 unsafe {
361 from_glib(ffi::gst_webrtc_ice_set_local_credentials(
362 self.as_ref().to_glib_none().0,
363 stream.as_ref().to_glib_none().0,
364 ufrag.to_glib_none().0,
365 pwd.to_glib_none().0,
366 ))
367 }
368 }
369
370 #[doc(alias = "gst_webrtc_ice_set_on_ice_candidate")]
375 fn set_on_ice_candidate<P: Fn(&WebRTCICE, u32, &str) + Send + Sync + 'static>(&self, func: P) {
376 let func_data: Box_<P> = Box_::new(func);
377 unsafe extern "C" fn func_func<P: Fn(&WebRTCICE, u32, &str) + Send + Sync + 'static>(
378 ice: *mut ffi::GstWebRTCICE,
379 stream_id: std::ffi::c_uint,
380 candidate: *const std::ffi::c_char,
381 user_data: glib::ffi::gpointer,
382 ) {
383 let ice = from_glib_borrow(ice);
384 let candidate: Borrowed<glib::GString> = from_glib_borrow(candidate);
385 let callback = &*(user_data as *mut P);
386 (*callback)(&ice, stream_id, candidate.as_str())
387 }
388 let func = Some(func_func::<P> as _);
389 unsafe extern "C" fn notify_func<P: Fn(&WebRTCICE, u32, &str) + Send + Sync + 'static>(
390 data: glib::ffi::gpointer,
391 ) {
392 let _callback = Box_::from_raw(data as *mut P);
393 }
394 let destroy_call3 = Some(notify_func::<P> as _);
395 let super_callback0: Box_<P> = func_data;
396 unsafe {
397 ffi::gst_webrtc_ice_set_on_ice_candidate(
398 self.as_ref().to_glib_none().0,
399 func,
400 Box_::into_raw(super_callback0) as *mut _,
401 destroy_call3,
402 );
403 }
404 }
405
406 #[doc(alias = "gst_webrtc_ice_set_remote_credentials")]
417 fn set_remote_credentials(
418 &self,
419 stream: &impl IsA<WebRTCICEStream>,
420 ufrag: &str,
421 pwd: &str,
422 ) -> bool {
423 unsafe {
424 from_glib(ffi::gst_webrtc_ice_set_remote_credentials(
425 self.as_ref().to_glib_none().0,
426 stream.as_ref().to_glib_none().0,
427 ufrag.to_glib_none().0,
428 pwd.to_glib_none().0,
429 ))
430 }
431 }
432
433 #[doc(alias = "gst_webrtc_ice_set_stun_server")]
436 fn set_stun_server(&self, uri: Option<&str>) {
437 unsafe {
438 ffi::gst_webrtc_ice_set_stun_server(
439 self.as_ref().to_glib_none().0,
440 uri.to_glib_none().0,
441 );
442 }
443 }
444
445 #[doc(alias = "gst_webrtc_ice_set_tos")]
450 fn set_tos(&self, stream: &impl IsA<WebRTCICEStream>, tos: u32) {
451 unsafe {
452 ffi::gst_webrtc_ice_set_tos(
453 self.as_ref().to_glib_none().0,
454 stream.as_ref().to_glib_none().0,
455 tos,
456 );
457 }
458 }
459
460 #[doc(alias = "gst_webrtc_ice_set_turn_server")]
463 fn set_turn_server(&self, uri: Option<&str>) {
464 unsafe {
465 ffi::gst_webrtc_ice_set_turn_server(
466 self.as_ref().to_glib_none().0,
467 uri.to_glib_none().0,
468 );
469 }
470 }
471
472 #[cfg(feature = "v1_20")]
475 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
476 #[doc(alias = "max-rtp-port")]
477 fn max_rtp_port(&self) -> u32 {
478 ObjectExt::property(self.as_ref(), "max-rtp-port")
479 }
480
481 #[cfg(feature = "v1_20")]
484 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
485 #[doc(alias = "max-rtp-port")]
486 fn set_max_rtp_port(&self, max_rtp_port: u32) {
487 ObjectExt::set_property(self.as_ref(), "max-rtp-port", max_rtp_port)
488 }
489
490 #[cfg(feature = "v1_20")]
493 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
494 #[doc(alias = "min-rtp-port")]
495 fn min_rtp_port(&self) -> u32 {
496 ObjectExt::property(self.as_ref(), "min-rtp-port")
497 }
498
499 #[cfg(feature = "v1_20")]
502 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
503 #[doc(alias = "min-rtp-port")]
504 fn set_min_rtp_port(&self, min_rtp_port: u32) {
505 ObjectExt::set_property(self.as_ref(), "min-rtp-port", min_rtp_port)
506 }
507
508 #[doc(alias = "add-local-ip-address")]
518 fn connect_add_local_ip_address<F: Fn(&Self, &str) -> bool + Send + Sync + 'static>(
519 &self,
520 f: F,
521 ) -> SignalHandlerId {
522 unsafe extern "C" fn add_local_ip_address_trampoline<
523 P: IsA<WebRTCICE>,
524 F: Fn(&P, &str) -> bool + Send + Sync + 'static,
525 >(
526 this: *mut ffi::GstWebRTCICE,
527 address: *mut std::ffi::c_char,
528 f: glib::ffi::gpointer,
529 ) -> glib::ffi::gboolean {
530 let f: &F = &*(f as *const F);
531 f(
532 WebRTCICE::from_glib_borrow(this).unsafe_cast_ref(),
533 &glib::GString::from_glib_borrow(address),
534 )
535 .into_glib()
536 }
537 unsafe {
538 let f: Box_<F> = Box_::new(f);
539 connect_raw(
540 self.as_ptr() as *mut _,
541 b"add-local-ip-address\0".as_ptr() as *const _,
542 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
543 add_local_ip_address_trampoline::<Self, F> as *const (),
544 )),
545 Box_::into_raw(f),
546 )
547 }
548 }
549
550 fn emit_add_local_ip_address(&self, address: &str) -> bool {
551 self.emit_by_name("add-local-ip-address", &[&address])
552 }
553
554 #[cfg(feature = "v1_20")]
555 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
556 #[doc(alias = "max-rtp-port")]
557 fn connect_max_rtp_port_notify<F: Fn(&Self) + Send + Sync + 'static>(
558 &self,
559 f: F,
560 ) -> SignalHandlerId {
561 unsafe extern "C" fn notify_max_rtp_port_trampoline<
562 P: IsA<WebRTCICE>,
563 F: Fn(&P) + Send + Sync + 'static,
564 >(
565 this: *mut ffi::GstWebRTCICE,
566 _param_spec: glib::ffi::gpointer,
567 f: glib::ffi::gpointer,
568 ) {
569 let f: &F = &*(f as *const F);
570 f(WebRTCICE::from_glib_borrow(this).unsafe_cast_ref())
571 }
572 unsafe {
573 let f: Box_<F> = Box_::new(f);
574 connect_raw(
575 self.as_ptr() as *mut _,
576 b"notify::max-rtp-port\0".as_ptr() as *const _,
577 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
578 notify_max_rtp_port_trampoline::<Self, F> as *const (),
579 )),
580 Box_::into_raw(f),
581 )
582 }
583 }
584
585 #[cfg(feature = "v1_20")]
586 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
587 #[doc(alias = "min-rtp-port")]
588 fn connect_min_rtp_port_notify<F: Fn(&Self) + Send + Sync + 'static>(
589 &self,
590 f: F,
591 ) -> SignalHandlerId {
592 unsafe extern "C" fn notify_min_rtp_port_trampoline<
593 P: IsA<WebRTCICE>,
594 F: Fn(&P) + Send + Sync + 'static,
595 >(
596 this: *mut ffi::GstWebRTCICE,
597 _param_spec: glib::ffi::gpointer,
598 f: glib::ffi::gpointer,
599 ) {
600 let f: &F = &*(f as *const F);
601 f(WebRTCICE::from_glib_borrow(this).unsafe_cast_ref())
602 }
603 unsafe {
604 let f: Box_<F> = Box_::new(f);
605 connect_raw(
606 self.as_ptr() as *mut _,
607 b"notify::min-rtp-port\0".as_ptr() as *const _,
608 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
609 notify_min_rtp_port_trampoline::<Self, F> as *const (),
610 )),
611 Box_::into_raw(f),
612 )
613 }
614 }
615}
616
617impl<O: IsA<WebRTCICE>> WebRTCICEExt for O {}