mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Auto merge of #23215 - ferjm:decoder.channels, r=jdm
Keep a map between channel position and channel index for decoded audio - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] There are WPTs for these changes. This should help fixing #22842 (along with https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/183). I couldn't reproduce it locally, so I cannot tell for sure. <!-- 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/23215) <!-- Reviewable:end -->
This commit is contained in:
commit
b20333a324
1 changed files with 12 additions and 1 deletions
|
@ -52,6 +52,7 @@ use servo_media::audio::decoder::AudioDecoderCallbacks;
|
||||||
use servo_media::audio::graph::NodeId;
|
use servo_media::audio::graph::NodeId;
|
||||||
use servo_media::ServoMedia;
|
use servo_media::ServoMedia;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
use std::collections::hash_map::Entry;
|
||||||
use std::collections::{HashMap, VecDeque};
|
use std::collections::{HashMap, VecDeque};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -432,6 +433,11 @@ impl BaseAudioContextMethods for BaseAudioContext {
|
||||||
let decoded_audio = Arc::new(Mutex::new(Vec::new()));
|
let decoded_audio = Arc::new(Mutex::new(Vec::new()));
|
||||||
let decoded_audio_ = decoded_audio.clone();
|
let decoded_audio_ = decoded_audio.clone();
|
||||||
let decoded_audio__ = decoded_audio.clone();
|
let decoded_audio__ = decoded_audio.clone();
|
||||||
|
// servo-media returns an audio channel position along
|
||||||
|
// with the AudioDecoderCallback progress callback, which
|
||||||
|
// may not be the same as the index of the decoded_audio
|
||||||
|
// Vec.
|
||||||
|
let channels = Arc::new(Mutex::new(HashMap::new()));
|
||||||
let this = Trusted::new(self);
|
let this = Trusted::new(self);
|
||||||
let this_ = this.clone();
|
let this_ = this.clone();
|
||||||
let (task_source, canceller) = window
|
let (task_source, canceller) = window
|
||||||
|
@ -447,8 +453,13 @@ impl BaseAudioContextMethods for BaseAudioContext {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.resize(channel_count as usize, Vec::new());
|
.resize(channel_count as usize, Vec::new());
|
||||||
})
|
})
|
||||||
.progress(move |buffer, channel| {
|
.progress(move |buffer, channel_pos| {
|
||||||
let mut decoded_audio = decoded_audio_.lock().unwrap();
|
let mut decoded_audio = decoded_audio_.lock().unwrap();
|
||||||
|
let mut channels = channels.lock().unwrap();
|
||||||
|
let channel = match channels.entry(channel_pos) {
|
||||||
|
Entry::Occupied(entry) => *entry.get(),
|
||||||
|
Entry::Vacant(entry) => *entry.insert(decoded_audio.len()),
|
||||||
|
};
|
||||||
decoded_audio[(channel - 1) as usize].extend_from_slice((*buffer).as_ref());
|
decoded_audio[(channel - 1) as usize].extend_from_slice((*buffer).as_ref());
|
||||||
})
|
})
|
||||||
.eos(move || {
|
.eos(move || {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue