From 85e46f39f30b555c8f58539a4f78c39a3665346c Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sat, 12 Dec 2020 19:53:55 +0100 Subject: [PATCH] video: Provide manual to_string and display for VideoChromaSite This function was named wrong before 1.20, and its return transfer type changed from none to full. To provide Note that, when 1.20 Gir files are imported, this `version` override in gstreamer-video/Gir.toml wil come into effect and create a Display trait for us (without version constraint). At that point the manual Display impl should be removed, but the manual to_string implementation remains. --- gstreamer-video/Gir.toml | 5 +++++ gstreamer-video/src/video_info.rs | 21 +++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/gstreamer-video/Gir.toml b/gstreamer-video/Gir.toml index c1dbdb602..a055f4199 100644 --- a/gstreamer-video/Gir.toml +++ b/gstreamer-video/Gir.toml @@ -481,6 +481,11 @@ status = "generate" [[object.function]] name = "to_string" + rename = "to_str" + # Manual function for < v1_20: + manual = true + # Always generate the trait, without version constraint: + version = "1.8" [object.function.return] nullable = false diff --git a/gstreamer-video/src/video_info.rs b/gstreamer-video/src/video_info.rs index 27ee8d0c5..a2b534e84 100644 --- a/gstreamer-video/src/video_info.rs +++ b/gstreamer-video/src/video_info.rs @@ -175,6 +175,22 @@ impl fmt::Display for crate::VideoColorimetry { } } +impl crate::VideoChromaSite { + pub fn to_str(self) -> glib::GString { + assert_initialized_main_thread!(); + + unsafe { + cfg_if::cfg_if! { + if #[cfg(feature = "v1_20")] { + from_glib_full(ffi::gst_video_chroma_site_to_string(self.to_glib())) + } else { + from_glib_none(ffi::gst_video_chroma_to_string(self.to_glib())) + } + } + } + } +} + impl str::FromStr for crate::VideoChromaSite { type Err = glib::error::BoolError; @@ -201,10 +217,7 @@ impl str::FromStr for crate::VideoChromaSite { impl fmt::Display for crate::VideoChromaSite { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let s = unsafe { - glib::GString::from_glib_full(ffi::gst_video_chroma_to_string(self.to_glib())) - }; - f.write_str(&s) + f.write_str(&self.to_str()) } }