/*
 * @(#)QuickTimeAtoms.txt  1.2.1  2005-01-03
 *
 * Copyright (c) 2000 Werner Randelshofer
 * Staldenmattweg 2, CH-6405 Immensee, Switzerland
 * All rights reserved.
 */

/* This file contains the description of some
 * well known QuickTime data structures as
 * published in
 *   Inside Macintosh: QuickTime
 *   Apple Technical Library, 1993
 *   Addison-Wesley, Reading ...
 *   ISBN 0-201-62201-7
 *
 * @version 1.2.1 Fixed a typo.
 */
magic movieAtom "moov";
description movieAtom "Movie Atom", "The movie atom holds the description of the movie.";

magic compressedMovieAtom "cmov";
description compressedMovieAtom "Compressed Movie", "The compressed movie atom holds the compressed description of the movie.";

magic dataCompressionAtom "dcom";
description dataCompressionAtom "Data Compression Atom", "Describes what lossless data compression algorithm was used to compress the movie header atoms.";

magic compressedMovieDataAtom "cmvd";
description compressedMovieDataAtom "Compressed Movie Data", "Holds the compressed movie header atoms. The first 32-bit integer in the compressed movie data atom indicates the uncompressed size of the movie resource and then the compressed movie resource data follows";

magic movieDataAtom "mdat";
description movieDataAtom "Movie Data Atom", "The movie data atom contains the media data of the movie. Usually this data can be interpreted only by using information provided by the movie atom.";

magic freeAtom "free";
description freeAtom "Free Atom", "The free atom marks unused space available in the file.";

magic skipAtom "skip";
description skipAtom "Skip Atom", "The skip atom marks unused space available in the file.";

magic wideAtom "wide";
description wideAtom "Reserved Space", "The wide atom marks reserved space which can be overwritten by an extended size field. The wide atom consists only of a type and size field. This occupies 8 bytes - enough space to add an extended size field to the header of the atom that follows. If an atom grows to exceed 2^32 bytes in size, and it is preceeded by a wide atom, you may create a new atom header, containing an extended size field, by overwriting the wide atom.";

magic previewAtom "pnot";
description previewAtom "Preview Atom", "The preview atom contains information that allows you to find the preview image associated with a QuickTime movie.";

magic referenceMovieAtom "rmra";
description referenceMovieAtom "Reference Movie Atom", "A movie that contains this atom references to alternate movies, i. e. movies having different data rates, allowing an application to choose the best-looking movie based on the configuration of the computer system. The reference movie atom contains one or more reference movie descriptor atoms, each of which describes an alternate movie.";

magic dataReferenceAtom "rdrf";
description dataReferenceAtom "Data Reference Atom", "A data reference atom contains the information necessary to locate a movie, or a stream or file that QuickTime canplay, typically in the form of a URL or a file alias.";

magic dataRateAtom "rmdr";
description dataRateAtom "Data Rate Atom", "A data rate atom specifies the minimum data rate required to play a movie.";
magic cpuSpeedAtom "rmcs";
description cpuSpeedAtom "CPU Speed Atom", "A CPU speed atom specifies the minimum computing power needed to display a movie. This is not a simple measurement of clock speed - it is a measurement of performance for QuickTime-related operations. Speed is expressed as a relative value between 100 and 2^31, in multiples of 100. Typical scores might range from a minimum score of 100, which would describe a computer as slow as, or slower than, a 166 MHz Pentium or 120 MHz Power PC, to a maximum score of 600 for a 500 MHz Pentium III or 400 MHz G4 PowerPC. A Computer with a graphics accelerator and a Gigahertz clock speed might score as high as 1000.";
magic versionCheckAtom "rmvc";
description versionCheckAtom "Version Check Atom", ".";
magic componentDetectAtom "rmcd";
description componentDetectAtom "Component Detect Atom", ".";
magic qualityAtom "rmqu";
description qualityAtom "Quality Atom", ".";

magic referenceMovieDescriptorAtom "rmda";
description referenceMovieDescriptorAtom "Reference Movie Descriptor Atom", "Describes where a particular movie can be found, and optionally what the system requirements are to play that movie, as well as an optonal quality rating for that movie.";

magic trackAtom "trak";
description trackAtom "Track Atom", "Track atoms define a single track of a movie. A movie may consist of one or more tracks. Each track is independent of the other tracks in the movie and carries its own temporal and spatial information.";

magic editAtom "edts";
description editAtom "Edit Atom", "Edit atoms define the portions of the media that are to be used to build up a track for a movie.";

