2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2018-11-21 06:49:36 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use glib::{prelude::*, translate::*};
|
2018-11-21 06:49:36 +00:00
|
|
|
use gst::subclass::prelude::*;
|
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use crate::{Aggregator, AggregatorPad};
|
2018-11-21 06:49:36 +00:00
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
pub trait AggregatorPadImpl: AggregatorPadImplExt + PadImpl {
|
2022-10-08 18:50:06 +00:00
|
|
|
fn flush(&self, aggregator: &Aggregator) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
self.parent_flush(aggregator)
|
2018-11-21 06:49:36 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn skip_buffer(&self, aggregator: &Aggregator, buffer: &gst::Buffer) -> bool {
|
|
|
|
self.parent_skip_buffer(aggregator, buffer)
|
2018-11-21 06:49:36 +00:00
|
|
|
}
|
2019-02-12 14:23:30 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
mod sealed {
|
|
|
|
pub trait Sealed {}
|
|
|
|
impl<T: super::AggregatorPadImplExt> Sealed for T {}
|
2019-02-12 14:23:30 +00:00
|
|
|
}
|
2018-11-21 06:49:36 +00:00
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
pub trait AggregatorPadImplExt: sealed::Sealed + ObjectSubclass {
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_flush(&self, aggregator: &Aggregator) -> Result<gst::FlowSuccess, gst::FlowError> {
|
2018-11-21 06:49:36 +00:00
|
|
|
unsafe {
|
2021-04-29 20:06:41 +00:00
|
|
|
let data = Self::type_data();
|
2021-04-11 19:39:50 +00:00
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAggregatorPadClass;
|
2018-11-21 06:49:36 +00:00
|
|
|
(*parent_class)
|
|
|
|
.flush
|
|
|
|
.map(|f| {
|
2021-05-13 12:54:41 +00:00
|
|
|
try_from_glib(f(
|
2022-10-23 19:59:23 +00:00
|
|
|
self.obj()
|
2020-11-14 16:01:13 +00:00
|
|
|
.unsafe_cast_ref::<AggregatorPad>()
|
|
|
|
.to_glib_none()
|
|
|
|
.0,
|
2018-11-21 06:49:36 +00:00
|
|
|
aggregator.to_glib_none().0,
|
|
|
|
))
|
|
|
|
})
|
2021-04-28 12:34:56 +00:00
|
|
|
.unwrap_or(Ok(gst::FlowSuccess::Ok))
|
2018-11-21 06:49:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_skip_buffer(&self, aggregator: &Aggregator, buffer: &gst::Buffer) -> bool {
|
2018-11-21 06:49:36 +00:00
|
|
|
unsafe {
|
2021-04-29 20:06:41 +00:00
|
|
|
let data = Self::type_data();
|
2021-04-11 19:39:50 +00:00
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAggregatorPadClass;
|
2018-11-21 06:49:36 +00:00
|
|
|
(*parent_class)
|
|
|
|
.skip_buffer
|
|
|
|
.map(|f| {
|
|
|
|
from_glib(f(
|
2022-10-23 19:59:23 +00:00
|
|
|
self.obj()
|
2020-11-14 16:01:13 +00:00
|
|
|
.unsafe_cast_ref::<AggregatorPad>()
|
|
|
|
.to_glib_none()
|
|
|
|
.0,
|
2018-11-21 06:49:36 +00:00
|
|
|
aggregator.to_glib_none().0,
|
2019-05-23 11:28:09 +00:00
|
|
|
buffer.to_glib_none().0,
|
2018-11-21 06:49:36 +00:00
|
|
|
))
|
|
|
|
})
|
|
|
|
.unwrap_or(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-05 20:21:43 +00:00
|
|
|
|
|
|
|
impl<T: AggregatorPadImpl> AggregatorPadImplExt for T {}
|
2020-11-05 13:18:19 +00:00
|
|
|
unsafe impl<T: AggregatorPadImpl> IsSubclassable<T> for AggregatorPad {
|
2021-03-08 10:06:56 +00:00
|
|
|
fn class_init(klass: &mut glib::Class<Self>) {
|
2021-08-24 05:55:37 +00:00
|
|
|
Self::parent_class_init::<T>(klass);
|
2020-11-05 17:07:31 +00:00
|
|
|
let klass = klass.as_mut();
|
|
|
|
klass.flush = Some(aggregator_pad_flush::<T>);
|
|
|
|
klass.skip_buffer = Some(aggregator_pad_skip_buffer::<T>);
|
2018-11-21 06:49:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn aggregator_pad_flush<T: AggregatorPadImpl>(
|
2020-11-21 17:59:22 +00:00
|
|
|
ptr: *mut ffi::GstAggregatorPad,
|
|
|
|
aggregator: *mut ffi::GstAggregator,
|
|
|
|
) -> gst::ffi::GstFlowReturn {
|
2018-11-21 06:49:36 +00:00
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2018-11-21 06:49:36 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
let res: gst::FlowReturn = imp.flush(&from_glib_borrow(aggregator)).into();
|
2021-04-27 15:15:46 +00:00
|
|
|
res.into_glib()
|
2018-11-21 06:49:36 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn aggregator_pad_skip_buffer<T: AggregatorPadImpl>(
|
2020-11-21 17:59:22 +00:00
|
|
|
ptr: *mut ffi::GstAggregatorPad,
|
|
|
|
aggregator: *mut ffi::GstAggregator,
|
|
|
|
buffer: *mut gst::ffi::GstBuffer,
|
|
|
|
) -> glib::ffi::gboolean {
|
2018-11-21 06:49:36 +00:00
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2018-11-21 06:49:36 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
imp.skip_buffer(&from_glib_borrow(aggregator), &from_glib_borrow(buffer))
|
|
|
|
.into_glib()
|
2018-11-21 06:49:36 +00:00
|
|
|
}
|