gstreamer_gl/
gl_base_memory.rs
1use ffi::GstGLBaseMemory;
2use glib::{prelude::*, translate::*};
3use gst::{Memory, MemoryRef};
4
5use crate::{ffi, GLAllocationParams, GLBaseMemoryAllocator};
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 Self::init_once();
51 glib::result_from_gboolean!(
52 ffi::gst_gl_base_memory_memcpy(
53 mut_override(&self.0),
54 dest.to_glib_none_mut().0,
55 offset,
56 size,
57 ),
58 "Failed to copy memory"
59 )
60 }
61
62 #[doc(alias = "gst_gl_base_memory_alloc")]
63 pub fn alloc<P: IsA<GLBaseMemoryAllocator>>(
64 allocator: &P,
65 params: &GLAllocationParams,
66 ) -> Result<GLBaseMemory, glib::BoolError> {
67 skip_assert_initialized!();
68 Self::init_once();
69 unsafe {
70 Option::<_>::from_glib_full(ffi::gst_gl_base_memory_alloc(
71 allocator.as_ref().to_glib_none().0,
72 mut_override(params.to_glib_none().0),
73 ))
74 .ok_or_else(|| glib::bool_error!("Failed to allocate memory"))
75 }
76 }
77
78 #[doc(alias = "gst_gl_base_memory_init_once")]
79 fn init_once() {
80 assert_initialized_main_thread!();
81 unsafe {
82 ffi::gst_gl_base_memory_init_once();
83 }
84 }
85
86 pub fn context(&self) -> &crate::GLContext {
87 unsafe {
88 &*(&(*self.as_ptr()).context as *const *mut ffi::GstGLContext
89 as *const crate::GLContext)
90 }
91 }
92}