1 | // Take a look at the license at the top of the repository in the LICENSE file. |
2 | |
3 | use std::{cmp, fmt, mem, str}; |
4 | |
5 | use glib::translate::*; |
6 | |
7 | glib::wrapper! { |
8 | #[doc (alias = "GstVideoTimeCodeInterval" )] |
9 | pub struct VideoTimeCodeInterval(BoxedInline<ffi::GstVideoTimeCodeInterval>); |
10 | |
11 | match fn { |
12 | type_ => || ffi::gst_video_time_code_interval_get_type(), |
13 | } |
14 | } |
15 | |
16 | impl VideoTimeCodeInterval { |
17 | pub fn new(hours: u32, minutes: u32, seconds: u32, frames: u32) -> Self { |
18 | assert_initialized_main_thread!(); |
19 | unsafe { |
20 | let mut v = mem::MaybeUninit::uninit(); |
21 | ffi::gst_video_time_code_interval_init(v.as_mut_ptr(), hours, minutes, seconds, frames); |
22 | Self { |
23 | inner: v.assume_init(), |
24 | } |
25 | } |
26 | } |
27 | |
28 | #[doc (alias = "get_hours" )] |
29 | pub fn hours(&self) -> u32 { |
30 | self.inner.hours |
31 | } |
32 | |
33 | pub fn set_hours(&mut self, hours: u32) { |
34 | self.inner.hours = hours |
35 | } |
36 | |
37 | #[doc (alias = "get_minutes" )] |
38 | pub fn minutes(&self) -> u32 { |
39 | self.inner.minutes |
40 | } |
41 | |
42 | pub fn set_minutes(&mut self, minutes: u32) { |
43 | assert!(minutes < 60); |
44 | self.inner.minutes = minutes |
45 | } |
46 | |
47 | #[doc (alias = "get_seconds" )] |
48 | pub fn seconds(&self) -> u32 { |
49 | self.inner.seconds |
50 | } |
51 | |
52 | pub fn set_seconds(&mut self, seconds: u32) { |
53 | assert!(seconds < 60); |
54 | self.inner.seconds = seconds |
55 | } |
56 | |
57 | #[doc (alias = "get_frames" )] |
58 | pub fn frames(&self) -> u32 { |
59 | self.inner.frames |
60 | } |
61 | |
62 | pub fn set_frames(&mut self, frames: u32) { |
63 | self.inner.frames = frames |
64 | } |
65 | } |
66 | |
67 | unsafe impl Send for VideoTimeCodeInterval {} |
68 | unsafe impl Sync for VideoTimeCodeInterval {} |
69 | |
70 | impl PartialEq for VideoTimeCodeInterval { |
71 | fn eq(&self, other: &Self) -> bool { |
72 | self.inner.hours == other.inner.hours |
73 | && self.inner.minutes == other.inner.minutes |
74 | && self.inner.seconds == other.inner.seconds |
75 | && self.inner.frames == other.inner.frames |
76 | } |
77 | } |
78 | |
79 | impl Eq for VideoTimeCodeInterval {} |
80 | |
81 | impl PartialOrd for VideoTimeCodeInterval { |
82 | #[inline ] |
83 | fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { |
84 | Some(self.cmp(other)) |
85 | } |
86 | } |
87 | |
88 | impl Ord for VideoTimeCodeInterval { |
89 | #[inline ] |
90 | fn cmp(&self, other: &Self) -> cmp::Ordering { |
91 | self.inner |
92 | .hours |
93 | .cmp(&other.inner.hours) |
94 | .then_with(|| self.inner.minutes.cmp(&other.inner.minutes)) |
95 | .then_with(|| self.inner.seconds.cmp(&other.inner.seconds)) |
96 | .then_with(|| self.inner.frames.cmp(&other.inner.frames)) |
97 | } |
98 | } |
99 | |
100 | impl fmt::Debug for VideoTimeCodeInterval { |
101 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
102 | f&mut DebugStruct<'_, '_>.debug_struct("VideoTimeCodeInterval" ) |
103 | .field("hours" , &self.inner.hours) |
104 | .field("minutes" , &self.inner.minutes) |
105 | .field("seconds" , &self.inner.seconds) |
106 | .field(name:"frames" , &self.inner.frames) |
107 | .finish() |
108 | } |
109 | } |
110 | |
111 | impl fmt::Display for VideoTimeCodeInterval { |
112 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
113 | write!( |
114 | f, |
115 | " {:02}: {:02}: {:02}: {:02}" , |
116 | self.inner.hours, self.inner.minutes, self.inner.seconds, self.inner.frames |
117 | ) |
118 | } |
119 | } |
120 | |
121 | impl str::FromStr for VideoTimeCodeInterval { |
122 | type Err = glib::error::BoolError; |
123 | |
124 | #[doc (alias = "gst_video_time_code_interval_new_from_string" )] |
125 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
126 | assert_initialized_main_thread!(); |
127 | unsafe { |
128 | Option::<Self>::from_glib_full(ffi::gst_video_time_code_interval_new_from_string( |
129 | s.to_glib_none().0, |
130 | )) |
131 | .ok_or_else(|| glib::bool_error!("Failed to create VideoTimeCodeInterval from string" )) |
132 | } |
133 | } |
134 | } |
135 | |