ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

quicktime.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 //
00024 // Heavily based on ffmpeg code.
00025 //
00026 // Copyright (c) 2001 Fabrice Bellard.
00027 // First version by Francois Revol revol@free.fr
00028 // Seek function by Gael Chardon gael.dev@4now.net
00029 //
00030 
00031 #ifndef COMMON_QUICKTIME_H
00032 #define COMMON_QUICKTIME_H
00033 
00034 #include "common/array.h"
00035 #include "common/scummsys.h"
00036 #include "common/stream.h"
00037 #include "common/rational.h"
00038 #include "common/types.h"
00039 
00040 namespace Common {
00041     class MacResManager;
00042 
00051 class QuickTimeParser {
00052 public:
00053     QuickTimeParser();
00054     virtual ~QuickTimeParser();
00055 
00060     bool parseFile(const String &filename);
00061 
00067     bool parseStream(SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle = DisposeAfterUse::YES);
00068 
00072     void close();
00073 
00079     void setChunkBeginOffset(uint32 offset) { _beginOffset = offset; }
00080 
00082     bool isOpen() const { return _fd != nullptr; }
00083 
00084 protected:
00085     // This is the file handle from which data is read from. It can be the actual file handle or a decompressed stream.
00086     SeekableReadStream *_fd;
00087 
00088     struct TimeToSampleEntry {
00089         int count;
00090         int duration;
00091     };
00092 
00093     struct SampleToChunkEntry {
00094         uint32 first;
00095         uint32 count;
00096         uint32 id;
00097     };
00098 
00099     struct EditListEntry {
00100         uint32 trackDuration;
00101         uint32 timeOffset;
00102         int32 mediaTime;
00103         Rational mediaRate;
00104     };
00105 
00106     struct Track;
00107 
00108     class SampleDesc {
00109     public:
00110         SampleDesc(Track *parentTrack, uint32 codecTag);
00111         virtual ~SampleDesc();
00112 
00113         uint32 getCodecTag() const { return _codecTag; }
00114 
00115         SeekableReadStream *_extraData;
00116         byte _objectTypeMP4;
00117 
00118     protected:
00119         Track *_parentTrack;
00120         uint32 _codecTag;
00121     };
00122 
00123     enum CodecType {
00124         CODEC_TYPE_MOV_OTHER,
00125         CODEC_TYPE_VIDEO,
00126         CODEC_TYPE_AUDIO,
00127         CODEC_TYPE_MIDI
00128     };
00129 
00130     struct Track {
00131         Track();
00132         ~Track();
00133 
00134         uint32 chunkCount;
00135         uint32 *chunkOffsets;
00136         int timeToSampleCount;
00137         TimeToSampleEntry *timeToSample;
00138         uint32 sampleToChunkCount;
00139         SampleToChunkEntry *sampleToChunk;
00140         uint32 sampleSize;
00141         uint32 sampleCount;
00142         uint32 *sampleSizes;
00143         uint32 keyframeCount;
00144         uint32 *keyframes;
00145         int32 timeScale;
00146 
00147         uint16 width;
00148         uint16 height;
00149         CodecType codecType;
00150 
00151         Array<SampleDesc *> sampleDescs;
00152 
00153         Common::Array<EditListEntry> editList;
00154 
00155         uint32 frameCount;
00156         uint32 duration;
00157         uint32 mediaDuration;
00158         uint32 startTime;
00159         Rational scaleFactorX;
00160         Rational scaleFactorY;
00161     };
00162 
00163     virtual SampleDesc *readSampleDesc(Track *track, uint32 format, uint32 descSize) = 0;
00164 
00165     uint32 _timeScale;
00166     uint32 _duration;
00167     Rational _scaleFactorX;
00168     Rational _scaleFactorY;
00169     Array<Track *> _tracks;
00170 
00171     void init();
00172 
00173 private:
00174     struct Atom {
00175         uint32 type;
00176         uint32 offset;
00177         uint32 size;
00178     };
00179 
00180     struct ParseTable {
00181         int (QuickTimeParser::*func)(Atom atom);
00182         uint32 type;
00183     };
00184 
00185     DisposeAfterUse::Flag _disposeFileHandle;
00186     const ParseTable *_parseTable;
00187     uint32 _beginOffset;
00188     MacResManager *_resFork;
00189     bool _foundMOOV;
00190 
00191     void initParseTable();
00192 
00193     int readDefault(Atom atom);
00194     int readLeaf(Atom atom);
00195     int readELST(Atom atom);
00196     int readHDLR(Atom atom);
00197     int readMDHD(Atom atom);
00198     int readMOOV(Atom atom);
00199     int readMVHD(Atom atom);
00200     int readTKHD(Atom atom);
00201     int readTRAK(Atom atom);
00202     int readSTCO(Atom atom);
00203     int readSTSC(Atom atom);
00204     int readSTSD(Atom atom);
00205     int readSTSS(Atom atom);
00206     int readSTSZ(Atom atom);
00207     int readSTTS(Atom atom);
00208     int readCMOV(Atom atom);
00209     int readWAVE(Atom atom);
00210     int readESDS(Atom atom);
00211     int readSMI(Atom atom);
00212 };
00213 
00214 } // End of namespace Common
00215 
00216 #endif


Generated on Sat Jul 13 2019 05:00:47 for ResidualVM by doxygen 1.7.1
curved edge   curved edge