Skip to main content

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::{BaseTransform, ffi};
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    /// Allows [`BaseTransform`][crate::BaseTransform] sub-classes to set the buffer `pool`, memory `allocator`,
41    /// its `params` and the `query` if they originate from an Allocation `GstQuery`.
42    /// ## `pool`
43    /// the [`gst::BufferPool`][crate::gst::BufferPool]
44    /// ## `allocator`
45    /// the [`gst::Allocator`][crate::gst::Allocator]
46    /// ## `params`
47    /// the [`gst::AllocationParams`][crate::gst::AllocationParams] of `allocator`
48    /// ## `query`
49    /// the Allocation `GstQuery` if any
50    ///
51    /// # Returns
52    ///
53    /// TRUE on success or FALSE if buffer `pool` activation failed
54    #[cfg(feature = "v1_30")]
55    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
56    #[doc(alias = "gst_base_transform_set_allocator")]
57    fn set_allocator(
58        &self,
59        pool: Option<impl IsA<gst::BufferPool>>,
60        allocator: Option<impl IsA<gst::Allocator>>,
61        params: Option<&gst::AllocationParams>,
62        query: Option<gst::query::Allocation<gst::Query>>,
63    ) -> Result<(), gst::LoggableError> {
64        unsafe {
65            gst::result_from_gboolean!(
66                ffi::gst_base_transform_set_allocator(
67                    self.as_ref().to_glib_none().0,
68                    pool.map(|p| p.upcast()).into_glib_ptr(),
69                    allocator.map(|p| p.upcast()).into_glib_ptr(),
70                    params.to_glib_none().0,
71                    query.map(gst::Query::from).into_glib_ptr(),
72                ),
73                gst::CAT_RUST,
74                "Failed to set allocator"
75            )
76        }
77    }
78
79    #[doc(alias = "get_segment")]
80    fn segment(&self) -> gst::Segment {
81        unsafe {
82            let trans: &ffi::GstBaseTransform = &*(self.as_ptr() as *const _);
83            let sinkpad = self.sink_pad();
84            let _guard = sinkpad.stream_lock();
85            from_glib_none(&trans.segment as *const _)
86        }
87    }
88
89    fn sink_pad(&self) -> &gst::Pad {
90        unsafe {
91            let elt = &*(self.as_ptr() as *const ffi::GstBaseTransform);
92            &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
93        }
94    }
95
96    fn src_pad(&self) -> &gst::Pad {
97        unsafe {
98            let elt = &*(self.as_ptr() as *const ffi::GstBaseTransform);
99            &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
100        }
101    }
102}
103
104impl<O: IsA<BaseTransform>> BaseTransformExtManual for O {}