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")]
79 pub struct WebRTCICE(Object<ffi::GstWebRTCICE, ffi::GstWebRTCICEClass>) @extends gst::Object;
80
81 match fn {
82 type_ => || ffi::gst_webrtc_ice_get_type(),
83 }
84}
85
86impl WebRTCICE {
87 pub const NONE: Option<&'static WebRTCICE> = None;
88}
89
90unsafe impl Send for WebRTCICE {}
91unsafe impl Sync for WebRTCICE {}
92
93pub trait WebRTCICEExt: IsA<WebRTCICE> + 'static {
99 #[doc(alias = "gst_webrtc_ice_add_stream")]
106 fn add_stream(&self, session_id: u32) -> Option<WebRTCICEStream> {
107 unsafe {
108 from_glib_full(ffi::gst_webrtc_ice_add_stream(
109 self.as_ref().to_glib_none().0,
110 session_id,
111 ))
112 }
113 }
114
115 #[doc(alias = "gst_webrtc_ice_add_turn_server")]
122 fn add_turn_server(&self, uri: &str) -> bool {
123 unsafe {
124 from_glib(ffi::gst_webrtc_ice_add_turn_server(
125 self.as_ref().to_glib_none().0,
126 uri.to_glib_none().0,
127 ))
128 }
129 }
130
131 #[cfg(feature = "v1_28")]
137 #[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
138 #[doc(alias = "gst_webrtc_ice_close")]
139 fn close(&self, promise: Option<&gst::Promise>) {
140 unsafe {
141 ffi::gst_webrtc_ice_close(self.as_ref().to_glib_none().0, promise.to_glib_none().0);
142 }
143 }
144
145 #[doc(alias = "gst_webrtc_ice_find_transport")]
154 fn find_transport(
155 &self,
156 stream: &impl IsA<WebRTCICEStream>,
157 component: WebRTCICEComponent,
158 ) -> Option<WebRTCICETransport> {
159 unsafe {
160 from_glib_full(ffi::gst_webrtc_ice_find_transport(
161 self.as_ref().to_glib_none().0,
162 stream.as_ref().to_glib_none().0,
163 component.into_glib(),
164 ))
165 }
166 }
167
168 #[doc(alias = "gst_webrtc_ice_gather_candidates")]
175 fn gather_candidates(&self, stream: &impl IsA<WebRTCICEStream>) -> bool {
176 unsafe {
177 from_glib(ffi::gst_webrtc_ice_gather_candidates(
178 self.as_ref().to_glib_none().0,
179 stream.as_ref().to_glib_none().0,
180 ))
181 }
182 }
183
184 #[doc(alias = "gst_webrtc_ice_get_http_proxy")]
192 #[doc(alias = "get_http_proxy")]
193 fn http_proxy(&self) -> glib::GString {
194 unsafe {
195 from_glib_full(ffi::gst_webrtc_ice_get_http_proxy(
196 self.as_ref().to_glib_none().0,
197 ))
198 }
199 }
200
201 #[doc(alias = "gst_webrtc_ice_get_is_controller")]
206 #[doc(alias = "get_is_controller")]
207 fn is_controller(&self) -> bool {
208 unsafe {
209 from_glib(ffi::gst_webrtc_ice_get_is_controller(
210 self.as_ref().to_glib_none().0,
211 ))
212 }
213 }
214
215 #[doc(alias = "gst_webrtc_ice_get_local_candidates")]
222 #[doc(alias = "get_local_candidates")]
223 fn local_candidates(&self, stream: &impl IsA<WebRTCICEStream>) -> Vec<WebRTCICECandidateStats> {
224 unsafe {
225 FromGlibPtrContainer::from_glib_full(ffi::gst_webrtc_ice_get_local_candidates(
226 self.as_ref().to_glib_none().0,
227 stream.as_ref().to_glib_none().0,
228 ))
229 }
230 }
231
232 #[doc(alias = "gst_webrtc_ice_get_remote_candidates")]
239 #[doc(alias = "get_remote_candidates")]
240 fn remote_candidates(
241 &self,
242 stream: &impl IsA<WebRTCICEStream>,
243 ) -> Vec<WebRTCICECandidateStats> {
244 unsafe {
245 FromGlibPtrContainer::from_glib_full(ffi::gst_webrtc_ice_get_remote_candidates(
246 self.as_ref().to_glib_none().0,
247 stream.as_ref().to_glib_none().0,
248 ))
249 }
250 }
251
252 #[cfg_attr(feature = "v1_28", deprecated = "Since 1.28")]
269 #[allow(deprecated)]
270 #[doc(alias = "gst_webrtc_ice_get_selected_pair")]
271 #[doc(alias = "get_selected_pair")]
272 fn selected_pair(
273 &self,
274 stream: &impl IsA<WebRTCICEStream>,
275 ) -> Option<(WebRTCICECandidateStats, WebRTCICECandidateStats)> {
276 unsafe {
277 let mut local_stats = std::ptr::null_mut();
278 let mut remote_stats = std::ptr::null_mut();
279 let ret = from_glib(ffi::gst_webrtc_ice_get_selected_pair(
280 self.as_ref().to_glib_none().0,
281 stream.as_ref().to_glib_none().0,
282 &mut local_stats,
283 &mut remote_stats,
284 ));
285 if ret {
286 Some((from_glib_full(local_stats), from_glib_full(remote_stats)))
287 } else {
288 None
289 }
290 }
291 }
292
293 #[doc(alias = "gst_webrtc_ice_get_stun_server")]
298 #[doc(alias = "get_stun_server")]
299 fn stun_server(&self) -> Option<glib::GString> {
300 unsafe {
301 from_glib_full(ffi::gst_webrtc_ice_get_stun_server(
302 self.as_ref().to_glib_none().0,
303 ))
304 }
305 }
306
307 #[doc(alias = "gst_webrtc_ice_get_turn_server")]
312 #[doc(alias = "get_turn_server")]
313 fn turn_server(&self) -> Option<glib::GString> {
314 unsafe {
315 from_glib_full(ffi::gst_webrtc_ice_get_turn_server(
316 self.as_ref().to_glib_none().0,
317 ))
318 }
319 }
320
321 #[doc(alias = "gst_webrtc_ice_set_force_relay")]
324 fn set_force_relay(&self, force_relay: bool) {
325 unsafe {
326 ffi::gst_webrtc_ice_set_force_relay(
327 self.as_ref().to_glib_none().0,
328 force_relay.into_glib(),
329 );
330 }
331 }
332
333 #[doc(alias = "gst_webrtc_ice_set_http_proxy")]
338 fn set_http_proxy(&self, uri: &str) {
339 unsafe {
340 ffi::gst_webrtc_ice_set_http_proxy(
341 self.as_ref().to_glib_none().0,
342 uri.to_glib_none().0,
343 );
344 }
345 }
346
347 #[doc(alias = "gst_webrtc_ice_set_is_controller")]
350 fn set_is_controller(&self, controller: bool) {
351 unsafe {
352 ffi::gst_webrtc_ice_set_is_controller(
353 self.as_ref().to_glib_none().0,
354 controller.into_glib(),
355 );
356 }
357 }
358
359 #[doc(alias = "gst_webrtc_ice_set_local_credentials")]
370 fn set_local_credentials(
371 &self,
372 stream: &impl IsA<WebRTCICEStream>,
373 ufrag: &str,
374 pwd: &str,
375 ) -> bool {
376 unsafe {
377 from_glib(ffi::gst_webrtc_ice_set_local_credentials(
378 self.as_ref().to_glib_none().0,
379 stream.as_ref().to_glib_none().0,
380 ufrag.to_glib_none().0,
381 pwd.to_glib_none().0,
382 ))
383 }
384 }
385
386 #[doc(alias = "gst_webrtc_ice_set_on_ice_candidate")]
391 fn set_on_ice_candidate<P: Fn(&WebRTCICE, u32, &str) + Send + Sync + 'static>(&self, func: P) {
392 let func_data: Box_<P> = Box_::new(func);
393 unsafe extern "C" fn func_func<P: Fn(&WebRTCICE, u32, &str) + Send + Sync + 'static>(
394 ice: *mut ffi::GstWebRTCICE,
395 stream_id: std::ffi::c_uint,
396 candidate: *const std::ffi::c_char,
397 user_data: glib::ffi::gpointer,
398 ) {
399 unsafe {
400 let ice = from_glib_borrow(ice);
401 let candidate: Borrowed<glib::GString> = from_glib_borrow(candidate);
402 let callback = &*(user_data as *mut P);
403 (*callback)(&ice, stream_id, candidate.as_str())
404 }
405 }
406 let func = Some(func_func::<P> as _);
407 unsafe extern "C" fn notify_func<P: Fn(&WebRTCICE, u32, &str) + Send + Sync + 'static>(
408 data: glib::ffi::gpointer,
409 ) {
410 unsafe {
411 let _callback = Box_::from_raw(data as *mut P);
412 }
413 }
414 let destroy_call3 = Some(notify_func::<P> as _);
415 let super_callback0: Box_<P> = func_data;
416 unsafe {
417 ffi::gst_webrtc_ice_set_on_ice_candidate(
418 self.as_ref().to_glib_none().0,
419 func,
420 Box_::into_raw(super_callback0) as *mut _,
421 destroy_call3,
422 );
423 }
424 }
425
426 #[doc(alias = "gst_webrtc_ice_set_remote_credentials")]
437 fn set_remote_credentials(
438 &self,
439 stream: &impl IsA<WebRTCICEStream>,
440 ufrag: &str,
441 pwd: &str,
442 ) -> bool {
443 unsafe {
444 from_glib(ffi::gst_webrtc_ice_set_remote_credentials(
445 self.as_ref().to_glib_none().0,
446 stream.as_ref().to_glib_none().0,
447 ufrag.to_glib_none().0,
448 pwd.to_glib_none().0,
449 ))
450 }
451 }
452
453 #[doc(alias = "gst_webrtc_ice_set_stun_server")]
456 fn set_stun_server(&self, uri: Option<&str>) {
457 unsafe {
458 ffi::gst_webrtc_ice_set_stun_server(
459 self.as_ref().to_glib_none().0,
460 uri.to_glib_none().0,
461 );
462 }
463 }
464
465 #[doc(alias = "gst_webrtc_ice_set_tos")]
470 fn set_tos(&self, stream: &impl IsA<WebRTCICEStream>, tos: u32) {
471 unsafe {
472 ffi::gst_webrtc_ice_set_tos(
473 self.as_ref().to_glib_none().0,
474 stream.as_ref().to_glib_none().0,
475 tos,
476 );
477 }
478 }
479
480 #[doc(alias = "gst_webrtc_ice_set_turn_server")]
483 fn set_turn_server(&self, uri: Option<&str>) {
484 unsafe {
485 ffi::gst_webrtc_ice_set_turn_server(
486 self.as_ref().to_glib_none().0,
487 uri.to_glib_none().0,
488 );
489 }
490 }
491
492 #[cfg(feature = "v1_20")]
495 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
496 #[doc(alias = "max-rtp-port")]
497 fn max_rtp_port(&self) -> u32 {
498 ObjectExt::property(self.as_ref(), "max-rtp-port")
499 }
500
501 #[cfg(feature = "v1_20")]
504 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
505 #[doc(alias = "max-rtp-port")]
506 fn set_max_rtp_port(&self, max_rtp_port: u32) {
507 ObjectExt::set_property(self.as_ref(), "max-rtp-port", max_rtp_port)
508 }
509
510 #[cfg(feature = "v1_20")]
513 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
514 #[doc(alias = "min-rtp-port")]
515 fn min_rtp_port(&self) -> u32 {
516 ObjectExt::property(self.as_ref(), "min-rtp-port")
517 }
518
519 #[cfg(feature = "v1_20")]
522 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
523 #[doc(alias = "min-rtp-port")]
524 fn set_min_rtp_port(&self, min_rtp_port: u32) {
525 ObjectExt::set_property(self.as_ref(), "min-rtp-port", min_rtp_port)
526 }
527
528 #[doc(alias = "add-local-ip-address")]
538 fn connect_add_local_ip_address<F: Fn(&Self, &str) -> bool + Send + Sync + 'static>(
539 &self,
540 f: F,
541 ) -> SignalHandlerId {
542 unsafe extern "C" fn add_local_ip_address_trampoline<
543 P: IsA<WebRTCICE>,
544 F: Fn(&P, &str) -> bool + Send + Sync + 'static,
545 >(
546 this: *mut ffi::GstWebRTCICE,
547 address: *mut std::ffi::c_char,
548 f: glib::ffi::gpointer,
549 ) -> glib::ffi::gboolean {
550 unsafe {
551 let f: &F = &*(f as *const F);
552 f(
553 WebRTCICE::from_glib_borrow(this).unsafe_cast_ref(),
554 &glib::GString::from_glib_borrow(address),
555 )
556 .into_glib()
557 }
558 }
559 unsafe {
560 let f: Box_<F> = Box_::new(f);
561 connect_raw(
562 self.as_ptr() as *mut _,
563 c"add-local-ip-address".as_ptr(),
564 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
565 add_local_ip_address_trampoline::<Self, F> as *const (),
566 )),
567 Box_::into_raw(f),
568 )
569 }
570 }
571
572 fn emit_add_local_ip_address(&self, address: &str) -> bool {
573 self.emit_by_name("add-local-ip-address", &[&address])
574 }
575
576 #[cfg(feature = "v1_20")]
577 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
578 #[doc(alias = "max-rtp-port")]
579 fn connect_max_rtp_port_notify<F: Fn(&Self) + Send + Sync + 'static>(
580 &self,
581 f: F,
582 ) -> SignalHandlerId {
583 unsafe extern "C" fn notify_max_rtp_port_trampoline<
584 P: IsA<WebRTCICE>,
585 F: Fn(&P) + Send + Sync + 'static,
586 >(
587 this: *mut ffi::GstWebRTCICE,
588 _param_spec: glib::ffi::gpointer,
589 f: glib::ffi::gpointer,
590 ) {
591 unsafe {
592 let f: &F = &*(f as *const F);
593 f(WebRTCICE::from_glib_borrow(this).unsafe_cast_ref())
594 }
595 }
596 unsafe {
597 let f: Box_<F> = Box_::new(f);
598 connect_raw(
599 self.as_ptr() as *mut _,
600 c"notify::max-rtp-port".as_ptr(),
601 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
602 notify_max_rtp_port_trampoline::<Self, F> as *const (),
603 )),
604 Box_::into_raw(f),
605 )
606 }
607 }
608
609 #[cfg(feature = "v1_20")]
610 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
611 #[doc(alias = "min-rtp-port")]
612 fn connect_min_rtp_port_notify<F: Fn(&Self) + Send + Sync + 'static>(
613 &self,
614 f: F,
615 ) -> SignalHandlerId {
616 unsafe extern "C" fn notify_min_rtp_port_trampoline<
617 P: IsA<WebRTCICE>,
618 F: Fn(&P) + Send + Sync + 'static,
619 >(
620 this: *mut ffi::GstWebRTCICE,
621 _param_spec: glib::ffi::gpointer,
622 f: glib::ffi::gpointer,
623 ) {
624 unsafe {
625 let f: &F = &*(f as *const F);
626 f(WebRTCICE::from_glib_borrow(this).unsafe_cast_ref())
627 }
628 }
629 unsafe {
630 let f: Box_<F> = Box_::new(f);
631 connect_raw(
632 self.as_ptr() as *mut _,
633 c"notify::min-rtp-port".as_ptr(),
634 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
635 notify_min_rtp_port_trampoline::<Self, F> as *const (),
636 )),
637 Box_::into_raw(f),
638 )
639 }
640 }
641}
642
643impl<O: IsA<WebRTCICE>> WebRTCICEExt for O {}