From de2f4e698270937251f0655c19555fb9099df55f Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Sun, 9 Aug 2015 20:05:40 -0400 Subject: VIDEO: Add support for MP3 in AVI --- video/avi_decoder.cpp | 65 ++++++++++++++++++++++++++++++++++----------------- video/avi_decoder.h | 6 +++-- 2 files changed, 48 insertions(+), 23 deletions(-) (limited to 'video') diff --git a/video/avi_decoder.cpp b/video/avi_decoder.cpp index 700975d9a2..aef5e763e9 100644 --- a/video/avi_decoder.cpp +++ b/video/avi_decoder.cpp @@ -31,6 +31,7 @@ // Audio Codecs #include "audio/decoders/adpcm.h" +#include "audio/decoders/mp3.h" #include "audio/decoders/raw.h" // Video Codecs @@ -841,15 +842,18 @@ void AVIDecoder::AVIVideoTrack::setDither(const byte *palette) { AVIDecoder::AVIAudioTrack::AVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType) : _audsHeader(streamHeader), _wvInfo(waveFormat), _soundType(soundType), _curChunk(0) { - _audStream = createAudioStream(); + createAudioStream(); } AVIDecoder::AVIAudioTrack::~AVIAudioTrack() { - delete _audStream; + delete _queueStream; + delete _packetStream; } void AVIDecoder::AVIAudioTrack::queueSound(Common::SeekableReadStream *stream) { - if (_audStream) { + if (_packetStream) { + _packetStream->queuePacket(stream); + } else if (_queueStream) { if (_wvInfo.tag == kWaveFormatPCM) { byte flags = 0; if (_audsHeader.sampleSize == 2) @@ -860,13 +864,13 @@ void AVIDecoder::AVIAudioTrack::queueSound(Common::SeekableReadStream *stream) { if (_wvInfo.channels == 2) flags |= Audio::FLAG_STEREO; - _audStream->queueAudioStream(Audio::makeRawStream(stream, _wvInfo.samplesPerSec, flags, DisposeAfterUse::YES), DisposeAfterUse::YES); + _queueStream->queueAudioStream(Audio::makeRawStream(stream, _wvInfo.samplesPerSec, flags, DisposeAfterUse::YES), DisposeAfterUse::YES); } else if (_wvInfo.tag == kWaveFormatMSADPCM) { - _audStream->queueAudioStream(Audio::makeADPCMStream(stream, DisposeAfterUse::YES, stream->size(), Audio::kADPCMMS, _wvInfo.samplesPerSec, _wvInfo.channels, _wvInfo.blockAlign), DisposeAfterUse::YES); + _queueStream->queueAudioStream(Audio::makeADPCMStream(stream, DisposeAfterUse::YES, stream->size(), Audio::kADPCMMS, _wvInfo.samplesPerSec, _wvInfo.channels, _wvInfo.blockAlign), DisposeAfterUse::YES); } else if (_wvInfo.tag == kWaveFormatMSIMAADPCM) { - _audStream->queueAudioStream(Audio::makeADPCMStream(stream, DisposeAfterUse::YES, stream->size(), Audio::kADPCMMSIma, _wvInfo.samplesPerSec, _wvInfo.channels, _wvInfo.blockAlign), DisposeAfterUse::YES); + _queueStream->queueAudioStream(Audio::makeADPCMStream(stream, DisposeAfterUse::YES, stream->size(), Audio::kADPCMMSIma, _wvInfo.samplesPerSec, _wvInfo.channels, _wvInfo.blockAlign), DisposeAfterUse::YES); } else if (_wvInfo.tag == kWaveFormatDK3) { - _audStream->queueAudioStream(Audio::makeADPCMStream(stream, DisposeAfterUse::YES, stream->size(), Audio::kADPCMDK3, _wvInfo.samplesPerSec, _wvInfo.channels, _wvInfo.blockAlign), DisposeAfterUse::YES); + _queueStream->queueAudioStream(Audio::makeADPCMStream(stream, DisposeAfterUse::YES, stream->size(), Audio::kADPCMDK3, _wvInfo.samplesPerSec, _wvInfo.channels, _wvInfo.blockAlign), DisposeAfterUse::YES); } } else { delete stream; @@ -882,17 +886,22 @@ void AVIDecoder::AVIAudioTrack::skipAudio(const Audio::Timestamp &time, const Au if (skipFrames <= 0) return; - if (_audStream->isStereo()) + Audio::AudioStream *audioStream = getAudioStream(); + if (!audioStream) + return; + + if (audioStream->isStereo()) skipFrames *= 2; int16 *tempBuffer = new int16[skipFrames]; - _audStream->readBuffer(tempBuffer, skipFrames); + audioStream->readBuffer(tempBuffer, skipFrames); delete[] tempBuffer; } void AVIDecoder::AVIAudioTrack::resetStream() { - delete _audStream; - _audStream = createAudioStream(); + delete _queueStream; + delete _packetStream; + createAudioStream(); _curChunk = 0; } @@ -902,18 +911,32 @@ bool AVIDecoder::AVIAudioTrack::rewind() { } Audio::AudioStream *AVIDecoder::AVIAudioTrack::getAudioStream() const { - return _audStream; -} - -Audio::QueuingAudioStream *AVIDecoder::AVIAudioTrack::createAudioStream() { - if (_wvInfo.tag == kWaveFormatPCM || _wvInfo.tag == kWaveFormatMSADPCM || _wvInfo.tag == kWaveFormatMSIMAADPCM || _wvInfo.tag == kWaveFormatDK3) - return Audio::makeQueuingAudioStream(_wvInfo.samplesPerSec, _wvInfo.channels == 2); - else if (_wvInfo.tag == kWaveFormatMP3) - warning("Unsupported AVI MP3 tracks"); - else if (_wvInfo.tag != kWaveFormatNone) // No sound + if (_packetStream) + return _packetStream; + + return _queueStream; +} + +void AVIDecoder::AVIAudioTrack::createAudioStream() { + _queueStream = 0; + _packetStream = 0; + + if (_wvInfo.tag == kWaveFormatPCM || _wvInfo.tag == kWaveFormatMSADPCM || _wvInfo.tag == kWaveFormatMSIMAADPCM || _wvInfo.tag == kWaveFormatDK3) { + // For now, a QueuingAudioStream will be created + } else if (_wvInfo.tag == kWaveFormatMP3) { + // MPEG audio +#ifdef USE_MAD + _packetStream = Audio::makePacketizedMP3Stream(_wvInfo.channels, _wvInfo.samplesPerSec); +#else + warning("AVI MP3 stream found, but no libmad support compiled in"); +#endif + } else if (_wvInfo.tag != kWaveFormatNone) { + // No supported format warning("Unsupported AVI audio format %d", _wvInfo.tag); + } - return 0; + if (!_packetStream) + _queueStream = Audio::makeQueuingAudioStream(_wvInfo.samplesPerSec, _wvInfo.channels == 2); } AVIDecoder::TrackStatus::TrackStatus() : track(0), chunkSearchOffset(0) { diff --git a/video/avi_decoder.h b/video/avi_decoder.h index 6c1ce1a4b9..8b12c23adf 100644 --- a/video/avi_decoder.h +++ b/video/avi_decoder.h @@ -32,6 +32,7 @@ #include "audio/mixer.h" namespace Audio { +class PacketizedAudioStream; class QueuingAudioStream; } @@ -241,8 +242,9 @@ protected: AVIStreamHeader _audsHeader; PCMWaveFormat _wvInfo; Audio::Mixer::SoundType _soundType; - Audio::QueuingAudioStream *_audStream; - Audio::QueuingAudioStream *createAudioStream(); + Audio::QueuingAudioStream *_queueStream; + Audio::PacketizedAudioStream *_packetStream; + void createAudioStream(); uint32 _curChunk; }; -- cgit v1.2.3