Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run GL commands on the GStreamer GL thread #25271

Merged
merged 1 commit into from Dec 13, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Run GL commands on the GStreamer GL thread

  • Loading branch information
asajeffrey committed Dec 12, 2019
commit 16122be83e8ef51f03f58d9aab9d6e3888756cda
@@ -55,8 +55,10 @@ use gstreamer_base::BaseSrcExt;
use gstreamer_gl::GLContext;
use gstreamer_gl::GLContextExt;
use gstreamer_gl::GLContextExtManual;
use gstreamer_gl_sys::gst_gl_context_thread_add;

This comment has been minimized.

Copy link
@Manishearth

Manishearth Dec 12, 2019

Member

is there no exported rust function for this? should there be one? we should file an upstream bug

This comment has been minimized.

use gstreamer_gl_sys::gst_gl_texture_target_to_gl;
use gstreamer_gl_sys::gst_is_gl_memory;
use gstreamer_gl_sys::GstGLContext;
use gstreamer_gl_sys::GstGLMemory;
use gstreamer_video::VideoInfo;

@@ -89,6 +91,7 @@ use surfman_chains_api::SwapChainAPI;
use std::cell::RefCell;
use std::collections::HashMap;
use std::convert::TryFrom;
use std::ffi::c_void;
use std::rc::Rc;
use std::sync::atomic::AtomicU64;
use std::sync::atomic::Ordering;
@@ -523,9 +526,6 @@ impl ObjectImpl for ServoWebSrc {

impl ElementImpl for ServoWebSrc {}

thread_local! {
static GL: RefCell<Option<Rc<Gl>>> = RefCell::new(None);
}
impl BaseSrcImpl for ServoWebSrc {
fn set_caps(&self, src: &BaseSrc, outcaps: &Caps) -> Result<(), LoggableError> {
// Save the video info for later use
@@ -655,8 +655,48 @@ impl BaseSrcImpl for ServoWebSrc {
FlowError::Error
})?;

// Fill the buffer on the GL thread
let result = Err(FlowError::Error);
let mut task = RunOnGLThread {
servo_web_src: self,
src,
gl_memory,
result,
};
let data = &mut task as *mut RunOnGLThread as *mut c_void;
unsafe { gst_gl_context_thread_add(gl_memory.mem.context, Some(fill_on_gl_thread), data) };
task.result?;

// Wake up Servo
let _ = self.sender.send(ServoWebSrcMsg::Heartbeat);
Ok(buffer)
}
}

struct RunOnGLThread<'a> {
servo_web_src: &'a ServoWebSrc,
src: &'a BaseSrc,
gl_memory: &'a GstGLMemory,
result: Result<(), FlowError>,
}

unsafe extern "C" fn fill_on_gl_thread(context: *mut GstGLContext, data: *mut c_void) {
let task = &mut *(data as *mut RunOnGLThread);
let gl_context = GLContext::from_glib_borrow(context);
task.result = task
.servo_web_src
.fill_gl_memory(task.src, gl_context, task.gl_memory);
}

impl ServoWebSrc {
// Runs on the GL thread
fn fill_gl_memory(
&self,
src: &BaseSrc,
gl_context: GLContext,
gl_memory: &GstGLMemory,
) -> Result<(), FlowError> {
// Get the data out of the memory
let gl_context = unsafe { GLContext::from_glib_borrow(gl_memory.mem.context) };
let draw_texture_id = gl_memory.tex_id;
let draw_texture_target = unsafe { gst_gl_texture_target_to_gl(gl_memory.tex_target) };
let height = gl_memory.info.height;
@@ -816,7 +856,6 @@ impl BaseSrcImpl for ServoWebSrc {
FlowError::Error
})?;

let _ = self.sender.send(ServoWebSrcMsg::Heartbeat);
Ok(buffer)
Ok(())
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.