gstreamer_gl/
gl_base_memory.rs1use ffi::GstGLBaseMemory;
2use glib::{prelude::*, translate::*};
3use gst::{Memory, MemoryRef};
4
5use crate::{GLAllocationParams, GLBaseMemoryAllocator, ffi};
6
7gst::memory_object_wrapper!(
8 GLBaseMemory,
9 GLBaseMemoryRef,
10 GstGLBaseMemory,
11 |mem: &MemoryRef| { unsafe { from_glib(ffi::gst_is_gl_base_memory(mem.as_mut_ptr())) } },
12 Memory,
13 MemoryRef
14);
15
16impl std::fmt::Debug for GLBaseMemory {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 GLBaseMemoryRef::fmt(self, f)
19 }
20}
21
22impl std::fmt::Debug for GLBaseMemoryRef {
23 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24 gst::MemoryRef::fmt(self, f)
25 }
26}
27
28impl GLBaseMemoryRef {
29 #[doc(alias = "gst_gl_base_memory_memcpy")]
44 pub unsafe fn memcpy(
45 &self,
46 dest: &mut GLBaseMemory,
47 offset: isize,
48 size: isize,
49 ) -> Result<(), glib::BoolError> {
50 unsafe {
51 Self::init_once();
52 glib::result_from_gboolean!(
53 ffi::gst_gl_base_memory_memcpy(
54 mut_override(&self.0),
55 dest.to_glib_none_mut().0,
56 offset,
57 size,
58 ),
59 "Failed to copy memory"
60 )
61 }
62 }
63
64 #[doc(alias = "gst_gl_base_memory_alloc")]
65 pub fn alloc<P: IsA<GLBaseMemoryAllocator>>(
66 allocator: &P,
67 params: &GLAllocationParams,
68 ) -> Result<GLBaseMemory, glib::BoolError> {
69 skip_assert_initialized!();
70 Self::init_once();
71 unsafe {
72 Option::<_>::from_glib_full(ffi::gst_gl_base_memory_alloc(
73 allocator.as_ref().to_glib_none().0,
74 mut_override(params.to_glib_none().0),
75 ))
76 .ok_or_else(|| glib::bool_error!("Failed to allocate memory"))
77 }
78 }
79
80 #[doc(alias = "gst_gl_base_memory_init_once")]
81 fn init_once() {
82 assert_initialized_main_thread!();
83 unsafe {
84 ffi::gst_gl_base_memory_init_once();
85 }
86 }
87
88 pub fn context(&self) -> &crate::GLContext {
89 unsafe {
90 &*(&(*self.as_ptr()).context as *const *mut ffi::GstGLContext
91 as *const crate::GLContext)
92 }
93 }
94}