gstreamer-base: update signatures to Result<(), LoggableError>

See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/175
This commit is contained in:
François Laignel 2019-01-26 14:54:48 +01:00 committed by Sebastian Dröge
parent 2b2c3bbade
commit 5d1a839558
3 changed files with 119 additions and 41 deletions

View file

@ -73,7 +73,12 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static {
self.parent_src_query(aggregator, query) self.parent_src_query(aggregator, query)
} }
fn src_activate(&self, aggregator: &Aggregator, mode: gst::PadMode, active: bool) -> bool { fn src_activate(
&self,
aggregator: &Aggregator,
mode: gst::PadMode,
active: bool,
) -> Result<(), gst::LoggableError> {
self.parent_src_activate(aggregator, mode, active) self.parent_src_activate(aggregator, mode, active)
} }
@ -117,7 +122,11 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static {
self.parent_fixate_src_caps(aggregator, caps) self.parent_fixate_src_caps(aggregator, caps)
} }
fn negotiated_src_caps(&self, aggregator: &Aggregator, caps: &gst::CapsRef) -> bool { fn negotiated_src_caps(
&self,
aggregator: &Aggregator,
caps: &gst::CapsRef,
) -> Result<(), gst::LoggableError> {
self.parent_negotiated_src_caps(aggregator, caps) self.parent_negotiated_src_caps(aggregator, caps)
} }
@ -240,20 +249,25 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static {
aggregator: &Aggregator, aggregator: &Aggregator,
mode: gst::PadMode, mode: gst::PadMode,
active: bool, active: bool,
) -> bool { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = self.get_type_data(); let data = self.get_type_data();
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorClass;
(*parent_class) let f = (*parent_class).src_activate.ok_or_else(|| {
.src_activate gst_loggable_error!(
.map(|f| { gst::CAT_RUST,
from_glib(f( "Parent function `src_activate` is not defined"
)
})?;
gst_result_from_gboolean!(
f(
aggregator.to_glib_none().0, aggregator.to_glib_none().0,
mode.to_glib(), mode.to_glib(),
active.to_glib(), active.to_glib()
)) ),
}) gst::CAT_RUST,
.unwrap_or(false) "Parent function `src_activate` failed"
)
} }
} }
@ -365,14 +379,25 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static {
} }
} }
fn parent_negotiated_src_caps(&self, aggregator: &Aggregator, caps: &gst::CapsRef) -> bool { fn parent_negotiated_src_caps(
&self,
aggregator: &Aggregator,
caps: &gst::CapsRef,
) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = self.get_type_data(); let data = self.get_type_data();
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorClass;
(*parent_class) let f = (*parent_class).negotiated_src_caps.ok_or_else(|| {
.negotiated_src_caps gst_loggable_error!(
.map(|f| from_glib(f(aggregator.to_glib_none().0, caps.as_mut_ptr()))) gst::CAT_RUST,
.unwrap_or(false) "Parent function `negotiated_src_caps` is not defined"
)
})?;
gst_result_from_gboolean!(
f(aggregator.to_glib_none().0, caps.as_mut_ptr()),
gst::CAT_RUST,
"Parent function `negotiated_src_caps` failed"
)
} }
} }
} }
@ -568,7 +593,13 @@ where
let wrap: Aggregator = from_glib_borrow(ptr); let wrap: Aggregator = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.src_activate(&wrap, from_glib(mode), from_glib(active)) match imp.src_activate(&wrap, from_glib(mode), from_glib(active)) {
Ok(()) => true,
Err(err) => {
err.log_with_object(&wrap);
false
}
}
}) })
.to_glib() .to_glib()
} }
@ -743,7 +774,13 @@ where
let wrap: Aggregator = from_glib_borrow(ptr); let wrap: Aggregator = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.negotiated_src_caps(&wrap, gst::CapsRef::from_ptr(caps)) match imp.negotiated_src_caps(&wrap, gst::CapsRef::from_ptr(caps)) {
Ok(()) => true,
Err(err) => {
err.log_with_object(&wrap);
false
}
}
}) })
.to_glib() .to_glib()
} }

View file

