gstreamer_base/
base_transform.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::{mem, ptr};
4
5use glib::{prelude::*, translate::*};
6use gst::prelude::*;
7
8use crate::{ffi, BaseTransform};
9
10mod sealed {
11    pub trait Sealed {}
12    impl<T: super::IsA<super::BaseTransform>> Sealed for T {}
13}
14
15pub trait BaseTransformExtManual: sealed::Sealed + IsA<BaseTransform> + 'static {
16    /// Lets [`BaseTransform`][crate::BaseTransform] sub-classes know the memory `allocator`
17    /// used by the base class and its `params`.
18    ///
19    /// Unref the `allocator` after use.
20    ///
21    /// # Returns
22    ///
23    ///
24    /// ## `allocator`
25    /// the [`gst::Allocator`][crate::gst::Allocator]
26    /// used
27    ///
28    /// ## `params`
29    /// the [`gst::AllocationParams`][crate::gst::AllocationParams] of `allocator`
30    #[doc(alias = "get_allocator")]
31    #[doc(alias = "gst_base_transform_get_allocator")]
32    fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
33        unsafe {
34            let mut allocator = ptr::null_mut();
35            let mut params = mem::MaybeUninit::uninit();
36            ffi::gst_base_transform_get_allocator(
37                self.as_ref().to_glib_none().0,
38                &mut allocator,
39                params.as_mut_ptr(),
40            );
41            (from_glib_full(allocator), params.assume_init().into())
42        }
43    }
44
45    #[doc(alias = "get_segment")]
46    fn segment(&self) -> gst::Segment {
47        unsafe {
48            let trans: &ffi::GstBaseTransform = &*(self.as_ptr() as *const _);
49            let sinkpad = self.sink_pad();
50            let _guard = sinkpad.stream_lock();
51            from_glib_none(&trans.segment as *const _)
52        }
53    }
54
55    fn sink_pad(&self) -> &gst::Pad {
56        unsafe {
57            let elt = &*(self.as_ptr() as *const ffi::GstBaseTransform);
58            &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
59        }
60    }
61
62    fn src_pad(&self) -> &gst::Pad {
63        unsafe {
64            let elt = &*(self.as_ptr() as *const ffi::GstBaseTransform);
65            &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
66        }
67    }
68}
69
70impl<O: IsA<BaseTransform>> BaseTransformExtManual for O {}