2009-10-16 18:05:56 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/stream.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/textconsole.h"
|
2009-10-16 18:05:56 +00:00
|
|
|
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/audiostream.h"
|
|
|
|
#include "audio/mixer.h"
|
2009-10-16 18:05:56 +00:00
|
|
|
|
2011-01-23 17:37:17 +00:00
|
|
|
#include "video/avi_decoder.h"
|
2009-10-16 18:05:56 +00:00
|
|
|
|
2010-11-11 13:23:26 +00:00
|
|
|
// Audio Codecs
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/decoders/adpcm.h"
|
|
|
|
#include "audio/decoders/raw.h"
|
2010-11-11 13:23:26 +00:00
|
|
|
|
|
|
|
// Video Codecs
|
2011-01-23 17:37:17 +00:00
|
|
|
#include "video/codecs/cinepak.h"
|
|
|
|
#include "video/codecs/indeo3.h"
|
|
|
|
#include "video/codecs/msvideo1.h"
|
|
|
|
#include "video/codecs/msrle.h"
|
|
|
|
#include "video/codecs/truemotion1.h"
|
2009-10-16 18:05:56 +00:00
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
namespace Video {
|
2009-10-16 18:05:56 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
#define UNKNOWN_HEADER(a) error("Unknown header found -- \'%s\'", tag2str(a))
|
|
|
|
|
|
|
|
// IDs used throughout the AVI files
|
|
|
|
// that will be handled by this player
|
|
|
|
#define ID_RIFF MKTAG('R','I','F','F')
|
|
|
|
#define ID_AVI MKTAG('A','V','I',' ')
|
|
|
|
#define ID_LIST MKTAG('L','I','S','T')
|
|
|
|
#define ID_HDRL MKTAG('h','d','r','l')
|
|
|
|
#define ID_AVIH MKTAG('a','v','i','h')
|
|
|
|
#define ID_STRL MKTAG('s','t','r','l')
|
|
|
|
#define ID_STRH MKTAG('s','t','r','h')
|
|
|
|
#define ID_VIDS MKTAG('v','i','d','s')
|
|
|
|
#define ID_AUDS MKTAG('a','u','d','s')
|
|
|
|
#define ID_MIDS MKTAG('m','i','d','s')
|
|
|
|
#define ID_TXTS MKTAG('t','x','t','s')
|
|
|
|
#define ID_JUNK MKTAG('J','U','N','K')
|
|
|
|
#define ID_STRF MKTAG('s','t','r','f')
|
|
|
|
#define ID_MOVI MKTAG('m','o','v','i')
|
|
|
|
#define ID_REC MKTAG('r','e','c',' ')
|
|
|
|
#define ID_VEDT MKTAG('v','e','d','t')
|
|
|
|
#define ID_IDX1 MKTAG('i','d','x','1')
|
|
|
|
#define ID_STRD MKTAG('s','t','r','d')
|
|
|
|
#define ID_00AM MKTAG('0','0','A','M')
|
|
|
|
//#define ID_INFO MKTAG('I','N','F','O')
|
|
|
|
|
|
|
|
// Codec tags
|
|
|
|
#define ID_RLE MKTAG('R','L','E',' ')
|
|
|
|
#define ID_CRAM MKTAG('C','R','A','M')
|
|
|
|
#define ID_MSVC MKTAG('m','s','v','c')
|
|
|
|
#define ID_WHAM MKTAG('W','H','A','M')
|
|
|
|
#define ID_CVID MKTAG('c','v','i','d')
|
|
|
|
#define ID_IV32 MKTAG('i','v','3','2')
|
|
|
|
#define ID_DUCK MKTAG('D','U','C','K')
|
|
|
|
|
2010-10-10 22:25:52 +00:00
|
|
|
static byte char2num(char c) {
|
2012-07-22 18:13:20 +00:00
|
|
|
c = tolower((byte)c);
|
|
|
|
return (c >= 'a' && c <= 'f') ? c - 'a' + 10 : c - '0';
|
2010-10-10 22:25:52 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
static byte getStreamIndex(uint32 tag) {
|
|
|
|
return char2num((tag >> 24) & 0xFF) << 4 | char2num((tag >> 16) & 0xFF);
|
2010-10-10 22:25:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint16 getStreamType(uint32 tag) {
|
|
|
|
return tag & 0xffff;
|
|
|
|
}
|
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
AVIDecoder::AVIDecoder(Audio::Mixer::SoundType soundType) : _soundType(soundType) {
|
2009-10-16 18:05:56 +00:00
|
|
|
_decodedHeader = false;
|
2012-07-22 18:13:20 +00:00
|
|
|
_fileStream = 0;
|
|
|
|
memset(&_ixInfo, 0, sizeof(_ixInfo));
|
|
|
|
memset(&_header, 0, sizeof(_header));
|
2009-10-16 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
AVIDecoder::~AVIDecoder() {
|
2010-05-18 14:17:24 +00:00
|
|
|
close();
|
2009-10-16 18:05:56 +00:00
|
|
|
}
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
void AVIDecoder::runHandle(uint32 tag) {
|
|
|
|
assert(_fileStream);
|
2009-10-16 18:05:56 +00:00
|
|
|
if (_fileStream->eos())
|
|
|
|
return;
|
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
debug(3, "Decoding tag %s", tag2str(tag));
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-10-16 18:05:56 +00:00
|
|
|
switch (tag) {
|
2012-07-22 18:13:20 +00:00
|
|
|
case ID_RIFF:
|
|
|
|
/*_filesize = */_fileStream->readUint32LE();
|
|
|
|
if (_fileStream->readUint32BE() != ID_AVI)
|
|
|
|
error("RIFF file is not an AVI video");
|
|
|
|
break;
|
|
|
|
case ID_LIST:
|
|
|
|
handleList();
|
|
|
|
break;
|
|
|
|
case ID_AVIH:
|
|
|
|
_header.size = _fileStream->readUint32LE();
|
|
|
|
_header.microSecondsPerFrame = _fileStream->readUint32LE();
|
|
|
|
_header.maxBytesPerSecond = _fileStream->readUint32LE();
|
|
|
|
_header.padding = _fileStream->readUint32LE();
|
|
|
|
_header.flags = _fileStream->readUint32LE();
|
|
|
|
_header.totalFrames = _fileStream->readUint32LE();
|
|
|
|
_header.initialFrames = _fileStream->readUint32LE();
|
|
|
|
_header.streams = _fileStream->readUint32LE();
|
|
|
|
_header.bufferSize = _fileStream->readUint32LE();
|
|
|
|
_header.width = _fileStream->readUint32LE();
|
|
|
|
_header.height = _fileStream->readUint32LE();
|
|
|
|
// Ignore 16 bytes of reserved data
|
|
|
|
_fileStream->skip(16);
|
|
|
|
break;
|
|
|
|
case ID_STRH:
|
|
|
|
handleStreamHeader();
|
|
|
|
break;
|
|
|
|
case ID_STRD: // Extra stream info, safe to ignore
|
|
|
|
case ID_VEDT: // Unknown, safe to ignore
|
|
|
|
case ID_JUNK: // Alignment bytes, should be ignored
|
|
|
|
{
|
|
|
|
uint32 junkSize = _fileStream->readUint32LE();
|
|
|
|
_fileStream->skip(junkSize + (junkSize & 1)); // Alignment
|
|
|
|
} break;
|
|
|
|
case ID_IDX1:
|
|
|
|
_ixInfo.size = _fileStream->readUint32LE();
|
|
|
|
_ixInfo.indices = new OldIndex::Index[_ixInfo.size / 16];
|
|
|
|
debug(0, "%d Indices", (_ixInfo.size / 16));
|
|
|
|
for (uint32 i = 0; i < (_ixInfo.size / 16); i++) {
|
|
|
|
_ixInfo.indices[i].id = _fileStream->readUint32BE();
|
|
|
|
_ixInfo.indices[i].flags = _fileStream->readUint32LE();
|
|
|
|
_ixInfo.indices[i].offset = _fileStream->readUint32LE();
|
|
|
|
_ixInfo.indices[i].size = _fileStream->readUint32LE();
|
|
|
|
debug(0, "Index %d == Tag \'%s\', Offset = %d, Size = %d", i, tag2str(_ixInfo.indices[i].id), _ixInfo.indices[i].offset, _ixInfo.indices[i].size);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Unknown tag \'%s\' found", tag2str(tag));
|
2009-10-16 18:05:56 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
void AVIDecoder::handleList() {
|
2009-10-16 18:05:56 +00:00
|
|
|
uint32 listSize = _fileStream->readUint32LE() - 4; // Subtract away listType's 4 bytes
|
|
|
|
uint32 listType = _fileStream->readUint32BE();
|
|
|
|
uint32 curPos = _fileStream->pos();
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
debug(0, "Found LIST of type %s", tag2str(listType));
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-10-16 18:05:56 +00:00
|
|
|
while ((_fileStream->pos() - curPos) < listSize)
|
|
|
|
runHandle(_fileStream->readUint32BE());
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-10-16 18:05:56 +00:00
|
|
|
// We now have all the header data
|
|
|
|
if (listType == ID_HDRL)
|
|
|
|
_decodedHeader = true;
|
|
|
|
}
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
void AVIDecoder::handleStreamHeader() {
|
2010-01-25 01:39:44 +00:00
|
|
|
AVIStreamHeader sHeader;
|
2009-10-16 18:05:56 +00:00
|
|
|
sHeader.size = _fileStream->readUint32LE();
|
|
|
|
sHeader.streamType = _fileStream->readUint32BE();
|
2012-07-22 18:13:20 +00:00
|
|
|
|
2009-10-16 18:05:56 +00:00
|
|
|
if (sHeader.streamType == ID_MIDS || sHeader.streamType == ID_TXTS)
|
2012-07-22 18:13:20 +00:00
|
|
|
error("Unhandled MIDI/Text stream");
|
|
|
|
|
2009-10-16 18:05:56 +00:00
|
|
|
sHeader.streamHandler = _fileStream->readUint32BE();
|
|
|
|
sHeader.flags = _fileStream->readUint32LE();
|
|
|
|
sHeader.priority = _fileStream->readUint16LE();
|
|
|
|
sHeader.language = _fileStream->readUint16LE();
|
|
|
|
sHeader.initialFrames = _fileStream->readUint32LE();
|
|
|
|
sHeader.scale = _fileStream->readUint32LE();
|
|
|
|
sHeader.rate = _fileStream->readUint32LE();
|
|
|
|
sHeader.start = _fileStream->readUint32LE();
|
|
|
|
sHeader.length = _fileStream->readUint32LE();
|
|
|
|
sHeader.bufferSize = _fileStream->readUint32LE();
|
|
|
|
sHeader.quality = _fileStream->readUint32LE();
|
|
|
|
sHeader.sampleSize = _fileStream->readUint32LE();
|
2010-05-27 23:57:44 +00:00
|
|
|
|
|
|
|
_fileStream->skip(sHeader.size - 48); // Skip over the remainder of the chunk (frame)
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-10-16 18:05:56 +00:00
|
|
|
if (_fileStream->readUint32BE() != ID_STRF)
|
|
|
|
error("Could not find STRF tag");
|
2012-07-22 18:13:20 +00:00
|
|
|
|
2010-11-11 04:53:52 +00:00
|
|
|
uint32 strfSize = _fileStream->readUint32LE();
|
|
|
|
uint32 startPos = _fileStream->pos();
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-10-16 18:05:56 +00:00
|
|
|
if (sHeader.streamType == ID_VIDS) {
|
2012-07-22 18:13:20 +00:00
|
|
|
BitmapInfoHeader bmInfo;
|
|
|
|
bmInfo.size = _fileStream->readUint32LE();
|
|
|
|
bmInfo.width = _fileStream->readUint32LE();
|
|
|
|
bmInfo.height = _fileStream->readUint32LE();
|
|
|
|
bmInfo.planes = _fileStream->readUint16LE();
|
|
|
|
bmInfo.bitCount = _fileStream->readUint16LE();
|
|
|
|
bmInfo.compression = _fileStream->readUint32BE();
|
|
|
|
bmInfo.sizeImage = _fileStream->readUint32LE();
|
|
|
|
bmInfo.xPelsPerMeter = _fileStream->readUint32LE();
|
|
|
|
bmInfo.yPelsPerMeter = _fileStream->readUint32LE();
|
|
|
|
bmInfo.clrUsed = _fileStream->readUint32LE();
|
|
|
|
bmInfo.clrImportant = _fileStream->readUint32LE();
|
|
|
|
|
|
|
|
if (bmInfo.clrUsed == 0)
|
|
|
|
bmInfo.clrUsed = 256;
|
|
|
|
|
|
|
|
if (sHeader.streamHandler == 0)
|
|
|
|
sHeader.streamHandler = bmInfo.compression;
|
|
|
|
|
|
|
|
AVIVideoTrack *track = new AVIVideoTrack(_header.totalFrames, sHeader, bmInfo);
|
|
|
|
|
|
|
|
if (bmInfo.bitCount == 8) {
|
|
|
|
byte *palette = const_cast<byte *>(track->getPalette());
|
|
|
|
for (uint32 i = 0; i < bmInfo.clrUsed; i++) {
|
|
|
|
palette[i * 3 + 2] = _fileStream->readByte();
|
|
|
|
palette[i * 3 + 1] = _fileStream->readByte();
|
|
|
|
palette[i * 3] = _fileStream->readByte();
|
2010-05-27 23:57:44 +00:00
|
|
|
_fileStream->readByte();
|
2009-10-16 18:05:56 +00:00
|
|
|
}
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
track->markPaletteDirty();
|
2009-10-16 18:05:56 +00:00
|
|
|
}
|
2010-05-27 23:57:44 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
addTrack(track);
|
2009-10-16 18:05:56 +00:00
|
|
|
} else if (sHeader.streamType == ID_AUDS) {
|
2012-07-22 18:13:20 +00:00
|
|
|
PCMWaveFormat wvInfo;
|
|
|
|
wvInfo.tag = _fileStream->readUint16LE();
|
|
|
|
wvInfo.channels = _fileStream->readUint16LE();
|
|
|
|
wvInfo.samplesPerSec = _fileStream->readUint32LE();
|
|
|
|
wvInfo.avgBytesPerSec = _fileStream->readUint32LE();
|
|
|
|
wvInfo.blockAlign = _fileStream->readUint16LE();
|
|
|
|
wvInfo.size = _fileStream->readUint16LE();
|
2010-05-27 23:57:44 +00:00
|
|
|
|
|
|
|
// AVI seems to treat the sampleSize as including the second
|
|
|
|
// channel as well, so divide for our sake.
|
2012-07-22 18:13:20 +00:00
|
|
|
if (wvInfo.channels == 2)
|
|
|
|
sHeader.sampleSize /= 2;
|
|
|
|
|
|
|
|
addTrack(new AVIAudioTrack(sHeader, wvInfo, _soundType));
|
2009-10-16 18:05:56 +00:00
|
|
|
}
|
2010-11-11 04:53:52 +00:00
|
|
|
|
|
|
|
// Ensure that we're at the end of the chunk
|
|
|
|
_fileStream->seek(startPos + strfSize);
|
2009-10-16 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
bool AVIDecoder::loadStream(Common::SeekableReadStream *stream) {
|
2010-05-18 14:17:24 +00:00
|
|
|
close();
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2010-08-04 08:25:05 +00:00
|
|
|
_fileStream = stream;
|
2009-10-16 18:05:56 +00:00
|
|
|
_decodedHeader = false;
|
|
|
|
|
|
|
|
// Read chunks until we have decoded the header
|
|
|
|
while (!_decodedHeader)
|
|
|
|
runHandle(_fileStream->readUint32BE());
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-10-16 18:05:56 +00:00
|
|
|
uint32 nextTag = _fileStream->readUint32BE();
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-10-16 18:05:56 +00:00
|
|
|
// Throw out any JUNK section
|
|
|
|
if (nextTag == ID_JUNK) {
|
|
|
|
runHandle(ID_JUNK);
|
|
|
|
nextTag = _fileStream->readUint32BE();
|
|
|
|
}
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-10-16 18:05:56 +00:00
|
|
|
// Ignore the 'movi' LIST
|
|
|
|
if (nextTag == ID_LIST) {
|
|
|
|
_fileStream->readUint32BE(); // Skip size
|
|
|
|
if (_fileStream->readUint32BE() != ID_MOVI)
|
2012-07-22 18:13:20 +00:00
|
|
|
error("Expected 'movi' LIST");
|
|
|
|
} else {
|
|
|
|
error("Expected 'movi' LIST");
|
|
|
|
}
|
2009-11-27 18:25:40 +00:00
|
|
|
|
2009-10-16 18:05:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
void AVIDecoder::close() {
|
2012-08-16 18:00:14 +00:00
|
|
|
VideoDecoder::close();
|
2009-10-16 18:05:56 +00:00
|
|
|
|
|
|
|
delete _fileStream;
|
|
|
|
_fileStream = 0;
|
|
|
|
_decodedHeader = false;
|
2009-11-30 01:58:15 +00:00
|
|
|
|
2009-10-16 18:05:56 +00:00
|
|
|
delete[] _ixInfo.indices;
|
2012-07-22 18:13:20 +00:00
|
|
|
memset(&_ixInfo, 0, sizeof(_ixInfo));
|
|
|
|
memset(&_header, 0, sizeof(_header));
|
2010-05-18 14:17:24 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
void AVIDecoder::readNextPacket() {
|
2009-10-16 18:05:56 +00:00
|
|
|
uint32 nextTag = _fileStream->readUint32BE();
|
2009-11-27 18:25:40 +00:00
|
|
|
|
|
|
|
if (_fileStream->eos())
|
2012-07-22 18:13:20 +00:00
|
|
|
return;
|
2010-05-18 14:17:24 +00:00
|
|
|
|
2009-10-16 18:05:56 +00:00
|
|
|
if (nextTag == ID_LIST) {
|
|
|
|
// A list of audio/video chunks
|
|
|
|
uint32 listSize = _fileStream->readUint32LE() - 4;
|
|
|
|
int32 startPos = _fileStream->pos();
|
|
|
|
|
|
|
|
if (_fileStream->readUint32BE() != ID_REC)
|
2012-07-22 18:13:20 +00:00
|
|
|
error("Expected 'rec ' LIST");
|
2009-10-16 18:05:56 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
// Decode chunks in the list
|
|
|
|
while (_fileStream->pos() < startPos + (int32)listSize)
|
|
|
|
readNextPacket();
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
return;
|
|
|
|
} else if (nextTag == ID_JUNK || nextTag == ID_IDX1) {
|
|
|
|
runHandle(nextTag);
|
|
|
|
return;
|
|
|
|
}
|
2009-10-16 18:05:56 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
Track *track = getTrack(getStreamIndex(nextTag));
|
2009-10-16 18:05:56 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
if (!track)
|
|
|
|
error("Cannot get track from tag '%s'", tag2str(nextTag));
|
2009-10-16 18:05:56 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
uint32 chunkSize = _fileStream->readUint32LE();
|
2012-08-27 15:09:38 +00:00
|
|
|
Common::SeekableReadStream *chunk = 0;
|
|
|
|
|
|
|
|
if (chunkSize != 0) {
|
|
|
|
chunk = _fileStream->readStream(chunkSize);
|
|
|
|
_fileStream->skip(chunkSize & 1);
|
|
|
|
}
|
2012-07-22 18:13:20 +00:00
|
|
|
|
|
|
|
if (track->getTrackType() == Track::kTrackTypeAudio) {
|
2012-08-26 16:38:35 +00:00
|
|
|
if (getStreamType(nextTag) != MKTAG16('w', 'b'))
|
2012-07-22 18:13:20 +00:00
|
|
|
error("Invalid audio track tag '%s'", tag2str(nextTag));
|
|
|
|
|
2012-08-27 15:09:38 +00:00
|
|
|
assert(chunk);
|
2012-07-22 18:13:20 +00:00
|
|
|
((AVIAudioTrack *)track)->queueSound(chunk);
|
|
|
|
} else {
|
|
|
|
AVIVideoTrack *videoTrack = (AVIVideoTrack *)track;
|
|
|
|
|
2012-08-26 16:38:35 +00:00
|
|
|
if (getStreamType(nextTag) == MKTAG16('p', 'c')) {
|
2012-07-22 18:13:20 +00:00
|
|
|
// Palette Change
|
2012-08-27 15:09:38 +00:00
|
|
|
assert(chunk);
|
2012-07-22 18:13:20 +00:00
|
|
|
byte firstEntry = chunk->readByte();
|
|
|
|
uint16 numEntries = chunk->readByte();
|
|
|
|
chunk->readUint16LE(); // Reserved
|
|
|
|
|
|
|
|
// 0 entries means all colors are going to be changed
|
|
|
|
if (numEntries == 0)
|
|
|
|
numEntries = 256;
|
|
|
|
|
|
|
|
byte *palette = const_cast<byte *>(videoTrack->getPalette());
|
|
|
|
|
|
|
|
for (uint16 i = firstEntry; i < numEntries + firstEntry; i++) {
|
|
|
|
palette[i * 3] = chunk->readByte();
|
|
|
|
palette[i * 3 + 1] = chunk->readByte();
|
|
|
|
palette[i * 3 + 2] = chunk->readByte();
|
|
|
|
chunk->readByte(); // Flags that don't serve us any purpose
|
|
|
|
}
|
|
|
|
|
|
|
|
delete chunk;
|
|
|
|
videoTrack->markPaletteDirty();
|
2012-08-26 16:38:35 +00:00
|
|
|
} else if (getStreamType(nextTag) == MKTAG16('d', 'b')) {
|
2012-07-22 18:13:20 +00:00
|
|
|
// TODO: Check if this really is uncompressed. Many videos
|
|
|
|
// falsely put compressed data in here.
|
|
|
|
error("Uncompressed AVI frame found");
|
|
|
|
} else {
|
|
|
|
// Otherwise, assume it's a compressed frame
|
|
|
|
videoTrack->decodeFrame(chunk);
|
|
|
|
}
|
2009-10-16 18:05:56 +00:00
|
|
|
}
|
2012-07-22 18:13:20 +00:00
|
|
|
}
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2012-09-26 02:17:31 +00:00
|
|
|
AVIDecoder::AVIVideoTrack::AVIVideoTrack(int frameCount, const AVIStreamHeader &streamHeader, const BitmapInfoHeader &bitmapInfoHeader)
|
2012-07-22 18:13:20 +00:00
|
|
|
: _frameCount(frameCount), _vidsHeader(streamHeader), _bmInfo(bitmapInfoHeader) {
|
|
|
|
memset(_palette, 0, sizeof(_palette));
|
|
|
|
_videoCodec = createCodec();
|
|
|
|
_dirtyPalette = false;
|
|
|
|
_lastFrame = 0;
|
|
|
|
_curFrame = -1;
|
2009-10-16 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
AVIDecoder::AVIVideoTrack::~AVIVideoTrack() {
|
|
|
|
delete _videoCodec;
|
2010-05-18 14:17:24 +00:00
|
|
|
}
|
2009-12-06 04:38:20 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
void AVIDecoder::AVIVideoTrack::decodeFrame(Common::SeekableReadStream *stream) {
|
2012-08-27 15:09:38 +00:00
|
|
|
if (stream) {
|
|
|
|
if (_videoCodec)
|
|
|
|
_lastFrame = _videoCodec->decodeImage(stream);
|
|
|
|
} else {
|
|
|
|
// Empty frame
|
|
|
|
_lastFrame = 0;
|
|
|
|
}
|
2009-10-16 18:05:56 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
delete stream;
|
|
|
|
_curFrame++;
|
2009-10-16 18:05:56 +00:00
|
|
|
}
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
Graphics::PixelFormat AVIDecoder::AVIVideoTrack::getPixelFormat() const {
|
|
|
|
if (_videoCodec)
|
|
|
|
return _videoCodec->getPixelFormat();
|
|
|
|
|
|
|
|
return Graphics::PixelFormat();
|
|
|
|
}
|
|
|
|
|
|
|
|
Codec *AVIDecoder::AVIVideoTrack::createCodec() {
|
|
|
|
switch (_vidsHeader.streamHandler) {
|
|
|
|
case ID_CRAM:
|
|
|
|
case ID_MSVC:
|
|
|
|
case ID_WHAM:
|
|
|
|
return new MSVideo1Decoder(_bmInfo.width, _bmInfo.height, _bmInfo.bitCount);
|
|
|
|
case ID_RLE:
|
|
|
|
return new MSRLEDecoder(_bmInfo.width, _bmInfo.height, _bmInfo.bitCount);
|
|
|
|
case ID_CVID:
|
|
|
|
return new CinepakDecoder(_bmInfo.bitCount);
|
|
|
|
case ID_IV32:
|
|
|
|
return new Indeo3Decoder(_bmInfo.width, _bmInfo.height);
|
|
|
|
#ifdef VIDEO_CODECS_TRUEMOTION1_H
|
|
|
|
case ID_DUCK:
|
|
|
|
return new TrueMotion1Decoder(_bmInfo.width, _bmInfo.height);
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
warning("Unknown/Unhandled compression format \'%s\'", tag2str(_vidsHeader.streamHandler));
|
2010-11-11 13:23:26 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-11-11 13:23:26 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
AVIDecoder::AVIAudioTrack::AVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType)
|
|
|
|
: _audsHeader(streamHeader), _wvInfo(waveFormat), _soundType(soundType) {
|
|
|
|
_audStream = createAudioStream();
|
|
|
|
}
|
2010-11-11 13:23:26 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
AVIDecoder::AVIAudioTrack::~AVIAudioTrack() {
|
|
|
|
delete _audStream;
|
|
|
|
}
|
2010-11-11 13:23:26 +00:00
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
void AVIDecoder::AVIAudioTrack::queueSound(Common::SeekableReadStream *stream) {
|
|
|
|
if (_audStream) {
|
|
|
|
if (_wvInfo.tag == kWaveFormatPCM) {
|
|
|
|
byte flags = 0;
|
|
|
|
if (_audsHeader.sampleSize == 2)
|
|
|
|
flags |= Audio::FLAG_16BITS | Audio::FLAG_LITTLE_ENDIAN;
|
|
|
|
else
|
|
|
|
flags |= Audio::FLAG_UNSIGNED;
|
|
|
|
|
|
|
|
if (_wvInfo.channels == 2)
|
|
|
|
flags |= Audio::FLAG_STEREO;
|
|
|
|
|
|
|
|
_audStream->queueAudioStream(Audio::makeRawStream(stream, _wvInfo.samplesPerSec, flags, DisposeAfterUse::YES), 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);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
delete stream;
|
2010-11-11 13:23:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
Audio::AudioStream *AVIDecoder::AVIAudioTrack::getAudioStream() const {
|
|
|
|
return _audStream;
|
2012-05-28 01:18:32 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
Audio::QueuingAudioStream *AVIDecoder::AVIAudioTrack::createAudioStream() {
|
|
|
|
if (_wvInfo.tag == kWaveFormatPCM || _wvInfo.tag == kWaveFormatDK3)
|
|
|
|
return Audio::makeQueuingAudioStream(_wvInfo.samplesPerSec, _wvInfo.channels == 2);
|
|
|
|
else if (_wvInfo.tag != kWaveFormatNone) // No sound
|
|
|
|
warning("Unsupported AVI audio format %d", _wvInfo.tag);
|
|
|
|
|
|
|
|
return 0;
|
2012-05-28 01:18:32 +00:00
|
|
|
}
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
} // End of namespace Video
|