ScummVM API documentation
quicktime.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 //
23 // Heavily based on ffmpeg code.
24 //
25 // Copyright (c) 2001 Fabrice Bellard.
26 // First version by Francois Revol revol@free.fr
27 // Seek function by Gael Chardon gael.dev@4now.net
28 //
29 
30 #ifndef COMMON_QUICKTIME_H
31 #define COMMON_QUICKTIME_H
32 
33 #include "common/array.h"
34 #include "common/scummsys.h"
35 #include "common/path.h"
36 #include "common/stream.h"
37 #include "common/rational.h"
38 #include "common/types.h"
39 
40 namespace Common {
41  class MacResManager;
42 
58 public:
60  virtual ~QuickTimeParser();
61 
66  bool parseFile(const Path &filename);
67 
73  bool parseStream(SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle = DisposeAfterUse::YES);
74 
78  void close();
79 
85  void setChunkBeginOffset(uint32 offset) { _beginOffset = offset; }
86 
90  uint32 getTimeScale() const { return _timeScale; }
91 
93  bool isOpen() const { return _fd != nullptr; }
94 
95 protected:
96  // This is the file handle from which data is read from. It can be the actual file handle or a decompressed stream.
97  SeekableReadStream *_fd;
98 
100  int count;
101  int duration; // media time
102  };
103 
105  uint32 first;
106  uint32 count;
107  uint32 id;
108  };
109 
110  struct EditListEntry {
111  uint32 trackDuration; // movie time
112  uint32 timeOffset; // movie time
113  int32 mediaTime; // media time
114  Rational mediaRate;
115  };
116 
117  struct Track;
118 
119  class SampleDesc {
120  public:
121  SampleDesc(Track *parentTrack, uint32 codecTag);
122  virtual ~SampleDesc();
123 
124  uint32 getCodecTag() const { return _codecTag; }
125 
126  SeekableReadStream *_extraData;
127  byte _objectTypeMP4;
128 
129  protected:
130  Track *_parentTrack;
131  uint32 _codecTag;
132  };
133 
134  enum CodecType {
135  CODEC_TYPE_MOV_OTHER,
136  CODEC_TYPE_VIDEO,
137  CODEC_TYPE_AUDIO,
138  CODEC_TYPE_MIDI
139  };
140 
141  struct Track {
142  Track();
143  ~Track();
144 
145  uint32 chunkCount;
146  uint32 *chunkOffsets;
147  int timeToSampleCount;
148  TimeToSampleEntry *timeToSample;
149  uint32 sampleToChunkCount;
150  SampleToChunkEntry *sampleToChunk;
151  uint32 sampleSize;
152  uint32 sampleCount;
153  uint32 *sampleSizes;
154  uint32 keyframeCount;
155  uint32 *keyframes;
156  int32 timeScale; // media time
157 
158  uint16 width;
159  uint16 height;
160  CodecType codecType;
161 
162  Array<SampleDesc *> sampleDescs;
163 
165 
166  uint32 frameCount; // from stts
167  uint32 duration; // movie time
168  uint32 mediaDuration; // media time
169  Rational scaleFactorX;
170  Rational scaleFactorY;
171  };
172 
173  virtual SampleDesc *readSampleDesc(Track *track, uint32 format, uint32 descSize) = 0;
174 
175  uint32 _timeScale; // movie time
176  uint32 _duration; // movie time
177  Rational _scaleFactorX;
178  Rational _scaleFactorY;
179  Array<Track *> _tracks;
180 
181  void init();
182 
183 private:
184  struct Atom {
185  uint32 type;
186  uint32 offset;
187  uint32 size;
188  };
189 
190  struct ParseTable {
191  int (QuickTimeParser::*func)(Atom atom);
192  uint32 type;
193  };
194 
195  DisposeAfterUse::Flag _disposeFileHandle;
196  const ParseTable *_parseTable;
197  uint32 _beginOffset;
198  MacResManager *_resFork;
199  bool _foundMOOV;
200 
201  void initParseTable();
202 
203  int readDefault(Atom atom);
204  int readLeaf(Atom atom);
205  int readELST(Atom atom);
206  int readHDLR(Atom atom);
207  int readMDHD(Atom atom);
208  int readMOOV(Atom atom);
209  int readMVHD(Atom atom);
210  int readTKHD(Atom atom);
211  int readTRAK(Atom atom);
212  int readSTCO(Atom atom);
213  int readSTSC(Atom atom);
214  int readSTSD(Atom atom);
215  int readSTSS(Atom atom);
216  int readSTSZ(Atom atom);
217  int readSTTS(Atom atom);
218  int readCMOV(Atom atom);
219  int readWAVE(Atom atom);
220  int readESDS(Atom atom);
221  int readSMI(Atom atom);
222 };
223 
226 } // End of namespace Common
227 
228 #endif
Definition: macresman.h:59
Definition: array.h:52
Definition: quicktime.h:99
Definition: quicktime.h:119
Definition: quicktime.h:110
Definition: path.h:50
Definition: stream.h:652
Definition: rational.h:40
Definition: quicktime.h:57
Definition: quicktime.h:141
uint32 getTimeScale() const
Definition: quicktime.h:90
bool parseStream(SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle=DisposeAfterUse::YES)
Definition: achievements.h:31
Definition: quicktime.h:104
bool parseFile(const Path &filename)
void setChunkBeginOffset(uint32 offset)
Definition: quicktime.h:85
bool isOpen() const
Definition: quicktime.h:93