From e24efa7259ec6c2e1bb621b67b44db3e6d7428ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Tue, 12 Feb 2019 15:23:30 +0100 Subject: [PATCH] gstreamer-base: subclassing: move parent fn in dedicated trait (!231) --- gstreamer-base/src/subclass/aggregator.rs | 80 +++++++++++++++++- gstreamer-base/src/subclass/aggregator_pad.rs | 20 ++++- gstreamer-base/src/subclass/base_sink.rs | 58 ++++++++++++- gstreamer-base/src/subclass/base_src.rs | 57 ++++++++++++- gstreamer-base/src/subclass/base_transform.rs | 83 ++++++++++++++++++- gstreamer-base/src/subclass/mod.rs | 12 +-- 6 files changed, 296 insertions(+), 14 deletions(-) diff --git a/gstreamer-base/src/subclass/aggregator.rs b/gstreamer-base/src/subclass/aggregator.rs index 76bb7f61a..aa0340539 100644 --- a/gstreamer-base/src/subclass/aggregator.rs +++ b/gstreamer-base/src/subclass/aggregator.rs @@ -25,7 +25,7 @@ use Aggregator; use AggregatorClass; use AggregatorPad; -pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static { +pub trait AggregatorImpl: AggregatorImplExt + ElementImpl + Send + Sync + 'static { fn flush(&self, aggregator: &Aggregator) -> Result { self.parent_flush(aggregator) } @@ -129,7 +129,85 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static { ) -> Result<(), gst::LoggableError> { self.parent_negotiated_src_caps(aggregator, caps) } +} +pub trait AggregatorImplExt { + fn parent_flush(&self, aggregator: &Aggregator) -> Result; + + fn parent_clip( + &self, + aggregator: &Aggregator, + aggregator_pad: &AggregatorPad, + buffer: gst::Buffer, + ) -> Option; + + fn parent_finish_buffer( + &self, + aggregator: &Aggregator, + buffer: gst::Buffer, + ) -> Result; + + fn parent_sink_event( + &self, + aggregator: &Aggregator, + aggregator_pad: &AggregatorPad, + event: gst::Event, + ) -> bool; + + fn parent_sink_query( + &self, + aggregator: &Aggregator, + aggregator_pad: &AggregatorPad, + query: &mut gst::QueryRef, + ) -> bool; + + fn parent_src_event(&self, aggregator: &Aggregator, event: gst::Event) -> bool; + + fn parent_src_query(&self, aggregator: &Aggregator, query: &mut gst::QueryRef) -> bool; + + fn parent_src_activate( + &self, + aggregator: &Aggregator, + mode: gst::PadMode, + active: bool, + ) -> Result<(), gst::LoggableError>; + + fn parent_aggregate( + &self, + aggregator: &Aggregator, + timeout: bool, + ) -> Result; + + fn parent_start(&self, aggregator: &Aggregator) -> Result<(), gst::ErrorMessage>; + + fn parent_stop(&self, aggregator: &Aggregator) -> Result<(), gst::ErrorMessage>; + + fn parent_get_next_time(&self, aggregator: &Aggregator) -> gst::ClockTime; + + fn parent_create_new_pad( + &self, + aggregator: &Aggregator, + templ: &gst::PadTemplate, + req_name: Option<&str>, + caps: Option<&gst::CapsRef>, + ) -> Option; + + fn parent_update_src_caps( + &self, + aggregator: &Aggregator, + caps: &gst::CapsRef, + ) -> Result; + + fn parent_fixate_src_caps(&self, aggregator: &Aggregator, caps: gst::Caps) -> gst::Caps; + + fn parent_negotiated_src_caps( + &self, + aggregator: &Aggregator, + caps: &gst::CapsRef, + ) -> Result<(), gst::LoggableError>; +} + +impl AggregatorImplExt for T { fn parent_flush(&self, aggregator: &Aggregator) -> Result { unsafe { let data = self.get_type_data(); diff --git a/gstreamer-base/src/subclass/aggregator_pad.rs b/gstreamer-base/src/subclass/aggregator_pad.rs index 09254c907..4623a5972 100644 --- a/gstreamer-base/src/subclass/aggregator_pad.rs +++ b/gstreamer-base/src/subclass/aggregator_pad.rs @@ -21,7 +21,7 @@ use Aggregator; use AggregatorPad; use AggregatorPadClass; -pub trait AggregatorPadImpl: PadImpl + Send + Sync + 'static { +pub trait AggregatorPadImpl: AggregatorPadImplExt + PadImpl + Send + Sync + 'static { fn flush( &self, aggregator_pad: &AggregatorPad, @@ -38,7 +38,24 @@ pub trait AggregatorPadImpl: PadImpl + Send + Sync + 'static { ) -> bool { self.parent_skip_buffer(aggregator_pad, aggregator, buffer) } +} +pub trait AggregatorPadImplExt { + fn parent_flush( + &self, + aggregator_pad: &AggregatorPad, + aggregator: &Aggregator, + ) -> Result; + + fn parent_skip_buffer( + &self, + aggregator_pad: &AggregatorPad, + aggregator: &Aggregator, + buffer: &gst::BufferRef, + ) -> bool; +} + +impl AggregatorPadImplExt for T { fn parent_flush( &self, aggregator_pad: &AggregatorPad, @@ -82,7 +99,6 @@ pub trait AggregatorPadImpl: PadImpl + Send + Sync + 'static { } } } - unsafe impl IsSubclassable for AggregatorPadClass { fn override_vfuncs(&mut self) { >::override_vfuncs(self); diff --git a/gstreamer-base/src/subclass/base_sink.rs b/gstreamer-base/src/subclass/base_sink.rs index da592166f..2a0cfe296 100644 --- a/gstreamer-base/src/subclass/base_sink.rs +++ b/gstreamer-base/src/subclass/base_sink.rs @@ -22,7 +22,7 @@ use std::ptr; use BaseSink; use BaseSinkClass; -pub trait BaseSinkImpl: ElementImpl + Send + Sync + 'static { +pub trait BaseSinkImpl: BaseSinkImplExt + ElementImpl + Send + Sync + 'static { fn start(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage> { self.parent_start(element) } @@ -62,7 +62,7 @@ pub trait BaseSinkImpl: ElementImpl + Send + Sync + 'static { } fn query(&self, element: &BaseSink, query: &mut gst::QueryRef) -> bool { - BaseSinkImpl::parent_query(self, element, query) + BaseSinkImplExt::parent_query(self, element, query) } fn event(&self, element: &BaseSink, event: gst::Event) -> bool { @@ -88,7 +88,61 @@ pub trait BaseSinkImpl: ElementImpl + Send + Sync + 'static { fn unlock_stop(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage> { self.parent_unlock_stop(element) } +} +pub trait BaseSinkImplExt { + fn parent_start(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage>; + + fn parent_stop(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage>; + + fn parent_render( + &self, + element: &BaseSink, + buffer: &gst::BufferRef, + ) -> Result; + + fn parent_prepare( + &self, + element: &BaseSink, + buffer: &gst::BufferRef, + ) -> Result; + + fn parent_render_list( + &self, + element: &BaseSink, + list: &gst::BufferListRef, + ) -> Result; + + fn parent_prepare_list( + &self, + element: &BaseSink, + list: &gst::BufferListRef, + ) -> Result; + + fn parent_query(&self, element: &BaseSink, query: &mut gst::QueryRef) -> bool; + + fn parent_event(&self, element: &BaseSink, event: gst::Event) -> bool; + + fn parent_get_caps( + &self, + element: &BaseSink, + filter: Option<&gst::CapsRef>, + ) -> Option; + + fn parent_set_caps( + &self, + element: &BaseSink, + caps: &gst::CapsRef, + ) -> Result<(), gst::LoggableError>; + + fn parent_fixate(&self, element: &BaseSink, caps: gst::Caps) -> gst::Caps; + + fn parent_unlock(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage>; + + fn parent_unlock_stop(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage>; +} + +impl BaseSinkImplExt for T { fn parent_start(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage> { unsafe { let data = self.get_type_data(); diff --git a/gstreamer-base/src/subclass/base_src.rs b/gstreamer-base/src/subclass/base_src.rs index ef5622b15..c52cd1b3c 100644 --- a/gstreamer-base/src/subclass/base_src.rs +++ b/gstreamer-base/src/subclass/base_src.rs @@ -22,7 +22,7 @@ use std::ptr; use BaseSrc; use BaseSrcClass; -pub trait BaseSrcImpl: ElementImpl + Send + Sync + 'static { +pub trait BaseSrcImpl: BaseSrcImplExt + ElementImpl + Send + Sync + 'static { fn start(&self, element: &BaseSrc) -> Result<(), gst::ErrorMessage> { self.parent_start(element) } @@ -63,7 +63,7 @@ pub trait BaseSrcImpl: ElementImpl + Send + Sync + 'static { } fn query(&self, element: &BaseSrc, query: &mut gst::QueryRef) -> bool { - BaseSrcImpl::parent_query(self, element, query) + BaseSrcImplExt::parent_query(self, element, query) } fn event(&self, element: &BaseSrc, event: &gst::Event) -> bool { @@ -93,7 +93,60 @@ pub trait BaseSrcImpl: ElementImpl + Send + Sync + 'static { fn unlock_stop(&self, element: &BaseSrc) -> Result<(), gst::ErrorMessage> { self.parent_unlock_stop(element) } +} +pub trait BaseSrcImplExt { + fn parent_start(&self, element: &BaseSrc) -> Result<(), gst::ErrorMessage>; + + fn parent_stop(&self, element: &BaseSrc) -> Result<(), gst::ErrorMessage>; + + fn parent_is_seekable(&self, element: &BaseSrc) -> bool; + + fn parent_get_size(&self, element: &BaseSrc) -> Option; + + fn parent_fill( + &self, + element: &BaseSrc, + offset: u64, + length: u32, + buffer: &mut gst::BufferRef, + ) -> Result; + + fn parent_create( + &self, + element: &BaseSrc, + offset: u64, + length: u32, + ) -> Result; + + fn parent_do_seek(&self, element: &BaseSrc, segment: &mut gst::Segment) -> bool; + + fn parent_query(&self, element: &BaseSrc, query: &mut gst::QueryRef) -> bool; + + fn parent_event(&self, element: &BaseSrc, event: &gst::Event) -> bool; + + fn parent_get_caps( + &self, + element: &BaseSrc, + filter: Option<&gst::CapsRef>, + ) -> Option; + + fn parent_negotiate(&self, element: &BaseSrc) -> Result<(), gst::LoggableError>; + + fn parent_set_caps( + &self, + element: &BaseSrc, + caps: &gst::CapsRef, + ) -> Result<(), gst::LoggableError>; + + fn parent_fixate(&self, element: &BaseSrc, caps: gst::Caps) -> gst::Caps; + + fn parent_unlock(&self, element: &BaseSrc) -> Result<(), gst::ErrorMessage>; + + fn parent_unlock_stop(&self, element: &BaseSrc) -> Result<(), gst::ErrorMessage>; +} + +impl BaseSrcImplExt for T { fn parent_start(&self, element: &BaseSrc) -> Result<(), gst::ErrorMessage> { unsafe { let data = self.get_type_data(); diff --git a/gstreamer-base/src/subclass/base_transform.rs b/gstreamer-base/src/subclass/base_transform.rs index 5167289cb..19b3986a8 100644 --- a/gstreamer-base/src/subclass/base_transform.rs +++ b/gstreamer-base/src/subclass/base_transform.rs @@ -20,7 +20,7 @@ use gst::subclass::prelude::*; use BaseTransform; use BaseTransformClass; -pub trait BaseTransformImpl: ElementImpl + Send + Sync + 'static { +pub trait BaseTransformImpl: BaseTransformImplExt + ElementImpl + Send + Sync + 'static { fn start(&self, element: &BaseTransform) -> Result<(), gst::ErrorMessage> { self.parent_start(element) } @@ -68,7 +68,7 @@ pub trait BaseTransformImpl: ElementImpl + Send + Sync + 'static { direction: gst::PadDirection, query: &mut gst::QueryRef, ) -> bool { - BaseTransformImpl::parent_query(self, element, direction, query) + BaseTransformImplExt::parent_query(self, element, direction, query) } fn transform_size( @@ -118,7 +118,86 @@ pub trait BaseTransformImpl: ElementImpl + Send + Sync + 'static { ) -> Result { self.parent_transform_ip_passthrough(element, buf) } +} +pub trait BaseTransformImplExt { + fn parent_start(&self, element: &BaseTransform) -> Result<(), gst::ErrorMessage>; + + fn parent_stop(&self, element: &BaseTransform) -> Result<(), gst::ErrorMessage>; + + fn parent_transform_caps( + &self, + element: &BaseTransform, + direction: gst::PadDirection, + caps: &gst::Caps, + filter: Option<&gst::Caps>, + ) -> Option; + + fn parent_fixate_caps( + &self, + element: &BaseTransform, + direction: gst::PadDirection, + caps: &gst::Caps, + othercaps: gst::Caps, + ) -> gst::Caps; + + fn parent_set_caps( + &self, + element: &BaseTransform, + incaps: &gst::Caps, + outcaps: &gst::Caps, + ) -> bool; + + fn parent_accept_caps( + &self, + element: &BaseTransform, + direction: gst::PadDirection, + caps: &gst::Caps, + ) -> bool; + + fn parent_query( + &self, + element: &BaseTransform, + direction: gst::PadDirection, + query: &mut gst::QueryRef, + ) -> bool; + + fn parent_transform_size( + &self, + element: &BaseTransform, + direction: gst::PadDirection, + caps: &gst::Caps, + size: usize, + othercaps: &gst::Caps, + ) -> Option; + + fn parent_get_unit_size(&self, element: &BaseTransform, caps: &gst::Caps) -> Option; + + fn parent_sink_event(&self, element: &BaseTransform, event: gst::Event) -> bool; + + fn parent_src_event(&self, element: &BaseTransform, event: gst::Event) -> bool; + + fn parent_transform( + &self, + element: &BaseTransform, + inbuf: &gst::Buffer, + outbuf: &mut gst::BufferRef, + ) -> Result; + + fn parent_transform_ip( + &self, + element: &BaseTransform, + buf: &mut gst::BufferRef, + ) -> Result; + + fn parent_transform_ip_passthrough( + &self, + element: &BaseTransform, + buf: &gst::BufferRef, + ) -> Result; +} + +impl BaseTransformImplExt for T { fn parent_start(&self, element: &BaseTransform) -> Result<(), gst::ErrorMessage> { unsafe { let data = self.get_type_data(); diff --git a/gstreamer-base/src/subclass/mod.rs b/gstreamer-base/src/subclass/mod.rs index 758bee920..caf292834 100644 --- a/gstreamer-base/src/subclass/mod.rs +++ b/gstreamer-base/src/subclass/mod.rs @@ -21,10 +21,12 @@ pub mod aggregator_pad; pub mod prelude { #[cfg(any(feature = "v1_14", feature = "dox"))] - pub use super::aggregator::AggregatorImpl; + pub use super::aggregator::{AggregatorImpl, AggregatorImplExt}; #[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}; + pub use super::aggregator_pad::{AggregatorPadImpl, AggregatorPadImplExt}; + pub use super::base_sink::{BaseSinkImpl, BaseSinkImplExt}; + pub use super::base_src::{BaseSrcImpl, BaseSrcImplExt}; + pub use super::base_transform::{ + BaseTransformClassSubclassExt, BaseTransformImpl, BaseTransformImplExt, + }; }