ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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() override;
69 
70  bool loadStream(Common::SeekableReadStream *stream) override;
71  void close() override;
72 
73 protected:
74  void readNextPacket() override;
75  bool useAudioSync() const override;
76 
77 private:
78  class PSXVideoTrack : public VideoTrack {
79  public:
80  PSXVideoTrack(Common::SeekableReadStream *firstSector, CDSpeed speed, int frameCount);
81  ~PSXVideoTrack() override;
82 
83  uint16 getWidth() const override { return _width; }
84  uint16 getHeight() const override { return _height; }
85  Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
86  bool setOutputPixelFormat(const Graphics::PixelFormat &format) override {
87  if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
88  return false;
89  _pixelFormat = format;
90  return true;
91  }
92  bool endOfTrack() const override { return _endOfTrack; }
93  int getCurFrame() const override { return _curFrame; }
94  int getFrameCount() const override { return _frameCount; }
95  uint32 getNextFrameStartTime() const override;
96  const Graphics::Surface *decodeNextFrame() override;
97 
98  void setEndOfTrack() { _endOfTrack = true; }
99  void decodeFrame(Common::BitStreamMemoryStream *frame, uint sectorCount);
100 
101  private:
102  Graphics::Surface *_surface;
103  Graphics::PixelFormat _pixelFormat;
104  uint16 _width;
105  uint16 _height;
106  uint32 _frameCount;
107  Audio::Timestamp _nextFrameStartTime;
108  bool _endOfTrack;
109  int _curFrame;
110 
111  enum PlaneType {
112  kPlaneY = 0,
113  kPlaneU = 1,
114  kPlaneV = 2
115  };
116 
118 
119  uint16 _macroBlocksW, _macroBlocksH;
120  byte *_yBuffer, *_cbBuffer, *_crBuffer;
121  void decodeMacroBlock(Common::BitStreamMemory16LEMSB *bits, int mbX, int mbY, uint16 scale, uint16 version);
122  void decodeBlock(Common::BitStreamMemory16LEMSB *bits, byte *block, int pitch, uint16 scale, uint16 version, PlaneType plane);
123 
124  void readAC(Common::BitStreamMemory16LEMSB *bits, int *block);
125  HuffmanDecoder *_acHuffman;
126 
127  int readDC(Common::BitStreamMemory16LEMSB *bits, uint16 version, PlaneType plane);
128  HuffmanDecoder *_dcHuffmanLuma, *_dcHuffmanChroma;
129  int _lastDC[3];
130 
131  void dequantizeBlock(int *coefficients, float *block, uint16 scale);
132  void idct(float *dequantData, float *result);
133  int readSignedCoefficient(Common::BitStreamMemory16LEMSB *bits);
134  };
135 
136  class PSXAudioTrack : public AudioTrack {
137  public:
138  PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType);
139  ~PSXAudioTrack() override;
140 
141  bool endOfTrack() const override;
142 
143  void setEndOfTrack() { _endOfTrack = true; }
144  void queueAudioFromSector(Common::SeekableReadStream *sector);
145 
146  private:
147  Audio::AudioStream *getAudioStream() const override;
148 
149  Audio::QueuingAudioStream *_audStream;
150 
151  bool _endOfTrack;
152  bool _stereo;
153  uint _rate;
154  };
155 
156  CDSpeed _speed;
157  uint32 _frameCount;
159  PSXVideoTrack *_videoTrack;
160  PSXAudioTrack *_audioTrack;
161 
162  Common::SeekableReadStream *readSector();
163 };
164 
165 } // End of namespace Video
166 
167 #endif
Definition: surface.h:67
Definition: pixelformat.h:138
Definition: video_decoder.h:723
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
byte bytesPerPixel
Definition: pixelformat.h:139
Definition: system.h:38
Definition: video_decoder.h:589