gstreamer_gl/
gl_memory.rs1use ffi::GstGLMemory;
2use glib::translate::*;
3use gst::{CAT_RUST, LoggableError, Memory, MemoryRef, result_from_gboolean};
4
5use crate::{GLBaseMemory, GLBaseMemoryRef, GLFormat, GLTextureTarget, ffi};
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 unsafe {
44 Self::init_once();
45 result_from_gboolean!(
46 ffi::gst_gl_memory_copy_into(
47 mut_override(&self.0),
48 tex_id,
49 target.into_glib(),
50 tex_format.into_glib(),
51 width,
52 height,
53 ),
54 CAT_RUST,
55 "Failed to copy memory into GL texture"
56 )
57 }
58 }
59
60 #[doc(alias = "gst_gl_memory_copy_teximage")]
64 pub unsafe fn copy_teximage(
65 &self,
66 tex_id: u32,
67 out_target: GLTextureTarget,
68 out_tex_format: GLFormat,
69 out_width: i32,
70 out_height: i32,
71 ) -> Result<(), LoggableError> {
72 unsafe {
73 Self::init_once();
74 result_from_gboolean!(
75 ffi::gst_gl_memory_copy_teximage(
76 mut_override(&self.0),
77 tex_id,
78 out_target.into_glib(),
79 out_tex_format.into_glib(),
80 out_width,
81 out_height,
82 ),
83 CAT_RUST,
84 "Failed to copy memory into GL texture"
85 )
86 }
87 }
88
89 #[doc(alias = "gst_gl_memory_get_texture_format")]
90 pub fn texture_format(&self) -> GLFormat {
91 unsafe { from_glib(ffi::gst_gl_memory_get_texture_format(mut_override(&self.0))) }
92 }
93
94 #[doc(alias = "gst_gl_memory_get_texture_height")]
95 pub fn texture_height(&self) -> i32 {
96 unsafe { ffi::gst_gl_memory_get_texture_height(mut_override(&self.0)) }
97 }
98
99 #[doc(alias = "gst_gl_memory_get_texture_id")]
100 pub fn texture_id(&self) -> u32 {
101 unsafe { ffi::gst_gl_memory_get_texture_id(mut_override(&self.0)) }
102 }
103
104 #[doc(alias = "gst_gl_memory_get_texture_target")]
105 pub fn texture_target(&self) -> GLTextureTarget {
106 unsafe { from_glib(ffi::gst_gl_memory_get_texture_target(mut_override(&self.0))) }
107 }
108
109 #[doc(alias = "gst_gl_memory_get_texture_width")]
110 pub fn texture_width(&self) -> i32 {
111 unsafe { ffi::gst_gl_memory_get_texture_width(mut_override(&self.0)) }
112 }
113
114 #[doc(alias = "gst_gl_memory_init_once")]
130 fn init_once() {
131 assert_initialized_main_thread!();
132 unsafe {
133 ffi::gst_gl_memory_init_once();
134 }
135 }
136
137 }