magic mediaAtom "mdia";
description mediaAtom "Media Atom",  "Media atoms define the data for a movie track. It specifies the component that is to interpret the media data, and it also specifies the data references.";

magic mediaInformationAtom "minf";
description mediaInformationAtom "Media Information Atom", "Media information atoms store handler-specific information for the media data that constitutes a track. The media handler uses this information to map from media time to media data. These atoms are formatted differently based on the type of media data stored in the atom. The format and content of media information atoms are dictated by the media handler that is responsible for interpreting the media data stream. Another media handler would not know how to interpret this information.";

magic dataInformationAtom "dinf";
description dataInformationAtom "Data Information Atom", "The handler reference atom (hdlr) contains information specifying the data handler component that provides access to the media data. The handler uses the data information atom to specify where the data is stored.";

magic sampleTableAtom "stbl";
description sampleTableAtom "Sample Table Atom", "The sample table atom contains information for converting from media time to sample number to sample location. This atom also indicates how to interpret the sample (for example, whether to decompress the video sample and, if so, how).";

magic userDefinedDataAtom "udta";
description userDefinedDataAtom "User Defined Data Atom", "This atom holds user-defined data.";

magic clippingAtom "clip";
description clippinAtom "Clipping Atom", "Clipping atoms specify the clipping regions for movies and tracks.";

magic trackMatteAtom "matt";
description trackMatteAtom "Track Matte Atom", "Track matte atoms specify the mattes for tracks. A track matte is a pixel map that defines the blending of visual track data.";

magic movieHeaderAtom "mvhd";
description movieHeaderAtom "Movie Header Atom", "The movie header atom defines the time scale and duration information of the entire movie, as well as its display characteristics.";

magic windowLocationAtom "WLOC";
description windowLocationAtom "Window Location Atom", "Default window location for movie.";

typedef struct {
    magic compressionMethod;
} dataCompressionAtom;

typedef struct {
    mactimestamp modificationDate;
    short versionNumber;
    magic atomType;
    short atomIndex;
} previewAtom;

// Enumeration for data reference flags
set {
    SelfContained = 0x1 // movie is self contained
} DataReferenceFlags;
typedef struct {
    int set DataReferenceFlags flags;
    magic dataReferenceType;
    int dataReferenceSize;
    string dataReference;
} dataReferenceAtom;

typedef struct {
    byte[4] flags;
    int bitsPerSecond;
} dataRateAtom;

typedef struct {
    byte[4] flags;
    int cpuSpeed;
} cpuSpeedAtom;

typedef struct {
    byte version;
    byte[3] flags;
    mactimestamp creationTime;
    mactimestamp modificationTime;
    int timeScale;
    int duration;
    int preferredRate;
    short preferredVolume;
    byte[10] reserved;
    int[9] matrix;
    int previewTime;
    int previewDuration;
    int posterTime;
    int selectionTime;
    int selectionDuration;
    int currentTime;
    int nextTrackId;
} movieHeaderAtom;


magic trackHeaderAtom "tkhd";
description trackHeaderAtom "Track Header Atom", "The track header atom describes the characteristics of a single track within a movie, including temporal, spatial, and volume information.";

// Enumeration for track header flags
set {
    TrackEnable = 0x1, // enabled track
    TrackInMovie = 0x2, // track in playback
    TrackInPreview = 0x4, // track in preview
    TrackInPoster = 0x8 // track in poster
} TrackHeaderFlags;


typedef struct {
    byte version;
    byte flag0;
    byte flag1;
    byte set TrackHeaderFlags flag2;
    mactimestamp creationTime;
    mactimestamp modificationTime;
    int trackId;
    byte[4] reserved;
    int duration;
    byte[8] reserved;
    short layer;
    short alternateGroup;
    short volume;
    byte[2] reserved;
    int[9] matrix;
    int trackWidth;
    int trackHeight;
} trackHeaderAtom;


magic mediaHeaderAtom "mdhd";
description mediaHeaderAtom "Media Header Atom", "The media header atom specifies the characteristics of the media that is used to store data for the movie track defined in its associated track atom.";

typedef struct {
    byte version;
    byte[3] flags;
    mactimestamp creationTime;
    mactimestamp modificationTime;
    int timeScale;
    int duration;
    short language;
    short quality;
} mediaHeaderAtom;


magic handlerReferenceAtom "hdlr";
description handlerReferenceAtom "Handler Reference Atom", "The handler reference atom specifies the component that is to interpret a media's data. This component is called a media handler.";

