diff --git a/Gir_GstBase.toml b/Gir_GstBase.toml index 551212336..8bc2bcb31 100644 --- a/Gir_GstBase.toml +++ b/Gir_GstBase.toml @@ -108,6 +108,7 @@ version = "1.14" [[object]] name = "GstBase.AggregatorPad" status = "generate" +subclassing = true version = "1.14" [[object]] diff --git a/gstreamer-base/src/aggregator_pad.rs b/gstreamer-base/src/aggregator_pad.rs index 19027fa75..fc46ae7f1 100644 --- a/gstreamer-base/src/aggregator_pad.rs +++ b/gstreamer-base/src/aggregator_pad.rs @@ -8,11 +8,13 @@ use ffi; use glib::translate::*; -use glib::IsA; +use glib::{IsA, IsClassFor}; use gst; use gst_ffi; use AggregatorPad; +use std::ops; + pub trait AggregatorPadExtManual { fn get_segment(&self) -> gst::Segment; } @@ -27,3 +29,27 @@ impl> AggregatorPadExtManual for O { } } } + +#[repr(C)] +pub struct AggregatorPadClass(ffi::GstAggregatorPadClass); + +unsafe impl IsClassFor for AggregatorPadClass { + type Instance = ::AggregatorPad; +} + +unsafe impl Send for AggregatorPadClass {} +unsafe impl Sync for AggregatorPadClass {} + +impl ops::Deref for AggregatorPadClass { + type Target = gst::PadClass; + + fn deref(&self) -> &Self::Target { + self.upcast_ref() + } +} + +impl ops::DerefMut for AggregatorPadClass { + fn deref_mut(&mut self) -> &mut Self::Target { + self.upcast_ref_mut() + } +} diff --git a/gstreamer-base/src/auto/aggregator_pad.rs b/gstreamer-base/src/auto/aggregator_pad.rs index b67400158..86b349a42 100644 --- a/gstreamer-base/src/auto/aggregator_pad.rs +++ b/gstreamer-base/src/auto/aggregator_pad.rs @@ -2,6 +2,7 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +use AggregatorPadClass; use ffi; use glib::object::IsA; use glib::translate::*; @@ -13,7 +14,7 @@ use std::mem; use std::ptr; glib_wrapper! { - pub struct AggregatorPad(Object): [ + pub struct AggregatorPad(Object): [ gst::Pad => gst_ffi::GstPad, gst::Object => gst_ffi::GstObject, ]; diff --git a/gstreamer-base/src/lib.rs b/gstreamer-base/src/lib.rs index 549f88173..bf48575b6 100644 --- a/gstreamer-base/src/lib.rs +++ b/gstreamer-base/src/lib.rs @@ -45,6 +45,8 @@ pub use flow_combiner::*; mod aggregator; #[cfg(any(feature = "v1_14", feature = "dox"))] mod aggregator_pad; +#[cfg(any(feature = "v1_14", feature = "dox"))] +pub use aggregator_pad::AggregatorPadClass; mod base_sink; pub use base_sink::BaseSinkClass; mod base_src; diff --git a/gstreamer-base/src/subclass/aggregator_pad.rs b/gstreamer-base/src/subclass/aggregator_pad.rs new file mode 100644 index 000000000..1c586600f --- /dev/null +++ b/gstreamer-base/src/subclass/aggregator_pad.rs @@ -0,0 +1,126 @@ +// Copyright (C) 2018 Sebastian Dröge +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use ffi; +use glib_ffi; +use gst_ffi; + +use glib::translate::*; +use gst; +use gst::prelude::*; + +use glib::subclass::prelude::*; +use gst::subclass::prelude::*; + +use Aggregator; +use AggregatorPad; +use AggregatorPadClass; + +pub trait AggregatorPadImpl: PadImpl + Send + Sync + 'static { + fn flush(&self, aggregator_pad: &AggregatorPad, aggregator: &Aggregator) -> gst::FlowReturn { + self.parent_flush(aggregator_pad, aggregator) + } + + fn skip_buffer( + &self, + aggregator_pad: &AggregatorPad, + aggregator: &Aggregator, + buffer: &gst::BufferRef, + ) -> bool { + self.parent_skip_buffer(aggregator_pad, aggregator, buffer) + } + + fn parent_flush( + &self, + aggregator_pad: &AggregatorPad, + aggregator: &Aggregator, + ) -> gst::FlowReturn { + unsafe { + let data = self.get_type_data(); + let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorPadClass; + (*parent_class) + .flush + .map(|f| { + from_glib(f( + aggregator_pad.to_glib_none().0, + aggregator.to_glib_none().0, + )) + }) + .unwrap_or(gst::FlowReturn::Ok) + } + } + + fn parent_skip_buffer( + &self, + aggregator_pad: &AggregatorPad, + aggregator: &Aggregator, + buffer: &gst::BufferRef, + ) -> bool { + unsafe { + let data = self.get_type_data(); + let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorPadClass; + (*parent_class) + .skip_buffer + .map(|f| { + from_glib(f( + aggregator_pad.to_glib_none().0, + aggregator.to_glib_none().0, + buffer.as_mut_ptr(), + )) + }) + .unwrap_or(false) + } + } +} + +unsafe impl IsSubclassable for AggregatorPadClass { + fn override_vfuncs(&mut self) { + >::override_vfuncs(self); + unsafe { + let klass = &mut *(self as *const Self as *mut ffi::GstAggregatorPadClass); + klass.flush = Some(aggregator_pad_flush::); + klass.skip_buffer = Some(aggregator_pad_skip_buffer::); + } + } +} + +unsafe extern "C" fn aggregator_pad_flush( + ptr: *mut ffi::GstAggregatorPad, + aggregator: *mut ffi::GstAggregator, +) -> gst_ffi::GstFlowReturn +where + T: AggregatorPadImpl, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: AggregatorPad = from_glib_borrow(ptr); + + imp.flush(&wrap, &from_glib_borrow(aggregator)).to_glib() +} + +unsafe extern "C" fn aggregator_pad_skip_buffer( + ptr: *mut ffi::GstAggregatorPad, + aggregator: *mut ffi::GstAggregator, + buffer: *mut gst_ffi::GstBuffer, +) -> glib_ffi::gboolean +where + T: AggregatorPadImpl, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: AggregatorPad = from_glib_borrow(ptr); + + imp.skip_buffer( + &wrap, + &from_glib_borrow(aggregator), + gst::BufferRef::from_ptr(buffer), + ) + .to_glib() +} diff --git a/gstreamer-base/src/subclass/mod.rs b/gstreamer-base/src/subclass/mod.rs index 68d346072..125739c46 100644 --- a/gstreamer-base/src/subclass/mod.rs +++ b/gstreamer-base/src/subclass/mod.rs @@ -14,7 +14,12 @@ pub mod base_transform; pub use self::base_transform::BaseTransformMode; +#[cfg(any(feature = "v1_14", feature = "dox"))] +pub mod aggregator_pad; + pub mod prelude { + #[cfg(any(feature = "v1_14", feature = "dox"))] + pub use super::aggregator_pad::AggregatorPadImpl; pub use super::base_sink::BaseSinkImpl; pub use super::base_src::BaseSrcImpl; pub use super::base_transform::{BaseTransformClassSubclassExt, BaseTransformImpl};