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


Generated on Sat Jul 20 2019 05:01:03 for ResidualVM by doxygen 1.7.1
curved edge   curved edge