From 3234a18677e8cb6c4bb63666a7713cf13fdf6913 Mon Sep 17 00:00:00 2001 From: Christian Meissl Date: Sat, 26 Feb 2022 16:36:05 +0100 Subject: [PATCH] Use new memory type infrastructure in gstreamer-gl --- gstreamer-gl/src/gl_base_memory.rs | 22 ++++++++++----------- gstreamer-gl/src/gl_memory.rs | 29 ++++++++++++++++++---------- gstreamer-gl/src/gl_memory_pbo.rs | 31 ++++++++++++++++++++++++++++++ gstreamer-gl/src/lib.rs | 2 ++ 4 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 gstreamer-gl/src/gl_memory_pbo.rs diff --git a/gstreamer-gl/src/gl_base_memory.rs b/gstreamer-gl/src/gl_base_memory.rs index 716017913..d221bd324 100644 --- a/gstreamer-gl/src/gl_base_memory.rs +++ b/gstreamer-gl/src/gl_base_memory.rs @@ -1,32 +1,32 @@ use glib::prelude::*; use glib::translate::*; +use gst::Memory; use crate::GLAllocationParams; use crate::GLBaseMemoryAllocator; use ffi::GstGLBaseMemory; -use gst::ffi::GstMemory; use gst::MemoryRef; use gst::{result_from_gboolean, LoggableError, CAT_RUST}; -gst::mini_object_wrapper!( +gst::memory_object_wrapper!( GLBaseMemory, GLBaseMemoryRef, GstGLBaseMemory, - ffi::gst_gl_base_memory_get_type + |mem: &MemoryRef| { unsafe { from_glib(ffi::gst_is_gl_base_memory(mem.as_mut_ptr())) } }, + Memory, + MemoryRef ); -impl std::ops::Deref for GLBaseMemoryRef { - type Target = MemoryRef; - - fn deref(&self) -> &Self::Target { - unsafe { &*(&self.0.mem as *const GstMemory).cast::() } +impl std::fmt::Debug for GLBaseMemory { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + GLBaseMemoryRef::fmt(self, f) } } -impl std::ops::DerefMut for GLBaseMemoryRef { - fn deref_mut(&mut self) -> &mut Self::Target { - unsafe { &mut *(&mut self.0.mem as *mut GstMemory).cast::() } +impl std::fmt::Debug for GLBaseMemoryRef { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + gst::MemoryRef::fmt(self, f) } } diff --git a/gstreamer-gl/src/gl_memory.rs b/gstreamer-gl/src/gl_memory.rs index 3fb211e64..b7fa022ee 100644 --- a/gstreamer-gl/src/gl_memory.rs +++ b/gstreamer-gl/src/gl_memory.rs @@ -1,25 +1,34 @@ use glib::translate::*; +use crate::GLBaseMemory; use crate::GLBaseMemoryRef; use crate::GLFormat; use crate::GLTextureTarget; -use ffi::{GstGLBaseMemory, GstGLMemory}; +use ffi::GstGLMemory; use gst::{result_from_gboolean, LoggableError, CAT_RUST}; +use gst::{Memory, MemoryRef}; -gst::mini_object_wrapper!(GLMemory, GLMemoryRef, GstGLMemory); +gst::memory_object_wrapper!( + GLMemory, + GLMemoryRef, + GstGLMemory, + |mem: &MemoryRef| { unsafe { from_glib(ffi::gst_is_gl_memory(mem.as_mut_ptr())) } }, + GLBaseMemory, + GLBaseMemoryRef, + Memory, + MemoryRef +); -impl std::ops::Deref for GLMemoryRef { - type Target = GLBaseMemoryRef; - - fn deref(&self) -> &Self::Target { - unsafe { &*(&self.0.mem as *const GstGLBaseMemory).cast::() } +impl std::fmt::Debug for GLMemory { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + GLMemoryRef::fmt(self, f) } } -impl std::ops::DerefMut for GLMemoryRef { - fn deref_mut(&mut self) -> &mut Self::Target { - unsafe { &mut *(&mut self.0.mem as *mut GstGLBaseMemory).cast::() } +impl std::fmt::Debug for GLMemoryRef { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + GLBaseMemoryRef::fmt(self, f) } } diff --git a/gstreamer-gl/src/gl_memory_pbo.rs b/gstreamer-gl/src/gl_memory_pbo.rs new file mode 100644 index 000000000..c6b75c9f4 --- /dev/null +++ b/gstreamer-gl/src/gl_memory_pbo.rs @@ -0,0 +1,31 @@ +use ffi::GstGLMemoryPBO; + +use glib::translate::*; + +use crate::{GLBaseMemory, GLBaseMemoryRef, GLMemory, GLMemoryRef}; +use gst::{Memory, MemoryRef}; + +gst::memory_object_wrapper!( + GLMemoryPBO, + GLMemoryPBORef, + GstGLMemoryPBO, + |mem: &MemoryRef| { unsafe { from_glib(ffi::gst_is_gl_memory_pbo(mem.as_mut_ptr())) } }, + GLMemory, + GLMemoryRef, + GLBaseMemory, + GLBaseMemoryRef, + Memory, + MemoryRef +); + +impl std::fmt::Debug for GLMemoryPBO { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + GLMemoryPBORef::fmt(self, f) + } +} + +impl std::fmt::Debug for GLMemoryPBORef { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + GLMemoryRef::fmt(self, f) + } +} diff --git a/gstreamer-gl/src/lib.rs b/gstreamer-gl/src/lib.rs index 3d50bb10a..4023867cd 100644 --- a/gstreamer-gl/src/lib.rs +++ b/gstreamer-gl/src/lib.rs @@ -45,6 +45,8 @@ mod gl_base_memory; pub use self::gl_base_memory::*; mod gl_memory; pub use crate::gl_memory::*; +mod gl_memory_pbo; +pub use crate::gl_memory_pbo::*; // Re-export all the traits in a prelude module, so that applications // can always "use gst_gl::prelude::*" without getting conflicts