From 2cb7fc8122c5564221b29ff8190bbf6b79134e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 10 Aug 2022 12:10:43 +0300 Subject: [PATCH] gstreamer: Add GstParamSpecBuilderExt trait to easily allow setting controllable, mutable-ready and other extension flags --- gstreamer/src/lib.rs | 2 ++ gstreamer/src/param_spec.rs | 49 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 322adf302..6322c87aa 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -342,6 +342,8 @@ pub mod prelude { pub use crate::tags::{CustomTag, Tag}; + pub use crate::param_spec::GstParamSpecBuilderExt; + pub use muldiv::MulDiv; pub use crate::format::{ diff --git a/gstreamer/src/param_spec.rs b/gstreamer/src/param_spec.rs index b01c99b0d..03cc05fff 100644 --- a/gstreamer/src/param_spec.rs +++ b/gstreamer/src/param_spec.rs @@ -306,6 +306,54 @@ impl<'a> glib::prelude::ParamSpecBuilderExt<'a> for ParamSpecArrayBuilder<'a> { } } +pub trait GstParamSpecBuilderExt<'a>: glib::prelude::ParamSpecBuilderExt<'a> { + // rustdoc-stripper-ignore-next + /// Mark the property as controllable + fn controllable(self) -> Self { + let flags = self.current_flags() | crate::PARAM_FLAG_CONTROLLABLE; + self.flags(flags) + } + + // rustdoc-stripper-ignore-next + /// Mark the property as mutable in ready state + fn mutable_ready(self) -> Self { + let flags = self.current_flags() | crate::PARAM_FLAG_MUTABLE_READY; + self.flags(flags) + } + + // rustdoc-stripper-ignore-next + /// Mark the property as mutable in paused state + fn mutable_paused(self) -> Self { + let flags = self.current_flags() | crate::PARAM_FLAG_MUTABLE_PAUSED; + self.flags(flags) + } + + // rustdoc-stripper-ignore-next + /// Mark the property as mutable in playing state + fn mutable_playing(self) -> Self { + let flags = self.current_flags() | crate::PARAM_FLAG_MUTABLE_PLAYING; + self.flags(flags) + } + + #[cfg(any(feature = "v1_18", feature = "dox"))] + // rustdoc-stripper-ignore-next + /// Mark the property for showing the default value in the docs + fn doc_show_default(self) -> Self { + let flags = self.current_flags() | crate::PARAM_FLAG_DOC_SHOW_DEFAULT; + self.flags(flags) + } + + #[cfg(any(feature = "v1_18", feature = "dox"))] + // rustdoc-stripper-ignore-next + /// Mark the property for being only conditionally available + fn conditionally_available(self) -> Self { + let flags = self.current_flags() | crate::PARAM_FLAG_CONDITIONALLY_AVAILABLE; + self.flags(flags) + } +} + +impl<'a, T: glib::prelude::ParamSpecBuilderExt<'a>> GstParamSpecBuilderExt<'a> for T {} + #[cfg(test)] mod tests { use super::*; @@ -332,6 +380,7 @@ mod tests { .maximum((100, 1).into()) .default_value((1, 1).into()) .readwrite() + .mutable_playing() .build(); } }