From 12b4a9a03d48d74a9ff3da97ec62ee15300deb92 Mon Sep 17 00:00:00 2001 From: SeaDve Date: Tue, 14 Feb 2023 23:37:43 +0800 Subject: [PATCH] gstreamer: implement HasParamSpec for ClockTime Part-of: --- gstreamer/src/format/clock_time.rs | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/gstreamer/src/format/clock_time.rs b/gstreamer/src/format/clock_time.rs index 4504272b6..39774612e 100644 --- a/gstreamer/src/format/clock_time.rs +++ b/gstreamer/src/format/clock_time.rs @@ -368,6 +368,16 @@ impl glib::StaticType for ClockTime { } } +impl glib::HasParamSpec for ClockTime { + type ParamSpec = glib::ParamSpecUInt64; + type SetValue = Self; + type BuilderFn = fn(&str) -> glib::ParamSpecUInt64Builder; + + fn param_spec_builder() -> Self::BuilderFn { + Self::ParamSpec::builder + } +} + #[derive(Debug)] pub struct DurationError; @@ -1418,4 +1428,54 @@ mod tests { assert_eq!(i64::MIN as i128, -(((u64::MAX >> 1) + 1) as i128)); assert_eq!(i64::try_from(time), Ok(i64::MIN)); } + + #[test] + fn properties_macro_usage() { + use super::ClockTime; + use glib::{prelude::*, subclass::prelude::*, ParamSpecBuilderExt}; + use std::cell::Cell; + + #[derive(Default, glib::Properties)] + #[properties(wrapper_type = TestObject)] + pub struct TestObjectImp { + #[property(get, set)] + clock_time: Cell, + #[property(get, set)] + optional_clock_time: Cell>, + } + + #[glib::object_subclass] + impl ObjectSubclass for TestObjectImp { + const NAME: &'static str = "GstTestObject"; + type Type = TestObject; + } + + impl ObjectImpl for TestObjectImp { + fn properties() -> &'static [glib::ParamSpec] { + Self::derived_properties() + } + + fn set_property(&self, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) { + self.derived_set_property(id, value, pspec); + } + + fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value { + self.derived_property(id, pspec) + } + } + + glib::wrapper! { + pub struct TestObject(ObjectSubclass); + } + + let obj: TestObject = glib::Object::new(); + + assert_eq!(obj.clock_time(), ClockTime::default()); + obj.set_clock_time(ClockTime::MAX); + assert_eq!(obj.clock_time(), ClockTime::MAX); + + assert_eq!(obj.optional_clock_time(), None); + obj.set_optional_clock_time(ClockTime::MAX); + assert_eq!(obj.optional_clock_time(), Some(ClockTime::MAX)); + } }