xoreos  0.0.5
quicktime.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos 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 xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 /* Based on the Quicktime implementation in FFmpeg (<https://ffmpeg.org/)>,
26  * which is released under the terms of version 2 or later of the GNU
27  * Lesser General Public License.
28  *
29  * The original copyright note in libavformat/mov.c reads as follows:
30  *
31  * MOV demuxer
32  * Copyright (c) 2001 Fabrice Bellard
33  * Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
34  *
35  * first version by Francois Revol <revol@free.fr>
36  * seek function by Gael Chardon <gael.dev@4now.net>
37  *
38  * This file is part of FFmpeg.
39  *
40  * FFmpeg is free software; you can redistribute it and/or
41  * modify it under the terms of the GNU Lesser General Public
42  * License as published by the Free Software Foundation; either
43  * version 2.1 of the License, or (at your option) any later version.
44  *
45  * FFmpeg is distributed in the hope that it will be useful,
46  * but WITHOUT ANY WARRANTY; without even the implied warranty of
47  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
48  * Lesser General Public License for more details.
49  *
50  * You should have received a copy of the GNU Lesser General Public
51  * License along with FFmpeg; if not, write to the Free Software
52  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
53  */
54 
55 #ifndef VIDEO_QUICKTIME_H
56 #define VIDEO_QUICKTIME_H
57 
58 #include <vector>
59 
60 #include "src/common/types.h"
61 #include "src/common/ptrvector.h"
62 #include "src/common/scopedptr.h"
63 #include "src/common/timestamp.h"
64 
65 #include "src/sound/audiostream.h"
66 
67 #include "src/video/decoder.h"
68 
69 namespace Common {
70  class SeekableReadStream;
71 }
72 
73 namespace Graphics {
74  class Surface;
75 }
76 
77 namespace Video {
78 
79 class Codec;
80 
85 public:
88 
89 protected:
90  void decodeNextTrackFrame(VideoTrack &track);
91 
92 private:
93  // This is the file handle from which data is read from. It can be the actual file handle or a decompressed stream.
95 
96  struct Atom {
100  };
101 
102  struct ParseTable {
103  int (QuickTimeDecoder::*func)(Atom atom);
105  };
106 
108  int count;
109  int duration;
110  };
111 
116  };
117 
118  struct QuickTimeTrack;
119 
120  class SampleDesc {
121  public:
122  SampleDesc(QuickTimeTrack *parentTrack, uint32 codecTag);
123  virtual ~SampleDesc() {}
124 
125  uint32 getCodecTag() const { return _codecTag; }
126 
129 
130  protected:
133  };
134 
135  class AudioSampleDesc : public SampleDesc {
136  public:
137  AudioSampleDesc(QuickTimeTrack *parentTrack, uint32 codecTag);
138 
139  bool isAudioCodecSupported() const;
141 
142  // TODO: Make private in the long run
148  };
149 
150  class VideoSampleDesc : public SampleDesc {
151  public:
152  VideoSampleDesc(QuickTimeTrack *parentTrack, uint32 codecTag);
154 
155  void initCodec();
156 
157  // TODO: Make private in the long run
159  char _codecName[32];
163  };
164 
165  enum CodecType {
169  };
170 
171  struct QuickTimeTrack {
172  QuickTimeTrack();
173 
186 
190 
192 
196  };
197 
199  public:
200  QuickTimeAudioTrack(QuickTimeDecoder *decoder, QuickTimeTrack *parentTrack);
201 
202  // AudioStream API
203  size_t readBuffer(int16 *data, const size_t numSamples) { return _stream->readBuffer(data, numSamples); }
204  int getChannels() const { return _stream->getChannels(); }
205  int getRate() const { return _stream->getRate(); }
206  bool endOfData() const { return _stream->endOfData(); }
207  bool endOfStream() const { return _stream->endOfStream(); }
208 
209  // Queue *at least* "length" audio
210  // If length is zero, it queues the next logical block of audio whether
211  // that be a whole edit or just one chunk within an edit
212  void queueAudio(const Common::Timestamp &length = Common::Timestamp());
213 
214  private:
222 
224  bool isOldDemuxing() const;
225  uint32 getAudioChunkSampleCount(uint chunk) const;
226  Common::Timestamp getChunkLength(uint chunk, bool skipAACPrimer = false) const;
227  uint32 getAACSampleTime(uint32 totalSampleCount, bool skipAACPrimer = false) const;
228  bool allAudioQueued() const { return _curChunk >= _parentTrack->chunkCount; }
229  };
230 
231  class VideoTrackHandler : public VideoTrack {
232  public:
234 
236  uint32 getWidth() const;
237  uint32 getHeight() const;
238  int getCurFrame() const { return _curFrame; }
239  int getFrameCount() const;
241 
242  bool decodeNextFrame(Graphics::Surface &surface);
243 
244  private:
249 
252  };
253 
254  // The AudioTrackHandler is currently just a wrapper around some
255  // QuickTimeDecoder functions.
256  class AudioTrackHandler : public AudioTrack {
257  public:
259 
260  bool canBufferData() const;
261 
262  void updateBuffer(const Common::Timestamp &endTime);
263 
264  protected:
266 
267  private:
270  };
271 
273 
278 
279  void initParseTable();
280 
281  void checkAudioBuffer(AudioTrack &track, const Common::Timestamp &endTime);
283 
284  Codec *findDefaultVideoCodec() const;
286 
287  int readDefault(Atom atom);
288  int readLeaf(Atom atom);
289  int readELST(Atom atom);
290  int readHDLR(Atom atom);
291  int readMDHD(Atom atom);
292  int readMOOV(Atom atom);
293  int readMVHD(Atom atom);
294  int readTRAK(Atom atom);
295  int readSTCO(Atom atom);
296  int readSTSC(Atom atom);
297  int readSTSD(Atom atom);
298  int readSTSS(Atom atom);
299  int readSTSZ(Atom atom);
300  int readSTTS(Atom atom);
301  int readESDS(Atom atom);
302 
303  void load();
304 };
305 
306 } // End of namespace Video
307 
308 #endif // VIDEO_QUICKTIME_H
int readELST(Atom atom)
Definition: quicktime.cpp:407
Common::ScopedArray< TimeToSampleEntry > timeToSample
Definition: quicktime.h:177
void checkAudioBuffer(AudioTrack &track, const Common::Timestamp &endTime)
Ensure that there is enough audio buffered in the given track to reach the given timestamp.
Definition: quicktime.cpp:767
AudioSampleDesc(QuickTimeTrack *parentTrack, uint32 codecTag)
Definition: quicktime.cpp:705
Definition: 2dafile.h:39
An abstract representation of an audio track.
Definition: decoder.h:302
AudioTrackHandler(QuickTimeDecoder *decoder, QuickTimeAudioTrack *audioTrack)
Definition: quicktime.cpp:1070
bool decodeNextFrame(Graphics::Surface &surface)
Definition: quicktime.cpp:991
Common::Timestamp getChunkLength(uint chunk, bool skipAACPrimer=false) const
Definition: quicktime.cpp:924
VideoSampleDesc(QuickTimeTrack *parentTrack, uint32 codecTag)
Definition: quicktime.cpp:771
int getRate() const
Sample rate of the stream.
Definition: quicktime.h:205
int readMOOV(Atom atom)
Definition: quicktime.cpp:364
int getChannels() const
Return the number channels in this stream.
Definition: quicktime.h:204
Sound::PacketizedAudioStream * createAudioStream() const
Definition: quicktime.cpp:743
Common::ScopedPtr< Common::SeekableReadStream > _fd
Definition: quicktime.h:94
Common::ScopedArray< uint32 > chunkOffsets
Definition: quicktime.h:175
void updateBuffer(const Common::Timestamp &endTime)
Definition: quicktime.cpp:1074
Common::ScopedArray< byte > _palette
Definition: quicktime.h:161
int readSTSD(Atom atom)
Definition: quicktime.cpp:482
int getCurFrame() const
Get the current frame of this track.
Definition: quicktime.h:238
int readSTTS(Atom atom)
Definition: quicktime.cpp:583
Sound::AudioStream * getAudioStream() const
Definition: quicktime.cpp:1078
Common::ScopedArray< SampleToChunkEntry > sampleToChunk
Definition: quicktime.h:179
Common::SeekableReadStream * readAudioChunk(uint chunk)
Definition: quicktime.cpp:859
bool endOfData() const
End of data reached? If this returns true, it means that at this time there is no data available in t...
Definition: quicktime.h:206
Lossless timestamping.
uint32 getAACSampleTime(uint32 totalSampleCount, bool skipAACPrimer=false) const
Definition: quicktime.cpp:934
A generic interface for video decoders.
Definition: decoder.h:55
int16_t int16
Definition: types.h:201
int readMVHD(Atom atom)
Definition: quicktime.cpp:373
SampleDesc(QuickTimeTrack *parentTrack, uint32 codecTag)
Definition: quicktime.cpp:693
A simple scoped smart pointer template.
uint32 getHeight() const
Get the height of this track.
Definition: quicktime.cpp:976
A vector of pointer to objects, with automatic deletion.
Definition: ptrvector.h:44
VideoTrackHandler(QuickTimeDecoder *decoder, QuickTimeTrack *parent)
Definition: quicktime.cpp:965
int readLeaf(Atom atom)
Definition: quicktime.cpp:357
int readMDHD(Atom atom)
Definition: quicktime.cpp:455
Common::PtrVector< SampleDesc > sampleDescs
Definition: quicktime.h:191
QuickTimeDecoder(Common::SeekableReadStream *stream)
Definition: quicktime.cpp:97
uint16_t uint16
Definition: types.h:202
int readSTSZ(Atom atom)
Definition: quicktime.cpp:560
An AudioStream designed to work in terms of packets.
Definition: audiostream.h:271
Common::Timestamp getDuration() const
Get the duration of the track.
Definition: quicktime.cpp:968
void queueAudio(const Common::Timestamp &length=Common::Timestamp())
Definition: quicktime.cpp:835
Common::ScopedPtr< Codec > _videoCodec
Definition: quicktime.h:162
Common::ScopedPtr< Sound::PacketizedAudioStream > _stream
Definition: quicktime.h:221
uint32 getWidth() const
Get the width of this track.
Definition: quicktime.cpp:972
Low-level type definitions to handle fixed width types portably.
An abstract representation of a video track.
Definition: decoder.h:226
A vector storing pointer to objects, with automatic deletion.
SampleDesc * readSampleDesc(QuickTimeTrack *track, uint32 format)
Definition: quicktime.cpp:157
size_t readBuffer(int16 *data, const size_t numSamples)
Fill the given buffer with up to numSamples samples.
Definition: quicktime.h:203
Common::ScopedArray< uint32 > sampleSizes
Definition: quicktime.h:182
Common::ScopedArray< uint32 > keyframes
Definition: quicktime.h:184
int readSTSS(Atom atom)
Definition: quicktime.cpp:542
Common::Timestamp getNextFrameStartTime() const
Get the start time of the next frame since the start of the video.
Definition: quicktime.cpp:984
int readTRAK(Atom atom)
Definition: quicktime.cpp:393
Generic audio input stream.
Definition: audiostream.h:70
QuickTimeAudioTrack(QuickTimeDecoder *decoder, QuickTimeTrack *parentTrack)
Definition: quicktime.cpp:819
int readHDLR(Atom atom)
Definition: quicktime.cpp:424
void decodeNextTrackFrame(VideoTrack &track)
Decode enough data for the next frame.
Definition: quicktime.cpp:253
Common::PtrVector< QuickTimeTrack > _tracks
Definition: quicktime.h:277
uint32_t uint32
Definition: types.h:204
Common::ScopedPtr< Common::SeekableReadStream > _extraData
Definition: quicktime.h:127
Decoder for QuickTime videos.
Definition: quicktime.h:84
int readSTSC(Atom atom)
Definition: quicktime.cpp:519
Timestamps allow specifying points in time and measuring time intervals with a sub-millisecond granul...
Definition: timestamp.h:108
bool endOfStream() const
End of stream reached? If this returns true, it means that all data in this stream is used up and no ...
Definition: quicktime.h:207
int readDefault(Atom atom)
Definition: quicktime.cpp:289
Common::PtrVector< QuickTimeAudioTrack > _audioTracks
Definition: quicktime.h:282
uint32 getAudioChunkSampleCount(uint chunk) const
Definition: quicktime.cpp:914
const ParseTable * _parseTable
Definition: quicktime.h:274
Common::SeekableReadStream * getNextFramePacket(uint32 &descId)
Definition: quicktime.cpp:1011
int(QuickTimeDecoder::* func)(Atom atom)
Definition: quicktime.h:103
Interface for a seekable & readable data stream.
Definition: readstream.h:265
Streaming audio.
int readSTCO(Atom atom)
Definition: quicktime.cpp:605
Codec * findDefaultVideoCodec() const
Definition: quicktime.cpp:246
uint8 byte
Definition: types.h:209
int getFrameCount() const
Get the frame count of this track.
Definition: quicktime.cpp:980
unsigned int uint
Definition: types.h:211
int readESDS(Atom atom)
Definition: quicktime.cpp:650
Generic video decoder interface.
int32_t int32
Definition: types.h:203