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