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