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    // 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        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    // rustdoc-stripper-ignore-next
59    /// # Safety
60    /// `tex_id` is not validated to be a valid GL texture, which may lead to undefined behaviour.
61    #[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")]
111    //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>) {
112    //    unsafe { TODO: call ffi:gst_gl_memory_init() }
113    //}
114
115    //#[doc(alias = "gst_gl_memory_read_pixels")]
116    //pub fn read_pixels(&self, write_pointer: /*Unimplemented*/Option<Fundamental: Pointer>) -> bool {
117    //    unsafe { TODO: call ffi:gst_gl_memory_read_pixels() }
118    //}
119
120    //#[doc(alias = "gst_gl_memory_texsubimage")]
121    //pub fn texsubimage(&mut self, read_pointer: /*Unimplemented*/Option<Fundamental: Pointer>) {
122    //    unsafe { TODO: call ffi:gst_gl_memory_texsubimage() }
123    //}
124
125    #[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    //#[doc(alias = "gst_gl_memory_setup_buffer")]
134    //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 {
135    //    unsafe { TODO: call ffi:gst_gl_memory_setup_buffer() }
136    //}
137}