Skip to content
Permalink
Browse files

Add a task source for messages from GLPlayer thread

  • Loading branch information...
ceyusa authored and ferjm committed Jun 14, 2019
1 parent a9ad088 commit 95c3d52e7bbc400e1109887a39a561840ec6119a
Showing with 35 additions and 4 deletions.
  1. +9 −1 components/canvas_traits/media_channel/mod.rs
  2. +26 −3 components/script/dom/htmlmediaelement.rs
@@ -70,13 +70,21 @@ where
GLPlayerReceiver::Mpsc(ref receiver) => receiver.recv().map_err(|_| ()),
}
}

pub fn to_opaque(self) -> ipc_channel::ipc::OpaqueIpcReceiver {
match self {
GLPlayerReceiver::Ipc(receiver) => receiver.to_opaque(),
_ => unreachable!(),
}
}
}

pub fn glplayer_channel<T>() -> Result<(GLPlayerSender<T>, GLPlayerReceiver<T>), ()>
where
T: for<'de> Deserialize<'de> + Serialize,
{
if *IS_MULTIPROCESS {
// Let's use Ipc until we move the Player instance into GPlayerThread
if true {
ipc::glplayer_channel()
.map(|(tx, rx)| (GLPlayerSender::Ipc(tx), GLPlayerReceiver::Ipc(rx)))
.map_err(|_| ())
@@ -1297,7 +1297,7 @@ impl HTMLMediaElement {
);

// GLPlayer thread setup
let player_id = window
let (player_id, image_receiver) = window
.get_player_context()
.glplayer_chan
.map(|pipeline| {
@@ -1308,14 +1308,37 @@ impl HTMLMediaElement {
.send(GLPlayerMsg::RegisterPlayer(image_sender))
.unwrap();
match image_receiver.recv().unwrap() {
GLPlayerMsgForward::PlayerId(id) => id,
GLPlayerMsgForward::PlayerId(id) => (id, Some(image_receiver)),
_ => unreachable!(),
}
})
.unwrap_or(0);
.unwrap_or((0, None));

self.id.set(player_id);
self.frame_renderer.lock().unwrap().id = player_id;

if let Some(image_receiver) = image_receiver {
let trusted_node = Trusted::new(self);
let (task_source, canceller) = window
.task_manager()
.media_element_task_source_with_canceller();
ROUTER.add_route(
image_receiver.to_opaque(),
Box::new(move |message| {
let msg: GLPlayerMsgForward = message.to().unwrap();
let _this = trusted_node.clone();
if let Err(err) = task_source.queue_with_canceller(
task!(handle_glplayer_message: move || {
trace!("GLPlayer message {:?}", msg);
}),
&canceller,
) {
warn!("Could not queue GL player message handler task {:?}", err);
}
}),
);
}

Ok(())
}

0 comments on commit 95c3d52

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