gstreamer_gl/
gl_memory.rs
1use ffi::GstGLMemory;
2use glib::translate::*;
3use gst::{result_from_gboolean, LoggableError, Memory, MemoryRef, CAT_RUST};
4
5use crate::{ffi, GLBaseMemory, GLBaseMemoryRef, GLFormat, GLTextureTarget};
6
7gst::memory_object_wrapper!(
8 GLMemory,
9 GLMemoryRef,
10 GstGLMemory,
11 |mem: &MemoryRef| { unsafe { from_glib(ffi::gst_is_gl_memory(mem.as_mut_ptr())) } },
12 GLBaseMemory,
13 GLBaseMemoryRef,
14 Memory,
15 MemoryRef
16);
17
18impl std::fmt::Debug for GLMemory {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 GLMemoryRef::fmt(self, f)
21 }
22}
23
24impl std::fmt::Debug for GLMemoryRef {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 GLBaseMemoryRef::fmt(self, f)
27 }
28}
29
30impl GLMemoryRef {
31 #[doc(alias = "gst_gl_memory_copy_into")]
35 pub unsafe fn copy_into(
36 &self,
37 tex_id: u32,
38 target: GLTextureTarget,
39 tex_format: GLFormat,
40 width: i32,
41 height: i32,
42 ) -> Result<(), LoggableError> {
43 Self::init_once();
44 result_from_gboolean!(
45 ffi::gst_gl_memory_copy_into(
46 mut_override(&self.0),
47 tex_id,
48 target.into_glib(),
49 tex_format.into_glib(),
50 width,
51 height,
52 ),
53 CAT_RUST,
54 "Failed to copy memory into GL texture"
55 )
56 }
57
58 #[doc(alias = "gst_gl_memory_copy_teximage")]
62 pub unsafe fn copy_teximage(
63 &self,
64 tex_id: u32,
65 out_target: GLTextureTarget,
66 out_tex_format: GLFormat,
67 out_width: i32,
68 out_height: i32,
69 ) -> Result<(), LoggableError> {
70 Self::init_once();
71 result_from_gboolean!(
72 ffi::gst_gl_memory_copy_teximage(
73 mut_override(&self.0),
74 tex_id,
75 out_target.into_glib(),
76 out_tex_format.into_glib(),
77 out_width,
78 out_height,
79 ),
80 CAT_RUST,
81 "Failed to copy memory into GL texture"
82 )
83 }
84
85 #[doc(alias = "gst_gl_memory_get_texture_format")]
86 pub fn texture_format(&self) -> GLFormat {
87 unsafe { from_glib(ffi::gst_gl_memory_get_texture_format(mut_override(&self.0))) }
88 }
89
90 #[doc(alias = "gst_gl_memory_get_texture_height")]
91 pub fn texture_height(&self) -> i32 {
92 unsafe { ffi::gst_gl_memory_get_texture_height(mut_override(&self.0)) }
93 }
94
95 #[doc(alias = "gst_gl_memory_get_texture_id")]
96 pub fn texture_id(&self) -> u32 {
97 unsafe { ffi::gst_gl_memory_get_texture_id(mut_override(&self.0)) }
98 }
99
100 #[doc(alias = "gst_gl_memory_get_texture_target")]
101 pub fn texture_target(&self) -> GLTextureTarget {
102 unsafe { from_glib(ffi::gst_gl_memory_get_texture_target(mut_override(&self.0))) }
103 }
104
105 #[doc(alias = "gst_gl_memory_get_texture_width")]
106 pub fn texture_width(&self) -> i32 {
107 unsafe { ffi::gst_gl_memory_get_texture_width(mut_override(&self.0)) }
108 }
109
110 #[doc(alias = "gst_gl_memory_init_once")]
126 fn init_once() {
127 assert_initialized_main_thread!();
128 unsafe {
129 ffi::gst_gl_memory_init_once();
130 }
131 }
132
133 }