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