Add accessor for owned Buffer to read-mapped AudioBuffer / MappedBuffer

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1374>
This commit is contained in:
Sebastian Dröge 2024-01-05 22:28:03 +02:00
parent 92064a0c41
commit e35782a3a4
3 changed files with 18 additions and 1 deletions

View file

@ -2,7 +2,7 @@
use std::{fmt, marker::PhantomData, mem, ops, ptr, slice}; use std::{fmt, marker::PhantomData, mem, ops, ptr, slice};
use glib::translate::{from_glib, Borrowed, ToGlibPtr}; use glib::translate::*;
use smallvec::SmallVec; use smallvec::SmallVec;
@ -200,6 +200,11 @@ impl AudioBuffer<Readable> {
} }
} }
} }
#[inline]
pub fn buffer_owned(&self) -> gst::Buffer {
unsafe { from_glib_none(self.audio_buffer.buffer) }
}
} }
impl AudioBuffer<Writable> { impl AudioBuffer<Writable> {

View file

@ -1368,6 +1368,14 @@ impl<T> MappedBuffer<T> {
} }
} }
impl MappedBuffer<Readable> {
#[doc(alias = "get_buffer")]
#[inline]
pub fn buffer_owned(&self) -> Buffer {
self.buffer.clone()
}
}
impl MappedBuffer<Writable> { impl MappedBuffer<Writable> {
#[inline] #[inline]
pub fn as_mut_slice(&mut self) -> &mut [u8] { pub fn as_mut_slice(&mut self) -> &mut [u8] {

View file

@ -287,6 +287,10 @@ impl BufferCursor<Readable> {
phantom: PhantomData, phantom: PhantomData,
} }
} }
pub fn buffer_owned(&self) -> Buffer {
self.buffer.as_ref().unwrap().clone()
}
} }
impl BufferCursor<Writable> { impl BufferCursor<Writable> {