diff options
author | bors-servo <servo-ops@mozilla.com> | 2020-05-04 08:41:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-04 08:41:13 -0400 |
commit | ad212b23ca73fea12ccd2ae995400b0fd9c028bc (patch) | |
tree | f7445bc667bf2d56dc81de5313d26a8a79b8ce84 /components/script/dom | |
parent | 0b05b5ed87df685c1a6118328d66e31650bac812 (diff) | |
parent | 492faa31053cc80cc428977c48bc821043191616 (diff) | |
download | servo-ad212b23ca73fea12ccd2ae995400b0fd9c028bc.tar.gz servo-ad212b23ca73fea12ccd2ae995400b0fd9c028bc.zip |
Auto merge of #26401 - khodzha:audio-decoder-channels-indices, r=ferjm
fixed BaseAudioContext.DecodeAudioData progress callback
Gstreamer backend returns channel as single bit mask (ie 1, 2, 4, 8, 32 etc).
Progress callback was using this mask as plain channel index, thus storing decoded
audio in wrong channel.
(log2 conversion of int to int is subpar at best, but idk how to extract bit position in a clean way without a loop, any suggestions are welcome)
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25840
- [X] There are tests for these changes
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/baseaudiocontext.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/components/script/dom/baseaudiocontext.rs b/components/script/dom/baseaudiocontext.rs index 14c6bc94e1c..42836dd61f0 100644 --- a/components/script/dom/baseaudiocontext.rs +++ b/components/script/dom/baseaudiocontext.rs @@ -481,14 +481,17 @@ impl BaseAudioContextMethods for BaseAudioContext { .unwrap() .resize(channel_count as usize, Vec::new()); }) - .progress(move |buffer, channel_pos| { + .progress(move |buffer, channel_pos_mask| { let mut decoded_audio = decoded_audio_.lock().unwrap(); let mut channels = channels.lock().unwrap(); - let channel = match channels.entry(channel_pos) { + let channel = match channels.entry(channel_pos_mask) { Entry::Occupied(entry) => *entry.get(), - Entry::Vacant(entry) => *entry.insert(decoded_audio.len()), + Entry::Vacant(entry) => { + let x = (channel_pos_mask as f32).log2() as usize; + *entry.insert(x) + }, }; - decoded_audio[(channel - 1) as usize].extend_from_slice((*buffer).as_ref()); + decoded_audio[channel].extend_from_slice((*buffer).as_ref()); }) .eos(move || { let _ = task_source.queue_with_canceller( |