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

psx_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_PSX_DECODER_H
00024 #define VIDEO_PSX_DECODER_H
00025 
00026 #include "common/bitstream.h"
00027 #include "common/endian.h"
00028 #include "common/rational.h"
00029 #include "common/rect.h"
00030 #include "common/str.h"
00031 #include "graphics/surface.h"
00032 #include "video/video_decoder.h"
00033 
00034 namespace Audio {
00035 class QueuingAudioStream;
00036 }
00037 
00038 namespace Common {
00039 class Huffman;
00040 }
00041 
00042 namespace Graphics {
00043 struct PixelFormat;
00044 }
00045 
00046 namespace Video {
00047 
00058 class PSXStreamDecoder : public VideoDecoder {
00059 public:
00060     // CD speed in sectors/second
00061     // Calling code should use these enum values instead of the constants
00062     enum CDSpeed {
00063         kCD1x = 75,
00064         kCD2x = 150
00065     };
00066 
00067     PSXStreamDecoder(CDSpeed speed, uint32 frameCount = 0);
00068     virtual ~PSXStreamDecoder();
00069 
00070     bool loadStream(Common::SeekableReadStream *stream);
00071     void close();
00072 
00073 protected:
00074     void readNextPacket();
00075     bool useAudioSync() const;
00076 
00077 private:
00078     class PSXVideoTrack : public VideoTrack {
00079     public:
00080         PSXVideoTrack(Common::SeekableReadStream *firstSector, CDSpeed speed, int frameCount);
00081         ~PSXVideoTrack();
00082 
00083         uint16 getWidth() const { return _surface->w; }
00084         uint16 getHeight() const { return _surface->h; }
00085         Graphics::PixelFormat getPixelFormat() const { return _surface->format; }
00086         bool endOfTrack() const { return _endOfTrack; }
00087         int getCurFrame() const { return _curFrame; }
00088         int getFrameCount() const { return _frameCount; }
00089         uint32 getNextFrameStartTime() const;
00090         const Graphics::Surface *decodeNextFrame();
00091 
00092         void setEndOfTrack() { _endOfTrack = true; }
00093         void decodeFrame(Common::BitStreamMemoryStream *frame, uint sectorCount);
00094 
00095     private:
00096         Graphics::Surface *_surface;
00097         uint32 _frameCount;
00098         Audio::Timestamp _nextFrameStartTime;
00099         bool _endOfTrack;
00100         int _curFrame;
00101 
00102         enum PlaneType {
00103             kPlaneY = 0,
00104             kPlaneU = 1,
00105             kPlaneV = 2
00106         };
00107 
00108         uint16 _macroBlocksW, _macroBlocksH;
00109         byte *_yBuffer, *_cbBuffer, *_crBuffer;
00110         void decodeMacroBlock(Common::BitStreamMemory16LEMSB *bits, int mbX, int mbY, uint16 scale, uint16 version);
00111         void decodeBlock(Common::BitStreamMemory16LEMSB *bits, byte *block, int pitch, uint16 scale, uint16 version, PlaneType plane);
00112 
00113         void readAC(Common::BitStreamMemory16LEMSB *bits, int *block);
00114         Common::Huffman *_acHuffman;
00115 
00116         int readDC(Common::BitStreamMemory16LEMSB *bits, uint16 version, PlaneType plane);
00117         Common::Huffman *_dcHuffmanLuma, *_dcHuffmanChroma;
00118         int _lastDC[3];
00119 
00120         void dequantizeBlock(int *coefficients, float *block, uint16 scale);
00121         void idct(float *dequantData, float *result);
00122         int readSignedCoefficient(Common::BitStreamMemory16LEMSB *bits);
00123     };
00124 
00125     class PSXAudioTrack : public AudioTrack {
00126     public:
00127         PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType);
00128         ~PSXAudioTrack();
00129 
00130         bool endOfTrack() const;
00131 
00132         void setEndOfTrack() { _endOfTrack = true; }
00133         void queueAudioFromSector(Common::SeekableReadStream *sector);
00134 
00135     private:
00136         Audio::AudioStream *getAudioStream() const;
00137 
00138         Audio::QueuingAudioStream *_audStream;
00139 
00140         struct ADPCMStatus {
00141             int16 sample[2];
00142         } _adpcmStatus[2];
00143 
00144         bool _endOfTrack;
00145     };
00146 
00147     CDSpeed _speed;
00148     uint32 _frameCount;
00149     Common::SeekableReadStream *_stream;
00150     PSXVideoTrack *_videoTrack;
00151     PSXAudioTrack *_audioTrack;
00152 
00153     Common::SeekableReadStream *readSector();
00154 };
00155 
00156 } // End of namespace Video
00157 
00158 #endif


Generated on Sat Feb 9 2019 05:00:38 for ResidualVM by doxygen 1.7.1
curved edge   curved edge