Skip to content

Instantly share code, notes, and snippets.

@nrbnlulu
Created February 16, 2025 10:25
Show Gist options
  • Save nrbnlulu/7cd7e6b0f9800323cd554268cf665398 to your computer and use it in GitHub Desktop.
Save nrbnlulu/7cd7e6b0f9800323cd554268cf665398 to your computer and use it in GitHub Desktop.
impls for gst_egl_sys
pub mod gst_egl_ext {
use glib::{ffi::gpointer, translate::*};
use gst_gl_sys::{GstGLContext, GstGLMemory};
macro_rules! skip_assert_initialized {
() => {};
}
mod ffi {
use glib::ffi::gpointer;
use gst::ffi::GstMiniObject;
use gst_gl_sys::{GstGLContext, GstGLFormat, GstGLMemory};
pub type GstEGLImageDestroyNotify =
Option<unsafe extern "C" fn(image: *mut GstEGLImage, data: gpointer)>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct GstEGLImage {
pub parent: GstMiniObject,
pub context: *mut GstGLContext,
pub image: gpointer,
pub format: GstGLFormat,
pub destroy_data: gpointer,
pub destroy_notify: GstEGLImageDestroyNotify,
pub _padding: [gpointer; 4],
}
extern "C" {
pub fn gst_egl_image_from_texture(
// A pointer to a `GstGLContext` (must be an EGL context).
context: *mut GstGLContext,
// A pointer to a `GstGLMemory`.
gl_mem: *mut GstGLMemory,
// Additional attributes to add to the `eglCreateImage()` call.
attribs: *mut usize,
) -> *mut GstEGLImage;
pub fn gst_egl_image_get_type() -> glib::ffi::GType;
pub fn gst_egl_image_get_image(image: *const GstEGLImage) -> gpointer;
}
}
gst::mini_object_wrapper!(EGLImage, EGLImageRef, ffi::GstEGLImage, || {
ffi::gst_egl_image_get_type()
});
impl EGLImage {
pub fn get_image(&self) -> gpointer {
unsafe { ffi::gst_egl_image_get_image(self.as_mut_ptr()) }
}
pub fn from_texture(
context: *mut GstGLContext,
gl_mem: *mut GstGLMemory,
attribs: &mut [usize],
) -> Self {
unsafe {
EGLImage::from_glib_full(ffi::gst_egl_image_from_texture(
context,
gl_mem,
attribs.as_mut_ptr(),
))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment