From 82b47b40228d56e922c374d4002c04a520fcafa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 26 May 2025 11:01:08 +0300 Subject: [PATCH] gl: Don't unnecessarily store buffer in `gst_gl::GLVideoFrame` Similar to the changes done to `gst_video::VideoFrame` a while ago. Part-of: --- gstreamer-gl/src/gl_video_frame.rs | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/gstreamer-gl/src/gl_video_frame.rs b/gstreamer-gl/src/gl_video_frame.rs index 4f9436695..9c26a9921 100644 --- a/gstreamer-gl/src/gl_video_frame.rs +++ b/gstreamer-gl/src/gl_video_frame.rs @@ -3,7 +3,7 @@ use std::{fmt::Debug, marker::PhantomData, mem, ptr}; use crate::{ffi, GLMemoryRef}; -use glib::translate::{from_glib, Borrowed, ToGlibPtr}; +use glib::translate::*; use gst_video::{video_frame::IsVideoFrame, VideoFrameExt}; pub enum Readable {} @@ -73,7 +73,6 @@ impl GLVideoFrameExt for O {} pub struct GLVideoFrame { frame: gst_video::ffi::GstVideoFrame, - buffer: gst::Buffer, phantom: PhantomData, } @@ -105,7 +104,7 @@ impl GLVideoFrame { 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); gst_video::ffi::gst_video_frame_unmap(&mut s.frame); buffer } @@ -113,21 +112,16 @@ impl GLVideoFrame { #[inline] pub unsafe fn from_glib_full(frame: gst_video::ffi::GstVideoFrame) -> Self { - let buffer = gst::Buffer::from_glib_none(frame.buffer); Self { frame, - buffer, phantom: PhantomData, } } #[inline] pub fn into_raw(self) -> gst_video::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 } #[inline] @@ -176,9 +170,7 @@ impl GLVideoFrame { frame.as_mut_ptr(), info.to_glib_none().0 as *mut _, buffer.to_glib_none().0, - gst_video::ffi::GST_VIDEO_FRAME_MAP_FLAG_NO_REF - | gst::ffi::GST_MAP_READ - | ffi::GST_MAP_GL as u32, + gst::ffi::GST_MAP_READ | ffi::GST_MAP_GL as u32, )); if !res { @@ -193,7 +185,6 @@ impl GLVideoFrame { frame.info.offset.fill(0); Ok(Self { frame, - buffer, phantom: PhantomData, }) } @@ -227,10 +218,7 @@ impl GLVideoFrame { frame.as_mut_ptr(), info.to_glib_none().0 as *mut _, buffer.to_glib_none().0, - gst_video::ffi::GST_VIDEO_FRAME_MAP_FLAG_NO_REF - | gst::ffi::GST_MAP_READ - | gst::ffi::GST_MAP_WRITE - | ffi::GST_MAP_GL as u32, + gst::ffi::GST_MAP_READ | gst::ffi::GST_MAP_WRITE | ffi::GST_MAP_GL as u32, )); if !res { @@ -245,7 +233,6 @@ impl GLVideoFrame { frame.info.offset.fill(0); Ok(Self { frame, - buffer, phantom: PhantomData, }) }