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    RTSPMediaFactoryImpl + ObjectSubclass<Type: IsA<RTSPOnvifMediaFactory>> + 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
21pub trait RTSPOnvifMediaFactoryImplExt: RTSPOnvifMediaFactoryImpl {
22    fn parent_has_backchannel_support(&self) -> bool {
23        unsafe {
24            let data = Self::type_data();
25            let parent_class =
26                data.as_ref().parent_class() as *mut ffi::GstRTSPOnvifMediaFactoryClass;
27            (*parent_class)
28                .has_backchannel_support
29                .map(|f| {
30                    from_glib(f(self
31                        .obj()
32                        .unsafe_cast_ref::<RTSPOnvifMediaFactory>()
33                        .to_glib_none()
34                        .0))
35                })
36                .unwrap_or(false)
37        }
38    }
39}
40
41impl<T: RTSPOnvifMediaFactoryImpl> RTSPOnvifMediaFactoryImplExt for T {}
42
43unsafe impl<T: RTSPOnvifMediaFactoryImpl> IsSubclassable<T> for RTSPOnvifMediaFactory {
44    fn class_init(klass: &mut glib::Class<Self>) {
45        Self::parent_class_init::<T>(klass);
46        let klass = klass.as_mut();
47        klass.has_backchannel_support = Some(factory_has_backchannel_support::<T>);
48    }
49}
50
51unsafe extern "C" fn factory_has_backchannel_support<T: RTSPOnvifMediaFactoryImpl>(
52    ptr: *mut ffi::GstRTSPOnvifMediaFactory,
53) -> glib::ffi::gboolean {
54    let instance = &*(ptr as *mut T::Instance);
55    let imp = instance.imp();
56
57    imp.has_backchannel_support().into_glib()
58}