gl: add memory access functions to GLVideoFrame

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1312>
This commit is contained in:
Anders Hellerup Madsen 2023-09-27 18:32:43 +02:00
parent e8387bf4cf
commit 61d559521b

View file

@ -2,6 +2,7 @@
use std::{marker::PhantomData, mem, ptr};
use crate::GLMemoryRef;
use glib::translate::{from_glib, Borrowed, ToGlibPtr};
use gst_video::VideoFrameExt;
@ -43,11 +44,34 @@ impl<T> VideoFrameExt for GLVideoFrame<T> {
}
impl<T> GLVideoFrame<T> {
#[inline]
#[doc(alias = "get_texture_id")]
pub fn texture_id(&self, idx: u32) -> Option<u32> {
self.as_video_frame_gl_ref().texture_id(idx)
}
pub fn memory(&self, idx: u32) -> Option<&GLMemoryRef> {
if idx >= buffer_n_gl_memory(self.buffer())? {
return None;
}
unsafe {
let ptr = (*self.as_ptr()).map[idx as usize].memory as _;
Some(GLMemoryRef::from_ptr(ptr))
}
}
pub fn memory_mut(&self, idx: u32) -> Option<&mut GLMemoryRef> {
if idx >= buffer_n_gl_memory(self.buffer())? {
return None;
}
unsafe {
let ptr = (*self.as_ptr()).map[idx as usize].memory as _;
Some(GLMemoryRef::from_mut_ptr(ptr))
}
}
#[inline]
pub fn into_buffer(self) -> gst::Buffer {
unsafe {
@ -348,6 +372,17 @@ impl<'a> GLVideoFrameRef<&'a gst::BufferRef> {
Some(*ptr)
}
}
pub fn memory(&self, idx: u32) -> Option<&GLMemoryRef> {
if idx >= buffer_n_gl_memory(self.buffer())? {
return None;
}
unsafe {
let ptr = (*self.as_ptr()).map[idx as usize].memory as _;
Some(GLMemoryRef::from_ptr(ptr))
}
}
}
impl<'a> GLVideoFrameRef<&'a mut gst::BufferRef> {
@ -435,6 +470,17 @@ impl<'a> GLVideoFrameRef<&'a mut gst::BufferRef> {
pub fn as_mut_ptr(&mut self) -> *mut gst_video::ffi::GstVideoFrame {
&mut self.frame
}
pub fn memory_mut(&self, idx: u32) -> Option<&mut GLMemoryRef> {
if idx >= buffer_n_gl_memory(self.buffer())? {
return None;
}
unsafe {
let ptr = (*self.as_ptr()).map[idx as usize].memory as _;
Some(GLMemoryRef::from_mut_ptr(ptr))
}
}
}
impl<'a> std::ops::Deref for GLVideoFrameRef<&'a mut gst::BufferRef> {