mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #23997 - collares:audiobuffersourcenode, r=ferjm
Implement missing functionality of AudioBufferSourceNode <!-- Please describe your changes on the following line: --> This is a tiny PR to support [Media #293](https://github.com/servo/media/pull/293). Last time I ran WPT there was only one failing AudioBufferSourceNode test (which I will debug later this week). Once I rebased, however, I started getting unrelated servo-media build failures: ``` error[E0599]: no method named `shutdown_audio_context` found for type `std::sync::Arc<servo_media::ServoMedia>` in the current scope --> components/script/dom/baseaudiocontext.rs:566:14 error[E0599]: no method named `shutdown_player` found for type `std::sync::Arc<servo_media::ServoMedia>` in the current scope --> components/script/dom/htmlmediaelement.rs:1866:18 ``` I wanted to get this PR up so https://github.com/servo/media/pull/293 can be tested. When the unrelated build failures are fixed, I will run `./mach update-wpt` and update this PR. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` only reports unrelated errors (broken servo/media master?) - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #22363 <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23997) <!-- Reviewable:end -->
This commit is contained in:
commit
cacd4ed4e2
24 changed files with 67 additions and 474 deletions
|
@ -115,8 +115,11 @@ impl AudioBuffer {
|
|||
// Initialize the underlying channels data with initial data provided by
|
||||
// the user or silence otherwise.
|
||||
fn set_initial_data(&self, initial_data: Option<&[Vec<f32>]>) {
|
||||
let mut channels =
|
||||
ServoMediaAudioBuffer::new(self.number_of_channels as u8, self.length as usize);
|
||||
let mut channels = ServoMediaAudioBuffer::new(
|
||||
self.number_of_channels as u8,
|
||||
self.length as usize,
|
||||
self.sample_rate,
|
||||
);
|
||||
for channel in 0..self.number_of_channels {
|
||||
channels.buffers[channel as usize] = match initial_data {
|
||||
Some(data) => data[channel as usize].clone(),
|
||||
|
@ -164,8 +167,11 @@ impl AudioBuffer {
|
|||
// https://webaudio.github.io/web-audio-api/#acquire-the-content
|
||||
#[allow(unsafe_code)]
|
||||
fn acquire_contents(&self) -> Option<ServoMediaAudioBuffer> {
|
||||
let mut result =
|
||||
ServoMediaAudioBuffer::new(self.number_of_channels as u8, self.length as usize);
|
||||
let mut result = ServoMediaAudioBuffer::new(
|
||||
self.number_of_channels as u8,
|
||||
self.length as usize,
|
||||
self.sample_rate,
|
||||
);
|
||||
let cx = self.global().get_cx();
|
||||
for (i, channel) in self.js_channels.borrow_mut().iter().enumerate() {
|
||||
// Step 1.
|
||||
|
|
|
@ -171,6 +171,10 @@ impl AudioBufferSourceNodeMethods for AudioBufferSourceNode {
|
|||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loop
|
||||
fn SetLoop(&self, should_loop: bool) {
|
||||
self.loop_enabled.set(should_loop);
|
||||
let msg = AudioNodeMessage::AudioBufferSourceNode(
|
||||
AudioBufferSourceNodeMessage::SetLoopEnabled(should_loop),
|
||||
);
|
||||
self.source_node.node().message(msg);
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopstart
|
||||
|
@ -181,6 +185,10 @@ impl AudioBufferSourceNodeMethods for AudioBufferSourceNode {
|
|||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopstart
|
||||
fn SetLoopStart(&self, loop_start: Finite<f64>) {
|
||||
self.loop_start.set(*loop_start);
|
||||
let msg = AudioNodeMessage::AudioBufferSourceNode(
|
||||
AudioBufferSourceNodeMessage::SetLoopStart(*loop_start),
|
||||
);
|
||||
self.source_node.node().message(msg);
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopend
|
||||
|
@ -190,7 +198,11 @@ impl AudioBufferSourceNodeMethods for AudioBufferSourceNode {
|
|||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopend
|
||||
fn SetLoopEnd(&self, loop_end: Finite<f64>) {
|
||||
self.loop_end.set(*loop_end)
|
||||
self.loop_end.set(*loop_end);
|
||||
let msg = AudioNodeMessage::AudioBufferSourceNode(
|
||||
AudioBufferSourceNodeMessage::SetLoopEnd(*loop_end),
|
||||
);
|
||||
self.source_node.node().message(msg);
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-start
|
||||
|
@ -224,6 +236,17 @@ impl AudioBufferSourceNodeMethods for AudioBufferSourceNode {
|
|||
));
|
||||
}
|
||||
}
|
||||
|
||||
self.source_node
|
||||
.node()
|
||||
.message(AudioNodeMessage::AudioBufferSourceNode(
|
||||
AudioBufferSourceNodeMessage::SetStartParams(
|
||||
*when,
|
||||
offset.map(|f| *f),
|
||||
duration.map(|f| *f),
|
||||
),
|
||||
));
|
||||
|
||||
self.source_node
|
||||
.upcast::<AudioScheduledSourceNode>()
|
||||
.Start(when)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue