mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
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:
parent
1ef3e107bd
commit
a24e92778a
5 changed files with 37 additions and 32 deletions
|
@ -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) {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue