aboutsummaryrefslogtreecommitdiff
path: root/video/psx_decoder.h
diff options
context:
space:
mode:
authorMatthew Hoops2012-01-06 23:00:37 -0500
committerWillem Jan Palenstijn2012-02-23 22:48:16 +0100
commit307908662af4f171e442e3b6b209e72845f30c06 (patch)
tree45b976540e46224f75bd70d3db15496b985ff583 /video/psx_decoder.h
parent4222a728e16e07e1d0fa29d8ade2dfca608ce400 (diff)
downloadscummvm-rg350-307908662af4f171e442e3b6b209e72845f30c06.tar.gz
scummvm-rg350-307908662af4f171e442e3b6b209e72845f30c06.tar.bz2
scummvm-rg350-307908662af4f171e442e3b6b209e72845f30c06.zip
VIDEO: Add a PlayStation stream decoder
To be used for sword1/sword2 PSX video playback
Diffstat (limited to 'video/psx_decoder.h')
-rw-r--r--video/psx_decoder.h120
1 files changed, 120 insertions, 0 deletions
diff --git a/video/psx_decoder.h b/video/psx_decoder.h
new file mode 100644
index 0000000000..e8de507589
--- /dev/null
+++ b/video/psx_decoder.h
@@ -0,0 +1,120 @@
+/* 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.
+
+ * 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.
+ *
+ */
+
+#ifndef VIDEO_PSX_DECODER_H
+#define VIDEO_PSX_DECODER_H
+
+#include "common/endian.h"
+#include "common/rational.h"
+#include "common/rect.h"
+#include "common/str.h"
+#include "graphics/surface.h"
+#include "video/video_decoder.h"
+
+namespace Audio {
+class QueuingAudioStream;
+}
+
+namespace Common {
+class BitStream;
+class Huffman;
+class SeekableReadStream;
+}
+
+namespace Graphics {
+struct PixelFormat;
+}
+
+namespace Video {
+
+/**
+ * Decoder for PSX stream videos.
+ *
+ * Video decoder used in engines:
+ * - sword1 (psx)
+ * - sword2 (psx)
+ */
+class PSXStreamDecoder : public FixedRateVideoDecoder {
+public:
+ // CD speed in sectors/second
+ // Calling code should use these enum values instead of the constants
+ enum CDSpeed {
+ kCDUnk = 0,
+ kCD1x = 75,
+ kCD2x = 150
+ };
+
+ PSXStreamDecoder(Common::Rational frameRate);
+ PSXStreamDecoder(CDSpeed speed, uint32 frameCount);
+ virtual ~PSXStreamDecoder();
+
+ bool loadStream(Common::SeekableReadStream *stream);
+ void close();
+
+ bool isVideoLoaded() const { return _stream != 0; }
+ uint16 getWidth() const { return _surface->w; }
+ uint16 getHeight() const { return _surface->h; }
+ uint32 getFrameCount() const { return _frameCount; }
+ uint32 getElapsedTime() const;
+ const Graphics::Surface *decodeNextFrame();
+ Graphics::PixelFormat getPixelFormat() const { return _surface->format; }
+ bool endOfVideo() const { return _stream->pos() >= _stream->size(); }
+
+protected:
+ // Hardcoded frame rate
+ Common::Rational getFrameRate() const { return _frameRate; }
+
+private:
+ void initCommon();
+ Common::SeekableReadStream *_stream;
+ Graphics::Surface *_surface;
+
+ CDSpeed _speed;
+ uint32 _frameCount;
+ Common::Rational _frameRate;
+
+ Audio::SoundHandle _audHandle;
+ Audio::QueuingAudioStream *_audStream;
+ void queueAudioFromSector(Common::SeekableReadStream *sector);
+
+ Common::Huffman *_huffman;
+ uint16 _macroBlocksW, _macroBlocksH;
+ byte *_yBuffer, *_cbBuffer, *_crBuffer;
+ void decodeFrame(Common::SeekableReadStream *frame);
+ void decodeMacroBlock(Common::BitStream *bits, int mbX, int mbY, uint16 scale, uint16 version);
+ void decodeBlock(Common::BitStream *bits, byte *block, int pitch, uint16 scale, uint16 version);
+
+ void dequantizeBlock(int *coefficients, float *block, uint16 scale);
+ void readAC(Common::BitStream *bits, int *block);
+ void idct(float *dequantData, float *result);
+ int readSignedCoefficient(Common::BitStream *bits);
+
+ struct ADPCMStatus {
+ int16 sample[2];
+ } _adpcmStatus[2];
+
+ Common::SeekableReadStream *readSector();
+};
+
+} // End of namespace Video
+
+#endif