From 7c2f3bafa07cf47c655967108c8421e5ab043725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 28 Mar 2020 19:57:49 +0200 Subject: [PATCH] gstreamer/pad: Add get_range_fill() and pull_range_fill() functions These allow providing an already allocated, writable buffer. Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/242 --- gstreamer/src/pad.rs | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index 5ccda4f19..79c251bf5 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -128,7 +128,19 @@ pub trait PadExtManual: 'static { fn push_list(&self, list: BufferList) -> Result; fn pull_range(&self, offset: u64, size: u32) -> Result; + fn pull_range_fill( + &self, + offset: u64, + buffer: &mut ::BufferRef, + size: u32, + ) -> Result<(), FlowError>; fn get_range(&self, offset: u64, size: u32) -> Result; + fn get_range_fill( + &self, + offset: u64, + buffer: &mut ::BufferRef, + size: u32, + ) -> Result<(), FlowError>; fn peer_query(&self, query: &mut QueryRef) -> bool; fn query(&self, query: &mut QueryRef) -> bool; @@ -351,6 +363,36 @@ impl> PadExtManual for O { } } + fn get_range_fill( + &self, + offset: u64, + buffer: &mut ::BufferRef, + size: u32, + ) -> Result<(), FlowError> { + assert!(buffer.get_size() >= size as usize); + + unsafe { + let mut buffer_ref = buffer.as_mut_ptr(); + let ret: FlowReturn = from_glib(gst_sys::gst_pad_get_range( + self.as_ref().to_glib_none().0, + offset, + size, + &mut buffer_ref, + )); + match ret.into_result_value(|| ()) { + Ok(_) => { + if buffer.as_mut_ptr() != buffer_ref { + gst_sys::gst_mini_object_unref(buffer_ref as *mut _); + Err(::FlowError::Error) + } else { + Ok(()) + } + } + Err(err) => Err(err), + } + } + } + fn pull_range(&self, offset: u64, size: u32) -> Result { unsafe { let mut buffer = ptr::null_mut(); @@ -364,6 +406,36 @@ impl> PadExtManual for O { } } + fn pull_range_fill( + &self, + offset: u64, + buffer: &mut ::BufferRef, + size: u32, + ) -> Result<(), FlowError> { + assert!(buffer.get_size() >= size as usize); + + unsafe { + let mut buffer_ref = buffer.as_mut_ptr(); + let ret: FlowReturn = from_glib(gst_sys::gst_pad_pull_range( + self.as_ref().to_glib_none().0, + offset, + size, + &mut buffer_ref, + )); + match ret.into_result_value(|| ()) { + Ok(_) => { + if buffer.as_mut_ptr() != buffer_ref { + gst_sys::gst_mini_object_unref(buffer_ref as *mut _); + Err(::FlowError::Error) + } else { + Ok(()) + } + } + Err(err) => Err(err), + } + } + } + fn query(&self, query: &mut QueryRef) -> bool { unsafe { from_glib(gst_sys::gst_pad_query(