From 01ae47c90c926f3377ce6a2ba3f14a24a51cc7fd Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sat, 5 Dec 2020 22:42:49 +0100 Subject: [PATCH] gstreamer: Manually implement StateChange::get_name on < v1_14 By setting the version to 1.8 and using `manual = true` an unconditional trait implementation calling get_name is generated, while the autogenerated version is omitted. --- gstreamer/Gir.toml | 11 ++++++++++- gstreamer/src/enums.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/gstreamer/Gir.toml b/gstreamer/Gir.toml index 86c44bcd9..ba4606dd7 100644 --- a/gstreamer/Gir.toml +++ b/gstreamer/Gir.toml @@ -43,7 +43,6 @@ generate = [ "Gst.SchedulingFlags", "Gst.SeekType", "Gst.State", - "Gst.StateChange", "Gst.StreamError", "Gst.StreamStatusType", "Gst.StreamType", @@ -1631,6 +1630,16 @@ status = "generate" # confusing return type ignore = true +[[object]] +name = "Gst.StateChange" +status = "generate" + [[object.function]] + name = "get_name" + # Manual function for < v1_14: + manual = true + # Always generate the trait, without version constraint: + version = "1.8" + [[object]] name = "Gst.StateChangeReturn" status = "generate" diff --git a/gstreamer/src/enums.rs b/gstreamer/src/enums.rs index b85983ff5..058329adb 100644 --- a/gstreamer/src/enums.rs +++ b/gstreamer/src/enums.rs @@ -684,4 +684,36 @@ impl StateChange { StateChange::__Unknown(value) => State::__Unknown(value & 0x7), } } + + pub fn get_name<'a>(self) -> &'a str { + cfg_if::cfg_if! { + if #[cfg(feature = "v1_14")] { + // This implementation is autogenerated on 1.14 and up + use std::ffi::CStr; + unsafe { + CStr::from_ptr( + ffi::gst_state_change_get_name(self.to_glib()) + .as_ref() + .expect("gst_state_change_get_name returned NULL"), + ) + .to_str() + .expect("gst_state_change_get_name returned an invalid string") + } + } else { + match self { + Self::NullToReady => "NULL->READY", + Self::ReadyToPaused => "READY->PAUSED", + Self::PausedToPlaying => "PAUSED->PLAYING", + Self::PlayingToPaused => "PLAYING->PAUSED", + Self::PausedToReady => "PAUSED->READY", + Self::ReadyToNull => "READY->NULL", + Self::NullToNull => "NULL->NULL", + Self::ReadyToReady => "READY->READY", + Self::PausedToPaused => "PAUSED->PAUSED", + Self::PlayingToPlaying => "PLAYING->PLAYING", + _ => "Unknown state return", + } + } + } + } }