diff --git a/gstreamer-video/src/subclass/video_decoder.rs b/gstreamer-video/src/subclass/video_decoder.rs index 2547d44c1..057d2d464 100644 --- a/gstreamer-video/src/subclass/video_decoder.rs +++ b/gstreamer-video/src/subclass/video_decoder.rs @@ -41,6 +41,10 @@ pub trait VideoDecoderImpl: VideoDecoderImplExt + ElementImpl + Send + Sync + 's self.parent_stop(element) } + fn finish(&self, element: &VideoDecoder) -> Result { + self.parent_finish(element) + } + fn set_format( &self, element: &VideoDecoder, @@ -97,6 +101,8 @@ pub trait VideoDecoderImplExt { fn parent_stop(&self, element: &VideoDecoder) -> Result<(), gst::ErrorMessage>; + fn parent_finish(&self, element: &VideoDecoder) -> Result; + fn parent_set_format( &self, element: &VideoDecoder, @@ -217,6 +223,19 @@ impl VideoDecoderImplExt for T { } } + fn parent_finish(&self, element: &VideoDecoder) -> Result { + unsafe { + let data = self.get_type_data(); + let parent_class = + data.as_ref().get_parent_class() as *mut gst_video_sys::GstVideoDecoderClass; + (*parent_class) + .finish + .map(|f| gst::FlowReturn::from_glib(f(element.to_glib_none().0))) + .unwrap_or(gst::FlowReturn::Ok) + .into_result() + } + } + fn parent_set_format( &self, element: &VideoDecoder, @@ -359,6 +378,7 @@ where klass.close = Some(video_decoder_close::); klass.start = Some(video_decoder_start::); klass.stop = Some(video_decoder_stop::); + klass.finish = Some(video_decoder_finish::); klass.set_format = Some(video_decoder_set_format::); klass.parse = Some(video_decoder_parse::); klass.handle_frame = Some(video_decoder_handle_frame::); @@ -465,6 +485,24 @@ where .to_glib() } +unsafe extern "C" fn video_decoder_finish( + ptr: *mut gst_video_sys::GstVideoDecoder, +) -> gst_sys::GstFlowReturn +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(), gst::FlowReturn::Error, { + imp.finish(&wrap).into() + }) + .to_glib() +} + unsafe extern "C" fn video_decoder_set_format( ptr: *mut gst_video_sys::GstVideoDecoder, state: *mut gst_video_sys::GstVideoCodecState, diff --git a/gstreamer-video/src/subclass/video_encoder.rs b/gstreamer-video/src/subclass/video_encoder.rs index 55ce3cec1..ff9165c9c 100644 --- a/gstreamer-video/src/subclass/video_encoder.rs +++ b/gstreamer-video/src/subclass/video_encoder.rs @@ -40,6 +40,10 @@ pub trait VideoEncoderImpl: VideoEncoderImplExt + ElementImpl + Send + Sync + 's self.parent_stop(element) } + fn finish(&self, element: &VideoEncoder) -> Result { + self.parent_finish(element) + } + fn set_format( &self, element: &VideoEncoder, @@ -86,6 +90,8 @@ pub trait VideoEncoderImplExt { fn parent_stop(&self, element: &VideoEncoder) -> Result<(), gst::ErrorMessage>; + fn parent_finish(&self, element: &VideoEncoder) -> Result; + fn parent_set_format( &self, element: &VideoEncoder, @@ -198,6 +204,19 @@ impl VideoEncoderImplExt for T { } } + fn parent_finish(&self, element: &VideoEncoder) -> Result { + unsafe { + let data = self.get_type_data(); + let parent_class = + data.as_ref().get_parent_class() as *mut gst_video_sys::GstVideoEncoderClass; + (*parent_class) + .finish + .map(|f| gst::FlowReturn::from_glib(f(element.to_glib_none().0))) + .unwrap_or(gst::FlowReturn::Ok) + .into_result() + } + } + fn parent_set_format( &self, element: &VideoEncoder, @@ -314,6 +333,7 @@ where klass.close = Some(video_encoder_close::); klass.start = Some(video_encoder_start::); klass.stop = Some(video_encoder_stop::); + klass.finish = Some(video_encoder_finish::); klass.set_format = Some(video_encoder_set_format::); klass.handle_frame = Some(video_encoder_handle_frame::); klass.flush = Some(video_encoder_flush::); @@ -419,6 +439,24 @@ where .to_glib() } +unsafe extern "C" fn video_encoder_finish( + ptr: *mut gst_video_sys::GstVideoEncoder, +) -> gst_sys::GstFlowReturn +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(), gst::FlowReturn::Error, { + imp.finish(&wrap).into() + }) + .to_glib() +} + unsafe extern "C" fn video_encoder_set_format( ptr: *mut gst_video_sys::GstVideoEncoder, state: *mut gst_video_sys::GstVideoCodecState,