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