2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2018-12-15 12:50:11 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use std::{cmp, fmt, mem, str};
|
|
|
|
|
2018-12-15 12:50:11 +00:00
|
|
|
use glib::translate::*;
|
|
|
|
|
2023-01-03 09:15:22 +00:00
|
|
|
glib::wrapper! {
|
|
|
|
#[doc(alias = "GstVideoTimeCodeInterval")]
|
|
|
|
pub struct VideoTimeCodeInterval(BoxedInline<ffi::GstVideoTimeCodeInterval>);
|
|
|
|
|
|
|
|
match fn {
|
|
|
|
type_ => || ffi::gst_video_time_code_interval_get_type(),
|
|
|
|
}
|
|
|
|
}
|
2018-12-15 12:50:11 +00:00
|
|
|
|
|
|
|
impl VideoTimeCodeInterval {
|
2019-02-21 17:29:47 +00:00
|
|
|
pub fn new(hours: u32, minutes: u32, seconds: u32, frames: u32) -> Self {
|
2018-12-15 12:50:11 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
2023-01-06 12:11:45 +00:00
|
|
|
let mut v = mem::MaybeUninit::uninit();
|
2020-11-22 09:53:17 +00:00
|
|
|
ffi::gst_video_time_code_interval_init(v.as_mut_ptr(), hours, minutes, seconds, frames);
|
2023-01-03 09:15:22 +00:00
|
|
|
Self {
|
|
|
|
inner: v.assume_init(),
|
|
|
|
}
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_hours")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn hours(&self) -> u32 {
|
2023-01-03 09:15:22 +00:00
|
|
|
self.inner.hours
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_hours(&mut self, hours: u32) {
|
2023-01-03 09:15:22 +00:00
|
|
|
self.inner.hours = hours
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_minutes")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn minutes(&self) -> u32 {
|
2023-01-03 09:15:22 +00:00
|
|
|
self.inner.minutes
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_minutes(&mut self, minutes: u32) {
|
|
|
|
assert!(minutes < 60);
|
2023-01-03 09:15:22 +00:00
|
|
|
self.inner.minutes = minutes
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_seconds")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn seconds(&self) -> u32 {
|
2023-01-03 09:15:22 +00:00
|
|
|
self.inner.seconds
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_seconds(&mut self, seconds: u32) {
|
|
|
|
assert!(seconds < 60);
|
2023-01-03 09:15:22 +00:00
|
|
|
self.inner.seconds = seconds
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_frames")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn frames(&self) -> u32 {
|
2023-01-03 09:15:22 +00:00
|
|
|
self.inner.frames
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-19 11:52:01 +00:00
|
|
|
pub fn set_frames(&mut self, frames: u32) {
|
2023-01-03 09:15:22 +00:00
|
|
|
self.inner.frames = frames
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl Send for VideoTimeCodeInterval {}
|
|
|
|
unsafe impl Sync for VideoTimeCodeInterval {}
|
|
|
|
|
|
|
|
impl PartialEq for VideoTimeCodeInterval {
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
2023-01-03 09:15:22 +00:00
|
|
|
self.inner.hours == other.inner.hours
|
|
|
|
&& self.inner.minutes == other.inner.minutes
|
|
|
|
&& self.inner.seconds == other.inner.seconds
|
|
|
|
&& self.inner.frames == other.inner.frames
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Eq for VideoTimeCodeInterval {}
|
|
|
|
|
|
|
|
impl PartialOrd for VideoTimeCodeInterval {
|
|
|
|
#[inline]
|
|
|
|
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
|
|
|
|
Some(self.cmp(other))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Ord for VideoTimeCodeInterval {
|
|
|
|
#[inline]
|
|
|
|
fn cmp(&self, other: &Self) -> cmp::Ordering {
|
2023-01-03 09:15:22 +00:00
|
|
|
self.inner
|
2018-12-15 12:50:11 +00:00
|
|
|
.hours
|
2023-01-03 09:15:22 +00:00
|
|
|
.cmp(&other.inner.hours)
|
|
|
|
.then_with(|| self.inner.minutes.cmp(&other.inner.minutes))
|
|
|
|
.then_with(|| self.inner.seconds.cmp(&other.inner.seconds))
|
|
|
|
.then_with(|| self.inner.frames.cmp(&other.inner.frames))
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Debug for VideoTimeCodeInterval {
|
2020-11-28 11:33:46 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2018-12-15 12:50:11 +00:00
|
|
|
f.debug_struct("VideoTimeCodeInterval")
|
2023-01-03 09:15:22 +00:00
|
|
|
.field("hours", &self.inner.hours)
|
|
|
|
.field("minutes", &self.inner.minutes)
|
|
|
|
.field("seconds", &self.inner.seconds)
|
|
|
|
.field("frames", &self.inner.frames)
|
2018-12-15 12:50:11 +00:00
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for VideoTimeCodeInterval {
|
2020-11-28 11:33:46 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2018-12-15 12:50:11 +00:00
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"{:02}:{:02}:{:02}:{:02}",
|
2023-01-03 09:15:22 +00:00
|
|
|
self.inner.hours, self.inner.minutes, self.inner.seconds, self.inner.frames
|
2018-12-15 12:50:11 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 06:11:30 +00:00
|
|
|
impl str::FromStr for VideoTimeCodeInterval {
|
2019-12-17 08:41:51 +00:00
|
|
|
type Err = glib::error::BoolError;
|
2019-10-04 06:11:30 +00:00
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_video_time_code_interval_new_from_string")]
|
2020-11-28 11:34:36 +00:00
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
2019-10-04 06:11:30 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
2020-11-28 11:34:36 +00:00
|
|
|
Option::<Self>::from_glib_full(ffi::gst_video_time_code_interval_new_from_string(
|
|
|
|
s.to_glib_none().0,
|
|
|
|
))
|
2020-12-17 22:38:06 +00:00
|
|
|
.ok_or_else(|| glib::bool_error!("Failed to create VideoTimeCodeInterval from string"))
|
2019-10-04 06:11:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|