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    #[doc(alias = "get_allocator")]
12    #[doc(alias = "gst_base_transform_get_allocator")]
13    fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
14        unsafe {
15            let mut allocator = ptr::null_mut();
16            let mut params = mem::MaybeUninit::uninit();
17            ffi::gst_base_transform_get_allocator(
18                self.as_ref().to_glib_none().0,
19                &mut allocator,
20                params.as_mut_ptr(),
21            );
22            (from_glib_full(allocator), params.assume_init().into())
23        }
24    }
25
26    #[cfg(feature = "v1_30")]
27    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
28    #[doc(alias = "gst_base_transform_set_allocator")]
29    fn set_allocator(
30        &self,
31        pool: Option<impl IsA<gst::BufferPool>>,
32        allocator: Option<impl IsA<gst::Allocator>>,
33        params: Option<&gst::AllocationParams>,
34        query: Option<gst::query::Allocation<gst::Query>>,
35    ) -> Result<(), gst::LoggableError> {
36        unsafe {
37            gst::result_from_gboolean!(
38                ffi::gst_base_transform_set_allocator(
39                    self.as_ref().to_glib_none().0,
40                    pool.map(|p| p.upcast()).into_glib_ptr(),
41                    allocator.map(|p| p.upcast()).into_glib_ptr(),
42                    params.to_glib_none().0,
43                    query.map(gst::Query::from).into_glib_ptr(),
44                ),
45                gst::CAT_RUST,
46                "Failed to set allocator"
47            )
48        }
49    }
50
51    #[doc(alias = "get_segment")]
52    fn segment(&self) -> gst::Segment {
53        unsafe {
54            let trans: &ffi::GstBaseTransform = &*(self.as_ptr() as *const _);
55            let sinkpad = self.sink_pad();
56            let _guard = sinkpad.stream_lock();
57            from_glib_none(&trans.segment as *const _)
58        }
59    }
60
61    fn sink_pad(&self) -> &gst::Pad {
62        unsafe {
63            let elt = &*(self.as_ptr() as *const ffi::GstBaseTransform);
64            &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
65        }
66    }
67
68    fn src_pad(&self) -> &gst::Pad {
69        unsafe {
70            let elt = &*(self.as_ptr() as *const ffi::GstBaseTransform);
71            &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
72        }
73    }
74}
75
76impl<O: IsA<BaseTransform>> BaseTransformExtManual for O {}