Register pipeline instead of browsing contexts for media instances

This commit is contained in:
Fernando Jiménez Moreno 2019-09-17 23:04:38 +02:00
parent 7b653cad7b
commit 51ed44c77d
4 changed files with 24 additions and 29 deletions

View file

@ -23,7 +23,7 @@ use crate::dom::promise::Promise;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::task_source::TaskSource; use crate::task_source::TaskSource;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use msg::constellation_msg::BrowsingContextId; use msg::constellation_msg::PipelineId;
use servo_media::audio::context::{LatencyCategory, ProcessingState, RealTimeAudioContextOptions}; use servo_media::audio::context::{LatencyCategory, ProcessingState, RealTimeAudioContextOptions};
use std::rc::Rc; use std::rc::Rc;
@ -40,14 +40,11 @@ pub struct AudioContext {
impl AudioContext { impl AudioContext {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
// https://webaudio.github.io/web-audio-api/#AudioContext-constructors // https://webaudio.github.io/web-audio-api/#AudioContext-constructors
fn new_inherited( fn new_inherited(options: &AudioContextOptions, pipeline_id: PipelineId) -> AudioContext {
options: &AudioContextOptions,
browsing_context_id: BrowsingContextId,
) -> AudioContext {
// Steps 1-3. // Steps 1-3.
let context = BaseAudioContext::new_inherited( let context = BaseAudioContext::new_inherited(
BaseAudioContextOptions::AudioContext(options.into()), BaseAudioContextOptions::AudioContext(options.into()),
browsing_context_id, pipeline_id,
); );
// Step 4.1. // Step 4.1.
@ -70,8 +67,10 @@ impl AudioContext {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new(window: &Window, options: &AudioContextOptions) -> DomRoot<AudioContext> { pub fn new(window: &Window, options: &AudioContextOptions) -> DomRoot<AudioContext> {
let browsing_context_id = window.window_proxy().top_level_browsing_context_id().0; let pipeline_id = window
let context = AudioContext::new_inherited(options, browsing_context_id); .pipeline_id()
.expect("Cannot create AudioContext outside of a pipeline");
let context = AudioContext::new_inherited(options, pipeline_id);
let context = reflect_dom_object(Box::new(context), window, AudioContextBinding::Wrap); let context = reflect_dom_object(Box::new(context), window, AudioContextBinding::Wrap);
context.resume(); context.resume();
context context

View file

@ -51,7 +51,7 @@ use crate::task_source::TaskSource;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use js::rust::CustomAutoRooterGuard; use js::rust::CustomAutoRooterGuard;
use js::typedarray::ArrayBuffer; use js::typedarray::ArrayBuffer;
use msg::constellation_msg::BrowsingContextId; use msg::constellation_msg::PipelineId;
use servo_media::audio::context::{AudioContext, AudioContextOptions, ProcessingState}; use servo_media::audio::context::{AudioContext, AudioContextOptions, ProcessingState};
use servo_media::audio::context::{OfflineAudioContextOptions, RealTimeAudioContextOptions}; use servo_media::audio::context::{OfflineAudioContextOptions, RealTimeAudioContextOptions};
use servo_media::audio::decoder::AudioDecoderCallbacks; use servo_media::audio::decoder::AudioDecoderCallbacks;
@ -109,7 +109,7 @@ impl BaseAudioContext {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new_inherited( pub fn new_inherited(
options: BaseAudioContextOptions, options: BaseAudioContextOptions,
browsing_context_id: BrowsingContextId, pipeline_id: PipelineId,
) -> BaseAudioContext { ) -> BaseAudioContext {
let (sample_rate, channel_count) = match options { let (sample_rate, channel_count) = match options {
BaseAudioContextOptions::AudioContext(ref opt) => (opt.sample_rate, 2), BaseAudioContextOptions::AudioContext(ref opt) => (opt.sample_rate, 2),
@ -118,10 +118,8 @@ impl BaseAudioContext {
}, },
}; };
let client_context_id = ClientContextId::build( let client_context_id =
browsing_context_id.namespace_id.0, ClientContextId::build(pipeline_id.namespace_id.0, pipeline_id.index.0.get());
browsing_context_id.index.0.get(),
);
let context = BaseAudioContext { let context = BaseAudioContext {
eventtarget: EventTarget::new_inherited(), eventtarget: EventTarget::new_inherited(),
audio_context_impl: ServoMedia::get() audio_context_impl: ServoMedia::get()

View file

@ -1329,11 +1329,11 @@ impl HTMLMediaElement {
HTMLMediaElementTypeId::HTMLVideoElement => Some(self.frame_renderer.clone()), HTMLMediaElementTypeId::HTMLVideoElement => Some(self.frame_renderer.clone()),
}; };
let browsing_context_id = window.window_proxy().top_level_browsing_context_id().0; let pipeline_id = window
let client_context_id = ClientContextId::build( .pipeline_id()
browsing_context_id.namespace_id.0, .expect("Cannot create player outside of a pipeline");
browsing_context_id.index.0.get(), let client_context_id =
); ClientContextId::build(pipeline_id.namespace_id.0, pipeline_id.index.0.get());
let player = ServoMedia::get().unwrap().create_player( let player = ServoMedia::get().unwrap().create_player(
&client_context_id, &client_context_id,
stream_type, stream_type,

View file

@ -23,7 +23,7 @@ use crate::dom::promise::Promise;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::task_source::TaskSource; use crate::task_source::TaskSource;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use msg::constellation_msg::BrowsingContextId; use msg::constellation_msg::PipelineId;
use servo_media::audio::context::OfflineAudioContextOptions as ServoMediaOfflineAudioContextOptions; use servo_media::audio::context::OfflineAudioContextOptions as ServoMediaOfflineAudioContextOptions;
use std::cell::Cell; use std::cell::Cell;
use std::rc::Rc; use std::rc::Rc;
@ -47,7 +47,7 @@ impl OfflineAudioContext {
channel_count: u32, channel_count: u32,
length: u32, length: u32,
sample_rate: f32, sample_rate: f32,
browsing_context_id: BrowsingContextId, pipeline_id: PipelineId,
) -> OfflineAudioContext { ) -> OfflineAudioContext {
let options = ServoMediaOfflineAudioContextOptions { let options = ServoMediaOfflineAudioContextOptions {
channels: channel_count as u8, channels: channel_count as u8,
@ -56,7 +56,7 @@ impl OfflineAudioContext {
}; };
let context = BaseAudioContext::new_inherited( let context = BaseAudioContext::new_inherited(
BaseAudioContextOptions::OfflineAudioContext(options), BaseAudioContextOptions::OfflineAudioContext(options),
browsing_context_id, pipeline_id,
); );
OfflineAudioContext { OfflineAudioContext {
context, context,
@ -82,13 +82,11 @@ impl OfflineAudioContext {
{ {
return Err(Error::NotSupported); return Err(Error::NotSupported);
} }
let browsing_context_id = window.window_proxy().top_level_browsing_context_id().0; let pipeline_id = window
let context = OfflineAudioContext::new_inherited( .pipeline_id()
channel_count, .expect("Cannot create audio context outside of a pipeline");
length, let context =
sample_rate, OfflineAudioContext::new_inherited(channel_count, length, sample_rate, pipeline_id);
browsing_context_id,
);
Ok(reflect_dom_object( Ok(reflect_dom_object(
Box::new(context), Box::new(context),
window, window,