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<ClockTime>`), the argument was declared:

```rust
    impl Into<GenericFormattedValue>,
```

This commit implements `FormattedValue` for any type representing
a format. E.g.: both `ClockTime` and `Option<ClockTime>` 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
This commit is contained in:
François Laignel 2022-07-03 18:04:06 +02:00
parent fbceaab941
commit fe319af598
16 changed files with 326 additions and 360 deletions

View file

@ -176,13 +176,11 @@ impl AudioInfo {
} }
#[doc(alias = "gst_audio_info_convert")] #[doc(alias = "gst_audio_info_convert")]
pub fn convert<V: Into<gst::GenericFormattedValue>, U: gst::SpecificFormattedValue>( pub fn convert<U: gst::SpecificFormattedValueFullRange>(
&self, &self,
src_val: V, src_val: impl gst::FormattedValue,
) -> Option<U> { ) -> Option<U> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
if from_glib(ffi::gst_audio_info_convert( if from_glib(ffi::gst_audio_info_convert(
@ -199,14 +197,12 @@ impl AudioInfo {
} }
} }
pub fn convert_generic<V: Into<gst::GenericFormattedValue>>( pub fn convert_generic(
&self, &self,
src_val: V, src_val: impl gst::FormattedValue,
dest_fmt: gst::Format, dest_fmt: gst::Format,
) -> Option<gst::GenericFormattedValue> { ) -> Option<gst::GenericFormattedValue> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
if from_glib(ffi::gst_audio_info_convert( if from_glib(ffi::gst_audio_info_convert(

View file

@ -23,21 +23,19 @@ unsafe impl Sync for AudioClippingMeta {}
impl AudioClippingMeta { impl AudioClippingMeta {
#[doc(alias = "gst_buffer_add_audio_clipping_meta")] #[doc(alias = "gst_buffer_add_audio_clipping_meta")]
pub fn add<V: Into<gst::GenericFormattedValue>>( pub fn add<V: gst::FormattedValue>(
buffer: &mut gst::BufferRef, buffer: &mut gst::BufferRef,
start: V, start: V,
end: V, end: V,
) -> gst::MetaRefMut<Self, gst::meta::Standalone> { ) -> gst::MetaRefMut<Self, gst::meta::Standalone> {
skip_assert_initialized!(); skip_assert_initialized!();
let start = start.into();
let end = end.into();
assert_eq!(start.format(), end.format()); assert_eq!(start.format(), end.format());
unsafe { unsafe {
let meta = ffi::gst_buffer_add_audio_clipping_meta( let meta = ffi::gst_buffer_add_audio_clipping_meta(
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
start.format().into_glib(), start.format().into_glib(),
start.value() as u64, start.into_raw_value() as u64,
end.value() as u64, end.into_raw_value() as u64,
); );
Self::from_mut_ptr(buffer, meta) Self::from_mut_ptr(buffer, meta)

View file

@ -55,7 +55,7 @@ pub trait AggregatorExtManual: 'static {
#[doc(alias = "gst_aggregator_update_segment")] #[doc(alias = "gst_aggregator_update_segment")]
fn update_segment<F: gst::FormattedValueIntrinsic>(&self, segment: &gst::FormattedSegment<F>); fn update_segment<F: gst::FormattedValueIntrinsic>(&self, segment: &gst::FormattedSegment<F>);
fn set_position<V: FormattedValue>(&self, position: V); fn set_position(&self, position: impl FormattedValue);
#[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
@ -167,7 +167,7 @@ impl<O: IsA<Aggregator>> AggregatorExtManual for O {
} }
} }
fn set_position<V: FormattedValue>(&self, position: V) { fn set_position(&self, position: impl FormattedValue) {
unsafe { unsafe {
let ptr: *mut ffi::GstAggregator = self.as_ref().to_glib_none().0; let ptr: *mut ffi::GstAggregator = self.as_ref().to_glib_none().0;
let ptr = &mut *ptr; let ptr = &mut *ptr;

View file

@ -4,7 +4,6 @@ use crate::BaseParse;
use crate::BaseParseFrame; use crate::BaseParseFrame;
use glib::prelude::*; use glib::prelude::*;
use glib::translate::*; use glib::translate::*;
use gst::FormattedValue;
use std::mem; use std::mem;
pub trait BaseParseExtManual: 'static { pub trait BaseParseExtManual: 'static {
@ -14,18 +13,18 @@ pub trait BaseParseExtManual: 'static {
fn src_pad(&self) -> &gst::Pad; fn src_pad(&self) -> &gst::Pad;
#[doc(alias = "gst_base_parse_set_duration")] #[doc(alias = "gst_base_parse_set_duration")]
fn set_duration<V: Into<gst::GenericFormattedValue>>(&self, duration: V, interval: u32); fn set_duration(&self, duration: impl gst::FormattedValue, interval: u32);
#[doc(alias = "gst_base_parse_set_frame_rate")] #[doc(alias = "gst_base_parse_set_frame_rate")]
fn set_frame_rate(&self, fps: gst::Fraction, lead_in: u32, lead_out: u32); fn set_frame_rate(&self, fps: gst::Fraction, lead_in: u32, lead_out: u32);
#[doc(alias = "gst_base_parse_convert_default")] #[doc(alias = "gst_base_parse_convert_default")]
fn convert_default<V: Into<gst::GenericFormattedValue>, U: gst::SpecificFormattedValue>( fn convert_default<U: gst::SpecificFormattedValueFullRange>(
&self, &self,
src_val: V, src_val: impl gst::FormattedValue,
) -> Option<U>; ) -> Option<U>;
fn convert_default_generic<V: Into<gst::GenericFormattedValue>>( fn convert_default_generic(
&self, &self,
src_val: V, src_val: impl gst::FormattedValue,
dest_format: gst::Format, dest_format: gst::Format,
) -> Option<gst::GenericFormattedValue>; ) -> Option<gst::GenericFormattedValue>;
@ -52,13 +51,12 @@ impl<O: IsA<BaseParse>> BaseParseExtManual for O {
} }
} }
fn set_duration<V: Into<gst::GenericFormattedValue>>(&self, duration: V, interval: u32) { fn set_duration(&self, duration: impl gst::FormattedValue, interval: u32) {
let duration = duration.into();
unsafe { unsafe {
ffi::gst_base_parse_set_duration( ffi::gst_base_parse_set_duration(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
duration.format().into_glib(), duration.format().into_glib(),
duration.value(), duration.into_raw_value(),
interval as i32, interval as i32,
); );
} }
@ -77,11 +75,10 @@ impl<O: IsA<BaseParse>> BaseParseExtManual for O {
} }
} }
fn convert_default<V: Into<gst::GenericFormattedValue>, U: gst::SpecificFormattedValue>( fn convert_default<U: gst::SpecificFormattedValueFullRange>(
&self, &self,
src_val: V, src_val: impl gst::FormattedValue,
) -> Option<U> { ) -> Option<U> {
let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_base_parse_convert_default( let ret = from_glib(ffi::gst_base_parse_convert_default(
@ -99,12 +96,11 @@ impl<O: IsA<BaseParse>> BaseParseExtManual for O {
} }
} }
fn convert_default_generic<V: Into<gst::GenericFormattedValue>>( fn convert_default_generic(
&self, &self,
src_val: V, src_val: impl gst::FormattedValue,
dest_format: gst::Format, dest_format: gst::Format,
) -> Option<gst::GenericFormattedValue> { ) -> Option<gst::GenericFormattedValue> {
let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_base_parse_convert_default( let ret = from_glib(ffi::gst_base_parse_convert_default(

View file

@ -36,10 +36,10 @@ pub trait BaseParseImpl: BaseParseImplExt + ElementImpl {
self.parent_handle_frame(element, frame) self.parent_handle_frame(element, frame)
} }
fn convert<V: Into<gst::GenericFormattedValue>>( fn convert(
&self, &self,
element: &Self::Type, element: &Self::Type,
src_val: V, src_val: impl gst::FormattedValue,
dest_format: gst::Format, dest_format: gst::Format,
) -> Option<gst::GenericFormattedValue> { ) -> Option<gst::GenericFormattedValue> {
self.parent_convert(element, src_val, dest_format) self.parent_convert(element, src_val, dest_format)
@ -63,10 +63,10 @@ pub trait BaseParseImplExt: ObjectSubclass {
frame: BaseParseFrame, frame: BaseParseFrame,
) -> Result<(gst::FlowSuccess, u32), gst::FlowError>; ) -> Result<(gst::FlowSuccess, u32), gst::FlowError>;
fn parent_convert<V: Into<gst::GenericFormattedValue>>( fn parent_convert(
&self, &self,
element: &Self::Type, element: &Self::Type,
src_val: V, src_val: impl gst::FormattedValue,
dest_format: gst::Format, dest_format: gst::Format,
) -> Option<gst::GenericFormattedValue>; ) -> Option<gst::GenericFormattedValue>;
} }
@ -159,16 +159,15 @@ impl<T: BaseParseImpl> BaseParseImplExt for T {
} }
} }
fn parent_convert<V: Into<gst::GenericFormattedValue>>( fn parent_convert(
&self, &self,
element: &Self::Type, element: &Self::Type,
src_val: V, src_val: impl gst::FormattedValue,
dest_format: gst::Format, dest_format: gst::Format,
) -> Option<gst::GenericFormattedValue> { ) -> Option<gst::GenericFormattedValue> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseParseClass; 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 res = (*parent_class).convert.map(|f| {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();

View file

@ -730,13 +730,11 @@ impl VideoInfo {
} }
#[doc(alias = "gst_video_info_convert")] #[doc(alias = "gst_video_info_convert")]
pub fn convert<V: Into<gst::GenericFormattedValue>, U: gst::SpecificFormattedValue>( pub fn convert<U: gst::SpecificFormattedValueFullRange>(
&self, &self,
src_val: V, src_val: impl gst::FormattedValue,
) -> Option<U> { ) -> Option<U> {
skip_assert_initialized!(); skip_assert_initialized!();
let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
if from_glib(ffi::gst_video_info_convert( if from_glib(ffi::gst_video_info_convert(
@ -753,14 +751,12 @@ impl VideoInfo {
} }
} }
pub fn convert_generic<V: Into<gst::GenericFormattedValue>>( pub fn convert_generic(
&self, &self,
src_val: V, src_val: impl gst::FormattedValue,
dest_fmt: gst::Format, dest_fmt: gst::Format,
) -> Option<gst::GenericFormattedValue> { ) -> Option<gst::GenericFormattedValue> {
skip_assert_initialized!(); skip_assert_initialized!();
let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
if from_glib(ffi::gst_video_info_convert( if from_glib(ffi::gst_video_info_convert(

View file

@ -8,16 +8,13 @@ use crate::prelude::*;
use crate::ClockTime; use crate::ClockTime;
use crate::ElementFlags; use crate::ElementFlags;
use crate::Event; use crate::Event;
use crate::Format;
use crate::FormattedValue;
use crate::GenericFormattedValue;
use crate::Pad; use crate::Pad;
use crate::PadTemplate; use crate::PadTemplate;
use crate::Plugin; use crate::Plugin;
use crate::QueryRef; use crate::QueryRef;
use crate::Rank; use crate::Rank;
use crate::SpecificFormattedValue;
use crate::State; use crate::State;
use crate::{Format, FormattedValue, GenericFormattedValue, SpecificFormattedValueFullRange};
use glib::translate::*; use glib::translate::*;
@ -208,13 +205,13 @@ pub trait ElementExtManual: 'static {
fn remove_property_notify_watch(&self, watch_id: NotifyWatchId); fn remove_property_notify_watch(&self, watch_id: NotifyWatchId);
#[doc(alias = "gst_element_query_convert")] #[doc(alias = "gst_element_query_convert")]
fn query_convert<V: Into<GenericFormattedValue>, U: SpecificFormattedValue>( fn query_convert<U: SpecificFormattedValueFullRange>(
&self, &self,
src_val: V, src_val: impl FormattedValue,
) -> Option<U>; ) -> Option<U>;
fn query_convert_generic<V: Into<GenericFormattedValue>>( fn query_convert_generic(
&self, &self,
src_val: V, src_val: impl FormattedValue,
dest_format: Format, dest_format: Format,
) -> Option<GenericFormattedValue>; ) -> Option<GenericFormattedValue>;
@ -229,7 +226,7 @@ pub trait ElementExtManual: 'static {
fn query_position_generic(&self, format: Format) -> Option<GenericFormattedValue>; fn query_position_generic(&self, format: Format) -> Option<GenericFormattedValue>;
#[doc(alias = "gst_element_seek")] #[doc(alias = "gst_element_seek")]
fn seek<V: Into<GenericFormattedValue>>( fn seek<V: FormattedValue>(
&self, &self,
rate: f64, rate: f64,
flags: crate::SeekFlags, flags: crate::SeekFlags,
@ -239,10 +236,10 @@ pub trait ElementExtManual: 'static {
stop: V, stop: V,
) -> Result<(), glib::error::BoolError>; ) -> Result<(), glib::error::BoolError>;
#[doc(alias = "gst_element_seek_simple")] #[doc(alias = "gst_element_seek_simple")]
fn seek_simple<V: Into<GenericFormattedValue>>( fn seek_simple(
&self, &self,
seek_flags: crate::SeekFlags, seek_flags: crate::SeekFlags,
seek_pos: V, seek_pos: impl FormattedValue,
) -> Result<(), glib::error::BoolError>; ) -> Result<(), glib::error::BoolError>;
#[doc(alias = "gst_element_call_async")] #[doc(alias = "gst_element_call_async")]
@ -553,11 +550,10 @@ impl<O: IsA<Element>> ElementExtManual for O {
} }
} }
fn query_convert<V: Into<GenericFormattedValue>, U: SpecificFormattedValue>( fn query_convert<U: SpecificFormattedValueFullRange>(
&self, &self,
src_val: V, src_val: impl FormattedValue,
) -> Option<U> { ) -> Option<U> {
let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_element_query_convert( let ret = from_glib(ffi::gst_element_query_convert(
@ -575,18 +571,17 @@ impl<O: IsA<Element>> ElementExtManual for O {
} }
} }
fn query_convert_generic<V: Into<GenericFormattedValue>>( fn query_convert_generic(
&self, &self,
src_val: V, src_val: impl FormattedValue,
dest_format: Format, dest_format: Format,
) -> Option<GenericFormattedValue> { ) -> Option<GenericFormattedValue> {
let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_element_query_convert( let ret = from_glib(ffi::gst_element_query_convert(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
src_val.format().into_glib(), src_val.format().into_glib(),
src_val.value(), src_val.into_raw_value(),
dest_format.into_glib(), dest_format.into_glib(),
dest_val.as_mut_ptr(), dest_val.as_mut_ptr(),
)); ));
@ -606,7 +601,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
let mut duration = mem::MaybeUninit::uninit(); let mut duration = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_element_query_duration( let ret = from_glib(ffi::gst_element_query_duration(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
T::FormattedValueType::default_format().into_glib(), T::default_format().into_glib(),
duration.as_mut_ptr(), duration.as_mut_ptr(),
)); ));
if ret { if ret {
@ -638,7 +633,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
let mut cur = mem::MaybeUninit::uninit(); let mut cur = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_element_query_position( let ret = from_glib(ffi::gst_element_query_position(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
T::FormattedValueType::default_format().into_glib(), T::default_format().into_glib(),
cur.as_mut_ptr(), cur.as_mut_ptr(),
)); ));
if ret { if ret {
@ -665,7 +660,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
} }
} }
fn seek<V: Into<GenericFormattedValue>>( fn seek<V: FormattedValue>(
&self, &self,
rate: f64, rate: f64,
flags: crate::SeekFlags, flags: crate::SeekFlags,
@ -674,9 +669,6 @@ impl<O: IsA<Element>> ElementExtManual for O {
stop_type: crate::SeekType, stop_type: crate::SeekType,
stop: V, stop: V,
) -> Result<(), glib::error::BoolError> { ) -> Result<(), glib::error::BoolError> {
let start = start.into();
let stop = stop.into();
assert_eq!(stop.format(), start.format()); assert_eq!(stop.format(), start.format());
unsafe { unsafe {
@ -687,28 +679,27 @@ impl<O: IsA<Element>> ElementExtManual for O {
start.format().into_glib(), start.format().into_glib(),
flags.into_glib(), flags.into_glib(),
start_type.into_glib(), start_type.into_glib(),
start.value(), start.into_raw_value(),
stop_type.into_glib(), stop_type.into_glib(),
stop.value(), stop.into_raw_value(),
), ),
"Failed to seek", "Failed to seek",
) )
} }
} }
fn seek_simple<V: Into<GenericFormattedValue>>( fn seek_simple(
&self, &self,
seek_flags: crate::SeekFlags, seek_flags: crate::SeekFlags,
seek_pos: V, seek_pos: impl FormattedValue,
) -> Result<(), glib::error::BoolError> { ) -> Result<(), glib::error::BoolError> {
let seek_pos = seek_pos.into();
unsafe { unsafe {
glib::result_from_gboolean!( glib::result_from_gboolean!(
ffi::gst_element_seek_simple( ffi::gst_element_seek_simple(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
seek_pos.format().into_glib(), seek_pos.format().into_glib(),
seek_flags.into_glib(), seek_flags.into_glib(),
seek_pos.value(), seek_pos.into_raw_value(),
), ),
"Failed to seek", "Failed to seek",
) )

View file

@ -2,7 +2,7 @@
use crate::structure::*; use crate::structure::*;
use crate::ClockTime; use crate::ClockTime;
use crate::GenericFormattedValue; use crate::{FormattedValue, GenericFormattedValue};
use std::borrow::Borrow; use std::borrow::Borrow;
use std::cmp; use std::cmp;
@ -642,22 +642,20 @@ declare_concrete_event!(@sticky Buffersize, T);
impl Buffersize<Event> { impl Buffersize<Event> {
#[doc(alias = "gst_event_new_buffer_size")] #[doc(alias = "gst_event_new_buffer_size")]
#[allow(clippy::new_ret_no_self)] #[allow(clippy::new_ret_no_self)]
pub fn new<V: Into<GenericFormattedValue>>(minsize: V, maxsize: V, r#async: bool) -> Event { pub fn new<V: FormattedValue>(minsize: V, maxsize: V, r#async: bool) -> Event {
skip_assert_initialized!(); skip_assert_initialized!();
Self::builder(minsize, maxsize, r#async).build() Self::builder(minsize, maxsize, r#async).build()
} }
pub fn builder<'a, V: Into<GenericFormattedValue>>( pub fn builder<'a, V: FormattedValue>(
minsize: V, minsize: V,
maxsize: V, maxsize: V,
r#async: bool, r#async: bool,
) -> BuffersizeBuilder<'a> { ) -> BuffersizeBuilder<'a> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let minsize = minsize.into();
let maxsize = maxsize.into();
assert_eq!(minsize.format(), maxsize.format()); 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<Event> { impl SegmentDone<Event> {
#[doc(alias = "gst_event_new_segment_done")] #[doc(alias = "gst_event_new_segment_done")]
#[allow(clippy::new_ret_no_self)] #[allow(clippy::new_ret_no_self)]
pub fn new<V: Into<GenericFormattedValue>>(position: V) -> Event { pub fn new(position: impl FormattedValue) -> Event {
skip_assert_initialized!(); skip_assert_initialized!();
Self::builder(position).build() Self::builder(position).build()
} }
pub fn builder<'a, V: Into<GenericFormattedValue>>(position: V) -> SegmentDoneBuilder<'a> { pub fn builder<'a>(position: impl FormattedValue) -> SegmentDoneBuilder<'a> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let position = position.into(); SegmentDoneBuilder::new(position.into())
SegmentDoneBuilder::new(position)
} }
} }
@ -1030,7 +1027,7 @@ declare_concrete_event!(Seek, T);
impl Seek<Event> { impl Seek<Event> {
#[doc(alias = "gst_event_new_seek")] #[doc(alias = "gst_event_new_seek")]
#[allow(clippy::new_ret_no_self)] #[allow(clippy::new_ret_no_self)]
pub fn new<V: Into<GenericFormattedValue>>( pub fn new<V: FormattedValue>(
rate: f64, rate: f64,
flags: crate::SeekFlags, flags: crate::SeekFlags,
start_type: crate::SeekType, start_type: crate::SeekType,
@ -1042,7 +1039,7 @@ impl Seek<Event> {
Self::builder(rate, flags, start_type, start, stop_type, stop).build() Self::builder(rate, flags, start_type, start, stop_type, stop).build()
} }
pub fn builder<'a, V: Into<GenericFormattedValue>>( pub fn builder<'a, V: FormattedValue>(
rate: f64, rate: f64,
flags: crate::SeekFlags, flags: crate::SeekFlags,
start_type: crate::SeekType, start_type: crate::SeekType,
@ -1051,11 +1048,16 @@ impl Seek<Event> {
stop: V, stop: V,
) -> SeekBuilder<'a> { ) -> SeekBuilder<'a> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let start = start.into();
let stop = stop.into();
assert_eq!(start.format(), stop.format()); 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<Event> { impl Step<Event> {
#[doc(alias = "gst_event_new_step")] #[doc(alias = "gst_event_new_step")]
#[allow(clippy::new_ret_no_self)] #[allow(clippy::new_ret_no_self)]
pub fn new<V: Into<GenericFormattedValue>>( pub fn new(amount: impl FormattedValue, rate: f64, flush: bool, intermediate: bool) -> Event {
amount: V,
rate: f64,
flush: bool,
intermediate: bool,
) -> Event {
skip_assert_initialized!(); skip_assert_initialized!();
Self::builder(amount.into(), rate, flush, intermediate).build() Self::builder(amount, rate, flush, intermediate).build()
} }
pub fn builder<'a, V: Into<GenericFormattedValue>>( pub fn builder<'a>(
amount: V, amount: impl FormattedValue,
rate: f64, rate: f64,
flush: bool, flush: bool,
intermediate: bool, intermediate: bool,

View file

@ -77,15 +77,31 @@ impl fmt::Display for GenericFormattedValue {
pub struct TryFromGenericFormattedValueError(()); pub struct TryFromGenericFormattedValueError(());
pub trait FormattedValue: Copy + Clone + Sized + Into<GenericFormattedValue> + 'static { pub trait FormattedValue: Copy + Clone + Sized + Into<GenericFormattedValue> + 'static {
// rustdoc-stripper-ignore-next
/// Type which allows building a `FormattedValue` of this format from any raw value.
type FullRange: FormattedValueFullRange + From<Self>;
#[doc(alias = "get_default_format")] #[doc(alias = "get_default_format")]
fn default_format() -> Format; fn default_format() -> Format;
#[doc(alias = "get_format")] #[doc(alias = "get_format")]
fn format(&self) -> Format; fn format(&self) -> Format;
unsafe fn from_raw(format: Format, value: i64) -> Self;
unsafe fn into_raw_value(self) -> i64; 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<Percent>` is the `FormattedValueFullRange` type for `Percent`.
pub trait FormattedValueFullRange: FormattedValue + TryFrom<GenericFormattedValue> {
unsafe fn from_raw(format: Format, value: i64) -> Self;
}
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// A trait implemented on the intrinsic type of a `FormattedValue`. /// A trait implemented on the intrinsic type of a `FormattedValue`.
/// ///
@ -94,11 +110,11 @@ pub trait FormattedValue: Copy + Clone + Sized + Into<GenericFormattedValue> + '
/// - `GenericFormattedValue` is the intrinsic type for `GenericFormattedValue`. /// - `GenericFormattedValue` is the intrinsic type for `GenericFormattedValue`.
/// - `Undefined` is the intrinsic type for `Undefined`. /// - `Undefined` is the intrinsic type for `Undefined`.
/// - `Bytes` is the intrinsic type for `Option<Bytes>`. /// - `Bytes` is the intrinsic type for `Option<Bytes>`.
pub trait FormattedValueIntrinsic: Copy + Clone + Sized + 'static { pub trait FormattedValueIntrinsic: FormattedValue {}
type FormattedValueType: FormattedValue;
}
pub trait SpecificFormattedValue: FormattedValue + TryFrom<GenericFormattedValue> {} pub trait SpecificFormattedValue: FormattedValue {}
pub trait SpecificFormattedValueFullRange: FormattedValueFullRange {}
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// A trait implemented on the intrinsic type of a `SpecificFormattedValue`. /// A trait implemented on the intrinsic type of a `SpecificFormattedValue`.
@ -110,6 +126,8 @@ pub trait SpecificFormattedValue: FormattedValue + TryFrom<GenericFormattedValue
pub trait SpecificFormattedValueIntrinsic: TryFromGlib<i64> + FormattedValueIntrinsic {} pub trait SpecificFormattedValueIntrinsic: TryFromGlib<i64> + FormattedValueIntrinsic {}
impl FormattedValue for GenericFormattedValue { impl FormattedValue for GenericFormattedValue {
type FullRange = GenericFormattedValue;
fn default_format() -> Format { fn default_format() -> Format {
Format::Undefined Format::Undefined
} }
@ -118,15 +136,17 @@ impl FormattedValue for GenericFormattedValue {
self.format() self.format()
} }
unsafe fn from_raw(format: Format, value: i64) -> Self {
GenericFormattedValue::new(format, value)
}
unsafe fn into_raw_value(self) -> i64 { unsafe fn into_raw_value(self) -> i64 {
self.value() self.value()
} }
} }
impl FormattedValueFullRange for GenericFormattedValue {
unsafe fn from_raw(format: Format, value: i64) -> Self {
GenericFormattedValue::new(format, value)
}
}
impl GenericFormattedValue { impl GenericFormattedValue {
pub fn new(format: Format, value: i64) -> Self { pub fn new(format: Format, value: i64) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
@ -136,7 +156,9 @@ impl GenericFormattedValue {
Format::Bytes => Self::Bytes(unsafe { FromGlib::from_glib(value as u64) }), Format::Bytes => Self::Bytes(unsafe { FromGlib::from_glib(value as u64) }),
Format::Time => Self::Time(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::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), Format::__Unknown(_) => Self::Other(format, value),
} }
} }
@ -170,9 +192,7 @@ impl GenericFormattedValue {
} }
} }
impl FormattedValueIntrinsic for GenericFormattedValue { impl FormattedValueIntrinsic for GenericFormattedValue {}
type FormattedValueType = GenericFormattedValue;
}
impl_common_ops_for_newtype_uint!(Default, u64); impl_common_ops_for_newtype_uint!(Default, u64);
impl_format_value_traits!(Default, Default, 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"); option_glib_newtype_display!(Buffers, "buffers");
impl FormattedValue for Undefined { impl FormattedValue for Undefined {
type FullRange = Undefined;
fn default_format() -> Format { fn default_format() -> Format {
Format::Undefined Format::Undefined
} }
@ -200,14 +222,16 @@ impl FormattedValue for Undefined {
Format::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 { unsafe fn from_raw(format: Format, value: i64) -> Self {
debug_assert_eq!(format, Format::Undefined); debug_assert_eq!(format, Format::Undefined);
Undefined(value) Undefined(value)
} }
unsafe fn into_raw_value(self) -> i64 {
self.0
}
} }
impl From<Undefined> for GenericFormattedValue { impl From<Undefined> for GenericFormattedValue {
@ -230,13 +254,7 @@ impl TryFrom<GenericFormattedValue> for Undefined {
} }
} }
impl FormattedValueIntrinsic for Undefined { impl FormattedValueIntrinsic for Undefined {}
type FormattedValueType = Undefined;
}
impl SpecificFormattedValue for Undefined {}
impl SpecificFormattedValueIntrinsic for Undefined {}
impl TryFromGlib<i64> for Undefined { impl TryFromGlib<i64> for Undefined {
type Error = std::convert::Infallible; type Error = std::convert::Infallible;
@ -298,6 +316,8 @@ impl_common_ops_for_newtype_uint!(Percent, u32);
option_glib_newtype_display!(Percent, "%"); option_glib_newtype_display!(Percent, "%");
impl FormattedValue for Option<Percent> { impl FormattedValue for Option<Percent> {
type FullRange = Option<Percent>;
fn default_format() -> Format { fn default_format() -> Format {
Format::Percent Format::Percent
} }
@ -306,14 +326,16 @@ impl FormattedValue for Option<Percent> {
Format::Percent Format::Percent
} }
unsafe fn into_raw_value(self) -> i64 {
self.map_or(-1, |v| v.0 as i64)
}
}
impl FormattedValueFullRange for Option<Percent> {
unsafe fn from_raw(format: Format, value: i64) -> Self { unsafe fn from_raw(format: Format, value: i64) -> Self {
debug_assert_eq!(format, Format::Percent); debug_assert_eq!(format, Format::Percent);
Percent::try_from_glib(value as i64).ok() 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<Option<Percent>> for GenericFormattedValue { impl From<Option<Percent>> for GenericFormattedValue {
@ -329,6 +351,23 @@ impl From<Percent> for GenericFormattedValue {
GenericFormattedValue::Percent(Some(v)) GenericFormattedValue::Percent(Some(v))
} }
} }
impl FormattedValue for Percent {
type FullRange = Option<Percent>;
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<u64> for Percent { impl TryFrom<u64> for Percent {
type Error = GlibNoneError; type Error = GlibNoneError;
@ -366,12 +405,9 @@ impl TryFrom<GenericFormattedValue> for Option<Percent> {
} }
} }
impl FormattedValueIntrinsic for Percent { impl FormattedValueIntrinsic for Percent {}
type FormattedValueType = Option<Percent>;
}
impl SpecificFormattedValue for Option<Percent> {} impl SpecificFormattedValue for Option<Percent> {}
impl SpecificFormattedValueFullRange for Option<Percent> {}
impl SpecificFormattedValueIntrinsic for Percent {} impl SpecificFormattedValueIntrinsic for Percent {}
impl ops::Deref for Percent { impl ops::Deref for Percent {

View file

@ -226,8 +226,8 @@ mod typefind_factory;
pub mod format; pub mod format;
pub use crate::format::{ pub use crate::format::{
FormattedValue, FormattedValueIntrinsic, GenericFormattedValue, SpecificFormattedValue, FormattedValue, FormattedValueFullRange, FormattedValueIntrinsic, GenericFormattedValue,
SpecificFormattedValueIntrinsic, SpecificFormattedValue, SpecificFormattedValueFullRange, SpecificFormattedValueIntrinsic,
}; };
#[cfg(feature = "ser_de")] #[cfg(feature = "ser_de")]
mod format_serde; mod format_serde;
@ -344,8 +344,8 @@ pub mod prelude {
pub use muldiv::MulDiv; pub use muldiv::MulDiv;
pub use crate::format::{ pub use crate::format::{
FormattedValue, FormattedValueIntrinsic, SpecificFormattedValue, FormattedValue, FormattedValueFullRange, FormattedValueIntrinsic, SpecificFormattedValue,
SpecificFormattedValueIntrinsic, SpecificFormattedValueFullRange, SpecificFormattedValueIntrinsic,
}; };
pub use crate::utils::Displayable; pub use crate::utils::Displayable;

View file

@ -375,6 +375,8 @@ macro_rules! impl_common_ops_for_newtype_uint(
macro_rules! impl_format_value_traits( macro_rules! impl_format_value_traits(
($name:ident, $format:ident, $format_value:ident, $inner_type:ty) => { ($name:ident, $format:ident, $format_value:ident, $inner_type:ty) => {
impl FormattedValue for Option<$name> { impl FormattedValue for Option<$name> {
type FullRange = Option<$name>;
fn default_format() -> Format { fn default_format() -> Format {
Format::$format Format::$format
} }
@ -383,14 +385,16 @@ macro_rules! impl_format_value_traits(
Format::$format 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> { unsafe fn from_raw(format: Format, value: i64) -> Option<$name> {
debug_assert_eq!(format, Format::$format); debug_assert_eq!(format, Format::$format);
FromGlib::from_glib(value as u64) FromGlib::from_glib(value as u64)
} }
unsafe fn into_raw_value(self) -> i64 {
IntoGlib::into_glib(self) as i64
}
} }
impl From<Option<$name>> for GenericFormattedValue { impl From<Option<$name>> for GenericFormattedValue {
@ -406,11 +410,28 @@ macro_rules! impl_format_value_traits(
Self::$format_value(Some(v)) Self::$format_value(Some(v))
} }
} }
impl FormattedValue for $name {
type FullRange = Option<$name>;
impl FormattedValueIntrinsic for $name { fn default_format() -> Format {
type FormattedValueType = Option<$name>; 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<GenericFormattedValue> for Option<$name> { impl TryFrom<GenericFormattedValue> for Option<$name> {
type Error = TryFromGenericFormattedValueError; 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 { impl ops::Deref for $name {
type Target = $inner_type; type Target = $inner_type;

View file

@ -673,32 +673,24 @@ declare_concrete_message!(StepDone, T);
impl StepDone { impl StepDone {
#[doc(alias = "gst_message_new_step_done")] #[doc(alias = "gst_message_new_step_done")]
#[allow(clippy::new_ret_no_self)] #[allow(clippy::new_ret_no_self)]
pub fn new<V: Into<GenericFormattedValue>>( pub fn new(
amount: V, amount: impl FormattedValue,
rate: f64, rate: f64,
flush: bool, flush: bool,
intermediate: bool, intermediate: bool,
duration: V, duration: impl Into<Option<crate::ClockTime>>,
eos: bool, eos: bool,
) -> Message { ) -> Message {
skip_assert_initialized!(); skip_assert_initialized!();
Self::builder( Self::builder(amount, rate, flush, intermediate, duration, eos).build()
amount.into(),
rate,
flush,
intermediate,
duration.into(),
eos,
)
.build()
} }
pub fn builder<'a, V: Into<GenericFormattedValue>>( pub fn builder<'a>(
amount: V, amount: impl FormattedValue,
rate: f64, rate: f64,
flush: bool, flush: bool,
intermediate: bool, intermediate: bool,
duration: V, duration: impl Into<Option<crate::ClockTime>>,
eos: bool, eos: bool,
) -> StepDoneBuilder<'a> { ) -> StepDoneBuilder<'a> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
@ -720,7 +712,7 @@ impl StepDone {
f64, f64,
bool, bool,
bool, bool,
GenericFormattedValue, Option<crate::ClockTime>,
bool, bool,
) { ) {
unsafe { unsafe {
@ -751,10 +743,7 @@ impl StepDone {
rate.assume_init(), rate.assume_init(),
from_glib(flush.assume_init()), from_glib(flush.assume_init()),
from_glib(intermediate.assume_init()), from_glib(intermediate.assume_init()),
GenericFormattedValue::new( from_glib(duration.assume_init()),
from_glib(format.assume_init()),
duration.assume_init() as i64,
),
from_glib(eos.assume_init()), from_glib(eos.assume_init()),
) )
} }
@ -970,15 +959,14 @@ declare_concrete_message!(SegmentStart, T);
impl SegmentStart { impl SegmentStart {
#[doc(alias = "gst_message_new_segment_start")] #[doc(alias = "gst_message_new_segment_start")]
#[allow(clippy::new_ret_no_self)] #[allow(clippy::new_ret_no_self)]
pub fn new<V: Into<GenericFormattedValue>>(position: V) -> Message { pub fn new(position: impl FormattedValue) -> Message {
skip_assert_initialized!(); skip_assert_initialized!();
Self::builder(position).build() Self::builder(position).build()
} }
pub fn builder<'a, V: Into<GenericFormattedValue>>(position: V) -> SegmentStartBuilder<'a> { pub fn builder<'a>(position: impl FormattedValue) -> SegmentStartBuilder<'a> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let position = position.into(); SegmentStartBuilder::new(position.into())
SegmentStartBuilder::new(position)
} }
#[doc(alias = "gst_message_parse_segment_start")] #[doc(alias = "gst_message_parse_segment_start")]
@ -1002,15 +990,14 @@ declare_concrete_message!(SegmentDone, T);
impl SegmentDone { impl SegmentDone {
#[doc(alias = "gst_message_new_segment_done")] #[doc(alias = "gst_message_new_segment_done")]
#[allow(clippy::new_ret_no_self)] #[allow(clippy::new_ret_no_self)]
pub fn new<V: Into<GenericFormattedValue>>(position: V) -> Message { pub fn new(position: impl FormattedValue) -> Message {
skip_assert_initialized!(); skip_assert_initialized!();
Self::builder(position).build() Self::builder(position).build()
} }
pub fn builder<'a, V: Into<GenericFormattedValue>>(position: V) -> SegmentDoneBuilder<'a> { pub fn builder<'a>(position: impl FormattedValue) -> SegmentDoneBuilder<'a> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let position = position.into(); SegmentDoneBuilder::new(position.into())
SegmentDoneBuilder::new(position)
} }
#[doc(alias = "gst_message_parse_segment_done")] #[doc(alias = "gst_message_parse_segment_done")]
@ -1133,20 +1120,20 @@ declare_concrete_message!(StepStart, T);
impl StepStart { impl StepStart {
#[doc(alias = "gst_message_new_step_start")] #[doc(alias = "gst_message_new_step_start")]
#[allow(clippy::new_ret_no_self)] #[allow(clippy::new_ret_no_self)]
pub fn new<V: Into<GenericFormattedValue>>( pub fn new(
active: bool, active: bool,
amount: V, amount: impl FormattedValue,
rate: f64, rate: f64,
flush: bool, flush: bool,
intermediate: bool, intermediate: bool,
) -> Message { ) -> Message {
skip_assert_initialized!(); 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<GenericFormattedValue>>( pub fn builder<'a>(
active: bool, active: bool,
amount: V, amount: impl FormattedValue,
rate: f64, rate: f64,
flush: bool, flush: bool,
intermediate: bool, intermediate: bool,
@ -2168,7 +2155,7 @@ pub struct StepDoneBuilder<'a> {
rate: f64, rate: f64,
flush: bool, flush: bool,
intermediate: bool, intermediate: bool,
duration: GenericFormattedValue, duration: Option<crate::ClockTime>,
eos: bool, eos: bool,
} }
@ -2178,7 +2165,7 @@ impl<'a> StepDoneBuilder<'a> {
rate: f64, rate: f64,
flush: bool, flush: bool,
intermediate: bool, intermediate: bool,
duration: GenericFormattedValue, duration: Option<crate::ClockTime>,
eos: bool, eos: bool,
) -> Self { ) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
@ -2201,7 +2188,7 @@ impl<'a> StepDoneBuilder<'a> {
s.rate, s.rate,
s.flush.into_glib(), s.flush.into_glib(),
s.intermediate.into_glib(), s.intermediate.into_glib(),
s.duration.value() as u64, s.duration.into_raw_value() as u64,
s.eos.into_glib(), s.eos.into_glib(),
)); ));
} }
@ -2613,12 +2600,10 @@ impl<'a> QosBuilder<'a> {
} }
} }
pub fn stats<V: Into<GenericFormattedValue>>(self, processed: V, dropped: V) -> Self { pub fn stats<V: FormattedValue>(self, processed: V, dropped: V) -> Self {
let processed = processed.into();
let dropped = dropped.into();
assert_eq!(processed.format(), dropped.format()); assert_eq!(processed.format(), dropped.format());
Self { Self {
stats: Some((processed, dropped)), stats: Some((processed.into(), dropped.into())),
..self ..self
} }
} }

View file

@ -6,9 +6,6 @@ use crate::Event;
use crate::FlowError; use crate::FlowError;
use crate::FlowReturn; use crate::FlowReturn;
use crate::FlowSuccess; use crate::FlowSuccess;
use crate::Format;
use crate::FormattedValue;
use crate::GenericFormattedValue;
use crate::LoggableError; use crate::LoggableError;
use crate::Pad; use crate::Pad;
use crate::PadFlags; use crate::PadFlags;
@ -17,7 +14,10 @@ use crate::PadProbeType;
use crate::Query; use crate::Query;
use crate::QueryRef; use crate::QueryRef;
use crate::StaticPadTemplate; use crate::StaticPadTemplate;
use crate::{SpecificFormattedValue, SpecificFormattedValueIntrinsic}; use crate::{
Format, FormattedValue, GenericFormattedValue, SpecificFormattedValueFullRange,
SpecificFormattedValueIntrinsic,
};
use std::mem; use std::mem;
use std::num::NonZeroU64; use std::num::NonZeroU64;
@ -272,14 +272,14 @@ pub trait PadExtManual: 'static {
fn start_task<F: FnMut() + Send + 'static>(&self, func: F) -> Result<(), glib::BoolError>; fn start_task<F: FnMut() + Send + 'static>(&self, func: F) -> Result<(), glib::BoolError>;
#[doc(alias = "gst_pad_peer_query_convert")] #[doc(alias = "gst_pad_peer_query_convert")]
fn peer_query_convert<V: Into<GenericFormattedValue>, U: SpecificFormattedValue>( fn peer_query_convert<U: SpecificFormattedValueFullRange>(
&self, &self,
src_val: V, src_val: impl FormattedValue,
) -> Option<U>; ) -> Option<U>;
#[doc(alias = "gst_pad_peer_query_convert")] #[doc(alias = "gst_pad_peer_query_convert")]
fn peer_query_convert_generic<V: Into<GenericFormattedValue>>( fn peer_query_convert_generic(
&self, &self,
src_val: V, src_val: impl FormattedValue,
dest_format: Format, dest_format: Format,
) -> Option<GenericFormattedValue>; ) -> Option<GenericFormattedValue>;
@ -294,14 +294,14 @@ pub trait PadExtManual: 'static {
fn peer_query_position_generic(&self, format: Format) -> Option<GenericFormattedValue>; fn peer_query_position_generic(&self, format: Format) -> Option<GenericFormattedValue>;
#[doc(alias = "gst_pad_query_convert")] #[doc(alias = "gst_pad_query_convert")]
fn query_convert<V: Into<GenericFormattedValue>, U: SpecificFormattedValue>( fn query_convert<U: SpecificFormattedValueFullRange>(
&self, &self,
src_val: V, src_val: impl FormattedValue,
) -> Option<U>; ) -> Option<U>;
#[doc(alias = "gst_pad_query_convert")] #[doc(alias = "gst_pad_query_convert")]
fn query_convert_generic<V: Into<GenericFormattedValue>>( fn query_convert_generic(
&self, &self,
src_val: V, src_val: impl FormattedValue,
dest_format: Format, dest_format: Format,
) -> Option<GenericFormattedValue>; ) -> Option<GenericFormattedValue>;
@ -781,11 +781,10 @@ impl<O: IsA<Pad>> PadExtManual for O {
} }
} }
fn peer_query_convert<V: Into<GenericFormattedValue>, U: SpecificFormattedValue>( fn peer_query_convert<U: SpecificFormattedValueFullRange>(
&self, &self,
src_val: V, src_val: impl FormattedValue,
) -> Option<U> { ) -> Option<U> {
let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_pad_peer_query_convert( let ret = from_glib(ffi::gst_pad_peer_query_convert(
@ -803,12 +802,11 @@ impl<O: IsA<Pad>> PadExtManual for O {
} }
} }
fn peer_query_convert_generic<V: Into<GenericFormattedValue>>( fn peer_query_convert_generic(
&self, &self,
src_val: V, src_val: impl FormattedValue,
dest_format: Format, dest_format: Format,
) -> Option<GenericFormattedValue> { ) -> Option<GenericFormattedValue> {
let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_pad_peer_query_convert( let ret = from_glib(ffi::gst_pad_peer_query_convert(
@ -834,7 +832,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
let mut duration = mem::MaybeUninit::uninit(); let mut duration = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_pad_peer_query_duration( let ret = from_glib(ffi::gst_pad_peer_query_duration(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
T::FormattedValueType::default_format().into_glib(), T::default_format().into_glib(),
duration.as_mut_ptr(), duration.as_mut_ptr(),
)); ));
if ret { if ret {
@ -866,7 +864,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
let mut cur = mem::MaybeUninit::uninit(); let mut cur = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_pad_peer_query_position( let ret = from_glib(ffi::gst_pad_peer_query_position(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
T::FormattedValueType::default_format().into_glib(), T::default_format().into_glib(),
cur.as_mut_ptr(), cur.as_mut_ptr(),
)); ));
if ret { if ret {
@ -893,12 +891,10 @@ impl<O: IsA<Pad>> PadExtManual for O {
} }
} }
fn query_convert<V: Into<GenericFormattedValue>, U: SpecificFormattedValue>( fn query_convert<U: SpecificFormattedValueFullRange>(
&self, &self,
src_val: V, src_val: impl FormattedValue,
) -> Option<U> { ) -> Option<U> {
let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_pad_query_convert( let ret = from_glib(ffi::gst_pad_query_convert(
@ -916,19 +912,17 @@ impl<O: IsA<Pad>> PadExtManual for O {
} }
} }
fn query_convert_generic<V: Into<GenericFormattedValue>>( fn query_convert_generic(
&self, &self,
src_val: V, src_val: impl FormattedValue,
dest_format: Format, dest_format: Format,
) -> Option<GenericFormattedValue> { ) -> Option<GenericFormattedValue> {
let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_pad_query_convert( let ret = from_glib(ffi::gst_pad_query_convert(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
src_val.format().into_glib(), src_val.format().into_glib(),
src_val.value(), src_val.into_raw_value(),
dest_format.into_glib(), dest_format.into_glib(),
dest_val.as_mut_ptr(), dest_val.as_mut_ptr(),
)); ));
@ -948,7 +942,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
let mut duration = mem::MaybeUninit::uninit(); let mut duration = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_pad_query_duration( let ret = from_glib(ffi::gst_pad_query_duration(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
T::FormattedValueType::default_format().into_glib(), T::default_format().into_glib(),
duration.as_mut_ptr(), duration.as_mut_ptr(),
)); ));
if ret { if ret {
@ -980,7 +974,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
let mut cur = mem::MaybeUninit::uninit(); let mut cur = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_pad_query_position( let ret = from_glib(ffi::gst_pad_query_position(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
T::FormattedValueType::default_format().into_glib(), T::default_format().into_glib(),
cur.as_mut_ptr(), cur.as_mut_ptr(),
)); ));
if ret { if ret {

View file

@ -1,7 +1,7 @@
// Take a look at the license at the top of the repository in the LICENSE file. // Take a look at the license at the top of the repository in the LICENSE file.
use crate::structure::*; use crate::structure::*;
use crate::GenericFormattedValue; use crate::{FormattedValue, GenericFormattedValue};
use std::borrow::{Borrow, BorrowMut}; use std::borrow::{Borrow, BorrowMut};
use std::ffi::CStr; use std::ffi::CStr;
@ -319,11 +319,14 @@ impl Position {
} }
#[doc(alias = "gst_query_set_position")] #[doc(alias = "gst_query_set_position")]
pub fn set<V: Into<GenericFormattedValue>>(&mut self, pos: V) { pub fn set(&mut self, pos: impl FormattedValue) {
let pos = pos.into();
assert_eq!(pos.format(), self.format()); assert_eq!(pos.format(), self.format());
unsafe { 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")] #[doc(alias = "gst_query_set_duration")]
pub fn set<V: Into<GenericFormattedValue>>(&mut self, dur: V) { pub fn set(&mut self, dur: impl FormattedValue) {
let dur = dur.into();
assert_eq!(dur.format(), self.format()); assert_eq!(dur.format(), self.format());
unsafe { 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")] #[doc(alias = "gst_query_set_seeking")]
pub fn set<V: Into<GenericFormattedValue>>(&mut self, seekable: bool, start: V, end: V) { pub fn set<V: FormattedValue>(&mut self, seekable: bool, start: V, end: V) {
let start = start.into();
let end = end.into();
assert_eq!(self.format(), start.format()); assert_eq!(self.format(), start.format());
assert_eq!(start.format(), end.format()); assert_eq!(start.format(), end.format());
@ -494,8 +497,8 @@ impl Seeking {
self.as_mut_ptr(), self.as_mut_ptr(),
start.format().into_glib(), start.format().into_glib(),
seekable.into_glib(), seekable.into_glib(),
start.value(), start.into_raw_value(),
end.value(), end.into_raw_value(),
); );
} }
} }
@ -553,10 +556,7 @@ impl Segment {
} }
#[doc(alias = "gst_query_set_segment")] #[doc(alias = "gst_query_set_segment")]
pub fn set<V: Into<GenericFormattedValue>>(&mut self, rate: f64, start: V, stop: V) { pub fn set<V: FormattedValue>(&mut self, rate: f64, start: V, stop: V) {
let start = start.into();
let stop = stop.into();
assert_eq!(start.format(), stop.format()); assert_eq!(start.format(), stop.format());
unsafe { unsafe {
@ -564,8 +564,8 @@ impl Segment {
self.as_mut_ptr(), self.as_mut_ptr(),
rate, rate,
start.format().into_glib(), start.format().into_glib(),
start.value(), start.into_raw_value(),
stop.value(), stop.into_raw_value(),
); );
} }
} }
@ -574,13 +574,12 @@ impl Segment {
declare_concrete_query!(Convert, T); declare_concrete_query!(Convert, T);
impl Convert<Query> { impl Convert<Query> {
#[doc(alias = "gst_query_new_convert")] #[doc(alias = "gst_query_new_convert")]
pub fn new<V: Into<GenericFormattedValue>>(value: V, dest_fmt: crate::Format) -> Self { pub fn new(value: impl FormattedValue, dest_fmt: crate::Format) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let value = value.into();
unsafe { unsafe {
Self(from_glib_full(ffi::gst_query_new_convert( Self(from_glib_full(ffi::gst_query_new_convert(
value.format().into_glib(), value.format().into_glib(),
value.value(), value.into_raw_value(),
dest_fmt.into_glib(), dest_fmt.into_glib(),
))) )))
} }
@ -633,17 +632,14 @@ impl Convert {
} }
#[doc(alias = "gst_query_set_convert")] #[doc(alias = "gst_query_set_convert")]
pub fn set<V: Into<GenericFormattedValue>>(&mut self, src: V, dest: V) { pub fn set(&mut self, src: impl FormattedValue, dest: impl FormattedValue) {
let src = src.into();
let dest = dest.into();
unsafe { unsafe {
ffi::gst_query_set_convert( ffi::gst_query_set_convert(
self.as_mut_ptr(), self.as_mut_ptr(),
src.format().into_glib(), src.format().into_glib(),
src.value(), src.into_raw_value(),
dest.format().into_glib(), dest.format().into_glib(),
dest.value(), dest.into_raw_value(),
); );
} }
} }
@ -840,15 +836,7 @@ impl Buffering {
} }
#[doc(alias = "gst_query_set_buffering_range")] #[doc(alias = "gst_query_set_buffering_range")]
pub fn set_range<V: Into<GenericFormattedValue>>( pub fn set_range<V: FormattedValue>(&mut self, start: V, stop: V, estimated_total: i64) {
&mut self,
start: V,
stop: V,
estimated_total: i64,
) {
let start = start.into();
let stop = stop.into();
assert_eq!(self.format(), start.format()); assert_eq!(self.format(), start.format());
assert_eq!(start.format(), stop.format()); assert_eq!(start.format(), stop.format());
@ -856,8 +844,8 @@ impl Buffering {
ffi::gst_query_set_buffering_range( ffi::gst_query_set_buffering_range(
self.as_mut_ptr(), self.as_mut_ptr(),
start.format().into_glib(), start.format().into_glib(),
start.value(), start.into_raw_value(),
stop.value(), stop.into_raw_value(),
estimated_total, estimated_total,
); );
} }
@ -884,19 +872,18 @@ impl Buffering {
} }
#[doc(alias = "gst_query_add_buffering_range")] #[doc(alias = "gst_query_add_buffering_range")]
pub fn add_buffering_ranges<V: Into<GenericFormattedValue> + Copy>( pub fn add_buffering_ranges<V: FormattedValue + Copy>(&mut self, ranges: &[(V, V)]) {
&mut self,
ranges: &[(V, V)],
) {
unsafe { unsafe {
let fmt = self.format(); let fmt = self.format();
for &(start, stop) in ranges { for &(start, stop) in ranges {
let start = start.into();
let stop = stop.into();
assert_eq!(start.format(), fmt); assert_eq!(start.format(), fmt);
assert_eq!(stop.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(),
);
} }
} }
} }

View file

@ -4,7 +4,7 @@ use crate::Format;
use crate::GenericFormattedValue; use crate::GenericFormattedValue;
use crate::SeekFlags; use crate::SeekFlags;
use crate::SeekType; use crate::SeekType;
use crate::{FormattedValue, FormattedValueIntrinsic}; use crate::{FormattedValue, FormattedValueFullRange, FormattedValueIntrinsic};
use glib::translate::*; use glib::translate::*;
use glib::StaticType; use glib::StaticType;
use std::fmt; use std::fmt;
@ -34,9 +34,7 @@ impl Segment {
} }
pub fn downcast<T: FormattedValueIntrinsic>(self) -> Result<FormattedSegment<T>, Self> { pub fn downcast<T: FormattedValueIntrinsic>(self) -> Result<FormattedSegment<T>, Self> {
if T::FormattedValueType::default_format() == Format::Undefined if T::default_format() == Format::Undefined || T::default_format() == self.format() {
|| T::FormattedValueType::default_format() == self.format()
{
Ok(FormattedSegment(self.0, PhantomData)) Ok(FormattedSegment(self.0, PhantomData))
} else { } else {
Err(self) Err(self)
@ -44,9 +42,7 @@ impl Segment {
} }
pub fn downcast_ref<T: FormattedValueIntrinsic>(&self) -> Option<&FormattedSegment<T>> { pub fn downcast_ref<T: FormattedValueIntrinsic>(&self) -> Option<&FormattedSegment<T>> {
if T::FormattedValueType::default_format() == Format::Undefined if T::default_format() == Format::Undefined || T::default_format() == self.format() {
|| T::FormattedValueType::default_format() == self.format()
{
Some(unsafe { Some(unsafe {
&*(self as *const FormattedSegment<GenericFormattedValue> &*(self as *const FormattedSegment<GenericFormattedValue>
as *const FormattedSegment<T>) as *const FormattedSegment<T>)
@ -57,9 +53,7 @@ impl Segment {
} }
pub fn downcast_mut<T: FormattedValueIntrinsic>(&mut self) -> Option<&mut FormattedSegment<T>> { pub fn downcast_mut<T: FormattedValueIntrinsic>(&mut self) -> Option<&mut FormattedSegment<T>> {
if T::FormattedValueType::default_format() == Format::Undefined if T::default_format() == Format::Undefined || T::default_format() == self.format() {
|| T::FormattedValueType::default_format() == self.format()
{
Some(unsafe { Some(unsafe {
&mut *(self as *mut FormattedSegment<GenericFormattedValue> &mut *(self as *mut FormattedSegment<GenericFormattedValue>
as *mut FormattedSegment<T>) as *mut FormattedSegment<T>)
@ -75,10 +69,7 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let segment = unsafe { let segment = unsafe {
let mut segment = mem::MaybeUninit::zeroed(); let mut segment = mem::MaybeUninit::zeroed();
ffi::gst_segment_init( ffi::gst_segment_init(segment.as_mut_ptr(), T::default_format().into_glib());
segment.as_mut_ptr(),
T::FormattedValueType::default_format().into_glib(),
);
segment.assume_init() segment.assume_init()
}; };
FormattedSegment(segment, PhantomData) FormattedSegment(segment, PhantomData)
@ -96,23 +87,20 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
pub fn reset(&mut self) { pub fn reset(&mut self) {
unsafe { unsafe {
ffi::gst_segment_init( ffi::gst_segment_init(&mut self.0, T::default_format().into_glib());
&mut self.0,
T::FormattedValueType::default_format().into_glib(),
);
} }
} }
#[doc(alias = "gst_segment_clip")] #[doc(alias = "gst_segment_clip")]
pub fn clip<V: Into<T::FormattedValueType>>( pub fn clip<V: Into<T::FullRange>>(
&self, &self,
start: V, start: V,
stop: V, stop: V,
) -> Option<(T::FormattedValueType, T::FormattedValueType)> { ) -> Option<(T::FullRange, T::FullRange)> {
let start = start.into(); let start = start.into();
let stop = stop.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(), start.format());
assert_eq!(self.format(), stop.format()); assert_eq!(self.format(), stop.format());
} }
@ -130,8 +118,8 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
)); ));
if ret { if ret {
Some(( Some((
T::FormattedValueType::from_raw(self.format(), clip_start.assume_init() as i64), T::FullRange::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_stop.assume_init() as i64),
)) ))
} else { } else {
None None
@ -141,7 +129,7 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
#[doc(alias = "gst_segment_do_seek")] #[doc(alias = "gst_segment_do_seek")]
pub fn do_seek<V: Into<T::FormattedValueType>>( pub fn do_seek<V: Into<T::FullRange>>(
&mut self, &mut self,
rate: f64, rate: f64,
flags: SeekFlags, flags: SeekFlags,
@ -154,7 +142,7 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
let start = start.into(); let start = start.into();
let stop = stop.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(), start.format());
assert_eq!(self.format(), stop.format()); assert_eq!(self.format(), stop.format());
} }
@ -195,18 +183,18 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
} }
#[doc(alias = "gst_segment_position_from_running_time")] #[doc(alias = "gst_segment_position_from_running_time")]
pub fn position_from_running_time<V: Into<T::FormattedValueType>>( pub fn position_from_running_time<V: Into<T::FullRange>>(
&self, &self,
running_time: V, running_time: V,
) -> T::FormattedValueType { ) -> T::FullRange {
let running_time = running_time.into(); 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()); assert_eq!(self.format(), running_time.format());
} }
unsafe { unsafe {
T::FormattedValueType::from_raw( T::FullRange::from_raw(
self.format(), self.format(),
ffi::gst_segment_position_from_running_time( ffi::gst_segment_position_from_running_time(
&self.0, &self.0,
@ -218,13 +206,13 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
} }
#[doc(alias = "gst_segment_position_from_running_time_full")] #[doc(alias = "gst_segment_position_from_running_time_full")]
pub fn position_from_running_time_full<V: Into<T::FormattedValueType>>( pub fn position_from_running_time_full<V: Into<T::FullRange>>(
&self, &self,
running_time: V, running_time: V,
) -> (i32, T::FormattedValueType) { ) -> (i32, T::FullRange) {
let running_time = running_time.into(); 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()); assert_eq!(self.format(), running_time.format());
} }
@ -238,24 +226,21 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
); );
( (
ret, 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")] #[doc(alias = "gst_segment_position_from_stream_time")]
pub fn position_from_stream_time<V: Into<T::FormattedValueType>>( pub fn position_from_stream_time<V: Into<T::FullRange>>(&self, stream_time: V) -> T::FullRange {
&self,
stream_time: V,
) -> T::FormattedValueType {
let stream_time = stream_time.into(); 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()); assert_eq!(self.format(), stream_time.format());
} }
unsafe { unsafe {
T::FormattedValueType::from_raw( T::FullRange::from_raw(
self.format(), self.format(),
ffi::gst_segment_position_from_stream_time( ffi::gst_segment_position_from_stream_time(
&self.0, &self.0,
@ -267,13 +252,13 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
} }
#[doc(alias = "gst_segment_position_from_stream_time_full")] #[doc(alias = "gst_segment_position_from_stream_time_full")]
pub fn position_from_stream_time_full<V: Into<T::FormattedValueType>>( pub fn position_from_stream_time_full<V: Into<T::FullRange>>(
&self, &self,
stream_time: V, stream_time: V,
) -> (i32, T::FormattedValueType) { ) -> (i32, T::FullRange) {
let stream_time = stream_time.into(); 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()); assert_eq!(self.format(), stream_time.format());
} }
@ -287,19 +272,19 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
); );
( (
ret, 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")] #[doc(alias = "gst_segment_set_running_time")]
pub fn set_running_time<V: Into<T::FormattedValueType>>( pub fn set_running_time<V: Into<T::FullRange>>(
&mut self, &mut self,
running_time: V, running_time: V,
) -> Result<(), glib::BoolError> { ) -> Result<(), glib::BoolError> {
let running_time = running_time.into(); 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()); assert_eq!(self.format(), running_time.format());
} }
@ -316,18 +301,15 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
} }
#[doc(alias = "gst_segment_to_running_time")] #[doc(alias = "gst_segment_to_running_time")]
pub fn to_running_time<V: Into<T::FormattedValueType>>( pub fn to_running_time<V: Into<T::FullRange>>(&self, position: V) -> T::FullRange {
&self,
position: V,
) -> T::FormattedValueType {
let position = position.into(); let position = position.into();
if T::FormattedValueType::default_format() == Format::Undefined { if T::default_format() == Format::Undefined {
assert_eq!(self.format(), position.format()); assert_eq!(self.format(), position.format());
} }
unsafe { unsafe {
T::FormattedValueType::from_raw( T::FullRange::from_raw(
self.format(), self.format(),
ffi::gst_segment_to_running_time( ffi::gst_segment_to_running_time(
&self.0, &self.0,
@ -339,13 +321,10 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
} }
#[doc(alias = "gst_segment_to_running_time_full")] #[doc(alias = "gst_segment_to_running_time_full")]
pub fn to_running_time_full<V: Into<T::FormattedValueType>>( pub fn to_running_time_full<V: Into<T::FullRange>>(&self, position: V) -> (i32, T::FullRange) {
&self,
position: V,
) -> (i32, T::FormattedValueType) {
let position = position.into(); let position = position.into();
if T::FormattedValueType::default_format() == Format::Undefined { if T::default_format() == Format::Undefined {
assert_eq!(self.format(), position.format()); assert_eq!(self.format(), position.format());
} }
@ -359,24 +338,21 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
); );
( (
ret, 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")] #[doc(alias = "gst_segment_to_stream_time")]
pub fn to_stream_time<V: Into<T::FormattedValueType>>( pub fn to_stream_time<V: Into<T::FullRange>>(&self, position: V) -> T::FullRange {
&self,
position: V,
) -> T::FormattedValueType {
let position = position.into(); let position = position.into();
if T::FormattedValueType::default_format() == Format::Undefined { if T::default_format() == Format::Undefined {
assert_eq!(self.format(), position.format()); assert_eq!(self.format(), position.format());
} }
unsafe { unsafe {
T::FormattedValueType::from_raw( T::FullRange::from_raw(
self.format(), self.format(),
ffi::gst_segment_to_stream_time( ffi::gst_segment_to_stream_time(
&self.0, &self.0,
@ -388,13 +364,10 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
} }
#[doc(alias = "gst_segment_to_stream_time_full")] #[doc(alias = "gst_segment_to_stream_time_full")]
pub fn to_stream_time_full<V: Into<T::FormattedValueType>>( pub fn to_stream_time_full<V: Into<T::FullRange>>(&self, position: V) -> (i32, T::FullRange) {
&self,
position: V,
) -> (i32, T::FormattedValueType) {
let position = position.into(); let position = position.into();
if T::FormattedValueType::default_format() == Format::Undefined { if T::default_format() == Format::Undefined {
assert_eq!(self.format(), position.format()); assert_eq!(self.format(), position.format());
} }
@ -408,7 +381,7 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
); );
( (
ret, 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<T: FormattedValueIntrinsic> FormattedSegment<T> {
} }
#[doc(alias = "get_base")] #[doc(alias = "get_base")]
pub fn base(&self) -> T::FormattedValueType { pub fn base(&self) -> T::FullRange {
unsafe { T::FormattedValueType::from_raw(self.format(), self.0.base as i64) } unsafe { T::FullRange::from_raw(self.format(), self.0.base as i64) }
} }
pub fn set_base<V: Into<T::FormattedValueType>>(&mut self, base: V) { pub fn set_base<V: Into<T::FullRange>>(&mut self, base: V) {
let base = base.into(); let base = base.into();
if T::FormattedValueType::default_format() == Format::Undefined { if T::default_format() == Format::Undefined {
assert_eq!(self.format(), base.format()); assert_eq!(self.format(), base.format());
} }
@ -465,14 +438,14 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
} }
#[doc(alias = "get_offset")] #[doc(alias = "get_offset")]
pub fn offset(&self) -> T::FormattedValueType { pub fn offset(&self) -> T::FullRange {
unsafe { T::FormattedValueType::from_raw(self.format(), self.0.offset as i64) } unsafe { T::FullRange::from_raw(self.format(), self.0.offset as i64) }
} }
pub fn set_offset<V: Into<T::FormattedValueType>>(&mut self, offset: V) { pub fn set_offset<V: Into<T::FullRange>>(&mut self, offset: V) {
let offset = offset.into(); let offset = offset.into();
if T::FormattedValueType::default_format() == Format::Undefined { if T::default_format() == Format::Undefined {
assert_eq!(self.format(), offset.format()); assert_eq!(self.format(), offset.format());
} }
@ -480,14 +453,14 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
} }
#[doc(alias = "get_start")] #[doc(alias = "get_start")]
pub fn start(&self) -> T::FormattedValueType { pub fn start(&self) -> T::FullRange {
unsafe { T::FormattedValueType::from_raw(self.format(), self.0.start as i64) } unsafe { T::FullRange::from_raw(self.format(), self.0.start as i64) }
} }
pub fn set_start<V: Into<T::FormattedValueType>>(&mut self, start: V) { pub fn set_start<V: Into<T::FullRange>>(&mut self, start: V) {
let start = start.into(); let start = start.into();
if T::FormattedValueType::default_format() == Format::Undefined { if T::default_format() == Format::Undefined {
assert_eq!(self.format(), start.format()); assert_eq!(self.format(), start.format());
} }
@ -495,14 +468,14 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
} }
#[doc(alias = "get_stop")] #[doc(alias = "get_stop")]
pub fn stop(&self) -> T::FormattedValueType { pub fn stop(&self) -> T::FullRange {
unsafe { T::FormattedValueType::from_raw(self.format(), self.0.stop as i64) } unsafe { T::FullRange::from_raw(self.format(), self.0.stop as i64) }
} }
pub fn set_stop<V: Into<T::FormattedValueType>>(&mut self, stop: V) { pub fn set_stop<V: Into<T::FullRange>>(&mut self, stop: V) {
let stop = stop.into(); let stop = stop.into();
if T::FormattedValueType::default_format() == Format::Undefined { if T::default_format() == Format::Undefined {
assert_eq!(self.format(), stop.format()); assert_eq!(self.format(), stop.format());
} }
@ -510,14 +483,14 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
} }
#[doc(alias = "get_time")] #[doc(alias = "get_time")]
pub fn time(&self) -> T::FormattedValueType { pub fn time(&self) -> T::FullRange {
unsafe { T::FormattedValueType::from_raw(self.format(), self.0.time as i64) } unsafe { T::FullRange::from_raw(self.format(), self.0.time as i64) }
} }
pub fn set_time<V: Into<T::FormattedValueType>>(&mut self, time: V) { pub fn set_time<V: Into<T::FullRange>>(&mut self, time: V) {
let time = time.into(); let time = time.into();
if T::FormattedValueType::default_format() == Format::Undefined { if T::default_format() == Format::Undefined {
assert_eq!(self.format(), time.format()); assert_eq!(self.format(), time.format());
} }
@ -525,14 +498,14 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
} }
#[doc(alias = "get_position")] #[doc(alias = "get_position")]
pub fn position(&self) -> T::FormattedValueType { pub fn position(&self) -> T::FullRange {
unsafe { T::FormattedValueType::from_raw(self.format(), self.0.position as i64) } unsafe { T::FullRange::from_raw(self.format(), self.0.position as i64) }
} }
pub fn set_position<V: Into<T::FormattedValueType>>(&mut self, position: V) { pub fn set_position<V: Into<T::FullRange>>(&mut self, position: V) {
let position = position.into(); let position = position.into();
if T::FormattedValueType::default_format() == Format::Undefined { if T::default_format() == Format::Undefined {
assert_eq!(self.format(), position.format()); assert_eq!(self.format(), position.format());
} }
@ -540,14 +513,14 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
} }
#[doc(alias = "get_duration")] #[doc(alias = "get_duration")]
pub fn duration(&self) -> T::FormattedValueType { pub fn duration(&self) -> T::FullRange {
unsafe { T::FormattedValueType::from_raw(self.format(), self.0.duration as i64) } unsafe { T::FullRange::from_raw(self.format(), self.0.duration as i64) }
} }
pub fn set_duration<V: Into<T::FormattedValueType>>(&mut self, duration: V) { pub fn set_duration<V: Into<T::FullRange>>(&mut self, duration: V) {
let duration = duration.into(); let duration = duration.into();
if T::FormattedValueType::default_format() == Format::Undefined { if T::default_format() == Format::Undefined {
assert_eq!(self.format(), duration.format()); assert_eq!(self.format(), duration.format());
} }

View file

@ -100,7 +100,7 @@ impl<'de, T: SpecificFormattedValueIntrinsic> Deserialize<'de> for FormattedSegm
de::Error::custom(format!( de::Error::custom(format!(
"failed to convert segment with format {:?} to {:?}", "failed to convert segment with format {:?} to {:?}",
segment.format(), segment.format(),
T::FormattedValueType::default_format(), T::default_format(),
)) ))
}) })
}) })