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", + } + } + } + } }