ScummVM API documentation
psx_decoder.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef VIDEO_PSX_DECODER_H
23 #define VIDEO_PSX_DECODER_H
24 
25 #include "common/bitstream.h"
26 #include "common/endian.h"
27 #include "common/rational.h"
28 #include "common/rect.h"
29 #include "common/str.h"
30 #include "graphics/surface.h"
31 #include "video/video_decoder.h"
32 
33 namespace Audio {
34 class QueuingAudioStream;
35 }
36 
37 namespace Common {
38 template <class BITSTREAM>
39 class Huffman;
40 }
41 
42 namespace Graphics {
43 struct PixelFormat;
44 }
45 
46 namespace Video {
47 
59 public:
60  // CD speed in sectors/second
61  // Calling code should use these enum values instead of the constants
62  enum CDSpeed {
63  kCD1x = 75,
64  kCD2x = 150
65  };
66 
67  PSXStreamDecoder(CDSpeed speed, uint32 frameCount = 0);
68  virtual ~PSXStreamDecoder();
69 
70  bool loadStream(Common::SeekableReadStream *stream);
71  void close();
72 
73 protected:
74  void readNextPacket();
75  bool useAudioSync() const;
76 
77 private:
78  class PSXVideoTrack : public VideoTrack {
79  public:
80  PSXVideoTrack(Common::SeekableReadStream *firstSector, CDSpeed speed, int frameCount);
81  ~PSXVideoTrack();
82 
83  uint16 getWidth() const { return _width; }
84  uint16 getHeight() const { return _height; }
85  Graphics::PixelFormat getPixelFormat() const { return _pixelFormat; }
86  bool setOutputPixelFormat(const Graphics::PixelFormat &format) { _pixelFormat = format; return true; }
87  bool endOfTrack() const { return _endOfTrack; }
88  int getCurFrame() const { return _curFrame; }
89  int getFrameCount() const { return _frameCount; }
90  uint32 getNextFrameStartTime() const;
91  const Graphics::Surface *decodeNextFrame();
92 
93  void setEndOfTrack() { _endOfTrack = true; }
94  void decodeFrame(Common::BitStreamMemoryStream *frame, uint sectorCount);
95 
96  private:
97  Graphics::Surface *_surface;
98  Graphics::PixelFormat _pixelFormat;
99  uint16 _width;
100  uint16 _height;
101  uint32 _frameCount;
102  Audio::Timestamp _nextFrameStartTime;
103  bool _endOfTrack;
104  int _curFrame;
105 
106  enum PlaneType {
107  kPlaneY = 0,
108  kPlaneU = 1,
109  kPlaneV = 2
110  };
111 
113 
114  uint16 _macroBlocksW, _macroBlocksH;
115  byte *_yBuffer, *_cbBuffer, *_crBuffer;
116  void decodeMacroBlock(Common::BitStreamMemory16LEMSB *bits, int mbX, int mbY, uint16 scale, uint16 version);
117  void decodeBlock(Common::BitStreamMemory16LEMSB *bits, byte *block, int pitch, uint16 scale, uint16 version, PlaneType plane);
118 
119  void readAC(Common::BitStreamMemory16LEMSB *bits, int *block);
120  HuffmanDecoder *_acHuffman;
121 
122  int readDC(Common::BitStreamMemory16LEMSB *bits, uint16 version, PlaneType plane);
123  HuffmanDecoder *_dcHuffmanLuma, *_dcHuffmanChroma;
124  int _lastDC[3];
125 
126  void dequantizeBlock(int *coefficients, float *block, uint16 scale);
127  void idct(float *dequantData, float *result);
128  int readSignedCoefficient(Common::BitStreamMemory16LEMSB *bits);
129  };
130 
131  class PSXAudioTrack : public AudioTrack {
132  public:
133  PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType);
134  ~PSXAudioTrack();
135 
136  bool endOfTrack() const;
137 
138  void setEndOfTrack() { _endOfTrack = true; }
139  void queueAudioFromSector(Common::SeekableReadStream *sector);
140 
141  private:
142  Audio::AudioStream *getAudioStream() const;
143 
144  Audio::QueuingAudioStream *_audStream;
145 
146  bool _endOfTrack;
147  bool _stereo;
148  uint _rate;
149  };
150 
151  CDSpeed _speed;
152  uint32 _frameCount;
154  PSXVideoTrack *_videoTrack;
155  PSXAudioTrack *_audioTrack;
156 
157  Common::SeekableReadStream *readSector();
158 };
159 
160 } // End of namespace Video
161 
162 #endif
Definition: surface.h:67
Definition: pixelformat.h:138
Definition: video_decoder.h:711
Definition: timestamp.h:83
Definition: stream.h:745
Definition: psx_decoder.h:58
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
SoundType
Definition: mixer.h:62
Definition: video_decoder.h:53
Definition: huffman.h:59
Definition: bitstream.h:55
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: audiostream.h:50
Definition: audiostream.h:370
Definition: bitstream.h:337
Definition: avi_frames.h:36
Definition: system.h:38
Definition: video_decoder.h:577