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 #include "common/rect.h"
40 
41 namespace Common {
42  class MacResManager;
43 
59 public:
61  virtual ~QuickTimeParser();
62 
67  bool parseFile(const Path &filename);
68 
74  bool parseStream(SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle = DisposeAfterUse::YES);
75 
79  void close();
80 
85  void flattenEditLists();
86 
92  void setChunkBeginOffset(uint32 offset) { _beginOffset = offset; }
93 
97  uint32 getTimeScale() const { return _timeScale; }
98 
100  bool isOpen() const { return _fd != nullptr; }
101 
102  enum class QTVRType {
103  OTHER,
104  OBJECT,
105  PANORAMA
106  };
107 
108 protected:
109  // This is the file handle from which data is read from. It can be the actual file handle or a decompressed stream.
110  SeekableReadStream *_fd;
111 
113  int count;
114  int duration; // media time
115  };
116 
118  uint32 first;
119  uint32 count;
120  uint32 id;
121  };
122 
123  struct EditListEntry {
124  uint32 trackDuration; // movie time
125  uint32 timeOffset; // movie time
126  int32 mediaTime; // media time
127  Rational mediaRate;
128  };
129 
130  struct Track;
131 
132  class SampleDesc {
133  public:
134  SampleDesc(Track *parentTrack, uint32 codecTag);
135  virtual ~SampleDesc();
136 
137  uint32 getCodecTag() const { return _codecTag; }
138 
139  SeekableReadStream *_extraData;
140  byte _objectTypeMP4;
141 
142  protected:
143  Track *_parentTrack;
144  uint32 _codecTag;
145  };
146 
147  enum CodecType {
148  CODEC_TYPE_MOV_OTHER,
149  CODEC_TYPE_VIDEO,
150  CODEC_TYPE_AUDIO,
151  CODEC_TYPE_MIDI,
152  CODEC_TYPE_PANO
153  };
154 
155  enum class GraphicsMode {
156  COPY = 0x0, // Directly copy the source image over the destination.
157  DITHER_COPY = 0x40, // Dither the image (if needed), otherwise copy.
158  BLEND = 0x20, // Blend source and destination pixel colors using opcolor values.
159  TRANSPARENT = 0x24, // Replace destination with source if not equal to opcolor.
160  STRAIGHT_ALPHA = 0x100, // Blend source and destination pixels, with the proportion controlled by the alpha channel.
161  PREMUL_WHITE_ALPHA = 0x101, // Blend after removing pre-multiplied white from the source.
162  PREMUL_BLACK_ALPHA = 0x102, // Blend after removing pre-multiplied black from the source.
163  STRAIGHT_ALPHA_BLEND = 0x104, // Similar to straight alpha, but the alpha for each channel is combined with the corresponding opcolor channel.
164  COMPOSITION = 0x103 // Render offscreen and then dither-copy to the main screen (tracks only).
165  };
166 
167  struct PanoramaNode {
168  uint32 nodeID;
169  uint32 timestamp;
170  };
171 
173  String name;
174  uint32 defNodeID;
175  float defZoom;
176  Array<PanoramaNode> nodes;
177  };
178 
180  uint32 nodeID;
181 
182  float defHPan;
183  float defVPan;
184  float defZoom;
185 
186  // Constraints for this node; zero for default
187  float minHPan;
188  float minVPan;
189  float maxHPan;
190  float maxVPan;
191  float minZoom;
192 
193  int32 nameStrOffset;
194  int32 commentStrOffset;
195  };
196 
197  enum class HotSpotType {
198  undefined,
199  link,
200  navg
201  };
202 
203  struct PanoHotSpot {
204  uint16 id;
205  HotSpotType type;
206  uint32 typeData; // for link and navg, the ID in the link and navg table
207 
208  // Canonical view for this hotspot
209  float viewHPan;
210  float viewVPan;
211  float viewZoom;
212 
213  Rect rect;
214 
215  int32 mouseOverCursorID;
216  int32 mouseDownCursorID;
217  int32 mouseUpCursorID;
218 
219  int32 nameStrOffset;
220  int32 commentStrOffset;
221  };
222 
224  Array<PanoHotSpot> hotSpots;
225  };
226 
228  String strings;
229 
230  String getString(int32 offset) const;
231  };
232 
233  struct PanoLink {
234  uint16 id;
235  uint16 toNodeID;
236 
237  // Values to set at the destination node
238  float toHPan;
239  float toVPan;
240  float toZoom;
241 
242  int32 nameStrOffset;
243  int32 commentStrOffset;
244  };
245 
246  struct PanoLinkTable {
247  Array<PanoLink> links;
248  };
249 
250  struct PanoNavigation {
251  uint16 id;
252 
253  uint32 hPan;
254  uint32 vPan;
255  uint32 zoom;
256 
257  Rect rect; // Starting rect for zoom out transitions
258 
259  // Values to set at the destination node
260  int32 nameStrOffset;
261  int32 commentStrOffset;
262  };
263 
266  };
267 
269  PanoSampleHeader hdr;
270  PanoHotSpotTable hotSpotTable;
271  PanoStringTable strTable;
272  PanoLinkTable linkTable;
273  PanoNavigationTable navTable;
274  };
275 
276  struct Track {
277  Track();
278  ~Track();
279 
280  uint32 chunkCount;
281  uint32 *chunkOffsets;
282  int timeToSampleCount;
283  TimeToSampleEntry *timeToSample;
284  uint32 sampleToChunkCount;
285  SampleToChunkEntry *sampleToChunk;
286  uint32 sampleSize;
287  uint32 sampleCount;
288  uint32 *sampleSizes;
289  uint32 keyframeCount;
290  uint32 *keyframes;
291  int32 timeScale; // media time
292 
293  uint16 width;
294  uint16 height;
295  CodecType codecType;
296 
297  Array<SampleDesc *> sampleDescs;
298 
300 
301  uint32 frameCount; // from stts
302  uint32 duration; // movie time
303  uint32 mediaDuration; // media time
304  Rational scaleFactorX;
305  Rational scaleFactorY;
306 
307  Common::String volume;
308  Common::String filename;
309  Common::String path;
310  Common::String directory;
311  int16 nlvlFrom;
312  int16 nlvlTo;
313 
314  PanoramaInformation panoInfo;
315  Array<PanoTrackSample> panoSamples;
316 
317  GraphicsMode graphicsMode; // Transfer mode
318  uint16 opcolor[3]; // RGB values used in the transfer mode specified by graphicsMode.
319 
320  uint16 soundBalance; // Controls the sound mix between the computer's two speakers, usually set to 0.
321  };
322 
323  enum class MovieType {
324  kStandardObject = 1,
325  kOldNavigableMovieScene,
326  kObjectInScene
327  };
328 
329  struct Navigation {
330  uint16 columns;
331  uint16 rows;
332  uint16 loop_size; // Number of frames shot at each position
333  uint16 frame_duration;
334 
335  MovieType movie_type;
336 
337  uint16 loop_ticks; // Number of ticks before next frame of loop is displayed
338 
339  float field_of_view;
340 
341  float startHPan;
342  float startVPan;
343  float endHPan;
344  float endVPan;
345  float initialHPan;
346  float initialVPan;
347  };
348 
349  virtual SampleDesc *readSampleDesc(Track *track, uint32 format, uint32 descSize) = 0;
350 
351  uint32 _timeScale; // movie time
352  uint32 _duration; // movie time
353  Rational _scaleFactorX;
354  Rational _scaleFactorY;
355  Array<Track *> _tracks;
356  Navigation _nav;
357  QTVRType _qtvrType;
358  uint16 _winX;
359  uint16 _winY;
360 
361  Track *_panoTrack;
362 
363  void init();
364 
365 private:
366  struct Atom {
367  uint32 type;
368  uint32 offset;
369  uint32 size;
370  };
371 
372  struct ParseTable {
373  int (QuickTimeParser::*func)(Atom atom);
374  uint32 type;
375  };
376 
377  DisposeAfterUse::Flag _disposeFileHandle;
378  const ParseTable *_parseTable;
379  uint32 _beginOffset;
380  MacResManager *_resFork;
381  bool _foundMOOV;
382 
383  void initParseTable();
384 
385  bool parsePanoramaAtoms();
386 
387  int readDefault(Atom atom);
388  int readLeaf(Atom atom);
389  int readDREF(Atom atom);
390  int readELST(Atom atom);
391  int readHDLR(Atom atom);
392  int readMDHD(Atom atom);
393  int readMOOV(Atom atom);
394  int readMVHD(Atom atom);
395  int readTKHD(Atom atom);
396  int readTRAK(Atom atom);
397  int readSMHD(Atom atom);
398  int readSTCO(Atom atom);
399  int readSTSC(Atom atom);
400  int readSTSD(Atom atom);
401  int readSTSS(Atom atom);
402  int readSTSZ(Atom atom);
403  int readSTTS(Atom atom);
404  int readVMHD(Atom atom);
405  int readCMOV(Atom atom);
406  int readWAVE(Atom atom);
407  int readESDS(Atom atom);
408  int readSMI(Atom atom);
409  int readCTYP(Atom atom);
410  int readWLOC(Atom atom);
411  int readNAVG(Atom atom);
412  int readGMIN(Atom atom);
413  int readPINF(Atom atom);
414 
415  int readPHDR(Atom atom);
416  int readPHOT(Atom atom);
417  int readSTRT(Atom atom);
418  int readPLNK(Atom atom);
419  int readPNAV(Atom atom);
420 };
421 
424 } // End of namespace Common
425 
426 #endif
Definition: macresman.h:125
Definition: str.h:59
Definition: quicktime.h:329
Definition: quicktime.h:250
Definition: array.h:52
Definition: quicktime.h:112
Definition: quicktime.h:167
Definition: quicktime.h:132
Definition: rect.h:144
Definition: quicktime.h:123
Definition: path.h:52
Definition: stream.h:745
Definition: rational.h:40
Definition: quicktime.h:58
Definition: quicktime.h:203
Definition: quicktime.h:276
uint32 getTimeScale() const
Definition: quicktime.h:97
bool parseStream(SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle=DisposeAfterUse::YES)
Definition: algorithm.h:29
Definition: quicktime.h:268
Definition: quicktime.h:117
Definition: quicktime.h:227
bool parseFile(const Path &filename)
void setChunkBeginOffset(uint32 offset)
Definition: quicktime.h:92
bool isOpen() const
Definition: quicktime.h:100