2017-11-05 17:58:44 +00:00
|
|
|
// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::ClockReturn;
|
|
|
|
use crate::FlowReturn;
|
|
|
|
use crate::PadLinkReturn;
|
|
|
|
use crate::State;
|
|
|
|
use crate::StateChange;
|
|
|
|
use crate::StateChangeReturn;
|
2019-06-04 07:21:26 +00:00
|
|
|
use std::{cmp, ops};
|
2020-01-10 11:33:03 +00:00
|
|
|
use thiserror::Error;
|
2017-12-19 17:13:54 +00:00
|
|
|
|
2019-05-10 16:07:02 +00:00
|
|
|
use glib::translate::*;
|
|
|
|
use glib::value::FromValue;
|
|
|
|
use glib::value::FromValueOptional;
|
|
|
|
use glib::value::SetValue;
|
|
|
|
use glib::value::Value;
|
|
|
|
use glib::StaticType;
|
|
|
|
use glib::Type;
|
2017-11-05 17:58:44 +00:00
|
|
|
|
|
|
|
impl StateChangeReturn {
|
|
|
|
pub fn into_result(self) -> Result<StateChangeSuccess, StateChangeError> {
|
|
|
|
match self {
|
|
|
|
StateChangeReturn::Success => Ok(StateChangeSuccess::Success),
|
|
|
|
StateChangeReturn::Async => Ok(StateChangeSuccess::Async),
|
|
|
|
StateChangeReturn::NoPreroll => Ok(StateChangeSuccess::NoPreroll),
|
|
|
|
StateChangeReturn::Failure => Err(StateChangeError),
|
|
|
|
_ => Err(StateChangeError),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_error(_: StateChangeError) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2017-11-05 17:58:44 +00:00
|
|
|
StateChangeReturn::Failure
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_ok(v: StateChangeSuccess) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2017-11-05 17:58:44 +00:00
|
|
|
match v {
|
|
|
|
StateChangeSuccess::Success => StateChangeReturn::Success,
|
|
|
|
StateChangeSuccess::Async => StateChangeReturn::Async,
|
|
|
|
StateChangeSuccess::NoPreroll => StateChangeReturn::NoPreroll,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
|
|
|
pub enum StateChangeSuccess {
|
|
|
|
Success,
|
|
|
|
Async,
|
|
|
|
NoPreroll,
|
|
|
|
}
|
|
|
|
|
2018-10-28 17:40:00 +00:00
|
|
|
impl From<StateChangeSuccess> for StateChangeReturn {
|
|
|
|
fn from(value: StateChangeSuccess) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2018-10-28 17:40:00 +00:00
|
|
|
StateChangeReturn::from_ok(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-10 11:33:03 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)]
|
2017-11-05 17:58:44 +00:00
|
|
|
#[must_use]
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Element failed to change its state")]
|
2017-11-05 17:58:44 +00:00
|
|
|
pub struct StateChangeError;
|
|
|
|
|
2018-10-28 17:40:00 +00:00
|
|
|
impl From<StateChangeError> for StateChangeReturn {
|
|
|
|
fn from(value: StateChangeError) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2018-10-28 17:40:00 +00:00
|
|
|
StateChangeReturn::from_error(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
impl From<Result<StateChangeSuccess, StateChangeError>> for StateChangeReturn {
|
|
|
|
fn from(res: Result<StateChangeSuccess, StateChangeError>) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2019-01-08 16:13:37 +00:00
|
|
|
match res {
|
|
|
|
Ok(success) => StateChangeReturn::from_ok(success),
|
|
|
|
Err(error) => StateChangeReturn::from_error(error),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-05 17:58:44 +00:00
|
|
|
impl FlowReturn {
|
|
|
|
pub fn into_result(self) -> Result<FlowSuccess, FlowError> {
|
|
|
|
match self {
|
|
|
|
FlowReturn::CustomSuccess2 => Ok(FlowSuccess::CustomSuccess2),
|
|
|
|
FlowReturn::CustomSuccess1 => Ok(FlowSuccess::CustomSuccess1),
|
|
|
|
FlowReturn::CustomSuccess => Ok(FlowSuccess::CustomSuccess),
|
|
|
|
FlowReturn::Ok => Ok(FlowSuccess::Ok),
|
|
|
|
FlowReturn::NotLinked => Err(FlowError::NotLinked),
|
|
|
|
FlowReturn::Flushing => Err(FlowError::Flushing),
|
|
|
|
FlowReturn::Eos => Err(FlowError::Eos),
|
|
|
|
FlowReturn::NotNegotiated => Err(FlowError::NotNegotiated),
|
|
|
|
FlowReturn::Error => Err(FlowError::Error),
|
|
|
|
FlowReturn::NotSupported => Err(FlowError::NotSupported),
|
|
|
|
FlowReturn::CustomError => Err(FlowError::CustomError),
|
|
|
|
FlowReturn::CustomError1 => Err(FlowError::CustomError1),
|
|
|
|
FlowReturn::CustomError2 => Err(FlowError::CustomError2),
|
|
|
|
_ => Err(FlowError::Error),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-28 22:57:21 +00:00
|
|
|
pub fn into_result_value<T, F: FnOnce() -> T>(self, func: F) -> Result<T, FlowError> {
|
|
|
|
match self.into_result() {
|
|
|
|
Ok(_) => Ok(func()),
|
|
|
|
Err(err) => Err(err),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-05 17:58:44 +00:00
|
|
|
pub fn from_error(v: FlowError) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2017-11-05 17:58:44 +00:00
|
|
|
match v {
|
|
|
|
FlowError::NotLinked => FlowReturn::NotLinked,
|
|
|
|
FlowError::Flushing => FlowReturn::Flushing,
|
|
|
|
FlowError::Eos => FlowReturn::Eos,
|
|
|
|
FlowError::NotNegotiated => FlowReturn::NotNegotiated,
|
|
|
|
FlowError::Error => FlowReturn::Error,
|
|
|
|
FlowError::NotSupported => FlowReturn::NotSupported,
|
|
|
|
FlowError::CustomError => FlowReturn::CustomError,
|
|
|
|
FlowError::CustomError1 => FlowReturn::CustomError1,
|
|
|
|
FlowError::CustomError2 => FlowReturn::CustomError2,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_ok(v: FlowSuccess) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2017-11-05 17:58:44 +00:00
|
|
|
match v {
|
|
|
|
FlowSuccess::CustomSuccess2 => FlowReturn::CustomSuccess2,
|
|
|
|
FlowSuccess::CustomSuccess1 => FlowReturn::CustomSuccess1,
|
|
|
|
FlowSuccess::CustomSuccess => FlowReturn::CustomSuccess,
|
|
|
|
FlowSuccess::Ok => FlowReturn::Ok,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
|
|
|
pub enum FlowSuccess {
|
|
|
|
CustomSuccess2,
|
|
|
|
CustomSuccess1,
|
|
|
|
CustomSuccess,
|
|
|
|
Ok,
|
|
|
|
}
|
|
|
|
|
2018-10-28 17:40:00 +00:00
|
|
|
impl From<FlowSuccess> for FlowReturn {
|
|
|
|
fn from(value: FlowSuccess) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2018-10-28 17:40:00 +00:00
|
|
|
FlowReturn::from_ok(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-10 11:33:03 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)]
|
2017-11-05 17:58:44 +00:00
|
|
|
#[must_use]
|
|
|
|
pub enum FlowError {
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Pad is not linked")]
|
2017-11-05 17:58:44 +00:00
|
|
|
NotLinked,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Pad is flushing")]
|
2017-11-05 17:58:44 +00:00
|
|
|
Flushing,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Pad is EOS")]
|
2017-11-05 17:58:44 +00:00
|
|
|
Eos,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Pad is not negotiated")]
|
2017-11-05 17:58:44 +00:00
|
|
|
NotNegotiated,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Some (fatal) error occurred. Element generating this error should post an error message with more details")]
|
2017-11-05 17:58:44 +00:00
|
|
|
Error,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("This operation is not supported")]
|
2017-11-05 17:58:44 +00:00
|
|
|
NotSupported,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Elements can use values starting from this (and lower) to define custom error codes")]
|
2017-11-05 17:58:44 +00:00
|
|
|
CustomError,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Pre-defined custom error code")]
|
2017-11-05 17:58:44 +00:00
|
|
|
CustomError1,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Pre-defined custom error code")]
|
2017-11-05 17:58:44 +00:00
|
|
|
CustomError2,
|
|
|
|
}
|
|
|
|
|
2018-10-28 17:40:00 +00:00
|
|
|
impl From<FlowError> for FlowReturn {
|
|
|
|
fn from(value: FlowError) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2018-10-28 17:40:00 +00:00
|
|
|
FlowReturn::from_error(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
impl From<Result<FlowSuccess, FlowError>> for FlowReturn {
|
|
|
|
fn from(res: Result<FlowSuccess, FlowError>) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2019-01-08 16:13:37 +00:00
|
|
|
match res {
|
|
|
|
Ok(success) => FlowReturn::from_ok(success),
|
|
|
|
Err(error) => FlowReturn::from_error(error),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-05 17:58:44 +00:00
|
|
|
impl PadLinkReturn {
|
|
|
|
pub fn into_result(self) -> Result<PadLinkSuccess, PadLinkError> {
|
|
|
|
match self {
|
|
|
|
PadLinkReturn::Ok => Ok(PadLinkSuccess),
|
|
|
|
PadLinkReturn::WrongHierarchy => Err(PadLinkError::WrongHierarchy),
|
|
|
|
PadLinkReturn::WasLinked => Err(PadLinkError::WasLinked),
|
|
|
|
PadLinkReturn::WrongDirection => Err(PadLinkError::WrongDirection),
|
|
|
|
PadLinkReturn::Noformat => Err(PadLinkError::Noformat),
|
|
|
|
PadLinkReturn::Nosched => Err(PadLinkError::Nosched),
|
|
|
|
PadLinkReturn::Refused => Err(PadLinkError::Refused),
|
|
|
|
_ => Err(PadLinkError::Refused),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_error(v: PadLinkError) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2017-11-05 17:58:44 +00:00
|
|
|
match v {
|
|
|
|
PadLinkError::WrongHierarchy => PadLinkReturn::WrongHierarchy,
|
|
|
|
PadLinkError::WasLinked => PadLinkReturn::WasLinked,
|
|
|
|
PadLinkError::WrongDirection => PadLinkReturn::WrongDirection,
|
|
|
|
PadLinkError::Noformat => PadLinkReturn::Noformat,
|
|
|
|
PadLinkError::Nosched => PadLinkReturn::Nosched,
|
|
|
|
PadLinkError::Refused => PadLinkReturn::Refused,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_ok(_: PadLinkSuccess) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2017-11-05 17:58:44 +00:00
|
|
|
PadLinkReturn::Ok
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
|
|
|
pub struct PadLinkSuccess;
|
|
|
|
|
2018-10-28 17:40:00 +00:00
|
|
|
impl From<PadLinkSuccess> for PadLinkReturn {
|
|
|
|
fn from(value: PadLinkSuccess) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2018-10-28 17:40:00 +00:00
|
|
|
PadLinkReturn::from_ok(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-10 11:33:03 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)]
|
2017-11-05 17:58:44 +00:00
|
|
|
#[must_use]
|
|
|
|
pub enum PadLinkError {
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Pads have no common grandparent")]
|
2017-11-05 17:58:44 +00:00
|
|
|
WrongHierarchy,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Pad was already linked")]
|
2017-11-05 17:58:44 +00:00
|
|
|
WasLinked,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Pads have wrong direction")]
|
2017-11-05 17:58:44 +00:00
|
|
|
WrongDirection,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Pads do not have common format")]
|
2017-11-05 17:58:44 +00:00
|
|
|
Noformat,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Pads cannot cooperate in scheduling")]
|
2017-11-05 17:58:44 +00:00
|
|
|
Nosched,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Refused for some other reason")]
|
2017-11-05 17:58:44 +00:00
|
|
|
Refused,
|
|
|
|
}
|
|
|
|
|
2018-10-28 17:40:00 +00:00
|
|
|
impl From<PadLinkError> for PadLinkReturn {
|
|
|
|
fn from(value: PadLinkError) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2018-10-28 17:40:00 +00:00
|
|
|
PadLinkReturn::from_error(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
impl From<Result<PadLinkSuccess, PadLinkError>> for PadLinkReturn {
|
|
|
|
fn from(res: Result<PadLinkSuccess, PadLinkError>) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2019-01-08 16:13:37 +00:00
|
|
|
match res {
|
|
|
|
Ok(success) => PadLinkReturn::from_ok(success),
|
|
|
|
Err(error) => PadLinkReturn::from_error(error),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-05 17:58:44 +00:00
|
|
|
impl ClockReturn {
|
|
|
|
pub fn into_result(self) -> Result<ClockSuccess, ClockError> {
|
|
|
|
match self {
|
|
|
|
ClockReturn::Ok => Ok(ClockSuccess::Ok),
|
|
|
|
ClockReturn::Done => Ok(ClockSuccess::Done),
|
|
|
|
ClockReturn::Early => Err(ClockError::Early),
|
|
|
|
ClockReturn::Unscheduled => Err(ClockError::Unscheduled),
|
|
|
|
ClockReturn::Busy => Err(ClockError::Busy),
|
|
|
|
ClockReturn::Badtime => Err(ClockError::Badtime),
|
|
|
|
ClockReturn::Error => Err(ClockError::Error),
|
|
|
|
ClockReturn::Unsupported => Err(ClockError::Unsupported),
|
|
|
|
_ => Err(ClockError::Error),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_error(v: ClockError) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2017-11-05 17:58:44 +00:00
|
|
|
match v {
|
|
|
|
ClockError::Early => ClockReturn::Early,
|
|
|
|
ClockError::Unscheduled => ClockReturn::Unscheduled,
|
|
|
|
ClockError::Busy => ClockReturn::Busy,
|
|
|
|
ClockError::Badtime => ClockReturn::Badtime,
|
|
|
|
ClockError::Error => ClockReturn::Error,
|
|
|
|
ClockError::Unsupported => ClockReturn::Unsupported,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_ok(v: ClockSuccess) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2017-11-05 17:58:44 +00:00
|
|
|
match v {
|
|
|
|
ClockSuccess::Ok => ClockReturn::Ok,
|
|
|
|
ClockSuccess::Done => ClockReturn::Done,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
|
|
|
pub enum ClockSuccess {
|
|
|
|
Ok,
|
|
|
|
Done,
|
|
|
|
}
|
|
|
|
|
2018-10-28 17:40:00 +00:00
|
|
|
impl From<ClockSuccess> for ClockReturn {
|
|
|
|
fn from(value: ClockSuccess) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2018-10-28 17:40:00 +00:00
|
|
|
ClockReturn::from_ok(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-10 11:33:03 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)]
|
2017-11-05 17:58:44 +00:00
|
|
|
#[must_use]
|
|
|
|
pub enum ClockError {
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("The operation was scheduled too late")]
|
2017-11-05 17:58:44 +00:00
|
|
|
Early,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("The clockID was unscheduled")]
|
2017-11-05 17:58:44 +00:00
|
|
|
Unscheduled,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("The ClockID is busy")]
|
2017-11-05 17:58:44 +00:00
|
|
|
Busy,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("A bad time was provided to a function")]
|
2017-11-05 17:58:44 +00:00
|
|
|
Badtime,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("An error occurred")]
|
2017-11-05 17:58:44 +00:00
|
|
|
Error,
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("Operation is not supported")]
|
2017-11-05 17:58:44 +00:00
|
|
|
Unsupported,
|
|
|
|
}
|
2017-11-10 11:41:06 +00:00
|
|
|
|
2018-10-28 17:40:00 +00:00
|
|
|
impl From<ClockError> for ClockReturn {
|
|
|
|
fn from(value: ClockError) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2018-10-28 17:40:00 +00:00
|
|
|
ClockReturn::from_error(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
impl From<Result<ClockSuccess, ClockError>> for ClockReturn {
|
|
|
|
fn from(res: Result<ClockSuccess, ClockError>) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2019-01-08 16:13:37 +00:00
|
|
|
match res {
|
|
|
|
Ok(success) => ClockReturn::from_ok(success),
|
|
|
|
Err(error) => ClockReturn::from_error(error),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl PartialEq for crate::TypeFindProbability {
|
|
|
|
fn eq(&self, other: &crate::TypeFindProbability) -> bool {
|
2019-06-04 07:47:38 +00:00
|
|
|
(self.to_glib() as u32).eq(&(other.to_glib() as u32))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl Eq for crate::TypeFindProbability {}
|
2019-06-04 07:47:38 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl PartialOrd for crate::TypeFindProbability {
|
2017-12-19 17:13:54 +00:00
|
|
|
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
|
2019-06-04 07:47:38 +00:00
|
|
|
(self.to_glib() as u32).partial_cmp(&(other.to_glib() as u32))
|
2017-12-19 17:13:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl Ord for crate::TypeFindProbability {
|
2017-12-19 17:13:54 +00:00
|
|
|
fn cmp(&self, other: &Self) -> cmp::Ordering {
|
2019-06-04 07:47:38 +00:00
|
|
|
(self.to_glib() as u32).cmp(&(other.to_glib() as u32))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl ops::Add<u32> for crate::TypeFindProbability {
|
|
|
|
type Output = crate::TypeFindProbability;
|
2019-06-04 07:47:38 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn add(self, rhs: u32) -> crate::TypeFindProbability {
|
2019-06-04 07:47:38 +00:00
|
|
|
let res = (self.to_glib() as u32).saturating_add(rhs);
|
|
|
|
from_glib(res as i32)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl ops::AddAssign<u32> for crate::TypeFindProbability {
|
2019-06-04 07:47:38 +00:00
|
|
|
fn add_assign(&mut self, rhs: u32) {
|
|
|
|
let res = (self.to_glib() as u32).saturating_add(rhs);
|
|
|
|
*self = from_glib(res as i32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl ops::Sub<u32> for crate::TypeFindProbability {
|
|
|
|
type Output = crate::TypeFindProbability;
|
2019-06-04 07:47:38 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn sub(self, rhs: u32) -> crate::TypeFindProbability {
|
2019-06-04 07:47:38 +00:00
|
|
|
let res = (self.to_glib() as u32).saturating_sub(rhs);
|
|
|
|
from_glib(res as i32)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl ops::SubAssign<u32> for crate::TypeFindProbability {
|
2019-06-04 07:47:38 +00:00
|
|
|
fn sub_assign(&mut self, rhs: u32) {
|
|
|
|
let res = (self.to_glib() as u32).saturating_sub(rhs);
|
|
|
|
*self = from_glib(res as i32);
|
2017-12-19 17:13:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl PartialEq for crate::Rank {
|
|
|
|
fn eq(&self, other: &crate::Rank) -> bool {
|
2019-06-04 07:21:26 +00:00
|
|
|
(self.to_glib() as u32).eq(&(other.to_glib() as u32))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl Eq for crate::Rank {}
|
2019-06-04 07:21:26 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl PartialOrd for crate::Rank {
|
2017-12-19 17:13:54 +00:00
|
|
|
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
|
2019-06-04 07:21:26 +00:00
|
|
|
(self.to_glib() as u32).partial_cmp(&(other.to_glib() as u32))
|
2017-12-19 17:13:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl Ord for crate::Rank {
|
2017-12-19 17:13:54 +00:00
|
|
|
fn cmp(&self, other: &Self) -> cmp::Ordering {
|
2019-06-04 07:21:26 +00:00
|
|
|
(self.to_glib() as u32).cmp(&(other.to_glib() as u32))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl ops::Add<u32> for crate::Rank {
|
|
|
|
type Output = crate::Rank;
|
2019-06-04 07:21:26 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn add(self, rhs: u32) -> crate::Rank {
|
2019-06-04 07:21:26 +00:00
|
|
|
let res = (self.to_glib() as u32).saturating_add(rhs);
|
|
|
|
from_glib(res as i32)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl ops::AddAssign<u32> for crate::Rank {
|
2019-06-04 07:21:26 +00:00
|
|
|
fn add_assign(&mut self, rhs: u32) {
|
|
|
|
let res = (self.to_glib() as u32).saturating_add(rhs);
|
|
|
|
*self = from_glib(res as i32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl ops::Sub<u32> for crate::Rank {
|
|
|
|
type Output = crate::Rank;
|
2019-06-04 07:21:26 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn sub(self, rhs: u32) -> crate::Rank {
|
2019-06-04 07:21:26 +00:00
|
|
|
let res = (self.to_glib() as u32).saturating_sub(rhs);
|
|
|
|
from_glib(res as i32)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl ops::SubAssign<u32> for crate::Rank {
|
2019-06-04 07:21:26 +00:00
|
|
|
fn sub_assign(&mut self, rhs: u32) {
|
|
|
|
let res = (self.to_glib() as u32).saturating_sub(rhs);
|
|
|
|
*self = from_glib(res as i32);
|
2017-12-19 17:13:54 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-08 16:42:06 +00:00
|
|
|
|
2020-01-10 11:33:03 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)]
|
2018-07-08 16:42:06 +00:00
|
|
|
#[must_use]
|
|
|
|
pub enum TagError {
|
2020-01-10 11:33:03 +00:00
|
|
|
#[error("The value type doesn't match with the specified Tag")]
|
2018-07-08 16:42:06 +00:00
|
|
|
TypeMismatch,
|
|
|
|
}
|
|
|
|
|
2019-05-10 16:07:02 +00:00
|
|
|
// This cannot be done automatically because in GStreamer it's exposed as a bitflag but works as an
|
|
|
|
// enum instead
|
|
|
|
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
|
|
|
pub enum MessageType {
|
|
|
|
Unknown,
|
|
|
|
Eos,
|
|
|
|
Error,
|
|
|
|
Warning,
|
|
|
|
Info,
|
|
|
|
Tag,
|
|
|
|
Buffering,
|
|
|
|
StateChanged,
|
|
|
|
StateDirty,
|
|
|
|
StepDone,
|
|
|
|
ClockProvide,
|
|
|
|
ClockLost,
|
|
|
|
NewClock,
|
|
|
|
StructureChange,
|
|
|
|
StreamStatus,
|
|
|
|
Application,
|
|
|
|
Element,
|
|
|
|
SegmentStart,
|
|
|
|
SegmentDone,
|
|
|
|
DurationChanged,
|
|
|
|
Latency,
|
|
|
|
AsyncStart,
|
|
|
|
AsyncDone,
|
|
|
|
RequestState,
|
|
|
|
StepStart,
|
|
|
|
Qos,
|
|
|
|
Progress,
|
|
|
|
Toc,
|
|
|
|
ResetTime,
|
|
|
|
StreamStart,
|
|
|
|
NeedContext,
|
|
|
|
HaveContext,
|
|
|
|
Extended,
|
|
|
|
DeviceAdded,
|
|
|
|
DeviceRemoved,
|
|
|
|
PropertyNotify,
|
|
|
|
StreamCollection,
|
|
|
|
StreamsSelected,
|
|
|
|
Redirect,
|
|
|
|
#[doc(hidden)]
|
|
|
|
__Unknown(i32),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
impl ToGlib for MessageType {
|
2020-11-21 13:46:48 +00:00
|
|
|
type GlibType = ffi::GstMessageType;
|
2019-05-10 16:07:02 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn to_glib(&self) -> ffi::GstMessageType {
|
2019-05-10 16:07:02 +00:00
|
|
|
match *self {
|
2020-11-21 13:46:48 +00:00
|
|
|
MessageType::Unknown => ffi::GST_MESSAGE_UNKNOWN,
|
|
|
|
MessageType::Eos => ffi::GST_MESSAGE_EOS,
|
|
|
|
MessageType::Error => ffi::GST_MESSAGE_ERROR,
|
|
|
|
MessageType::Warning => ffi::GST_MESSAGE_WARNING,
|
|
|
|
MessageType::Info => ffi::GST_MESSAGE_INFO,
|
|
|
|
MessageType::Tag => ffi::GST_MESSAGE_TAG,
|
|
|
|
MessageType::Buffering => ffi::GST_MESSAGE_BUFFERING,
|
|
|
|
MessageType::StateChanged => ffi::GST_MESSAGE_STATE_CHANGED,
|
|
|
|
MessageType::StateDirty => ffi::GST_MESSAGE_STATE_DIRTY,
|
|
|
|
MessageType::StepDone => ffi::GST_MESSAGE_STEP_DONE,
|
|
|
|
MessageType::ClockProvide => ffi::GST_MESSAGE_CLOCK_PROVIDE,
|
|
|
|
MessageType::ClockLost => ffi::GST_MESSAGE_CLOCK_LOST,
|
|
|
|
MessageType::NewClock => ffi::GST_MESSAGE_NEW_CLOCK,
|
|
|
|
MessageType::StructureChange => ffi::GST_MESSAGE_STRUCTURE_CHANGE,
|
|
|
|
MessageType::StreamStatus => ffi::GST_MESSAGE_STREAM_STATUS,
|
|
|
|
MessageType::Application => ffi::GST_MESSAGE_APPLICATION,
|
|
|
|
MessageType::Element => ffi::GST_MESSAGE_ELEMENT,
|
|
|
|
MessageType::SegmentStart => ffi::GST_MESSAGE_SEGMENT_START,
|
|
|
|
MessageType::SegmentDone => ffi::GST_MESSAGE_SEGMENT_DONE,
|
|
|
|
MessageType::DurationChanged => ffi::GST_MESSAGE_DURATION_CHANGED,
|
|
|
|
MessageType::Latency => ffi::GST_MESSAGE_LATENCY,
|
|
|
|
MessageType::AsyncStart => ffi::GST_MESSAGE_ASYNC_START,
|
|
|
|
MessageType::AsyncDone => ffi::GST_MESSAGE_ASYNC_DONE,
|
|
|
|
MessageType::RequestState => ffi::GST_MESSAGE_REQUEST_STATE,
|
|
|
|
MessageType::StepStart => ffi::GST_MESSAGE_STEP_START,
|
|
|
|
MessageType::Qos => ffi::GST_MESSAGE_QOS,
|
|
|
|
MessageType::Progress => ffi::GST_MESSAGE_PROGRESS,
|
|
|
|
MessageType::Toc => ffi::GST_MESSAGE_TOC,
|
|
|
|
MessageType::ResetTime => ffi::GST_MESSAGE_RESET_TIME,
|
|
|
|
MessageType::StreamStart => ffi::GST_MESSAGE_STREAM_START,
|
|
|
|
MessageType::NeedContext => ffi::GST_MESSAGE_NEED_CONTEXT,
|
|
|
|
MessageType::HaveContext => ffi::GST_MESSAGE_HAVE_CONTEXT,
|
|
|
|
MessageType::Extended => ffi::GST_MESSAGE_EXTENDED,
|
|
|
|
MessageType::DeviceAdded => ffi::GST_MESSAGE_DEVICE_ADDED,
|
|
|
|
MessageType::DeviceRemoved => ffi::GST_MESSAGE_DEVICE_REMOVED,
|
|
|
|
MessageType::PropertyNotify => ffi::GST_MESSAGE_PROPERTY_NOTIFY,
|
|
|
|
MessageType::StreamCollection => ffi::GST_MESSAGE_STREAM_COLLECTION,
|
|
|
|
MessageType::StreamsSelected => ffi::GST_MESSAGE_STREAMS_SELECTED,
|
|
|
|
MessageType::Redirect => ffi::GST_MESSAGE_REDIRECT,
|
2019-05-10 16:07:02 +00:00
|
|
|
MessageType::__Unknown(value) => value as u32,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2020-11-21 13:46:48 +00:00
|
|
|
impl FromGlib<ffi::GstMessageType> for MessageType {
|
2019-07-11 15:50:37 +00:00
|
|
|
#[allow(clippy::unreadable_literal)]
|
2020-11-21 13:46:48 +00:00
|
|
|
fn from_glib(value: ffi::GstMessageType) -> Self {
|
2019-05-10 16:07:02 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
match value {
|
|
|
|
0 => MessageType::Unknown,
|
|
|
|
1 => MessageType::Eos,
|
|
|
|
2 => MessageType::Error,
|
|
|
|
4 => MessageType::Warning,
|
|
|
|
8 => MessageType::Info,
|
|
|
|
16 => MessageType::Tag,
|
|
|
|
32 => MessageType::Buffering,
|
|
|
|
64 => MessageType::StateChanged,
|
|
|
|
128 => MessageType::StateDirty,
|
|
|
|
256 => MessageType::StepDone,
|
|
|
|
512 => MessageType::ClockProvide,
|
|
|
|
1024 => MessageType::ClockLost,
|
|
|
|
2048 => MessageType::NewClock,
|
|
|
|
4096 => MessageType::StructureChange,
|
|
|
|
8192 => MessageType::StreamStatus,
|
|
|
|
16384 => MessageType::Application,
|
|
|
|
32768 => MessageType::Element,
|
|
|
|
65536 => MessageType::SegmentStart,
|
|
|
|
131072 => MessageType::SegmentDone,
|
|
|
|
262144 => MessageType::DurationChanged,
|
|
|
|
524288 => MessageType::Latency,
|
|
|
|
1048576 => MessageType::AsyncStart,
|
|
|
|
2097152 => MessageType::AsyncDone,
|
|
|
|
4194304 => MessageType::RequestState,
|
|
|
|
8388608 => MessageType::StepStart,
|
|
|
|
16777216 => MessageType::Qos,
|
|
|
|
33554432 => MessageType::Progress,
|
|
|
|
67108864 => MessageType::Toc,
|
|
|
|
134217728 => MessageType::ResetTime,
|
|
|
|
268435456 => MessageType::StreamStart,
|
|
|
|
536870912 => MessageType::NeedContext,
|
|
|
|
1073741824 => MessageType::HaveContext,
|
|
|
|
2147483648 => MessageType::Extended,
|
|
|
|
2147483649 => MessageType::DeviceAdded,
|
|
|
|
2147483650 => MessageType::DeviceRemoved,
|
|
|
|
2147483651 => MessageType::PropertyNotify,
|
|
|
|
2147483652 => MessageType::StreamCollection,
|
|
|
|
2147483653 => MessageType::StreamsSelected,
|
|
|
|
2147483654 => MessageType::Redirect,
|
|
|
|
value => MessageType::__Unknown(value as i32),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl StaticType for MessageType {
|
|
|
|
fn static_type() -> Type {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_message_type_get_type()) }
|
2019-05-10 16:07:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> FromValueOptional<'a> for MessageType {
|
|
|
|
unsafe fn from_value_optional(value: &Value) -> Option<Self> {
|
|
|
|
Some(FromValue::from_value(value))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> FromValue<'a> for MessageType {
|
|
|
|
unsafe fn from_value(value: &Value) -> Self {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(glib::gobject_ffi::g_value_get_flags(value.to_glib_none().0))
|
2019-05-10 16:07:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SetValue for MessageType {
|
|
|
|
unsafe fn set_value(value: &mut Value, this: &Self) {
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib())
|
2019-05-10 16:07:02 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-18 06:09:18 +00:00
|
|
|
|
|
|
|
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),
|
|
|
|
}
|
|
|
|
}
|
2020-12-05 21:42:49 +00:00
|
|
|
|
|
|
|
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",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-18 06:09:18 +00:00
|
|
|
}
|