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
123pub trait RTSPServerExt: IsA<RTSPServer> + 'static {
129    #[doc(alias = "gst_rtsp_server_client_filter")]
152    fn client_filter(
153        &self,
154        func: Option<&mut dyn FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult>,
155    ) -> Vec<RTSPClient> {
156        let mut func_data: Option<&mut dyn FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult> =
157            func;
158        unsafe extern "C" fn func_func(
159            server: *mut ffi::GstRTSPServer,
160            client: *mut ffi::GstRTSPClient,
161            user_data: glib::ffi::gpointer,
162        ) -> ffi::GstRTSPFilterResult {
163            let server = from_glib_borrow(server);
164            let client = from_glib_borrow(client);
165            let callback = user_data
166                as *mut Option<&mut dyn FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult>;
167            if let Some(ref mut callback) = *callback {
168                callback(&server, &client)
169            } else {
170                panic!("cannot get closure...")
171            }
172            .into_glib()
173        }
174        let func = if func_data.is_some() {
175            Some(func_func as _)
176        } else {
177            None
178        };
179        let super_callback0: &mut Option<
180            &mut dyn FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult,
181        > = &mut func_data;
182        unsafe {
183            FromGlibPtrContainer::from_glib_full(ffi::gst_rtsp_server_client_filter(
184                self.as_ref().to_glib_none().0,
185                func,
186                super_callback0 as *mut _ as *mut _,
187            ))
188        }
189    }
190
191    #[doc(alias = "gst_rtsp_server_create_socket")]
201    fn create_socket(
202        &self,
203        cancellable: Option<&impl IsA<gio::Cancellable>>,
204    ) -> Result<gio::Socket, glib::Error> {
205        unsafe {
206            let mut error = std::ptr::null_mut();
207            let ret = ffi::gst_rtsp_server_create_socket(
208                self.as_ref().to_glib_none().0,
209                cancellable.map(|p| p.as_ref()).to_glib_none().0,
210                &mut error,
211            );
212            if error.is_null() {
213                Ok(from_glib_full(ret))
214            } else {
215                Err(from_glib_full(error))
216            }
217        }
218    }
219
220    #[doc(alias = "gst_rtsp_server_create_source")]
237    fn create_source(
238        &self,
239        cancellable: Option<&impl IsA<gio::Cancellable>>,
240    ) -> Result<glib::Source, glib::Error> {
241        unsafe {
242            let mut error = std::ptr::null_mut();
243            let ret = ffi::gst_rtsp_server_create_source(
244                self.as_ref().to_glib_none().0,
245                cancellable.map(|p| p.as_ref()).to_glib_none().0,
246                &mut error,
247            );
248            if error.is_null() {
249                Ok(from_glib_full(ret))
250            } else {
251                Err(from_glib_full(error))
252            }
253        }
254    }
255
256    #[doc(alias = "gst_rtsp_server_get_address")]
262    #[doc(alias = "get_address")]
263    fn address(&self) -> Option<glib::GString> {
264        unsafe {
265            from_glib_full(ffi::gst_rtsp_server_get_address(
266                self.as_ref().to_glib_none().0,
267            ))
268        }
269    }
270
271    #[doc(alias = "gst_rtsp_server_get_auth")]
278    #[doc(alias = "get_auth")]
279    fn auth(&self) -> Option<RTSPAuth> {
280        unsafe {
281            from_glib_full(ffi::gst_rtsp_server_get_auth(
282                self.as_ref().to_glib_none().0,
283            ))
284        }
285    }
286
287    #[doc(alias = "gst_rtsp_server_get_backlog")]
293    #[doc(alias = "get_backlog")]
294    fn backlog(&self) -> i32 {
295        unsafe { ffi::gst_rtsp_server_get_backlog(self.as_ref().to_glib_none().0) }
296    }
297
298    #[doc(alias = "gst_rtsp_server_get_bound_port")]
304    #[doc(alias = "get_bound_port")]
305    #[doc(alias = "bound-port")]
306    fn bound_port(&self) -> i32 {
307        unsafe { ffi::gst_rtsp_server_get_bound_port(self.as_ref().to_glib_none().0) }
308    }
309
310    #[cfg(feature = "v1_18")]
316    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
317    #[doc(alias = "gst_rtsp_server_get_content_length_limit")]
318    #[doc(alias = "get_content_length_limit")]
319    #[doc(alias = "content-length-limit")]
320    fn content_length_limit(&self) -> u32 {
321        unsafe { ffi::gst_rtsp_server_get_content_length_limit(self.as_ref().to_glib_none().0) }
322    }
323
324    #[doc(alias = "gst_rtsp_server_get_mount_points")]
331    #[doc(alias = "get_mount_points")]
332    #[doc(alias = "mount-points")]
333    fn mount_points(&self) -> Option<RTSPMountPoints> {
334        unsafe {
335            from_glib_full(ffi::gst_rtsp_server_get_mount_points(
336                self.as_ref().to_glib_none().0,
337            ))
338        }
339    }
340
341    #[doc(alias = "gst_rtsp_server_get_service")]
347    #[doc(alias = "get_service")]
348    fn service(&self) -> glib::GString {
349        unsafe {
350            from_glib_full(ffi::gst_rtsp_server_get_service(
351                self.as_ref().to_glib_none().0,
352            ))
353        }
354    }
355
356    #[doc(alias = "gst_rtsp_server_get_session_pool")]
363    #[doc(alias = "get_session_pool")]
364    #[doc(alias = "session-pool")]
365    fn session_pool(&self) -> Option<RTSPSessionPool> {
366        unsafe {
367            from_glib_full(ffi::gst_rtsp_server_get_session_pool(
368                self.as_ref().to_glib_none().0,
369            ))
370        }
371    }
372
373    #[doc(alias = "gst_rtsp_server_get_thread_pool")]
380    #[doc(alias = "get_thread_pool")]
381    fn thread_pool(&self) -> Option<RTSPThreadPool> {
382        unsafe {
383            from_glib_full(ffi::gst_rtsp_server_get_thread_pool(
384                self.as_ref().to_glib_none().0,
385            ))
386        }
387    }
388
389    #[doc(alias = "gst_rtsp_server_set_address")]
395    #[doc(alias = "address")]
396    fn set_address(&self, address: &str) {
397        unsafe {
398            ffi::gst_rtsp_server_set_address(
399                self.as_ref().to_glib_none().0,
400                address.to_glib_none().0,
401            );
402        }
403    }
404
405    #[doc(alias = "gst_rtsp_server_set_auth")]
409    fn set_auth(&self, auth: Option<&impl IsA<RTSPAuth>>) {
410        unsafe {
411            ffi::gst_rtsp_server_set_auth(
412                self.as_ref().to_glib_none().0,
413                auth.map(|p| p.as_ref()).to_glib_none().0,
414            );
415        }
416    }
417
418    #[doc(alias = "gst_rtsp_server_set_backlog")]
425    #[doc(alias = "backlog")]
426    fn set_backlog(&self, backlog: i32) {
427        unsafe {
428            ffi::gst_rtsp_server_set_backlog(self.as_ref().to_glib_none().0, backlog);
429        }
430    }
431
432    #[cfg(feature = "v1_18")]
435    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
436    #[doc(alias = "gst_rtsp_server_set_content_length_limit")]
437    #[doc(alias = "content-length-limit")]
438    fn set_content_length_limit(&self, limit: u32) {
439        unsafe {
440            ffi::gst_rtsp_server_set_content_length_limit(self.as_ref().to_glib_none().0, limit);
441        }
442    }
443
444    #[doc(alias = "gst_rtsp_server_set_mount_points")]
448    #[doc(alias = "mount-points")]
449    fn set_mount_points(&self, mounts: Option<&impl IsA<RTSPMountPoints>>) {
450        unsafe {
451            ffi::gst_rtsp_server_set_mount_points(
452                self.as_ref().to_glib_none().0,
453                mounts.map(|p| p.as_ref()).to_glib_none().0,
454            );
455        }
456    }
457
458    #[doc(alias = "gst_rtsp_server_set_service")]
470    #[doc(alias = "service")]
471    fn set_service(&self, service: &str) {
472        unsafe {
473            ffi::gst_rtsp_server_set_service(
474                self.as_ref().to_glib_none().0,
475                service.to_glib_none().0,
476            );
477        }
478    }
479
480    #[doc(alias = "gst_rtsp_server_set_session_pool")]
484    #[doc(alias = "session-pool")]
485    fn set_session_pool(&self, pool: Option<&impl IsA<RTSPSessionPool>>) {
486        unsafe {
487            ffi::gst_rtsp_server_set_session_pool(
488                self.as_ref().to_glib_none().0,
489                pool.map(|p| p.as_ref()).to_glib_none().0,
490            );
491        }
492    }
493
494    #[doc(alias = "gst_rtsp_server_set_thread_pool")]
498    fn set_thread_pool(&self, pool: Option<&impl IsA<RTSPThreadPool>>) {
499        unsafe {
500            ffi::gst_rtsp_server_set_thread_pool(
501                self.as_ref().to_glib_none().0,
502                pool.map(|p| p.as_ref()).to_glib_none().0,
503            );
504        }
505    }
506
507    #[doc(alias = "gst_rtsp_server_transfer_connection")]
524    fn transfer_connection(
525        &self,
526        socket: impl IsA<gio::Socket>,
527        ip: &str,
528        port: i32,
529        initial_buffer: Option<&str>,
530    ) -> Result<(), glib::error::BoolError> {
531        unsafe {
532            glib::result_from_gboolean!(
533                ffi::gst_rtsp_server_transfer_connection(
534                    self.as_ref().to_glib_none().0,
535                    socket.upcast().into_glib_ptr(),
536                    ip.to_glib_none().0,
537                    port,
538                    initial_buffer.to_glib_none().0
539                ),
540                "Failed to transfer to the connection"
541            )
542        }
543    }
544
545    #[cfg(not(feature = "v1_18"))]
546    #[cfg_attr(docsrs, doc(cfg(not(feature = "v1_18"))))]
547    #[doc(alias = "content-length-limit")]
548    fn content_length_limit(&self) -> u32 {
549        ObjectExt::property(self.as_ref(), "content-length-limit")
550    }
551
552    #[cfg(not(feature = "v1_18"))]
553    #[cfg_attr(docsrs, doc(cfg(not(feature = "v1_18"))))]
554    #[doc(alias = "content-length-limit")]
555    fn set_content_length_limit(&self, content_length_limit: u32) {
556        ObjectExt::set_property(self.as_ref(), "content-length-limit", content_length_limit)
557    }
558
559    #[doc(alias = "client-connected")]
560    fn connect_client_connected<F: Fn(&Self, &RTSPClient) + Send + Sync + 'static>(
561        &self,
562        f: F,
563    ) -> SignalHandlerId {
564        unsafe extern "C" fn client_connected_trampoline<
565            P: IsA<RTSPServer>,
566            F: Fn(&P, &RTSPClient) + Send + Sync + 'static,
567        >(
568            this: *mut ffi::GstRTSPServer,
569            object: *mut ffi::GstRTSPClient,
570            f: glib::ffi::gpointer,
571        ) {
572            let f: &F = &*(f as *const F);
573            f(
574                RTSPServer::from_glib_borrow(this).unsafe_cast_ref(),
575                &from_glib_borrow(object),
576            )
577        }
578        unsafe {
579            let f: Box_<F> = Box_::new(f);
580            connect_raw(
581                self.as_ptr() as *mut _,
582                c"client-connected".as_ptr() as *const _,
583                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
584                    client_connected_trampoline::<Self, F> as *const (),
585                )),
586                Box_::into_raw(f),
587            )
588        }
589    }
590
591    #[doc(alias = "address")]
592    fn connect_address_notify<F: Fn(&Self) + Send + Sync + 'static>(
593        &self,
594        f: F,
595    ) -> SignalHandlerId {
596        unsafe extern "C" fn notify_address_trampoline<
597            P: IsA<RTSPServer>,
598            F: Fn(&P) + Send + Sync + 'static,
599        >(
600            this: *mut ffi::GstRTSPServer,
601            _param_spec: glib::ffi::gpointer,
602            f: glib::ffi::gpointer,
603        ) {
604            let f: &F = &*(f as *const F);
605            f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
606        }
607        unsafe {
608            let f: Box_<F> = Box_::new(f);
609            connect_raw(
610                self.as_ptr() as *mut _,
611                c"notify::address".as_ptr() as *const _,
612                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
613                    notify_address_trampoline::<Self, F> as *const (),
614                )),
615                Box_::into_raw(f),
616            )
617        }
618    }
619
620    #[doc(alias = "backlog")]
621    fn connect_backlog_notify<F: Fn(&Self) + Send + Sync + 'static>(
622        &self,
623        f: F,
624    ) -> SignalHandlerId {
625        unsafe extern "C" fn notify_backlog_trampoline<
626            P: IsA<RTSPServer>,
627            F: Fn(&P) + Send + Sync + 'static,
628        >(
629            this: *mut ffi::GstRTSPServer,
630            _param_spec: glib::ffi::gpointer,
631            f: glib::ffi::gpointer,
632        ) {
633            let f: &F = &*(f as *const F);
634            f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
635        }
636        unsafe {
637            let f: Box_<F> = Box_::new(f);
638            connect_raw(
639                self.as_ptr() as *mut _,
640                c"notify::backlog".as_ptr() as *const _,
641                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
642                    notify_backlog_trampoline::<Self, F> as *const (),
643                )),
644                Box_::into_raw(f),
645            )
646        }
647    }
648
649    #[doc(alias = "bound-port")]
650    fn connect_bound_port_notify<F: Fn(&Self) + Send + Sync + 'static>(
651        &self,
652        f: F,
653    ) -> SignalHandlerId {
654        unsafe extern "C" fn notify_bound_port_trampoline<
655            P: IsA<RTSPServer>,
656            F: Fn(&P) + Send + Sync + 'static,
657        >(
658            this: *mut ffi::GstRTSPServer,
659            _param_spec: glib::ffi::gpointer,
660            f: glib::ffi::gpointer,
661        ) {
662            let f: &F = &*(f as *const F);
663            f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
664        }
665        unsafe {
666            let f: Box_<F> = Box_::new(f);
667            connect_raw(
668                self.as_ptr() as *mut _,
669                c"notify::bound-port".as_ptr() as *const _,
670                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
671                    notify_bound_port_trampoline::<Self, F> as *const (),
672                )),
673                Box_::into_raw(f),
674            )
675        }
676    }
677
678    #[doc(alias = "content-length-limit")]
679    fn connect_content_length_limit_notify<F: Fn(&Self) + Send + Sync + 'static>(
680        &self,
681        f: F,
682    ) -> SignalHandlerId {
683        unsafe extern "C" fn notify_content_length_limit_trampoline<
684            P: IsA<RTSPServer>,
685            F: Fn(&P) + Send + Sync + 'static,
686        >(
687            this: *mut ffi::GstRTSPServer,
688            _param_spec: glib::ffi::gpointer,
689            f: glib::ffi::gpointer,
690        ) {
691            let f: &F = &*(f as *const F);
692            f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
693        }
694        unsafe {
695            let f: Box_<F> = Box_::new(f);
696            connect_raw(
697                self.as_ptr() as *mut _,
698                c"notify::content-length-limit".as_ptr() as *const _,
699                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
700                    notify_content_length_limit_trampoline::<Self, F> as *const (),
701                )),
702                Box_::into_raw(f),
703            )
704        }
705    }
706
707    #[doc(alias = "mount-points")]
708    fn connect_mount_points_notify<F: Fn(&Self) + Send + Sync + 'static>(
709        &self,
710        f: F,
711    ) -> SignalHandlerId {
712        unsafe extern "C" fn notify_mount_points_trampoline<
713            P: IsA<RTSPServer>,
714            F: Fn(&P) + Send + Sync + 'static,
715        >(
716            this: *mut ffi::GstRTSPServer,
717            _param_spec: glib::ffi::gpointer,
718            f: glib::ffi::gpointer,
719        ) {
720            let f: &F = &*(f as *const F);
721            f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
722        }
723        unsafe {
724            let f: Box_<F> = Box_::new(f);
725            connect_raw(
726                self.as_ptr() as *mut _,
727                c"notify::mount-points".as_ptr() as *const _,
728                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
729                    notify_mount_points_trampoline::<Self, F> as *const (),
730                )),
731                Box_::into_raw(f),
732            )
733        }
734    }
735
736    #[doc(alias = "service")]
737    fn connect_service_notify<F: Fn(&Self) + Send + Sync + 'static>(
738        &self,
739        f: F,
740    ) -> SignalHandlerId {
741        unsafe extern "C" fn notify_service_trampoline<
742            P: IsA<RTSPServer>,
743            F: Fn(&P) + Send + Sync + 'static,
744        >(
745            this: *mut ffi::GstRTSPServer,
746            _param_spec: glib::ffi::gpointer,
747            f: glib::ffi::gpointer,
748        ) {
749            let f: &F = &*(f as *const F);
750            f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
751        }
752        unsafe {
753            let f: Box_<F> = Box_::new(f);
754            connect_raw(
755                self.as_ptr() as *mut _,
756                c"notify::service".as_ptr() as *const _,
757                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
758                    notify_service_trampoline::<Self, F> as *const (),
759                )),
760                Box_::into_raw(f),
761            )
762        }
763    }
764
765    #[doc(alias = "session-pool")]
766    fn connect_session_pool_notify<F: Fn(&Self) + Send + Sync + 'static>(
767        &self,
768        f: F,
769    ) -> SignalHandlerId {
770        unsafe extern "C" fn notify_session_pool_trampoline<
771            P: IsA<RTSPServer>,
772            F: Fn(&P) + Send + Sync + 'static,
773        >(
774            this: *mut ffi::GstRTSPServer,
775            _param_spec: glib::ffi::gpointer,
776            f: glib::ffi::gpointer,
777        ) {
778            let f: &F = &*(f as *const F);
779            f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
780        }
781        unsafe {
782            let f: Box_<F> = Box_::new(f);
783            connect_raw(
784                self.as_ptr() as *mut _,
785                c"notify::session-pool".as_ptr() as *const _,
786                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
787                    notify_session_pool_trampoline::<Self, F> as *const (),
788                )),
789                Box_::into_raw(f),
790            )
791        }
792    }
793}
794
795impl<O: IsA<RTSPServer>> RTSPServerExt for O {}