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    /// Make a path string from `url`.
12    /// ## `url`
13    /// a [`gst_rtsp::RTSPUrl`][crate::gst_rtsp::RTSPUrl]
14    ///
15    /// # Returns
16    ///
17    /// a path string for `url`, `g_free()` after usage.
18    fn make_path(&self, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString> {
19        self.parent_make_path(url)
20    }
21}
22
23pub trait RTSPMountPointsImplExt: RTSPMountPointsImpl {
24    fn parent_make_path(&self, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString> {
25        unsafe {
26            let data = Self::type_data();
27            let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMountPointsClass;
28            let f = (*parent_class)
29                .make_path
30                .expect("No `make_path` virtual method implementation in parent class");
31            from_glib_full(f(
32                self.obj()
33                    .unsafe_cast_ref::<RTSPMountPoints>()
34                    .to_glib_none()
35                    .0,
36                url.to_glib_none().0,
37            ))
38        }
39    }
40}
41
42impl<T: RTSPMountPointsImpl> RTSPMountPointsImplExt for T {}
43
44unsafe impl<T: RTSPMountPointsImpl> IsSubclassable<T> for RTSPMountPoints {
45    fn class_init(klass: &mut glib::Class<Self>) {
46        Self::parent_class_init::<T>(klass);
47        let klass = klass.as_mut();
48        klass.make_path = Some(mount_points_make_path::<T>);
49    }
50}
51
52unsafe extern "C" fn mount_points_make_path<T: RTSPMountPointsImpl>(
53    ptr: *mut ffi::GstRTSPMountPoints,
54    url: *const GstRTSPUrl,
55) -> *mut std::os::raw::c_char {
56    let instance = &*(ptr as *mut T::Instance);
57    let imp = instance.imp();
58
59    imp.make_path(&from_glib_borrow(url)).into_glib_ptr()
60}