@ -79,7 +79,7 @@ pub trait BaseSinkImpl: ElementImpl + Send + Sync + 'static {
self.parent_get_caps(element, filter) self.parent_get_caps(element, filter)
} }
fn set_caps(&self, element: &BaseSink, caps: &gst::CapsRef) -> bool { fn set_caps(&self, element: &BaseSink, caps: &gst::CapsRef) -> Result<(), gst::LoggableError> {
self.parent_set_caps(element, caps) self.parent_set_caps(element, caps)
} }
@ -138,14 +138,22 @@ pub trait BaseSinkImpl: ElementImpl + Send + Sync + 'static {
} }
} }
fn parent_set_caps(&self, element: &BaseSink, caps: &gst::CapsRef) -> bool { fn parent_set_caps(
&self,
element: &BaseSink,
caps: &gst::CapsRef,
) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = self.get_type_data(); let data = self.get_type_data();
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBaseSinkClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBaseSinkClass;
(*parent_class) let f = (*parent_class).set_caps.ok_or_else(|| {
.set_caps gst_loggable_error!(gst::CAT_RUST, "Parent function `set_caps` is not defined")
.map(|f| from_glib(f(element.to_glib_none().0, caps.as_mut_ptr()))) })?;
.unwrap_or(true) gst_result_from_gboolean!(
f(element.to_glib_none().0, caps.as_mut_ptr()),
gst::CAT_RUST,
"Parent function `set_caps` failed"
)
} }
} }
@ -376,7 +384,13 @@ where
let caps = gst::CapsRef::from_ptr(caps); let caps = gst::CapsRef::from_ptr(caps);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.set_caps(&wrap, caps) match imp.set_caps(&wrap, caps) {
Ok(()) => true,
Err(err) => {
err.log_with_object(&wrap);
false
}
}
}) })
.to_glib() .to_glib()
} }

View file

@ -74,11 +74,11 @@ pub trait BaseSrcImpl: ElementImpl + Send + Sync + 'static {
self.parent_get_caps(element, filter) self.parent_get_caps(element, filter)
} }
fn negotiate(&self, element: &BaseSrc) -> bool { fn negotiate(&self, element: &BaseSrc) -> Result<(), gst::LoggableError> {
self.parent_negotiate(element) self.parent_negotiate(element)
} }
fn set_caps(&self, element: &BaseSrc, caps: &gst::CapsRef) -> bool { fn set_caps(&self, element: &BaseSrc, caps: &gst::CapsRef) -> Result<(), gst::LoggableError> {
self.parent_set_caps(element, caps) self.parent_set_caps(element, caps)
} }
@ -173,25 +173,37 @@ pub trait BaseSrcImpl: ElementImpl + Send + Sync + 'static {
} }
} }
fn parent_negotiate(&self, element: &BaseSrc) -> bool { fn parent_negotiate(&self, element: &BaseSrc) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = self.get_type_data(); let data = self.get_type_data();
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBaseSrcClass;
(*parent_class) let f = (*parent_class).negotiate.ok_or_else(|| {
.negotiate gst_loggable_error!(gst::CAT_RUST, "Parent function `negotiate` is not defined")
.map(|f| from_glib(f(element.to_glib_none().0))) })?;
.unwrap_or(false) gst_result_from_gboolean!(
f(element.to_glib_none().0),
gst::CAT_RUST,
"Parent function `negotiate` failed"
)
} }
} }
fn parent_set_caps(&self, element: &BaseSrc, caps: &gst::CapsRef) -> bool { fn parent_set_caps(
&self,
element: &BaseSrc,
caps: &gst::CapsRef,
) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = self.get_type_data(); let data = self.get_type_data();
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBaseSrcClass;
(*parent_class) let f = (*parent_class).set_caps.ok_or_else(|| {
.set_caps gst_loggable_error!(gst::CAT_RUST, "Parent function `set_caps` is not defined")
.map(|f| from_glib(f(element.to_glib_none().0, caps.as_mut_ptr()))) })?;
.unwrap_or(true) gst_result_from_gboolean!(
f(element.to_glib_none().0, caps.as_mut_ptr()),
gst::CAT_RUST,
"Parent function `set_caps` failed"
)
} }
} }
@ -455,7 +467,16 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: BaseSrc = from_glib_borrow(ptr); let wrap: BaseSrc = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { imp.negotiate(&wrap) }).to_glib() 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 base_src_set_caps<T: ObjectSubclass>( unsafe extern "C" fn base_src_set_caps<T: ObjectSubclass>(
@ -473,7 +494,13 @@ where
let caps = gst::CapsRef::from_ptr(caps); let caps = gst::CapsRef::from_ptr(caps);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.set_caps(&wrap, caps) match imp.set_caps(&wrap, caps) {
Ok(()) => true,
Err(err) => {
err.log_with_object(&wrap);
false
}
}
}) })
.to_glib() .to_glib()
} }