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
92pub trait WebRTCICEExt: IsA<WebRTCICE> + 'static {
98 #[doc(alias = "gst_webrtc_ice_add_stream")]
105 fn add_stream(&self, session_id: u32) -> Option<WebRTCICEStream> {
106 unsafe {
107 from_glib_full(ffi::gst_webrtc_ice_add_stream(
108 self.as_ref().to_glib_none().0,
109 session_id,
110 ))
111 }
112 }
113
114 #[doc(alias = "gst_webrtc_ice_add_turn_server")]
121 fn add_turn_server(&self, uri: &str) -> bool {
122 unsafe {
123 from_glib(ffi::gst_webrtc_ice_add_turn_server(
124 self.as_ref().to_glib_none().0,
125 uri.to_glib_none().0,
126 ))
127 }
128 }
129
130 #[doc(alias = "gst_webrtc_ice_find_transport")]
139 fn find_transport(
140 &self,
141 stream: &impl IsA<WebRTCICEStream>,
142 component: WebRTCICEComponent,
143 ) -> Option<WebRTCICETransport> {
144 unsafe {
145 from_glib_full(ffi::gst_webrtc_ice_find_transport(
146 self.as_ref().to_glib_none().0,
147 stream.as_ref().to_glib_none().0,
148 component.into_glib(),
149 ))
150 }
151 }
152
153 #[doc(alias = "gst_webrtc_ice_gather_candidates")]
160 fn gather_candidates(&self, stream: &impl IsA<WebRTCICEStream>) -> bool {
161 unsafe {
162 from_glib(ffi::gst_webrtc_ice_gather_candidates(
163 self.as_ref().to_glib_none().0,
164 stream.as_ref().to_glib_none().0,
165 ))
166 }
167 }
168
169 #[doc(alias = "gst_webrtc_ice_get_http_proxy")]
177 #[doc(alias = "get_http_proxy")]
178 fn http_proxy(&self) -> glib::GString {
179 unsafe {
180 from_glib_full(ffi::gst_webrtc_ice_get_http_proxy(
181 self.as_ref().to_glib_none().0,
182 ))
183 }
184 }
185
186 #[doc(alias = "gst_webrtc_ice_get_is_controller")]
191 #[doc(alias = "get_is_controller")]
192 fn is_controller(&self) -> bool {
193 unsafe {
194 from_glib(ffi::gst_webrtc_ice_get_is_controller(
195 self.as_ref().to_glib_none().0,
196 ))
197 }
198 }
199
200 #[doc(alias = "gst_webrtc_ice_get_local_candidates")]
207 #[doc(alias = "get_local_candidates")]
208 fn local_candidates(&self, stream: &impl IsA<WebRTCICEStream>) -> Vec<WebRTCICECandidateStats> {
209 unsafe {
210 FromGlibPtrContainer::from_glib_full(ffi::gst_webrtc_ice_get_local_candidates(
211 self.as_ref().to_glib_none().0,
212 stream.as_ref().to_glib_none().0,
213 ))
214 }
215 }
216
217 #[doc(alias = "gst_webrtc_ice_get_remote_candidates")]
224 #[doc(alias = "get_remote_candidates")]
225 fn remote_candidates(
226 &self,
227 stream: &impl IsA<WebRTCICEStream>,
228 ) -> Vec<WebRTCICECandidateStats> {
229 unsafe {
230 FromGlibPtrContainer::from_glib_full(ffi::gst_webrtc_ice_get_remote_candidates(
231 self.as_ref().to_glib_none().0,
232 stream.as_ref().to_glib_none().0,
233 ))
234 }
235 }
236
237 #[doc(alias = "gst_webrtc_ice_get_selected_pair")]
250 #[doc(alias = "get_selected_pair")]
251 fn selected_pair(
252 &self,
253 stream: &impl IsA<WebRTCICEStream>,
254 ) -> Option<(WebRTCICECandidateStats, WebRTCICECandidateStats)> {
255 unsafe {
256 let mut local_stats = std::ptr::null_mut();
257 let mut remote_stats = std::ptr::null_mut();
258 let ret = from_glib(ffi::gst_webrtc_ice_get_selected_pair(
259 self.as_ref().to_glib_none().0,
260 stream.as_ref().to_glib_none().0,
261 &mut local_stats,
262 &mut remote_stats,
263 ));
264 if ret {
265 Some((from_glib_full(local_stats), from_glib_full(remote_stats)))
266 } else {
267 None
268 }
269 }
270 }
271
272 #[doc(alias = "gst_webrtc_ice_get_stun_server")]
277 #[doc(alias = "get_stun_server")]
278 fn stun_server(&self) -> Option<glib::GString> {
279 unsafe {
280 from_glib_full(ffi::gst_webrtc_ice_get_stun_server(
281 self.as_ref().to_glib_none().0,
282 ))
283 }
284 }
285
286 #[doc(alias = "gst_webrtc_ice_get_turn_server")]
291 #[doc(alias = "get_turn_server")]
292 fn turn_server(&self) -> Option<glib::GString> {
293 unsafe {
294 from_glib_full(ffi::gst_webrtc_ice_get_turn_server(
295 self.as_ref().to_glib_none().0,
296 ))
297 }
298 }
299
300 #[doc(alias = "gst_webrtc_ice_set_force_relay")]
303 fn set_force_relay(&self, force_relay: bool) {
304 unsafe {
305 ffi::gst_webrtc_ice_set_force_relay(
306 self.as_ref().to_glib_none().0,
307 force_relay.into_glib(),
308 );
309 }
310 }
311
312 #[doc(alias = "gst_webrtc_ice_set_http_proxy")]
317 fn set_http_proxy(&self, uri: &str) {
318 unsafe {
319 ffi::gst_webrtc_ice_set_http_proxy(
320 self.as_ref().to_glib_none().0,
321 uri.to_glib_none().0,
322 );
323 }
324 }
325
326 #[doc(alias = "gst_webrtc_ice_set_is_controller")]
329 fn set_is_controller(&self, controller: bool) {
330 unsafe {
331 ffi::gst_webrtc_ice_set_is_controller(
332 self.as_ref().to_glib_none().0,
333 controller.into_glib(),
334 );
335 }
336 }
337
338 #[doc(alias = "gst_webrtc_ice_set_local_credentials")]
349 fn set_local_credentials(
350 &self,
351 stream: &impl IsA<WebRTCICEStream>,
352 ufrag: &str,
353 pwd: &str,
354 ) -> bool {
355 unsafe {
356 from_glib(ffi::gst_webrtc_ice_set_local_credentials(
357 self.as_ref().to_glib_none().0,
358 stream.as_ref().to_glib_none().0,
359 ufrag.to_glib_none().0,
360 pwd.to_glib_none().0,
361 ))
362 }
363 }
364
365 #[doc(alias = "gst_webrtc_ice_set_on_ice_candidate")]
370 fn set_on_ice_candidate<P: Fn(&WebRTCICE, u32, &str) + Send + Sync + 'static>(&self, func: P) {
371 let func_data: Box_<P> = Box_::new(func);
372 unsafe extern "C" fn func_func<P: Fn(&WebRTCICE, u32, &str) + Send + Sync + 'static>(
373 ice: *mut ffi::GstWebRTCICE,
374 stream_id: std::ffi::c_uint,
375 candidate: *const std::ffi::c_char,
376 user_data: glib::ffi::gpointer,
377 ) {
378 let ice = from_glib_borrow(ice);
379 let candidate: Borrowed<glib::GString> = from_glib_borrow(candidate);
380 let callback = &*(user_data as *mut P);
381 (*callback)(&ice, stream_id, candidate.as_str())
382 }
383 let func = Some(func_func::<P> as _);
384 unsafe extern "C" fn notify_func<P: Fn(&WebRTCICE, u32, &str) + Send + Sync + 'static>(
385 data: glib::ffi::gpointer,
386 ) {
387 let _callback = Box_::from_raw(data as *mut P);
388 }
389 let destroy_call3 = Some(notify_func::<P> as _);
390 let super_callback0: Box_<P> = func_data;
391 unsafe {
392 ffi::gst_webrtc_ice_set_on_ice_candidate(
393 self.as_ref().to_glib_none().0,
394 func,
395 Box_::into_raw(super_callback0) as *mut _,
396 destroy_call3,
397 );
398 }
399 }
400
401 #[doc(alias = "gst_webrtc_ice_set_remote_credentials")]
412 fn set_remote_credentials(
413 &self,
414 stream: &impl IsA<WebRTCICEStream>,
415 ufrag: &str,
416 pwd: &str,
417 ) -> bool {
418 unsafe {
419 from_glib(ffi::gst_webrtc_ice_set_remote_credentials(
420 self.as_ref().to_glib_none().0,
421 stream.as_ref().to_glib_none().0,
422 ufrag.to_glib_none().0,
423 pwd.to_glib_none().0,
424 ))
425 }
426 }
427
428 #[doc(alias = "gst_webrtc_ice_set_stun_server")]
431 fn set_stun_server(&self, uri: Option<&str>) {
432 unsafe {
433 ffi::gst_webrtc_ice_set_stun_server(
434 self.as_ref().to_glib_none().0,
435 uri.to_glib_none().0,
436 );
437 }
438 }
439
440 #[doc(alias = "gst_webrtc_ice_set_tos")]
445 fn set_tos(&self, stream: &impl IsA<WebRTCICEStream>, tos: u32) {
446 unsafe {
447 ffi::gst_webrtc_ice_set_tos(
448 self.as_ref().to_glib_none().0,
449 stream.as_ref().to_glib_none().0,
450 tos,
451 );
452 }
453 }
454
455 #[doc(alias = "gst_webrtc_ice_set_turn_server")]
458 fn set_turn_server(&self, uri: Option<&str>) {
459 unsafe {
460 ffi::gst_webrtc_ice_set_turn_server(
461 self.as_ref().to_glib_none().0,
462 uri.to_glib_none().0,
463 );
464 }
465 }
466
467 #[cfg(feature = "v1_20")]
470 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
471 #[doc(alias = "max-rtp-port")]
472 fn max_rtp_port(&self) -> u32 {
473 ObjectExt::property(self.as_ref(), "max-rtp-port")
474 }
475
476 #[cfg(feature = "v1_20")]
479 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
480 #[doc(alias = "max-rtp-port")]
481 fn set_max_rtp_port(&self, max_rtp_port: u32) {
482 ObjectExt::set_property(self.as_ref(), "max-rtp-port", max_rtp_port)
483 }
484
485 #[cfg(feature = "v1_20")]
488 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
489 #[doc(alias = "min-rtp-port")]
490 fn min_rtp_port(&self) -> u32 {
491 ObjectExt::property(self.as_ref(), "min-rtp-port")
492 }
493
494 #[cfg(feature = "v1_20")]
497 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
498 #[doc(alias = "min-rtp-port")]
499 fn set_min_rtp_port(&self, min_rtp_port: u32) {
500 ObjectExt::set_property(self.as_ref(), "min-rtp-port", min_rtp_port)
501 }
502
503 #[doc(alias = "add-local-ip-address")]
513 fn connect_add_local_ip_address<F: Fn(&Self, &str) -> bool + Send + Sync + 'static>(
514 &self,
515 f: F,
516 ) -> SignalHandlerId {
517 unsafe extern "C" fn add_local_ip_address_trampoline<
518 P: IsA<WebRTCICE>,
519 F: Fn(&P, &str) -> bool + Send + Sync + 'static,
520 >(
521 this: *mut ffi::GstWebRTCICE,
522 address: *mut std::ffi::c_char,
523 f: glib::ffi::gpointer,
524 ) -> glib::ffi::gboolean {
525 let f: &F = &*(f as *const F);
526 f(
527 WebRTCICE::from_glib_borrow(this).unsafe_cast_ref(),
528 &glib::GString::from_glib_borrow(address),
529 )
530 .into_glib()
531 }
532 unsafe {
533 let f: Box_<F> = Box_::new(f);
534 connect_raw(
535 self.as_ptr() as *mut _,
536 c"add-local-ip-address".as_ptr() as *const _,
537 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
538 add_local_ip_address_trampoline::<Self, F> as *const (),
539 )),
540 Box_::into_raw(f),
541 )
542 }
543 }
544
545 fn emit_add_local_ip_address(&self, address: &str) -> bool {
546 self.emit_by_name("add-local-ip-address", &[&address])
547 }
548
549 #[cfg(feature = "v1_20")]
550 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
551 #[doc(alias = "max-rtp-port")]
552 fn connect_max_rtp_port_notify<F: Fn(&Self) + Send + Sync + 'static>(
553 &self,
554 f: F,
555 ) -> SignalHandlerId {
556 unsafe extern "C" fn notify_max_rtp_port_trampoline<
557 P: IsA<WebRTCICE>,
558 F: Fn(&P) + Send + Sync + 'static,
559 >(
560 this: *mut ffi::GstWebRTCICE,
561 _param_spec: glib::ffi::gpointer,
562 f: glib::ffi::gpointer,
563 ) {
564 let f: &F = &*(f as *const F);
565 f(WebRTCICE::from_glib_borrow(this).unsafe_cast_ref())
566 }
567 unsafe {
568 let f: Box_<F> = Box_::new(f);
569 connect_raw(
570 self.as_ptr() as *mut _,
571 c"notify::max-rtp-port".as_ptr() as *const _,
572 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
573 notify_max_rtp_port_trampoline::<Self, F> as *const (),
574 )),
575 Box_::into_raw(f),
576 )
577 }
578 }
579
580 #[cfg(feature = "v1_20")]
581 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
582 #[doc(alias = "min-rtp-port")]
583 fn connect_min_rtp_port_notify<F: Fn(&Self) + Send + Sync + 'static>(
584 &self,
585 f: F,
586 ) -> SignalHandlerId {
587 unsafe extern "C" fn notify_min_rtp_port_trampoline<
588 P: IsA<WebRTCICE>,
589 F: Fn(&P) + Send + Sync + 'static,
590 >(
591 this: *mut ffi::GstWebRTCICE,
592 _param_spec: glib::ffi::gpointer,
593 f: glib::ffi::gpointer,
594 ) {
595 let f: &F = &*(f as *const F);
596 f(WebRTCICE::from_glib_borrow(this).unsafe_cast_ref())
597 }
598 unsafe {
599 let f: Box_<F> = Box_::new(f);
600 connect_raw(
601 self.as_ptr() as *mut _,
602 c"notify::min-rtp-port".as_ptr() as *const _,
603 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
604 notify_min_rtp_port_trampoline::<Self, F> as *const (),
605 )),
606 Box_::into_raw(f),
607 )
608 }
609 }
610}
611
612impl<O: IsA<WebRTCICE>> WebRTCICEExt for O {}