Media crate

This commit is contained in:
Fernando Jiménez Moreno 2019-06-24 18:45:31 +02:00
parent 2b3a8bf490
commit 7d589ed4f5
23 changed files with 152 additions and 128 deletions

21
Cargo.lock generated
View file

@ -426,7 +426,6 @@ dependencies = [
"pixels 0.0.1",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-media 0.1.0 (git+https://github.com/servo/media)",
"servo_config 0.0.1",
"typetag 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"webrender_api 0.60.0 (git+https://github.com/jdm/webrender?branch=servo-hl)",
@ -648,6 +647,7 @@ dependencies = [
"keyboard-types 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"layout_traits 0.0.1",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"media 0.0.1",
"metrics 0.0.1",
"msg 0.0.1",
"net 0.0.1",
@ -2518,6 +2518,7 @@ dependencies = [
"keyboard-types 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"layout_thread 0.0.1",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"media 0.0.1",
"mozangle 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"net 0.0.1",
@ -2710,6 +2711,22 @@ name = "matches"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "media"
version = "0.0.1"
dependencies = [
"euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-media 0.1.0 (git+https://github.com/servo/media)",
"servo_config 0.0.1",
"webrender 0.60.0 (git+https://github.com/servo/webrender)",
"webrender_api 0.60.0 (git+https://github.com/servo/webrender)",
]
[[package]]
name = "memchr"
version = "2.2.0"
@ -3804,6 +3821,7 @@ dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"malloc_size_of 0.0.1",
"malloc_size_of_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"media 0.0.1",
"metrics 0.0.1",
"mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
"mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3929,6 +3947,7 @@ dependencies = [
"libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)",
"malloc_size_of 0.0.1",
"malloc_size_of_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"media 0.0.1",
"msg 0.0.1",
"net_traits 0.0.1",
"pixels 0.0.1",

View file

@ -16,7 +16,5 @@ 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;

View file

@ -1,6 +0,0 @@
/* 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;

View file

@ -25,7 +25,6 @@ pixels = {path = "../pixels"}
serde = "1.0"
serde_bytes = "0.10"
servo_config = {path = "../config"}
servo-media = {git = "https://github.com/servo/media"}
typetag = "0.1"
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
webvr_traits = {path = "../webvr_traits"}

View file

@ -14,8 +14,6 @@ extern crate malloc_size_of_derive;
extern crate serde;
pub mod canvas;
pub mod media;
mod media_channel;
#[macro_use]
pub mod webgl;
mod webgl_channel;

View file

@ -1,94 +0,0 @@
/* 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 euclid::Size2D;
use servo_media::player::context::{GlApi, GlContext, NativeDisplay, PlayerGLContext};
/// Helper function that creates a GLPlayer channel (GLPlayerSender,
/// GLPlayerReceiver) to be used in GLPlayerMsg.
pub use crate::media_channel::glplayer_channel;
/// Entry point channel type used for sending GLPlayerMsg messages to
/// the GLPlayer thread.
pub use crate::media_channel::GLPlayerChan;
/// Entry point type used in a Script Pipeline to get the GLPlayerChan
/// to be used in that thread.
pub use crate::media_channel::GLPlayerPipeline;
/// Receiver type used in GLPlayerMsg.
pub use crate::media_channel::GLPlayerReceiver;
/// Result type for send()/recv() calls in in GLPlayerMsg.
pub use crate::media_channel::GLPlayerSendResult;
/// Sender type used in GLPlayerMsg.
pub use crate::media_channel::GLPlayerSender;
/// These are the messages that the GLPlayer thread will forward to
/// the video player which lives in htmlmediaelement
#[derive(Debug, Deserialize, Serialize)]
pub enum GLPlayerMsgForward {
PlayerId(u64),
Lock(GLPlayerSender<(u32, Size2D<i32>, usize)>),
Unlock(),
}
/// GLPlayer thread Message API
///
/// These are the message that the thread will receive from the
/// constellation, the webrender::ExternalImageHandle multiplexor
/// implementation, or a htmlmediaelement
#[derive(Debug, Deserialize, Serialize)]
pub enum GLPlayerMsg {
/// Registers an instantiated player in DOM
RegisterPlayer(GLPlayerSender<GLPlayerMsgForward>),
/// Unregisters a player's ID
UnregisterPlayer(u64),
/// Locks a specific texture from a player. Lock messages are used
/// for a correct synchronization with WebRender external image
/// API.
///
/// WR locks a external texture when it wants to use the shared
/// texture contents.
///
/// The WR client should not change the shared texture content
/// until the Unlock call.
///
/// Currently OpenGL Sync Objects are used to implement the
/// synchronization mechanism.
Lock(u64, GLPlayerSender<(u32, Size2D<i32>, usize)>),
/// Unlocks a specific texture from a player. Unlock messages are
/// used for a correct synchronization with WebRender external
/// image API.
///
/// The WR unlocks a context when it finished reading the shared
/// texture contents.
///
/// Unlock messages are always sent after a Lock message.
Unlock(u64),
/// Frees all resources and closes the thread.
Exit,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct WindowGLContext {
/// Application's GL Context
pub gl_context: GlContext,
/// Application's GL Api
pub gl_api: GlApi,
/// Application's native display
pub native_display: NativeDisplay,
/// A channel to the GLPlayer thread.
pub glplayer_chan: Option<GLPlayerPipeline>,
}
impl PlayerGLContext for WindowGLContext {
fn get_gl_context(&self) -> GlContext {
self.gl_context.clone()
}
fn get_native_display(&self) -> NativeDisplay {
self.native_display.clone()
}
fn get_gl_api(&self) -> GlApi {
self.gl_api.clone()
}
}

View file

@ -35,6 +35,7 @@ ipc-channel = "0.11"
layout_traits = {path = "../layout_traits"}
keyboard-types = "0.4.3"
log = "0.4"
media = {path = "../media"}
metrics = {path = "../metrics"}
msg = {path = "../msg"}
net = {path = "../net"}

View file

@ -104,11 +104,9 @@ use background_hang_monitor::HangMonitorRegister;
use backtrace::Backtrace;
use bluetooth_traits::BluetoothRequest;
use canvas::canvas_paint_thread::CanvasPaintThread;
use canvas::media_thread::GLPlayerThreads;
use canvas::webgl_thread::WebGLThreads;
use canvas_traits::canvas::CanvasId;
use canvas_traits::canvas::CanvasMsg;
use canvas_traits::media::WindowGLContext;
use compositing::compositor_thread::CompositorProxy;
use compositing::compositor_thread::Msg as ToCompositorMsg;
use compositing::SendableFrameTree;
@ -125,6 +123,7 @@ use keyboard_types::webdriver::Event as WebDriverInputEvent;
use keyboard_types::KeyboardEvent;
use layout_traits::LayoutThreadFactory;
use log::{Level, LevelFilter, Log, Metadata, Record};
use media::{GLPlayerThreads, WindowGLContext};
use msg::constellation_msg::{BackgroundHangMonitorRegister, HangMonitorAlert, SamplerControlMsg};
use msg::constellation_msg::{
BrowsingContextGroupId, BrowsingContextId, HistoryStateId, PipelineId,

View file

@ -5,7 +5,6 @@
use crate::event_loop::EventLoop;
use background_hang_monitor::HangMonitorRegister;
use bluetooth_traits::BluetoothRequest;
use canvas_traits::media::WindowGLContext;
use canvas_traits::webgl::WebGLPipeline;
use compositing::compositor_thread::Msg as CompositorMsg;
use compositing::CompositionPipeline;
@ -18,6 +17,7 @@ use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use ipc_channel::Error;
use layout_traits::LayoutThreadFactory;
use media::WindowGLContext;
use metrics::PaintTimeMetrics;
use msg::constellation_msg::TopLevelBrowsingContextId;
use msg::constellation_msg::{BackgroundHangMonitorRegister, HangMonitorAlert, SamplerControlMsg};

View file

@ -0,0 +1,23 @@
[package]
name = "media"
version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
edition = "2018"
publish = false
[lib]
name = "media"
path = "lib.rs"
[dependencies]
euclid = "0.19"
fnv = "1.0"
ipc-channel = "0.11"
lazy_static = "1"
log = "0.4"
serde = "1.0"
servo_config = {path = "../config"}
servo-media = {git = "https://github.com/servo/media"}
webrender = {git = "https://github.com/servo/webrender"}
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}

View file

@ -2,12 +2,99 @@
* 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::{GLPlayerExternalImageApi, GLPlayerExternalImageHandler, GLPlayerThread};
use canvas_traits::media::glplayer_channel;
use canvas_traits::media::{
GLPlayerChan, GLPlayerMsg, GLPlayerPipeline, GLPlayerReceiver, GLPlayerSender,
};
#![crate_name = "media"]
#![crate_type = "rlib"]
#![deny(unsafe_code)]
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde;
use euclid::Size2D;
use servo_media::player::context::{GlApi, GlContext, NativeDisplay, PlayerGLContext};
mod media_channel;
mod media_thread;
pub use crate::media_channel::glplayer_channel;
use crate::media_channel::{GLPlayerChan, GLPlayerPipeline, GLPlayerReceiver, GLPlayerSender};
use crate::media_thread::{GLPlayerExternalImageApi, GLPlayerExternalImageHandler, GLPlayerThread};
/// These are the messages that the GLPlayer thread will forward to
/// the video player which lives in htmlmediaelement
#[derive(Debug, Deserialize, Serialize)]
pub enum GLPlayerMsgForward {
PlayerId(u64),
Lock(GLPlayerSender<(u32, Size2D<i32>, usize)>),
Unlock(),
}
/// GLPlayer thread Message API
///
/// These are the message that the thread will receive from the
/// constellation, the webrender::ExternalImageHandle multiplexor
/// implementation, or a htmlmediaelement
#[derive(Debug, Deserialize, Serialize)]
pub enum GLPlayerMsg {
/// Registers an instantiated player in DOM
RegisterPlayer(GLPlayerSender<GLPlayerMsgForward>),
/// Unregisters a player's ID
UnregisterPlayer(u64),
/// Locks a specific texture from a player. Lock messages are used
/// for a correct synchronization with WebRender external image
/// API.
///
/// WR locks a external texture when it wants to use the shared
/// texture contents.
///
/// The WR client should not change the shared texture content
/// until the Unlock call.
///
/// Currently OpenGL Sync Objects are used to implement the
/// synchronization mechanism.
Lock(u64, GLPlayerSender<(u32, Size2D<i32>, usize)>),
/// Unlocks a specific texture from a player. Unlock messages are
/// used for a correct synchronization with WebRender external
/// image API.
///
/// The WR unlocks a context when it finished reading the shared
/// texture contents.
///
/// Unlock messages are always sent after a Lock message.
Unlock(u64),
/// Frees all resources and closes the thread.
Exit,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct WindowGLContext {
/// Application's GL Context
pub gl_context: GlContext,
/// Application's GL Api
pub gl_api: GlApi,
/// Application's native display
pub native_display: NativeDisplay,
/// A channel to the GLPlayer thread.
pub glplayer_chan: Option<GLPlayerPipeline>,
}
impl PlayerGLContext for WindowGLContext {
fn get_gl_context(&self) -> GlContext {
self.gl_context.clone()
}
fn get_native_display(&self) -> NativeDisplay {
self.native_display.clone()
}
fn get_gl_api(&self) -> GlApi {
self.gl_api.clone()
}
}
/// GLPlayer Threading API entry point that lives in the constellation.
pub struct GLPlayerThreads(GLPlayerSender<GLPlayerMsg>);

View file

@ -7,7 +7,7 @@
mod ipc;
mod mpsc;
use crate::media::GLPlayerMsg;
use crate::GLPlayerMsg;
use serde::{Deserialize, Serialize};
use servo_config::opts;
use std::fmt;

View file

@ -2,17 +2,14 @@
* 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 crate::media_channel::{glplayer_channel, GLPlayerSender};
/// GL player threading API entry point that lives in the
/// constellation.
use crate::{GLPlayerMsg, GLPlayerMsgForward};
use euclid::Size2D;
use fnv::FnvHashMap;
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 {

View file

@ -70,6 +70,7 @@ libc = "0.2"
log = "0.4"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = "0.1"
media = {path = "../media"}
metrics = {path = "../metrics"}
mitochondria = "1.1.2"
mime = "0.3.13"

View file

@ -58,7 +58,6 @@ use crate::microtask::{Microtask, MicrotaskRunnable};
use crate::network_listener::{self, NetworkListener, PreInvoke, ResourceTimingListener};
use crate::script_thread::ScriptThread;
use crate::task_source::TaskSource;
use canvas_traits::media::*;
use dom_struct::dom_struct;
use euclid::Size2D;
use headers::{ContentLength, ContentRange, HeaderMapExt};
@ -66,6 +65,7 @@ use html5ever::{LocalName, Prefix};
use http::header::{self, HeaderMap, HeaderValue};
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use media::{glplayer_channel, GLPlayerMsg, GLPlayerMsgForward};
use net_traits::image::base::Image;
use net_traits::image_cache::ImageResponse;
use net_traits::request::{CredentialsMode, Destination, Referrer, RequestBuilder, RequestMode};

View file

@ -68,7 +68,6 @@ use crate::webdriver_handlers::jsval_to_webdriver;
use app_units::Au;
use base64;
use bluetooth_traits::BluetoothRequest;
use canvas_traits::media::WindowGLContext;
use canvas_traits::webgl::WebGLChan;
use crossbeam_channel::{unbounded, Sender, TryRecvError};
use cssparser::{Parser, ParserInput, SourceLocation};
@ -86,6 +85,7 @@ use js::jsval::JSVal;
use js::jsval::UndefinedValue;
use js::rust::wrappers::JS_DefineProperty;
use js::rust::HandleValue;
use media::WindowGLContext;
use msg::constellation_msg::PipelineId;
use net_traits::image_cache::{ImageCache, ImageResponder, ImageResponse};
use net_traits::image_cache::{PendingImageId, PendingImageResponse};

View file

@ -86,7 +86,6 @@ use crate::task_source::websocket::WebsocketTaskSource;
use crate::task_source::TaskSourceName;
use crate::webdriver_handlers;
use bluetooth_traits::BluetoothRequest;
use canvas_traits::media::WindowGLContext;
use canvas_traits::webgl::WebGLPipeline;
use crossbeam_channel::{unbounded, Receiver, Sender};
use devtools_traits::CSSError;
@ -104,6 +103,7 @@ use js::jsapi::{JSContext, JS_SetWrapObjectCallbacks};
use js::jsapi::{JSTracer, SetWindowProxyClass};
use js::jsval::UndefinedValue;
use js::rust::ParentRuntime;
use media::WindowGLContext;
use metrics::{PaintTimeMetrics, MAX_TASK_NS};
use mime::{self, Mime};
use msg::constellation_msg::{

View file

@ -27,6 +27,7 @@ keyboard-types = "0.4.3"
libc = "0.2"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = "0.1"
media = {path = "../media"}
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
pixels = {path = "../pixels"}

View file

@ -21,7 +21,6 @@ pub mod webdriver_msg;
use crate::webdriver_msg::{LoadStatus, WebDriverScriptCommand};
use bluetooth_traits::BluetoothRequest;
use canvas_traits::media::WindowGLContext;
use canvas_traits::webgl::WebGLPipeline;
use crossbeam_channel::{Receiver, RecvTimeoutError, Sender};
use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg, WorkerId};
@ -35,6 +34,7 @@ use ipc_channel::Error as IpcError;
use keyboard_types::webdriver::Event as WebDriverInputEvent;
use keyboard_types::{CompositionEvent, KeyboardEvent};
use libc::c_void;
use media::WindowGLContext;
use msg::constellation_msg::BackgroundHangMonitorRegister;
use msg::constellation_msg::{BrowsingContextId, HistoryStateId, PipelineId};
use msg::constellation_msg::{PipelineNamespaceId, TopLevelBrowsingContextId, TraversalDirection};

View file

@ -55,6 +55,7 @@ ipc-channel = "0.11"
keyboard-types = "0.4"
layout_thread = {path = "../layout_thread"}
log = "0.4"
media = {path = "../media"}
msg = {path = "../msg"}
net = {path = "../net"}
net_traits = {path = "../net_traits"}

View file

@ -35,6 +35,7 @@ pub use euclid;
pub use gfx;
pub use ipc_channel;
pub use layout_thread;
pub use media;
pub use msg;
pub use net;
pub use net_traits;
@ -63,9 +64,7 @@ fn webdriver(_port: u16, _constellation: Sender<ConstellationMsg>) {}
use bluetooth::BluetoothThreadFactory;
use bluetooth_traits::BluetoothRequest;
use canvas::gl_context::GLContextFactory;
use canvas::media_thread::GLPlayerThreads;
use canvas::webgl_thread::WebGLThreads;
use canvas_traits::media::WindowGLContext;
use compositing::compositor_thread::{
CompositorProxy, CompositorReceiver, InitialCompositorState, Msg,
};
@ -95,6 +94,7 @@ use gaol::sandbox::{ChildSandbox, ChildSandboxMethods};
use gfx::font_cache_thread::FontCacheThread;
use ipc_channel::ipc::{self, IpcSender};
use log::{Log, Metadata, Record};
use media::{GLPlayerThreads, WindowGLContext};
use msg::constellation_msg::{PipelineNamespace, PipelineNamespaceId};
use net::resource_thread::new_resource_threads;
use net_traits::IpcSend;