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.
This commit is contained in:
Marijn Suijten 2020-12-05 22:42:49 +01:00
parent 1b1a99b320
commit 01ae47c90c
2 changed files with 42 additions and 1 deletions

View file

@ -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"

View file

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