From 86673009df49456b5424f27b030f126235ca3822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 15 Dec 2018 14:36:51 +0200 Subject: [PATCH] video: Add support for VideoTimeCodeMeta --- gstreamer-video/src/lib.rs | 2 +- gstreamer-video/src/video_time_code.rs | 50 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/gstreamer-video/src/lib.rs b/gstreamer-video/src/lib.rs index 01fed64c4..50dac87aa 100644 --- a/gstreamer-video/src/lib.rs +++ b/gstreamer-video/src/lib.rs @@ -65,7 +65,7 @@ pub use video_meta::*; #[cfg(any(feature = "v1_10", feature = "dox"))] mod video_time_code; #[cfg(any(feature = "v1_10", feature = "dox"))] -pub use video_time_code::{ValidVideoTimeCode, VideoTimeCode}; +pub use video_time_code::{ValidVideoTimeCode, VideoTimeCode, VideoTimeCodeMeta}; #[cfg(any(feature = "v1_12", feature = "dox"))] mod video_time_code_interval; #[cfg(any(feature = "v1_12", feature = "dox"))] diff --git a/gstreamer-video/src/video_time_code.rs b/gstreamer-video/src/video_time_code.rs index f059e3973..5d01888d8 100644 --- a/gstreamer-video/src/video_time_code.rs +++ b/gstreamer-video/src/video_time_code.rs @@ -490,3 +490,53 @@ impl From for VideoTimeCode { VideoTimeCode(v.0) } } + +#[repr(C)] +pub struct VideoTimeCodeMeta(ffi::GstVideoTimeCodeMeta); + +impl VideoTimeCodeMeta { + pub fn add<'a>( + buffer: &'a mut gst::BufferRef, + tc: &ValidVideoTimeCode, + ) -> gst::MetaRefMut<'a, Self, gst::meta::Standalone> { + unsafe { + let meta = ffi::gst_buffer_add_video_time_code_meta( + buffer.as_mut_ptr(), + tc.to_glib_none().0 as *mut _, + ); + + Self::from_mut_ptr(buffer, meta) + } + } + + pub fn get_tc(&self) -> ValidVideoTimeCode { + unsafe { ValidVideoTimeCode::from_glib_none(&self.0.tc as *const _) } + } + + pub fn set_tc(&mut self, tc: ValidVideoTimeCode) { + #![cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] + unsafe { + ffi::gst_video_time_code_clear(&mut self.0.tc); + self.0.tc = tc.0; + if !self.0.tc.config.latest_daily_jam.is_null() { + glib_ffi::g_date_time_ref(self.0.tc.config.latest_daily_jam); + } + } + } +} + +unsafe impl MetaAPI for VideoTimeCodeMeta { + type GstType = ffi::GstVideoTimeCodeMeta; + + fn get_meta_api() -> glib::Type { + unsafe { from_glib(ffi::gst_video_time_code_meta_api_get_type()) } + } +} + +impl fmt::Debug for VideoTimeCodeMeta { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("VideoTimeCodeMeta") + .field("tc", &self.get_tc()) + .finish() + } +}