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
33namespace Audio {
34class QueuingAudioStream;
35}
36
37namespace Common {
38template <class BITSTREAM>
39class Huffman;
40}
41
42namespace Graphics {
43struct PixelFormat;
44}
45
46namespace Video {
47
59public:
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 ~PSXStreamDecoder() override;
69
70 bool loadStream(Common::SeekableReadStream *stream) override;
71 void close() override;
72
73protected:
74 void readNextPacket() override;
75 bool useAudioSync() const override;
76
77private:
78 class PSXVideoTrack : public VideoTrack {
79 public:
80 PSXVideoTrack(Common::SeekableReadStream *firstSector, CDSpeed speed, int frameCount, byte channel);
81 ~PSXVideoTrack() override;
82
83 byte getChannel() const { return _channel; }
84 uint16 getWidth() const override { return _width; }
85 uint16 getHeight() const override { return _height; }
86 Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
87 bool setOutputPixelFormat(const Graphics::PixelFormat &format) override {
88 if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
89 return false;
90 _pixelFormat = format;
91 return true;
92 }
93 bool endOfTrack() const override { return _endOfTrack; }
94 int getCurFrame() const override { return _curFrame; }
95 int getFrameCount() const override { return _frameCount; }
96 uint32 getNextFrameStartTime() const override;
97 const Graphics::Surface *decodeNextFrame() override;
98
99 void setEndOfTrack() { _endOfTrack = true; }
100 void decodeFrame(Common::BitStreamMemoryStream *frame, uint sectorCount);
101
102 private:
103 Graphics::Surface *_surface;
104 Graphics::PixelFormat _pixelFormat;
105 uint16 _width;
106 uint16 _height;
107 uint32 _frameCount;
108 Audio::Timestamp _nextFrameStartTime;
109 byte _channel;
110 bool _endOfTrack;
111 int _curFrame;
112
113 enum PlaneType {
114 kPlaneY = 0,
115 kPlaneU = 1,
116 kPlaneV = 2
117 };
118
120
121 uint16 _macroBlocksW, _macroBlocksH;
122 byte *_yBuffer, *_cbBuffer, *_crBuffer;
123 void decodeMacroBlock(Common::BitStreamMemory16LEMSB *bits, int mbX, int mbY, uint16 scale, uint16 version);
124 void decodeBlock(Common::BitStreamMemory16LEMSB *bits, byte *block, int pitch, uint16 scale, uint16 version, PlaneType plane);
125
126 void readAC(Common::BitStreamMemory16LEMSB *bits, int *block);
127 HuffmanDecoder *_acHuffman;
128
129 int readDC(Common::BitStreamMemory16LEMSB *bits, uint16 version, PlaneType plane);
130 HuffmanDecoder *_dcHuffmanLuma, *_dcHuffmanChroma;
131 int _lastDC[3];
132
133 void dequantizeBlock(int *coefficients, float *block, uint16 scale);
134 void idct(float *dequantData, float *result);
135 int readSignedCoefficient(Common::BitStreamMemory16LEMSB *bits);
136 };
137
138 class PSXAudioTrack : public AudioTrack {
139 public:
140 PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType, byte channel);
141 ~PSXAudioTrack() override;
142
143 byte getChannel() const { return _channel; }
144 bool endOfTrack() const override;
145
146 void setEndOfTrack() { _endOfTrack = true; }
147 void queueAudioFromSector(Common::SeekableReadStream *sector);
148
149 private:
150 Audio::AudioStream *getAudioStream() const override;
151
152 Audio::QueuingAudioStream *_audStream;
153
154 byte _channel;
155 bool _endOfTrack;
156 bool _stereo;
157 uint _rate;
158 };
159
160 CDSpeed _speed;
161 uint32 _frameCount;
163 PSXVideoTrack *_videoTrack;
164 PSXAudioTrack *_audioTrack;
165
166 Common::SeekableReadStream *readSector();
167};
168
169} // End of namespace Video
170
171#endif
Definition: audiostream.h:50
SoundType
Definition: mixer.h:73
Definition: audiostream.h:370
Definition: timestamp.h:83
Definition: bitstream.h:55
Definition: bitstream.h:339
Definition: huffman.h:60
Definition: stream.h:745
Definition: psx_decoder.h:58
bool useAudioSync() const override
void close() override
bool loadStream(Common::SeekableReadStream *stream) override
void readNextPacket() override
Definition: video_decoder.h:616
Definition: video_decoder.h:53
Graphics::PixelFormat getPixelFormat() const
virtual uint16 getHeight() const
bool setOutputPixelFormat(const Graphics::PixelFormat &format)
virtual const Graphics::Surface * decodeNextFrame()
int getCurFrame() const
uint32 getFrameCount() const
virtual uint16 getWidth() const
Definition: system.h:39
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: pixelformat.h:138
Definition: surface.h:67