1use crate::{
7 ffi, RTSPAuth, RTSPClient, RTSPFilterResult, RTSPMountPoints, RTSPSessionPool, RTSPThreadPool,
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 = "GstRTSPServer")]
61 pub struct RTSPServer(Object<ffi::GstRTSPServer, ffi::GstRTSPServerClass>);
62
63 match fn {
64 type_ => || ffi::gst_rtsp_server_get_type(),
65 }
66}
67
68impl RTSPServer {
69 pub const NONE: Option<&'static RTSPServer> = None;
70
71 #[doc(alias = "gst_rtsp_server_new")]
77 pub fn new() -> RTSPServer {
78 assert_initialized_main_thread!();
79 unsafe { from_glib_full(ffi::gst_rtsp_server_new()) }
80 }
81
82 #[doc(alias = "gst_rtsp_server_io_func")]
95 pub fn io_func(
96 socket: &impl IsA<gio::Socket>,
97 condition: glib::IOCondition,
98 server: &impl IsA<RTSPServer>,
99 ) -> Result<(), glib::error::BoolError> {
100 skip_assert_initialized!();
101 unsafe {
102 glib::result_from_gboolean!(
103 ffi::gst_rtsp_server_io_func(
104 socket.as_ref().to_glib_none().0,
105 condition.into_glib(),
106 server.as_ref().to_glib_none().0
107 ),
108 "Failed to connect the source"
109 )
110 }
111 }
112}
113
114impl Default for RTSPServer {
115 fn default() -> Self {
116 Self::new()
117 }
118}
119
120unsafe impl Send for RTSPServer {}
121unsafe impl Sync for RTSPServer {}
122
123mod sealed {
124 pub trait Sealed {}
125 impl<T: super::IsA<super::RTSPServer>> Sealed for T {}
126}
127
128pub trait RTSPServerExt: IsA<RTSPServer> + sealed::Sealed + 'static {
134 #[doc(alias = "gst_rtsp_server_client_filter")]
157 fn client_filter(
158 &self,
159 func: Option<&mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult)>,
160 ) -> Vec<RTSPClient> {
161 let mut func_data: Option<&mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult)> =
162 func;
163 unsafe extern "C" fn func_func(
164 server: *mut ffi::GstRTSPServer,
165 client: *mut ffi::GstRTSPClient,
166 user_data: glib::ffi::gpointer,
167 ) -> ffi::GstRTSPFilterResult {
168 let server = from_glib_borrow(server);
169 let client = from_glib_borrow(client);
170 let callback = user_data
171 as *mut Option<&mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult)>;
172 if let Some(ref mut callback) = *callback {
173 callback(&server, &client)
174 } else {
175 panic!("cannot get closure...")
176 }
177 .into_glib()
178 }
179 let func = if func_data.is_some() {
180 Some(func_func as _)
181 } else {
182 None
183 };
184 let super_callback0: &mut Option<
185 &mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult),
186 > = &mut func_data;
187 unsafe {
188 FromGlibPtrContainer::from_glib_full(ffi::gst_rtsp_server_client_filter(
189 self.as_ref().to_glib_none().0,
190 func,
191 super_callback0 as *mut _ as *mut _,
192 ))
193 }
194 }
195
196 #[doc(alias = "gst_rtsp_server_create_socket")]
206 fn create_socket(
207 &self,
208 cancellable: Option<&impl IsA<gio::Cancellable>>,
209 ) -> Result<gio::Socket, glib::Error> {
210 unsafe {
211 let mut error = std::ptr::null_mut();
212 let ret = ffi::gst_rtsp_server_create_socket(
213 self.as_ref().to_glib_none().0,
214 cancellable.map(|p| p.as_ref()).to_glib_none().0,
215 &mut error,
216 );
217 if error.is_null() {
218 Ok(from_glib_full(ret))
219 } else {
220 Err(from_glib_full(error))
221 }
222 }
223 }
224
225 #[doc(alias = "gst_rtsp_server_create_source")]
242 fn create_source(
243 &self,
244 cancellable: Option<&impl IsA<gio::Cancellable>>,
245 ) -> Result<glib::Source, glib::Error> {
246 unsafe {
247 let mut error = std::ptr::null_mut();
248 let ret = ffi::gst_rtsp_server_create_source(
249 self.as_ref().to_glib_none().0,
250 cancellable.map(|p| p.as_ref()).to_glib_none().0,
251 &mut error,
252 );
253 if error.is_null() {
254 Ok(from_glib_full(ret))
255 } else {
256 Err(from_glib_full(error))
257 }
258 }
259 }
260
261 #[doc(alias = "gst_rtsp_server_get_address")]
267 #[doc(alias = "get_address")]
268 fn address(&self) -> Option<glib::GString> {
269 unsafe {
270 from_glib_full(ffi::gst_rtsp_server_get_address(
271 self.as_ref().to_glib_none().0,
272 ))
273 }
274 }
275
276 #[doc(alias = "gst_rtsp_server_get_auth")]
283 #[doc(alias = "get_auth")]
284 fn auth(&self) -> Option<RTSPAuth> {
285 unsafe {
286 from_glib_full(ffi::gst_rtsp_server_get_auth(
287 self.as_ref().to_glib_none().0,
288 ))
289 }
290 }
291
292 #[doc(alias = "gst_rtsp_server_get_backlog")]
298 #[doc(alias = "get_backlog")]
299 fn backlog(&self) -> i32 {
300 unsafe { ffi::gst_rtsp_server_get_backlog(self.as_ref().to_glib_none().0) }
301 }
302
303 #[doc(alias = "gst_rtsp_server_get_bound_port")]
309 #[doc(alias = "get_bound_port")]
310 #[doc(alias = "bound-port")]
311 fn bound_port(&self) -> i32 {
312 unsafe { ffi::gst_rtsp_server_get_bound_port(self.as_ref().to_glib_none().0) }
313 }
314
315 #[cfg(feature = "v1_18")]
321 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
322 #[doc(alias = "gst_rtsp_server_get_content_length_limit")]
323 #[doc(alias = "get_content_length_limit")]
324 #[doc(alias = "content-length-limit")]
325 fn content_length_limit(&self) -> u32 {
326 unsafe { ffi::gst_rtsp_server_get_content_length_limit(self.as_ref().to_glib_none().0) }
327 }
328
329 #[doc(alias = "gst_rtsp_server_get_mount_points")]
336 #[doc(alias = "get_mount_points")]
337 #[doc(alias = "mount-points")]
338 fn mount_points(&self) -> Option<RTSPMountPoints> {
339 unsafe {
340 from_glib_full(ffi::gst_rtsp_server_get_mount_points(
341 self.as_ref().to_glib_none().0,
342 ))
343 }
344 }
345
346 #[doc(alias = "gst_rtsp_server_get_service")]
352 #[doc(alias = "get_service")]
353 fn service(&self) -> glib::GString {
354 unsafe {
355 from_glib_full(ffi::gst_rtsp_server_get_service(
356 self.as_ref().to_glib_none().0,
357 ))
358 }
359 }
360
361 #[doc(alias = "gst_rtsp_server_get_session_pool")]
368 #[doc(alias = "get_session_pool")]
369 #[doc(alias = "session-pool")]
370 fn session_pool(&self) -> Option<RTSPSessionPool> {
371 unsafe {
372 from_glib_full(ffi::gst_rtsp_server_get_session_pool(
373 self.as_ref().to_glib_none().0,
374 ))
375 }
376 }
377
378 #[doc(alias = "gst_rtsp_server_get_thread_pool")]
385 #[doc(alias = "get_thread_pool")]
386 fn thread_pool(&self) -> Option<RTSPThreadPool> {
387 unsafe {
388 from_glib_full(ffi::gst_rtsp_server_get_thread_pool(
389 self.as_ref().to_glib_none().0,
390 ))
391 }
392 }
393
394 #[doc(alias = "gst_rtsp_server_set_address")]
400 #[doc(alias = "address")]
401 fn set_address(&self, address: &str) {
402 unsafe {
403 ffi::gst_rtsp_server_set_address(
404 self.as_ref().to_glib_none().0,
405 address.to_glib_none().0,
406 );
407 }
408 }
409
410 #[doc(alias = "gst_rtsp_server_set_auth")]
414 fn set_auth(&self, auth: Option<&impl IsA<RTSPAuth>>) {
415 unsafe {
416 ffi::gst_rtsp_server_set_auth(
417 self.as_ref().to_glib_none().0,
418 auth.map(|p| p.as_ref()).to_glib_none().0,
419 );
420 }
421 }
422
423 #[doc(alias = "gst_rtsp_server_set_backlog")]
430 #[doc(alias = "backlog")]
431 fn set_backlog(&self, backlog: i32) {
432 unsafe {
433 ffi::gst_rtsp_server_set_backlog(self.as_ref().to_glib_none().0, backlog);
434 }
435 }
436
437 #[cfg(feature = "v1_18")]
440 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
441 #[doc(alias = "gst_rtsp_server_set_content_length_limit")]
442 #[doc(alias = "content-length-limit")]
443 fn set_content_length_limit(&self, limit: u32) {
444 unsafe {
445 ffi::gst_rtsp_server_set_content_length_limit(self.as_ref().to_glib_none().0, limit);
446 }
447 }
448
449 #[doc(alias = "gst_rtsp_server_set_mount_points")]
453 #[doc(alias = "mount-points")]
454 fn set_mount_points(&self, mounts: Option<&impl IsA<RTSPMountPoints>>) {
455 unsafe {
456 ffi::gst_rtsp_server_set_mount_points(
457 self.as_ref().to_glib_none().0,
458 mounts.map(|p| p.as_ref()).to_glib_none().0,
459 );
460 }
461 }
462
463 #[doc(alias = "gst_rtsp_server_set_service")]
475 #[doc(alias = "service")]
476 fn set_service(&self, service: &str) {
477 unsafe {
478 ffi::gst_rtsp_server_set_service(
479 self.as_ref().to_glib_none().0,
480 service.to_glib_none().0,
481 );
482 }
483 }
484
485 #[doc(alias = "gst_rtsp_server_set_session_pool")]
489 #[doc(alias = "session-pool")]
490 fn set_session_pool(&self, pool: Option<&impl IsA<RTSPSessionPool>>) {
491 unsafe {
492 ffi::gst_rtsp_server_set_session_pool(
493 self.as_ref().to_glib_none().0,
494 pool.map(|p| p.as_ref()).to_glib_none().0,
495 );
496 }
497 }
498
499 #[doc(alias = "gst_rtsp_server_set_thread_pool")]
503 fn set_thread_pool(&self, pool: Option<&impl IsA<RTSPThreadPool>>) {
504 unsafe {
505 ffi::gst_rtsp_server_set_thread_pool(
506 self.as_ref().to_glib_none().0,
507 pool.map(|p| p.as_ref()).to_glib_none().0,
508 );
509 }
510 }
511
512 #[doc(alias = "gst_rtsp_server_transfer_connection")]
529 fn transfer_connection(
530 &self,
531 socket: impl IsA<gio::Socket>,
532 ip: &str,
533 port: i32,
534 initial_buffer: Option<&str>,
535 ) -> Result<(), glib::error::BoolError> {
536 unsafe {
537 glib::result_from_gboolean!(
538 ffi::gst_rtsp_server_transfer_connection(
539 self.as_ref().to_glib_none().0,
540 socket.upcast().into_glib_ptr(),
541 ip.to_glib_none().0,
542 port,
543 initial_buffer.to_glib_none().0
544 ),
545 "Failed to transfer to the connection"
546 )
547 }
548 }
549
550 #[cfg(not(feature = "v1_18"))]
551 #[cfg_attr(docsrs, doc(cfg(not(feature = "v1_18"))))]
552 #[doc(alias = "content-length-limit")]
553 fn content_length_limit(&self) -> u32 {
554 ObjectExt::property(self.as_ref(), "content-length-limit")
555 }
556
557 #[cfg(not(feature = "v1_18"))]
558 #[cfg_attr(docsrs, doc(cfg(not(feature = "v1_18"))))]
559 #[doc(alias = "content-length-limit")]
560 fn set_content_length_limit(&self, content_length_limit: u32) {
561 ObjectExt::set_property(self.as_ref(), "content-length-limit", content_length_limit)
562 }
563
564 #[doc(alias = "client-connected")]
565 fn connect_client_connected<F: Fn(&Self, &RTSPClient) + Send + Sync + 'static>(
566 &self,
567 f: F,
568 ) -> SignalHandlerId {
569 unsafe extern "C" fn client_connected_trampoline<
570 P: IsA<RTSPServer>,
571 F: Fn(&P, &RTSPClient) + Send + Sync + 'static,
572 >(
573 this: *mut ffi::GstRTSPServer,
574 object: *mut ffi::GstRTSPClient,
575 f: glib::ffi::gpointer,
576 ) {
577 let f: &F = &*(f as *const F);
578 f(
579 RTSPServer::from_glib_borrow(this).unsafe_cast_ref(),
580 &from_glib_borrow(object),
581 )
582 }
583 unsafe {
584 let f: Box_<F> = Box_::new(f);
585 connect_raw(
586 self.as_ptr() as *mut _,
587 b"client-connected\0".as_ptr() as *const _,
588 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
589 client_connected_trampoline::<Self, F> as *const (),
590 )),
591 Box_::into_raw(f),
592 )
593 }
594 }
595
596 #[doc(alias = "address")]
597 fn connect_address_notify<F: Fn(&Self) + Send + Sync + 'static>(
598 &self,
599 f: F,
600 ) -> SignalHandlerId {
601 unsafe extern "C" fn notify_address_trampoline<
602 P: IsA<RTSPServer>,
603 F: Fn(&P) + Send + Sync + 'static,
604 >(
605 this: *mut ffi::GstRTSPServer,
606 _param_spec: glib::ffi::gpointer,
607 f: glib::ffi::gpointer,
608 ) {
609 let f: &F = &*(f as *const F);
610 f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
611 }
612 unsafe {
613 let f: Box_<F> = Box_::new(f);
614 connect_raw(
615 self.as_ptr() as *mut _,
616 b"notify::address\0".as_ptr() as *const _,
617 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
618 notify_address_trampoline::<Self, F> as *const (),
619 )),
620 Box_::into_raw(f),
621 )
622 }
623 }
624
625 #[doc(alias = "backlog")]
626 fn connect_backlog_notify<F: Fn(&Self) + Send + Sync + 'static>(
627 &self,
628 f: F,
629 ) -> SignalHandlerId {
630 unsafe extern "C" fn notify_backlog_trampoline<
631 P: IsA<RTSPServer>,
632 F: Fn(&P) + Send + Sync + 'static,
633 >(
634 this: *mut ffi::GstRTSPServer,
635 _param_spec: glib::ffi::gpointer,
636 f: glib::ffi::gpointer,
637 ) {
638 let f: &F = &*(f as *const F);
639 f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
640 }
641 unsafe {
642 let f: Box_<F> = Box_::new(f);
643 connect_raw(
644 self.as_ptr() as *mut _,
645 b"notify::backlog\0".as_ptr() as *const _,
646 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
647 notify_backlog_trampoline::<Self, F> as *const (),
648 )),
649 Box_::into_raw(f),
650 )
651 }
652 }
653
654 #[doc(alias = "bound-port")]
655 fn connect_bound_port_notify<F: Fn(&Self) + Send + Sync + 'static>(
656 &self,
657 f: F,
658 ) -> SignalHandlerId {
659 unsafe extern "C" fn notify_bound_port_trampoline<
660 P: IsA<RTSPServer>,
661 F: Fn(&P) + Send + Sync + 'static,
662 >(
663 this: *mut ffi::GstRTSPServer,
664 _param_spec: glib::ffi::gpointer,
665 f: glib::ffi::gpointer,
666 ) {
667 let f: &F = &*(f as *const F);
668 f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
669 }
670 unsafe {
671 let f: Box_<F> = Box_::new(f);
672 connect_raw(
673 self.as_ptr() as *mut _,
674 b"notify::bound-port\0".as_ptr() as *const _,
675 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
676 notify_bound_port_trampoline::<Self, F> as *const (),
677 )),
678 Box_::into_raw(f),
679 )
680 }
681 }
682
683 #[doc(alias = "content-length-limit")]
684 fn connect_content_length_limit_notify<F: Fn(&Self) + Send + Sync + 'static>(
685 &self,
686 f: F,
687 ) -> SignalHandlerId {
688 unsafe extern "C" fn notify_content_length_limit_trampoline<
689 P: IsA<RTSPServer>,
690 F: Fn(&P) + Send + Sync + 'static,
691 >(
692 this: *mut ffi::GstRTSPServer,
693 _param_spec: glib::ffi::gpointer,
694 f: glib::ffi::gpointer,
695 ) {
696 let f: &F = &*(f as *const F);
697 f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
698 }
699 unsafe {
700 let f: Box_<F> = Box_::new(f);
701 connect_raw(
702 self.as_ptr() as *mut _,
703 b"notify::content-length-limit\0".as_ptr() as *const _,
704 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
705 notify_content_length_limit_trampoline::<Self, F> as *const (),
706 )),
707 Box_::into_raw(f),
708 )
709 }
710 }
711
712 #[doc(alias = "mount-points")]
713 fn connect_mount_points_notify<F: Fn(&Self) + Send + Sync + 'static>(
714 &self,
715 f: F,
716 ) -> SignalHandlerId {
717 unsafe extern "C" fn notify_mount_points_trampoline<
718 P: IsA<RTSPServer>,
719 F: Fn(&P) + Send + Sync + 'static,
720 >(
721 this: *mut ffi::GstRTSPServer,
722 _param_spec: glib::ffi::gpointer,
723 f: glib::ffi::gpointer,
724 ) {
725 let f: &F = &*(f as *const F);
726 f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
727 }
728 unsafe {
729 let f: Box_<F> = Box_::new(f);
730 connect_raw(
731 self.as_ptr() as *mut _,
732 b"notify::mount-points\0".as_ptr() as *const _,
733 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
734 notify_mount_points_trampoline::<Self, F> as *const (),
735 )),
736 Box_::into_raw(f),
737 )
738 }
739 }
740
741 #[doc(alias = "service")]
742 fn connect_service_notify<F: Fn(&Self) + Send + Sync + 'static>(
743 &self,
744 f: F,
745 ) -> SignalHandlerId {
746 unsafe extern "C" fn notify_service_trampoline<
747 P: IsA<RTSPServer>,
748 F: Fn(&P) + Send + Sync + 'static,
749 >(
750 this: *mut ffi::GstRTSPServer,
751 _param_spec: glib::ffi::gpointer,
752 f: glib::ffi::gpointer,
753 ) {
754 let f: &F = &*(f as *const F);
755 f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
756 }
757 unsafe {
758 let f: Box_<F> = Box_::new(f);
759 connect_raw(
760 self.as_ptr() as *mut _,
761 b"notify::service\0".as_ptr() as *const _,
762 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
763 notify_service_trampoline::<Self, F> as *const (),
764 )),
765 Box_::into_raw(f),
766 )
767 }
768 }
769
770 #[doc(alias = "session-pool")]
771 fn connect_session_pool_notify<F: Fn(&Self) + Send + Sync + 'static>(
772 &self,
773 f: F,
774 ) -> SignalHandlerId {
775 unsafe extern "C" fn notify_session_pool_trampoline<
776 P: IsA<RTSPServer>,
777 F: Fn(&P) + Send + Sync + 'static,
778 >(
779 this: *mut ffi::GstRTSPServer,
780 _param_spec: glib::ffi::gpointer,
781 f: glib::ffi::gpointer,
782 ) {
783 let f: &F = &*(f as *const F);
784 f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
785 }
786 unsafe {
787 let f: Box_<F> = Box_::new(f);
788 connect_raw(
789 self.as_ptr() as *mut _,
790 b"notify::session-pool\0".as_ptr() as *const _,
791 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
792 notify_session_pool_trampoline::<Self, F> as *const (),
793 )),
794 Box_::into_raw(f),
795 )
796 }
797 }
798}
799
800impl<O: IsA<RTSPServer>> RTSPServerExt for O {}