1#![allow(deprecated)]
6
7use crate::{
8 WebRTCICECandidateStats, WebRTCICEComponent, WebRTCICEStream, WebRTCICETransport, ffi,
9};
10use glib::{
11 object::ObjectType as _,
12 prelude::*,
13 signal::{SignalHandlerId, connect_raw},
14 translate::*,
15};
16use std::boxed::Box as Box_;
17
18glib::wrapper! {
19 #[doc(alias = "GstWebRTCICE")]
77 pub struct WebRTCICE(Object<ffi::GstWebRTCICE, ffi::GstWebRTCICEClass>) @extends gst::Object;
78
79 match fn {
80 type_ => || ffi::gst_webrtc_ice_get_type(),
81 }
82}
83
84impl WebRTCICE {
85 pub const NONE: Option<&'static WebRTCICE> = None;
86}
87
88unsafe impl Send for WebRTCICE {}
89unsafe impl Sync for WebRTCICE {}
90
91pub trait WebRTCICEExt: IsA<WebRTCICE> + 'static {
97 #[doc(alias = "gst_webrtc_ice_add_stream")]
104 fn add_stream(&self, session_id: u32) -> Option<WebRTCICEStream> {
105 unsafe {
106 from_glib_full(ffi::gst_webrtc_ice_add_stream(
107 self.as_ref().to_glib_none().0,
108 session_id,
109 ))
110 }
111 }
112
113 #[doc(alias = "gst_webrtc_ice_add_turn_server")]
120 fn add_turn_server(&self, uri: &str) -> bool {
121 unsafe {
122 from_glib(ffi::gst_webrtc_ice_add_turn_server(
123 self.as_ref().to_glib_none().0,
124 uri.to_glib_none().0,
125 ))
126 }
127 }
128
129 #[cfg(feature = "v1_28")]
135 #[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
136 #[doc(alias = "gst_webrtc_ice_close")]
137 fn close(&self, promise: Option<&gst::Promise>) {
138 unsafe {
139 ffi::gst_webrtc_ice_close(self.as_ref().to_glib_none().0, promise.to_glib_none().0);
140 }
141 }
142
143 #[doc(alias = "gst_webrtc_ice_find_transport")]
152 fn find_transport(
153 &self,
154 stream: &impl IsA<WebRTCICEStream>,
155 component: WebRTCICEComponent,
156 ) -> Option<WebRTCICETransport> {
157 unsafe {
158 from_glib_full(ffi::gst_webrtc_ice_find_transport(
159 self.as_ref().to_glib_none().0,
160 stream.as_ref().to_glib_none().0,
161 component.into_glib(),
162 ))
163 }
164 }
165
166 #[doc(alias = "gst_webrtc_ice_gather_candidates")]
173 fn gather_candidates(&self, stream: &impl IsA<WebRTCICEStream>) -> bool {
174 unsafe {
175 from_glib(ffi::gst_webrtc_ice_gather_candidates(
176 self.as_ref().to_glib_none().0,
177 stream.as_ref().to_glib_none().0,
178 ))
179 }
180 }
181
182 #[doc(alias = "gst_webrtc_ice_get_http_proxy")]
189 #[doc(alias = "get_http_proxy")]
190 fn http_proxy(&self) -> glib::GString {
191 unsafe {
192 from_glib_full(ffi::gst_webrtc_ice_get_http_proxy(
193 self.as_ref().to_glib_none().0,
194 ))
195 }
196 }
197
198 #[doc(alias = "gst_webrtc_ice_get_is_controller")]
203 #[doc(alias = "get_is_controller")]
204 fn is_controller(&self) -> bool {
205 unsafe {
206 from_glib(ffi::gst_webrtc_ice_get_is_controller(
207 self.as_ref().to_glib_none().0,
208 ))
209 }
210 }
211
212 #[doc(alias = "gst_webrtc_ice_get_local_candidates")]
219 #[doc(alias = "get_local_candidates")]
220 fn local_candidates(&self, stream: &impl IsA<WebRTCICEStream>) -> Vec<WebRTCICECandidateStats> {
221 unsafe {
222 FromGlibPtrContainer::from_glib_full(ffi::gst_webrtc_ice_get_local_candidates(
223 self.as_ref().to_glib_none().0,
224 stream.as_ref().to_glib_none().0,
225 ))
226 }
227 }
228
229 #[doc(alias = "gst_webrtc_ice_get_remote_candidates")]
236 #[doc(alias = "get_remote_candidates")]
237 fn remote_candidates(
238 &self,
239 stream: &impl IsA<WebRTCICEStream>,
240 ) -> Vec<WebRTCICECandidateStats> {
241 unsafe {
242 FromGlibPtrContainer::from_glib_full(ffi::gst_webrtc_ice_get_remote_candidates(
243 self.as_ref().to_glib_none().0,
244 stream.as_ref().to_glib_none().0,
245 ))
246 }
247 }
248
249 #[cfg_attr(feature = "v1_28", deprecated = "Since 1.28")]
266 #[allow(deprecated)]
267 #[doc(alias = "gst_webrtc_ice_get_selected_pair")]
268 #[doc(alias = "get_selected_pair")]
269 fn selected_pair(
270 &self,
271 stream: &impl IsA<WebRTCICEStream>,
272 ) -> Option<(WebRTCICECandidateStats, WebRTCICECandidateStats)> {
273 unsafe {
274 let mut local_stats = std::ptr::null_mut();
275 let mut remote_stats = std::ptr::null_mut();
276 let ret = from_glib(ffi::gst_webrtc_ice_get_selected_pair(
277 self.as_ref().to_glib_none().0,
278 stream.as_ref().to_glib_none().0,
279 &mut local_stats,
280 &mut remote_stats,
281 ));
282 if ret {
283 Some((from_glib_full(local_stats), from_glib_full(remote_stats)))
284 } else {
285 None
286 }
287 }
288 }
289
290 #[doc(alias = "gst_webrtc_ice_get_stun_server")]
295 #[doc(alias = "get_stun_server")]
296 fn stun_server(&self) -> Option<glib::GString> {
297 unsafe {
298 from_glib_full(ffi::gst_webrtc_ice_get_stun_server(
299 self.as_ref().to_glib_none().0,
300 ))
301 }
302 }
303
304 #[doc(alias = "gst_webrtc_ice_get_turn_server")]
309 #[doc(alias = "get_turn_server")]
310 fn turn_server(&self) -> Option<glib::GString> {
311 unsafe {
312 from_glib_full(ffi::gst_webrtc_ice_get_turn_server(
313 self.as_ref().to_glib_none().0,
314 ))
315 }
316 }
317
318 #[doc(alias = "gst_webrtc_ice_set_force_relay")]
321 fn set_force_relay(&self, force_relay: bool) {
322 unsafe {
323 ffi::gst_webrtc_ice_set_force_relay(
324 self.as_ref().to_glib_none().0,
325 force_relay.into_glib(),
326 );
327 }
328 }
329
330 #[doc(alias = "gst_webrtc_ice_set_http_proxy")]
334 fn set_http_proxy(&self, uri: &str) {
335 unsafe {
336 ffi::gst_webrtc_ice_set_http_proxy(
337 self.as_ref().to_glib_none().0,
338 uri.to_glib_none().0,
339 );
340 }
341 }
342
343 #[doc(alias = "gst_webrtc_ice_set_is_controller")]
346 fn set_is_controller(&self, controller: bool) {
347 unsafe {
348 ffi::gst_webrtc_ice_set_is_controller(
349 self.as_ref().to_glib_none().0,
350 controller.into_glib(),
351 );
352 }
353 }
354
355 #[doc(alias = "gst_webrtc_ice_set_local_credentials")]
366 fn set_local_credentials(
367 &self,
368 stream: &impl IsA<WebRTCICEStream>,
369 ufrag: &str,
370 pwd: &str,
371 ) -> bool {
372 unsafe {
373 from_glib(ffi::gst_webrtc_ice_set_local_credentials(
374 self.as_ref().to_glib_none().0,
375 stream.as_ref().to_glib_none().0,
376 ufrag.to_glib_none().0,
377 pwd.to_glib_none().0,
378 ))
379 }
380 }
381
382 #[doc(alias = "gst_webrtc_ice_set_on_ice_candidate")]
387 fn set_on_ice_candidate<P: Fn(&WebRTCICE, u32, &str) + Send + Sync + 'static>(&self, func: P) {
388 let func_data: Box_<P> = Box_::new(func);
389 unsafe extern "C" fn func_func<P: Fn(&WebRTCICE, u32, &str) + Send + Sync + 'static>(
390 ice: *mut ffi::GstWebRTCICE,
391 stream_id: std::ffi::c_uint,
392 candidate: *const std::ffi::c_char,
393 user_data: glib::ffi::gpointer,
394 ) {
395 unsafe {
396 let ice = from_glib_borrow(ice);
397 let candidate: Borrowed<glib::GString> = from_glib_borrow(candidate);
398 let callback = &*(user_data as *mut P);
399 (*callback)(&ice, stream_id, candidate.as_str())
400 }
401 }
402 let func = Some(func_func::<P> as _);
403 unsafe extern "C" fn notify_func<P: Fn(&WebRTCICE, u32, &str) + Send + Sync + 'static>(
404 data: glib::ffi::gpointer,
405 ) {
406 unsafe {
407 let _callback = Box_::from_raw(data as *mut P);
408 }
409 }
410 let destroy_call3 = Some(notify_func::<P> as _);
411 let super_callback0: Box_<P> = func_data;
412 unsafe {
413 ffi::gst_webrtc_ice_set_on_ice_candidate(
414 self.as_ref().to_glib_none().0,
415 func,
416 Box_::into_raw(super_callback0) as *mut _,
417 destroy_call3,
418 );
419 }
420 }
421
422 #[doc(alias = "gst_webrtc_ice_set_remote_credentials")]
433 fn set_remote_credentials(
434 &self,
435 stream: &impl IsA<WebRTCICEStream>,
436 ufrag: &str,
437 pwd: &str,
438 ) -> bool {
439 unsafe {
440 from_glib(ffi::gst_webrtc_ice_set_remote_credentials(
441 self.as_ref().to_glib_none().0,
442 stream.as_ref().to_glib_none().0,
443 ufrag.to_glib_none().0,
444 pwd.to_glib_none().0,
445 ))
446 }
447 }
448
449 #[doc(alias = "gst_webrtc_ice_set_stun_server")]
452 fn set_stun_server(&self, uri: Option<&str>) {
453 unsafe {
454 ffi::gst_webrtc_ice_set_stun_server(
455 self.as_ref().to_glib_none().0,
456 uri.to_glib_none().0,
457 );
458 }
459 }
460
461 #[doc(alias = "gst_webrtc_ice_set_tos")]
466 fn set_tos(&self, stream: &impl IsA<WebRTCICEStream>, tos: u32) {
467 unsafe {
468 ffi::gst_webrtc_ice_set_tos(
469 self.as_ref().to_glib_none().0,
470 stream.as_ref().to_glib_none().0,
471 tos,
472 );
473 }
474 }
475
476 #[doc(alias = "gst_webrtc_ice_set_turn_server")]
479 fn set_turn_server(&self, uri: Option<&str>) {
480 unsafe {
481 ffi::gst_webrtc_ice_set_turn_server(
482 self.as_ref().to_glib_none().0,
483 uri.to_glib_none().0,
484 );
485 }
486 }
487
488 #[cfg(feature = "v1_20")]
490 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
491 #[doc(alias = "max-rtp-port")]
492 fn max_rtp_port(&self) -> u32 {
493 ObjectExt::property(self.as_ref(), "max-rtp-port")
494 }
495
496 #[cfg(feature = "v1_20")]
498 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
499 #[doc(alias = "max-rtp-port")]
500 fn set_max_rtp_port(&self, max_rtp_port: u32) {
501 ObjectExt::set_property(self.as_ref(), "max-rtp-port", max_rtp_port)
502 }
503
504 #[cfg(feature = "v1_20")]
506 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
507 #[doc(alias = "min-rtp-port")]
508 fn min_rtp_port(&self) -> u32 {
509 ObjectExt::property(self.as_ref(), "min-rtp-port")
510 }
511
512 #[cfg(feature = "v1_20")]
514 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
515 #[doc(alias = "min-rtp-port")]
516 fn set_min_rtp_port(&self, min_rtp_port: u32) {
517 ObjectExt::set_property(self.as_ref(), "min-rtp-port", min_rtp_port)
518 }
519
520 #[doc(alias = "add-local-ip-address")]
530 fn connect_add_local_ip_address<F: Fn(&Self, &str) -> bool + Send + Sync + 'static>(
531 &self,
532 f: F,
533 ) -> SignalHandlerId {
534 unsafe extern "C" fn add_local_ip_address_trampoline<
535 P: IsA<WebRTCICE>,
536 F: Fn(&P, &str) -> bool + Send + Sync + 'static,
537 >(
538 this: *mut ffi::GstWebRTCICE,
539 address: *mut std::ffi::c_char,
540 f: glib::ffi::gpointer,
541 ) -> glib::ffi::gboolean {
542 unsafe {
543 let f: &F = &*(f as *const F);
544 f(
545 WebRTCICE::from_glib_borrow(this).unsafe_cast_ref(),
546 &glib::GString::from_glib_borrow(address),
547 )
548 .into_glib()
549 }
550 }
551 unsafe {
552 let f: Box_<F> = Box_::new(f);
553 connect_raw(
554 self.as_ptr() as *mut _,
555 c"add-local-ip-address".as_ptr(),
556 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
557 add_local_ip_address_trampoline::<Self, F> as *const (),
558 )),
559 Box_::into_raw(f),
560 )
561 }
562 }
563
564 fn emit_add_local_ip_address(&self, address: &str) -> bool {
565 self.emit_by_name("add-local-ip-address", &[&address])
566 }
567
568 #[cfg(feature = "v1_20")]
569 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
570 #[doc(alias = "max-rtp-port")]
571 fn connect_max_rtp_port_notify<F: Fn(&Self) + Send + Sync + 'static>(
572 &self,
573 f: F,
574 ) -> SignalHandlerId {
575 unsafe extern "C" fn notify_max_rtp_port_trampoline<
576 P: IsA<WebRTCICE>,
577 F: Fn(&P) + Send + Sync + 'static,
578 >(
579 this: *mut ffi::GstWebRTCICE,
580 _param_spec: glib::ffi::gpointer,
581 f: glib::ffi::gpointer,
582 ) {
583 unsafe {
584 let f: &F = &*(f as *const F);
585 f(WebRTCICE::from_glib_borrow(this).unsafe_cast_ref())
586 }
587 }
588 unsafe {
589 let f: Box_<F> = Box_::new(f);
590 connect_raw(
591 self.as_ptr() as *mut _,
592 c"notify::max-rtp-port".as_ptr(),
593 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
594 notify_max_rtp_port_trampoline::<Self, F> as *const (),
595 )),
596 Box_::into_raw(f),
597 )
598 }
599 }
600
601 #[cfg(feature = "v1_20")]
602 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
603 #[doc(alias = "min-rtp-port")]
604 fn connect_min_rtp_port_notify<F: Fn(&Self) + Send + Sync + 'static>(
605 &self,
606 f: F,
607 ) -> SignalHandlerId {
608 unsafe extern "C" fn notify_min_rtp_port_trampoline<
609 P: IsA<WebRTCICE>,
610 F: Fn(&P) + Send + Sync + 'static,
611 >(
612 this: *mut ffi::GstWebRTCICE,
613 _param_spec: glib::ffi::gpointer,
614 f: glib::ffi::gpointer,
615 ) {
616 unsafe {
617 let f: &F = &*(f as *const F);
618 f(WebRTCICE::from_glib_borrow(this).unsafe_cast_ref())
619 }
620 }
621 unsafe {
622 let f: Box_<F> = Box_::new(f);
623 connect_raw(
624 self.as_ptr() as *mut _,
625 c"notify::min-rtp-port".as_ptr(),
626 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
627 notify_min_rtp_port_trampoline::<Self, F> as *const (),
628 )),
629 Box_::into_raw(f),
630 )
631 }
632 }
633}
634
635impl<O: IsA<WebRTCICE>> WebRTCICEExt for O {}