gstreamer_rtsp_server/subclass/
rtsp_onvif_media_factory.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::{prelude::*, subclass::prelude::*, translate::*};
4
5use super::prelude::*;
6use crate::{ffi, RTSPOnvifMediaFactory};
7
8pub trait RTSPOnvifMediaFactoryImpl:
9    RTSPMediaFactoryImplExt + RTSPMediaFactoryImpl + Send + Sync
10{
11    /// Returns [`true`] if an ONVIF backchannel is supported by the media factory.
12    ///
13    /// # Returns
14    ///
15    /// [`true`] if an ONVIF backchannel is supported by the media factory.
16    fn has_backchannel_support(&self) -> bool {
17        self.parent_has_backchannel_support()
18    }
19}
20
21mod sealed {
22    pub trait Sealed {}
23    impl<T: super::RTSPOnvifMediaFactoryImplExt> Sealed for T {}
24}
25
26pub trait RTSPOnvifMediaFactoryImplExt: sealed::Sealed + ObjectSubclass {
27    fn parent_has_backchannel_support(&self) -> bool {
28        unsafe {
29            let data = Self::type_data();
30            let parent_class =
31                data.as_ref().parent_class() as *mut ffi::GstRTSPOnvifMediaFactoryClass;
32            (*parent_class)
33                .has_backchannel_support
34                .map(|f| {
35                    from_glib(f(self
36                        .obj()
37                        .unsafe_cast_ref::<RTSPOnvifMediaFactory>()
38                        .to_glib_none()
39                        .0))
40                })
41                .unwrap_or(false)
42        }
43    }
44}
45
46impl<T: RTSPOnvifMediaFactoryImpl> RTSPOnvifMediaFactoryImplExt for T {}
47
48unsafe impl<T: RTSPOnvifMediaFactoryImpl> IsSubclassable<T> for RTSPOnvifMediaFactory {
49    fn class_init(klass: &mut glib::Class<Self>) {
50        Self::parent_class_init::<T>(klass);
51        let klass = klass.as_mut();
52        klass.has_backchannel_support = Some(factory_has_backchannel_support::<T>);
53    }
54}
55
56unsafe extern "C" fn factory_has_backchannel_support<T: RTSPOnvifMediaFactoryImpl>(
57    ptr: *mut ffi::GstRTSPOnvifMediaFactory,
58) -> glib::ffi::gboolean {
59    let instance = &*(ptr as *mut T::Instance);
60    let imp = instance.imp();
61
62    imp.has_backchannel_support().into_glib()
63}