forked from mirrors/gstreamer-rs
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:
parent
019afd54f9
commit
2b70db3a9e
1 changed files with 15 additions and 0 deletions
|
@ -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()) }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue