diff --git a/examples/src/bin/fd_allocator.rs b/examples/src/bin/fd_allocator.rs index 76df9c2b0..b627186e6 100644 --- a/examples/src/bin/fd_allocator.rs +++ b/examples/src/bin/fd_allocator.rs @@ -459,7 +459,7 @@ mod video_filter { frame: &mut VideoFrameRef<&mut gst::BufferRef>, ) -> Result { self.transform_fd_mem_ip(frame).map_err(|err| { - gst::error!(CAT, imp: self, "Failed to transform frame`: {}", err); + gst::error!(CAT, imp = self, "Failed to transform frame`: {}", err); gst::FlowError::Error })?; diff --git a/examples/src/bin/glfilter.rs b/examples/src/bin/glfilter.rs index 08f8fdd7d..a2534def2 100644 --- a/examples/src/bin/glfilter.rs +++ b/examples/src/bin/glfilter.rs @@ -80,7 +80,7 @@ mod mirror { gst::debug!( CAT, - imp: self, + imp = self, "Compiling fragment shader {}", FRAGMENT_SHADER ); @@ -99,7 +99,7 @@ mod mirror { gst::debug!( CAT, - imp: self, + imp = self, "Successfully compiled and linked {:?}", shader ); diff --git a/examples/src/bin/subclass.rs b/examples/src/bin/subclass.rs index bf00e35ea..a5cb0ab5d 100644 --- a/examples/src/bin/subclass.rs +++ b/examples/src/bin/subclass.rs @@ -142,7 +142,7 @@ mod fir_filter { // Drop state self.history.lock().unwrap().clear(); - gst::info!(CAT, imp: self, "Stopped"); + gst::info!(CAT, imp = self, "Stopped"); Ok(()) } @@ -155,7 +155,7 @@ mod fir_filter { // Get coefficients and return directly if we have none let coeffs = self.coeffs.lock().unwrap(); if coeffs.is_empty() { - gst::trace!(CAT, imp: self, "No coefficients set -- passthrough"); + gst::trace!(CAT, imp = self, "No coefficients set -- passthrough"); return Ok(gst::FlowSuccess::Ok); } @@ -183,7 +183,7 @@ mod fir_filter { gst::trace!( CAT, - imp: self, + imp = self, "Transforming {} samples with filter of length {}", samples.len(), coeffs.len() diff --git a/examples/src/bin/subclass_vfuncs/iirfilter/imp.rs b/examples/src/bin/subclass_vfuncs/iirfilter/imp.rs index 5c6f4dcd6..b078db8e3 100644 --- a/examples/src/bin/subclass_vfuncs/iirfilter/imp.rs +++ b/examples/src/bin/subclass_vfuncs/iirfilter/imp.rs @@ -116,7 +116,7 @@ impl BaseTransformImpl for IirFilter { } let mut map = buf.map_writable().map_err(|_| { - gst::error!(CAT, imp: self, "Failed to map buffer writable"); + gst::error!(CAT, imp = self, "Failed to map buffer writable"); gst::FlowError::Error })?; @@ -166,7 +166,7 @@ impl AudioFilterImpl for IirFilter { fn setup(&self, info: &gst_audio::AudioInfo) -> Result<(), gst::LoggableError> { self.parent_setup(info)?; - gst::debug!(CAT, imp: self, "Rate changed to {}", info.rate()); + gst::debug!(CAT, imp = self, "Rate changed to {}", info.rate()); let obj = self.obj(); (obj.class().as_ref().set_rate)(&obj, info.rate()); @@ -177,7 +177,7 @@ impl AudioFilterImpl for IirFilter { /// Wrappers for public methods and associated helper functions. impl IirFilter { pub(super) fn set_coeffs(&self, a: Vec, b: Vec) { - gst::debug!(CAT, imp: self, "Setting coefficients a: {a:?}, b: {b:?}"); + gst::debug!(CAT, imp = self, "Setting coefficients a: {a:?}, b: {b:?}"); *self.coeffs.lock().unwrap() = Some((a, b)); } } diff --git a/gstreamer-base/src/subclass/base_src.rs b/gstreamer-base/src/subclass/base_src.rs index efcc39450..2dc95846d 100644 --- a/gstreamer-base/src/subclass/base_src.rs +++ b/gstreamer-base/src/subclass/base_src.rs @@ -308,7 +308,7 @@ pub trait BaseSrcImplExt: sealed::Sealed + ObjectSubclass { if buffer_ptr.is_null() && pending_buffer_list.is_none() { gst::error!( gst::CAT_RUST, - obj: instance, + obj = instance, "No buffer and no buffer list returned" ); return Err(gst::FlowError::Error); @@ -317,7 +317,7 @@ pub trait BaseSrcImplExt: sealed::Sealed + ObjectSubclass { if !buffer_ptr.is_null() && pending_buffer_list.is_some() { gst::error!( gst::CAT_RUST, - obj: instance, + obj = instance, "Both buffer and buffer list returned" ); return Err(gst::FlowError::Error); @@ -329,7 +329,7 @@ pub trait BaseSrcImplExt: sealed::Sealed + ObjectSubclass { gst::debug!( gst::CAT_PERFORMANCE, - obj: instance, + obj = instance, "Returned new buffer from parent create function, copying into passed buffer" ); @@ -338,7 +338,7 @@ pub trait BaseSrcImplExt: sealed::Sealed + ObjectSubclass { Err(_) => { gst::error!( gst::CAT_RUST, - obj: instance, + obj = instance, "Failed to map passed buffer writable" ); return Err(gst::FlowError::Error); @@ -357,7 +357,7 @@ pub trait BaseSrcImplExt: sealed::Sealed + ObjectSubclass { Err(_) => { gst::error!( gst::CAT_RUST, - obj: instance, + obj = instance, "Failed to copy buffer metadata" ); @@ -752,7 +752,7 @@ unsafe extern "C" fn base_src_create( if passed_buffer.as_ptr() != new_buffer.as_ptr() { gst::debug!( gst::CAT_PERFORMANCE, - obj: instance, + obj = instance, "Returned new buffer from create function, copying into passed buffer" ); @@ -761,7 +761,7 @@ unsafe extern "C" fn base_src_create( Err(_) => { gst::error!( gst::CAT_RUST, - obj: instance, + obj = instance, "Failed to map passed buffer writable" ); return gst::FlowReturn::Error; @@ -780,7 +780,7 @@ unsafe extern "C" fn base_src_create( Err(_) => { gst::error!( gst::CAT_RUST, - obj: instance, + obj = instance, "Failed to copy buffer metadata" ); diff --git a/gstreamer-base/src/subclass/base_transform.rs b/gstreamer-base/src/subclass/base_transform.rs index 23f07b957..7d3ea8fb0 100644 --- a/gstreamer-base/src/subclass/base_transform.rs +++ b/gstreamer-base/src/subclass/base_transform.rs @@ -1215,7 +1215,7 @@ unsafe extern "C" fn base_transform_copy_metadata( if gst::ffi::gst_mini_object_is_writable(outbuf as *mut _) == glib::ffi::GFALSE { let instance = imp.obj(); let obj = instance.unsafe_cast_ref::(); - gst::warning!(gst::CAT_RUST, obj: obj, "buffer {:?} not writable", outbuf); + gst::warning!(gst::CAT_RUST, obj = obj, "buffer {:?} not writable", outbuf); return glib::ffi::GFALSE; } diff --git a/gstreamer-base/src/subclass/push_src.rs b/gstreamer-base/src/subclass/push_src.rs index 6a7c15d5c..81bc19643 100644 --- a/gstreamer-base/src/subclass/push_src.rs +++ b/gstreamer-base/src/subclass/push_src.rs @@ -110,7 +110,7 @@ pub trait PushSrcImplExt: sealed::Sealed + ObjectSubclass { if buffer_ptr.is_null() && pending_buffer_list.is_none() { gst::error!( gst::CAT_RUST, - obj: instance, + obj = instance, "No buffer and no buffer list returned" ); return Err(gst::FlowError::Error); @@ -119,7 +119,7 @@ pub trait PushSrcImplExt: sealed::Sealed + ObjectSubclass { if !buffer_ptr.is_null() && pending_buffer_list.is_some() { gst::error!( gst::CAT_RUST, - obj: instance, + obj = instance, "Both buffer and buffer list returned" ); return Err(gst::FlowError::Error); @@ -131,7 +131,7 @@ pub trait PushSrcImplExt: sealed::Sealed + ObjectSubclass { gst::debug!( gst::CAT_PERFORMANCE, - obj: instance, + obj = instance, "Returned new buffer from parent create function, copying into passed buffer" ); @@ -140,7 +140,7 @@ pub trait PushSrcImplExt: sealed::Sealed + ObjectSubclass { Err(_) => { gst::error!( gst::CAT_RUST, - obj: instance, + obj = instance, "Failed to map passed buffer writable" ); return Err(gst::FlowError::Error); @@ -159,7 +159,7 @@ pub trait PushSrcImplExt: sealed::Sealed + ObjectSubclass { Err(_) => { gst::error!( gst::CAT_RUST, - obj: instance, + obj = instance, "Failed to copy buffer metadata" ); @@ -259,7 +259,7 @@ unsafe extern "C" fn push_src_create( if passed_buffer.as_ptr() != new_buffer.as_ptr() { gst::debug!( gst::CAT_PERFORMANCE, - imp: imp, + imp = imp, "Returned new buffer from create function, copying into passed buffer" ); @@ -268,7 +268,7 @@ unsafe extern "C" fn push_src_create( Err(_) => { gst::error!( gst::CAT_RUST, - imp: imp, + imp = imp, "Failed to map passed buffer writable" ); return gst::FlowReturn::Error; @@ -287,7 +287,7 @@ unsafe extern "C" fn push_src_create( Err(_) => { gst::error!( gst::CAT_RUST, - imp: imp, + imp = imp, "Failed to copy buffer metadata" ); diff --git a/gstreamer-utils/src/streamproducer.rs b/gstreamer-utils/src/streamproducer.rs index 2df8f718d..452779840 100644 --- a/gstreamer-utils/src/streamproducer.rs +++ b/gstreamer-utils/src/streamproducer.rs @@ -181,11 +181,23 @@ impl StreamProducer { ) -> Result<(), AddConsumerError> { let mut consumers = self.consumers.lock().unwrap(); if consumers.consumers.contains_key(consumer) { - gst::error!(CAT, obj: &self.appsink, "Consumer {} ({:?}) already added", consumer.name(), consumer); + gst::error!( + CAT, + obj = &self.appsink, + "Consumer {} ({:?}) already added", + consumer.name(), + consumer + ); return Err(AddConsumerError::AlreadyAdded); } - gst::debug!(CAT, obj: &self.appsink, "Adding consumer {} ({:?})", consumer.name(), consumer); + gst::debug!( + CAT, + obj = &self.appsink, + "Adding consumer {} ({:?})", + consumer.name(), + consumer + ); Self::configure_consumer(consumer); @@ -205,7 +217,7 @@ impl StreamProducer { }; if gst_video::UpstreamForceKeyUnitEvent::parse(event).is_ok() { - gst::debug!(CAT, obj: &appsink, "Requesting keyframe"); + gst::debug!(CAT, obj = &appsink, "Requesting keyframe"); // Do not use `gst_element_send_event()` as it takes the state lock which may lead to dead locks. let pad = appsink.static_pad("sink").unwrap(); let _ = pad.push_event(event.clone()); @@ -232,7 +244,7 @@ impl StreamProducer { let appsink_pad = self.appsink.static_pad("sink").unwrap(); appsink_pad.sticky_events_foreach(|event| { if events_to_forward.contains(&event.type_()) { - gst::debug!(CAT, obj: &self.appsink, "forward sticky event {:?}", event); + gst::debug!(CAT, obj = &self.appsink, "forward sticky event {:?}", event); consumer.send_event(event.clone()); } @@ -258,7 +270,12 @@ impl StreamProducer { (false, true) }; - gst::trace!(CAT, obj: appsink, "processing sample {:?}", sample.buffer()); + gst::trace!( + CAT, + obj = appsink, + "processing sample {:?}", + sample.buffer() + ); let latency = consumers.current_latency; let latency_updated = mem::replace(&mut consumers.latency_updated, false); @@ -302,7 +319,7 @@ impl StreamProducer { if !is_keyframe && consumer.needs_keyframe.load(atomic::Ordering::SeqCst) { // If we need a keyframe (and this one isn't) request a keyframe upstream if !needs_keyframe_request { - gst::debug!(CAT, obj: appsink, "Requesting keyframe for first buffer"); + gst::debug!(CAT, obj = appsink, "Requesting keyframe for first buffer"); needs_keyframe_request = true; } @@ -310,7 +327,7 @@ impl StreamProducer { gst::debug!( CAT, - obj: appsink, + obj = appsink, "Ignoring frame for {} while waiting for a keyframe", consumer.appsrc.name() ); @@ -340,7 +357,7 @@ impl StreamProducer { for consumer in current_consumers { if let Err(err) = consumer.push_sample(&sample) { - gst::warning!(CAT, obj: appsink, "Failed to push sample: {}", err); + gst::warning!(CAT, obj = appsink, "Failed to push sample: {}", err); } } Ok(gst::FlowSuccess::Ok) @@ -357,10 +374,22 @@ impl StreamProducer { .remove(consumer) .is_some() { - gst::debug!(CAT, obj: &self.appsink, "Removed consumer {} ({:?})", name, consumer); + gst::debug!( + CAT, + obj = &self.appsink, + "Removed consumer {} ({:?})", + name, + consumer + ); consumer.set_callbacks(gst_app::AppSrcCallbacks::builder().build()); } else { - gst::debug!(CAT, obj: &self.appsink, "Consumer {} ({:?}) not found", name, consumer); + gst::debug!( + CAT, + obj = &self.appsink, + "Consumer {} ({:?}) not found", + name, + consumer + ); } } @@ -415,89 +444,116 @@ impl<'a> From<&'a gst_app::AppSink> for StreamProducer { appsink.set_callbacks( gst_app::AppSinkCallbacks::builder() - .new_sample(glib::clone!(#[strong] consumers, move |appsink| { - let mut consumers = consumers.lock().unwrap(); + .new_sample(glib::clone!( + #[strong] + consumers, + move |appsink| { + let mut consumers = consumers.lock().unwrap(); - let sample = match appsink.pull_sample() { - Ok(sample) => sample, - Err(_err) => { - gst::debug!(CAT, obj: appsink, "Failed to pull sample"); - return Err(gst::FlowError::Flushing); + let sample = match appsink.pull_sample() { + Ok(sample) => sample, + Err(_err) => { + gst::debug!(CAT, obj = appsink, "Failed to pull sample"); + return Err(gst::FlowError::Flushing); + } + }; + + let just_forwarded_preroll = + mem::replace(&mut consumers.just_forwarded_preroll, false); + + if just_forwarded_preroll { + return Ok(gst::FlowSuccess::Ok); } - }; - - let just_forwarded_preroll = mem::replace(&mut consumers.just_forwarded_preroll, false); - - if just_forwarded_preroll { - return Ok(gst::FlowSuccess::Ok); - } - - StreamProducer::process_sample(sample, appsink, consumers) - })) - .new_preroll(glib::clone!(#[strong] consumers, move |appsink| { - let mut consumers = consumers.lock().unwrap(); - - let sample = match appsink.pull_preroll() { - Ok(sample) => sample, - Err(_err) => { - gst::debug!(CAT, obj: appsink, "Failed to pull preroll"); - return Err(gst::FlowError::Flushing); - } - }; - - if consumers.forward_preroll { - consumers.just_forwarded_preroll = true; StreamProducer::process_sample(sample, appsink, consumers) - } else { - Ok(gst::FlowSuccess::Ok) } - })) - .new_event(glib::clone!(#[strong] consumers, move |appsink| { - match appsink.pull_object().map(|obj| obj.downcast::()) { - Ok(Ok(event)) => { - let (events_to_forward, appsrcs) = { - // clone so we don't keep the lock while pushing events - let consumers = consumers.lock().unwrap(); - let events = consumers.events_to_forward.clone(); - let appsrcs = consumers.consumers.keys().cloned().collect::>(); + )) + .new_preroll(glib::clone!( + #[strong] + consumers, + move |appsink| { + let mut consumers = consumers.lock().unwrap(); - (events, appsrcs) - }; + let sample = match appsink.pull_preroll() { + Ok(sample) => sample, + Err(_err) => { + gst::debug!(CAT, obj = appsink, "Failed to pull preroll"); + return Err(gst::FlowError::Flushing); + } + }; - if events_to_forward.contains(&event.type_()){ - for appsrc in appsrcs { - appsrc.send_event(event.clone()); + if consumers.forward_preroll { + consumers.just_forwarded_preroll = true; + + StreamProducer::process_sample(sample, appsink, consumers) + } else { + Ok(gst::FlowSuccess::Ok) + } + } + )) + .new_event(glib::clone!( + #[strong] + consumers, + move |appsink| { + match appsink + .pull_object() + .map(|obj| obj.downcast::()) + { + Ok(Ok(event)) => { + let (events_to_forward, appsrcs) = { + // clone so we don't keep the lock while pushing events + let consumers = consumers.lock().unwrap(); + let events = consumers.events_to_forward.clone(); + let appsrcs = + consumers.consumers.keys().cloned().collect::>(); + + (events, appsrcs) + }; + + if events_to_forward.contains(&event.type_()) { + for appsrc in appsrcs { + appsrc.send_event(event.clone()); + } } } + Ok(Err(_)) => {} // pulled another unsupported object type, ignore + Err(_err) => gst::warning!(CAT, obj = appsink, "Failed to pull event"), } - Ok(Err(_)) => {}, // pulled another unsupported object type, ignore - Err(_err) => gst::warning!(CAT, obj: appsink, "Failed to pull event"), + + false } + )) + .eos(glib::clone!( + #[strong] + consumers, + move |appsink| { + let stream_consumers = consumers.lock().unwrap(); - false - })) - .eos(glib::clone!(#[strong] consumers, move |appsink| { - let stream_consumers = consumers - .lock() - .unwrap(); + if stream_consumers + .events_to_forward + .contains(&gst::EventType::Eos) + { + let current_consumers = stream_consumers + .consumers + .values() + .map(|c| c.appsrc.clone()) + .collect::>(); + drop(stream_consumers); - if stream_consumers.events_to_forward.contains(&gst::EventType::Eos) { - let current_consumers = stream_consumers - .consumers - .values() - .map(|c| c.appsrc.clone()) - .collect::>(); - drop(stream_consumers); - - for consumer in current_consumers { - gst::debug!(CAT, obj: appsink, "set EOS on consumer {}", consumer.name()); - let _ = consumer.end_of_stream(); + for consumer in current_consumers { + gst::debug!( + CAT, + obj = appsink, + "set EOS on consumer {}", + consumer.name() + ); + let _ = consumer.end_of_stream(); + } + } else { + gst::debug!(CAT, obj = appsink, "don't forward EOS to consumers"); } - } else { - gst::debug!(CAT, obj: appsink, "don't forward EOS to consumers"); } - })) + )) .build(), ); @@ -591,7 +647,7 @@ impl StreamConsumer { .enough_data(move |appsrc| { gst::debug!( CAT, - obj: appsrc, + obj = appsrc, "consumer {} ({:?}) is not consuming fast enough, old samples are getting dropped", appsrc.name(), appsrc, diff --git a/gstreamer/src/element_factory.rs b/gstreamer/src/element_factory.rs index 7f1d06024..34ed8362d 100644 --- a/gstreamer/src/element_factory.rs +++ b/gstreamer/src/element_factory.rs @@ -304,7 +304,7 @@ impl<'a> ElementBuilder<'a> { let factory = factory.load().map_err(|_| { crate::warning!( crate::CAT_RUST, - obj: factory, + obj = factory, "loading element factory '{}' failed", factory.name(), ); @@ -318,7 +318,7 @@ impl<'a> ElementBuilder<'a> { if !element_type.is_valid() { crate::warning!( crate::CAT_RUST, - obj: &factory, + obj = &factory, "element factory '{}' has no type", factory.name() ); @@ -422,7 +422,7 @@ impl<'a> ElementBuilder<'a> { crate::log!( crate::CAT_RUST, - obj: &factory, + obj = &factory, "created element \"{}\"", factory.name() ); diff --git a/gstreamer/src/log.rs b/gstreamer/src/log.rs index e8d2d66b2..aab914ba2 100644 --- a/gstreamer/src/log.rs +++ b/gstreamer/src/log.rs @@ -613,135 +613,383 @@ declare_debug_category_from_name!(CAT_CONTEXT, "GST_CONTEXT"); #[macro_export] macro_rules! error( + ($cat:expr, obj = $obj:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Error, obj = $obj, $($args)*) + }}; + ($cat:expr, imp = $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Error, imp = $imp, $($args)*) + }}; + ($cat:expr, id = $id:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Error, id = $id, $($args)*) + }}; + ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Error, obj: $obj, $($args)*) + { + #[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"] + macro_rules! error( + () => {} + ); + error!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Error, obj = $obj, $($args)*) }}; ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Error, imp: $imp, $($args)*) + { + #[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"] + macro_rules! error( + () => {} + ); + error!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Error, imp = $imp, $($args)*) }}; ($cat:expr, id: $id:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Error, id: $id, $($args)*) + { + #[deprecated = "Using old-style id format. Use `id = ` instead of `id: ` for better tooling support"] + macro_rules! error( + () => {} + ); + error!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Error, id = $id, $($args)*) }}; ($cat:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Error, $($args)*) + $crate::log_with_level!($cat, $crate::DebugLevel::Error, $($args)*) }}; ); #[macro_export] macro_rules! warning( + ($cat:expr, obj = $obj:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Warning, obj = $obj, $($args)*) + }}; + ($cat:expr, imp = $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Warning, imp = $imp, $($args)*) + }}; + ($cat:expr, id = $id:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Warning, id = $id, $($args)*) + }}; + ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Warning, obj: $obj, $($args)*) + { + #[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"] + macro_rules! warning( + () => {} + ); + warning!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Warning, obj = $obj, $($args)*) }}; ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Warning, imp: $imp, $($args)*) + { + #[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"] + macro_rules! warning( + () => {} + ); + warning!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Warning, imp = $imp, $($args)*) }}; ($cat:expr, id: $id:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Warning, id: $id, $($args)*) + { + #[deprecated = "Using old-style id format. Use `id = ` instead of `id: ` for better tooling support"] + macro_rules! warning( + () => {} + ); + warning!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Warning, id = $id, $($args)*) }}; ($cat:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Warning, $($args)*) + $crate::log_with_level!($cat, $crate::DebugLevel::Warning, $($args)*) }}; ); #[macro_export] macro_rules! fixme( + ($cat:expr, obj = $obj:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Fixme, obj = $obj, $($args)*) + }}; + ($cat:expr, imp = $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Fixme, imp = $imp, $($args)*) + }}; + ($cat:expr, id = $id:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Fixme, id = $id, $($args)*) + }}; + ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Fixme, obj: $obj, $($args)*) + { + #[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"] + macro_rules! fixme( + () => {} + ); + fixme!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Fixme, obj = $obj, $($args)*) }}; ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Fixme, imp: $imp, $($args)*) + { + #[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"] + macro_rules! fixme( + () => {} + ); + fixme!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Fixme, imp = $imp, $($args)*) }}; ($cat:expr, id: $id:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Fixme, id: $id, $($args)*) + { + #[deprecated = "Using old-style id format. Use `id = ` instead of `id: ` for better tooling support"] + macro_rules! fixme( + () => {} + ); + fixme!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Fixme, id = $id, $($args)*) }}; ($cat:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Fixme, $($args)*) + $crate::log_with_level!($cat, $crate::DebugLevel::Fixme, $($args)*) }}; ); #[macro_export] macro_rules! info( + ($cat:expr, obj = $obj:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Info, obj = $obj, $($args)*) + }}; + ($cat:expr, imp = $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Info, imp = $imp, $($args)*) + }}; + ($cat:expr, id = $id:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Info, id = $id, $($args)*) + }}; + ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Info, obj: $obj, $($args)*) + { + #[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"] + macro_rules! info( + () => {} + ); + info!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Info, obj = $obj, $($args)*) }}; ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Info, imp: $imp, $($args)*) + { + #[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"] + macro_rules! info( + () => {} + ); + info!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Info, imp = $imp, $($args)*) }}; ($cat:expr, id: $id:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Info, id: $id, $($args)*) + { + #[deprecated = "Using old-style id format. Use `id = ` instead of `id: ` for better tooling support"] + macro_rules! info( + () => {} + ); + info!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Info, id = $id, $($args)*) }}; ($cat:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Info, $($args)*) + $crate::log_with_level!($cat, $crate::DebugLevel::Info, $($args)*) }}; ); #[macro_export] macro_rules! debug( + ($cat:expr, obj = $obj:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Debug, obj = $obj, $($args)*) + }}; + ($cat:expr, imp = $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Debug, imp = $imp, $($args)*) + }}; + ($cat:expr, id = $id:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Debug, id = $id, $($args)*) + }}; + ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Debug, obj: $obj, $($args)*) + { + #[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"] + macro_rules! debug( + () => {} + ); + debug!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Debug, obj = $obj, $($args)*) }}; ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Debug, imp: $imp, $($args)*) + { + #[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"] + macro_rules! debug( + () => {} + ); + debug!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Debug, imp = $imp, $($args)*) }}; ($cat:expr, id: $id:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Debug, id: $id, $($args)*) + { + #[deprecated = "Using old-style id format. Use `id = ` instead of `id: ` for better tooling support"] + macro_rules! debug( + () => {} + ); + debug!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Debug, id = $id, $($args)*) }}; ($cat:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Debug, $($args)*) + $crate::log_with_level!($cat, $crate::DebugLevel::Debug, $($args)*) }}; ); #[macro_export] macro_rules! log( + ($cat:expr, obj = $obj:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Log, obj = $obj, $($args)*) + }}; + ($cat:expr, imp = $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Log, imp = $imp, $($args)*) + }}; + ($cat:expr, id = $id:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Log, id = $id, $($args)*) + }}; + ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Log, obj: $obj, $($args)*) + { + #[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"] + macro_rules! log( + () => {} + ); + log!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Log, obj = $obj, $($args)*) }}; ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Log, imp: $imp, $($args)*) + { + #[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"] + macro_rules! log( + () => {} + ); + log!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Log, imp = $imp, $($args)*) }}; ($cat:expr, id: $id:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Log, id: $id, $($args)*) + { + #[deprecated = "Using old-style id format. Use `id = ` instead of `id: ` for better tooling support"] + macro_rules! log( + () => {} + ); + log!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Log, id = $id, $($args)*) }}; ($cat:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Log, $($args)*) + $crate::log_with_level!($cat, $crate::DebugLevel::Log, $($args)*) }}; ); #[macro_export] macro_rules! trace( + ($cat:expr, obj = $obj:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Trace, obj = $obj, $($args)*) + }}; + ($cat:expr, imp = $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Trace, imp = $imp, $($args)*) + }}; + ($cat:expr, id = $id:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Trace, id = $id, $($args)*) + }}; + ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Trace, obj: $obj, $($args)*) + { + #[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"] + macro_rules! trace( + () => {} + ); + trace!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Trace, obj = $obj, $($args)*) }}; ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Trace, imp: $imp, $($args)*) + { + #[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"] + macro_rules! trace( + () => {} + ); + trace!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Trace, imp = $imp, $($args)*) }}; ($cat:expr, id: $id:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Trace, id: $id, $($args)*) + { + #[deprecated = "Using old-style id format. Use `id = ` instead of `id: `"] + macro_rules! trace( + () => {} + ); + trace!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Trace, id = $id, $($args)*) }}; ($cat:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Trace, $($args)*) + $crate::log_with_level!($cat, $crate::DebugLevel::Trace, $($args)*) }}; ); #[macro_export] macro_rules! memdump( + ($cat:expr, obj = $obj:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Memdump, obj = $obj, $($args)*) + }}; + ($cat:expr, imp = $imp:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Memdump, imp = $imp, $($args)*) + }}; + ($cat:expr, id = $id:expr, $($args:tt)*) => { { + $crate::log_with_level!($cat, $crate::DebugLevel::Memdump, id = $id, $($args)*) + }}; + ($cat:expr, obj: $obj:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Memdump, obj: $obj, $($args)*) + { + #[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"] + macro_rules! memdump( + () => {} + ); + memdump!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Memdump, obj = $obj, $($args)*) }}; ($cat:expr, imp: $imp:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Memdump, imp: $imp, $($args)*) + { + #[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"] + macro_rules! memdump( + () => {} + ); + memdump!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Memdump, imp = $imp, $($args)*) }}; ($cat:expr, id: $id:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Memdump, id: $id, $($args)*) + { + #[deprecated = "Using old-style id format. Use `id = ` instead of `id: ` for better tooling support"] + macro_rules! memdump( + () => {} + ); + memdump!(); + } + $crate::log_with_level!($cat, $crate::DebugLevel::Memdump, id = $id, $($args)*) }}; ($cat:expr, $($args:tt)*) => { { - $crate::log_with_level!($cat, level: $crate::DebugLevel::Memdump, $($args)*) + $crate::log_with_level!($cat, $crate::DebugLevel::Memdump, $($args)*) }}; ); #[macro_export] macro_rules! log_with_level( - ($cat:expr, level: $level:expr, obj: $obj:expr, $msg:literal) => { { + ($cat:expr, $level:expr, obj = $obj:expr, $msg:literal) => { { let cat = $cat.clone(); // Check the log level before using `format_args!` otherwise @@ -785,7 +1033,7 @@ macro_rules! log_with_level( })(format_args!($msg)) } }}; - ($cat:expr, level: $level:expr, obj: $obj:expr, $($args:tt)*) => { { + ($cat:expr, $level:expr, obj = $obj:expr, $($args:tt)*) => { { let cat = $cat.clone(); // Check the log level before using `format_args!` otherwise @@ -809,7 +1057,7 @@ macro_rules! log_with_level( ) } }}; - ($cat:expr, level: $level:expr, imp: $imp:expr, $msg:literal) => { { + ($cat:expr, $level:expr, imp = $imp:expr, $msg:literal) => { { let cat = $cat.clone(); // Check the log level before using `format_args!` otherwise @@ -854,7 +1102,7 @@ macro_rules! log_with_level( })(format_args!($msg)) } }}; - ($cat:expr, level: $level:expr, imp: $imp:expr, $($args:tt)*) => { { + ($cat:expr, $level:expr, imp = $imp:expr, $($args:tt)*) => { { let cat = $cat.clone(); // Check the log level before using `format_args!` otherwise @@ -879,7 +1127,7 @@ macro_rules! log_with_level( ) } }}; - ($cat:expr, level: $level:expr, id: $id:literal, $msg:literal) => { { + ($cat:expr, $level:expr, id = $id:literal, $msg:literal) => { { let cat = $cat.clone(); // Check the log level before using `format_args!` otherwise @@ -920,7 +1168,7 @@ macro_rules! log_with_level( })(format_args!($msg)) } }}; - ($cat:expr, level: $level:expr, id: $id:literal, $($args:tt)*) => { { + ($cat:expr, $level:expr, id = $id:literal, $($args:tt)*) => { { let cat = $cat.clone(); // Check the log level before using `format_args!` otherwise @@ -941,7 +1189,7 @@ macro_rules! log_with_level( ) } }}; - ($cat:expr, level: $level:expr, id: $id:expr, $msg:literal) => { { + ($cat:expr, $level:expr, id = $id:expr, $msg:literal) => { { let cat = $cat.clone(); // Check the log level before using `format_args!` otherwise @@ -982,7 +1230,7 @@ macro_rules! log_with_level( })(format_args!($msg)) } }}; - ($cat:expr, level: $level:expr, id: $id:expr, $($args:tt)*) => { { + ($cat:expr, $level:expr, id = $id:expr, $($args:tt)*) => { { let cat = $cat.clone(); // Check the log level before using `format_args!` otherwise @@ -1003,7 +1251,7 @@ macro_rules! log_with_level( ) } }}; - ($cat:expr, level: $level:expr, $msg:literal) => { { + ($cat:expr, $level:expr, $msg:literal) => { { let cat = $cat.clone(); // Check the log level before using `format_args!` otherwise @@ -1044,7 +1292,7 @@ macro_rules! log_with_level( })(format_args!($msg)) } }}; - ($cat:expr, level: $level:expr, $($args:tt)*) => { { + ($cat:expr, $level:expr, $($args:tt)*) => { { let cat = $cat.clone(); // Check the log level before using `format_args!` otherwise @@ -1343,23 +1591,23 @@ mod tests { let obj = crate::Bin::with_name("meh"); - error!(cat, obj: &obj, "meh"); - warning!(cat, obj: &obj, "meh"); - fixme!(cat, obj: &obj, "meh"); - info!(cat, obj: &obj, "meh"); - debug!(cat, obj: &obj, "meh"); - log!(cat, obj: &obj, "meh"); - trace!(cat, obj: &obj, "meh"); - memdump!(cat, obj: &obj, "meh"); + error!(cat, obj = &obj, "meh"); + warning!(cat, obj = &obj, "meh"); + fixme!(cat, obj = &obj, "meh"); + info!(cat, obj = &obj, "meh"); + debug!(cat, obj = &obj, "meh"); + log!(cat, obj = &obj, "meh"); + trace!(cat, obj = &obj, "meh"); + memdump!(cat, obj = &obj, "meh"); - error!(cat, obj: obj, "meh"); - warning!(cat, obj: obj, "meh"); - fixme!(cat, obj: obj, "meh"); - info!(cat, obj: obj, "meh"); - debug!(cat, obj: obj, "meh"); - log!(cat, obj: obj, "meh"); - trace!(cat, obj: obj, "meh"); - memdump!(cat, obj: obj, "meh"); + error!(cat, obj = obj, "meh"); + warning!(cat, obj = obj, "meh"); + fixme!(cat, obj = obj, "meh"); + info!(cat, obj = obj, "meh"); + debug!(cat, obj = obj, "meh"); + log!(cat, obj = obj, "meh"); + trace!(cat, obj = obj, "meh"); + memdump!(cat, obj = obj, "meh"); } #[cfg(feature = "log")] @@ -1459,13 +1707,13 @@ mod tests { remove_default_log_function(); let log_fn = add_log_function(handler); - info!(cat, obj: &obj, "meh"); + info!(cat, obj = &obj, "meh"); receiver.recv().unwrap(); remove_log_function(log_fn); - info!(cat, obj: &obj, "meh2"); + info!(cat, obj = &obj, "meh2"); assert!(receiver.recv().is_err()); } @@ -1501,12 +1749,12 @@ mod tests { cat.set_threshold(crate::DebugLevel::Trace); - trace!(cat, id: "123", "test"); - trace!(cat, id: glib::GString::from("123"), "test"); - trace!(cat, id: &glib::GString::from("123"), "test"); + trace!(cat, id = "123", "test"); + trace!(cat, id = glib::GString::from("123"), "test"); + trace!(cat, id = &glib::GString::from("123"), "test"); // Try with a formatted string too (which is a different code path in the bindings) let log_id = glib::GString::from("456"); - trace!(cat, id: &log_id , "{log_id:?}"); + trace!(cat, id = &log_id, "{log_id:?}"); } } diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index c7b4abd5d..490cff89f 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -1277,7 +1277,7 @@ where if let Some(passed_buffer) = passed_buffer { crate::debug!( crate::CAT_PERFORMANCE, - obj: pad.unsafe_cast_ref::(), + obj = pad.unsafe_cast_ref::(), "Returned new buffer from getrange function, copying into passed buffer" ); @@ -1286,7 +1286,7 @@ where Err(_) => { crate::error!( crate::CAT_RUST, - obj: pad.unsafe_cast_ref::(), + obj = pad.unsafe_cast_ref::(), "Failed to map passed buffer writable" ); return ffi::GST_FLOW_ERROR; @@ -1305,7 +1305,7 @@ where Err(_) => { crate::error!( crate::CAT_RUST, - obj: pad.unsafe_cast_ref::(), + obj = pad.unsafe_cast_ref::(), "Failed to copy buffer metadata" ); diff --git a/gstreamer/src/subclass/allocator.rs b/gstreamer/src/subclass/allocator.rs index 411f97379..494429492 100644 --- a/gstreamer/src/subclass/allocator.rs +++ b/gstreamer/src/subclass/allocator.rs @@ -89,7 +89,7 @@ unsafe extern "C" fn alloc( imp.alloc(size, params) .map(|memory| memory.into_glib_ptr()) .unwrap_or_else(|error| { - error!(crate::CAT_RUST, obj: instance, "{:?}", error); + error!(crate::CAT_RUST, obj = instance, "{:?}", error); ptr::null_mut() }) diff --git a/gstreamer/src/subclass/task_pool.rs b/gstreamer/src/subclass/task_pool.rs index e1f83a1c8..df1e37599 100644 --- a/gstreamer/src/subclass/task_pool.rs +++ b/gstreamer/src/subclass/task_pool.rs @@ -111,7 +111,11 @@ unsafe extern "C" fn task_pool_push( unsafe extern "C" fn task_pool_join(ptr: *mut ffi::GstTaskPool, id: gpointer) { if id.is_null() { let wrap: Borrowed = from_glib_borrow(ptr); - crate::warning!(crate::CAT_RUST, obj: wrap.as_ref(), "Tried to join null handle"); + crate::warning!( + crate::CAT_RUST, + obj = wrap.as_ref(), + "Tried to join null handle" + ); return; } @@ -127,7 +131,11 @@ unsafe extern "C" fn task_pool_dispose_handle( ) { if id.is_null() { let wrap: Borrowed = from_glib_borrow(ptr); - crate::warning!(crate::CAT_RUST, obj: wrap.as_ref(), "Tried to dispose null handle"); + crate::warning!( + crate::CAT_RUST, + obj = wrap.as_ref(), + "Tried to dispose null handle" + ); return; } diff --git a/gstreamer/src/task_pool.rs b/gstreamer/src/task_pool.rs index a9e40f8da..a1fc6479e 100644 --- a/gstreamer/src/task_pool.rs +++ b/gstreamer/src/task_pool.rs @@ -114,7 +114,7 @@ impl Drop for TaskPoolTaskHandle { if #[cfg(feature = "v1_20")] { unsafe { task_pool.dispose_handle(self.handle) } } else { - crate::warning!(crate::CAT_RUST, obj: &task_pool, "Leaked task handle"); + crate::warning!(crate::CAT_RUST, obj = &task_pool, "Leaked task handle"); } } }