ScummVM API documentation
avi_decoder.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef VIDEO_AVI_DECODER_H
23#define VIDEO_AVI_DECODER_H
24
25#include "common/array.h"
26#include "common/rational.h"
27#include "common/rect.h"
28#include "common/str.h"
29#include "graphics/palette.h"
30
31#include "video/video_decoder.h"
32#include "audio/mixer.h"
33
34namespace Audio {
35class AudioStream;
36class PacketizedAudioStream;
37}
38
39namespace Common {
40class SeekableReadStream;
41}
42
43namespace Graphics {
44struct PixelFormat;
45}
46
47namespace Image {
48class Codec;
49}
50
51namespace Video {
52
65class AVIDecoder : public VideoDecoder {
66public:
67 AVIDecoder();
68 AVIDecoder(const Common::Rational &frameRateOverride);
69 virtual ~AVIDecoder();
70
71 bool loadStream(Common::SeekableReadStream *stream) override;
72 void close() override;
73 uint16 getWidth() const override { return _header.width; }
74 uint16 getHeight() const override { return _header.height; }
75
76 bool rewind() override;
77 bool isRewindable() const override { return true; }
78 bool isSeekable() const override;
79
96
101protected:
102 // VideoDecoder API
103 void readNextPacket() override;
104 bool seekIntern(const Audio::Timestamp &time) override;
105 bool supportsAudioTrackSwitching() const override { return true; }
106 AudioTrack *getAudioTrack(int index) override;
107
116 void addTrack(Track *track, bool isExternal = false);
117
119 uint32 size;
120 uint32 width;
121 uint32 height;
122 uint16 planes;
123 uint16 bitCount;
124 uint32 compression;
125 uint32 sizeImage;
126 uint32 xPelsPerMeter;
127 uint32 yPelsPerMeter;
128 uint32 clrUsed;
129 uint32 clrImportant;
130 };
131
132 struct WaveFormat {
133 uint16 tag;
134 uint16 channels;
135 uint32 samplesPerSec;
136 uint32 avgBytesPerSec;
137 uint16 blockAlign;
138 };
139
140 struct PCMWaveFormat : public WaveFormat {
141 uint16 size;
142 };
143
144 struct WaveFormatEX : public WaveFormat {
145 uint16 bitsPerSample;
146 uint16 size;
147 };
148
149 struct OldIndex {
150 uint32 id;
151 uint32 flags;
152 uint32 offset;
153 uint32 size;
154 };
155
156 // Index Flags
157 enum IndexFlags {
158 AVIIF_INDEX = 0x10
159 };
160
161 struct AVIHeader {
162 uint32 size;
163 uint32 microSecondsPerFrame;
164 uint32 maxBytesPerSecond;
165 uint32 padding;
166 uint32 flags;
167 uint32 totalFrames;
168 uint32 initialFrames;
169 uint32 streams;
170 uint32 bufferSize;
171 uint32 width;
172 uint32 height;
173 };
174
175 // Flags from the AVIHeader
176 enum AVIFlags {
177 AVIF_HASINDEX = 0x00000010,
178 AVIF_MUSTUSEINDEX = 0x00000020,
179 AVIF_ISINTERLEAVED = 0x00000100,
180 AVIF_TRUSTCKTYPE = 0x00000800,
181 AVIF_WASCAPTUREFILE = 0x00010000,
182 AVIF_WASCOPYRIGHTED = 0x00020000
183 };
184
186 uint32 size;
187 uint32 streamType;
188 uint32 streamHandler;
189 uint32 flags;
190 uint16 priority;
191 uint16 language;
192 uint32 initialFrames;
193 uint32 scale;
194 uint32 rate;
195 uint32 start;
196 uint32 length;
197 uint32 bufferSize;
198 uint32 quality;
199 uint32 sampleSize;
200 Common::Rect frame;
201 Common::String name;
202 };
203
205 public:
206 AVIVideoTrack(int frameCount, const AVIStreamHeader &streamHeader, const BitmapInfoHeader &bitmapInfoHeader, byte *initialPalette, Image::CodecAccuracy accuracy);
208
209 void decodeFrame(Common::SeekableReadStream *stream);
210 void forceTrackEnd();
211
212 uint16 getWidth() const override { return _bmInfo.width; }
213 uint16 getHeight() const override { return _bmInfo.height; }
214 uint16 getBitCount() const { return _bmInfo.bitCount; }
216 bool setOutputPixelFormat(const Graphics::PixelFormat &format) override;
217 void setCodecAccuracy(Image::CodecAccuracy accuracy) override;
218 int getCurFrame() const override { return _curFrame; }
219 int getFrameCount() const override { return _frameCount; }
220 Common::String &getName() { return _vidsHeader.name; }
221 const Graphics::Surface *decodeNextFrame() override { return _lastFrame; }
222
223 const byte *getPalette() const override;
224 bool hasDirtyPalette() const override;
225 void setCurFrame(int frame) { _curFrame = frame; }
226 void loadPaletteFromChunk(Common::SeekableReadStream *chunk);
227 void loadPaletteFromChunkRaw(Common::SeekableReadStream *chunk, int firstEntry, int numEntries);
228 void useInitialPalette();
229 bool canDither() const override;
230 void setDither(const byte *palette) override;
231 bool isValid() const { return _videoCodec != nullptr; }
232
233 bool isTruemotion1() const;
234 void forceDimensions(uint16 width, uint16 height);
235
236 bool isRewindable() const override { return true; }
237 bool rewind() override;
238
247 bool setReverse(bool reverse) override;
248
252 bool isReversed() const override { return _reversed; }
253
257 bool endOfTrack() const override;
258
262 Common::Rational getFrameRate() const override { return Common::Rational(_vidsHeader.rate, _vidsHeader.scale); }
263
268 _vidsHeader.rate = r.getNumerator();
269 _vidsHeader.scale = r.getDenominator();
270 }
271 private:
272 AVIStreamHeader _vidsHeader;
273 BitmapInfoHeader _bmInfo;
274 Graphics::Palette _palette;
275 byte *_initialPalette;
276 mutable bool _dirtyPalette;
277 int _frameCount, _curFrame;
278 bool _reversed;
279
280 Image::Codec *_videoCodec;
281 const Graphics::Surface *_lastFrame;
282 Image::CodecAccuracy _accuracy;
283
284 Image::Codec *createCodec();
285 };
286
287 class AVIAudioTrack : public AudioTrack {
288 public:
289 AVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType);
291
292 virtual void createAudioStream();
293 virtual void queueSound(Common::SeekableReadStream *stream);
294 void skipAudio(const Audio::Timestamp &time, const Audio::Timestamp &frameTime);
295 virtual void resetStream();
296 uint32 getCurChunk() const { return _curChunk; }
297 Common::String &getName() { return _audsHeader.name; }
298 void setCurChunk(uint32 chunk) { _curChunk = chunk; }
299 bool needsAudioOnlyBuffering();
300 void setAllPacketsQueued() { _allPacketsQueued = true; }
301 bool endOfTrack() const override;
302
303 bool isRewindable() const override { return true; }
304 bool rewind() override;
305
306 protected:
307 Audio::AudioStream *getAudioStream() const override { return _audioStream; }
308
309 AVIStreamHeader _audsHeader;
310 PCMWaveFormat _wvInfo;
311 Audio::AudioStream *_audioStream;
312 Audio::PacketizedAudioStream *_packetStream;
313 uint32 _curChunk;
314 bool _bufferedAudioOnly;
315 bool _allPacketsQueued;
316 };
317
318 struct TrackStatus {
319 TrackStatus();
320
321 Track *track;
322 uint32 index;
323 uint32 chunkSearchOffset;
324 };
325
326 class IndexEntries : public Common::Array<OldIndex> {
327 public:
328 OldIndex *find(uint index, uint frameNumber);
329 };
330
331 AVIHeader _header;
332
333 void readOldIndex(uint32 size);
334 IndexEntries _indexEntries;
335
336 Common::SeekableReadStream *_fileStream;
337 bool _decodedHeader;
338 bool _foundMovieList;
339 uint32 _movieListStart, _movieListEnd;
340
341 Common::Rational _frameRateOverride;
342
343 int _videoTrackCounter, _audioTrackCounter;
344 Track *_lastAddedTrack;
345
346 void initCommon();
347
348 bool parseNextChunk();
349 void skipChunk(uint32 size);
350 void handleList(uint32 listSize);
351 bool handleStreamHeader(uint32 size);
352 void readStreamName(uint32 size);
353 void readPalette8(uint32 size);
354 uint16 getStreamType(uint32 tag) const { return tag & 0xFFFF; }
355 static byte getStreamIndex(uint32 tag);
356 void checkTruemotion1();
357 uint getVideoTrackOffset(uint trackIndex, uint frameNumber = 0);
358
359 void handleNextPacket(TrackStatus& status);
360 bool shouldQueueAudio(TrackStatus& status);
361 void seekTransparencyFrame(int frame);
362
363 Common::Array<TrackStatus> _videoTracks, _audioTracks;
364 TrackStatus _transparencyTrack;
365
366public:
367 virtual AVIAudioTrack *createAudioTrack(AVIStreamHeader sHeader, PCMWaveFormat wvInfo);
368
375 bool seekToFrame(uint frame) override;
376};
377
378} // End of namespace Video
379
380#endif
Definition: audiostream.h:50
SoundType
Definition: mixer.h:73
Definition: audiostream.h:446
Definition: timestamp.h:83
Definition: array.h:52
Definition: rational.h:40
Definition: stream.h:745
Definition: str.h:59
Simple class for handling a palette data.
Definition: palette.h:61
Definition: codec.h:57
Definition: avi_decoder.h:287
bool endOfTrack() const override
Audio::AudioStream * getAudioStream() const override
Definition: avi_decoder.h:307
bool isRewindable() const override
Definition: avi_decoder.h:303
Definition: avi_decoder.h:204
void setCodecAccuracy(Image::CodecAccuracy accuracy) override
bool isRewindable() const override
Definition: avi_decoder.h:236
bool setReverse(bool reverse) override
int getFrameCount() const override
Definition: avi_decoder.h:219
uint16 getWidth() const override
Definition: avi_decoder.h:212
bool canDither() const override
int getCurFrame() const override
Definition: avi_decoder.h:218
const Graphics::Surface * decodeNextFrame() override
Definition: avi_decoder.h:221
bool hasDirtyPalette() const override
bool isReversed() const override
Definition: avi_decoder.h:252
uint16 getHeight() const override
Definition: avi_decoder.h:213
void setDither(const byte *palette) override
bool endOfTrack() const override
void setFrameRate(const Common::Rational &r)
Definition: avi_decoder.h:267
Common::Rational getFrameRate() const override
Definition: avi_decoder.h:262
Graphics::PixelFormat getPixelFormat() const override
const byte * getPalette() const override
bool setOutputPixelFormat(const Graphics::PixelFormat &format) override
Definition: avi_decoder.h:326
Definition: avi_decoder.h:65
void readNextPacket() override
bool seekToFrame(uint frame) override
bool isRewindable() const override
Definition: avi_decoder.h:77
bool rewind() override
AudioTrack * getAudioTrack(int index) override
void close() override
bool supportsAudioTrackSwitching() const override
Definition: avi_decoder.h:105
const Graphics::Surface * decodeNextFrame() override
const Graphics::Surface * decodeNextTransparency()
uint16 getWidth() const override
Definition: avi_decoder.h:73
void addTrack(Track *track, bool isExternal=false)
bool isSeekable() const override
uint16 getHeight() const override
Definition: avi_decoder.h:74
bool seekIntern(const Audio::Timestamp &time) override
bool loadStream(Common::SeekableReadStream *stream) override
Definition: video_decoder.h:759
Definition: video_decoder.h:734
Definition: video_decoder.h:532
Definition: video_decoder.h:53
Definition: system.h:39
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: rect.h:536
Definition: pixelformat.h:138
Definition: surface.h:67
Definition: avi_decoder.h:161
Definition: avi_decoder.h:185
Definition: avi_decoder.h:118
Definition: avi_decoder.h:149
Definition: avi_decoder.h:140
Definition: avi_decoder.h:318
Definition: avi_decoder.h:144
Definition: avi_decoder.h:132