fix: add error handling to BaseAudioContext::new_inherited (#33023)

* fix: add error handling to BaseAudioContext::new_inherited

Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>

* Update servo-media

Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>

* Update test expectations

Signed-off-by: Taym <haddadi.taym@gmail.com>

* Update servo-media

Signed-off-by: Taym <haddadi.taym@gmail.com>

---------

Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>
Signed-off-by: Taym <haddadi.taym@gmail.com>
This commit is contained in:
Taym Haddadi 2024-08-18 15:58:43 +02:00 committed by GitHub
parent 1ef3e107bd
commit a24e92778a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 37 additions and 32 deletions

24
Cargo.lock generated
View file

@ -5889,7 +5889,7 @@ dependencies = [
[[package]] [[package]]
name = "servo-media" name = "servo-media"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"servo-media-audio", "servo-media-audio",
@ -5902,7 +5902,7 @@ dependencies = [
[[package]] [[package]]
name = "servo-media-audio" name = "servo-media-audio"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83"
dependencies = [ dependencies = [
"byte-slice-cast", "byte-slice-cast",
"euclid", "euclid",
@ -5923,7 +5923,7 @@ dependencies = [
[[package]] [[package]]
name = "servo-media-derive" name = "servo-media-derive"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -5933,7 +5933,7 @@ dependencies = [
[[package]] [[package]]
name = "servo-media-dummy" name = "servo-media-dummy"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83"
dependencies = [ dependencies = [
"ipc-channel", "ipc-channel",
"servo-media", "servo-media",
@ -5947,7 +5947,7 @@ dependencies = [
[[package]] [[package]]
name = "servo-media-gstreamer" name = "servo-media-gstreamer"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83"
dependencies = [ dependencies = [
"byte-slice-cast", "byte-slice-cast",
"glib", "glib",
@ -5981,7 +5981,7 @@ dependencies = [
[[package]] [[package]]
name = "servo-media-gstreamer-render" name = "servo-media-gstreamer-render"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83"
dependencies = [ dependencies = [
"gstreamer", "gstreamer",
"gstreamer-video", "gstreamer-video",
@ -5991,7 +5991,7 @@ dependencies = [
[[package]] [[package]]
name = "servo-media-gstreamer-render-android" name = "servo-media-gstreamer-render-android"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83"
dependencies = [ dependencies = [
"glib", "glib",
"gstreamer", "gstreamer",
@ -6005,7 +6005,7 @@ dependencies = [
[[package]] [[package]]
name = "servo-media-gstreamer-render-unix" name = "servo-media-gstreamer-render-unix"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83"
dependencies = [ dependencies = [
"glib", "glib",
"gstreamer", "gstreamer",
@ -6020,7 +6020,7 @@ dependencies = [
[[package]] [[package]]
name = "servo-media-player" name = "servo-media-player"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83"
dependencies = [ dependencies = [
"ipc-channel", "ipc-channel",
"serde", "serde",
@ -6032,7 +6032,7 @@ dependencies = [
[[package]] [[package]]
name = "servo-media-streams" name = "servo-media-streams"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"uuid", "uuid",
@ -6041,12 +6041,12 @@ dependencies = [
[[package]] [[package]]
name = "servo-media-traits" name = "servo-media-traits"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83"
[[package]] [[package]]
name = "servo-media-webrtc" name = "servo-media-webrtc"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/media#f6e6ee0528c8735e3ded8b9a9f68acfabefaf539" source = "git+https://github.com/servo/media#ed1d4c7c11c93e7e66afc0224fc15f70d6b1fe83"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"log", "log",

View file

@ -48,12 +48,15 @@ pub struct AudioContext {
impl AudioContext { impl AudioContext {
#[allow(crown::unrooted_must_root)] #[allow(crown::unrooted_must_root)]
// https://webaudio.github.io/web-audio-api/#AudioContext-constructors // 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<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()),
pipeline_id, pipeline_id,
); )?;
// Step 4.1. // Step 4.1.
let latency_hint = match options.latencyHint { let latency_hint = match options.latencyHint {
@ -70,12 +73,12 @@ impl AudioContext {
// Steps 5 and 6 of the construction algorithm will happen in `resume`, // Steps 5 and 6 of the construction algorithm will happen in `resume`,
// after reflecting dom object. // after reflecting dom object.
AudioContext { Ok(AudioContext {
context, context,
latency_hint, latency_hint,
base_latency: 0., // TODO base_latency: 0., // TODO
output_latency: 0., // TODO output_latency: 0., // TODO
} })
} }
#[allow(crown::unrooted_must_root)] #[allow(crown::unrooted_must_root)]
@ -83,12 +86,12 @@ impl AudioContext {
window: &Window, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
options: &AudioContextOptions, options: &AudioContextOptions,
) -> DomRoot<AudioContext> { ) -> Fallible<DomRoot<AudioContext>> {
let pipeline_id = window.pipeline_id(); 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); let context = reflect_dom_object_with_proto(Box::new(context), window, proto);
context.resume(); context.resume();
context Ok(context)
} }
// https://webaudio.github.io/web-audio-api/#AudioContext-constructors // https://webaudio.github.io/web-audio-api/#AudioContext-constructors
@ -98,7 +101,7 @@ impl AudioContext {
proto: Option<HandleObject>, proto: Option<HandleObject>,
options: &AudioContextOptions, options: &AudioContextOptions,
) -> Fallible<DomRoot<AudioContext>> { ) -> Fallible<DomRoot<AudioContext>> {
Ok(AudioContext::new(window, proto, options)) AudioContext::new(window, proto, options)
} }
fn resume(&self) { fn resume(&self) {

View file

@ -116,7 +116,7 @@ impl BaseAudioContext {
pub fn new_inherited( pub fn new_inherited(
options: BaseAudioContextOptions, options: BaseAudioContextOptions,
pipeline_id: PipelineId, pipeline_id: PipelineId,
) -> BaseAudioContext { ) -> Fallible<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),
BaseAudioContextOptions::OfflineAudioContext(ref opt) => { BaseAudioContextOptions::OfflineAudioContext(ref opt) => {
@ -126,11 +126,14 @@ impl BaseAudioContext {
let client_context_id = let client_context_id =
ClientContextId::build(pipeline_id.namespace_id.0, pipeline_id.index.0.get()); ClientContextId::build(pipeline_id.namespace_id.0, pipeline_id.index.0.get());
BaseAudioContext { let audio_context_impl = ServoMedia::get()
eventtarget: EventTarget::new_inherited(),
audio_context_impl: ServoMedia::get()
.unwrap() .unwrap()
.create_audio_context(&client_context_id, options.into()), .create_audio_context(&client_context_id, options.into())
.map_err(|_| Error::NotSupported)?;
Ok(BaseAudioContext {
eventtarget: EventTarget::new_inherited(),
audio_context_impl,
destination: Default::default(), destination: Default::default(),
listener: Default::default(), listener: Default::default(),
in_flight_resume_promises_queue: Default::default(), in_flight_resume_promises_queue: Default::default(),
@ -139,7 +142,7 @@ impl BaseAudioContext {
sample_rate, sample_rate,
state: Cell::new(AudioContextState::Suspended), state: Cell::new(AudioContextState::Suspended),
channel_count: channel_count.into(), channel_count: channel_count.into(),
} })
} }
/// Tells whether this is an OfflineAudioContext or not. /// Tells whether this is an OfflineAudioContext or not.

View file

@ -51,7 +51,7 @@ impl OfflineAudioContext {
length: u32, length: u32,
sample_rate: f32, sample_rate: f32,
pipeline_id: PipelineId, pipeline_id: PipelineId,
) -> OfflineAudioContext { ) -> Fallible<OfflineAudioContext> {
let options = ServoMediaOfflineAudioContextOptions { let options = ServoMediaOfflineAudioContextOptions {
channels: channel_count as u8, channels: channel_count as u8,
length: length as usize, length: length as usize,
@ -60,14 +60,14 @@ impl OfflineAudioContext {
let context = BaseAudioContext::new_inherited( let context = BaseAudioContext::new_inherited(
BaseAudioContextOptions::OfflineAudioContext(options), BaseAudioContextOptions::OfflineAudioContext(options),
pipeline_id, pipeline_id,
); )?;
OfflineAudioContext { Ok(OfflineAudioContext {
context, context,
channel_count, channel_count,
length, length,
rendering_started: Cell::new(false), rendering_started: Cell::new(false),
pending_rendering_promise: Default::default(), pending_rendering_promise: Default::default(),
} })
} }
#[allow(crown::unrooted_must_root)] #[allow(crown::unrooted_must_root)]
@ -87,7 +87,7 @@ impl OfflineAudioContext {
} }
let pipeline_id = window.pipeline_id(); let pipeline_id = window.pipeline_id();
let context = 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( Ok(reflect_dom_object_with_proto(
Box::new(context), Box::new(context),
window, window,

View file

@ -1,5 +1,4 @@
[audiocontextoptions.html] [audiocontextoptions.html]
expected: CRASH
[X context = new AudioContext({sampleRate: 1}) did not throw an exception.] [X context = new AudioContext({sampleRate: 1}) did not throw an exception.]
expected: FAIL expected: FAIL