diff --git a/gstreamer/src/error.rs b/gstreamer/src/error.rs index 91928149d..9201b5033 100644 --- a/gstreamer/src/error.rs +++ b/gstreamer/src/error.rs @@ -145,6 +145,19 @@ impl LoggableError { ); } + pub fn log_with_imp(&self, imp: &I) { + use glib::subclass::prelude::*; + + self.category.log( + Some(unsafe { imp.instance().unsafe_cast_ref::() }), + crate::DebugLevel::Error, + self.bool_error.filename, + self.bool_error.function, + self.bool_error.line, + format_args!("{}", self.bool_error.message), + ); + } + pub fn category(&self) -> crate::DebugCategory { self.category } diff --git a/gstreamer/src/log.rs b/gstreamer/src/log.rs index 05d36271c..75f0dafc7 100644 --- a/gstreamer/src/log.rs +++ b/gstreamer/src/log.rs @@ -176,7 +176,7 @@ impl DebugCategory { } let obj_ptr = match obj { - Some(obj) => obj.to_glib_none().0 as *mut glib::gobject_ffi::GObject, + Some(obj) => obj.as_ptr() as *mut glib::gobject_ffi::GObject, None => ptr::null_mut(), }; @@ -386,6 +386,9 @@ macro_rules! error( ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Error, obj: $obj, $($args)*) }}; + ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Error, imp: $imp, $($args)*) + }}; ($cat:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Error, $($args)*) }}; @@ -396,6 +399,9 @@ macro_rules! warning( ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Warning, obj: $obj, $($args)*) }}; + ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Warning, imp: $imp, $($args)*) + }}; ($cat:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Warning, $($args)*) }}; @@ -406,6 +412,9 @@ macro_rules! fixme( ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Fixme, obj: $obj, $($args)*) }}; + ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Fixme, imp: $imp, $($args)*) + }}; ($cat:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Fixme, $($args)*) }}; @@ -416,6 +425,9 @@ macro_rules! info( ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Info, obj: $obj, $($args)*) }}; + ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Info, imp: $imp, $($args)*) + }}; ($cat:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Info, $($args)*) }}; @@ -426,6 +438,9 @@ macro_rules! debug( ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Debug, obj: $obj, $($args)*) }}; + ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Debug, imp: $imp, $($args)*) + }}; ($cat:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Debug, $($args)*) }}; @@ -436,6 +451,9 @@ macro_rules! log( ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Log, obj: $obj, $($args)*) }}; + ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Log, imp: $imp, $($args)*) + }}; ($cat:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Log, $($args)*) }}; @@ -446,6 +464,9 @@ macro_rules! trace( ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Trace, obj: $obj, $($args)*) }}; + ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Trace, imp: $imp, $($args)*) + }}; ($cat:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Trace, $($args)*) }}; @@ -456,6 +477,9 @@ macro_rules! memdump( ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Memdump, obj: $obj, $($args)*) }}; + ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Memdump, imp: $imp, $($args)*) + }}; ($cat:expr, $($args:tt)*) => { { $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Memdump, $($args)*) }}; @@ -471,6 +495,18 @@ macro_rules! log_with_level( $level, file!(), module_path!(), line!(), format_args!($($args)*)) } }}; + ($cat:expr, level: $level:expr, imp: $imp:expr, $($args:tt)*) => { { + // Check the log level before using `format_args!` otherwise + // formatted arguments are evaluated even if we end up not logging. + if $level <= $cat.threshold() { + use $crate::glib::Cast; + + let obj = $imp.instance(); + let obj = unsafe { obj.unsafe_cast_ref::<$crate::glib::Object>() }; + $crate::DebugCategory::log_unfiltered($cat.clone(), Some(&*obj), + $level, file!(), module_path!(), line!(), format_args!($($args)*)) + } + }}; ($cat:expr, level: $level:expr, $($args:tt)*) => { { // Check the log level before using `format_args!` otherwise // formatted arguments are evaluated even if we end up not logging. diff --git a/gstreamer/src/subclass/element.rs b/gstreamer/src/subclass/element.rs index c6df35efa..6880d5e28 100644 --- a/gstreamer/src/subclass/element.rs +++ b/gstreamer/src/subclass/element.rs @@ -173,6 +173,8 @@ pub trait ElementImplExt: ObjectSubclass { fallback: G, f: F, ) -> R; + + fn post_error_message(&self, msg: crate::ErrorMessage); } impl ElementImplExt for T { @@ -371,6 +373,14 @@ impl ElementImplExt for T { }) } } + + fn post_error_message(&self, msg: crate::ErrorMessage) { + unsafe { + self.instance() + .unsafe_cast_ref::() + .post_error_message(msg) + } + } } unsafe impl IsSubclassable for Element {