Skip to content
Permalink
Browse files

Add GLPlayerThreads in canvas

This factory will launch a GLPlayerThread from the application main
thread.

And add GLPlayerThread, the multiplexor for media players' video
renderers. This thread will receive commands from htmlmedialement
and webrenderer.

This code is also inspired by webgl_threads and WebGLThread.
  • Loading branch information...
ceyusa authored and ferjm committed Jun 11, 2019
1 parent 0d52d5d commit 43467b4290ad5b8b735de1321d64ce4b5aa7cab1
@@ -16,5 +16,7 @@ mod raqote_backend;
pub mod canvas_data;
pub mod canvas_paint_thread;
pub mod gl_context;
mod media_mode;
pub mod media_thread;
mod webgl_mode;
pub mod webgl_thread;
@@ -0,0 +1,30 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::media_thread::GLPlayerThread;
use canvas_traits::media::{GLPlayerChan, GLPlayerMsg, GLPlayerPipeline, GLPlayerSender};

/// GLPlayer Threading API entry point that lives in the constellation.
pub struct GLPlayerThreads(GLPlayerSender<GLPlayerMsg>);

impl GLPlayerThreads {
pub fn new() -> GLPlayerThreads {
let channel = GLPlayerThread::start();
GLPlayerThreads(channel)
}

/// Gets the GLPlayerThread handle for each script pipeline.
pub fn pipeline(&self) -> GLPlayerPipeline {
// This mode creates a single thread, so the existing
// GLPlayerChan is just cloned.
GLPlayerPipeline(GLPlayerChan(self.0.clone()))
}

/// Sends an exit message to close the GLPlayerThreads
pub fn exit(&self) -> Result<(), &'static str> {
self.0
.send(GLPlayerMsg::Exit)
.map_err(|_| "Failed to send Exit message")
}
}
@@ -0,0 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

mod inprocess;
pub use self::inprocess::GLPlayerThreads;
@@ -0,0 +1,53 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use canvas_traits::media::*;
use std::thread;

/// GL player threading API entry point that lives in the
/// constellation.
///
/// It allows to get a GLPlayerThead handle for each script pipeline.
pub use crate::media_mode::GLPlayerThreads;

/// A GLPlayerThrx1ead manages the life cycle and message multiplexign of
/// a set of video players with GL render.
pub struct GLPlayerThread ();

impl GLPlayerThread {
pub fn new() -> Self {
GLPlayerThread()
}

pub fn start() -> GLPlayerSender<GLPlayerMsg> {
let (sender, receiver) = glplayer_channel::<GLPlayerMsg>().unwrap();
thread::Builder::new()
.name("GLPlayerThread".to_owned())
.spawn(move || {
let renderer = GLPlayerThread::new();
loop {
let msg = receiver.recv().unwrap();
let exit = renderer.handle_msg(msg);
if exit {
return;
}
}
})
.expect("Thread spawning failed");

sender
}

/// Handles a generic WebGLMsg message
#[inline]
fn handle_msg(&self, msg: GLPlayerMsg) -> bool {
trace!("processing {:?}", msg);
match msg {
GLPlayerMsg::Exit => return true,
_ => (),
}

false
}
}

0 comments on commit 43467b4

Please sign in to comment.
You can’t perform that action at this time.