From ede4588e0c57de37b3d23faa81f31c86703ed57d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 1 Jun 2020 23:25:49 +0300 Subject: [PATCH] gstreamer: Add bindings for ProtectionMeta --- gstreamer/src/lib.rs | 2 +- gstreamer/src/meta.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index b3e039b9f..d28e77668 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -123,7 +123,7 @@ pub mod meta; pub use meta::MetaSeqnum; #[cfg(any(feature = "v1_14", feature = "dox"))] pub use meta::ReferenceTimestampMeta; -pub use meta::{Meta, MetaAPI, MetaRef, MetaRefMut, ParentBufferMeta}; +pub use meta::{Meta, MetaAPI, MetaRef, MetaRefMut, ParentBufferMeta, ProtectionMeta}; pub mod buffer; pub use buffer::{ Buffer, BufferMap, BufferRef, MappedBuffer, BUFFER_COPY_ALL, BUFFER_COPY_METADATA, diff --git a/gstreamer/src/meta.rs b/gstreamer/src/meta.rs index 374ccaedf..019090d92 100644 --- a/gstreamer/src/meta.rs +++ b/gstreamer/src/meta.rs @@ -300,6 +300,48 @@ impl fmt::Debug for ParentBufferMeta { } } +#[repr(C)] +pub struct ProtectionMeta(gst_sys::GstProtectionMeta); + +unsafe impl Send for ProtectionMeta {} +unsafe impl Sync for ProtectionMeta {} + +impl ProtectionMeta { + pub fn add(buffer: &mut BufferRef, info: ::Structure) -> MetaRefMut { + skip_assert_initialized!(); + unsafe { + let meta = + gst_sys::gst_buffer_add_protection_meta(buffer.as_mut_ptr(), info.into_ptr()); + + Self::from_mut_ptr(buffer, meta) + } + } + + pub fn get_info(&self) -> &::StructureRef { + unsafe { ::StructureRef::from_glib_borrow(self.0.info) } + } + + pub fn get_info_mut(&mut self) -> &mut ::StructureRef { + unsafe { ::StructureRef::from_glib_borrow_mut(self.0.info) } + } +} + +unsafe impl MetaAPI for ProtectionMeta { + type GstType = gst_sys::GstProtectionMeta; + + fn get_meta_api() -> glib::Type { + unsafe { from_glib(gst_sys::gst_protection_meta_api_get_type()) } + } +} + +impl fmt::Debug for ProtectionMeta { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("ProtectionMeta") + .field("info", &self.get_info()) + .finish() + } +} + #[cfg(any(feature = "v1_14", feature = "dox"))] #[repr(C)] pub struct ReferenceTimestampMeta(gst_sys::GstReferenceTimestampMeta);