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
|
|
|
|
|
|
|
use glib::prelude::*;
|
|
|
|
use glib::translate::*;
|
|
|
|
use std::cmp;
|
|
|
|
use std::fmt;
|
|
|
|
use std::mem;
|
|
|
|
use std::ptr;
|
2019-10-04 06:11:30 +00:00
|
|
|
use std::str;
|
2018-12-15 12:50:11 +00:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
2021-06-01 13:15:59 +00:00
|
|
|
#[doc(alias = "GstVideoTimeCodeInterval")]
|
2020-11-22 09:53:17 +00:00
|
|
|
pub struct VideoTimeCodeInterval(ffi::GstVideoTimeCodeInterval);
|
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 {
|
2019-07-11 13:02:46 +00:00
|
|
|
let mut v = mem::MaybeUninit::zeroed();
|
2020-11-22 09:53:17 +00:00
|
|
|
ffi::gst_video_time_code_interval_init(v.as_mut_ptr(), hours, minutes, seconds, frames);
|
2021-04-29 20:49:40 +00:00
|
|
|
Self(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 {
|
2018-12-15 12:50:11 +00:00
|
|
|
self.0.hours
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_hours(&mut self, hours: u32) {
|
|
|
|
self.0.hours = hours
|
|
|
|
}
|
|
|
|
|
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 {
|
2018-12-15 12:50:11 +00:00
|
|
|
self.0.minutes
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_minutes(&mut self, minutes: u32) {
|
|
|
|
assert!(minutes < 60);
|
|
|
|
self.0.minutes = minutes
|
|
|
|
}
|
|
|
|
|
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 {
|
2018-12-15 12:50:11 +00:00
|
|
|
self.0.seconds
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_seconds(&mut self, seconds: u32) {
|
|
|
|
assert!(seconds < 60);
|
|
|
|
self.0.seconds = seconds
|
|
|
|
}
|
|
|
|
|
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 {
|
2018-12-15 12:50:11 +00:00
|
|
|
self.0.frames
|
|
|
|
}
|
|
|
|
|
2020-12-19 11:52:01 +00:00
|
|
|
pub fn set_frames(&mut self, frames: u32) {
|
|
|
|
self.0.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 {
|
|
|
|
self.0.hours == other.0.hours
|
2020-12-19 11:48:28 +00:00
|
|
|
&& self.0.minutes == other.0.minutes
|
2018-12-15 12:50:11 +00:00
|
|
|
&& self.0.seconds == other.0.seconds
|
|
|
|
&& self.0.frames == other.0.frames
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0
|
|
|
|
.hours
|
|
|
|
.cmp(&other.0.hours)
|
2020-12-19 11:53:04 +00:00
|
|
|
.then_with(|| self.0.minutes.cmp(&other.0.minutes))
|
2018-12-15 12:50:11 +00:00
|
|
|
.then_with(|| self.0.seconds.cmp(&other.0.seconds))
|
|
|
|
.then_with(|| self.0.frames.cmp(&other.0.frames))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
.field("hours", &self.0.hours)
|
|
|
|
.field("minutes", &self.0.minutes)
|
|
|
|
.field("seconds", &self.0.seconds)
|
|
|
|
.field("frames", &self.0.frames)
|
|
|
|
.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}",
|
|
|
|
self.0.hours, self.0.minutes, self.0.seconds, self.0.frames
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-15 12:50:11 +00:00
|
|
|
#[doc(hidden)]
|
|
|
|
impl GlibPtrDefault for VideoTimeCodeInterval {
|
2020-11-22 09:53:17 +00:00
|
|
|
type GlibType = *mut ffi::GstVideoTimeCodeInterval;
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2020-11-22 09:53:17 +00:00
|
|
|
impl<'a> ToGlibPtr<'a, *const ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterval {
|
2018-12-15 12:50:11 +00:00
|
|
|
type Storage = &'a Self;
|
|
|
|
|
|
|
|
#[inline]
|
2020-11-22 09:53:17 +00:00
|
|
|
fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstVideoTimeCodeInterval, Self> {
|
2018-12-15 12:50:11 +00:00
|
|
|
Stash(&self.0 as *const _, self)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2020-11-22 09:53:17 +00:00
|
|
|
fn to_glib_full(&self) -> *const ffi::GstVideoTimeCodeInterval {
|
|
|
|
unsafe { ffi::gst_video_time_code_interval_copy(&self.0 as *const _) }
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2020-11-22 09:53:17 +00:00
|
|
|
impl<'a> ToGlibPtrMut<'a, *mut ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterval {
|
2018-12-15 12:50:11 +00:00
|
|
|
type Storage = &'a mut Self;
|
|
|
|
|
|
|
|
#[inline]
|
2020-11-22 09:53:17 +00:00
|
|
|
fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut ffi::GstVideoTimeCodeInterval, Self> {
|
2018-12-15 12:50:11 +00:00
|
|
|
let ptr = &mut self.0 as *mut _;
|
|
|
|
StashMut(ptr, self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2020-11-22 09:53:17 +00:00
|
|
|
impl FromGlibPtrNone<*mut ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterval {
|
2018-12-15 12:50:11 +00:00
|
|
|
#[inline]
|
2020-11-22 09:53:17 +00:00
|
|
|
unsafe fn from_glib_none(ptr: *mut ffi::GstVideoTimeCodeInterval) -> Self {
|
2018-12-15 12:50:11 +00:00
|
|
|
assert!(!ptr.is_null());
|
2021-04-29 20:49:40 +00:00
|
|
|
Self(ptr::read(ptr))
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2020-11-22 09:53:17 +00:00
|
|
|
impl FromGlibPtrNone<*const ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterval {
|
2018-12-15 12:50:11 +00:00
|
|
|
#[inline]
|
2020-11-22 09:53:17 +00:00
|
|
|
unsafe fn from_glib_none(ptr: *const ffi::GstVideoTimeCodeInterval) -> Self {
|
2018-12-15 12:50:11 +00:00
|
|
|
assert!(!ptr.is_null());
|
2021-04-29 20:49:40 +00:00
|
|
|
Self(ptr::read(ptr))
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2020-11-22 09:53:17 +00:00
|
|
|
impl FromGlibPtrFull<*mut ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterval {
|
2018-12-15 12:50:11 +00:00
|
|
|
#[inline]
|
2020-11-22 09:53:17 +00:00
|
|
|
unsafe fn from_glib_full(ptr: *mut ffi::GstVideoTimeCodeInterval) -> Self {
|
2018-12-15 12:50:11 +00:00
|
|
|
assert!(!ptr.is_null());
|
2021-04-29 20:49:40 +00:00
|
|
|
let res = Self(ptr::read(ptr));
|
2020-11-22 09:53:17 +00:00
|
|
|
ffi::gst_video_time_code_interval_free(ptr);
|
2018-12-15 12:50:11 +00:00
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2020-11-22 09:53:17 +00:00
|
|
|
impl FromGlibPtrBorrow<*mut ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterval {
|
2018-12-15 12:50:11 +00:00
|
|
|
#[inline]
|
2020-11-22 09:53:17 +00:00
|
|
|
unsafe fn from_glib_borrow(ptr: *mut ffi::GstVideoTimeCodeInterval) -> Borrowed<Self> {
|
2018-12-15 12:50:11 +00:00
|
|
|
assert!(!ptr.is_null());
|
2021-04-29 20:49:40 +00:00
|
|
|
Borrowed::new(Self(ptr::read(ptr)))
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl StaticType for VideoTimeCodeInterval {
|
|
|
|
fn static_type() -> glib::Type {
|
2020-11-22 09:53:17 +00:00
|
|
|
unsafe { from_glib(ffi::gst_video_time_code_interval_get_type()) }
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ValueType for VideoTimeCodeInterval {
|
|
|
|
type Type = Self;
|
|
|
|
}
|
|
|
|
|
2021-12-16 17:39:43 +00:00
|
|
|
impl glib::value::ValueTypeOptional for VideoTimeCodeInterval {}
|
|
|
|
|
2018-12-15 12:50:11 +00:00
|
|
|
#[doc(hidden)]
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe impl<'a> glib::value::FromValue<'a> for VideoTimeCodeInterval {
|
|
|
|
type Checker = glib::value::GenericValueTypeOrNoneChecker<Self>;
|
|
|
|
|
|
|
|
unsafe fn from_value(value: &'a glib::Value) -> Self {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
from_glib_none(glib::gobject_ffi::g_value_get_boxed(value.to_glib_none().0)
|
2020-11-22 09:53:17 +00:00
|
|
|
as *mut ffi::GstVideoTimeCodeInterval)
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ToValue for VideoTimeCodeInterval {
|
|
|
|
fn to_value(&self) -> glib::Value {
|
2021-04-25 16:46:18 +00:00
|
|
|
let mut value = glib::Value::for_value_type::<Self>();
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe {
|
|
|
|
glib::gobject_ffi::g_value_set_boxed(
|
|
|
|
value.to_glib_none_mut().0,
|
|
|
|
self.to_glib_none().0 as *mut _,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
value
|
|
|
|
}
|
|
|
|
|
|
|
|
fn value_type(&self) -> glib::Type {
|
|
|
|
Self::static_type()
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ToValueOptional for VideoTimeCodeInterval {
|
|
|
|
fn to_value_optional(s: Option<&Self>) -> glib::Value {
|
|
|
|
skip_assert_initialized!();
|
2021-04-25 16:46:18 +00:00
|
|
|
let mut value = glib::Value::for_value_type::<Self>();
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe {
|
|
|
|
glib::gobject_ffi::g_value_set_boxed(
|
|
|
|
value.to_glib_none_mut().0,
|
|
|
|
s.to_glib_none().0 as *mut _,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
value
|
2018-12-15 12:50:11 +00:00
|
|
|
}
|
|
|
|
}
|