From 1df5b0d028de4558851d9d2a52374d4432886f84 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Wed, 14 Jun 2023 11:22:53 +0200 Subject: [PATCH] pbutils: implement debug() method on DiscovererInfo related structs The default Debug implementation is not very useful but unfortunately cannot be overridden. Part-of: --- gstreamer-pbutils/src/discoverer.rs | 76 ++++++++++++++++++- .../src/discoverer_audio_info.rs | 32 ++++++++ .../src/discoverer_container_info.rs | 32 ++++++++ .../src/discoverer_stream_info.rs | 26 +++++++ .../src/discoverer_subtitle_info.rs | 26 +++++++ .../src/discoverer_video_info.rs | 29 ++++++- gstreamer-pbutils/src/lib.rs | 3 + 7 files changed, 220 insertions(+), 4 deletions(-) create mode 100644 gstreamer-pbutils/src/discoverer_audio_info.rs create mode 100644 gstreamer-pbutils/src/discoverer_container_info.rs create mode 100644 gstreamer-pbutils/src/discoverer_subtitle_info.rs diff --git a/gstreamer-pbutils/src/discoverer.rs b/gstreamer-pbutils/src/discoverer.rs index 8fddcba1e..9e7bdc00e 100644 --- a/gstreamer-pbutils/src/discoverer.rs +++ b/gstreamer-pbutils/src/discoverer.rs @@ -1,6 +1,6 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use std::{boxed::Box as Box_, mem::transmute}; +use std::{boxed::Box as Box_, fmt, mem::transmute}; use glib::{ prelude::*, @@ -8,7 +8,7 @@ use glib::{ translate::*, }; -use crate::auto::Discoverer; +use crate::{auto::Discoverer, DiscovererInfo}; impl Discoverer { pub fn set_timeout(&self, timeout: gst::ClockTime) { @@ -48,3 +48,75 @@ unsafe extern "C" fn notify_timeout_trampoline(&'a DiscovererInfo); + +impl<'a> fmt::Debug for DebugInfo<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let stream_info = self.0.stream_info(); + let stream_list = self.0.stream_list(); + let container_streams = self.0.container_streams(); + let audio_streams = self.0.audio_streams(); + let video_streams = self.0.video_streams(); + let subtitle_streams = self.0.subtitle_streams(); + + f.debug_struct("DiscovererInfo") + .field("uri", &self.0.uri()) + .field("result", &self.0.result()) + .field("duration", &self.0.duration()) + .field("is-live", &self.0.is_live()) + .field("is-seekable", &self.0.is_seekable()) + .field( + "stream-info", + &stream_info.as_ref().map(|info| info.debug()), + ) + .field( + "stream-list", + &stream_list + .iter() + .map(|info| info.debug()) + .collect::>(), + ) + .field( + "container-streams", + &container_streams + .iter() + .map(|info| info.debug()) + .collect::>(), + ) + .field( + "audio-streams", + &audio_streams + .iter() + .map(|info| info.debug()) + .collect::>(), + ) + .field( + "video-streams", + &video_streams + .iter() + .map(|info| info.debug()) + .collect::>(), + ) + .field( + "subtitle-streams", + &subtitle_streams + .iter() + .map(|info| info.debug()) + .collect::>(), + ) + .field("toc", &self.0.toc()) + .field("misc", &self.0.misc()) + .field( + "missing-elements-installer-details", + &self.0.missing_elements_installer_details(), + ) + .finish() + } +} + +impl DiscovererInfo { + pub fn debug(&self) -> DebugInfo { + DebugInfo(self) + } +} diff --git a/gstreamer-pbutils/src/discoverer_audio_info.rs b/gstreamer-pbutils/src/discoverer_audio_info.rs new file mode 100644 index 000000000..1f1eb86bc --- /dev/null +++ b/gstreamer-pbutils/src/discoverer_audio_info.rs @@ -0,0 +1,32 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use std::fmt; + +use glib::Cast; + +use crate::{DiscovererAudioInfo, DiscovererStreamInfo}; + +pub struct Debug<'a>(&'a DiscovererAudioInfo); + +impl<'a> fmt::Debug for Debug<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let info = self.0.upcast_ref::(); + + f.debug_struct("DiscovererAudioInfo") + .field("channels", &self.0.channels()) + .field("sample-rate", &self.0.sample_rate()) + .field("depth", &self.0.depth()) + .field("bitrate", &self.0.bitrate()) + .field("max-bitrate", &self.0.max_bitrate()) + .field("channel-mask", &self.0.channel_mask()) + .field("language", &self.0.language()) + .field("stream", &info.debug()) + .finish() + } +} + +impl DiscovererAudioInfo { + pub fn debug(&self) -> Debug { + Debug(self) + } +} diff --git a/gstreamer-pbutils/src/discoverer_container_info.rs b/gstreamer-pbutils/src/discoverer_container_info.rs new file mode 100644 index 000000000..d897f3326 --- /dev/null +++ b/gstreamer-pbutils/src/discoverer_container_info.rs @@ -0,0 +1,32 @@ +// Take a look at the license at the top of the repository in the LICENSE file. +use std::fmt; + +use crate::{prelude::*, DiscovererContainerInfo}; + +pub struct Debug<'a>(&'a DiscovererContainerInfo); + +impl<'a> fmt::Debug for Debug<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let streams = self.0.streams(); + + let mut d = f.debug_struct("DiscovererContainerInfo"); + + d.field("tags", &self.0.tags()).field( + "streams", + &streams.iter().map(|info| info.debug()).collect::>(), + ); + + #[cfg(feature = "v1_20")] + d.field("stream-number", &self.0.stream_number()); + #[cfg(feature = "v1_20")] + d.field("tags", &self.0.tags()); + + d.finish() + } +} + +impl DiscovererContainerInfo { + pub fn debug(&self) -> Debug { + Debug(self) + } +} diff --git a/gstreamer-pbutils/src/discoverer_stream_info.rs b/gstreamer-pbutils/src/discoverer_stream_info.rs index 7d0cb9939..a23474c9e 100644 --- a/gstreamer-pbutils/src/discoverer_stream_info.rs +++ b/gstreamer-pbutils/src/discoverer_stream_info.rs @@ -1,4 +1,5 @@ // Take a look at the license at the top of the repository in the LICENSE file. +use std::fmt; use crate::{prelude::*, DiscovererStreamInfo}; @@ -50,3 +51,28 @@ impl> DiscovererStreamInfoExtManual for O { } } } + +pub struct Debug<'a>(&'a DiscovererStreamInfo); + +impl<'a> fmt::Debug for Debug<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let mut d = f.debug_struct("DiscovererStreamInfo"); + d.field("caps", &self.0.caps()) + .field("stream-id", &self.0.stream_id()) + .field("misc", &self.0.misc()) + .field("stream-type-nick", &self.0.stream_type_nick()) + .field("tags", &self.0.tags()) + .field("toc", &self.0.toc()); + + #[cfg(feature = "v1_20")] + d.field("stream-number", &self.0.stream_number()); + + d.finish() + } +} + +impl DiscovererStreamInfo { + pub fn debug(&self) -> Debug { + Debug(self) + } +} diff --git a/gstreamer-pbutils/src/discoverer_subtitle_info.rs b/gstreamer-pbutils/src/discoverer_subtitle_info.rs new file mode 100644 index 000000000..b48fbd5af --- /dev/null +++ b/gstreamer-pbutils/src/discoverer_subtitle_info.rs @@ -0,0 +1,26 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use std::fmt; + +use glib::Cast; + +use crate::{DiscovererStreamInfo, DiscovererSubtitleInfo}; + +pub struct Debug<'a>(&'a DiscovererSubtitleInfo); + +impl<'a> fmt::Debug for Debug<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let info = self.0.upcast_ref::(); + + f.debug_struct("DiscovererSubtitleInfo") + .field("language", &self.0.language()) + .field("stream", &info.debug()) + .finish() + } +} + +impl DiscovererSubtitleInfo { + pub fn debug(&self) -> Debug { + Debug(self) + } +} diff --git a/gstreamer-pbutils/src/discoverer_video_info.rs b/gstreamer-pbutils/src/discoverer_video_info.rs index d5c48ce47..144a6ddec 100644 --- a/gstreamer-pbutils/src/discoverer_video_info.rs +++ b/gstreamer-pbutils/src/discoverer_video_info.rs @@ -1,8 +1,10 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use glib::translate::*; +use std::fmt; -use crate::DiscovererVideoInfo; +use glib::{translate::*, Cast}; + +use crate::{DiscovererStreamInfo, DiscovererVideoInfo}; impl DiscovererVideoInfo { #[doc(alias = "get_framerate")] @@ -28,4 +30,27 @@ impl DiscovererVideoInfo { ) } } + + pub fn debug(&self) -> Debug { + Debug(self) + } +} + +pub struct Debug<'a>(&'a DiscovererVideoInfo); + +impl<'a> fmt::Debug for Debug<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let info = self.0.upcast_ref::(); + + f.debug_struct("DiscovererVideoInfo") + .field("width", &self.0.width()) + .field("height", &self.0.height()) + .field("depth", &self.0.depth()) + .field("bitrate", &self.0.bitrate()) + .field("max-bitrate", &self.0.max_bitrate()) + .field("is-image", &self.0.is_image()) + .field("is-interlaced", &self.0.is_interlaced()) + .field("stream", &info.debug()) + .finish() + } } diff --git a/gstreamer-pbutils/src/lib.rs b/gstreamer-pbutils/src/lib.rs index 5a64094e7..4004106f4 100644 --- a/gstreamer-pbutils/src/lib.rs +++ b/gstreamer-pbutils/src/lib.rs @@ -41,7 +41,10 @@ mod flag_serde; mod discoverer; pub use crate::discoverer::*; +mod discoverer_audio_info; +mod discoverer_container_info; pub mod discoverer_stream_info; +mod discoverer_subtitle_info; mod discoverer_video_info; pub mod encoding_profile;