forked from mirrors/gstreamer-rs
gstreamer-video: Implement VideoTimeCodeInterval
via glib::wrapper!
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1180>
This commit is contained in:
parent
cbd3035a5b
commit
30838b6549
1 changed files with 33 additions and 168 deletions
|
@ -1,17 +1,19 @@
|
|||
// Take a look at the license at the top of the repository in the LICENSE file.
|
||||
|
||||
use glib::prelude::*;
|
||||
use glib::translate::*;
|
||||
use std::cmp;
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::str;
|
||||
|
||||
#[derive(Clone)]
|
||||
#[doc(alias = "GstVideoTimeCodeInterval")]
|
||||
pub struct VideoTimeCodeInterval(ffi::GstVideoTimeCodeInterval);
|
||||
glib::wrapper! {
|
||||
#[doc(alias = "GstVideoTimeCodeInterval")]
|
||||
pub struct VideoTimeCodeInterval(BoxedInline<ffi::GstVideoTimeCodeInterval>);
|
||||
|
||||
match fn {
|
||||
type_ => || ffi::gst_video_time_code_interval_get_type(),
|
||||
}
|
||||
}
|
||||
|
||||
impl VideoTimeCodeInterval {
|
||||
pub fn new(hours: u32, minutes: u32, seconds: u32, frames: u32) -> Self {
|
||||
|
@ -19,46 +21,48 @@ impl VideoTimeCodeInterval {
|
|||
unsafe {
|
||||
let mut v = mem::MaybeUninit::zeroed();
|
||||
ffi::gst_video_time_code_interval_init(v.as_mut_ptr(), hours, minutes, seconds, frames);
|
||||
Self(v.assume_init())
|
||||
Self {
|
||||
inner: v.assume_init(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(alias = "get_hours")]
|
||||
pub fn hours(&self) -> u32 {
|
||||
self.0.hours
|
||||
self.inner.hours
|
||||
}
|
||||
|
||||
pub fn set_hours(&mut self, hours: u32) {
|
||||
self.0.hours = hours
|
||||
self.inner.hours = hours
|
||||
}
|
||||
|
||||
#[doc(alias = "get_minutes")]
|
||||
pub fn minutes(&self) -> u32 {
|
||||
self.0.minutes
|
||||
self.inner.minutes
|
||||
}
|
||||
|
||||
pub fn set_minutes(&mut self, minutes: u32) {
|
||||
assert!(minutes < 60);
|
||||
self.0.minutes = minutes
|
||||
self.inner.minutes = minutes
|
||||
}
|
||||
|
||||
#[doc(alias = "get_seconds")]
|
||||
pub fn seconds(&self) -> u32 {
|
||||
self.0.seconds
|
||||
self.inner.seconds
|
||||
}
|
||||
|
||||
pub fn set_seconds(&mut self, seconds: u32) {
|
||||
assert!(seconds < 60);
|
||||
self.0.seconds = seconds
|
||||
self.inner.seconds = seconds
|
||||
}
|
||||
|
||||
#[doc(alias = "get_frames")]
|
||||
pub fn frames(&self) -> u32 {
|
||||
self.0.frames
|
||||
self.inner.frames
|
||||
}
|
||||
|
||||
pub fn set_frames(&mut self, frames: u32) {
|
||||
self.0.frames = frames
|
||||
self.inner.frames = frames
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,10 +71,10 @@ unsafe impl Sync for VideoTimeCodeInterval {}
|
|||
|
||||
impl PartialEq for VideoTimeCodeInterval {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0.hours == other.0.hours
|
||||
&& self.0.minutes == other.0.minutes
|
||||
&& self.0.seconds == other.0.seconds
|
||||
&& self.0.frames == other.0.frames
|
||||
self.inner.hours == other.inner.hours
|
||||
&& self.inner.minutes == other.inner.minutes
|
||||
&& self.inner.seconds == other.inner.seconds
|
||||
&& self.inner.frames == other.inner.frames
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,22 +90,22 @@ impl PartialOrd for VideoTimeCodeInterval {
|
|||
impl Ord for VideoTimeCodeInterval {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &Self) -> cmp::Ordering {
|
||||
self.0
|
||||
self.inner
|
||||
.hours
|
||||
.cmp(&other.0.hours)
|
||||
.then_with(|| self.0.minutes.cmp(&other.0.minutes))
|
||||
.then_with(|| self.0.seconds.cmp(&other.0.seconds))
|
||||
.then_with(|| self.0.frames.cmp(&other.0.frames))
|
||||
.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))
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for VideoTimeCodeInterval {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("VideoTimeCodeInterval")
|
||||
.field("hours", &self.0.hours)
|
||||
.field("minutes", &self.0.minutes)
|
||||
.field("seconds", &self.0.seconds)
|
||||
.field("frames", &self.0.frames)
|
||||
.field("hours", &self.inner.hours)
|
||||
.field("minutes", &self.inner.minutes)
|
||||
.field("seconds", &self.inner.seconds)
|
||||
.field("frames", &self.inner.frames)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +115,7 @@ impl fmt::Display for VideoTimeCodeInterval {
|
|||
write!(
|
||||
f,
|
||||
"{:02}:{:02}:{:02}:{:02}",
|
||||
self.0.hours, self.0.minutes, self.0.seconds, self.0.frames
|
||||
self.inner.hours, self.inner.minutes, self.inner.seconds, self.inner.frames
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -130,142 +134,3 @@ impl str::FromStr for VideoTimeCodeInterval {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl GlibPtrDefault for VideoTimeCodeInterval {
|
||||
type GlibType = *mut ffi::GstVideoTimeCodeInterval;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
unsafe impl TransparentType for VideoTimeCodeInterval {
|
||||
type GlibType = ffi::GstVideoTimeCodeInterval;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl<'a> ToGlibPtr<'a, *const ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterval {
|
||||
type Storage = PhantomData<&'a Self>;
|
||||
|
||||
#[inline]
|
||||
fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstVideoTimeCodeInterval, Self> {
|
||||
Stash(&self.0 as *const _, PhantomData)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn to_glib_full(&self) -> *const ffi::GstVideoTimeCodeInterval {
|
||||
unsafe { ffi::gst_video_time_code_interval_copy(&self.0 as *const _) }
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl<'a> ToGlibPtrMut<'a, *mut ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterval {
|
||||
type Storage = PhantomData<&'a mut Self>;
|
||||
|
||||
#[inline]
|
||||
fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut ffi::GstVideoTimeCodeInterval, Self> {
|
||||
let ptr = &mut self.0 as *mut _;
|
||||
StashMut(ptr, PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl FromGlibPtrNone<*mut ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterval {
|
||||
#[inline]
|
||||
unsafe fn from_glib_none(ptr: *mut ffi::GstVideoTimeCodeInterval) -> Self {
|
||||
assert!(!ptr.is_null());
|
||||
Self(ptr::read(ptr))
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl FromGlibPtrNone<*const ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterval {
|
||||
#[inline]
|
||||
unsafe fn from_glib_none(ptr: *const ffi::GstVideoTimeCodeInterval) -> Self {
|
||||
assert!(!ptr.is_null());
|
||||
Self(ptr::read(ptr))
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl FromGlibPtrFull<*mut ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterval {
|
||||
#[inline]
|
||||
unsafe fn from_glib_full(ptr: *mut ffi::GstVideoTimeCodeInterval) -> Self {
|
||||
assert!(!ptr.is_null());
|
||||
let res = Self(ptr::read(ptr));
|
||||
ffi::gst_video_time_code_interval_free(ptr);
|
||||
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl FromGlibPtrBorrow<*mut ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterval {
|
||||
#[inline]
|
||||
unsafe fn from_glib_borrow(ptr: *mut ffi::GstVideoTimeCodeInterval) -> Borrowed<Self> {
|
||||
assert!(!ptr.is_null());
|
||||
Borrowed::new(Self(ptr::read(ptr)))
|
||||
}
|
||||
}
|
||||
|
||||
impl StaticType for VideoTimeCodeInterval {
|
||||
fn static_type() -> glib::Type {
|
||||
unsafe { from_glib(ffi::gst_video_time_code_interval_get_type()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl glib::value::ValueType for VideoTimeCodeInterval {
|
||||
type Type = Self;
|
||||
}
|
||||
|
||||
impl glib::value::ValueTypeOptional for VideoTimeCodeInterval {}
|
||||
|
||||
#[doc(hidden)]
|
||||
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)
|
||||
as *mut ffi::GstVideoTimeCodeInterval)
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl glib::value::ToValue for VideoTimeCodeInterval {
|
||||
fn to_value(&self) -> glib::Value {
|
||||
let mut value = glib::Value::for_value_type::<Self>();
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl glib::value::ToValueOptional for VideoTimeCodeInterval {
|
||||
fn to_value_optional(s: Option<&Self>) -> glib::Value {
|
||||
skip_assert_initialized!();
|
||||
let mut value = glib::Value::for_value_type::<Self>();
|
||||
unsafe {
|
||||
glib::gobject_ffi::g_value_set_boxed(
|
||||
value.to_glib_none_mut().0,
|
||||
s.to_glib_none().0 as *mut _,
|
||||
)
|
||||
}
|
||||
value
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl From<VideoTimeCodeInterval> for glib::Value {
|
||||
fn from(v: VideoTimeCodeInterval) -> glib::Value {
|
||||
skip_assert_initialized!();
|
||||
glib::value::ToValue::to_value(&v)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue