diff --git a/gstreamer-base/src/subclass/aggregator.rs b/gstreamer-base/src/subclass/aggregator.rs index 352d23bbb..07223a8db 100644 --- a/gstreamer-base/src/subclass/aggregator.rs +++ b/gstreamer-base/src/subclass/aggregator.rs @@ -88,11 +88,11 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static { timeout: bool, ) -> Result; - fn start(&self, aggregator: &Aggregator) -> bool { + fn start(&self, aggregator: &Aggregator) -> Result<(), gst::ErrorMessage> { self.parent_start(aggregator) } - fn stop(&self, aggregator: &Aggregator) -> bool { + fn stop(&self, aggregator: &Aggregator) -> Result<(), gst::ErrorMessage> { self.parent_stop(aggregator) } @@ -287,25 +287,45 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static { } } - fn parent_start(&self, aggregator: &Aggregator) -> bool { + fn parent_start(&self, aggregator: &Aggregator) -> Result<(), gst::ErrorMessage> { unsafe { let data = self.get_type_data(); let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorClass; - (*parent_class) - .start - .map(|f| from_glib(f(aggregator.to_glib_none().0))) - .unwrap_or(false) + let f = (*parent_class).start.ok_or_else(|| { + gst_error_msg!( + gst::CoreError::Failed, + ["Parent function `start` is not defined"] + ) + })?; + if from_glib(f(aggregator.to_glib_none().0)) { + Ok(()) + } else { + Err(gst_error_msg!( + gst::CoreError::Failed, + ["Parent function `start` failed"] + )) + } } } - fn parent_stop(&self, aggregator: &Aggregator) -> bool { + fn parent_stop(&self, aggregator: &Aggregator) -> Result<(), gst::ErrorMessage> { unsafe { let data = self.get_type_data(); let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorClass; - (*parent_class) - .stop - .map(|f| from_glib(f(aggregator.to_glib_none().0))) - .unwrap_or(false) + let f = (*parent_class).stop.ok_or_else(|| { + gst_error_msg!( + gst::CoreError::Failed, + ["Parent function `stop` is not defined"] + ) + })?; + if from_glib(f(aggregator.to_glib_none().0)) { + Ok(()) + } else { + Err(gst_error_msg!( + gst::CoreError::Failed, + ["Parent function `stop` failed"] + )) + } } } @@ -635,7 +655,16 @@ where let imp = instance.get_impl(); let wrap: Aggregator = from_glib_borrow(ptr); - gst_panic_to_error!(&wrap, &instance.panicked(), false, { imp.start(&wrap) }).to_glib() + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + match imp.start(&wrap) { + Ok(()) => true, + Err(err) => { + wrap.post_error_message(&err); + false + } + } + }) + .to_glib() } unsafe extern "C" fn aggregator_stop( @@ -650,7 +679,16 @@ where let imp = instance.get_impl(); let wrap: Aggregator = from_glib_borrow(ptr); - gst_panic_to_error!(&wrap, &instance.panicked(), false, { imp.stop(&wrap) }).to_glib() + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + match imp.stop(&wrap) { + Ok(()) => true, + Err(err) => { + wrap.post_error_message(&err); + false + } + } + }) + .to_glib() } unsafe extern "C" fn aggregator_get_next_time( diff --git a/gstreamer-base/src/subclass/base_sink.rs b/gstreamer-base/src/subclass/base_sink.rs index acf6fafc5..ad60ddb36 100644 --- a/gstreamer-base/src/subclass/base_sink.rs +++ b/gstreamer-base/src/subclass/base_sink.rs @@ -23,12 +23,12 @@ use BaseSink; use BaseSinkClass; pub trait BaseSinkImpl: ElementImpl + Send + Sync + 'static { - fn start(&self, _element: &BaseSink) -> bool { - true + fn start(&self, _element: &BaseSink) -> Result<(), gst::ErrorMessage> { + Ok(()) } - fn stop(&self, _element: &BaseSink) -> bool { - true + fn stop(&self, _element: &BaseSink) -> Result<(), gst::ErrorMessage> { + Ok(()) } fn render( @@ -87,12 +87,12 @@ pub trait BaseSinkImpl: ElementImpl + Send + Sync + 'static { self.parent_fixate(element, caps) } - fn unlock(&self, _element: &BaseSink) -> bool { - true + fn unlock(&self, _element: &BaseSink) -> Result<(), gst::ErrorMessage> { + Ok(()) } - fn unlock_stop(&self, _element: &BaseSink) -> bool { - true + fn unlock_stop(&self, _element: &BaseSink) -> Result<(), gst::ErrorMessage> { + Ok(()) } fn parent_query(&self, element: &BaseSink, query: &mut gst::QueryRef) -> bool { @@ -207,7 +207,16 @@ where let imp = instance.get_impl(); let wrap: BaseSink = from_glib_borrow(ptr); - gst_panic_to_error!(&wrap, &instance.panicked(), false, { imp.start(&wrap) }).to_glib() + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + match imp.start(&wrap) { + Ok(()) => true, + Err(err) => { + wrap.post_error_message(&err); + false + } + } + }) + .to_glib() } unsafe extern "C" fn base_sink_stop( @@ -222,7 +231,16 @@ where let imp = instance.get_impl(); let wrap: BaseSink = from_glib_borrow(ptr); - gst_panic_to_error!(&wrap, &instance.panicked(), false, { imp.stop(&wrap) }).to_glib() + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + match imp.stop(&wrap) { + Ok(()) => true, + Err(err) => { + wrap.post_error_message(&err); + false + } + } + }) + .to_glib() } unsafe extern "C" fn base_sink_render( @@ -427,7 +445,16 @@ where let imp = instance.get_impl(); let wrap: BaseSink = from_glib_borrow(ptr); - gst_panic_to_error!(&wrap, &instance.panicked(), false, { imp.unlock(&wrap) }).to_glib() + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + match imp.unlock(&wrap) { + Ok(()) => true, + Err(err) => { + wrap.post_error_message(&err); + false + } + } + }) + .to_glib() } unsafe extern "C" fn base_sink_unlock_stop( @@ -443,7 +470,13 @@ where let wrap: BaseSink = from_glib_borrow(ptr); gst_panic_to_error!(&wrap, &instance.panicked(), false, { - imp.unlock_stop(&wrap) + match imp.unlock_stop(&wrap) { + Ok(()) => true, + Err(err) => { + wrap.post_error_message(&err); + false + } + } }) .to_glib() } diff --git a/gstreamer-base/src/subclass/base_src.rs b/gstreamer-base/src/subclass/base_src.rs index e2ff94d05..cf29864f6 100644 --- a/gstreamer-base/src/subclass/base_src.rs +++ b/gstreamer-base/src/subclass/base_src.rs @@ -23,12 +23,12 @@ use BaseSrc; use BaseSrcClass; pub trait BaseSrcImpl: ElementImpl + Send + Sync + 'static { - fn start(&self, _element: &BaseSrc) -> bool { - true + fn start(&self, _element: &BaseSrc) -> Result<(), gst::ErrorMessage> { + Ok(()) } - fn stop(&self, _element: &BaseSrc) -> bool { - true + fn stop(&self, _element: &BaseSrc) -> Result<(), gst::ErrorMessage> { + Ok(()) } fn is_seekable(&self, _element: &BaseSrc) -> bool { @@ -86,12 +86,12 @@ pub trait BaseSrcImpl: ElementImpl + Send + Sync + 'static { self.parent_fixate(element, caps) } - fn unlock(&self, _element: &BaseSrc) -> bool { - true + fn unlock(&self, _element: &BaseSrc) -> Result<(), gst::ErrorMessage> { + Ok(()) } - fn unlock_stop(&self, _element: &BaseSrc) -> bool { - true + fn unlock_stop(&self, _element: &BaseSrc) -> Result<(), gst::ErrorMessage> { + Ok(()) } fn parent_create( @@ -259,7 +259,16 @@ where let imp = instance.get_impl(); let wrap: BaseSrc = from_glib_borrow(ptr); - gst_panic_to_error!(&wrap, &instance.panicked(), false, { imp.start(&wrap) }).to_glib() + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + match imp.start(&wrap) { + Ok(()) => true, + Err(err) => { + wrap.post_error_message(&err); + false + } + } + }) + .to_glib() } unsafe extern "C" fn base_src_stop( @@ -274,7 +283,16 @@ where let imp = instance.get_impl(); let wrap: BaseSrc = from_glib_borrow(ptr); - gst_panic_to_error!(&wrap, &instance.panicked(), false, { imp.stop(&wrap) }).to_glib() + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + match imp.stop(&wrap) { + Ok(()) => true, + Err(err) => { + wrap.post_error_message(&err); + false + } + } + }) + .to_glib() } unsafe extern "C" fn base_src_is_seekable( @@ -537,7 +555,16 @@ where let imp = instance.get_impl(); let wrap: BaseSrc = from_glib_borrow(ptr); - gst_panic_to_error!(&wrap, &instance.panicked(), false, { imp.unlock(&wrap) }).to_glib() + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + match imp.unlock(&wrap) { + Ok(()) => true, + Err(err) => { + wrap.post_error_message(&err); + false + } + } + }) + .to_glib() } unsafe extern "C" fn base_src_unlock_stop( @@ -553,7 +580,13 @@ where let wrap: BaseSrc = from_glib_borrow(ptr); gst_panic_to_error!(&wrap, &instance.panicked(), false, { - imp.unlock_stop(&wrap) + match imp.unlock_stop(&wrap) { + Ok(()) => true, + Err(err) => { + wrap.post_error_message(&err); + false + } + } }) .to_glib() } diff --git a/gstreamer-base/src/subclass/base_transform.rs b/gstreamer-base/src/subclass/base_transform.rs index d4ba53570..c88038c2d 100644 --- a/gstreamer-base/src/subclass/base_transform.rs +++ b/gstreamer-base/src/subclass/base_transform.rs @@ -21,12 +21,12 @@ use BaseTransform; use BaseTransformClass; pub trait BaseTransformImpl: ElementImpl + Send + Sync + 'static { - fn start(&self, _element: &BaseTransform) -> bool { - true + fn start(&self, _element: &BaseTransform) -> Result<(), gst::ErrorMessage> { + Ok(()) } - fn stop(&self, _element: &BaseTransform) -> bool { - true + fn stop(&self, _element: &BaseTransform) -> Result<(), gst::ErrorMessage> { + Ok(()) } fn transform_caps( @@ -349,7 +349,16 @@ where let imp = instance.get_impl(); let wrap: BaseTransform = from_glib_borrow(ptr); - gst_panic_to_error!(&wrap, &instance.panicked(), false, { imp.start(&wrap) }).to_glib() + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + match imp.start(&wrap) { + Ok(()) => true, + Err(err) => { + wrap.post_error_message(&err); + false + } + } + }) + .to_glib() } unsafe extern "C" fn base_transform_stop( @@ -364,7 +373,16 @@ where let imp = instance.get_impl(); let wrap: BaseTransform = from_glib_borrow(ptr); - gst_panic_to_error!(&wrap, &instance.panicked(), false, { imp.stop(&wrap) }).to_glib() + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + match imp.stop(&wrap) { + Ok(()) => true, + Err(err) => { + wrap.post_error_message(&err); + false + } + } + }) + .to_glib() } unsafe extern "C" fn base_transform_transform_caps(