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