Make OfflineAudioContextOptions spec compliant

This commit is contained in:
Fernando Jiménez Moreno 2018-07-30 18:50:36 +02:00
parent 19e4c627a3
commit 3b8cb83e04
2 changed files with 21 additions and 25 deletions

View file

@ -41,22 +41,32 @@ pub struct OfflineAudioContext {
impl OfflineAudioContext { impl OfflineAudioContext {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
fn new_inherited(options: &OfflineAudioContextOptions) -> OfflineAudioContext { fn new_inherited(channel_count: u32,
length: u32,
sample_rate: f32) -> OfflineAudioContext {
let options = ServoMediaOfflineAudioContextOptions {
channels: channel_count as u8,
length: length as usize,
sample_rate,
};
let context = BaseAudioContext::new_inherited( let context = BaseAudioContext::new_inherited(
BaseAudioContextOptions::OfflineAudioContext(options.into()), BaseAudioContextOptions::OfflineAudioContext(options),
); );
OfflineAudioContext { OfflineAudioContext {
context, context,
channel_count: options.numberOfChannels, channel_count,
length: options.length, length,
rendering_started: Cell::new(false), rendering_started: Cell::new(false),
pending_rendering_promise: Default::default(), pending_rendering_promise: Default::default(),
} }
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
fn new(window: &Window, options: &OfflineAudioContextOptions) -> DomRoot<OfflineAudioContext> { fn new(window: &Window,
let context = OfflineAudioContext::new_inherited(options); channel_count: u32,
length: u32,
sample_rate: f32) -> DomRoot<OfflineAudioContext> {
let context = OfflineAudioContext::new_inherited(channel_count, length, sample_rate);
reflect_dom_object(Box::new(context), window, OfflineAudioContextBinding::Wrap) reflect_dom_object(Box::new(context), window, OfflineAudioContextBinding::Wrap)
} }
@ -64,7 +74,7 @@ impl OfflineAudioContext {
window: &Window, window: &Window,
options: &OfflineAudioContextOptions, options: &OfflineAudioContextOptions,
) -> Fallible<DomRoot<OfflineAudioContext>> { ) -> Fallible<DomRoot<OfflineAudioContext>> {
Ok(OfflineAudioContext::new(window, options)) Ok(OfflineAudioContext::new(window, options.numberOfChannels, options.length, *options.sampleRate))
} }
pub fn Constructor_( pub fn Constructor_(
@ -82,11 +92,7 @@ impl OfflineAudioContext {
return Err(Error::NotSupported); return Err(Error::NotSupported);
} }
let mut options = OfflineAudioContextOptions::empty(); Ok(OfflineAudioContext::new(window, number_of_channels, length, *sample_rate))
options.numberOfChannels = number_of_channels;
options.length = length;
options.sampleRate = sample_rate;
Ok(OfflineAudioContext::new(window, &options))
} }
} }
@ -166,13 +172,3 @@ impl OfflineAudioContextMethods for OfflineAudioContext {
promise promise
} }
} }
impl<'a> From<&'a OfflineAudioContextOptions> for ServoMediaOfflineAudioContextOptions {
fn from(options: &OfflineAudioContextOptions) -> Self {
Self {
channels: options.numberOfChannels as u8,
length: options.length as usize,
sample_rate: *options.sampleRate,
}
}
}

View file

@ -8,12 +8,12 @@
dictionary OfflineAudioContextOptions { dictionary OfflineAudioContextOptions {
unsigned long numberOfChannels = 1; unsigned long numberOfChannels = 1;
unsigned long length = 0; required unsigned long length;
float sampleRate = 48000.; required float sampleRate;
}; };
[Exposed=Window, [Exposed=Window,
Constructor (optional OfflineAudioContextOptions contextOptions), Constructor (OfflineAudioContextOptions contextOptions),
Constructor (unsigned long numberOfChannels, unsigned long length, float sampleRate)] Constructor (unsigned long numberOfChannels, unsigned long length, float sampleRate)]
interface OfflineAudioContext : BaseAudioContext { interface OfflineAudioContext : BaseAudioContext {
readonly attribute unsigned long length; readonly attribute unsigned long length;