From 19cb3499f587630f2429c3e99b4fcadf491836cb Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sat, 18 Jan 2014 03:18:40 +0100 Subject: KYRA: Rewrite the VQA decoder, using the VideoDecoder classes There isn't really a lot of benefit to this, but I think it's nicer if all our video decoders at least try to use the same infrastructure. --- engines/kyra/vqa.h | 179 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 103 insertions(+), 76 deletions(-) (limited to 'engines/kyra/vqa.h') diff --git a/engines/kyra/vqa.h b/engines/kyra/vqa.h index 839bf5ac48..26dbc8d062 100644 --- a/engines/kyra/vqa.h +++ b/engines/kyra/vqa.h @@ -23,9 +23,9 @@ #ifndef KYRA_VQA_H #define KYRA_VQA_H -#include "common/scummsys.h" - -#include "audio/mixer.h" +#include "video/video_decoder.h" +#include "common/file.h" +#include "common/rational.h" class OSystem; @@ -33,98 +33,125 @@ namespace Audio { class QueuingAudioStream; } // End of namespace Audio -namespace Common { -class SeekableReadStream; -} // End of namespace Common - namespace Kyra { class KyraEngine_v1; class Screen; +class VQADecoder : public Video::VideoDecoder { +public: + VQADecoder(); + virtual ~VQADecoder(); + + bool loadStream(Common::SeekableReadStream *stream); + +private: + class VQAAudioTrack : public AudioTrack { + public: + VQAAudioTrack(Common::SeekableReadStream *stream, int freq); + ~VQAAudioTrack(); + + void handleSND0(); + void handleSND1(); + void handleSND2(); + + protected: + Audio::AudioStream *getAudioStream() const; + + private: + Audio::QueuingAudioStream *_audioStream; + Common::SeekableReadStream *_fileStream; + }; + + class VQAVideoTrack : public FixedRateVideoTrack { + public: + VQAVideoTrack(Common::SeekableReadStream *stream); + ~VQAVideoTrack(); + + uint16 getWidth() const; + uint16 getHeight() const; + Graphics::PixelFormat getPixelFormat() const; + int getCurFrame() const; + int getFrameCount() const; + const Graphics::Surface *decodeNextFrame(); + + bool hasSound() const; + int getAudioFreq() const; + bool hasDirtyPalette() const; + const byte *getPalette() const; + + void setAudioTrack(VQAAudioTrack *audioTrack); + + void handleVQHD(); + void handleFINF(); + void handleVQFR(); + + protected: + Common::Rational getFrameRate() const; + + private: + Common::SeekableReadStream *_fileStream; + Graphics::Surface *_surface; + byte _palette[3 * 256]; + mutable bool _dirtyPalette; + VQAAudioTrack *_audioTrack; + + int _curFrame; + + struct VQAHeader { + uint16 version; + uint16 flags; + uint16 numFrames; + uint16 width; + uint16 height; + uint8 blockW; + uint8 blockH; + uint8 frameRate; + uint8 cbParts; + uint16 colors; + uint16 maxBlocks; + uint32 unk1; + uint16 unk2; + uint16 freq; + uint8 channels; + uint8 bits; + uint32 unk3; + uint16 unk4; + uint32 maxCBFZSize; + uint32 unk5; + }; + + VQAHeader _header; + uint32 *_frameInfo; + uint32 _codeBookSize; + bool _compressedCodeBook; + byte *_codeBook; + int _partialCodeBookSize; + int _numPartialCodeBooks; + byte *_partialCodeBook; + uint32 _numVectorPointers; + uint16 *_vectorPointers; + }; +}; + class VQAMovie { public: VQAMovie(KyraEngine_v1 *vm, OSystem *system); ~VQAMovie(); - bool opened() { return _opened; } - int frames() { return _opened ? _header.numFrames : -1; } - - // It's unlikely that we ever want to change the movie position from - // its default. - - void setDrawPage(int page) { _drawPage = page; } + void setDrawPage(int page); bool open(const char *filename); void close(); void play(); - -protected: +private: OSystem *_system; KyraEngine_v1 *_vm; Screen *_screen; + VQADecoder *_decoder; + Common::File _file; - bool _opened; - int _x, _y; int _drawPage; - - struct VQAHeader { - uint16 version; - uint16 flags; - uint16 numFrames; - uint16 width; - uint16 height; - uint8 blockW; - uint8 blockH; - uint8 frameRate; - uint8 cbParts; - uint16 colors; - uint16 maxBlocks; - uint32 unk1; - uint16 unk2; - uint16 freq; - uint8 channels; - uint8 bits; - uint32 unk3; - uint16 unk4; - uint32 maxCBFZSize; - uint32 unk5; - }; - - struct Buffer { - uint8 *data; - uint32 size; - }; - - Buffer _buffers[2]; - - void initBuffers(); - void *allocBuffer(int num, uint32 size); - void freeBuffers(); - - void decodeSND1(byte *inbuf, uint32 insize, byte *outbuf, uint32 outsize); - - void displayFrame(uint frameNum); - - Common::SeekableReadStream *_file; - - VQAHeader _header; - uint32 *_frameInfo; - uint32 _codeBookSize; - byte *_codeBook; - byte *_partialCodeBook; - bool _compressedCodeBook; - int _partialCodeBookSize; - int _numPartialCodeBooks; - uint32 _numVectorPointers; - uint16 *_vectorPointers; - - byte *_frame; - - Audio::QueuingAudioStream *_stream; - Audio::SoundHandle _sound; - - uint32 readTag(); }; } // End of namespace Kyra -- cgit v1.2.3 From 238aa2be2aeefda17cb5c2023f89e3934bed8424 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sat, 18 Jan 2014 03:18:40 +0100 Subject: KYRA: Let the VQA decoder draw directly to the backend As an alternative to using the Screen class's functions, we can let the VQA decoder draw directly to the backend. This won't work if the game uses "hi-res mode", but I don't think that's ever the case for Malcolm's Revenge. I believe the KyraEngine_MR::playVQA() function ensures that the screen is properly updated after the movie has finished. This almost limits the VQA rewrite to vqa.cpp and vqa.h. Whether it's better this way than changing the Screen functions to take a 'pitch' parameter...? I don't know. But it's an alternative. --- engines/kyra/vqa.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'engines/kyra/vqa.h') diff --git a/engines/kyra/vqa.h b/engines/kyra/vqa.h index 26dbc8d062..44d1354f3d 100644 --- a/engines/kyra/vqa.h +++ b/engines/kyra/vqa.h @@ -139,8 +139,6 @@ public: VQAMovie(KyraEngine_v1 *vm, OSystem *system); ~VQAMovie(); - void setDrawPage(int page); - bool open(const char *filename); void close(); void play(); @@ -150,8 +148,6 @@ private: Screen *_screen; VQADecoder *_decoder; Common::File _file; - - int _drawPage; }; } // End of namespace Kyra -- cgit v1.2.3 From 16d36224e21bbd42349e6c64d525bc9c602162a5 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sat, 18 Jan 2014 03:18:40 +0100 Subject: KYRA: Restructure the VQA decoder, as suggested by clone2727 Untangled the audio and video track from each other, and the parsing of the stream from the decoding of its data. Also fixed a memory leak as it turns out deleting a Surface doesn't free its data. You have to call free() in it. I have only checked the intro, not every cutscene, but that seems to work fine at least. --- engines/kyra/vqa.h | 86 +++++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 40 deletions(-) (limited to 'engines/kyra/vqa.h') diff --git a/engines/kyra/vqa.h b/engines/kyra/vqa.h index 44d1354f3d..02414819db 100644 --- a/engines/kyra/vqa.h +++ b/engines/kyra/vqa.h @@ -44,28 +44,59 @@ public: virtual ~VQADecoder(); bool loadStream(Common::SeekableReadStream *stream); + void readNextPacket(); private: + Common::SeekableReadStream *_fileStream; + + void handleVQHD(Common::SeekableReadStream *stream); + void handleFINF(Common::SeekableReadStream *stream); + + struct VQAHeader { + uint16 version; + uint16 flags; + uint16 numFrames; + uint16 width; + uint16 height; + uint8 blockW; + uint8 blockH; + uint8 frameRate; + uint8 cbParts; + uint16 colors; + uint16 maxBlocks; + uint32 unk1; + uint16 unk2; + uint16 freq; + uint8 channels; + uint8 bits; + uint32 unk3; + uint16 unk4; + uint32 maxCBFZSize; + uint32 unk5; + }; + + VQAHeader _header; + uint32 *_frameInfo; + class VQAAudioTrack : public AudioTrack { public: - VQAAudioTrack(Common::SeekableReadStream *stream, int freq); + VQAAudioTrack(VQAHeader *header); ~VQAAudioTrack(); - void handleSND0(); - void handleSND1(); - void handleSND2(); + void handleSND0(Common::SeekableReadStream *stream); + void handleSND1(Common::SeekableReadStream *stream); + void handleSND2(Common::SeekableReadStream *stream); protected: Audio::AudioStream *getAudioStream() const; private: Audio::QueuingAudioStream *_audioStream; - Common::SeekableReadStream *_fileStream; }; class VQAVideoTrack : public FixedRateVideoTrack { public: - VQAVideoTrack(Common::SeekableReadStream *stream); + VQAVideoTrack(VQAHeader *header); ~VQAVideoTrack(); uint16 getWidth() const; @@ -75,54 +106,29 @@ private: int getFrameCount() const; const Graphics::Surface *decodeNextFrame(); - bool hasSound() const; - int getAudioFreq() const; + void setHasDirtyPalette(); bool hasDirtyPalette() const; const byte *getPalette() const; - void setAudioTrack(VQAAudioTrack *audioTrack); - - void handleVQHD(); - void handleFINF(); - void handleVQFR(); + void handleVQFR(Common::SeekableReadStream *stream); protected: Common::Rational getFrameRate() const; private: - Common::SeekableReadStream *_fileStream; Graphics::Surface *_surface; byte _palette[3 * 256]; mutable bool _dirtyPalette; - VQAAudioTrack *_audioTrack; + bool _newFrame; + + uint16 _width, _height; + uint8 _blockW, _blockH; + uint8 _cbParts; + int _frameCount; int _curFrame; + byte _frameRate; - struct VQAHeader { - uint16 version; - uint16 flags; - uint16 numFrames; - uint16 width; - uint16 height; - uint8 blockW; - uint8 blockH; - uint8 frameRate; - uint8 cbParts; - uint16 colors; - uint16 maxBlocks; - uint32 unk1; - uint16 unk2; - uint16 freq; - uint8 channels; - uint8 bits; - uint32 unk3; - uint16 unk4; - uint32 maxCBFZSize; - uint32 unk5; - }; - - VQAHeader _header; - uint32 *_frameInfo; uint32 _codeBookSize; bool _compressedCodeBook; byte *_codeBook; -- cgit v1.2.3 From 18ef3ed6b357bbe3ea35989b19ecac32fdf07892 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sat, 18 Jan 2014 03:18:40 +0100 Subject: KYRA: Make pointers to VQAHeader const This is just to enforce the idea that VQADecoder owns the VQAHeader and that the audio/video tracks are only allowed to look at it, not change it. --- engines/kyra/vqa.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/kyra/vqa.h') diff --git a/engines/kyra/vqa.h b/engines/kyra/vqa.h index 02414819db..f3890107a8 100644 --- a/engines/kyra/vqa.h +++ b/engines/kyra/vqa.h @@ -80,7 +80,7 @@ private: class VQAAudioTrack : public AudioTrack { public: - VQAAudioTrack(VQAHeader *header); + VQAAudioTrack(const VQAHeader *header); ~VQAAudioTrack(); void handleSND0(Common::SeekableReadStream *stream); @@ -96,7 +96,7 @@ private: class VQAVideoTrack : public FixedRateVideoTrack { public: - VQAVideoTrack(VQAHeader *header); + VQAVideoTrack(const VQAHeader *header); ~VQAVideoTrack(); uint16 getWidth() const; -- cgit v1.2.3 From b79c2156d03aa6a40a94395453f6b0436ed48c03 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 18 Feb 2014 02:34:21 +0100 Subject: KYRA: Make GPL headers consistent in themselves. --- engines/kyra/vqa.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/kyra/vqa.h') diff --git a/engines/kyra/vqa.h b/engines/kyra/vqa.h index f3890107a8..d23704a9ea 100644 --- a/engines/kyra/vqa.h +++ b/engines/kyra/vqa.h @@ -8,12 +8,12 @@ * 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. -- cgit v1.2.3