gstreamer_rtsp_server/subclass/
rtsp_mount_points.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::*};
4use gst_rtsp::ffi::GstRTSPUrl;
5
6use crate::{ffi, RTSPMountPoints};
7
8pub trait RTSPMountPointsImpl:
9    ObjectImpl + ObjectSubclass<Type: IsA<RTSPMountPoints>> + Send + Sync
10{
11    fn make_path(&self, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString> {
12        self.parent_make_path(url)
13    }
14}
15
16pub trait RTSPMountPointsImplExt: RTSPMountPointsImpl {
17    fn parent_make_path(&self, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString> {
18        unsafe {
19            let data = Self::type_data();
20            let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMountPointsClass;
21            let f = (*parent_class)
22                .make_path
23                .expect("No `make_path` virtual method implementation in parent class");
24            from_glib_full(f(
25                self.obj()
26                    .unsafe_cast_ref::<RTSPMountPoints>()
27                    .to_glib_none()
28                    .0,
29                url.to_glib_none().0,
30            ))
31        }
32    }
33}
34
35impl<T: RTSPMountPointsImpl> RTSPMountPointsImplExt for T {}
36
37unsafe impl<T: RTSPMountPointsImpl> IsSubclassable<T> for RTSPMountPoints {
38    fn class_init(klass: &mut glib::Class<Self>) {
39        Self::parent_class_init::<T>(klass);
40        let klass = klass.as_mut();
41        klass.make_path = Some(mount_points_make_path::<T>);
42    }
43}
44
45unsafe extern "C" fn mount_points_make_path<T: RTSPMountPointsImpl>(
46    ptr: *mut ffi::GstRTSPMountPoints,
47    url: *const GstRTSPUrl,
48) -> *mut std::os::raw::c_char {
49    let instance = &*(ptr as *mut T::Instance);
50    let imp = instance.imp();
51
52    imp.make_path(&from_glib_borrow(url)).into_glib_ptr()
53}