mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2025-09-03 10:23:48 +00:00
video-frame: Store buffer directly as part of the GstVideoFrame
There's no need to store it again separately, and this allows dropping the usage of GST_VIDEO_FRAME_MAP_FLAG_NO_REF too. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1725>
This commit is contained in:
parent
aad6fdfed3
commit
fd9cc77438
1 changed files with 23 additions and 21 deletions
|
@ -50,7 +50,6 @@ fn plane_buffer_info<T: IsVideoFrame>(
|
|||
|
||||
pub struct VideoFrame<T> {
|
||||
frame: ffi::GstVideoFrame,
|
||||
buffer: gst::Buffer,
|
||||
phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
|
@ -250,7 +249,7 @@ impl<T> VideoFrame<T> {
|
|||
pub fn into_buffer(self) -> gst::Buffer {
|
||||
unsafe {
|
||||
let mut s = mem::ManuallyDrop::new(self);
|
||||
let buffer = ptr::read(&s.buffer);
|
||||
let buffer = from_glib_none(s.frame.buffer);
|
||||
ffi::gst_video_frame_unmap(&mut s.frame);
|
||||
buffer
|
||||
}
|
||||
|
@ -331,10 +330,8 @@ impl<T> VideoFrame<T> {
|
|||
|
||||
#[inline]
|
||||
pub unsafe fn from_glib_full(frame: ffi::GstVideoFrame) -> Self {
|
||||
let buffer = gst::Buffer::from_glib_none(frame.buffer);
|
||||
Self {
|
||||
frame,
|
||||
buffer,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
@ -351,11 +348,8 @@ impl<T> VideoFrame<T> {
|
|||
|
||||
#[inline]
|
||||
pub fn into_raw(self) -> ffi::GstVideoFrame {
|
||||
unsafe {
|
||||
let mut s = mem::ManuallyDrop::new(self);
|
||||
ptr::drop_in_place(&mut s.buffer);
|
||||
s.frame
|
||||
}
|
||||
let s = mem::ManuallyDrop::new(self);
|
||||
s.frame
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -380,11 +374,15 @@ impl VideoFrame<Readable> {
|
|||
|
||||
unsafe {
|
||||
let mut frame = mem::MaybeUninit::uninit();
|
||||
// Takes another reference of the buffer but only
|
||||
// when successful, so we can safely return the buffer
|
||||
// on failure and on success drop the additional
|
||||
// reference.
|
||||
let res: bool = from_glib(ffi::gst_video_frame_map(
|
||||
frame.as_mut_ptr(),
|
||||
info.to_glib_none().0 as *mut _,
|
||||
buffer.to_glib_none().0,
|
||||
ffi::GST_VIDEO_FRAME_MAP_FLAG_NO_REF | gst::ffi::GST_MAP_READ,
|
||||
gst::ffi::GST_MAP_READ,
|
||||
));
|
||||
|
||||
if !res {
|
||||
|
@ -393,7 +391,6 @@ impl VideoFrame<Readable> {
|
|||
let frame = frame.assume_init();
|
||||
Ok(Self {
|
||||
frame,
|
||||
buffer,
|
||||
phantom: PhantomData,
|
||||
})
|
||||
}
|
||||
|
@ -412,12 +409,16 @@ impl VideoFrame<Readable> {
|
|||
|
||||
unsafe {
|
||||
let mut frame = mem::MaybeUninit::uninit();
|
||||
// Takes another reference of the buffer but only
|
||||
// when successful, so we can safely return the buffer
|
||||
// on failure and on success drop the additional
|
||||
// reference.
|
||||
let res: bool = from_glib(ffi::gst_video_frame_map_id(
|
||||
frame.as_mut_ptr(),
|
||||
info.to_glib_none().0 as *mut _,
|
||||
buffer.to_glib_none().0,
|
||||
id,
|
||||
ffi::GST_VIDEO_FRAME_MAP_FLAG_NO_REF | gst::ffi::GST_MAP_READ,
|
||||
gst::ffi::GST_MAP_READ,
|
||||
));
|
||||
|
||||
if !res {
|
||||
|
@ -426,7 +427,6 @@ impl VideoFrame<Readable> {
|
|||
let frame = frame.assume_init();
|
||||
Ok(Self {
|
||||
frame,
|
||||
buffer,
|
||||
phantom: PhantomData,
|
||||
})
|
||||
}
|
||||
|
@ -451,13 +451,15 @@ impl VideoFrame<Writable> {
|
|||
|
||||
unsafe {
|
||||
let mut frame = mem::MaybeUninit::uninit();
|
||||
// Takes another reference of the buffer but only
|
||||
// when successful, so we can safely return the buffer
|
||||
// on failure and on success drop the additional
|
||||
// reference.
|
||||
let res: bool = from_glib(ffi::gst_video_frame_map(
|
||||
frame.as_mut_ptr(),
|
||||
info.to_glib_none().0 as *mut _,
|
||||
buffer.to_glib_none().0,
|
||||
ffi::GST_VIDEO_FRAME_MAP_FLAG_NO_REF
|
||||
| gst::ffi::GST_MAP_READ
|
||||
| gst::ffi::GST_MAP_WRITE,
|
||||
gst::ffi::GST_MAP_READ | gst::ffi::GST_MAP_WRITE,
|
||||
));
|
||||
|
||||
if !res {
|
||||
|
@ -466,7 +468,6 @@ impl VideoFrame<Writable> {
|
|||
let frame = frame.assume_init();
|
||||
Ok(Self {
|
||||
frame,
|
||||
buffer,
|
||||
phantom: PhantomData,
|
||||
})
|
||||
}
|
||||
|
@ -485,14 +486,16 @@ impl VideoFrame<Writable> {
|
|||
|
||||
unsafe {
|
||||
let mut frame = mem::MaybeUninit::uninit();
|
||||
// Takes another reference of the buffer but only
|
||||
// when successful, so we can safely return the buffer
|
||||
// on failure and on success drop the additional
|
||||
// reference.
|
||||
let res: bool = from_glib(ffi::gst_video_frame_map_id(
|
||||
frame.as_mut_ptr(),
|
||||
info.to_glib_none().0 as *mut _,
|
||||
buffer.to_glib_none().0,
|
||||
id,
|
||||
ffi::GST_VIDEO_FRAME_MAP_FLAG_NO_REF
|
||||
| gst::ffi::GST_MAP_READ
|
||||
| gst::ffi::GST_MAP_WRITE,
|
||||
gst::ffi::GST_MAP_READ | gst::ffi::GST_MAP_WRITE,
|
||||
));
|
||||
|
||||
if !res {
|
||||
|
@ -501,7 +504,6 @@ impl VideoFrame<Writable> {
|
|||
let frame = frame.assume_init();
|
||||
Ok(Self {
|
||||
frame,
|
||||
buffer,
|
||||
phantom: PhantomData,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue