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
41namespace Common {
42 class MacResManager;
43
59public:
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
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
108protected:
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
124 uint32 trackDuration; // movie time
125 uint32 timeOffset; // movie time
126 int32 mediaTime; // media time
127 Rational mediaRate;
128 };
129
130public:
131 struct Track;
132
133protected:
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
149public:
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
171 uint32 nodeID = 0;
172 uint32 timestamp = 0;
173 };
174
176 String name;
177 uint32 defNodeID = 0;
178 float defZoom = 0.0f;
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 float maxZoom;
196
197 int32 nameStrOffset;
198 int32 commentStrOffset;
199 };
200
201 struct PanoHotSpot {
202 uint16 id;
203 uint32 type;
204 uint32 typeData; // for link and navg, the ID in the link and navg table
205
206 // Canonical view for this hotspot
207 float viewHPan;
208 float viewVPan;
209 float viewZoom;
210
211 Rect rect;
212
213 int32 mouseOverCursorID;
214 int32 mouseDownCursorID;
215 int32 mouseUpCursorID;
216
217 int32 nameStrOffset;
218 int32 commentStrOffset;
219 };
220
222 Array<PanoHotSpot> hotSpots;
223
224 PanoHotSpot *get(uint16 id) {
225 for (uint i = 0; i < hotSpots.size(); i++)
226 if (hotSpots[i].id == id)
227 return &hotSpots[i];
228
229 return nullptr;
230 }
231 };
232
234 String strings;
235
236 String getString(int32 offset) const;
237 void debugPrint(int level, uint32 debugChannel, String prefix) const;
238 };
239
240 struct PanoLink {
241 uint16 id;
242 uint16 toNodeID;
243
244 // Values to set at the destination node
245 float toHPan;
246 float toVPan;
247 float toZoom;
248
249 int32 nameStrOffset;
250 int32 commentStrOffset;
251 };
252
254 Array<PanoLink> links;
255
256 PanoLink *get(uint16 id) {
257 for (uint i = 0; i < links.size(); i++)
258 if (links[i].id == id)
259 return &links[i];
260
261 return nullptr;
262 }
263 };
264
266 uint16 id;
267
268 // Info for Navigable Movie Controller
269 float navgHPan; // the object's orientation in the scene
270 float navgVPan;
271 float navgZoom;
272
273 Rect zoomRect; // Starting rect for zoom out transitions
274
275 // Values to set at the destination node
276 int32 nameStrOffset;
277 int32 commentStrOffset;
278 };
279
282
283 PanoNavigation *get(uint16 id) {
284 for (uint i = 0; i < navs.size(); i++)
285 if (navs[i].id == id)
286 return &navs[i];
287
288 return nullptr;
289 }
290 };
291
294 PanoHotSpotTable hotSpotTable;
295 PanoStringTable strTable;
296 PanoLinkTable linkTable;
297 PanoNavigationTable navTable;
298 };
299
300 struct Track {
301 Track();
302 ~Track();
303
304 uint32 chunkCount;
305 uint32 *chunkOffsets;
306 int timeToSampleCount;
307 TimeToSampleEntry *timeToSample;
308 uint32 sampleToChunkCount;
309 SampleToChunkEntry *sampleToChunk;
310 uint32 sampleSize;
311 uint32 sampleCount;
312 uint32 *sampleSizes;
313 uint32 keyframeCount;
314 uint32 *keyframes;
315 int32 timeScale; // media time
316
317 uint16 width;
318 uint16 height;
319 CodecType codecType;
320
321 Array<SampleDesc *> sampleDescs;
322
324
325 uint32 frameCount; // from stts
326 uint32 duration; // movie time
327 uint32 mediaDuration; // media time
328 Rational scaleFactorX;
329 Rational scaleFactorY;
330
331 Common::String volume;
332 Common::String filename;
333 Common::String path;
334 Common::String directory;
335 int16 nlvlFrom;
336 int16 nlvlTo;
337
338 PanoramaInformation panoInfo;
339 Array<PanoTrackSample> panoSamples;
340
341 GraphicsMode graphicsMode; // Transfer mode
342 uint16 opcolor[3]; // RGB values used in the transfer mode specified by graphicsMode.
343
344 uint16 soundBalance; // Controls the sound mix between the computer's two speakers, usually set to 0.
345
346 uint targetTrack;
347 };
348
349 enum class MovieType {
350 kStandardObject = 1,
351 kOldNavigableMovieScene,
352 kObjectInScene
353 };
354
355 struct Navigation {
356 uint16 columns = 1;
357 uint16 rows = 1;
358 uint16 loop_size = 0; // Number of frames shot at each position
359 uint16 frame_duration = 1;
360
361 MovieType movie_type = MovieType::kStandardObject;
362
363 uint16 loop_ticks = 0; // Number of ticks before next frame of loop is displayed
364
365 float field_of_view = 1.0f;
366
367 float startHPan = 1.0f;
368 float startVPan = 1.0f;
369 float endHPan = 1.0f;
370 float endVPan = 1.0f;
371 float initialHPan = 1.0f;
372 float initialVPan = 1.0f;
373 };
374
375protected:
376 virtual SampleDesc *readSampleDesc(Track *track, uint32 format, uint32 descSize) = 0;
377
378 uint32 _timeScale; // movie time
379 uint32 _duration; // movie time
380 Rational _scaleFactorX;
381 Rational _scaleFactorY;
382 Array<Track *> _tracks;
383 Navigation _nav;
384 QTVRType _qtvrType;
385 uint16 _winX;
386 uint16 _winY;
387
388 Track *_panoTrack;
389
390 void init();
391
392private:
393 struct Atom {
394 uint32 type;
395 uint32 offset;
396 uint32 size;
397 };
398
399 struct ParseTable {
400 int (QuickTimeParser::*func)(Atom atom);
401 uint32 type;
402 };
403
404 DisposeAfterUse::Flag _disposeFileHandle;
405 const ParseTable *_parseTable;
406 uint32 _beginOffset;
407 MacResManager *_resFork;
408 bool _foundMOOV;
409
410 void initParseTable();
411
412 bool parsePanoramaAtoms();
413
414 int readDefault(Atom atom);
415 int readLeaf(Atom atom);
416 int readDREF(Atom atom);
417 int readELST(Atom atom);
418 int readHDLR(Atom atom);
419 int readMDHD(Atom atom);
420 int readMOOV(Atom atom);
421 int readMVHD(Atom atom);
422 int readTKHD(Atom atom);
423 int readTRAK(Atom atom);
424 int readSMHD(Atom atom);
425 int readSTCO(Atom atom);
426 int readSTSC(Atom atom);
427 int readSTSD(Atom atom);
428 int readSTSS(Atom atom);
429 int readSTSZ(Atom atom);
430 int readSTTS(Atom atom);
431 int readVMHD(Atom atom);
432 int readCMOV(Atom atom);
433 int readWAVE(Atom atom);
434 int readESDS(Atom atom);
435 int readSMI(Atom atom);
436 int readCTYP(Atom atom);
437 int readWLOC(Atom atom);
438 int readNAVG(Atom atom);
439 int readGMIN(Atom atom);
440 int readPINF(Atom atom);
441
442 int readPHDR(Atom atom);
443 int readPHOT(Atom atom);
444 int readSTRT(Atom atom);
445 int readPLNK(Atom atom);
446 int readPNAV(Atom atom);
447};
448
451} // End of namespace Common
452
453#endif
Definition: array.h:52
size_type size() const
Definition: array.h:316
Definition: path.h:52
Definition: quicktime.h:134
Definition: quicktime.h:58
bool parseFile(const Path &filename)
uint32 getTimeScale() const
Definition: quicktime.h:97
bool isOpen() const
Definition: quicktime.h:100
bool parseStream(SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle=DisposeAfterUse::YES)
void setChunkBeginOffset(uint32 offset)
Definition: quicktime.h:92
Definition: rational.h:40
Definition: stream.h:745
Definition: str.h:59
Definition: algorithm.h:29
Definition: quicktime.h:123
Definition: quicktime.h:355
Definition: quicktime.h:201
Definition: quicktime.h:265
Definition: quicktime.h:233
Definition: quicktime.h:292
Definition: quicktime.h:170
Definition: quicktime.h:117
Definition: quicktime.h:112
Definition: quicktime.h:300
Definition: rect.h:536