ScummVM API documentation
mkv_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_VPX
23
24#ifdef USE_VPX
25
26#ifndef VIDEO_MKV_DECODER_H
27#define VIDEO_MKV_DECODER_H
28
29#include "common/queue.h"
30#include "video/video_decoder.h"
31#include "audio/mixer.h"
32#include "graphics/surface.h"
33
34#ifdef USE_TREMOR
35#include <tremor/ivorbiscodec.h>
36#else
37#include <vorbis/codec.h>
38#endif
39
40#include <vpx/vpx_decoder.h>
41#include <vpx/vp8dx.h>
42
43
44namespace Common {
45class SeekableReadStream;
46}
47
48namespace Audio {
49class AudioStream;
50class QueuingAudioStream;
51}
52
53namespace mkvparser {
54class MkvReader;
55class Cluster;
56class Track;
57class Tracks;
58class Block;
59class BlockEntry;
60class Segment;
61}
62
63namespace Video {
64
65class MkvReader;
66
73class MKVDecoder : public VideoDecoder {
74public:
75 MKVDecoder();
76 virtual ~MKVDecoder();
77
82 bool loadStream(Common::SeekableReadStream *stream) override;
83 void close() override;
84
85protected:
86 void readNextPacket() override;
87
88private:
89 class VPXVideoTrack : public VideoTrack {
90 public:
91 VPXVideoTrack(const mkvparser::Track *const pTrack);
92 ~VPXVideoTrack();
93
94 bool endOfTrack() const override;
95 uint16 getWidth() const override { return _width; }
96 uint16 getHeight() const override { return _height; }
97 Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
98 bool setOutputPixelFormat(const Graphics::PixelFormat &format) override {
99 if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
100 return false;
101 _pixelFormat = format;
102 return true;
103 }
104
105 int getCurFrame() const override { return _curFrame; }
106 uint32 getNextFrameStartTime() const override { return (uint32)(_nextFrameStartTime * 1000); }
107 const Graphics::Surface *decodeNextFrame() override;
108 bool decodeFrame(byte *frame, long size);
109 void setEndOfVideo() { _endOfVideo = true; }
110
111 private:
112 int _curFrame;
113 bool _endOfVideo;
114 double _nextFrameStartTime;
115
116 uint16 _width;
117 uint16 _height;
118 Graphics::PixelFormat _pixelFormat;
119
120 Graphics::Surface _surface;
122
123 vpx_codec_ctx_t *_codec = nullptr;
124 };
125
126 class VorbisAudioTrack : public AudioTrack {
127 public:
128 VorbisAudioTrack(const mkvparser::Track *const pTrack);
129 ~VorbisAudioTrack();
130
131 bool decodeSamples(byte *frame, long size);
132 bool hasAudio() const;
133 bool needsAudio() const;
134 bool synthesizePacket(byte *frame, long size);
135 void setEndOfAudio() { _endOfAudio = true; }
136
137 protected:
138 Audio::AudioStream *getAudioStream() const override;
139
140 private:
141 Audio::QueuingAudioStream *_audStream;
142
143 vorbis_block _vorbisBlock;
144 vorbis_dsp_state _vorbisDSP;
145
146 vorbis_info _vorbisInfo;
147 bool _endOfAudio;
148
149 ogg_packet oggPacket;
150 };
151
152 bool queueAudio(long size);
153
154 Common::SeekableReadStream *_fileStream;
155
156 bool _hasVideo, _hasAudio;
157
158 VPXVideoTrack *_videoTrack = nullptr;
159 VorbisAudioTrack *_audioTrack = nullptr;
160
161 mkvparser::MkvReader *_reader = nullptr;
162
163 const mkvparser::Cluster *_cluster = nullptr;
164 const mkvparser::Tracks *_pTracks = nullptr;
165 const mkvparser::BlockEntry *_pBlockEntry = nullptr;
166 mkvparser::Segment *_pSegment = nullptr;
167
168 byte *_frame = nullptr;
169 int _frameCounter = 0;
170
171 int _vTrack = -1;
172 int _aTrack = -1;
173
174 const mkvparser::Block *_pBlock;
175 long long _trackNum;
176 int _frameCount;
177};
178
179} // End of namespace Video
180
181#endif
182
183#endif
Definition: audiostream.h:50
Definition: audiostream.h:370
Definition: queue.h:42
Definition: stream.h:745
Definition: mkvparser.h:119
Definition: mkvparser.h:71
Definition: mkvparser.h:970
Definition: mkvparser.h:1050
Definition: mkvparser.h:299
Definition: mkvparser.h:566
Definition: system.h:39
Definition: algorithm.h:29
Definition: pixelformat.h:138
Definition: surface.h:67