ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

smk_decoder.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef VIDEO_SMK_PLAYER_H
00024 #define VIDEO_SMK_PLAYER_H
00025 
00026 #include "common/bitstream.h"
00027 #include "common/rational.h"
00028 #include "graphics/pixelformat.h"
00029 #include "graphics/surface.h"
00030 #include "video/video_decoder.h"
00031 #include "audio/mixer.h"
00032 
00033 namespace Audio {
00034 class QueuingAudioStream;
00035 }
00036 
00037 namespace Common {
00038 class SeekableReadStream;
00039 }
00040 
00041 namespace Video {
00042 
00043 class BigHuffmanTree;
00044 
00060 class SmackerDecoder : public VideoDecoder {
00061 public:
00062     SmackerDecoder();
00063     virtual ~SmackerDecoder();
00064 
00065     virtual bool loadStream(Common::SeekableReadStream *stream);
00066     void close();
00067 
00068     bool rewind();
00069 
00070     // ResidualVM-specific function
00071     Common::Rational getFrameRate() const;
00072 
00073 protected:
00074     void readNextPacket();
00075     bool supportsAudioTrackSwitching() const { return true; }
00076     AudioTrack *getAudioTrack(int index);
00077 
00078     virtual void handleAudioTrack(byte track, uint32 chunkSize, uint32 unpackedSize);
00079 
00080     class SmackerVideoTrack : public FixedRateVideoTrack {
00081     public:
00082         SmackerVideoTrack(uint32 width, uint32 height, uint32 frameCount, const Common::Rational &frameRate, uint32 flags, uint32 signature);
00083         ~SmackerVideoTrack();
00084 
00085         bool isRewindable() const { return true; }
00086         bool rewind() { _curFrame = -1; return true; }
00087 
00088         uint16 getWidth() const;
00089         uint16 getHeight() const;
00090         Graphics::PixelFormat getPixelFormat() const;
00091         int getCurFrame() const { return _curFrame; }
00092         int getFrameCount() const { return _frameCount; }
00093         const Graphics::Surface *decodeNextFrame() { return _surface; }
00094         const byte *getPalette() const { _dirtyPalette = false; return _palette; }
00095         bool hasDirtyPalette() const { return _dirtyPalette; }
00096 
00097         void readTrees(Common::BitStreamMemory8LSB &bs, uint32 mMapSize, uint32 mClrSize, uint32 fullSize, uint32 typeSize);
00098         void increaseCurFrame() { _curFrame++; }
00099         void decodeFrame(Common::BitStreamMemory8LSB &bs);
00100         void unpackPalette(Common::SeekableReadStream *stream);
00101 
00102         // ResidualVM-specific code
00103         Common::Rational getFrameRate() const { return _frameRate; }
00104 
00105     protected:
00106         Graphics::Surface *_surface;
00107 
00108     private:
00109         Common::Rational _frameRate;
00110         uint32 _flags, _signature;
00111 
00112         byte _palette[3 * 256];
00113         mutable bool _dirtyPalette;
00114 
00115         int _curFrame;
00116         uint32 _frameCount;
00117 
00118         BigHuffmanTree *_MMapTree;
00119         BigHuffmanTree *_MClrTree;
00120         BigHuffmanTree *_FullTree;
00121         BigHuffmanTree *_TypeTree;
00122 
00123         // Possible runs of blocks
00124         static uint getBlockRun(int index) { return (index <= 58) ? index + 1 : 128 << (index - 59); }
00125     };
00126 
00127     virtual SmackerVideoTrack *createVideoTrack(uint32 width, uint32 height, uint32 frameCount, const Common::Rational &frameRate, uint32 flags, uint32 signature) const;
00128 
00129     Common::SeekableReadStream *_fileStream;
00130 
00131     enum AudioCompression {
00132         kCompressionNone,
00133         kCompressionDPCM,
00134         kCompressionRDFT,
00135         kCompressionDCT
00136     };
00137 
00138     struct AudioInfo {
00139         AudioCompression compression;
00140         bool hasAudio;
00141         bool is16Bits;
00142         bool isStereo;
00143         uint32 sampleRate;
00144     };
00145 
00146     struct {
00147         uint32 signature;
00148         uint32 flags;
00149         uint32 audioSize[7];
00150         uint32 treesSize;
00151         uint32 mMapSize;
00152         uint32 mClrSize;
00153         uint32 fullSize;
00154         uint32 typeSize;
00155         AudioInfo audioInfo[7];
00156         uint32 dummy;
00157     } _header;
00158 
00159     uint32 *_frameSizes;
00160 
00161 private:
00162 
00163     class SmackerAudioTrack : public AudioTrack {
00164     public:
00165         SmackerAudioTrack(const AudioInfo &audioInfo, Audio::Mixer::SoundType soundType);
00166         ~SmackerAudioTrack();
00167 
00168         bool isRewindable() const { return true; }
00169         bool rewind();
00170 
00171         void queueCompressedBuffer(byte *buffer, uint32 bufferSize, uint32 unpackedSize);
00172         void queuePCM(byte *buffer, uint32 bufferSize);
00173 
00174     protected:
00175         Audio::AudioStream *getAudioStream() const;
00176 
00177     private:
00178         Audio::QueuingAudioStream *_audioStream;
00179         AudioInfo _audioInfo;
00180     };
00181 
00182     // The FrameTypes section of a Smacker file contains an array of bytes, where
00183     // the 8 bits of each byte describe the contents of the corresponding frame.
00184     // The highest 7 bits correspond to audio frames (bit 7 is track 6, bit 6 track 5
00185     // and so on), so there can be up to 7 different audio tracks. When the lowest bit
00186     // (bit 0) is set, it denotes a frame that contains a palette record
00187     byte *_frameTypes;
00188 
00189     uint32 _firstFrameStart;
00190 };
00191 
00192 } // End of namespace Video
00193 
00194 #endif


Generated on Sat Oct 12 2019 05:01:12 for ResidualVM by doxygen 1.7.1
curved edge   curved edge