diff --git a/Cargo.lock b/Cargo.lock index b7effd5014e..47c641b0f17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5889,7 +5889,7 @@ dependencies = [ [[package]] name = "servo-media" version = "0.1.0" -source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" +source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83" dependencies = [ "once_cell", "servo-media-audio", @@ -5902,7 +5902,7 @@ dependencies = [ [[package]] name = "servo-media-audio" version = "0.2.0" -source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" +source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83" dependencies = [ "byte-slice-cast", "euclid", @@ -5923,7 +5923,7 @@ dependencies = [ [[package]] name = "servo-media-derive" version = "0.1.0" -source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" +source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83" dependencies = [ "proc-macro2", "quote", @@ -5933,7 +5933,7 @@ dependencies = [ [[package]] name = "servo-media-dummy" version = "0.1.0" -source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" +source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83" dependencies = [ "ipc-channel", "servo-media", @@ -5947,7 +5947,7 @@ dependencies = [ [[package]] name = "servo-media-gstreamer" version = "0.1.0" -source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" +source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83" dependencies = [ "byte-slice-cast", "glib", @@ -5981,7 +5981,7 @@ dependencies = [ [[package]] name = "servo-media-gstreamer-render" version = "0.1.0" -source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" +source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83" dependencies = [ "gstreamer", "gstreamer-video", @@ -5991,7 +5991,7 @@ dependencies = [ [[package]] name = "servo-media-gstreamer-render-android" version = "0.1.0" -source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" +source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83" dependencies = [ "glib", "gstreamer", @@ -6005,7 +6005,7 @@ dependencies = [ [[package]] name = "servo-media-gstreamer-render-unix" version = "0.1.0" -source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" +source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83" dependencies = [ "glib", "gstreamer", @@ -6020,7 +6020,7 @@ dependencies = [ [[package]] name = "servo-media-player" version = "0.1.0" -source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" +source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83" dependencies = [ "ipc-channel", "serde", @@ -6032,7 +6032,7 @@ dependencies = [ [[package]] name = "servo-media-streams" version = "0.1.0" -source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" +source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83" dependencies = [ "lazy_static", "uuid", @@ -6041,12 +6041,12 @@ dependencies = [ [[package]] name = "servo-media-traits" version = "0.1.0" -source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" +source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83" [[package]] name = "servo-media-webrtc" version = "0.1.0" -source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" +source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83" dependencies = [ "lazy_static", "log", diff --git a/components/script/dom/audiocontext.rs b/components/script/dom/audiocontext.rs index e3be006aced..8f10869f03f 100644 --- a/components/script/dom/audiocontext.rs +++ b/components/script/dom/audiocontext.rs @@ -48,12 +48,15 @@ pub struct AudioContext { impl AudioContext { #[allow(crown::unrooted_must_root)] // https://webaudio.github.io/web-audio-api/#AudioContext-constructors - fn new_inherited(options: &AudioContextOptions, pipeline_id: PipelineId) -> AudioContext { + fn new_inherited( + options: &AudioContextOptions, + pipeline_id: PipelineId, + ) -> Fallible { // Steps 1-3. let context = BaseAudioContext::new_inherited( BaseAudioContextOptions::AudioContext(options.into()), pipeline_id, - ); + )?; // Step 4.1. let latency_hint = match options.latencyHint { @@ -70,12 +73,12 @@ impl AudioContext { // Steps 5 and 6 of the construction algorithm will happen in `resume`, // after reflecting dom object. - AudioContext { + Ok(AudioContext { context, latency_hint, base_latency: 0., // TODO output_latency: 0., // TODO - } + }) } #[allow(crown::unrooted_must_root)] @@ -83,12 +86,12 @@ impl AudioContext { window: &Window, proto: Option, options: &AudioContextOptions, - ) -> DomRoot { + ) -> Fallible> { let pipeline_id = window.pipeline_id(); - let context = AudioContext::new_inherited(options, pipeline_id); + let context = AudioContext::new_inherited(options, pipeline_id)?; let context = reflect_dom_object_with_proto(Box::new(context), window, proto); context.resume(); - context + Ok(context) } // https://webaudio.github.io/web-audio-api/#AudioContext-constructors @@ -98,7 +101,7 @@ impl AudioContext { proto: Option, options: &AudioContextOptions, ) -> Fallible> { - Ok(AudioContext::new(window, proto, options)) + AudioContext::new(window, proto, options) } fn resume(&self) { diff --git a/components/script/dom/baseaudiocontext.rs b/components/script/dom/baseaudiocontext.rs index 6e3126b1362..7203e5fe1e5 100644 --- a/components/script/dom/baseaudiocontext.rs +++ b/components/script/dom/baseaudiocontext.rs @@ -116,7 +116,7 @@ impl BaseAudioContext { pub fn new_inherited( options: BaseAudioContextOptions, pipeline_id: PipelineId, - ) -> BaseAudioContext { + ) -> Fallible { let (sample_rate, channel_count) = match options { BaseAudioContextOptions::AudioContext(ref opt) => (opt.sample_rate, 2), BaseAudioContextOptions::OfflineAudioContext(ref opt) => { @@ -126,11 +126,14 @@ impl BaseAudioContext { let client_context_id = ClientContextId::build(pipeline_id.namespace_id.0, pipeline_id.index.0.get()); - BaseAudioContext { + let audio_context_impl = ServoMedia::get() + .unwrap() + .create_audio_context(&client_context_id, options.into()) + .map_err(|_| Error::NotSupported)?; + + Ok(BaseAudioContext { eventtarget: EventTarget::new_inherited(), - audio_context_impl: ServoMedia::get() - .unwrap() - .create_audio_context(&client_context_id, options.into()), + audio_context_impl, destination: Default::default(), listener: Default::default(), in_flight_resume_promises_queue: Default::default(), @@ -139,7 +142,7 @@ impl BaseAudioContext { sample_rate, state: Cell::new(AudioContextState::Suspended), channel_count: channel_count.into(), - } + }) } /// Tells whether this is an OfflineAudioContext or not. diff --git a/components/script/dom/offlineaudiocontext.rs b/components/script/dom/offlineaudiocontext.rs index 0d47380ab61..a00b52ddca4 100644 --- a/components/script/dom/offlineaudiocontext.rs +++ b/components/script/dom/offlineaudiocontext.rs @@ -51,7 +51,7 @@ impl OfflineAudioContext { length: u32, sample_rate: f32, pipeline_id: PipelineId, - ) -> OfflineAudioContext { + ) -> Fallible { let options = ServoMediaOfflineAudioContextOptions { channels: channel_count as u8, length: length as usize, @@ -60,14 +60,14 @@ impl OfflineAudioContext { let context = BaseAudioContext::new_inherited( BaseAudioContextOptions::OfflineAudioContext(options), pipeline_id, - ); - OfflineAudioContext { + )?; + Ok(OfflineAudioContext { context, channel_count, length, rendering_started: Cell::new(false), pending_rendering_promise: Default::default(), - } + }) } #[allow(crown::unrooted_must_root)] @@ -87,7 +87,7 @@ impl OfflineAudioContext { } let pipeline_id = window.pipeline_id(); let context = - OfflineAudioContext::new_inherited(channel_count, length, sample_rate, pipeline_id); + OfflineAudioContext::new_inherited(channel_count, length, sample_rate, pipeline_id)?; Ok(reflect_dom_object_with_proto( Box::new(context), window, diff --git a/tests/wpt/meta/webaudio/the-audio-api/the-audiocontext-interface/audiocontextoptions.html.ini b/tests/wpt/meta/webaudio/the-audio-api/the-audiocontext-interface/audiocontextoptions.html.ini index e86d0df261e..d4b2efa1bd3 100644 --- a/tests/wpt/meta/webaudio/the-audio-api/the-audiocontext-interface/audiocontextoptions.html.ini +++ b/tests/wpt/meta/webaudio/the-audio-api/the-audiocontext-interface/audiocontextoptions.html.ini @@ -1,5 +1,4 @@ [audiocontextoptions.html] - expected: CRASH [X context = new AudioContext({sampleRate: 1}) did not throw an exception.] expected: FAIL