Bug 1865091 - When the channel count and channel map disagree in a WAVE file, disregard the channel map. r=azebrowski

Differential Revision: https://phabricator.services.mozilla.com/D193887
This commit is contained in:
Paul Adenot 2023-11-20 09:12:27 +00:00
parent a9cb8b07d4
commit bebe89a87e
4 changed files with 27 additions and 2 deletions

View file

@ -10,7 +10,6 @@
#include <algorithm>
#include "mozilla/Assertions.h"
#include "mozilla/EndianUtils.h"
#include "mozilla/Utf8.h"
#include "BufferReader.h"
#include "VideoUtils.h"
@ -166,6 +165,19 @@ bool WAVTrackDemuxer::Init() {
mInfo->mDuration = Duration();
mInfo->mChannelMap = mFmtChunk.ChannelMap();
if (AudioConfig::ChannelLayout::Channels(mInfo->mChannelMap) !=
mInfo->mChannels) {
AudioConfig::ChannelLayout::ChannelMap defaultForChannelCount =
AudioConfig::ChannelLayout(mInfo->mChannels).Map();
LOG(("Channel count of %" PRIu32
" and channel layout disagree, overriding channel map from %s to %s",
mInfo->mChannels,
AudioConfig::ChannelLayout::ChannelMapToString(mInfo->mChannelMap)
.get(),
AudioConfig::ChannelLayout::ChannelMapToString(defaultForChannelCount)
.get()));
mInfo->mChannelMap = defaultForChannelCount;
}
LOG(("WavDemuxer initialized: %s", mInfo->ToString().get()));
return mInfo->mDuration.IsPositive();
@ -270,6 +282,8 @@ bool WAVTrackDemuxer::ListChunkParserInit(uint32_t aChunkSize) {
case 0x494e414d: // INAM
mInfo->mTags.AppendElement(MetadataTag("name"_ns, val));
break;
default:
LOG(("Metadata key %08x not handled", id));
}
mHeaderParser.Reset();

View file

@ -78,6 +78,7 @@ support-files = [
"half-a-second-2ch-48000.wav",
"half-a-second-1ch-44100-aac-afconvert.mp4",
"waveformatextensible.wav",
"waveformatextensiblebadmask.wav",
"sixteen-frames.mp3", # only 16 frames of valid audio
"../../webrtc/tests/mochitests/mediaStreamPlayback.js",
"../../webrtc/tests/mochitests/head.js",

View file

@ -247,6 +247,16 @@
sampleRate: 44100,
frames: 472,
duration: 0.01
},
{
// A wav file that has 8 channel, but has a channel mask that doesn't
// match the channel count.
url: "waveformatextensiblebadmask.wav",
valid: true,
numberOfChannels: 8,
sampleRate: 8000,
frames: 80,
duration: 0.01
}
];
@ -290,7 +300,7 @@
is(buffer.numberOfChannels, test.numberOfChannels, "Correct number of channels");
return;
}
ok(Math.abs(buffer.duration - test.duration) < 1e-3, "Correct duration");
ok(Math.abs(buffer.duration - test.duration) < 1e-3, `Correct duration expected ${test.duration} got ${buffer.duration}`);
if (Math.abs(buffer.duration - test.duration) >= 1e-3) {
ok(false, "got: " + buffer.duration + ", expected: " + test.duration);
}