gstreamer_base/subclass/
aggregator_pad.rs
1use glib::{prelude::*, translate::*};
4use gst::subclass::prelude::*;
5
6use crate::{ffi, Aggregator, AggregatorPad};
7
8pub trait AggregatorPadImpl: PadImpl + ObjectSubclass<Type: IsA<AggregatorPad>> {
9 fn flush(&self, aggregator: &Aggregator) -> Result<gst::FlowSuccess, gst::FlowError> {
14 self.parent_flush(aggregator)
15 }
16
17 fn skip_buffer(&self, aggregator: &Aggregator, buffer: &gst::Buffer) -> bool {
21 self.parent_skip_buffer(aggregator, buffer)
22 }
23}
24
25pub trait AggregatorPadImplExt: AggregatorPadImpl {
26 fn parent_flush(&self, aggregator: &Aggregator) -> Result<gst::FlowSuccess, gst::FlowError> {
27 unsafe {
28 let data = Self::type_data();
29 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAggregatorPadClass;
30 (*parent_class)
31 .flush
32 .map(|f| {
33 try_from_glib(f(
34 self.obj()
35 .unsafe_cast_ref::<AggregatorPad>()
36 .to_glib_none()
37 .0,
38 aggregator.to_glib_none().0,
39 ))
40 })
41 .unwrap_or(Ok(gst::FlowSuccess::Ok))
42 }
43 }
44
45 fn parent_skip_buffer(&self, aggregator: &Aggregator, buffer: &gst::Buffer) -> bool {
46 unsafe {
47 let data = Self::type_data();
48 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAggregatorPadClass;
49 (*parent_class)
50 .skip_buffer
51 .map(|f| {
52 from_glib(f(
53 self.obj()
54 .unsafe_cast_ref::<AggregatorPad>()
55 .to_glib_none()
56 .0,
57 aggregator.to_glib_none().0,
58 buffer.to_glib_none().0,
59 ))
60 })
61 .unwrap_or(false)
62 }
63 }
64}
65
66impl<T: AggregatorPadImpl> AggregatorPadImplExt for T {}
67unsafe impl<T: AggregatorPadImpl> IsSubclassable<T> for AggregatorPad {
68 fn class_init(klass: &mut glib::Class<Self>) {
69 Self::parent_class_init::<T>(klass);
70 let klass = klass.as_mut();
71 klass.flush = Some(aggregator_pad_flush::<T>);
72 klass.skip_buffer = Some(aggregator_pad_skip_buffer::<T>);
73 }
74}
75
76unsafe extern "C" fn aggregator_pad_flush<T: AggregatorPadImpl>(
77 ptr: *mut ffi::GstAggregatorPad,
78 aggregator: *mut ffi::GstAggregator,
79) -> gst::ffi::GstFlowReturn {
80 let instance = &*(ptr as *mut T::Instance);
81 let imp = instance.imp();
82
83 let res: gst::FlowReturn = imp.flush(&from_glib_borrow(aggregator)).into();
84 res.into_glib()
85}
86
87unsafe extern "C" fn aggregator_pad_skip_buffer<T: AggregatorPadImpl>(
88 ptr: *mut ffi::GstAggregatorPad,
89 aggregator: *mut ffi::GstAggregator,
90 buffer: *mut gst::ffi::GstBuffer,
91) -> glib::ffi::gboolean {
92 let instance = &*(ptr as *mut T::Instance);
93 let imp = instance.imp();
94
95 imp.skip_buffer(&from_glib_borrow(aggregator), &from_glib_borrow(buffer))
96 .into_glib()
97}