typedef struct {
    byte version;
    byte[3] flags;
    magic componentType;
    magic componentSubtype;
    magic componentManufacturer;
    int componentFlags;
    int componentFlagsMask;
    pstring componentName;
} handlerReferenceAtom;

magic copyrightStatementAtom "cpy";

typedef struct {
    pstring copyright;
} copyrightStatementAtom;

magic movieNameAtom "nam";
typedef struct {
    pstring name;
} movieNameAtom;

magic copyrightCommentsAtom "cmt";
typedef struct {
    pstring comments;
} copyrightCommentsAtom;

magic copyrightDisclaimerAtom "dis";
typedef struct {
    pstring disclaimer;
} copyrightDisclaimerAtom;

magic copyrightSoftwareAtom "swr";
typedef struct {
    pstring software;
} copyrightSoftwareAtom;

magic creationDateAtom "day";
typedef struct {
    pstring date;
} creationDateAtom;

magic movieDirectorAtom "dir";
typedef struct {
    pstring director;
} movieDirectorAtom;

magic editComment1Atom "ed1";
typedef struct {
    pstring edit;
} editComment1Atom;

magic editComment2Atom "ed2";
typedef struct {
    pstring edit;
} editComment2Atom;

magic editComment3Atom "ed3";

typedef struct {
    pstring edit;
} editComment3Atom;

magic editComment4Atom "ed4";

typedef struct {
    pstring edit;
} editComment4Atom;

magic editComment5Atom "ed5";

typedef struct {
    pstring edit;
} editComment5Atom;

magic editComment6Atom "ed6";

typedef struct {
    pstring edit;
} editComment7Atom;

magic editComment7Atom "ed7";

typedef struct {
    pstring edit;
} editComment7Atom;

magic editComment8Atom "ed8";

typedef struct {
    pstring edit;
} editComment8Atom;

magic editComment9Atom "ed9";

typedef struct {
    pstring edit;
} editComment9Atom;

magic formatAtom "fmt";

typedef struct {
    pstring format;
} formatAtom;

magic movieInfoAtom "inf";

typedef struct {
    pstring info;
} movieInfoAtom;

magic movieProducerAtom "prd";

typedef struct {
    pstring producer;
} movieProducerAtom;

magic moviePerformersAtom "prf";

typedef struct {
    pstring performer;
} moviePerformersAtom;

magic movieRequirementsAtom "req";

typedef struct {
    pstring requirements;
} movieRequirementsAtom;

magic movieSourceCreditsAtom "src";

typedef struct {
    pstring source;
} movieSourceCreditsAtom;

magic movieWriterAtom "wrt";

typedef struct {
    pstring writer;
} movieWriterAtom;

magic clippingRegionAtom "crgn";

typedef struct {
    short regionSize;
    short[4] regionBoundaryBox;
    byte[] clippingRegionData;
} clippingRegionAtom;

magic compressedMatteAtom "kmat";
description compressedMatteAtom "Compressed Matte Atom", "The compressed matte atom specifies the image description structure associated with a particular matte atom.";

typedef struct {
    byte versions;
    byte[3] flags;
    byte[] matteImageDescriptionStructureAndMatteData;
} compressedMatteAtom;

magic editListAtom "elst";
description editListAtom "Edit List Atom", "Edit list atoms specify how to map from a time in a movie to a time in a media, and ultimatively to media data";

typedef struct {
    byte versions;
    byte[3] flags;
    int numberOfEntries;
    editListTable editListTable[numberOfEntries];
} editListAtom;

typedef struct {
    int trackDuration;
    int mediaTime;
    int mediaRate;
} editListTable;

magic videoMediaInformationHeaderAtom "vmhd";
description videoMediaInformationHeaderAtom "Video Media Information Header Atom", "Video media information atoms are the highest-level atoms in video media. A number of other atoms define specific characteristics of the video media data.";

set {
    videoFlagNoLeanAhead=1 // I am not shure if this is the correct value for this flag
} vmhdFlags;

typedef struct {
    byte version;
    byte flag1;
    byte flag2;
    byte set vmhdFlags flag3;
    short graphicsMode;
    short[3] opcolor;
} videoMediaInformationHeaderAtom;

magic soundMediaInformationHeaderAtom "smhd";
description soundMediaInformationHeaderAtom "Sound Media Information Header Atom", "The sound media information header atom stores the sound media information.";

