Skip to main content

gstreamer_gl/
gl_memory.rs

1use 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    // rustdoc-stripper-ignore-next
32    /// # Safety
33    /// `tex_id` is not validated to be a valid GL texture, which may lead to undefined behaviour.
34    #[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    // rustdoc-stripper-ignore-next
61    /// # Safety
62    /// `tex_id` is not validated to be a valid GL texture, which may lead to undefined behaviour.
63    #[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")]
115    //pub fn init<P: IsA<gst::Allocator>, Q: IsA<GLContext>>(&self, allocator: &P, parent: Option<&mut gst::Memory>, context: &Q, target: GLTextureTarget, tex_format: GLFormat, params: Option<&mut gst::AllocationParams>, info: &mut gst_video::VideoInfo, plane: u32, valign: Option<&mut gst_video::VideoAlignment>, user_data: /*Unimplemented*/Option<Fundamental: Pointer>) {
116    //    unsafe { TODO: call ffi:gst_gl_memory_init() }
117    //}
118
119    //#[doc(alias = "gst_gl_memory_read_pixels")]
120    //pub fn read_pixels(&self, write_pointer: /*Unimplemented*/Option<Fundamental: Pointer>) -> bool {
121    //    unsafe { TODO: call ffi:gst_gl_memory_read_pixels() }
122    //}
123
124    //#[doc(alias = "gst_gl_memory_texsubimage")]
125    //pub fn texsubimage(&mut self, read_pointer: /*Unimplemented*/Option<Fundamental: Pointer>) {
126    //    unsafe { TODO: call ffi:gst_gl_memory_texsubimage() }
127    //}
128
129    #[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    //#[doc(alias = "gst_gl_memory_setup_buffer")]
138    //pub fn setup_buffer<P: IsA<GLMemoryAllocator>>(allocator: &P, buffer: &gst::Buffer, params: &mut GLVideoAllocationParams, tex_formats: /*Unimplemented*/Option<&CArray TypeId { ns_id: 1, id: 55 }>, wrapped_data: /*Unimplemented*/&[&Fundamental: Pointer]) -> bool {
139    //    unsafe { TODO: call ffi:gst_gl_memory_setup_buffer() }
140    //}
141}