From 8160521574affc3e71a6500af49e2d119cae64fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 13 Sep 2019 22:58:53 +0300 Subject: [PATCH] video: Add support for getcaps(), negotiate(), src/sink_query/event() vfuncs in VideoEncoder/Decoder --- gstreamer-video/src/subclass/video_decoder.rs | 251 ++++++++++++++++++ gstreamer-video/src/subclass/video_encoder.rs | 251 ++++++++++++++++++ 2 files changed, 502 insertions(+) diff --git a/gstreamer-video/src/subclass/video_decoder.rs b/gstreamer-video/src/subclass/video_decoder.rs index 120bd718f..2fbb84e94 100644 --- a/gstreamer-video/src/subclass/video_decoder.rs +++ b/gstreamer-video/src/subclass/video_decoder.rs @@ -75,6 +75,30 @@ pub trait VideoDecoderImpl: VideoDecoderImplExt + ElementImpl + Send + Sync + 's self.parent_flush(element) } + fn negotiate(&self, element: &VideoDecoder) -> Result<(), gst::LoggableError> { + self.parent_negotiate(element) + } + + fn get_caps(&self, element: &VideoDecoder, filter: Option<&gst::Caps>) -> Option { + self.parent_get_caps(element, filter) + } + + fn sink_event(&self, element: &VideoDecoder, event: gst::Event) -> bool { + self.parent_sink_event(element, event) + } + + fn sink_query(&self, element: &VideoDecoder, query: &mut gst::QueryRef) -> bool { + self.parent_sink_query(element, query) + } + + fn src_event(&self, element: &VideoDecoder, event: gst::Event) -> bool { + self.parent_src_event(element, event) + } + + fn src_query(&self, element: &VideoDecoder, query: &mut gst::QueryRef) -> bool { + self.parent_src_query(element, query) + } + fn propose_allocation( &self, element: &VideoDecoder, @@ -125,6 +149,22 @@ pub trait VideoDecoderImplExt { fn parent_flush(&self, element: &VideoDecoder) -> bool; + fn parent_negotiate(&self, element: &VideoDecoder) -> Result<(), gst::LoggableError>; + + fn parent_get_caps( + &self, + element: &VideoDecoder, + filter: Option<&gst::Caps>, + ) -> Option; + + fn parent_sink_event(&self, element: &VideoDecoder, event: gst::Event) -> bool; + + fn parent_sink_query(&self, element: &VideoDecoder, query: &mut gst::QueryRef) -> bool; + + fn parent_src_event(&self, element: &VideoDecoder, event: gst::Event) -> bool; + + fn parent_src_query(&self, element: &VideoDecoder, query: &mut gst::QueryRef) -> bool; + fn parent_propose_allocation( &self, element: &VideoDecoder, @@ -315,6 +355,88 @@ impl VideoDecoderImplExt for T { } } + fn parent_negotiate(&self, element: &VideoDecoder) -> Result<(), gst::LoggableError> { + unsafe { + let data = self.get_type_data(); + let parent_class = + data.as_ref().get_parent_class() as *mut gst_video_sys::GstVideoDecoderClass; + (*parent_class) + .negotiate + .map(|f| { + gst_result_from_gboolean!( + f(element.to_glib_none().0), + gst::CAT_RUST, + "Parent function `negotiate` failed" + ) + }) + .unwrap_or(Ok(())) + } + } + + fn parent_get_caps( + &self, + element: &VideoDecoder, + filter: Option<&gst::Caps>, + ) -> Option { + unsafe { + let data = self.get_type_data(); + let parent_class = + data.as_ref().get_parent_class() as *mut gst_video_sys::GstVideoDecoderClass; + (*parent_class) + .getcaps + .map(|f| from_glib_full(f(element.to_glib_none().0, filter.to_glib_none().0))) + .unwrap_or(None) + } + } + + fn parent_sink_event(&self, element: &VideoDecoder, event: gst::Event) -> bool { + unsafe { + let data = self.get_type_data(); + let parent_class = + data.as_ref().get_parent_class() as *mut gst_video_sys::GstVideoDecoderClass; + let f = (*parent_class) + .sink_event + .expect("Missing parent function `sink_event`"); + from_glib(f(element.to_glib_none().0, event.into_ptr())) + } + } + + fn parent_sink_query(&self, element: &VideoDecoder, query: &mut gst::QueryRef) -> bool { + unsafe { + let data = self.get_type_data(); + let parent_class = + data.as_ref().get_parent_class() as *mut gst_video_sys::GstVideoDecoderClass; + let f = (*parent_class) + .sink_query + .expect("Missing parent function `sink_query`"); + from_glib(f(element.to_glib_none().0, query.as_mut_ptr())) + } + } + + fn parent_src_event(&self, element: &VideoDecoder, event: gst::Event) -> bool { + unsafe { + let data = self.get_type_data(); + let parent_class = + data.as_ref().get_parent_class() as *mut gst_video_sys::GstVideoDecoderClass; + let f = (*parent_class) + .src_event + .expect("Missing parent function `src_event`"); + from_glib(f(element.to_glib_none().0, event.into_ptr())) + } + } + + fn parent_src_query(&self, element: &VideoDecoder, query: &mut gst::QueryRef) -> bool { + unsafe { + let data = self.get_type_data(); + let parent_class = + data.as_ref().get_parent_class() as *mut gst_video_sys::GstVideoDecoderClass; + let f = (*parent_class) + .src_query + .expect("Missing parent function `src_query`"); + from_glib(f(element.to_glib_none().0, query.as_mut_ptr())) + } + } + fn parent_propose_allocation( &self, element: &VideoDecoder, @@ -383,6 +505,12 @@ where klass.parse = Some(video_decoder_parse::); klass.handle_frame = Some(video_decoder_handle_frame::); klass.flush = Some(video_decoder_flush::); + klass.negotiate = Some(video_decoder_negotiate::); + klass.getcaps = Some(video_decoder_getcaps::); + klass.sink_event = Some(video_decoder_sink_event::); + klass.src_event = Some(video_decoder_src_event::); + klass.sink_query = Some(video_decoder_sink_query::); + klass.src_query = Some(video_decoder_src_query::); klass.propose_allocation = Some(video_decoder_propose_allocation::); klass.decide_allocation = Some(video_decoder_decide_allocation::); } @@ -593,6 +721,129 @@ where .to_glib() } +unsafe extern "C" fn video_decoder_negotiate( + ptr: *mut gst_video_sys::GstVideoDecoder, +) -> glib_sys::gboolean +where + T: VideoDecoderImpl, + T::Instance: PanicPoison, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: VideoDecoder = from_glib_borrow(ptr); + + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + match imp.negotiate(&wrap) { + Ok(()) => true, + Err(err) => { + err.log_with_object(&wrap); + false + } + } + }) + .to_glib() +} + +unsafe extern "C" fn video_decoder_getcaps( + ptr: *mut gst_video_sys::GstVideoDecoder, + filter: *mut gst_sys::GstCaps, +) -> *mut gst_sys::GstCaps +where + T: VideoDecoderImpl, + T::Instance: PanicPoison, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: VideoDecoder = from_glib_borrow(ptr); + + gst_panic_to_error!(&wrap, &instance.panicked(), None, { + VideoDecoderImpl::get_caps( + imp, + &wrap, + Option::::from_glib_borrow(filter).as_ref(), + ) + }) + .to_glib_full() +} + +unsafe extern "C" fn video_decoder_sink_event( + ptr: *mut gst_video_sys::GstVideoDecoder, + event: *mut gst_sys::GstEvent, +) -> glib_sys::gboolean +where + T: VideoDecoderImpl, + T::Instance: PanicPoison, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: VideoDecoder = from_glib_borrow(ptr); + + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + imp.sink_event(&wrap, from_glib_full(event)) + }) + .to_glib() +} + +unsafe extern "C" fn video_decoder_sink_query( + ptr: *mut gst_video_sys::GstVideoDecoder, + query: *mut gst_sys::GstQuery, +) -> glib_sys::gboolean +where + T: VideoDecoderImpl, + T::Instance: PanicPoison, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: VideoDecoder = from_glib_borrow(ptr); + + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + imp.sink_query(&wrap, gst::QueryRef::from_mut_ptr(query)) + }) + .to_glib() +} + +unsafe extern "C" fn video_decoder_src_event( + ptr: *mut gst_video_sys::GstVideoDecoder, + event: *mut gst_sys::GstEvent, +) -> glib_sys::gboolean +where + T: VideoDecoderImpl, + T::Instance: PanicPoison, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: VideoDecoder = from_glib_borrow(ptr); + + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + imp.src_event(&wrap, from_glib_full(event)) + }) + .to_glib() +} + +unsafe extern "C" fn video_decoder_src_query( + ptr: *mut gst_video_sys::GstVideoDecoder, + query: *mut gst_sys::GstQuery, +) -> glib_sys::gboolean +where + T: VideoDecoderImpl, + T::Instance: PanicPoison, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: VideoDecoder = from_glib_borrow(ptr); + + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + imp.src_query(&wrap, gst::QueryRef::from_mut_ptr(query)) + }) + .to_glib() +} + unsafe extern "C" fn video_decoder_propose_allocation( ptr: *mut gst_video_sys::GstVideoDecoder, query: *mut gst_sys::GstQuery, diff --git a/gstreamer-video/src/subclass/video_encoder.rs b/gstreamer-video/src/subclass/video_encoder.rs index 76e1cac34..4fee1fea8 100644 --- a/gstreamer-video/src/subclass/video_encoder.rs +++ b/gstreamer-video/src/subclass/video_encoder.rs @@ -64,6 +64,30 @@ pub trait VideoEncoderImpl: VideoEncoderImplExt + ElementImpl + Send + Sync + 's self.parent_flush(element) } + fn negotiate(&self, element: &VideoEncoder) -> Result<(), gst::LoggableError> { + self.parent_negotiate(element) + } + + fn get_caps(&self, element: &VideoEncoder, filter: Option<&gst::Caps>) -> Option { + self.parent_get_caps(element, filter) + } + + fn sink_event(&self, element: &VideoEncoder, event: gst::Event) -> bool { + self.parent_sink_event(element, event) + } + + fn sink_query(&self, element: &VideoEncoder, query: &mut gst::QueryRef) -> bool { + self.parent_sink_query(element, query) + } + + fn src_event(&self, element: &VideoEncoder, event: gst::Event) -> bool { + self.parent_src_event(element, event) + } + + fn src_query(&self, element: &VideoEncoder, query: &mut gst::QueryRef) -> bool { + self.parent_src_query(element, query) + } + fn propose_allocation( &self, element: &VideoEncoder, @@ -106,6 +130,22 @@ pub trait VideoEncoderImplExt { fn parent_flush(&self, element: &VideoEncoder) -> bool; + fn parent_negotiate(&self, element: &VideoEncoder) -> Result<(), gst::LoggableError>; + + fn parent_get_caps( + &self, + element: &VideoEncoder, + filter: Option<&gst::Caps>, + ) -> Option; + + fn parent_sink_event(&self, element: &VideoEncoder, event: gst::Event) -> bool; + + fn parent_sink_query(&self, element: &VideoEncoder, query: &mut gst::QueryRef) -> bool; + + fn parent_src_event(&self, element: &VideoEncoder, event: gst::Event) -> bool; + + fn parent_src_query(&self, element: &VideoEncoder, query: &mut gst::QueryRef) -> bool; + fn parent_propose_allocation( &self, element: &VideoEncoder, @@ -270,6 +310,88 @@ impl VideoEncoderImplExt for T { } } + fn parent_negotiate(&self, element: &VideoEncoder) -> Result<(), gst::LoggableError> { + unsafe { + let data = self.get_type_data(); + let parent_class = + data.as_ref().get_parent_class() as *mut gst_video_sys::GstVideoEncoderClass; + (*parent_class) + .negotiate + .map(|f| { + gst_result_from_gboolean!( + f(element.to_glib_none().0), + gst::CAT_RUST, + "Parent function `negotiate` failed" + ) + }) + .unwrap_or(Ok(())) + } + } + + fn parent_get_caps( + &self, + element: &VideoEncoder, + filter: Option<&gst::Caps>, + ) -> Option { + unsafe { + let data = self.get_type_data(); + let parent_class = + data.as_ref().get_parent_class() as *mut gst_video_sys::GstVideoEncoderClass; + (*parent_class) + .getcaps + .map(|f| from_glib_full(f(element.to_glib_none().0, filter.to_glib_none().0))) + .unwrap_or(None) + } + } + + fn parent_sink_event(&self, element: &VideoEncoder, event: gst::Event) -> bool { + unsafe { + let data = self.get_type_data(); + let parent_class = + data.as_ref().get_parent_class() as *mut gst_video_sys::GstVideoEncoderClass; + let f = (*parent_class) + .sink_event + .expect("Missing parent function `sink_event`"); + from_glib(f(element.to_glib_none().0, event.into_ptr())) + } + } + + fn parent_sink_query(&self, element: &VideoEncoder, query: &mut gst::QueryRef) -> bool { + unsafe { + let data = self.get_type_data(); + let parent_class = + data.as_ref().get_parent_class() as *mut gst_video_sys::GstVideoEncoderClass; + let f = (*parent_class) + .sink_query + .expect("Missing parent function `sink_query`"); + from_glib(f(element.to_glib_none().0, query.as_mut_ptr())) + } + } + + fn parent_src_event(&self, element: &VideoEncoder, event: gst::Event) -> bool { + unsafe { + let data = self.get_type_data(); + let parent_class = + data.as_ref().get_parent_class() as *mut gst_video_sys::GstVideoEncoderClass; + let f = (*parent_class) + .src_event + .expect("Missing parent function `src_event`"); + from_glib(f(element.to_glib_none().0, event.into_ptr())) + } + } + + fn parent_src_query(&self, element: &VideoEncoder, query: &mut gst::QueryRef) -> bool { + unsafe { + let data = self.get_type_data(); + let parent_class = + data.as_ref().get_parent_class() as *mut gst_video_sys::GstVideoEncoderClass; + let f = (*parent_class) + .src_query + .expect("Missing parent function `src_query`"); + from_glib(f(element.to_glib_none().0, query.as_mut_ptr())) + } + } + fn parent_propose_allocation( &self, element: &VideoEncoder, @@ -337,6 +459,12 @@ where klass.set_format = Some(video_encoder_set_format::); klass.handle_frame = Some(video_encoder_handle_frame::); klass.flush = Some(video_encoder_flush::); + klass.negotiate = Some(video_encoder_negotiate::); + klass.getcaps = Some(video_encoder_getcaps::); + klass.sink_event = Some(video_encoder_sink_event::); + klass.src_event = Some(video_encoder_src_event::); + klass.sink_query = Some(video_encoder_sink_query::); + klass.src_query = Some(video_encoder_src_query::); klass.propose_allocation = Some(video_encoder_propose_allocation::); klass.decide_allocation = Some(video_encoder_decide_allocation::); } @@ -522,6 +650,129 @@ where .to_glib() } +unsafe extern "C" fn video_encoder_negotiate( + ptr: *mut gst_video_sys::GstVideoEncoder, +) -> glib_sys::gboolean +where + T: VideoEncoderImpl, + T::Instance: PanicPoison, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: VideoEncoder = from_glib_borrow(ptr); + + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + match imp.negotiate(&wrap) { + Ok(()) => true, + Err(err) => { + err.log_with_object(&wrap); + false + } + } + }) + .to_glib() +} + +unsafe extern "C" fn video_encoder_getcaps( + ptr: *mut gst_video_sys::GstVideoEncoder, + filter: *mut gst_sys::GstCaps, +) -> *mut gst_sys::GstCaps +where + T: VideoEncoderImpl, + T::Instance: PanicPoison, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: VideoEncoder = from_glib_borrow(ptr); + + gst_panic_to_error!(&wrap, &instance.panicked(), None, { + VideoEncoderImpl::get_caps( + imp, + &wrap, + Option::::from_glib_borrow(filter).as_ref(), + ) + }) + .to_glib_full() +} + +unsafe extern "C" fn video_encoder_sink_event( + ptr: *mut gst_video_sys::GstVideoEncoder, + event: *mut gst_sys::GstEvent, +) -> glib_sys::gboolean +where + T: VideoEncoderImpl, + T::Instance: PanicPoison, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: VideoEncoder = from_glib_borrow(ptr); + + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + imp.sink_event(&wrap, from_glib_full(event)) + }) + .to_glib() +} + +unsafe extern "C" fn video_encoder_sink_query( + ptr: *mut gst_video_sys::GstVideoEncoder, + query: *mut gst_sys::GstQuery, +) -> glib_sys::gboolean +where + T: VideoEncoderImpl, + T::Instance: PanicPoison, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: VideoEncoder = from_glib_borrow(ptr); + + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + imp.sink_query(&wrap, gst::QueryRef::from_mut_ptr(query)) + }) + .to_glib() +} + +unsafe extern "C" fn video_encoder_src_event( + ptr: *mut gst_video_sys::GstVideoEncoder, + event: *mut gst_sys::GstEvent, +) -> glib_sys::gboolean +where + T: VideoEncoderImpl, + T::Instance: PanicPoison, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: VideoEncoder = from_glib_borrow(ptr); + + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + imp.src_event(&wrap, from_glib_full(event)) + }) + .to_glib() +} + +unsafe extern "C" fn video_encoder_src_query( + ptr: *mut gst_video_sys::GstVideoEncoder, + query: *mut gst_sys::GstQuery, +) -> glib_sys::gboolean +where + T: VideoEncoderImpl, + T::Instance: PanicPoison, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: VideoEncoder = from_glib_borrow(ptr); + + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + imp.src_query(&wrap, gst::QueryRef::from_mut_ptr(query)) + }) + .to_glib() +} + unsafe extern "C" fn video_encoder_propose_allocation( ptr: *mut gst_video_sys::GstVideoEncoder, query: *mut gst_sys::GstQuery,