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]]
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",

View file

@ -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<AudioContext> {
// 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<HandleObject>,
options: &AudioContextOptions,
) -> DomRoot<AudioContext> {
) -> Fallible<DomRoot<AudioContext>> {
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<HandleObject>,
options: &AudioContextOptions,
) -> Fallible<DomRoot<AudioContext>> {
Ok(AudioContext::new(window, proto, options))
AudioContext::new(window, proto, options)
}
fn resume(&self) {

View file

@ -116,7 +116,7 @@ impl BaseAudioContext {
pub fn new_inherited(
options: BaseAudioContextOptions,
pipeline_id: PipelineId,
) -> BaseAudioContext {
) -> Fallible<BaseAudioContext> {
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.

View file

@ -51,7 +51,7 @@ impl OfflineAudioContext {
length: u32,
sample_rate: f32,
pipeline_id: PipelineId,
) -> OfflineAudioContext {
) -> Fallible<OfflineAudioContext> {
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,

View file

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