aboutsummaryrefslogtreecommitdiff
path: root/video/bink_decoder.h
diff options
context:
space:
mode:
authorMatthew Hoops2012-07-25 11:22:28 -0400
committerMatthew Hoops2012-07-25 11:22:28 -0400
commit57a06e383b7c3c950653a99c81c1c7fd7dcd5b1d (patch)
tree26d5770e1b8507fb0e518aba7a809f2d50b2d812 /video/bink_decoder.h
parentc0cece8d1335a3397ea980d9a2abc4075656068c (diff)
downloadscummvm-rg350-57a06e383b7c3c950653a99c81c1c7fd7dcd5b1d.tar.gz
scummvm-rg350-57a06e383b7c3c950653a99c81c1c7fd7dcd5b1d.tar.bz2
scummvm-rg350-57a06e383b7c3c950653a99c81c1c7fd7dcd5b1d.zip
VIDEO: Convert Bink to the new AdvancedVideoDecoder API
Diffstat (limited to 'video/bink_decoder.h')
-rw-r--r--video/bink_decoder.h420
1 files changed, 215 insertions, 205 deletions
diff --git a/video/bink_decoder.h b/video/bink_decoder.h
index a5e1b10270..836238ce99 100644
--- a/video/bink_decoder.h
+++ b/video/bink_decoder.h
@@ -31,22 +31,27 @@
#ifndef VIDEO_BINK_DECODER_H
#define VIDEO_BINK_DECODER_H
-#include "audio/audiostream.h"
-#include "audio/mixer.h"
#include "common/array.h"
#include "common/rational.h"
-#include "graphics/surface.h"
-
#include "video/video_decoder.h"
+namespace Audio {
+class AudioStream;
+class QueuingAudioStream;
+}
+
namespace Common {
- class SeekableReadStream;
- class BitStream;
- class Huffman;
+class SeekableReadStream;
+class BitStream;
+class Huffman;
- class RDFT;
- class DCT;
+class RDFT;
+class DCT;
+}
+
+namespace Graphics {
+struct Surface;
}
namespace Video {
@@ -57,92 +62,28 @@ namespace Video {
* Video decoder used in engines:
* - scumm (he)
*/
-class BinkDecoder : public FixedRateVideoDecoder {
+class BinkDecoder : public AdvancedVideoDecoder {
public:
BinkDecoder();
~BinkDecoder();
- // VideoDecoder API
bool loadStream(Common::SeekableReadStream *stream);
void close();
- bool isVideoLoaded() const { return _bink != 0; }
- uint16 getWidth() const { return _surface.w; }
- uint16 getHeight() const { return _surface.h; }
- Graphics::PixelFormat getPixelFormat() const { return _surface.format; }
- uint32 getFrameCount() const { return _frames.size(); }
- uint32 getTime() const;
- const Graphics::Surface *decodeNextFrame();
-
- // FixedRateVideoDecoder
- Common::Rational getFrameRate() const { return _frameRate; }
-
- // Bink specific
- bool loadStream(Common::SeekableReadStream *stream, const Graphics::PixelFormat &format);
protected:
- // VideoDecoder API
- void updateVolume();
- void updateBalance();
+ void readNextPacket();
+private:
static const int kAudioChannelsMax = 2;
static const int kAudioBlockSizeMax = (kAudioChannelsMax << 11);
- /** IDs for different data types used in Bink video codec. */
- enum Source {
- kSourceBlockTypes = 0, ///< 8x8 block types.
- kSourceSubBlockTypes , ///< 16x16 block types (a subset of 8x8 block types).
- kSourceColors , ///< Pixel values used for different block types.
- kSourcePattern , ///< 8-bit values for 2-color pattern fill.
- kSourceXOff , ///< X components of motion value.
- kSourceYOff , ///< Y components of motion value.
- kSourceIntraDC , ///< DC values for intrablocks with DCT.
- kSourceInterDC , ///< DC values for interblocks with DCT.
- kSourceRun , ///< Run lengths for special fill block.
-
- kSourceMAX
- };
-
- /** Bink video block types. */
- enum BlockType {
- kBlockSkip = 0, ///< Skipped block.
- kBlockScaled , ///< Block has size 16x16.
- kBlockMotion , ///< Block is copied from previous frame with some offset.
- kBlockRun , ///< Block is composed from runs of colors with custom scan order.
- kBlockResidue , ///< Motion block with some difference added.
- kBlockIntra , ///< Intra DCT block.
- kBlockFill , ///< Block is filled with single color.
- kBlockInter , ///< Motion block with DCT applied to the difference.
- kBlockPattern , ///< Block is filled with two colors following custom pattern.
- kBlockRaw ///< Uncoded 8x8 block.
- };
-
- /** Data structure for decoding and tranlating Huffman'd data. */
- struct Huffman {
- int index; ///< Index of the Huffman codebook to use.
- byte symbols[16]; ///< Huffman symbol => Bink symbol tranlation list.
- };
-
- /** Data structure used for decoding a single Bink data type. */
- struct Bundle {
- int countLengths[2]; ///< Lengths of number of entries to decode (in bits).
- int countLength; ///< Length of number of entries to decode (in bits) for the current plane.
-
- Huffman huffman; ///< Huffman codebook.
-
- byte *data; ///< Buffer for decoded symbols.
- byte *dataEnd; ///< Buffer end.
-
- byte *curDec; ///< Pointer to the data that wasn't yet decoded.
- byte *curPtr; ///< Pointer to the data that wasn't yet read.
- };
-
enum AudioCodec {
kAudioCodecDCT,
kAudioCodecRDFT
};
/** An audio track. */
- struct AudioTrack {
+ struct AudioInfo {
uint16 flags;
uint32 sampleRate;
@@ -177,8 +118,8 @@ protected:
Common::RDFT *rdft;
Common::DCT *dct;
- AudioTrack();
- ~AudioTrack();
+ AudioInfo();
+ ~AudioInfo();
};
/** A video frame. */
@@ -194,149 +135,218 @@ protected:
~VideoFrame();
};
- /** A decoder state. */
- struct DecodeContext {
- VideoFrame *video;
+ class BinkVideoTrack : public FixedRateVideoTrack {
+ public:
+ BinkVideoTrack(uint32 width, uint32 height, const Graphics::PixelFormat &format, uint32 frameCount, const Common::Rational &frameRate, bool swapPlanes, bool hasAlpha, uint32 id);
+ ~BinkVideoTrack();
+
+ uint16 getWidth() const { return _surface.w; }
+ uint16 getHeight() const { return _surface.h; }
+ Graphics::PixelFormat getPixelFormat() const { return _surface.format; }
+ int getCurFrame() const { return _curFrame; }
+ int getFrameCount() const { return _frameCount; }
+ const Graphics::Surface *decodeNextFrame() { return &_surface; }
+
+ /** Decode a video packet. */
+ void decodePacket(VideoFrame &frame);
+
+ protected:
+ Common::Rational getFrameRate() const { return _frameRate; }
- uint32 planeIdx;
+ private:
+ /** A decoder state. */
+ struct DecodeContext {
+ VideoFrame *video;
+
+ uint32 planeIdx;
- uint32 blockX;
- uint32 blockY;
+ uint32 blockX;
+ uint32 blockY;
- byte *dest;
- byte *prev;
+ byte *dest;
+ byte *prev;
- byte *destStart, *destEnd;
- byte *prevStart, *prevEnd;
+ byte *destStart, *destEnd;
+ byte *prevStart, *prevEnd;
- uint32 pitch;
+ uint32 pitch;
- int coordMap[64];
- int coordScaledMap1[64];
- int coordScaledMap2[64];
- int coordScaledMap3[64];
- int coordScaledMap4[64];
+ int coordMap[64];
+ int coordScaledMap1[64];
+ int coordScaledMap2[64];
+ int coordScaledMap3[64];
+ int coordScaledMap4[64];
+ };
+
+ /** IDs for different data types used in Bink video codec. */
+ enum Source {
+ kSourceBlockTypes = 0, ///< 8x8 block types.
+ kSourceSubBlockTypes , ///< 16x16 block types (a subset of 8x8 block types).
+ kSourceColors , ///< Pixel values used for different block types.
+ kSourcePattern , ///< 8-bit values for 2-color pattern fill.
+ kSourceXOff , ///< X components of motion value.
+ kSourceYOff , ///< Y components of motion value.
+ kSourceIntraDC , ///< DC values for intrablocks with DCT.
+ kSourceInterDC , ///< DC values for interblocks with DCT.
+ kSourceRun , ///< Run lengths for special fill block.
+
+ kSourceMAX
+ };
+
+ /** Bink video block types. */
+ enum BlockType {
+ kBlockSkip = 0, ///< Skipped block.
+ kBlockScaled , ///< Block has size 16x16.
+ kBlockMotion , ///< Block is copied from previous frame with some offset.
+ kBlockRun , ///< Block is composed from runs of colors with custom scan order.
+ kBlockResidue , ///< Motion block with some difference added.
+ kBlockIntra , ///< Intra DCT block.
+ kBlockFill , ///< Block is filled with single color.
+ kBlockInter , ///< Motion block with DCT applied to the difference.
+ kBlockPattern , ///< Block is filled with two colors following custom pattern.
+ kBlockRaw ///< Uncoded 8x8 block.
+ };
+
+ /** Data structure for decoding and tranlating Huffman'd data. */
+ struct Huffman {
+ int index; ///< Index of the Huffman codebook to use.
+ byte symbols[16]; ///< Huffman symbol => Bink symbol tranlation list.
+ };
+
+ /** Data structure used for decoding a single Bink data type. */
+ struct Bundle {
+ int countLengths[2]; ///< Lengths of number of entries to decode (in bits).
+ int countLength; ///< Length of number of entries to decode (in bits) for the current plane.
+
+ Huffman huffman; ///< Huffman codebook.
+
+ byte *data; ///< Buffer for decoded symbols.
+ byte *dataEnd; ///< Buffer end.
+
+ byte *curDec; ///< Pointer to the data that wasn't yet decoded.
+ byte *curPtr; ///< Pointer to the data that wasn't yet read.
+ };
+
+ int _curFrame;
+ int _frameCount;
+
+ Graphics::Surface _surface;
+
+ uint32 _id; ///< The BIK FourCC.
+
+ bool _hasAlpha; ///< Do video frames have alpha?
+ bool _swapPlanes; ///< Are the planes ordered (A)YVU instead of (A)YUV?
+
+ Common::Rational _frameRate;
+
+ Bundle _bundles[kSourceMAX]; ///< Bundles for decoding all data types.
+
+ Common::Huffman *_huffman[16]; ///< The 16 Huffman codebooks used in Bink decoding.
+
+ /** Huffman codebooks to use for decoding high nibbles in color data types. */
+ Huffman _colHighHuffman[16];
+ /** Value of the last decoded high nibble in color data types. */
+ int _colLastVal;
+
+ byte *_curPlanes[4]; ///< The 4 color planes, YUVA, current frame.
+ byte *_oldPlanes[4]; ///< The 4 color planes, YUVA, last frame.
+
+ /** Initialize the bundles. */
+ void initBundles();
+ /** Deinitialize the bundles. */
+ void deinitBundles();
+
+ /** Initialize the Huffman decoders. */
+ void initHuffman();
+
+ /** Decode a plane. */
+ void decodePlane(VideoFrame &video, int planeIdx, bool isChroma);
+
+ /** Read/Initialize a bundle for decoding a plane. */
+ void readBundle(VideoFrame &video, Source source);
+
+ /** Read the symbols for a Huffman code. */
+ void readHuffman(VideoFrame &video, Huffman &huffman);
+ /** Merge two Huffman symbol lists. */
+ void mergeHuffmanSymbols(VideoFrame &video, byte *dst, const byte *src, int size);
+
+ /** Read and translate a symbol out of a Huffman code. */
+ byte getHuffmanSymbol(VideoFrame &video, Huffman &huffman);
+
+ /** Get a direct value out of a bundle. */
+ int32 getBundleValue(Source source);
+ /** Read a count value out of a bundle. */
+ uint32 readBundleCount(VideoFrame &video, Bundle &bundle);
+
+ // Handle the block types
+ void blockSkip (DecodeContext &ctx);
+ void blockScaledSkip (DecodeContext &ctx);
+ void blockScaledRun (DecodeContext &ctx);
+ void blockScaledIntra (DecodeContext &ctx);
+ void blockScaledFill (DecodeContext &ctx);
+ void blockScaledPattern(DecodeContext &ctx);
+ void blockScaledRaw (DecodeContext &ctx);
+ void blockScaled (DecodeContext &ctx);
+ void blockMotion (DecodeContext &ctx);
+ void blockRun (DecodeContext &ctx);
+ void blockResidue (DecodeContext &ctx);
+ void blockIntra (DecodeContext &ctx);
+ void blockFill (DecodeContext &ctx);
+ void blockInter (DecodeContext &ctx);
+ void blockPattern (DecodeContext &ctx);
+ void blockRaw (DecodeContext &ctx);
+
+ // Read the bundles
+ void readRuns (VideoFrame &video, Bundle &bundle);
+ void readMotionValues(VideoFrame &video, Bundle &bundle);
+ void readBlockTypes (VideoFrame &video, Bundle &bundle);
+ void readPatterns (VideoFrame &video, Bundle &bundle);
+ void readColors (VideoFrame &video, Bundle &bundle);
+ void readDCS (VideoFrame &video, Bundle &bundle, int startBits, bool hasSign);
+ void readDCTCoeffs (VideoFrame &video, int16 *block, bool isIntra);
+ void readResidue (VideoFrame &video, int16 *block, int masksCount);
+
+ // Bink video IDCT
+ void IDCT(int16 *block);
+ void IDCTPut(DecodeContext &ctx, int16 *block);
+ void IDCTAdd(DecodeContext &ctx, int16 *block);
};
- Common::SeekableReadStream *_bink;
+ class BinkAudioTrack : public AudioTrack {
+ public:
+ BinkAudioTrack(AudioInfo &audio);
+ ~BinkAudioTrack();
+
+ /** Decode an audio packet. */
+ void decodePacket();
- uint32 _id; ///< The BIK FourCC.
+ protected:
+ Audio::AudioStream *getAudioStream() const;
- Common::Rational _frameRate;
+ private:
+ AudioInfo *_audioInfo;
+ Audio::QueuingAudioStream *_audioStream;
- Graphics::Surface _surface;
+ float getFloat();
- Audio::SoundHandle _audioHandle;
- Audio::QueuingAudioStream *_audioStream;
- int32 _audioStartOffset;
+ /** Decode an audio block. */
+ void audioBlock(int16 *out);
+ /** Decode a DCT'd audio block. */
+ void audioBlockDCT();
+ /** Decode a RDFT'd audio block. */
+ void audioBlockRDFT();
- uint32 _videoFlags; ///< Video frame features.
+ void readAudioCoeffs(float *coeffs);
- bool _hasAlpha; ///< Do video frames have alpha?
- bool _swapPlanes; ///< Are the planes ordered (A)YVU instead of (A)YUV?
+ static void floatToInt16Interleave(int16 *dst, const float **src, uint32 length, uint8 channels);
+ };
+
+ Common::SeekableReadStream *_bink;
- Common::Array<AudioTrack> _audioTracks; ///< All audio tracks.
+ Common::Array<AudioInfo> _audioTracks; ///< All audio tracks.
Common::Array<VideoFrame> _frames; ///< All video frames.
- uint32 _audioTrack; ///< Audio track to use.
-
- Common::Huffman *_huffman[16]; ///< The 16 Huffman codebooks used in Bink decoding.
-
- Bundle _bundles[kSourceMAX]; ///< Bundles for decoding all data types.
-
- /** Huffman codebooks to use for decoding high nibbles in color data types. */
- Huffman _colHighHuffman[16];
- /** Value of the last decoded high nibble in color data types. */
- int _colLastVal;
-
- byte *_curPlanes[4]; ///< The 4 color planes, YUVA, current frame.
- byte *_oldPlanes[4]; ///< The 4 color planes, YUVA, last frame.
-
-
- /** Initialize the bundles. */
- void initBundles();
- /** Deinitialize the bundles. */
- void deinitBundles();
-
- /** Initialize the Huffman decoders. */
- void initHuffman();
-
- /** Decode an audio packet. */
- void audioPacket(AudioTrack &audio);
- /** Decode a video packet. */
- virtual void videoPacket(VideoFrame &video);
-
- /** Decode a plane. */
- void decodePlane(VideoFrame &video, int planeIdx, bool isChroma);
-
- /** Read/Initialize a bundle for decoding a plane. */
- void readBundle(VideoFrame &video, Source source);
-
- /** Read the symbols for a Huffman code. */
- void readHuffman(VideoFrame &video, Huffman &huffman);
- /** Merge two Huffman symbol lists. */
- void mergeHuffmanSymbols(VideoFrame &video, byte *dst, const byte *src, int size);
-
- /** Read and translate a symbol out of a Huffman code. */
- byte getHuffmanSymbol(VideoFrame &video, Huffman &huffman);
-
- /** Get a direct value out of a bundle. */
- int32 getBundleValue(Source source);
- /** Read a count value out of a bundle. */
- uint32 readBundleCount(VideoFrame &video, Bundle &bundle);
-
- // Handle the block types
- void blockSkip (DecodeContext &ctx);
- void blockScaledSkip (DecodeContext &ctx);
- void blockScaledRun (DecodeContext &ctx);
- void blockScaledIntra (DecodeContext &ctx);
- void blockScaledFill (DecodeContext &ctx);
- void blockScaledPattern(DecodeContext &ctx);
- void blockScaledRaw (DecodeContext &ctx);
- void blockScaled (DecodeContext &ctx);
- void blockMotion (DecodeContext &ctx);
- void blockRun (DecodeContext &ctx);
- void blockResidue (DecodeContext &ctx);
- void blockIntra (DecodeContext &ctx);
- void blockFill (DecodeContext &ctx);
- void blockInter (DecodeContext &ctx);
- void blockPattern (DecodeContext &ctx);
- void blockRaw (DecodeContext &ctx);
-
- // Read the bundles
- void readRuns (VideoFrame &video, Bundle &bundle);
- void readMotionValues(VideoFrame &video, Bundle &bundle);
- void readBlockTypes (VideoFrame &video, Bundle &bundle);
- void readPatterns (VideoFrame &video, Bundle &bundle);
- void readColors (VideoFrame &video, Bundle &bundle);
- void readDCS (VideoFrame &video, Bundle &bundle, int startBits, bool hasSign);
- void readDCTCoeffs (VideoFrame &video, int16 *block, bool isIntra);
- void readResidue (VideoFrame &video, int16 *block, int masksCount);
-
- void initAudioTrack(AudioTrack &audio);
-
- float getFloat(AudioTrack &audio);
-
- /** Decode an audio block. */
- void audioBlock (AudioTrack &audio, int16 *out);
- /** Decode a DCT'd audio block. */
- void audioBlockDCT (AudioTrack &audio);
- /** Decode a RDFT'd audio block. */
- void audioBlockRDFT(AudioTrack &audio);
-
- void readAudioCoeffs(AudioTrack &audio, float *coeffs);
-
- void floatToInt16Interleave(int16 *dst, const float **src, uint32 length, uint8 channels);
-
- // Bink video IDCT
- void IDCT(int16 *block);
- void IDCTPut(DecodeContext &ctx, int16 *block);
- void IDCTAdd(DecodeContext &ctx, int16 *block);
-
- /** Start playing the audio track */
- void startAudio();
- /** Stop playing the audio track */
- void stopAudio();
+ void initAudioTrack(AudioInfo &audio);
};
} // End of namespace Video