ScummVM API documentation
theora_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#include "common/scummsys.h" // for USE_THEORADEC
23
24#ifdef USE_THEORADEC
25
26#ifndef VIDEO_THEORA_DECODER_H
27#define VIDEO_THEORA_DECODER_H
28
29#include "common/rational.h"
30#include "video/video_decoder.h"
31#include "audio/mixer.h"
32#include "graphics/surface.h"
33
34#include <theora/theoradec.h>
35
36#ifdef USE_TREMOR
37#include <tremor/ivorbiscodec.h>
38#else
39#include <vorbis/codec.h>
40#endif
41
42namespace Common {
43class SeekableReadStream;
44}
45
46namespace Audio {
47class AudioStream;
48class QueuingAudioStream;
49}
50
51namespace Video {
52
65class TheoraDecoder : public VideoDecoder {
66public:
67 TheoraDecoder();
68 virtual ~TheoraDecoder();
69
74 bool loadStream(Common::SeekableReadStream *stream) override;
75 void close() override;
76
78 Common::Rational getFrameRate() const;
79
80protected:
81 void readNextPacket() override;
82
83private:
84 class TheoraVideoTrack : public VideoTrack {
85 public:
86 TheoraVideoTrack(th_info &theoraInfo, th_setup_info *theoraSetup);
87 ~TheoraVideoTrack();
88
89 bool endOfTrack() const override { return _endOfVideo; }
90 uint16 getWidth() const override { return _width; }
91 uint16 getHeight() const override { return _height; }
92 Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
93 bool setOutputPixelFormat(const Graphics::PixelFormat &format) override {
94 if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
95 return false;
96 _pixelFormat = format;
97 return true;
98 }
99
100 int getCurFrame() const override { return _curFrame; }
101 const Common::Rational &getFrameRate() const { return _frameRate; }
102 uint32 getNextFrameStartTime() const override { return (uint32)(_nextFrameStartTime * 1000); }
103 const Graphics::Surface *decodeNextFrame() override { return _displaySurface; }
104
105 bool decodePacket(ogg_packet &oggPacket);
106 void setEndOfVideo() { _endOfVideo = true; }
107
108 private:
109 int _curFrame;
110 bool _endOfVideo;
111 Common::Rational _frameRate;
112 double _nextFrameStartTime;
113
114 Graphics::Surface *_surface;
115 Graphics::Surface *_displaySurface;
116 Graphics::PixelFormat _pixelFormat;
117 int _x;
118 int _y;
119 uint16 _width;
120 uint16 _height;
121 uint16 _surfaceWidth;
122 uint16 _surfaceHeight;
123
124 th_dec_ctx *_theoraDecode;
125 th_pixel_fmt _theoraPixelFormat;
126
127 void translateYUVtoRGBA(th_ycbcr_buffer &YUVBuffer);
128 };
129
130 class VorbisAudioTrack : public AudioTrack {
131 public:
132 VorbisAudioTrack(Audio::Mixer::SoundType soundType, vorbis_info &vorbisInfo);
133 ~VorbisAudioTrack();
134
135 bool decodeSamples();
136 bool hasAudio() const;
137 bool needsAudio() const;
138 void synthesizePacket(ogg_packet &oggPacket);
139 void setEndOfAudio() { _endOfAudio = true; }
140
141 protected:
142 Audio::AudioStream *getAudioStream() const override;
143
144 private:
145 // single audio fragment audio buffering
146 int _audioBufferFill;
147 ogg_int16_t *_audioBuffer;
148
149 Audio::QueuingAudioStream *_audStream;
150
151 vorbis_block _vorbisBlock;
152 vorbis_dsp_state _vorbisDSP;
153
154 bool _endOfAudio;
155 };
156
157 void queuePage(ogg_page *page);
158 int bufferData();
159 bool queueAudio();
160 void ensureAudioBufferSize();
161
162 Common::SeekableReadStream *_fileStream;
163
164 ogg_sync_state _oggSync;
165 ogg_page _oggPage;
166 ogg_packet _oggPacket;
167
168 ogg_stream_state _theoraOut, _vorbisOut;
169 bool _hasVideo, _hasAudio;
170
171 vorbis_info _vorbisInfo;
172
173 TheoraVideoTrack *_videoTrack;
174 VorbisAudioTrack *_audioTrack;
175};
176
177} // End of namespace Video
178
179#endif
180
181#endif
Definition: audiostream.h:50
SoundType
Definition: mixer.h:73
Definition: audiostream.h:370
Definition: rational.h:40
Definition: stream.h:745
Definition: system.h:39
Definition: algorithm.h:29
Definition: pixelformat.h:138
Definition: surface.h:67