gstreamer/buffer: Add BufferRef::peek_memory_mut() function

This gives a mutable reference to the given memory and fails if the
memory is not actually writable.
This commit is contained in:
Sebastian Dröge 2020-04-06 19:27:40 +03:00
parent 019afd54f9
commit 2b70db3a9e

View file

@ -540,6 +540,21 @@ impl BufferRef {
unsafe { MemoryRef::from_ptr(gst_sys::gst_buffer_peek_memory(self.as_mut_ptr(), idx)) }
}
pub fn peek_memory_mut(&mut self, idx: u32) -> Result<&mut MemoryRef, glib::BoolError> {
assert!(idx < self.n_memory());
unsafe {
let mem = gst_sys::gst_buffer_peek_memory(self.as_mut_ptr(), idx);
if gst_sys::gst_mini_object_is_writable(mem as *mut _) == glib_sys::GFALSE {
Err(glib_bool_error!("Memory not writable"))
} else {
Ok(MemoryRef::from_mut_ptr(gst_sys::gst_buffer_peek_memory(
self.as_mut_ptr(),
idx,
)))
}
}
}
pub fn prepend_memory(&mut self, mem: Memory) {
unsafe { gst_sys::gst_buffer_prepend_memory(self.as_mut_ptr(), mem.into_ptr()) }
}