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 
84  void flattenEditLists();
85 
91  void setChunkBeginOffset(uint32 offset) { _beginOffset = offset; }
92 
96  uint32 getTimeScale() const { return _timeScale; }
97 
99  bool isOpen() const { return _fd != nullptr; }
100 
101 protected:
102  // This is the file handle from which data is read from. It can be the actual file handle or a decompressed stream.
103  SeekableReadStream *_fd;
104 
106  int count;
107  int duration; // media time
108  };
109 
111  uint32 first;
112  uint32 count;
113  uint32 id;
114  };
115 
116  struct EditListEntry {
117  uint32 trackDuration; // movie time
118  uint32 timeOffset; // movie time
119  int32 mediaTime; // media time
120  Rational mediaRate;
121  };
122 
123  struct Track;
124 
125  class SampleDesc {
126  public:
127  SampleDesc(Track *parentTrack, uint32 codecTag);
128  virtual ~SampleDesc();
129 
130  uint32 getCodecTag() const { return _codecTag; }
131 
132  SeekableReadStream *_extraData;
133  byte _objectTypeMP4;
134 
135  protected:
136  Track *_parentTrack;
137  uint32 _codecTag;
138  };
139 
140  enum CodecType {
141  CODEC_TYPE_MOV_OTHER,
142  CODEC_TYPE_VIDEO,
143  CODEC_TYPE_AUDIO,
144  CODEC_TYPE_MIDI
145  };
146 
147  struct Track {
148  Track();
149  ~Track();
150 
151  uint32 chunkCount;
152  uint32 *chunkOffsets;
153  int timeToSampleCount;
154  TimeToSampleEntry *timeToSample;
155  uint32 sampleToChunkCount;
156  SampleToChunkEntry *sampleToChunk;
157  uint32 sampleSize;
158  uint32 sampleCount;
159  uint32 *sampleSizes;
160  uint32 keyframeCount;
161  uint32 *keyframes;
162  int32 timeScale; // media time
163 
164  uint16 width;
165  uint16 height;
166  CodecType codecType;
167 
168  Array<SampleDesc *> sampleDescs;
169 
171 
172  uint32 frameCount; // from stts
173  uint32 duration; // movie time
174  uint32 mediaDuration; // media time
175  Rational scaleFactorX;
176  Rational scaleFactorY;
177 
178  Common::String volume;
179  Common::String filename;
180  Common::String path;
181  Common::String directory;
182  int16 nlvlFrom;
183  int16 nlvlTo;
184  };
185 
186  virtual SampleDesc *readSampleDesc(Track *track, uint32 format, uint32 descSize) = 0;
187 
188  uint32 _timeScale; // movie time
189  uint32 _duration; // movie time
190  Rational _scaleFactorX;
191  Rational _scaleFactorY;
192  Array<Track *> _tracks;
193 
194  void init();
195 
196 private:
197  struct Atom {
198  uint32 type;
199  uint32 offset;
200  uint32 size;
201  };
202 
203  struct ParseTable {
204  int (QuickTimeParser::*func)(Atom atom);
205  uint32 type;
206  };
207 
208  DisposeAfterUse::Flag _disposeFileHandle;
209  const ParseTable *_parseTable;
210  uint32 _beginOffset;
211  MacResManager *_resFork;
212  bool _foundMOOV;
213 
214  void initParseTable();
215 
216  int readDefault(Atom atom);
217  int readLeaf(Atom atom);
218  int readDREF(Atom atom);
219  int readELST(Atom atom);
220  int readHDLR(Atom atom);
221  int readMDHD(Atom atom);
222  int readMOOV(Atom atom);
223  int readMVHD(Atom atom);
224  int readTKHD(Atom atom);
225  int readTRAK(Atom atom);
226  int readSTCO(Atom atom);
227  int readSTSC(Atom atom);
228  int readSTSD(Atom atom);
229  int readSTSS(Atom atom);
230  int readSTSZ(Atom atom);
231  int readSTTS(Atom atom);
232  int readCMOV(Atom atom);
233  int readWAVE(Atom atom);
234  int readESDS(Atom atom);
235  int readSMI(Atom atom);
236 };
237 
240 } // End of namespace Common
241 
242 #endif
Definition: macresman.h:125
Definition: str.h:59
Definition: array.h:52
Definition: quicktime.h:105
Definition: quicktime.h:125
Definition: quicktime.h:116
Definition: path.h:52
Definition: stream.h:745
Definition: rational.h:40
Definition: quicktime.h:57
Definition: quicktime.h:147
uint32 getTimeScale() const
Definition: quicktime.h:96
bool parseStream(SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle=DisposeAfterUse::YES)
Definition: algorithm.h:29
Definition: quicktime.h:110
bool parseFile(const Path &filename)
void setChunkBeginOffset(uint32 offset)
Definition: quicktime.h:91
bool isOpen() const
Definition: quicktime.h:99