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
This commit is contained in:
bors-servo 2020-05-04 08:41:13 -04:00 committed by GitHub
commit ad212b23ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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(