forked from mirrors/gstreamer-rs
gl: add memory access functions to GLVideoFrame
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1312>
This commit is contained in:
parent
e8387bf4cf
commit
61d559521b
1 changed files with 46 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use std::{marker::PhantomData, mem, ptr};
|
use std::{marker::PhantomData, mem, ptr};
|
||||||
|
|
||||||
|
use crate::GLMemoryRef;
|
||||||
use glib::translate::{from_glib, Borrowed, ToGlibPtr};
|
use glib::translate::{from_glib, Borrowed, ToGlibPtr};
|
||||||
use gst_video::VideoFrameExt;
|
use gst_video::VideoFrameExt;
|
||||||
|
|
||||||
|
@ -43,11 +44,34 @@ impl<T> VideoFrameExt for GLVideoFrame<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> GLVideoFrame<T> {
|
impl<T> GLVideoFrame<T> {
|
||||||
|
#[inline]
|
||||||
#[doc(alias = "get_texture_id")]
|
#[doc(alias = "get_texture_id")]
|
||||||
pub fn texture_id(&self, idx: u32) -> Option<u32> {
|
pub fn texture_id(&self, idx: u32) -> Option<u32> {
|
||||||
self.as_video_frame_gl_ref().texture_id(idx)
|
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]
|
#[inline]
|
||||||
pub fn into_buffer(self) -> gst::Buffer {
|
pub fn into_buffer(self) -> gst::Buffer {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -348,6 +372,17 @@ impl<'a> GLVideoFrameRef<&'a gst::BufferRef> {
|
||||||
Some(*ptr)
|
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> {
|
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 {
|
pub fn as_mut_ptr(&mut self) -> *mut gst_video::ffi::GstVideoFrame {
|
||||||
&mut self.frame
|
&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> {
|
impl<'a> std::ops::Deref for GLVideoFrameRef<&'a mut gst::BufferRef> {
|
||||||
|
|
Loading…
Reference in a new issue