From fe319af598a6071711f40934b2de0a005d9faae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Sun, 3 Jul 2022 18:04:06 +0200 Subject: [PATCH] Implement FormattedValue on any candidate type The trait FormattedValue was only implemented on types which could implement the full range of values for a Format. In order to declare a function which could take both the intrinsic type of any Format (e.g. `ClockTime`) as well the full range of values (e.g. `Option`), the argument was declared: ```rust impl Into, ``` This commit implements `FormattedValue` for any type representing a format. E.g.: both `ClockTime` and `Option` will now implement `FormattedValue`. The trait `FormattedValueFullRange` is implemented on types which can be built from any raw value. These changes are intended to help for the implementation of a means to enforce format conformity at compilation time for functions with multiple formatted value arguments. The following signatures were found to be incorrect and are fixed: - `message::StepDone`: forced the type for `amount` and `duration` to be of the same type, when `duration` is expected to be of the `Time` format. - `query::Convert::set`: the two arguments were forced to the same type, so potentialy the same format, unless a `GenericFormattedValue` was used. See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1059 --- gstreamer-audio/src/audio_info.rs | 12 +- gstreamer-audio/src/audio_meta.rs | 8 +- gstreamer-base/src/aggregator.rs | 4 +- gstreamer-base/src/base_parse.rs | 26 ++-- gstreamer-base/src/subclass/base_parse.rs | 13 +- gstreamer-video/src/video_info.rs | 12 +- gstreamer/src/element.rs | 51 +++---- gstreamer/src/event.rs | 45 +++--- gstreamer/src/format.rs | 102 ++++++++----- gstreamer/src/lib.rs | 8 +- gstreamer/src/macros.rs | 36 +++-- gstreamer/src/message.rs | 65 ++++----- gstreamer/src/pad.rs | 56 ++++---- gstreamer/src/query.rs | 79 +++++----- gstreamer/src/segment.rs | 167 +++++++++------------- gstreamer/src/segment_serde.rs | 2 +- 16 files changed, 326 insertions(+), 360 deletions(-) diff --git a/gstreamer-audio/src/audio_info.rs b/gstreamer-audio/src/audio_info.rs index 4eaabbea9..b8a5ac1fd 100644 --- a/gstreamer-audio/src/audio_info.rs +++ b/gstreamer-audio/src/audio_info.rs @@ -176,13 +176,11 @@ impl AudioInfo { } #[doc(alias = "gst_audio_info_convert")] - pub fn convert, U: gst::SpecificFormattedValue>( + pub fn convert( &self, - src_val: V, + src_val: impl gst::FormattedValue, ) -> Option { assert_initialized_main_thread!(); - - let src_val = src_val.into(); unsafe { let mut dest_val = mem::MaybeUninit::uninit(); if from_glib(ffi::gst_audio_info_convert( @@ -199,14 +197,12 @@ impl AudioInfo { } } - pub fn convert_generic>( + pub fn convert_generic( &self, - src_val: V, + src_val: impl gst::FormattedValue, dest_fmt: gst::Format, ) -> Option { assert_initialized_main_thread!(); - - let src_val = src_val.into(); unsafe { let mut dest_val = mem::MaybeUninit::uninit(); if from_glib(ffi::gst_audio_info_convert( diff --git a/gstreamer-audio/src/audio_meta.rs b/gstreamer-audio/src/audio_meta.rs index 75037adea..d58b2106c 100644 --- a/gstreamer-audio/src/audio_meta.rs +++ b/gstreamer-audio/src/audio_meta.rs @@ -23,21 +23,19 @@ unsafe impl Sync for AudioClippingMeta {} impl AudioClippingMeta { #[doc(alias = "gst_buffer_add_audio_clipping_meta")] - pub fn add>( + pub fn add( buffer: &mut gst::BufferRef, start: V, end: V, ) -> gst::MetaRefMut { skip_assert_initialized!(); - let start = start.into(); - let end = end.into(); assert_eq!(start.format(), end.format()); unsafe { let meta = ffi::gst_buffer_add_audio_clipping_meta( buffer.as_mut_ptr(), start.format().into_glib(), - start.value() as u64, - end.value() as u64, + start.into_raw_value() as u64, + end.into_raw_value() as u64, ); Self::from_mut_ptr(buffer, meta) diff --git a/gstreamer-base/src/aggregator.rs b/gstreamer-base/src/aggregator.rs index 8ac0dce86..da9bcd2dd 100644 --- a/gstreamer-base/src/aggregator.rs +++ b/gstreamer-base/src/aggregator.rs @@ -55,7 +55,7 @@ pub trait AggregatorExtManual: 'static { #[doc(alias = "gst_aggregator_update_segment")] fn update_segment(&self, segment: &gst::FormattedSegment); - fn set_position(&self, position: V); + fn set_position(&self, position: impl FormattedValue); #[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] @@ -167,7 +167,7 @@ impl> AggregatorExtManual for O { } } - fn set_position(&self, position: V) { + fn set_position(&self, position: impl FormattedValue) { unsafe { let ptr: *mut ffi::GstAggregator = self.as_ref().to_glib_none().0; let ptr = &mut *ptr; diff --git a/gstreamer-base/src/base_parse.rs b/gstreamer-base/src/base_parse.rs index 0fcb78810..5a1719a6e 100644 --- a/gstreamer-base/src/base_parse.rs +++ b/gstreamer-base/src/base_parse.rs @@ -4,7 +4,6 @@ use crate::BaseParse; use crate::BaseParseFrame; use glib::prelude::*; use glib::translate::*; -use gst::FormattedValue; use std::mem; pub trait BaseParseExtManual: 'static { @@ -14,18 +13,18 @@ pub trait BaseParseExtManual: 'static { fn src_pad(&self) -> &gst::Pad; #[doc(alias = "gst_base_parse_set_duration")] - fn set_duration>(&self, duration: V, interval: u32); + fn set_duration(&self, duration: impl gst::FormattedValue, interval: u32); #[doc(alias = "gst_base_parse_set_frame_rate")] fn set_frame_rate(&self, fps: gst::Fraction, lead_in: u32, lead_out: u32); #[doc(alias = "gst_base_parse_convert_default")] - fn convert_default, U: gst::SpecificFormattedValue>( + fn convert_default( &self, - src_val: V, + src_val: impl gst::FormattedValue, ) -> Option; - fn convert_default_generic>( + fn convert_default_generic( &self, - src_val: V, + src_val: impl gst::FormattedValue, dest_format: gst::Format, ) -> Option; @@ -52,13 +51,12 @@ impl> BaseParseExtManual for O { } } - fn set_duration>(&self, duration: V, interval: u32) { - let duration = duration.into(); + fn set_duration(&self, duration: impl gst::FormattedValue, interval: u32) { unsafe { ffi::gst_base_parse_set_duration( self.as_ref().to_glib_none().0, duration.format().into_glib(), - duration.value(), + duration.into_raw_value(), interval as i32, ); } @@ -77,11 +75,10 @@ impl> BaseParseExtManual for O { } } - fn convert_default, U: gst::SpecificFormattedValue>( + fn convert_default( &self, - src_val: V, + src_val: impl gst::FormattedValue, ) -> Option { - let src_val = src_val.into(); unsafe { let mut dest_val = mem::MaybeUninit::uninit(); let ret = from_glib(ffi::gst_base_parse_convert_default( @@ -99,12 +96,11 @@ impl> BaseParseExtManual for O { } } - fn convert_default_generic>( + fn convert_default_generic( &self, - src_val: V, + src_val: impl gst::FormattedValue, dest_format: gst::Format, ) -> Option { - let src_val = src_val.into(); unsafe { let mut dest_val = mem::MaybeUninit::uninit(); let ret = from_glib(ffi::gst_base_parse_convert_default( diff --git a/gstreamer-base/src/subclass/base_parse.rs b/gstreamer-base/src/subclass/base_parse.rs index bad0f351c..09fea1bbb 100644 --- a/gstreamer-base/src/subclass/base_parse.rs +++ b/gstreamer-base/src/subclass/base_parse.rs @@ -36,10 +36,10 @@ pub trait BaseParseImpl: BaseParseImplExt + ElementImpl { self.parent_handle_frame(element, frame) } - fn convert>( + fn convert( &self, element: &Self::Type, - src_val: V, + src_val: impl gst::FormattedValue, dest_format: gst::Format, ) -> Option { self.parent_convert(element, src_val, dest_format) @@ -63,10 +63,10 @@ pub trait BaseParseImplExt: ObjectSubclass { frame: BaseParseFrame, ) -> Result<(gst::FlowSuccess, u32), gst::FlowError>; - fn parent_convert>( + fn parent_convert( &self, element: &Self::Type, - src_val: V, + src_val: impl gst::FormattedValue, dest_format: gst::Format, ) -> Option; } @@ -159,16 +159,15 @@ impl BaseParseImplExt for T { } } - fn parent_convert>( + fn parent_convert( &self, element: &Self::Type, - src_val: V, + src_val: impl gst::FormattedValue, dest_format: gst::Format, ) -> Option { unsafe { let data = Self::type_data(); let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseParseClass; - let src_val = src_val.into(); let res = (*parent_class).convert.map(|f| { let mut dest_val = mem::MaybeUninit::uninit(); diff --git a/gstreamer-video/src/video_info.rs b/gstreamer-video/src/video_info.rs index bf3c8a6a8..67e3d97f1 100644 --- a/gstreamer-video/src/video_info.rs +++ b/gstreamer-video/src/video_info.rs @@ -730,13 +730,11 @@ impl VideoInfo { } #[doc(alias = "gst_video_info_convert")] - pub fn convert, U: gst::SpecificFormattedValue>( + pub fn convert( &self, - src_val: V, + src_val: impl gst::FormattedValue, ) -> Option { skip_assert_initialized!(); - - let src_val = src_val.into(); unsafe { let mut dest_val = mem::MaybeUninit::uninit(); if from_glib(ffi::gst_video_info_convert( @@ -753,14 +751,12 @@ impl VideoInfo { } } - pub fn convert_generic>( + pub fn convert_generic( &self, - src_val: V, + src_val: impl gst::FormattedValue, dest_fmt: gst::Format, ) -> Option { skip_assert_initialized!(); - - let src_val = src_val.into(); unsafe { let mut dest_val = mem::MaybeUninit::uninit(); if from_glib(ffi::gst_video_info_convert( diff --git a/gstreamer/src/element.rs b/gstreamer/src/element.rs index eb52d22f5..7b14ae084 100644 --- a/gstreamer/src/element.rs +++ b/gstreamer/src/element.rs @@ -8,16 +8,13 @@ use crate::prelude::*; use crate::ClockTime; use crate::ElementFlags; use crate::Event; -use crate::Format; -use crate::FormattedValue; -use crate::GenericFormattedValue; use crate::Pad; use crate::PadTemplate; use crate::Plugin; use crate::QueryRef; use crate::Rank; -use crate::SpecificFormattedValue; use crate::State; +use crate::{Format, FormattedValue, GenericFormattedValue, SpecificFormattedValueFullRange}; use glib::translate::*; @@ -208,13 +205,13 @@ pub trait ElementExtManual: 'static { fn remove_property_notify_watch(&self, watch_id: NotifyWatchId); #[doc(alias = "gst_element_query_convert")] - fn query_convert, U: SpecificFormattedValue>( + fn query_convert( &self, - src_val: V, + src_val: impl FormattedValue, ) -> Option; - fn query_convert_generic>( + fn query_convert_generic( &self, - src_val: V, + src_val: impl FormattedValue, dest_format: Format, ) -> Option; @@ -229,7 +226,7 @@ pub trait ElementExtManual: 'static { fn query_position_generic(&self, format: Format) -> Option; #[doc(alias = "gst_element_seek")] - fn seek>( + fn seek( &self, rate: f64, flags: crate::SeekFlags, @@ -239,10 +236,10 @@ pub trait ElementExtManual: 'static { stop: V, ) -> Result<(), glib::error::BoolError>; #[doc(alias = "gst_element_seek_simple")] - fn seek_simple>( + fn seek_simple( &self, seek_flags: crate::SeekFlags, - seek_pos: V, + seek_pos: impl FormattedValue, ) -> Result<(), glib::error::BoolError>; #[doc(alias = "gst_element_call_async")] @@ -553,11 +550,10 @@ impl> ElementExtManual for O { } } - fn query_convert, U: SpecificFormattedValue>( + fn query_convert( &self, - src_val: V, + src_val: impl FormattedValue, ) -> Option { - let src_val = src_val.into(); unsafe { let mut dest_val = mem::MaybeUninit::uninit(); let ret = from_glib(ffi::gst_element_query_convert( @@ -575,18 +571,17 @@ impl> ElementExtManual for O { } } - fn query_convert_generic>( + fn query_convert_generic( &self, - src_val: V, + src_val: impl FormattedValue, dest_format: Format, ) -> Option { - let src_val = src_val.into(); unsafe { let mut dest_val = mem::MaybeUninit::uninit(); let ret = from_glib(ffi::gst_element_query_convert( self.as_ref().to_glib_none().0, src_val.format().into_glib(), - src_val.value(), + src_val.into_raw_value(), dest_format.into_glib(), dest_val.as_mut_ptr(), )); @@ -606,7 +601,7 @@ impl> ElementExtManual for O { let mut duration = mem::MaybeUninit::uninit(); let ret = from_glib(ffi::gst_element_query_duration( self.as_ref().to_glib_none().0, - T::FormattedValueType::default_format().into_glib(), + T::default_format().into_glib(), duration.as_mut_ptr(), )); if ret { @@ -638,7 +633,7 @@ impl> ElementExtManual for O { let mut cur = mem::MaybeUninit::uninit(); let ret = from_glib(ffi::gst_element_query_position( self.as_ref().to_glib_none().0, - T::FormattedValueType::default_format().into_glib(), + T::default_format().into_glib(), cur.as_mut_ptr(), )); if ret { @@ -665,7 +660,7 @@ impl> ElementExtManual for O { } } - fn seek>( + fn seek( &self, rate: f64, flags: crate::SeekFlags, @@ -674,9 +669,6 @@ impl> ElementExtManual for O { stop_type: crate::SeekType, stop: V, ) -> Result<(), glib::error::BoolError> { - let start = start.into(); - let stop = stop.into(); - assert_eq!(stop.format(), start.format()); unsafe { @@ -687,28 +679,27 @@ impl> ElementExtManual for O { start.format().into_glib(), flags.into_glib(), start_type.into_glib(), - start.value(), + start.into_raw_value(), stop_type.into_glib(), - stop.value(), + stop.into_raw_value(), ), "Failed to seek", ) } } - fn seek_simple>( + fn seek_simple( &self, seek_flags: crate::SeekFlags, - seek_pos: V, + seek_pos: impl FormattedValue, ) -> Result<(), glib::error::BoolError> { - let seek_pos = seek_pos.into(); unsafe { glib::result_from_gboolean!( ffi::gst_element_seek_simple( self.as_ref().to_glib_none().0, seek_pos.format().into_glib(), seek_flags.into_glib(), - seek_pos.value(), + seek_pos.into_raw_value(), ), "Failed to seek", ) diff --git a/gstreamer/src/event.rs b/gstreamer/src/event.rs index ecfead2ce..20a412154 100644 --- a/gstreamer/src/event.rs +++ b/gstreamer/src/event.rs @@ -2,7 +2,7 @@ use crate::structure::*; use crate::ClockTime; -use crate::GenericFormattedValue; +use crate::{FormattedValue, GenericFormattedValue}; use std::borrow::Borrow; use std::cmp; @@ -642,22 +642,20 @@ declare_concrete_event!(@sticky Buffersize, T); impl Buffersize { #[doc(alias = "gst_event_new_buffer_size")] #[allow(clippy::new_ret_no_self)] - pub fn new>(minsize: V, maxsize: V, r#async: bool) -> Event { + pub fn new(minsize: V, maxsize: V, r#async: bool) -> Event { skip_assert_initialized!(); Self::builder(minsize, maxsize, r#async).build() } - pub fn builder<'a, V: Into>( + pub fn builder<'a, V: FormattedValue>( minsize: V, maxsize: V, r#async: bool, ) -> BuffersizeBuilder<'a> { assert_initialized_main_thread!(); - let minsize = minsize.into(); - let maxsize = maxsize.into(); assert_eq!(minsize.format(), maxsize.format()); - BuffersizeBuilder::new(minsize, maxsize, r#async) + BuffersizeBuilder::new(minsize.into(), maxsize.into(), r#async) } } @@ -858,15 +856,14 @@ declare_concrete_event!(SegmentDone, T); impl SegmentDone { #[doc(alias = "gst_event_new_segment_done")] #[allow(clippy::new_ret_no_self)] - pub fn new>(position: V) -> Event { + pub fn new(position: impl FormattedValue) -> Event { skip_assert_initialized!(); Self::builder(position).build() } - pub fn builder<'a, V: Into>(position: V) -> SegmentDoneBuilder<'a> { + pub fn builder<'a>(position: impl FormattedValue) -> SegmentDoneBuilder<'a> { assert_initialized_main_thread!(); - let position = position.into(); - SegmentDoneBuilder::new(position) + SegmentDoneBuilder::new(position.into()) } } @@ -1030,7 +1027,7 @@ declare_concrete_event!(Seek, T); impl Seek { #[doc(alias = "gst_event_new_seek")] #[allow(clippy::new_ret_no_self)] - pub fn new>( + pub fn new( rate: f64, flags: crate::SeekFlags, start_type: crate::SeekType, @@ -1042,7 +1039,7 @@ impl Seek { Self::builder(rate, flags, start_type, start, stop_type, stop).build() } - pub fn builder<'a, V: Into>( + pub fn builder<'a, V: FormattedValue>( rate: f64, flags: crate::SeekFlags, start_type: crate::SeekType, @@ -1051,11 +1048,16 @@ impl Seek { stop: V, ) -> SeekBuilder<'a> { assert_initialized_main_thread!(); - let start = start.into(); - let stop = stop.into(); assert_eq!(start.format(), stop.format()); - SeekBuilder::new(rate, flags, start_type, start, stop_type, stop) + SeekBuilder::new( + rate, + flags, + start_type, + start.into(), + stop_type, + stop.into(), + ) } } @@ -1168,18 +1170,13 @@ declare_concrete_event!(Step, T); impl Step { #[doc(alias = "gst_event_new_step")] #[allow(clippy::new_ret_no_self)] - pub fn new>( - amount: V, - rate: f64, - flush: bool, - intermediate: bool, - ) -> Event { + pub fn new(amount: impl FormattedValue, rate: f64, flush: bool, intermediate: bool) -> Event { skip_assert_initialized!(); - Self::builder(amount.into(), rate, flush, intermediate).build() + Self::builder(amount, rate, flush, intermediate).build() } - pub fn builder<'a, V: Into>( - amount: V, + pub fn builder<'a>( + amount: impl FormattedValue, rate: f64, flush: bool, intermediate: bool, diff --git a/gstreamer/src/format.rs b/gstreamer/src/format.rs index 1d1a0ee23..01d5a4b15 100644 --- a/gstreamer/src/format.rs +++ b/gstreamer/src/format.rs @@ -77,15 +77,31 @@ impl fmt::Display for GenericFormattedValue { pub struct TryFromGenericFormattedValueError(()); pub trait FormattedValue: Copy + Clone + Sized + Into + 'static { + // rustdoc-stripper-ignore-next + /// Type which allows building a `FormattedValue` of this format from any raw value. + type FullRange: FormattedValueFullRange + From; + #[doc(alias = "get_default_format")] fn default_format() -> Format; + #[doc(alias = "get_format")] fn format(&self) -> Format; - unsafe fn from_raw(format: Format, value: i64) -> Self; unsafe fn into_raw_value(self) -> i64; } +// rustdoc-stripper-ignore-next +/// A [`FormattedValue`] which can be built from any raw value. +/// +/// # Examples: +/// +/// - `GenericFormattedValue` is the `FormattedValueFullRange` type for `GenericFormattedValue`. +/// - `Undefined` is the `FormattedValueFullRange` type for `Undefined`. +/// - `Option` is the `FormattedValueFullRange` type for `Percent`. +pub trait FormattedValueFullRange: FormattedValue + TryFrom { + unsafe fn from_raw(format: Format, value: i64) -> Self; +} + // rustdoc-stripper-ignore-next /// A trait implemented on the intrinsic type of a `FormattedValue`. /// @@ -94,11 +110,11 @@ pub trait FormattedValue: Copy + Clone + Sized + Into + ' /// - `GenericFormattedValue` is the intrinsic type for `GenericFormattedValue`. /// - `Undefined` is the intrinsic type for `Undefined`. /// - `Bytes` is the intrinsic type for `Option`. -pub trait FormattedValueIntrinsic: Copy + Clone + Sized + 'static { - type FormattedValueType: FormattedValue; -} +pub trait FormattedValueIntrinsic: FormattedValue {} -pub trait SpecificFormattedValue: FormattedValue + TryFrom {} +pub trait SpecificFormattedValue: FormattedValue {} + +pub trait SpecificFormattedValueFullRange: FormattedValueFullRange {} // rustdoc-stripper-ignore-next /// A trait implemented on the intrinsic type of a `SpecificFormattedValue`. @@ -110,6 +126,8 @@ pub trait SpecificFormattedValue: FormattedValue + TryFrom + FormattedValueIntrinsic {} impl FormattedValue for GenericFormattedValue { + type FullRange = GenericFormattedValue; + fn default_format() -> Format { Format::Undefined } @@ -118,15 +136,17 @@ impl FormattedValue for GenericFormattedValue { self.format() } - unsafe fn from_raw(format: Format, value: i64) -> Self { - GenericFormattedValue::new(format, value) - } - unsafe fn into_raw_value(self) -> i64 { self.value() } } +impl FormattedValueFullRange for GenericFormattedValue { + unsafe fn from_raw(format: Format, value: i64) -> Self { + GenericFormattedValue::new(format, value) + } +} + impl GenericFormattedValue { pub fn new(format: Format, value: i64) -> Self { skip_assert_initialized!(); @@ -136,7 +156,9 @@ impl GenericFormattedValue { Format::Bytes => Self::Bytes(unsafe { FromGlib::from_glib(value as u64) }), Format::Time => Self::Time(unsafe { FromGlib::from_glib(value as u64) }), Format::Buffers => Self::Buffers(unsafe { FromGlib::from_glib(value as u64) }), - Format::Percent => Self::Percent(unsafe { FormattedValue::from_raw(format, value) }), + Format::Percent => { + Self::Percent(unsafe { FormattedValueFullRange::from_raw(format, value) }) + } Format::__Unknown(_) => Self::Other(format, value), } } @@ -170,9 +192,7 @@ impl GenericFormattedValue { } } -impl FormattedValueIntrinsic for GenericFormattedValue { - type FormattedValueType = GenericFormattedValue; -} +impl FormattedValueIntrinsic for GenericFormattedValue {} impl_common_ops_for_newtype_uint!(Default, u64); impl_format_value_traits!(Default, Default, Default, u64); @@ -192,6 +212,8 @@ option_glib_newtype_from_to!(Buffers, Buffers::OFFSET_NONE); option_glib_newtype_display!(Buffers, "buffers"); impl FormattedValue for Undefined { + type FullRange = Undefined; + fn default_format() -> Format { Format::Undefined } @@ -200,14 +222,16 @@ impl FormattedValue for Undefined { Format::Undefined } + unsafe fn into_raw_value(self) -> i64 { + self.0 + } +} + +impl FormattedValueFullRange for Undefined { unsafe fn from_raw(format: Format, value: i64) -> Self { debug_assert_eq!(format, Format::Undefined); Undefined(value) } - - unsafe fn into_raw_value(self) -> i64 { - self.0 - } } impl From for GenericFormattedValue { @@ -230,13 +254,7 @@ impl TryFrom for Undefined { } } -impl FormattedValueIntrinsic for Undefined { - type FormattedValueType = Undefined; -} - -impl SpecificFormattedValue for Undefined {} - -impl SpecificFormattedValueIntrinsic for Undefined {} +impl FormattedValueIntrinsic for Undefined {} impl TryFromGlib for Undefined { type Error = std::convert::Infallible; @@ -298,6 +316,8 @@ impl_common_ops_for_newtype_uint!(Percent, u32); option_glib_newtype_display!(Percent, "%"); impl FormattedValue for Option { + type FullRange = Option; + fn default_format() -> Format { Format::Percent } @@ -306,14 +326,16 @@ impl FormattedValue for Option { Format::Percent } + unsafe fn into_raw_value(self) -> i64 { + self.map_or(-1, |v| v.0 as i64) + } +} + +impl FormattedValueFullRange for Option { unsafe fn from_raw(format: Format, value: i64) -> Self { debug_assert_eq!(format, Format::Percent); Percent::try_from_glib(value as i64).ok() } - - unsafe fn into_raw_value(self) -> i64 { - self.map_or(-1, |v| v.0 as i64) - } } impl From> for GenericFormattedValue { @@ -329,6 +351,23 @@ impl From for GenericFormattedValue { GenericFormattedValue::Percent(Some(v)) } } + +impl FormattedValue for Percent { + type FullRange = Option; + + fn default_format() -> Format { + Format::Percent + } + + fn format(&self) -> Format { + Format::Percent + } + + unsafe fn into_raw_value(self) -> i64 { + self.0 as i64 + } +} + impl TryFrom for Percent { type Error = GlibNoneError; @@ -366,12 +405,9 @@ impl TryFrom for Option { } } -impl FormattedValueIntrinsic for Percent { - type FormattedValueType = Option; -} - +impl FormattedValueIntrinsic for Percent {} impl SpecificFormattedValue for Option {} - +impl SpecificFormattedValueFullRange for Option {} impl SpecificFormattedValueIntrinsic for Percent {} impl ops::Deref for Percent { diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index a1ef97928..d0dc1eb67 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -226,8 +226,8 @@ mod typefind_factory; pub mod format; pub use crate::format::{ - FormattedValue, FormattedValueIntrinsic, GenericFormattedValue, SpecificFormattedValue, - SpecificFormattedValueIntrinsic, + FormattedValue, FormattedValueFullRange, FormattedValueIntrinsic, GenericFormattedValue, + SpecificFormattedValue, SpecificFormattedValueFullRange, SpecificFormattedValueIntrinsic, }; #[cfg(feature = "ser_de")] mod format_serde; @@ -344,8 +344,8 @@ pub mod prelude { pub use muldiv::MulDiv; pub use crate::format::{ - FormattedValue, FormattedValueIntrinsic, SpecificFormattedValue, - SpecificFormattedValueIntrinsic, + FormattedValue, FormattedValueFullRange, FormattedValueIntrinsic, SpecificFormattedValue, + SpecificFormattedValueFullRange, SpecificFormattedValueIntrinsic, }; pub use crate::utils::Displayable; diff --git a/gstreamer/src/macros.rs b/gstreamer/src/macros.rs index 0d5b6098e..d06b6a337 100644 --- a/gstreamer/src/macros.rs +++ b/gstreamer/src/macros.rs @@ -375,6 +375,8 @@ macro_rules! impl_common_ops_for_newtype_uint( macro_rules! impl_format_value_traits( ($name:ident, $format:ident, $format_value:ident, $inner_type:ty) => { impl FormattedValue for Option<$name> { + type FullRange = Option<$name>; + fn default_format() -> Format { Format::$format } @@ -383,14 +385,16 @@ macro_rules! impl_format_value_traits( Format::$format } + unsafe fn into_raw_value(self) -> i64 { + IntoGlib::into_glib(self) as i64 + } + } + + impl FormattedValueFullRange for Option<$name> { unsafe fn from_raw(format: Format, value: i64) -> Option<$name> { debug_assert_eq!(format, Format::$format); FromGlib::from_glib(value as u64) } - - unsafe fn into_raw_value(self) -> i64 { - IntoGlib::into_glib(self) as i64 - } } impl From> for GenericFormattedValue { @@ -406,11 +410,28 @@ macro_rules! impl_format_value_traits( Self::$format_value(Some(v)) } } + impl FormattedValue for $name { + type FullRange = Option<$name>; - impl FormattedValueIntrinsic for $name { - type FormattedValueType = Option<$name>; + fn default_format() -> Format { + Format::$format + } + + fn format(&self) -> Format { + Format::$format + } + + unsafe fn into_raw_value(self) -> i64 { + IntoGlib::into_glib(self) as i64 + } } + impl SpecificFormattedValue for Option<$name> {} + impl SpecificFormattedValueFullRange for Option<$name> {} + impl SpecificFormattedValue for $name {} + impl FormattedValueIntrinsic for $name {} + impl SpecificFormattedValueIntrinsic for $name {} + impl TryFrom for Option<$name> { type Error = TryFromGenericFormattedValueError; @@ -442,9 +463,6 @@ macro_rules! impl_format_value_traits( } } - impl SpecificFormattedValue for Option<$name> {} - impl SpecificFormattedValueIntrinsic for $name {} - impl ops::Deref for $name { type Target = $inner_type; diff --git a/gstreamer/src/message.rs b/gstreamer/src/message.rs index fe6496f6f..f6d26fc86 100644 --- a/gstreamer/src/message.rs +++ b/gstreamer/src/message.rs @@ -673,32 +673,24 @@ declare_concrete_message!(StepDone, T); impl StepDone { #[doc(alias = "gst_message_new_step_done")] #[allow(clippy::new_ret_no_self)] - pub fn new>( - amount: V, + pub fn new( + amount: impl FormattedValue, rate: f64, flush: bool, intermediate: bool, - duration: V, + duration: impl Into>, eos: bool, ) -> Message { skip_assert_initialized!(); - Self::builder( - amount.into(), - rate, - flush, - intermediate, - duration.into(), - eos, - ) - .build() + Self::builder(amount, rate, flush, intermediate, duration, eos).build() } - pub fn builder<'a, V: Into>( - amount: V, + pub fn builder<'a>( + amount: impl FormattedValue, rate: f64, flush: bool, intermediate: bool, - duration: V, + duration: impl Into>, eos: bool, ) -> StepDoneBuilder<'a> { assert_initialized_main_thread!(); @@ -720,7 +712,7 @@ impl StepDone { f64, bool, bool, - GenericFormattedValue, + Option, bool, ) { unsafe { @@ -751,10 +743,7 @@ impl StepDone { rate.assume_init(), from_glib(flush.assume_init()), from_glib(intermediate.assume_init()), - GenericFormattedValue::new( - from_glib(format.assume_init()), - duration.assume_init() as i64, - ), + from_glib(duration.assume_init()), from_glib(eos.assume_init()), ) } @@ -970,15 +959,14 @@ declare_concrete_message!(SegmentStart, T); impl SegmentStart { #[doc(alias = "gst_message_new_segment_start")] #[allow(clippy::new_ret_no_self)] - pub fn new>(position: V) -> Message { + pub fn new(position: impl FormattedValue) -> Message { skip_assert_initialized!(); Self::builder(position).build() } - pub fn builder<'a, V: Into>(position: V) -> SegmentStartBuilder<'a> { + pub fn builder<'a>(position: impl FormattedValue) -> SegmentStartBuilder<'a> { assert_initialized_main_thread!(); - let position = position.into(); - SegmentStartBuilder::new(position) + SegmentStartBuilder::new(position.into()) } #[doc(alias = "gst_message_parse_segment_start")] @@ -1002,15 +990,14 @@ declare_concrete_message!(SegmentDone, T); impl SegmentDone { #[doc(alias = "gst_message_new_segment_done")] #[allow(clippy::new_ret_no_self)] - pub fn new>(position: V) -> Message { + pub fn new(position: impl FormattedValue) -> Message { skip_assert_initialized!(); Self::builder(position).build() } - pub fn builder<'a, V: Into>(position: V) -> SegmentDoneBuilder<'a> { + pub fn builder<'a>(position: impl FormattedValue) -> SegmentDoneBuilder<'a> { assert_initialized_main_thread!(); - let position = position.into(); - SegmentDoneBuilder::new(position) + SegmentDoneBuilder::new(position.into()) } #[doc(alias = "gst_message_parse_segment_done")] @@ -1133,20 +1120,20 @@ declare_concrete_message!(StepStart, T); impl StepStart { #[doc(alias = "gst_message_new_step_start")] #[allow(clippy::new_ret_no_self)] - pub fn new>( + pub fn new( active: bool, - amount: V, + amount: impl FormattedValue, rate: f64, flush: bool, intermediate: bool, ) -> Message { skip_assert_initialized!(); - Self::builder(active, amount.into(), rate, flush, intermediate).build() + Self::builder(active, amount, rate, flush, intermediate).build() } - pub fn builder<'a, V: Into>( + pub fn builder<'a>( active: bool, - amount: V, + amount: impl FormattedValue, rate: f64, flush: bool, intermediate: bool, @@ -2168,7 +2155,7 @@ pub struct StepDoneBuilder<'a> { rate: f64, flush: bool, intermediate: bool, - duration: GenericFormattedValue, + duration: Option, eos: bool, } @@ -2178,7 +2165,7 @@ impl<'a> StepDoneBuilder<'a> { rate: f64, flush: bool, intermediate: bool, - duration: GenericFormattedValue, + duration: Option, eos: bool, ) -> Self { skip_assert_initialized!(); @@ -2201,7 +2188,7 @@ impl<'a> StepDoneBuilder<'a> { s.rate, s.flush.into_glib(), s.intermediate.into_glib(), - s.duration.value() as u64, + s.duration.into_raw_value() as u64, s.eos.into_glib(), )); } @@ -2613,12 +2600,10 @@ impl<'a> QosBuilder<'a> { } } - pub fn stats>(self, processed: V, dropped: V) -> Self { - let processed = processed.into(); - let dropped = dropped.into(); + pub fn stats(self, processed: V, dropped: V) -> Self { assert_eq!(processed.format(), dropped.format()); Self { - stats: Some((processed, dropped)), + stats: Some((processed.into(), dropped.into())), ..self } } diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index d963ac02d..98a2937da 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -6,9 +6,6 @@ use crate::Event; use crate::FlowError; use crate::FlowReturn; use crate::FlowSuccess; -use crate::Format; -use crate::FormattedValue; -use crate::GenericFormattedValue; use crate::LoggableError; use crate::Pad; use crate::PadFlags; @@ -17,7 +14,10 @@ use crate::PadProbeType; use crate::Query; use crate::QueryRef; use crate::StaticPadTemplate; -use crate::{SpecificFormattedValue, SpecificFormattedValueIntrinsic}; +use crate::{ + Format, FormattedValue, GenericFormattedValue, SpecificFormattedValueFullRange, + SpecificFormattedValueIntrinsic, +}; use std::mem; use std::num::NonZeroU64; @@ -272,14 +272,14 @@ pub trait PadExtManual: 'static { fn start_task(&self, func: F) -> Result<(), glib::BoolError>; #[doc(alias = "gst_pad_peer_query_convert")] - fn peer_query_convert, U: SpecificFormattedValue>( + fn peer_query_convert( &self, - src_val: V, + src_val: impl FormattedValue, ) -> Option; #[doc(alias = "gst_pad_peer_query_convert")] - fn peer_query_convert_generic>( + fn peer_query_convert_generic( &self, - src_val: V, + src_val: impl FormattedValue, dest_format: Format, ) -> Option; @@ -294,14 +294,14 @@ pub trait PadExtManual: 'static { fn peer_query_position_generic(&self, format: Format) -> Option; #[doc(alias = "gst_pad_query_convert")] - fn query_convert, U: SpecificFormattedValue>( + fn query_convert( &self, - src_val: V, + src_val: impl FormattedValue, ) -> Option; #[doc(alias = "gst_pad_query_convert")] - fn query_convert_generic>( + fn query_convert_generic( &self, - src_val: V, + src_val: impl FormattedValue, dest_format: Format, ) -> Option; @@ -781,11 +781,10 @@ impl> PadExtManual for O { } } - fn peer_query_convert, U: SpecificFormattedValue>( + fn peer_query_convert( &self, - src_val: V, + src_val: impl FormattedValue, ) -> Option { - let src_val = src_val.into(); unsafe { let mut dest_val = mem::MaybeUninit::uninit(); let ret = from_glib(ffi::gst_pad_peer_query_convert( @@ -803,12 +802,11 @@ impl> PadExtManual for O { } } - fn peer_query_convert_generic>( + fn peer_query_convert_generic( &self, - src_val: V, + src_val: impl FormattedValue, dest_format: Format, ) -> Option { - let src_val = src_val.into(); unsafe { let mut dest_val = mem::MaybeUninit::uninit(); let ret = from_glib(ffi::gst_pad_peer_query_convert( @@ -834,7 +832,7 @@ impl> PadExtManual for O { let mut duration = mem::MaybeUninit::uninit(); let ret = from_glib(ffi::gst_pad_peer_query_duration( self.as_ref().to_glib_none().0, - T::FormattedValueType::default_format().into_glib(), + T::default_format().into_glib(), duration.as_mut_ptr(), )); if ret { @@ -866,7 +864,7 @@ impl> PadExtManual for O { let mut cur = mem::MaybeUninit::uninit(); let ret = from_glib(ffi::gst_pad_peer_query_position( self.as_ref().to_glib_none().0, - T::FormattedValueType::default_format().into_glib(), + T::default_format().into_glib(), cur.as_mut_ptr(), )); if ret { @@ -893,12 +891,10 @@ impl> PadExtManual for O { } } - fn query_convert, U: SpecificFormattedValue>( + fn query_convert( &self, - src_val: V, + src_val: impl FormattedValue, ) -> Option { - let src_val = src_val.into(); - unsafe { let mut dest_val = mem::MaybeUninit::uninit(); let ret = from_glib(ffi::gst_pad_query_convert( @@ -916,19 +912,17 @@ impl> PadExtManual for O { } } - fn query_convert_generic>( + fn query_convert_generic( &self, - src_val: V, + src_val: impl FormattedValue, dest_format: Format, ) -> Option { - let src_val = src_val.into(); - unsafe { let mut dest_val = mem::MaybeUninit::uninit(); let ret = from_glib(ffi::gst_pad_query_convert( self.as_ref().to_glib_none().0, src_val.format().into_glib(), - src_val.value(), + src_val.into_raw_value(), dest_format.into_glib(), dest_val.as_mut_ptr(), )); @@ -948,7 +942,7 @@ impl> PadExtManual for O { let mut duration = mem::MaybeUninit::uninit(); let ret = from_glib(ffi::gst_pad_query_duration( self.as_ref().to_glib_none().0, - T::FormattedValueType::default_format().into_glib(), + T::default_format().into_glib(), duration.as_mut_ptr(), )); if ret { @@ -980,7 +974,7 @@ impl> PadExtManual for O { let mut cur = mem::MaybeUninit::uninit(); let ret = from_glib(ffi::gst_pad_query_position( self.as_ref().to_glib_none().0, - T::FormattedValueType::default_format().into_glib(), + T::default_format().into_glib(), cur.as_mut_ptr(), )); if ret { diff --git a/gstreamer/src/query.rs b/gstreamer/src/query.rs index 80ea0a38c..c4b3154b9 100644 --- a/gstreamer/src/query.rs +++ b/gstreamer/src/query.rs @@ -1,7 +1,7 @@ // Take a look at the license at the top of the repository in the LICENSE file. use crate::structure::*; -use crate::GenericFormattedValue; +use crate::{FormattedValue, GenericFormattedValue}; use std::borrow::{Borrow, BorrowMut}; use std::ffi::CStr; @@ -319,11 +319,14 @@ impl Position { } #[doc(alias = "gst_query_set_position")] - pub fn set>(&mut self, pos: V) { - let pos = pos.into(); + pub fn set(&mut self, pos: impl FormattedValue) { assert_eq!(pos.format(), self.format()); unsafe { - ffi::gst_query_set_position(self.as_mut_ptr(), pos.format().into_glib(), pos.value()); + ffi::gst_query_set_position( + self.as_mut_ptr(), + pos.format().into_glib(), + pos.into_raw_value(), + ); } } } @@ -364,11 +367,14 @@ impl Duration { } #[doc(alias = "gst_query_set_duration")] - pub fn set>(&mut self, dur: V) { - let dur = dur.into(); + pub fn set(&mut self, dur: impl FormattedValue) { assert_eq!(dur.format(), self.format()); unsafe { - ffi::gst_query_set_duration(self.as_mut_ptr(), dur.format().into_glib(), dur.value()); + ffi::gst_query_set_duration( + self.as_mut_ptr(), + dur.format().into_glib(), + dur.into_raw_value(), + ); } } } @@ -482,10 +488,7 @@ impl Seeking { } #[doc(alias = "gst_query_set_seeking")] - pub fn set>(&mut self, seekable: bool, start: V, end: V) { - let start = start.into(); - let end = end.into(); - + pub fn set(&mut self, seekable: bool, start: V, end: V) { assert_eq!(self.format(), start.format()); assert_eq!(start.format(), end.format()); @@ -494,8 +497,8 @@ impl Seeking { self.as_mut_ptr(), start.format().into_glib(), seekable.into_glib(), - start.value(), - end.value(), + start.into_raw_value(), + end.into_raw_value(), ); } } @@ -553,10 +556,7 @@ impl Segment { } #[doc(alias = "gst_query_set_segment")] - pub fn set>(&mut self, rate: f64, start: V, stop: V) { - let start = start.into(); - let stop = stop.into(); - + pub fn set(&mut self, rate: f64, start: V, stop: V) { assert_eq!(start.format(), stop.format()); unsafe { @@ -564,8 +564,8 @@ impl Segment { self.as_mut_ptr(), rate, start.format().into_glib(), - start.value(), - stop.value(), + start.into_raw_value(), + stop.into_raw_value(), ); } } @@ -574,13 +574,12 @@ impl Segment { declare_concrete_query!(Convert, T); impl Convert { #[doc(alias = "gst_query_new_convert")] - pub fn new>(value: V, dest_fmt: crate::Format) -> Self { + pub fn new(value: impl FormattedValue, dest_fmt: crate::Format) -> Self { assert_initialized_main_thread!(); - let value = value.into(); unsafe { Self(from_glib_full(ffi::gst_query_new_convert( value.format().into_glib(), - value.value(), + value.into_raw_value(), dest_fmt.into_glib(), ))) } @@ -633,17 +632,14 @@ impl Convert { } #[doc(alias = "gst_query_set_convert")] - pub fn set>(&mut self, src: V, dest: V) { - let src = src.into(); - let dest = dest.into(); - + pub fn set(&mut self, src: impl FormattedValue, dest: impl FormattedValue) { unsafe { ffi::gst_query_set_convert( self.as_mut_ptr(), src.format().into_glib(), - src.value(), + src.into_raw_value(), dest.format().into_glib(), - dest.value(), + dest.into_raw_value(), ); } } @@ -840,15 +836,7 @@ impl Buffering { } #[doc(alias = "gst_query_set_buffering_range")] - pub fn set_range>( - &mut self, - start: V, - stop: V, - estimated_total: i64, - ) { - let start = start.into(); - let stop = stop.into(); - + pub fn set_range(&mut self, start: V, stop: V, estimated_total: i64) { assert_eq!(self.format(), start.format()); assert_eq!(start.format(), stop.format()); @@ -856,8 +844,8 @@ impl Buffering { ffi::gst_query_set_buffering_range( self.as_mut_ptr(), start.format().into_glib(), - start.value(), - stop.value(), + start.into_raw_value(), + stop.into_raw_value(), estimated_total, ); } @@ -884,19 +872,18 @@ impl Buffering { } #[doc(alias = "gst_query_add_buffering_range")] - pub fn add_buffering_ranges + Copy>( - &mut self, - ranges: &[(V, V)], - ) { + pub fn add_buffering_ranges(&mut self, ranges: &[(V, V)]) { unsafe { let fmt = self.format(); for &(start, stop) in ranges { - let start = start.into(); - let stop = stop.into(); assert_eq!(start.format(), fmt); assert_eq!(stop.format(), fmt); - ffi::gst_query_add_buffering_range(self.as_mut_ptr(), start.value(), stop.value()); + ffi::gst_query_add_buffering_range( + self.as_mut_ptr(), + start.into_raw_value(), + stop.into_raw_value(), + ); } } } diff --git a/gstreamer/src/segment.rs b/gstreamer/src/segment.rs index f4e1e926d..573772aa1 100644 --- a/gstreamer/src/segment.rs +++ b/gstreamer/src/segment.rs @@ -4,7 +4,7 @@ use crate::Format; use crate::GenericFormattedValue; use crate::SeekFlags; use crate::SeekType; -use crate::{FormattedValue, FormattedValueIntrinsic}; +use crate::{FormattedValue, FormattedValueFullRange, FormattedValueIntrinsic}; use glib::translate::*; use glib::StaticType; use std::fmt; @@ -34,9 +34,7 @@ impl Segment { } pub fn downcast(self) -> Result, Self> { - if T::FormattedValueType::default_format() == Format::Undefined - || T::FormattedValueType::default_format() == self.format() - { + if T::default_format() == Format::Undefined || T::default_format() == self.format() { Ok(FormattedSegment(self.0, PhantomData)) } else { Err(self) @@ -44,9 +42,7 @@ impl Segment { } pub fn downcast_ref(&self) -> Option<&FormattedSegment> { - if T::FormattedValueType::default_format() == Format::Undefined - || T::FormattedValueType::default_format() == self.format() - { + if T::default_format() == Format::Undefined || T::default_format() == self.format() { Some(unsafe { &*(self as *const FormattedSegment as *const FormattedSegment) @@ -57,9 +53,7 @@ impl Segment { } pub fn downcast_mut(&mut self) -> Option<&mut FormattedSegment> { - if T::FormattedValueType::default_format() == Format::Undefined - || T::FormattedValueType::default_format() == self.format() - { + if T::default_format() == Format::Undefined || T::default_format() == self.format() { Some(unsafe { &mut *(self as *mut FormattedSegment as *mut FormattedSegment) @@ -75,10 +69,7 @@ impl FormattedSegment { assert_initialized_main_thread!(); let segment = unsafe { let mut segment = mem::MaybeUninit::zeroed(); - ffi::gst_segment_init( - segment.as_mut_ptr(), - T::FormattedValueType::default_format().into_glib(), - ); + ffi::gst_segment_init(segment.as_mut_ptr(), T::default_format().into_glib()); segment.assume_init() }; FormattedSegment(segment, PhantomData) @@ -96,23 +87,20 @@ impl FormattedSegment { pub fn reset(&mut self) { unsafe { - ffi::gst_segment_init( - &mut self.0, - T::FormattedValueType::default_format().into_glib(), - ); + ffi::gst_segment_init(&mut self.0, T::default_format().into_glib()); } } #[doc(alias = "gst_segment_clip")] - pub fn clip>( + pub fn clip>( &self, start: V, stop: V, - ) -> Option<(T::FormattedValueType, T::FormattedValueType)> { + ) -> Option<(T::FullRange, T::FullRange)> { let start = start.into(); let stop = stop.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), start.format()); assert_eq!(self.format(), stop.format()); } @@ -130,8 +118,8 @@ impl FormattedSegment { )); if ret { Some(( - T::FormattedValueType::from_raw(self.format(), clip_start.assume_init() as i64), - T::FormattedValueType::from_raw(self.format(), clip_stop.assume_init() as i64), + T::FullRange::from_raw(self.format(), clip_start.assume_init() as i64), + T::FullRange::from_raw(self.format(), clip_stop.assume_init() as i64), )) } else { None @@ -141,7 +129,7 @@ impl FormattedSegment { #[allow(clippy::too_many_arguments)] #[doc(alias = "gst_segment_do_seek")] - pub fn do_seek>( + pub fn do_seek>( &mut self, rate: f64, flags: SeekFlags, @@ -154,7 +142,7 @@ impl FormattedSegment { let start = start.into(); let stop = stop.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), start.format()); assert_eq!(self.format(), stop.format()); } @@ -195,18 +183,18 @@ impl FormattedSegment { } #[doc(alias = "gst_segment_position_from_running_time")] - pub fn position_from_running_time>( + pub fn position_from_running_time>( &self, running_time: V, - ) -> T::FormattedValueType { + ) -> T::FullRange { let running_time = running_time.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), running_time.format()); } unsafe { - T::FormattedValueType::from_raw( + T::FullRange::from_raw( self.format(), ffi::gst_segment_position_from_running_time( &self.0, @@ -218,13 +206,13 @@ impl FormattedSegment { } #[doc(alias = "gst_segment_position_from_running_time_full")] - pub fn position_from_running_time_full>( + pub fn position_from_running_time_full>( &self, running_time: V, - ) -> (i32, T::FormattedValueType) { + ) -> (i32, T::FullRange) { let running_time = running_time.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), running_time.format()); } @@ -238,24 +226,21 @@ impl FormattedSegment { ); ( ret, - T::FormattedValueType::from_raw(self.format(), position.assume_init() as i64), + T::FullRange::from_raw(self.format(), position.assume_init() as i64), ) } } #[doc(alias = "gst_segment_position_from_stream_time")] - pub fn position_from_stream_time>( - &self, - stream_time: V, - ) -> T::FormattedValueType { + pub fn position_from_stream_time>(&self, stream_time: V) -> T::FullRange { let stream_time = stream_time.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), stream_time.format()); } unsafe { - T::FormattedValueType::from_raw( + T::FullRange::from_raw( self.format(), ffi::gst_segment_position_from_stream_time( &self.0, @@ -267,13 +252,13 @@ impl FormattedSegment { } #[doc(alias = "gst_segment_position_from_stream_time_full")] - pub fn position_from_stream_time_full>( + pub fn position_from_stream_time_full>( &self, stream_time: V, - ) -> (i32, T::FormattedValueType) { + ) -> (i32, T::FullRange) { let stream_time = stream_time.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), stream_time.format()); } @@ -287,19 +272,19 @@ impl FormattedSegment { ); ( ret, - T::FormattedValueType::from_raw(self.format(), position.assume_init() as i64), + T::FullRange::from_raw(self.format(), position.assume_init() as i64), ) } } #[doc(alias = "gst_segment_set_running_time")] - pub fn set_running_time>( + pub fn set_running_time>( &mut self, running_time: V, ) -> Result<(), glib::BoolError> { let running_time = running_time.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), running_time.format()); } @@ -316,18 +301,15 @@ impl FormattedSegment { } #[doc(alias = "gst_segment_to_running_time")] - pub fn to_running_time>( - &self, - position: V, - ) -> T::FormattedValueType { + pub fn to_running_time>(&self, position: V) -> T::FullRange { let position = position.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), position.format()); } unsafe { - T::FormattedValueType::from_raw( + T::FullRange::from_raw( self.format(), ffi::gst_segment_to_running_time( &self.0, @@ -339,13 +321,10 @@ impl FormattedSegment { } #[doc(alias = "gst_segment_to_running_time_full")] - pub fn to_running_time_full>( - &self, - position: V, - ) -> (i32, T::FormattedValueType) { + pub fn to_running_time_full>(&self, position: V) -> (i32, T::FullRange) { let position = position.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), position.format()); } @@ -359,24 +338,21 @@ impl FormattedSegment { ); ( ret, - T::FormattedValueType::from_raw(self.format(), running_time.assume_init() as i64), + T::FullRange::from_raw(self.format(), running_time.assume_init() as i64), ) } } #[doc(alias = "gst_segment_to_stream_time")] - pub fn to_stream_time>( - &self, - position: V, - ) -> T::FormattedValueType { + pub fn to_stream_time>(&self, position: V) -> T::FullRange { let position = position.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), position.format()); } unsafe { - T::FormattedValueType::from_raw( + T::FullRange::from_raw( self.format(), ffi::gst_segment_to_stream_time( &self.0, @@ -388,13 +364,10 @@ impl FormattedSegment { } #[doc(alias = "gst_segment_to_stream_time_full")] - pub fn to_stream_time_full>( - &self, - position: V, - ) -> (i32, T::FormattedValueType) { + pub fn to_stream_time_full>(&self, position: V) -> (i32, T::FullRange) { let position = position.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), position.format()); } @@ -408,7 +381,7 @@ impl FormattedSegment { ); ( ret, - T::FormattedValueType::from_raw(self.format(), stream_time.assume_init() as i64), + T::FullRange::from_raw(self.format(), stream_time.assume_init() as i64), ) } } @@ -450,14 +423,14 @@ impl FormattedSegment { } #[doc(alias = "get_base")] - pub fn base(&self) -> T::FormattedValueType { - unsafe { T::FormattedValueType::from_raw(self.format(), self.0.base as i64) } + pub fn base(&self) -> T::FullRange { + unsafe { T::FullRange::from_raw(self.format(), self.0.base as i64) } } - pub fn set_base>(&mut self, base: V) { + pub fn set_base>(&mut self, base: V) { let base = base.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), base.format()); } @@ -465,14 +438,14 @@ impl FormattedSegment { } #[doc(alias = "get_offset")] - pub fn offset(&self) -> T::FormattedValueType { - unsafe { T::FormattedValueType::from_raw(self.format(), self.0.offset as i64) } + pub fn offset(&self) -> T::FullRange { + unsafe { T::FullRange::from_raw(self.format(), self.0.offset as i64) } } - pub fn set_offset>(&mut self, offset: V) { + pub fn set_offset>(&mut self, offset: V) { let offset = offset.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), offset.format()); } @@ -480,14 +453,14 @@ impl FormattedSegment { } #[doc(alias = "get_start")] - pub fn start(&self) -> T::FormattedValueType { - unsafe { T::FormattedValueType::from_raw(self.format(), self.0.start as i64) } + pub fn start(&self) -> T::FullRange { + unsafe { T::FullRange::from_raw(self.format(), self.0.start as i64) } } - pub fn set_start>(&mut self, start: V) { + pub fn set_start>(&mut self, start: V) { let start = start.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), start.format()); } @@ -495,14 +468,14 @@ impl FormattedSegment { } #[doc(alias = "get_stop")] - pub fn stop(&self) -> T::FormattedValueType { - unsafe { T::FormattedValueType::from_raw(self.format(), self.0.stop as i64) } + pub fn stop(&self) -> T::FullRange { + unsafe { T::FullRange::from_raw(self.format(), self.0.stop as i64) } } - pub fn set_stop>(&mut self, stop: V) { + pub fn set_stop>(&mut self, stop: V) { let stop = stop.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), stop.format()); } @@ -510,14 +483,14 @@ impl FormattedSegment { } #[doc(alias = "get_time")] - pub fn time(&self) -> T::FormattedValueType { - unsafe { T::FormattedValueType::from_raw(self.format(), self.0.time as i64) } + pub fn time(&self) -> T::FullRange { + unsafe { T::FullRange::from_raw(self.format(), self.0.time as i64) } } - pub fn set_time>(&mut self, time: V) { + pub fn set_time>(&mut self, time: V) { let time = time.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), time.format()); } @@ -525,14 +498,14 @@ impl FormattedSegment { } #[doc(alias = "get_position")] - pub fn position(&self) -> T::FormattedValueType { - unsafe { T::FormattedValueType::from_raw(self.format(), self.0.position as i64) } + pub fn position(&self) -> T::FullRange { + unsafe { T::FullRange::from_raw(self.format(), self.0.position as i64) } } - pub fn set_position>(&mut self, position: V) { + pub fn set_position>(&mut self, position: V) { let position = position.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), position.format()); } @@ -540,14 +513,14 @@ impl FormattedSegment { } #[doc(alias = "get_duration")] - pub fn duration(&self) -> T::FormattedValueType { - unsafe { T::FormattedValueType::from_raw(self.format(), self.0.duration as i64) } + pub fn duration(&self) -> T::FullRange { + unsafe { T::FullRange::from_raw(self.format(), self.0.duration as i64) } } - pub fn set_duration>(&mut self, duration: V) { + pub fn set_duration>(&mut self, duration: V) { let duration = duration.into(); - if T::FormattedValueType::default_format() == Format::Undefined { + if T::default_format() == Format::Undefined { assert_eq!(self.format(), duration.format()); } diff --git a/gstreamer/src/segment_serde.rs b/gstreamer/src/segment_serde.rs index 6b31c4173..65a25836b 100644 --- a/gstreamer/src/segment_serde.rs +++ b/gstreamer/src/segment_serde.rs @@ -100,7 +100,7 @@ impl<'de, T: SpecificFormattedValueIntrinsic> Deserialize<'de> for FormattedSegm de::Error::custom(format!( "failed to convert segment with format {:?} to {:?}", segment.format(), - T::FormattedValueType::default_format(), + T::default_format(), )) }) })