gstreamer/
timed_value.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::marker::PhantomData;
4
5use glib::translate::*;
6
7use crate::{ffi, ClockTime};
8
9#[derive(Debug, Clone, Copy)]
10#[doc(alias = "GstTimedValue")]
11#[repr(transparent)]
12pub struct TimedValue(ffi::GstTimedValue);
13
14unsafe impl Send for TimedValue {}
15unsafe impl Sync for TimedValue {}
16
17impl TimedValue {
18    #[doc(alias = "get_timestamp")]
19    pub fn timestamp(&self) -> ClockTime {
20        unsafe { try_from_glib(self.0.timestamp).expect("undefined timestamp") }
21    }
22
23    #[doc(alias = "get_value")]
24    #[inline]
25    pub fn value(&self) -> f64 {
26        self.0.value
27    }
28
29    #[inline]
30    pub fn as_ptr(&self) -> *const ffi::GstTimedValue {
31        &self.0
32    }
33}
34
35impl From<ffi::GstTimedValue> for TimedValue {
36    #[inline]
37    fn from(value: ffi::GstTimedValue) -> Self {
38        skip_assert_initialized!();
39        TimedValue(value)
40    }
41}
42
43#[doc(hidden)]
44impl<'a> ToGlibPtr<'a, *const ffi::GstTimedValue> for TimedValue {
45    type Storage = PhantomData<&'a Self>;
46
47    #[inline]
48    fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstTimedValue, Self> {
49        Stash(&self.0, PhantomData)
50    }
51}
52
53impl FromGlib<ffi::GstTimedValue> for TimedValue {
54    #[inline]
55    unsafe fn from_glib(value: ffi::GstTimedValue) -> Self {
56        skip_assert_initialized!();
57        Self::from(value)
58    }
59}
60
61impl PartialEq for TimedValue {
62    fn eq(&self, other: &Self) -> bool {
63        self.timestamp() == other.timestamp() && self.value() == other.value()
64    }
65}
66
67impl Eq for TimedValue {}
68
69unsafe impl glib::translate::TransparentType for TimedValue {
70    type GlibType = ffi::GstTimedValue;
71}