gstreamer: Add an gst::element_error! variant that works on element implementations

This commit is contained in:
Sebastian Dröge 2022-10-09 14:18:18 +03:00
parent 7bd4d770ff
commit a4d901ee63
2 changed files with 243 additions and 8 deletions

View file

@ -156,19 +156,17 @@ mod fir_filter {
&self,
buf: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError> {
let element = self.instance();
// Get coefficients and return directly if we have none
let coeffs = self.coeffs.lock().unwrap();
if coeffs.is_empty() {
gst::trace!(CAT, obj: element, "No coefficients set -- passthrough");
gst::trace!(CAT, imp: self, "No coefficients set -- passthrough");
return Ok(gst::FlowSuccess::Ok);
}
// Try mapping the input buffer as writable
let mut data = buf.map_writable().map_err(|_| {
gst::element_error!(
element,
gst::element_imp_error!(
self,
gst::CoreError::Failed,
["Failed to map input buffer readable"]
);
@ -177,8 +175,8 @@ mod fir_filter {
// And reinterprete it as a slice of f32
let samples = data.as_mut_slice_of::<f32>().map_err(|err| {
gst::element_error!(
element,
gst::element_imp_error!(
self,
gst::CoreError::Failed,
["Failed to cast input buffer as f32 slice: {}", err]
);
@ -189,7 +187,7 @@ mod fir_filter {
gst::trace!(
CAT,
obj: element,
imp: self,
"Transforming {} samples with filter of length {}",
samples.len(),
coeffs.len()

View file

@ -1347,6 +1347,243 @@ macro_rules! element_info(
}};
);
#[doc(alias = "GST_ELEMENT_ERROR")]
#[doc(alias = "GST_ELEMENT_ERROR_WITH_DETAILS")]
#[macro_export]
macro_rules! element_imp_error(
($imp:expr, $err:expr, ($msg:expr), [$debug:expr]) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_error!(obj, $err, ($msg), [$debug]);
}};
($imp:expr, $err:expr, ($msg:expr)) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_error!(obj, $err, ($msg));
}};
($imp:expr, $err:expr, [$debug:expr]) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_error!(obj, $err, [$debug]);
}};
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_error!(obj, $err, ($($msg)*), [$($debug)*]);
}};
($imp:expr, $err:expr, ($($msg:tt)*)) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_error!(obj, $err, ($($msg)*));
}};
($imp:expr, $err:expr, [$($debug:tt)*]) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_error!(obj, $err, [$($debug)*]);
}};
($imp:expr, $err:expr, ($msg:expr), [$debug:expr], details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_error!(obj, $err, ($msg), [$debug], details: $details);
}};
($imp:expr, $err:expr, ($msg:expr), details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_error!(obj, $err, ($msg), details: $details);
}};
($imp:expr, $err:expr, [$debug:expr], details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_error!(obj, $err, [$debug], details: $details);
}};
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_error!(obj, $err, ($($msg)*), [$($debug)*], details: $details);
}};
($imp:expr, $err:expr, ($($msg:tt)*), details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_error!(obj, $err, ($($msg)*), details: $details);
}};
($imp:expr, $err:expr, [$($debug:tt)*], details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_error!(obj, $err, [$($debug)*], details: $details);
}};
);
#[doc(alias = "GST_ELEMENT_WARNING")]
#[doc(alias = "GST_ELEMENT_WARNING_WITH_DETAILS")]
#[macro_export]
macro_rules! element_imp_warning(
($imp:expr, $err:expr, ($msg:expr), [$debug:expr]) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_warning!(obj, $err, ($msg), [$debug]);
}};
($imp:expr, $err:expr, ($msg:expr)) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_warning!(obj, $err, ($msg));
}};
($imp:expr, $err:expr, [$debug:expr]) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_warning!(obj, $err, [$debug]);
}};
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_warning!(obj, $err, ($($msg)*), [$($debug)*]);
}};
($imp:expr, $err:expr, ($($msg:tt)*)) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_warning!(obj, $err, ($($msg)*));
}};
($imp:expr, $err:expr, [$($debug:tt)*]) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_warning!(obj, $err, [$($debug)*]);
}};
($imp:expr, $err:expr, ($msg:expr), [$debug:expr], details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_warning!(obj, $err, ($msg), [$debug], details: $details);
}};
($imp:expr, $err:expr, ($msg:expr), details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_warning!(obj, $err, ($msg), details: $details);
}};
($imp:expr, $err:expr, [$debug:expr], details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_warning!(obj, $err, [$debug], details: $details);
}};
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_warning!(obj, $err, ($($msg)*), [$($debug)*], details: $details);
}};
($imp:expr, $err:expr, ($($msg:tt)*), details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_warning!(obj, $err, ($($msg)*), details: $details);
}};
($imp:expr, $err:expr, [$($debug:tt)*], details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_warning!(obj, $err, [$($debug)*], details: $details);
}};
);
#[doc(alias = "GST_ELEMENT_INFO")]
#[doc(alias = "GST_ELEMENT_INFO_WITH_DETAILS")]
#[macro_export]
macro_rules! element_imp_info(
($imp:expr, $err:expr, ($msg:expr), [$debug:expr]) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_info!(obj, $err, ($msg), [$debug]);
}};
($imp:expr, $err:expr, ($msg:expr)) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_info!(obj, $err, ($msg));
}};
($imp:expr, $err:expr, [$debug:expr]) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_info!(obj, $err, [$debug]);
}};
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_info!(obj, $err, ($($msg)*), [$($debug)*]);
}};
($imp:expr, $err:expr, ($($msg:tt)*)) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_info!(obj, $err, ($($msg)*));
}};
($imp:expr, $err:expr, [$($debug:tt)*]) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_info!(obj, $err, [$($debug)*]);
}};
($imp:expr, $err:expr, ($msg:expr), [$debug:expr], details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_info!(obj, $err, ($msg), [$debug], details: $details);
}};
($imp:expr, $err:expr, ($msg:expr), details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_info!(obj, $err, ($msg), details: $details);
}};
($imp:expr, $err:expr, [$debug:expr], details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_info!(obj, $err, [$debug], details: $details);
}};
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_info!(obj, $err, ($($msg)*), [$($debug)*], details: $details);
}};
($imp:expr, $err:expr, ($($msg:tt)*), details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_info!(obj, $err, ($($msg)*), details: $details);
}};
($imp:expr, $err:expr, [$($debug:tt)*], details: $details:expr) => { {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = obj.dynamic_cast_ref::<$crate::Element>().unwrap();
$crate::element_info!(obj, $err, [$($debug)*], details: $details);
}};
);
#[cfg(test)]
mod tests {
use super::*;