2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
|
|
|
|
2019-03-19 14:06:27 +00:00
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
use glib::translate::*;
|
|
|
|
use gst::prelude::*;
|
|
|
|
|
2020-11-22 10:28:12 +00:00
|
|
|
use crate::GLContext;
|
2019-03-19 14:06:27 +00:00
|
|
|
|
2020-10-24 17:06:59 +00:00
|
|
|
#[repr(transparent)]
|
2020-11-22 10:28:12 +00:00
|
|
|
pub struct GLSyncMeta(ffi::GstGLSyncMeta);
|
2019-03-19 14:06:27 +00:00
|
|
|
|
2019-12-18 15:04:42 +00:00
|
|
|
unsafe impl Send for GLSyncMeta {}
|
|
|
|
unsafe impl Sync for GLSyncMeta {}
|
|
|
|
|
2019-03-19 14:06:27 +00:00
|
|
|
impl GLSyncMeta {
|
|
|
|
pub fn add<'a, C: IsA<GLContext>>(
|
|
|
|
buffer: &'a mut gst::BufferRef,
|
|
|
|
context: &C,
|
|
|
|
) -> gst::MetaRefMut<'a, Self, gst::meta::Standalone> {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2019-03-19 14:06:27 +00:00
|
|
|
unsafe {
|
2020-11-22 10:28:12 +00:00
|
|
|
let meta = ffi::gst_buffer_add_gl_sync_meta(
|
2019-03-19 14:06:27 +00:00
|
|
|
context.as_ref().to_glib_none().0,
|
|
|
|
buffer.as_mut_ptr(),
|
|
|
|
);
|
|
|
|
Self::from_mut_ptr(buffer, meta)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn context(&self) -> GLContext {
|
2019-03-19 14:06:27 +00:00
|
|
|
unsafe { from_glib_none(self.0.context) }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_sync_point<C: IsA<GLContext>>(&self, context: &C) {
|
|
|
|
unsafe {
|
2020-11-22 10:28:12 +00:00
|
|
|
ffi::gst_gl_sync_meta_set_sync_point(
|
2019-03-19 14:06:27 +00:00
|
|
|
&self.0 as *const _ as *mut _,
|
|
|
|
context.as_ref().to_glib_none().0,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn wait<C: IsA<GLContext>>(&self, context: &C) {
|
|
|
|
unsafe {
|
2020-11-22 10:28:12 +00:00
|
|
|
ffi::gst_gl_sync_meta_wait(
|
2019-03-19 14:06:27 +00:00
|
|
|
&self.0 as *const _ as *mut _,
|
|
|
|
context.as_ref().to_glib_none().0,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn wait_cpu<C: IsA<GLContext>>(&self, context: &C) {
|
|
|
|
unsafe {
|
2020-11-22 10:28:12 +00:00
|
|
|
ffi::gst_gl_sync_meta_wait_cpu(
|
2019-03-19 14:06:27 +00:00
|
|
|
&self.0 as *const _ as *mut _,
|
|
|
|
context.as_ref().to_glib_none().0,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl MetaAPI for GLSyncMeta {
|
2020-11-22 10:28:12 +00:00
|
|
|
type GstType = ffi::GstGLSyncMeta;
|
2019-03-19 14:06:27 +00:00
|
|
|
|
2021-04-20 10:23:24 +00:00
|
|
|
fn meta_api() -> glib::Type {
|
2020-11-22 10:28:12 +00:00
|
|
|
unsafe { from_glib(ffi::gst_gl_sync_meta_api_get_type()) }
|
2019-03-19 14:06:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Debug for GLSyncMeta {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.debug_struct("GLSyncMeta")
|
2021-04-11 19:39:50 +00:00
|
|
|
.field("context", &self.context())
|
2019-03-19 14:06:27 +00:00
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|