typedef struct {
    ubyte version;
    ubyte[3] flags;
    short balance;
    short reserved;
} soundMediaInformationHeaderAtom;

magic dataReferenceAtom "dref";
description dataReferenceAtom "Data Reference Atom", "The data reference atom encompasses the data references.";

typedef struct {
    ubyte version;
    ubyte[3] flags;
    int numberOfEntries;
    dataReferenceEntry dataReference[numberOfEntries];
} dataReferenceAtom;

set {
    dataRefSelfReference=1 // I am not shure if this is the correct value for this flag
} drefEntryFlags;

typedef struct {
    int size;
    magic type;
    byte version;
    ubyte flag1;
    ubyte flag2;
    ubyte set drefEntryFlags flag3;
    byte[size - 12] data;
} dataReferenceEntry;

magic sampleDescriptionAtom "stsd";
description sampleDescriptionAtom  "Sample Description Atom", "The sample description atom stores information for the decoding of samples in the media. In the case of video media, the sample descriptions are image description structures.";

typedef struct {
    byte version;
    byte[3] flags;
    int numberOfEntries;
    sampleDescriptionEntry sampleDescriptionTable[numberOfEntries];
} sampleDescriptionAtom;

typedef struct {
    int size;
    magic type;
    byte[size - 8] data;
} sampleDescriptionEntry;

magic timeToSampleAtom "stts";
description timeToSampleAtom "Time-to-Sample Atom", "Time-to-sample atoms store duration information for the samples in a media, providing a mapping from a time in a media to the corresponding data sample.";

typedef struct {
    byte version;
    byte[3] flags;
    int numberOfEntries;
    timeToSampleTable timeToSampleTable[numberOfEntries];
} timeToSampleAtom;

typedef struct {
    int sampleCount;
    int sampleDuration;
} timeToSampleTable;

magic syncSampleAtom "stss";
description syncSampleAtom "Sync Sample Atom", "The sync sample atom identifies the key frames in the media. In a media that contains compressed data, key frames define starting points for portions of a teemporally compressed sequence. The key frame is self-contained - that is, it is independent of preceding frames. Subsequent frames may depend on the key frame.";

typedef struct {
    byte version;
    byte[3] flags;
    int numberOfEntries;
    syncSampleTable syncSampleTable[numberOfEntries];
} syncSampleAtom;

typedef struct {
    int number;
} syncSampleTable;

magic sampleToChunkAtom "stsc";
description sampleToChunkAtom "Sample-to-Chunk Atom", "As samples are added to a media, they are collected into chunks that allow optimized data access. A chunk may contain one or more samples. Chunks in a media may have different sizes, and the samples within a chunk may have different sizes.";

typedef struct {
    byte version;
    byte[3] flags;
    int numberOfEntries;
    sampleToChunkTable sampleToChunkTable[numberOfEntries];
} sampleToChunkAtom;

typedef struct {
    int firstChunk;
    int samplesPerChunk;
    int sampleDescription;
} sampleToChunkTable;

magic sampleSizeAtom "stsz";
description sampleSizeAtom "Sample Size Atom", "Sample size atoms identify the size of each sample in the media.";

typedef struct {
    byte version;
    byte[3] flags;
    int sampleSize;
    int numberOfEntries;
    sampleSizeTable sampleSizeTable[numberOfEntries];
} sampleSizeAtom;

typedef struct {
    int size;
} sampleSizeTable;

magic chunkOffsetAtom "stco";
description chunkOffsetAtom "Chunk Offset Atom", "Chunk offset atoms identify the location of each chunk of data in the media's data stream.";

typedef struct {
    byte version;
    byte[3] flags;
    int numberOfEntries;
    chunkOffsetTable chunkOffsetTable[numberOfEntries];
} chunkOffsetAtom;

typedef struct {
    int offset;
} chunkOffsetTable;

magic shadowSyncAtom "stsh";
description shadowSyncAtom "Shadow Sync Atom", "Shadow sync atoms contain self-contained samples that are alternates for existing frame difference samples. Shadow sync atoms are used to optimiye random access operations on a movie. Scrubbing is an example of such a random access operation. These atoms are used to enhance playback performance.";

typedef struct {
    byte version;
    byte[3] flags;
    int numberOfEntries;
    shadowSyncTable shadowSyncTable[numberOfEntries];
} shadowSyncAtom;

typedef struct {
    int frameDifferenceSampleNumber;
    int syncSampleNumber;
} shadowSyncTable;

typedef struct {
    short x;
    short y;
} windowLocationAtom;


