Bug 881092 - Allow decoding files we know we can't play, in the context of WebAudio. r=kinetik,rillian

This commit is contained in:
Paul Adenot 2013-08-29 11:43:44 +02:00
parent 5c4387bb40
commit 220846b1f6
4 changed files with 28 additions and 6 deletions

View File

@ -382,7 +382,8 @@ void* MediaDecoderReader::VideoQueueMemoryFunctor::operator()(void* anObject) {
}
MediaDecoderReader::MediaDecoderReader(AbstractMediaDecoder* aDecoder)
: mDecoder(aDecoder)
: mDecoder(aDecoder),
mIgnoreAudioBackendFormat(false)
{
MOZ_COUNT_CTOR(MediaDecoderReader);
}

View File

@ -467,6 +467,14 @@ public:
// decode thread could start up and run in future.
virtual void OnDecodeThreadFinish() {}
// Tell the reader that the data decoded are not for direct playback, so it
// can accept more files, in particular those which have more channels than
// available in the audio output.
void SetIgnoreAudioOutputFormat()
{
mIgnoreAudioOutputFormat = true;
}
protected:
// Queue of audio frames. This queue is threadsafe, and is accessed from
// the audio, decoder, state machine, and main threads.
@ -543,6 +551,11 @@ protected:
// Stores presentation info required for playback.
VideoInfo mInfo;
// Whether we should accept media that we know we can't play
// directly, because they have a number of channel higher than
// what we support.
bool mIgnoreAudioOutputFormat;
};
} // namespace mozilla

View File

@ -61,7 +61,8 @@ static const uint16_t WAVE_FORMAT_CHUNK_SIZE = 16;
// supported by AudioStream.
static const uint16_t WAVE_FORMAT_ENCODING_PCM = 1;
// Maximum number of channels supported
// We reject files with more than this number of channels if we're decoding for
// playback.
static const uint8_t MAX_CHANNELS = 2;
namespace {
@ -430,11 +431,13 @@ WaveReader::LoadFormatChunk(uint32_t aChunkSize)
// Make sure metadata is fairly sane. The rate check is fairly arbitrary,
// but the channels check is intentionally limited to mono or stereo
// because that's what the audio backend currently supports.
// when the media is intended for direct playback because that's what the
// audio backend currently supports.
unsigned int actualFrameSize = sampleFormat == 8 ? 1 : 2 * channels;
if (rate < 100 || rate > 96000 ||
channels < 1 || channels > MAX_CHANNELS ||
(frameSize != 1 && frameSize != 2 && frameSize != 4) ||
(((channels < 1 || channels > MAX_CHANNELS) ||
(frameSize != 1 && frameSize != 2 && frameSize != 4)) &&
!mIgnoreAudioBackendFormat) ||
(sampleFormat != 8 && sampleFormat != 16) ||
frameSize != actualFrameSize) {
NS_WARNING("Invalid WAVE metadata");

View File

@ -508,6 +508,11 @@ MediaDecodeTask::Decode()
mBufferDecoder->BeginDecoding(NS_GetCurrentThread());
// Tell the decoder reader that we are not going to play the data directly,
// and that we should not reject files with more channels than the audio
// bakend support.
mDecoderReader->SetIgnoreAudioOutputFormat();
mDecoderReader->OnDecodeThreadStart();
VideoInfo videoInfo;