2009-08-30 19:47:14 +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.
|
2014-02-18 01:34:27 +00:00
|
|
|
*
|
2009-08-30 19:47:14 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:27 +00:00
|
|
|
*
|
2009-08-30 19:47:14 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-08-06 03:24:00 +00:00
|
|
|
#ifndef VIDEO_AVI_DECODER_H
|
|
|
|
#define VIDEO_AVI_DECODER_H
|
2009-08-30 19:47:14 +00:00
|
|
|
|
2013-08-06 03:24:00 +00:00
|
|
|
#include "common/array.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/rational.h"
|
|
|
|
#include "common/rect.h"
|
|
|
|
#include "common/str.h"
|
|
|
|
|
2011-01-23 17:37:17 +00:00
|
|
|
#include "video/video_decoder.h"
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/mixer.h"
|
2009-08-30 19:47:14 +00:00
|
|
|
|
2011-04-24 08:34:27 +00:00
|
|
|
namespace Audio {
|
2015-08-12 02:54:00 +00:00
|
|
|
class AudioStream;
|
2015-08-10 00:05:40 +00:00
|
|
|
class PacketizedAudioStream;
|
2011-04-24 08:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
class SeekableReadStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Graphics {
|
|
|
|
struct PixelFormat;
|
|
|
|
}
|
|
|
|
|
2014-02-28 02:27:23 +00:00
|
|
|
namespace Image {
|
2011-04-24 08:34:27 +00:00
|
|
|
class Codec;
|
2014-02-28 02:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace Video {
|
2011-04-24 08:34:27 +00:00
|
|
|
|
2011-01-23 01:27:40 +00:00
|
|
|
/**
|
|
|
|
* Decoder for AVI videos.
|
|
|
|
*
|
|
|
|
* Video decoder used in engines:
|
|
|
|
* - sci
|
2012-11-29 20:53:19 +00:00
|
|
|
* - sword1
|
|
|
|
* - sword2
|
2016-07-17 17:05:48 +00:00
|
|
|
* - titanic
|
2013-10-26 14:38:25 +00:00
|
|
|
* - zvision
|
2011-01-23 01:27:40 +00:00
|
|
|
*/
|
2012-08-16 18:00:14 +00:00
|
|
|
class AVIDecoder : public VideoDecoder {
|
2009-08-30 19:47:14 +00:00
|
|
|
public:
|
2017-07-10 19:36:19 +00:00
|
|
|
AVIDecoder();
|
|
|
|
AVIDecoder(const Common::Rational &frameRateOverride);
|
2012-07-22 18:13:20 +00:00
|
|
|
virtual ~AVIDecoder();
|
2009-08-30 19:47:14 +00:00
|
|
|
|
2011-02-07 17:54:16 +00:00
|
|
|
bool loadStream(Common::SeekableReadStream *stream);
|
2010-05-18 14:17:24 +00:00
|
|
|
void close();
|
|
|
|
uint16 getWidth() const { return _header.width; }
|
|
|
|
uint16 getHeight() const { return _header.height; }
|
2009-10-16 18:05:56 +00:00
|
|
|
|
2013-08-26 02:23:33 +00:00
|
|
|
bool rewind();
|
|
|
|
bool isRewindable() const { return true; }
|
|
|
|
bool isSeekable() const;
|
|
|
|
|
2016-10-02 18:24:40 +00:00
|
|
|
const Graphics::Surface *decodeNextTransparency();
|
2010-05-18 14:17:24 +00:00
|
|
|
protected:
|
2014-01-10 02:27:52 +00:00
|
|
|
// VideoDecoder API
|
|
|
|
void readNextPacket();
|
|
|
|
bool seekIntern(const Audio::Timestamp &time);
|
|
|
|
bool supportsAudioTrackSwitching() const { return true; }
|
|
|
|
AudioTrack *getAudioTrack(int index);
|
2009-10-16 18:32:20 +00:00
|
|
|
|
2016-07-12 01:49:11 +00:00
|
|
|
/**
|
|
|
|
* Define a track to be used by this class.
|
|
|
|
*
|
|
|
|
* The pointer is then owned by this base class.
|
|
|
|
*
|
|
|
|
* @param track The track to add
|
|
|
|
* @param isExternal Is this an external track not found by loadStream()?
|
|
|
|
*/
|
|
|
|
void addTrack(Track *track, bool isExternal = false);
|
|
|
|
|
2012-07-22 18:13:20 +00:00
|
|
|
struct BitmapInfoHeader {
|
|
|
|
uint32 size;
|
|
|
|
uint32 width;
|
|
|
|
uint32 height;
|
|
|
|
uint16 planes;
|
|
|
|
uint16 bitCount;
|
|
|
|
uint32 compression;
|
|
|
|
uint32 sizeImage;
|
|
|
|
uint32 xPelsPerMeter;
|
|
|
|
uint32 yPelsPerMeter;
|
|
|
|
uint32 clrUsed;
|
|
|
|
uint32 clrImportant;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct WaveFormat {
|
|
|
|
uint16 tag;
|
|
|
|
uint16 channels;
|
|
|
|
uint32 samplesPerSec;
|
|
|
|
uint32 avgBytesPerSec;
|
|
|
|
uint16 blockAlign;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PCMWaveFormat : public WaveFormat {
|
|
|
|
uint16 size;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct WaveFormatEX : public WaveFormat {
|
|
|
|
uint16 bitsPerSample;
|
|
|
|
uint16 size;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OldIndex {
|
2013-08-06 03:24:00 +00:00
|
|
|
uint32 id;
|
|
|
|
uint32 flags;
|
|
|
|
uint32 offset;
|
2012-07-22 18:13:20 +00:00
|
|
|
uint32 size;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Index Flags
|
|
|
|
enum IndexFlags {
|
|
|
|
AVIIF_INDEX = 0x10
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AVIHeader {
|
|
|
|
uint32 size;
|
|
|
|
uint32 microSecondsPerFrame;
|
|
|
|
uint32 maxBytesPerSecond;
|
|
|
|
uint32 padding;
|
|
|
|
uint32 flags;
|
|
|
|
uint32 totalFrames;
|
|
|
|
uint32 initialFrames;
|
|
|
|
uint32 streams;
|
|
|
|
uint32 bufferSize;
|
|
|
|
uint32 width;
|
|
|
|
uint32 height;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Flags from the AVIHeader
|
|
|
|
enum AVIFlags {
|
|
|
|
AVIF_HASINDEX = 0x00000010,
|
|
|
|
AVIF_MUSTUSEINDEX = 0x00000020,
|
|
|
|
AVIF_ISINTERLEAVED = 0x00000100,
|
|
|
|
AVIF_TRUSTCKTYPE = 0x00000800,
|
|
|
|
AVIF_WASCAPTUREFILE = 0x00010000,
|
|
|
|
AVIF_WASCOPYRIGHTED = 0x00020000
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AVIStreamHeader {
|
|
|
|
uint32 size;
|
|
|
|
uint32 streamType;
|
|
|
|
uint32 streamHandler;
|
|
|
|
uint32 flags;
|
|
|
|
uint16 priority;
|
|
|
|
uint16 language;
|
|
|
|
uint32 initialFrames;
|
|
|
|
uint32 scale;
|
|
|
|
uint32 rate;
|
|
|
|
uint32 start;
|
|
|
|
uint32 length;
|
|
|
|
uint32 bufferSize;
|
|
|
|
uint32 quality;
|
|
|
|
uint32 sampleSize;
|
|
|
|
Common::Rect frame;
|
2016-07-12 01:49:11 +00:00
|
|
|
Common::String name;
|
2012-07-22 18:13:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AVIVideoTrack : public FixedRateVideoTrack {
|
|
|
|
public:
|
2013-08-26 02:23:33 +00:00
|
|
|
AVIVideoTrack(int frameCount, const AVIStreamHeader &streamHeader, const BitmapInfoHeader &bitmapInfoHeader, byte *initialPalette = 0);
|
2012-07-22 18:13:20 +00:00
|
|
|
~AVIVideoTrack();
|
|
|
|
|
|
|
|
void decodeFrame(Common::SeekableReadStream *stream);
|
2013-11-26 01:32:53 +00:00
|
|
|
void forceTrackEnd();
|
2012-07-22 18:13:20 +00:00
|
|
|
|
|
|
|
uint16 getWidth() const { return _bmInfo.width; }
|
|
|
|
uint16 getHeight() const { return _bmInfo.height; }
|
2016-10-07 00:32:25 +00:00
|
|
|
uint16 getBitCount() const { return _bmInfo.bitCount; }
|
2012-07-22 18:13:20 +00:00
|
|
|
Graphics::PixelFormat getPixelFormat() const;
|
|
|
|
int getCurFrame() const { return _curFrame; }
|
|
|
|
int getFrameCount() const { return _frameCount; }
|
2016-07-12 01:49:11 +00:00
|
|
|
Common::String &getName() { return _vidsHeader.name; }
|
2012-07-22 18:13:20 +00:00
|
|
|
const Graphics::Surface *decodeNextFrame() { return _lastFrame; }
|
2013-06-23 23:36:27 +00:00
|
|
|
|
|
|
|
const byte *getPalette() const;
|
|
|
|
bool hasDirtyPalette() const;
|
2013-08-26 02:23:33 +00:00
|
|
|
void setCurFrame(int frame) { _curFrame = frame; }
|
|
|
|
void loadPaletteFromChunk(Common::SeekableReadStream *chunk);
|
|
|
|
void useInitialPalette();
|
2013-06-23 23:36:27 +00:00
|
|
|
bool canDither() const;
|
|
|
|
void setDither(const byte *palette);
|
2013-08-26 02:23:33 +00:00
|
|
|
|
2014-05-27 04:09:11 +00:00
|
|
|
bool isTruemotion1() const;
|
|
|
|
void forceDimensions(uint16 width, uint16 height);
|
|
|
|
|
2013-08-26 02:23:33 +00:00
|
|
|
bool isRewindable() const { return true; }
|
|
|
|
bool rewind();
|
2012-07-22 18:13:20 +00:00
|
|
|
|
2016-12-06 04:15:44 +00:00
|
|
|
/**
|
|
|
|
* Set the video track to play in reverse or forward.
|
|
|
|
*
|
|
|
|
* By default, a VideoTrack must decode forward.
|
|
|
|
*
|
|
|
|
* @param reverse true for reverse, false for forward
|
|
|
|
* @return true for success, false for failure
|
|
|
|
*/
|
|
|
|
virtual bool setReverse(bool reverse);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is the video track set to play in reverse?
|
|
|
|
*/
|
|
|
|
virtual bool isReversed() const { return _reversed; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if at the end of the video track
|
|
|
|
*/
|
|
|
|
virtual bool endOfTrack() const;
|
2017-06-26 00:48:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get track frame rate
|
|
|
|
*/
|
2012-07-22 18:13:20 +00:00
|
|
|
Common::Rational getFrameRate() const { return Common::Rational(_vidsHeader.rate, _vidsHeader.scale); }
|
|
|
|
|
2017-06-26 00:48:12 +00:00
|
|
|
/**
|
|
|
|
* Force sets a new frame rate
|
|
|
|
*/
|
|
|
|
void setFrameRate(const Common::Rational &r) {
|
|
|
|
_vidsHeader.rate = r.getNumerator();
|
|
|
|
_vidsHeader.scale = r.getDenominator();
|
|
|
|
}
|
2012-07-22 18:13:20 +00:00
|
|
|
private:
|
|
|
|
AVIStreamHeader _vidsHeader;
|
|
|
|
BitmapInfoHeader _bmInfo;
|
|
|
|
byte _palette[3 * 256];
|
2013-08-26 02:23:33 +00:00
|
|
|
byte *_initialPalette;
|
2012-07-22 18:13:20 +00:00
|
|
|
mutable bool _dirtyPalette;
|
|
|
|
int _frameCount, _curFrame;
|
2016-12-06 04:15:44 +00:00
|
|
|
bool _reversed;
|
2012-07-22 18:13:20 +00:00
|
|
|
|
2014-02-28 02:27:23 +00:00
|
|
|
Image::Codec *_videoCodec;
|
2012-07-22 18:13:20 +00:00
|
|
|
const Graphics::Surface *_lastFrame;
|
2014-02-28 02:27:23 +00:00
|
|
|
Image::Codec *createCodec();
|
2012-07-22 18:13:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AVIAudioTrack : public AudioTrack {
|
|
|
|
public:
|
|
|
|
AVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType);
|
|
|
|
~AVIAudioTrack();
|
|
|
|
|
2015-08-12 02:54:00 +00:00
|
|
|
virtual void createAudioStream();
|
2013-06-07 19:11:28 +00:00
|
|
|
virtual void queueSound(Common::SeekableReadStream *stream);
|
2013-08-26 02:23:33 +00:00
|
|
|
void skipAudio(const Audio::Timestamp &time, const Audio::Timestamp &frameTime);
|
2014-11-03 01:45:38 +00:00
|
|
|
virtual void resetStream();
|
2014-11-03 00:26:18 +00:00
|
|
|
uint32 getCurChunk() const { return _curChunk; }
|
2016-07-12 01:49:11 +00:00
|
|
|
Common::String &getName() { return _audsHeader.name; }
|
2014-11-03 00:26:18 +00:00
|
|
|
void setCurChunk(uint32 chunk) { _curChunk = chunk; }
|
2013-08-26 02:23:33 +00:00
|
|
|
|
|
|
|
bool isRewindable() const { return true; }
|
|
|
|
bool rewind();
|
2012-07-22 18:13:20 +00:00
|
|
|
|
|
|
|
protected:
|
2015-08-12 02:54:00 +00:00
|
|
|
Audio::AudioStream *getAudioStream() const { return _audioStream; }
|
2012-07-22 18:13:20 +00:00
|
|
|
|
|
|
|
// Audio Codecs
|
|
|
|
enum {
|
|
|
|
kWaveFormatNone = 0,
|
|
|
|
kWaveFormatPCM = 1,
|
2013-01-26 01:42:29 +00:00
|
|
|
kWaveFormatMSADPCM = 2,
|
|
|
|
kWaveFormatMSIMAADPCM = 17,
|
2014-06-08 19:54:07 +00:00
|
|
|
kWaveFormatMP3 = 85,
|
2013-01-26 01:42:29 +00:00
|
|
|
kWaveFormatDK3 = 98 // rogue format number
|
2012-07-22 18:13:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AVIStreamHeader _audsHeader;
|
|
|
|
PCMWaveFormat _wvInfo;
|
2015-08-12 02:54:00 +00:00
|
|
|
Audio::AudioStream *_audioStream;
|
2015-08-10 00:05:40 +00:00
|
|
|
Audio::PacketizedAudioStream *_packetStream;
|
2014-11-03 00:26:18 +00:00
|
|
|
uint32 _curChunk;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TrackStatus {
|
|
|
|
TrackStatus();
|
|
|
|
|
|
|
|
Track *track;
|
|
|
|
uint32 index;
|
|
|
|
uint32 chunkSearchOffset;
|
2012-07-22 18:13:20 +00:00
|
|
|
};
|
|
|
|
|
2016-10-13 00:09:36 +00:00
|
|
|
class IndexEntries : public Common::Array<OldIndex> {
|
|
|
|
public:
|
|
|
|
OldIndex *find(uint index, uint frameNumber);
|
|
|
|
};
|
|
|
|
|
2012-09-26 02:17:31 +00:00
|
|
|
AVIHeader _header;
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2013-11-23 15:58:01 +00:00
|
|
|
void readOldIndex(uint32 size);
|
2016-10-13 00:09:36 +00:00
|
|
|
IndexEntries _indexEntries;
|
2013-11-23 15:58:01 +00:00
|
|
|
|
2010-05-18 14:17:24 +00:00
|
|
|
Common::SeekableReadStream *_fileStream;
|
2013-08-06 03:24:00 +00:00
|
|
|
bool _decodedHeader;
|
|
|
|
bool _foundMovieList;
|
2013-11-26 01:32:53 +00:00
|
|
|
uint32 _movieListStart, _movieListEnd;
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2012-11-29 20:50:43 +00:00
|
|
|
Common::Rational _frameRateOverride;
|
2016-07-11 23:39:53 +00:00
|
|
|
|
|
|
|
int _videoTrackCounter, _audioTrackCounter;
|
2016-07-12 01:49:11 +00:00
|
|
|
Track *_lastAddedTrack;
|
2016-07-11 23:39:53 +00:00
|
|
|
|
2012-11-29 20:50:43 +00:00
|
|
|
void initCommon();
|
2009-11-28 00:38:18 +00:00
|
|
|
|
2013-08-06 03:24:00 +00:00
|
|
|
bool parseNextChunk();
|
|
|
|
void skipChunk(uint32 size);
|
|
|
|
void handleList(uint32 listSize);
|
|
|
|
void handleStreamHeader(uint32 size);
|
2016-07-12 01:49:11 +00:00
|
|
|
void readStreamName(uint32 size);
|
2013-08-06 03:24:00 +00:00
|
|
|
uint16 getStreamType(uint32 tag) const { return tag & 0xFFFF; }
|
2016-10-13 00:09:36 +00:00
|
|
|
static byte getStreamIndex(uint32 tag);
|
2014-05-27 04:09:11 +00:00
|
|
|
void checkTruemotion1();
|
2016-10-13 00:09:36 +00:00
|
|
|
uint getVideoTrackOffset(uint trackIndex, uint frameNumber = 0);
|
2013-06-07 19:11:28 +00:00
|
|
|
|
2014-11-03 00:26:18 +00:00
|
|
|
void handleNextPacket(TrackStatus& status);
|
|
|
|
bool shouldQueueAudio(TrackStatus& status);
|
2017-07-01 01:31:17 +00:00
|
|
|
void seekTransparencyFrame(int frame);
|
2014-11-03 00:26:18 +00:00
|
|
|
|
2017-07-01 01:31:17 +00:00
|
|
|
Common::Array<TrackStatus> _videoTracks, _audioTracks;
|
|
|
|
TrackStatus _transparencyTrack;
|
2013-06-07 19:11:28 +00:00
|
|
|
public:
|
|
|
|
virtual AVIAudioTrack *createAudioTrack(AVIStreamHeader sHeader, PCMWaveFormat wvInfo);
|
2016-10-03 00:22:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Seek to a given frame.
|
|
|
|
*
|
|
|
|
* This only works when the video track(s) supports getFrameTime().
|
|
|
|
* This calls seek() internally.
|
|
|
|
*/
|
|
|
|
virtual bool seekToFrame(uint frame);
|
2009-08-30 19:47:14 +00:00
|
|
|
};
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
} // End of namespace Video
|
2009-08-30 19:47:14 +00:00
|
|
|
|
|
|
|
#endif
|