forked from mirrors/gstreamer-rs
Use ClockTime for the Duration tag
And implement the Value traits for ClockTime
This commit is contained in:
parent
f1c6c4fd06
commit
e6da3554ee
2 changed files with 35 additions and 8 deletions
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
use std::ops;
|
use std::ops;
|
||||||
use ffi;
|
use ffi;
|
||||||
|
use glib;
|
||||||
use glib::translate::*;
|
use glib::translate::*;
|
||||||
use std::{cmp, fmt};
|
use std::{cmp, fmt};
|
||||||
use muldiv::MulDiv;
|
use muldiv::MulDiv;
|
||||||
|
@ -280,6 +281,35 @@ impl FromGlib<ffi::GstClockTime> for ClockTime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
impl<'a> glib::value::FromValueOptional<'a> for ClockTime {
|
||||||
|
unsafe fn from_value_optional(value: &'a glib::Value) -> Option<Self> {
|
||||||
|
<u64 as glib::value::FromValueOptional>::from_value_optional(value)
|
||||||
|
.map(ClockTime::from_glib)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
impl<'a> glib::value::FromValue<'a> for ClockTime {
|
||||||
|
unsafe fn from_value(value: &'a glib::Value) -> Self {
|
||||||
|
ClockTime::from_glib(<u64 as glib::value::FromValue>::from_value(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
impl glib::value::SetValue for ClockTime {
|
||||||
|
unsafe fn set_value(value: &mut glib::Value, this: &Self) {
|
||||||
|
<u64 as glib::value::SetValue>::set_value(value, &this.to_glib());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
impl glib::StaticType for ClockTime {
|
||||||
|
fn static_type() -> glib::Type {
|
||||||
|
<u64 as glib::StaticType>::static_type()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl MulDiv<ClockTime> for ClockTime {
|
impl MulDiv<ClockTime> for ClockTime {
|
||||||
type Output = ClockTime;
|
type Output = ClockTime;
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ impl_tag!(Contact, &'a str, *TAG_CONTACT);
|
||||||
impl_tag!(License, &'a str, *TAG_LICENSE);
|
impl_tag!(License, &'a str, *TAG_LICENSE);
|
||||||
impl_tag!(LicenseUri, &'a str, *TAG_LICENSE_URI);
|
impl_tag!(LicenseUri, &'a str, *TAG_LICENSE_URI);
|
||||||
impl_tag!(Performer, &'a str, *TAG_PERFORMER);
|
impl_tag!(Performer, &'a str, *TAG_PERFORMER);
|
||||||
impl_tag!(Duration, u64, *TAG_DURATION);
|
impl_tag!(Duration, ::ClockTime, *TAG_DURATION);
|
||||||
impl_tag!(Codec, &'a str, *TAG_CODEC);
|
impl_tag!(Codec, &'a str, *TAG_CODEC);
|
||||||
impl_tag!(VideoCodec, &'a str, *TAG_VIDEO_CODEC);
|
impl_tag!(VideoCodec, &'a str, *TAG_VIDEO_CODEC);
|
||||||
impl_tag!(AudioCodec, &'a str, *TAG_AUDIO_CODEC);
|
impl_tag!(AudioCodec, &'a str, *TAG_AUDIO_CODEC);
|
||||||
|
@ -455,7 +455,7 @@ mod tests {
|
||||||
{
|
{
|
||||||
let tags = tags.get_mut().unwrap();
|
let tags = tags.get_mut().unwrap();
|
||||||
tags.add::<Title>(&"some title", TagMergeMode::Append);
|
tags.add::<Title>(&"some title", TagMergeMode::Append);
|
||||||
tags.add::<Duration>(&(1000u64 * 1000 * 1000 * 120).into(), TagMergeMode::Append);
|
tags.add::<Duration>(&(::SECOND * 120).into(), TagMergeMode::Append);
|
||||||
}
|
}
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
tags.to_string(),
|
tags.to_string(),
|
||||||
|
@ -472,21 +472,18 @@ mod tests {
|
||||||
{
|
{
|
||||||
let tags = tags.get_mut().unwrap();
|
let tags = tags.get_mut().unwrap();
|
||||||
tags.add::<Title>(&"some title", TagMergeMode::Append);
|
tags.add::<Title>(&"some title", TagMergeMode::Append);
|
||||||
tags.add::<Duration>(&(1000u64 * 1000 * 1000 * 120).into(), TagMergeMode::Append);
|
tags.add::<Duration>(&(::SECOND * 120).into(), TagMergeMode::Append);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(tags.get::<Title>().unwrap().get(), Some("some title"));
|
assert_eq!(tags.get::<Title>().unwrap().get(), Some("some title"));
|
||||||
assert_eq!(
|
assert_eq!(tags.get::<Duration>().unwrap().get_some(), (::SECOND * 120));
|
||||||
tags.get::<Duration>().unwrap().get_some(),
|
|
||||||
(1000u64 * 1000 * 1000 * 120)
|
|
||||||
);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
tags.get_index::<Title>(0).unwrap().get(),
|
tags.get_index::<Title>(0).unwrap().get(),
|
||||||
Some("some title")
|
Some("some title")
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
tags.get_index::<Duration>(0).unwrap().get_some(),
|
tags.get_index::<Duration>(0).unwrap().get_some(),
|
||||||
(1000u64 * 1000 * 1000 * 120)
|
(::SECOND * 120)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue