From 3de73d89f29826ee20273747ab9297c5c260dc1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 16 Dec 2017 15:15:42 +0200 Subject: [PATCH] Add Buffer::copy_into() and add flags parameter to ::copy_region() Also ::copy_deep() can fail, return an Option<_> --- Gir_Gst.toml | 1 + gstreamer/src/auto/flags.rs | 53 +++++++++++++++++++++++++++++++++++++ gstreamer/src/auto/mod.rs | 1 + gstreamer/src/buffer.rs | 33 ++++++++++++++++++++--- 4 files changed, 85 insertions(+), 3 deletions(-) diff --git a/Gir_Gst.toml b/Gir_Gst.toml index 44992835a..62c40290c 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -48,6 +48,7 @@ generate = [ "Gst.PadProbeReturn", "Gst.CapsIntersectMode", "Gst.BufferFlags", + "Gst.BufferCopyFlags", "Gst.SegmentFlags", "Gst.PadMode", "Gst.SchedulingFlags", diff --git a/gstreamer/src/auto/flags.rs b/gstreamer/src/auto/flags.rs index 0fbd9ccb8..fcfc72c0c 100644 --- a/gstreamer/src/auto/flags.rs +++ b/gstreamer/src/auto/flags.rs @@ -8,6 +8,59 @@ use glib::value::{Value, SetValue, FromValue, FromValueOptional}; use gobject_ffi; use glib::translate::*; +bitflags! { + pub struct BufferCopyFlags: u32 { + const NONE = 0; + const FLAGS = 1; + const TIMESTAMPS = 2; + const META = 4; + const MEMORY = 8; + const MERGE = 16; + const DEEP = 32; + } +} + +#[doc(hidden)] +impl ToGlib for BufferCopyFlags { + type GlibType = ffi::GstBufferCopyFlags; + + fn to_glib(&self) -> ffi::GstBufferCopyFlags { + ffi::GstBufferCopyFlags::from_bits_truncate(self.bits()) + } +} + +#[doc(hidden)] +impl FromGlib for BufferCopyFlags { + fn from_glib(value: ffi::GstBufferCopyFlags) -> BufferCopyFlags { + skip_assert_initialized!(); + BufferCopyFlags::from_bits_truncate(value.bits()) + } +} + +impl StaticType for BufferCopyFlags { + fn static_type() -> Type { + unsafe { from_glib(ffi::gst_buffer_copy_flags_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for BufferCopyFlags { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for BufferCopyFlags { + unsafe fn from_value(value: &Value) -> Self { + from_glib(ffi::GstBufferCopyFlags::from_bits_truncate(gobject_ffi::g_value_get_flags(value.to_glib_none().0))) + } +} + +impl SetValue for BufferCopyFlags { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib().bits()) + } +} + bitflags! { pub struct BufferFlags: u32 { const LIVE = 16; diff --git a/gstreamer/src/auto/mod.rs b/gstreamer/src/auto/mod.rs index 3062591b1..d71092e6f 100644 --- a/gstreamer/src/auto/mod.rs +++ b/gstreamer/src/auto/mod.rs @@ -143,6 +143,7 @@ pub use self::enums::URIError; pub use self::enums::URIType; mod flags; +pub use self::flags::BufferCopyFlags; pub use self::flags::BufferFlags; pub use self::flags::DebugColorFlags; pub use self::flags::DebugGraphDetails; diff --git a/gstreamer/src/buffer.rs b/gstreamer/src/buffer.rs index 1f1abc701..461e5ede4 100644 --- a/gstreamer/src/buffer.rs +++ b/gstreamer/src/buffer.rs @@ -199,18 +199,45 @@ impl BufferRef { } } - pub fn copy_region(&self, offset: usize, size: Option) -> Option { + pub fn copy_region( + &self, + flags: ::BufferCopyFlags, + offset: usize, + size: Option, + ) -> Option { let size_real = size.unwrap_or(usize::MAX); unsafe { from_glib_full(ffi::gst_buffer_copy_region( self.as_mut_ptr(), - ffi::GST_BUFFER_COPY_ALL, + flags.to_glib(), offset, size_real, )) } } + pub fn copy_into( + &self, + dest: &mut BufferRef, + flags: ::BufferCopyFlags, + offset: usize, + size: Option, + ) -> Result<(), glib::BoolError> { + let size_real = size.unwrap_or(usize::MAX); + unsafe { + glib::BoolError::from_glib( + ffi::gst_buffer_copy_into( + dest.as_mut_ptr(), + self.as_mut_ptr(), + flags.to_glib(), + offset, + size_real, + ), + "Failed to copy into destination buffer", + ) + } + } + pub fn copy_from_slice(&mut self, offset: usize, slice: &[u8]) -> Result<(), usize> { let maxsize = self.get_maxsize(); let size = slice.len(); @@ -252,7 +279,7 @@ impl BufferRef { } } - pub fn copy_deep(&self) -> Buffer { + pub fn copy_deep(&self) -> Option { unsafe { from_glib_full(ffi::gst_buffer_copy_deep(self.as_ptr())) } }