gstreamer: Add some API to calculate the next state convert state changes into their component states and back

This commit is contained in:
Sebastian Dröge 2020-04-18 09:09:18 +03:00
parent 77af65634f
commit caae679d6f

View file

@ -11,6 +11,8 @@ use thiserror::Error;
use ClockReturn;
use FlowReturn;
use PadLinkReturn;
use State;
use StateChange;
use StateChangeReturn;
use glib::translate::*;
@ -631,3 +633,55 @@ impl SetValue for MessageType {
gobject_sys::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib())
}
}
impl State {
pub fn next(self, pending: Self) -> Self {
let current = self.to_glib();
let pending = pending.to_glib();
let sign = (pending - current).signum();
from_glib(current + sign)
}
}
impl StateChange {
pub fn new(current: State, next: State) -> Self {
skip_assert_initialized!();
let current = current.to_glib();
let next = next.to_glib();
from_glib((current << 3) | next)
}
pub fn current(self) -> State {
match self {
StateChange::NullToReady => State::Null,
StateChange::ReadyToPaused => State::Ready,
StateChange::PausedToPlaying => State::Paused,
StateChange::PlayingToPaused => State::Playing,
StateChange::PausedToReady => State::Paused,
StateChange::ReadyToNull => State::Ready,
StateChange::NullToNull => State::Null,
StateChange::ReadyToReady => State::Ready,
StateChange::PausedToPaused => State::Paused,
StateChange::PlayingToPlaying => State::Playing,
StateChange::__Unknown(value) => State::__Unknown(value >> 3),
}
}
pub fn next(self) -> State {
match self {
StateChange::NullToReady => State::Ready,
StateChange::ReadyToPaused => State::Paused,
StateChange::PausedToPlaying => State::Playing,
StateChange::PlayingToPaused => State::Paused,
StateChange::PausedToReady => State::Ready,
StateChange::ReadyToNull => State::Null,
StateChange::NullToNull => State::Null,
StateChange::ReadyToReady => State::Ready,
StateChange::PausedToPaused => State::Paused,
StateChange::PlayingToPlaying => State::Playing,
StateChange::__Unknown(value) => State::__Unknown(value & 0x7),
}
}
}