mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Audio context options
This commit is contained in:
parent
ba9dfb0293
commit
db52d1f65c
2 changed files with 41 additions and 11 deletions
|
@ -2,10 +2,10 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::baseaudiocontext::BaseAudioContext;
|
use dom::baseaudiocontext::{BaseAudioContext, BaseAudioContextOptions};
|
||||||
use dom::bindings::codegen::Bindings::AudioContextBinding;
|
use dom::bindings::codegen::Bindings::AudioContextBinding;
|
||||||
use dom::bindings::codegen::Bindings::AudioContextBinding::AudioContextMethods;
|
use dom::bindings::codegen::Bindings::AudioContextBinding::{AudioContextMethods, AudioContextOptions};
|
||||||
use dom::bindings::codegen::Bindings::AudioContextBinding::{AudioContextOptions, AudioTimestamp};
|
use dom::bindings::codegen::Bindings::AudioContextBinding::{AudioContextLatencyCategory, AudioTimestamp};
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::inheritance::Castable;
|
use dom::bindings::inheritance::Castable;
|
||||||
use dom::bindings::num::Finite;
|
use dom::bindings::num::Finite;
|
||||||
|
@ -15,6 +15,7 @@ use dom::globalscope::GlobalScope;
|
||||||
use dom::promise::Promise;
|
use dom::promise::Promise;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
use servo_media::audio::graph::{LatencyCategory, RealTimeAudioGraphOptions};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
|
@ -25,9 +26,9 @@ pub struct AudioContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AudioContext {
|
impl AudioContext {
|
||||||
fn new_inherited(global: &GlobalScope, sample_rate: f32) -> AudioContext {
|
fn new_inherited(global: &GlobalScope, options: &AudioContextOptions) -> AudioContext {
|
||||||
AudioContext {
|
AudioContext {
|
||||||
context: BaseAudioContext::new_inherited(global, 2 /* channel_count */, sample_rate),
|
context: BaseAudioContext::new_inherited(global, BaseAudioContextOptions::AudioContext(options.into())),
|
||||||
base_latency: 0., // TODO
|
base_latency: 0., // TODO
|
||||||
output_latency: 0., // TODO
|
output_latency: 0., // TODO
|
||||||
}
|
}
|
||||||
|
@ -38,7 +39,7 @@ impl AudioContext {
|
||||||
options: &AudioContextOptions) -> DomRoot<AudioContext> {
|
options: &AudioContextOptions) -> DomRoot<AudioContext> {
|
||||||
let context = AudioContext::new_inherited(
|
let context = AudioContext::new_inherited(
|
||||||
global,
|
global,
|
||||||
*options.sampleRate.unwrap_or(Finite::wrap(0.)),
|
options,
|
||||||
); // TODO
|
); // TODO
|
||||||
reflect_dom_object(Box::new(context), global, AudioContextBinding::Wrap)
|
reflect_dom_object(Box::new(context), global, AudioContextBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
@ -79,3 +80,22 @@ impl AudioContextMethods for AudioContext {
|
||||||
Promise::new(&self.global())
|
Promise::new(&self.global())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<AudioContextLatencyCategory> for LatencyCategory {
|
||||||
|
fn from(category: AudioContextLatencyCategory) -> Self {
|
||||||
|
match category {
|
||||||
|
AudioContextLatencyCategory::Balanced => LatencyCategory::Balanced,
|
||||||
|
AudioContextLatencyCategory::Interactive => LatencyCategory::Interactive,
|
||||||
|
AudioContextLatencyCategory::Playback => LatencyCategory::Playback,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> From<&'a AudioContextOptions> for RealTimeAudioGraphOptions {
|
||||||
|
fn from(options: &AudioContextOptions) -> Self {
|
||||||
|
Self {
|
||||||
|
sample_rate: *options.sampleRate.unwrap_or(Finite::wrap(48000.)),
|
||||||
|
latency_hint: options.latencyHint.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -17,10 +17,16 @@ use dom::oscillatornode::OscillatorNode;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use servo_media::ServoMedia;
|
use servo_media::ServoMedia;
|
||||||
use servo_media::audio::graph::AudioGraph;
|
use servo_media::audio::graph::AudioGraph;
|
||||||
|
use servo_media::audio::graph::{OfflineAudioGraphOptions, RealTimeAudioGraphOptions};
|
||||||
use servo_media::audio::graph_impl::NodeId;
|
use servo_media::audio::graph_impl::NodeId;
|
||||||
use servo_media::audio::node::AudioNodeType;
|
use servo_media::audio::node::AudioNodeType;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
pub enum BaseAudioContextOptions {
|
||||||
|
AudioContext(RealTimeAudioGraphOptions),
|
||||||
|
OfflineAudioContext(OfflineAudioGraphOptions),
|
||||||
|
}
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct BaseAudioContext {
|
pub struct BaseAudioContext {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
|
@ -37,12 +43,16 @@ impl BaseAudioContext {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn new_inherited(
|
pub fn new_inherited(
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
channel_count: u32,
|
options: BaseAudioContextOptions,
|
||||||
sample_rate: f32,
|
|
||||||
) -> BaseAudioContext {
|
) -> BaseAudioContext {
|
||||||
|
let options = match options {
|
||||||
|
BaseAudioContextOptions::AudioContext(options) => options,
|
||||||
|
BaseAudioContextOptions::OfflineAudioContext(_) => unimplemented!(),
|
||||||
|
};
|
||||||
|
let sample_rate = options.sample_rate;
|
||||||
let mut context = BaseAudioContext {
|
let mut context = BaseAudioContext {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
audio_graph: ServoMedia::get().unwrap().create_audio_graph(),
|
audio_graph: ServoMedia::get().unwrap().create_audio_graph(Some(options.into())),
|
||||||
destination: None,
|
destination: None,
|
||||||
current_time: 0.,
|
current_time: 0.,
|
||||||
sample_rate,
|
sample_rate,
|
||||||
|
@ -50,7 +60,7 @@ impl BaseAudioContext {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut options = unsafe { AudioNodeOptions::empty(global.get_cx()) };
|
let mut options = unsafe { AudioNodeOptions::empty(global.get_cx()) };
|
||||||
options.channelCount = Some(channel_count);
|
options.channelCount = Some(2);
|
||||||
options.channelCountMode = Some(ChannelCountMode::Explicit);
|
options.channelCountMode = Some(ChannelCountMode::Explicit);
|
||||||
options.channelInterpretation = Some(ChannelInterpretation::Speakers);
|
options.channelInterpretation = Some(ChannelInterpretation::Speakers);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue