sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef _MP4ATOM_H sl@0: #define _MP4ATOM_H sl@0: sl@0: #include <3gplibrary/mp4config.h> sl@0: #include <3gplibrary/mp4lib.h> sl@0: #include "mp4list.h" sl@0: #include "filewriter.h" /* Async buffering filewriter */ sl@0: #include "metadatafilewriter.h" /* Async buffering filewriter */ sl@0: #include "asyncfileparser.h" /*Async file reader for parsing */ sl@0: sl@0: #define ATOMTYPE_FTYP 0x66747970 /* 'ftyp' */ sl@0: #define ATOMTYPE_MOOV 0x6d6f6f76 /* 'moov' */ sl@0: #define ATOMTYPE_MDAT 0x6d646174 /* 'mdat' */ sl@0: #define ATOMTYPE_FREE 0x66726565 /* 'free' */ sl@0: #define ATOMTYPE_SKIP 0x736b6970 /* 'skip' */ sl@0: #define ATOMTYPE_UDTA 0x75647461 /* 'udta' */ sl@0: #define ATOMTYPE_MVHD 0x6d766864 /* 'mvhd' */ sl@0: #define ATOMTYPE_IODS 0x696f6473 /* 'iods' */ sl@0: #define ATOMTYPE_TRAK 0x7472616b /* 'trak' */ sl@0: #define ATOMTYPE_TKHD 0x746b6864 /* 'tkhd' */ sl@0: #define ATOMTYPE_MDIA 0x6d646961 /* 'mdia' */ sl@0: #define ATOMTYPE_MDHD 0x6d646864 /* 'mdhd' */ sl@0: #define ATOMTYPE_HDLR 0x68646c72 /* 'hdlr' */ sl@0: #define ATOMTYPE_MINF 0x6d696e66 /* 'minf' */ sl@0: #define ATOMTYPE_VMHD 0x766d6864 /* 'vmhd' */ sl@0: #define ATOMTYPE_SMHD 0x736d6864 /* 'smhd' */ sl@0: #define ATOMTYPE_DINF 0x64696e66 /* 'dinf' */ sl@0: #define ATOMTYPE_DREF 0x64726566 /* 'dref' */ sl@0: #define ATOMTYPE_TREF 0x74726566 /* 'tref' */ sl@0: #define ATOMTYPE_STBL 0x7374626c /* 'stbl' */ sl@0: #define ATOMTYPE_STTS 0x73747473 /* 'stts' */ sl@0: #define ATOMTYPE_CTTS 0x63747473 /* 'ctts' */ sl@0: #define ATOMTYPE_STSS 0x73747373 /* 'stss' */ sl@0: #define ATOMTYPE_STSD 0x73747364 /* 'stsd' */ sl@0: #define ATOMTYPE_STSZ 0x7374737a /* 'stsz' */ sl@0: #define ATOMTYPE_STZ2 0x73747a32 /* 'stz2' */ sl@0: #define ATOMTYPE_STSC 0x73747363 /* 'stsc' */ sl@0: #define ATOMTYPE_STCO 0x7374636f /* 'stco' */ sl@0: #define ATOMTYPE_CO64 0x636f3634 /* 'co64' */ sl@0: #define ATOMTYPE_MP4V 0x6d703476 /* 'mp4v' */ sl@0: #define ATOMTYPE_MP4A 0x6d703461 /* 'mp4a' */ sl@0: #define ATOMTYPE_MP4S 0x6d703473 /* 'mp4s' */ sl@0: #define ATOMTYPE_S263 0x73323633 /* 's263' */ sl@0: #define ATOMTYPE_D263 0x64323633 /* 'd263' */ sl@0: #define ATOMTYPE_BITR 0x62697472 /* 'bitr' */ sl@0: #define ATOMTYPE_SAMR 0x73616d72 /* 'samr' */ sl@0: #define ATOMTYPE_SAWB 0x73617762 /* 'sawb' */ sl@0: #define ATOMTYPE_DAMR 0x64616d72 /* 'damr' */ sl@0: #define ATOMTYPE_ESD 0x65736473 /* 'esds' */ sl@0: #define ATOMTYPE_URL 0x75726c20 /* 'url ' */ sl@0: #define ATOMTYPE_URN 0x75726e20 /* 'urn ' */ sl@0: #define ATOMTYPE_UUID 0x75756964 /* 'uuid' */ sl@0: #define ATOMTYPE_EDTS 0x65647473 /* 'edts' */ sl@0: #define ATOMTYPE_META 0x6d657461 /* 'meta' */ sl@0: /* AVC Additions */ sl@0: #define ATOMTYPE_AVCC 0x61766343 /* 'avcC' */ sl@0: #define ATOMTYPE_BTRT 0x62747274 /* 'btrt' */ sl@0: #define ATOMTYPE_AVC1 0x61766331 /* 'avc1' */ sl@0: #define ATOMTYPE_M4DS 0x6d346473 /* 'm4ds' */ sl@0: #define ATOMTYPE_SDTP 0x73647470 /* 'sdtp' */ sl@0: #define ATOMTYPE_AVCP 0x61766370 /* 'avcp' */ sl@0: /* QCELP 13K Additions */ sl@0: #define ATOMTYPE_SQCP 0x73716370 /* 'sqcp' */ sl@0: #define ATOMTYPE_DQCP 0x64716370 /* 'dqcp' */ sl@0: /* inline Addition */ sl@0: #define ATOMTYPE_ID32 0x49443332 /* 'ID32' */ sl@0: sl@0: #define HANDLERTYPE_ODSM 0x6f64736d /* 'odsm' */ sl@0: #define HANDLERTYPE_VIDE 0x76696465 /* 'vide' */ sl@0: #define HANDLERTYPE_SOUN 0x736f756e /* 'soun' */ sl@0: sl@0: sl@0: sl@0: #define FTYP_SIZE 24 /* Size of FTYP box in bytes */ sl@0: sl@0: #define READBUFSIZE 8192 /* Size of file reading buffer */ sl@0: #define WRITEBUFSIZE 2048 /* Size of file writing buffer */ sl@0: sl@0: #define BLOCK_LIMIT 200 /* Max number of metadata blocks to keep in memory */ sl@0: sl@0: #define MAXSAMPLESPERSECOND 150 /* magic number used to try validate input data to parser from possibly corrupted file */ sl@0: sl@0: sl@0: #define METADATAFILE_VIDEO_STTS_SAMPLE_COUNT 0 sl@0: #define METADATAFILE_VIDEO_STTS_SAMPLE_DELTA 1 sl@0: #define METADATAFILE_VIDEO_STSZ_ENTRY_SIZE 2 sl@0: #define METADATAFILE_VIDEO_STCO_CHUNK_OFFSET 3 sl@0: #define METADATAFILE_VIDEO_STSS_SAMPLE_NUMBER 4 sl@0: #define METADATAFILE_AUDIO_STTS_SAMPLE_COUNT 5 sl@0: #define METADATAFILE_AUDIO_STTS_SAMPLE_DELTA 6 sl@0: #define METADATAFILE_AUDIO_STSZ_ENTRY_SIZE 7 sl@0: #define METADATAFILE_AUDIO_STCO_CHUNK_OFFSET 8 sl@0: #define METADATAFILE_VIDEO_SDTP_SAMPLE_DEPENDENCY 9 sl@0: sl@0: /* Multiple Sample Entry Inclusion */ sl@0: #define STSDMAXSAMPLEENTRYCOUNT 10 /* defined the maximum number of sample entried allowed in a Sample Description Box */ sl@0: sl@0: sl@0: typedef struct atomHeader sl@0: { sl@0: mp4_u32 size; sl@0: mp4_u32 type; sl@0: mp4_u64 largeSize; sl@0: mp4_u8 extendedType[16]; sl@0: mp4_u8 version; sl@0: mp4_u8 flags[3]; sl@0: } atomHeader; sl@0: sl@0: sl@0: typedef struct fileTypeAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 majorBrand; sl@0: mp4_u32 minorVersion; sl@0: mp4_u32 *compatibleBrands; sl@0: } fileTypeAtom; sl@0: sl@0: sl@0: typedef struct movieHeaderAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 creationTime; sl@0: mp4_u32 modificationTime; sl@0: mp4_u32 timeScale; sl@0: mp4_u32 duration; sl@0: mp4_u32 nextTrackID; sl@0: mp4_u64 creationTime64; sl@0: mp4_u64 modificationTime64; sl@0: mp4_u64 duration64; sl@0: } movieHeaderAtom; sl@0: sl@0: sl@0: typedef struct objectDescriptorAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u8 tag; sl@0: mp4_u32 sizeOfInstance; sl@0: mp4_u16 flags; sl@0: mp4_u8 ODProfileLevelIndication; sl@0: mp4_u8 SceneProfileLevelIndication; sl@0: mp4_u8 AudioProfileLevelIndication; sl@0: mp4_u8 VisualProfileLevelIndication; sl@0: mp4_u8 GraphicsProfileLevelIndication; sl@0: } objectDescriptorAtom; sl@0: sl@0: sl@0: typedef struct trackHeaderAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 creationTime; sl@0: mp4_u32 modificationTime; sl@0: mp4_u32 trackID; sl@0: mp4_u32 reserved; sl@0: mp4_u32 duration; sl@0: mp4_u64 creationTime64; sl@0: mp4_u64 modificationTime64; sl@0: mp4_u64 duration64; sl@0: mp4_u16 width; sl@0: mp4_u16 height; sl@0: mp4_bool isAudio; sl@0: mp4_bool isVisual; sl@0: } trackHeaderAtom; sl@0: sl@0: sl@0: typedef struct mediaHeaderAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 creationTime; sl@0: mp4_u32 modificationTime; sl@0: mp4_u32 timeScale; sl@0: mp4_u32 duration; sl@0: mp4_u64 creationTime64; sl@0: mp4_u64 modificationTime64; sl@0: mp4_u64 duration64; sl@0: } mediaHeaderAtom; sl@0: sl@0: sl@0: typedef struct handlerAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 handlerType; sl@0: mp4_u8 *name; sl@0: } handlerAtom; sl@0: sl@0: sl@0: typedef struct dataEntryURLAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: } dataEntryURLAtom; sl@0: sl@0: sl@0: typedef struct dataEntryURNAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: } dataEntryURNAtom; sl@0: sl@0: sl@0: typedef struct dataReferenceAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 entryCount; sl@0: dataEntryURLAtom *url; sl@0: dataEntryURNAtom *urn; sl@0: } dataReferenceAtom; sl@0: sl@0: sl@0: typedef struct dataInformationAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: dataReferenceAtom *dref; sl@0: } dataInformationAtom; sl@0: sl@0: sl@0: typedef struct timeToSampleAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 entryCount; sl@0: mp4_u32 *sampleCount; sl@0: mp4_i32 *sampleDelta; sl@0: } timeToSampleAtom; sl@0: sl@0: sl@0: typedef struct compositionTimeToSampleAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 entryCount; sl@0: mp4_u32 *sampleCount; sl@0: mp4_u32 *sampleOffset; sl@0: } compositionTimeToSampleAtom; sl@0: sl@0: sl@0: typedef struct ESDAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u8 esDescrTag; sl@0: mp4_u32 size; sl@0: mp4_u16 ESID; sl@0: mp4_u8 flags; sl@0: mp4_u16 dependsOnESID; sl@0: mp4_u8 URLLength; sl@0: mp4_u8 *URLString; sl@0: mp4_u16 OCRESID; sl@0: mp4_u8 decConfDescrTag; sl@0: mp4_u32 decConfDescrSize; sl@0: mp4_u8 objectTypeIndication; sl@0: mp4_u8 stream; sl@0: mp4_u32 bufferSizeDB; sl@0: mp4_u32 maxBitrate; sl@0: mp4_u32 avgBitrate; sl@0: mp4_u8 decSpecificInfoTag; sl@0: mp4_u32 decSpecificInfoSize; sl@0: mp4_u8 *decSpecificInfo; sl@0: } ESDAtom; sl@0: sl@0: sl@0: typedef struct visualSampleEntry sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u16 dataReferenceIndex; sl@0: mp4_u16 width; sl@0: mp4_u16 height; sl@0: ESDAtom *esd; sl@0: } visualSampleEntry; sl@0: sl@0: sl@0: typedef struct audioSampleEntry sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u16 dataReferenceIndex; sl@0: mp4_u16 timeScale; sl@0: ESDAtom *esd; sl@0: } audioSampleEntry; sl@0: sl@0: sl@0: typedef struct mpegSampleEntry sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u16 dataReferenceIndex; sl@0: ESDAtom *esd; sl@0: } mpegSampleEntry; sl@0: sl@0: sl@0: typedef struct bitrateAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 avgBitrate; sl@0: mp4_u32 maxBitrate; sl@0: } bitrateAtom; sl@0: sl@0: sl@0: typedef struct h263SpecificAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 vendor; sl@0: mp4_u8 decoderVersion; sl@0: mp4_u8 h263Level; sl@0: mp4_u8 h263Profile; sl@0: bitrateAtom *bitr; sl@0: } h263SpecificAtom; sl@0: sl@0: sl@0: typedef struct h263SampleEntry sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u16 dataReferenceIndex; sl@0: mp4_u16 width; sl@0: mp4_u16 height; sl@0: h263SpecificAtom *d263; sl@0: } h263SampleEntry; sl@0: sl@0: sl@0: typedef struct amrDecSpecStruc sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 vendor; sl@0: mp4_u8 decoderVersion; sl@0: mp4_u16 modeSet; sl@0: mp4_u8 modeChangePeriod; sl@0: mp4_u8 framesPerSample; sl@0: } amrDecSpecStruc; sl@0: sl@0: sl@0: typedef struct amrSampleEntry sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u16 dataReferenceIndex; sl@0: mp4_u16 timeScale; sl@0: amrDecSpecStruc *damr; sl@0: } amrSampleEntry; sl@0: sl@0: typedef struct avcConfigurationAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u8 *avcConfig; sl@0: mp4_u32 avcConfigSize; sl@0: } avcConfigurationAtom; sl@0: sl@0: typedef struct mpeg4BitrateAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 bufferSizeDB; sl@0: mp4_u32 maxBitRate; sl@0: mp4_u32 avgBitrate; sl@0: } mpeg4BitrateAtom; sl@0: sl@0: typedef struct mpeg4ExtensionDescriptorsAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u8 *descr; sl@0: mp4_u32 descrSize; sl@0: } mpeg4ExtensionDescriptorsAtom; sl@0: sl@0: typedef struct avcSampleEntry sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u16 dataReferenceIndex; sl@0: mp4_u16 width; sl@0: mp4_u16 height; sl@0: avcConfigurationAtom *avcc; sl@0: mpeg4BitrateAtom *btrt; sl@0: mpeg4ExtensionDescriptorsAtom *m4ds; sl@0: } avcSampleEntry; sl@0: sl@0: typedef struct qcelpDecSpecStruc sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 vendor; sl@0: mp4_u8 decoderVersion; sl@0: mp4_u8 framesPerSample; sl@0: } qcelpDecSpecStruc; sl@0: sl@0: typedef struct qcelpSampleEntry sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u16 dataReferenceIndex; sl@0: mp4_u16 timeScale; sl@0: qcelpDecSpecStruc *dqcp; sl@0: } qcelpSampleEntry; sl@0: sl@0: typedef struct avcParameterSampleEntry sl@0: { sl@0: sl@0: } avcParameterSampleEntry; sl@0: sl@0: typedef struct sampleDescriptionAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 entryCount; sl@0: visualSampleEntry *mp4v[STSDMAXSAMPLEENTRYCOUNT]; sl@0: audioSampleEntry *mp4a[STSDMAXSAMPLEENTRYCOUNT]; sl@0: mpegSampleEntry *mp4s[STSDMAXSAMPLEENTRYCOUNT]; sl@0: h263SampleEntry *s263[STSDMAXSAMPLEENTRYCOUNT]; sl@0: amrSampleEntry *samr[STSDMAXSAMPLEENTRYCOUNT]; sl@0: amrSampleEntry *sawb[STSDMAXSAMPLEENTRYCOUNT]; sl@0: /* AVC addition */ sl@0: avcSampleEntry *avc1[STSDMAXSAMPLEENTRYCOUNT]; sl@0: /* QCELP 13K addition */ sl@0: qcelpSampleEntry *sqcp[STSDMAXSAMPLEENTRYCOUNT]; sl@0: avcParameterSampleEntry *avcp[STSDMAXSAMPLEENTRYCOUNT]; sl@0: } sampleDescriptionAtom; sl@0: sl@0: sl@0: typedef struct sampleSizeAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 sampleSize; sl@0: mp4_u32 sampleCount; sl@0: mp4_u32 *entrySize; sl@0: } sampleSizeAtom; sl@0: sl@0: sl@0: typedef struct sampleToChunkAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 entryCount; sl@0: mp4_u32 *firstChunk; sl@0: mp4_u32 *samplesPerChunk; sl@0: mp4_u32 *sampleDescriptionIndex; sl@0: } sampleToChunkAtom; sl@0: sl@0: sl@0: typedef struct chunkOffsetAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 entryCount; sl@0: mp4_u32 *chunkOffset; sl@0: } chunkOffsetAtom; sl@0: sl@0: typedef struct chunkOffset64Atom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 entryCount; sl@0: mp4_u64 *chunkOffset; sl@0: } chunkOffset64Atom; sl@0: sl@0: sl@0: typedef struct syncSampleAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 entryCount; sl@0: mp4_u32 *sampleNumber; sl@0: } syncSampleAtom; sl@0: sl@0: sl@0: typedef struct shadowSyncSampleAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: } shadowSyncSampleAtom; sl@0: sl@0: typedef struct sampleDependency sl@0: { sl@0: mp4_u8 sDependsOn; sl@0: mp4_u8 sIsDependentOn; sl@0: mp4_u8 sHasRedundancy; sl@0: } sampleDependency; sl@0: sl@0: typedef struct sampleDependencyAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u32 sampleCount; sl@0: sampleDependency *dep; sl@0: } sampleDependencyAtom; sl@0: sl@0: typedef struct sampleTableAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: timeToSampleAtom *stts; sl@0: compositionTimeToSampleAtom *ctts; sl@0: sampleDescriptionAtom *stsd; sl@0: sampleSizeAtom *stsz; sl@0: sampleToChunkAtom *stsc; sl@0: mp4_bool is32BitOffsets; sl@0: union sl@0: { sl@0: chunkOffsetAtom *stco; sl@0: chunkOffset64Atom *stco64; sl@0: }; sl@0: syncSampleAtom *stss; sl@0: shadowSyncSampleAtom *stsh; sl@0: sampleDependencyAtom *sdtp; sl@0: } sampleTableAtom; sl@0: sl@0: sl@0: typedef struct videoMediaHeaderAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: } videoMediaHeaderAtom; sl@0: sl@0: sl@0: typedef struct soundMediaHeaderAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: } soundMediaHeaderAtom; sl@0: sl@0: sl@0: typedef struct mediaInformationAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: videoMediaHeaderAtom *vmhd; sl@0: soundMediaHeaderAtom *smhd; sl@0: dataInformationAtom *dinf; sl@0: sampleTableAtom *stbl; sl@0: } mediaInformationAtom; sl@0: sl@0: sl@0: typedef struct mediaAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mediaHeaderAtom *mdhd; sl@0: handlerAtom *hdlr; sl@0: mediaInformationAtom *minf; sl@0: } mediaAtom; sl@0: sl@0: sl@0: typedef struct trackReferenceAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: } trackReferenceAtom; sl@0: sl@0: sl@0: typedef struct editListContainerAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: } editListContainerAtom; sl@0: sl@0: sl@0: typedef struct copyrightAtom sl@0: { sl@0: void *p; sl@0: } copyrightAtom; sl@0: sl@0: typedef struct userDataAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u64 atomcontentloc; //used for parsing sl@0: mp4_u32 atomcontentsize; //used for parsing and composing sl@0: mp4_u8 *contentdata; //used for composing sl@0: } userDataAtom; sl@0: sl@0: typedef struct trackAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: trackHeaderAtom *tkhd; sl@0: trackReferenceAtom *tref; sl@0: editListContainerAtom *edts; sl@0: mediaAtom *mdia; sl@0: userDataAtom *udta; sl@0: } trackAtom; sl@0: sl@0: typedef struct ID32Atom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u64 atomcontentloc; sl@0: mp4_u16 language; // top bit is padding, remaining 15 bits is Packed ISO-639-2/T language code sl@0: } ID32Atom; sl@0: sl@0: typedef struct metaAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: handlerAtom *hdlr; sl@0: ID32Atom *ID32; sl@0: } metaAtom; sl@0: sl@0: typedef struct movieAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: movieHeaderAtom *mvhd; sl@0: trackAtom *trakAudio; // audio sl@0: trackAtom *trakVideo; // video sl@0: objectDescriptorAtom *iods; sl@0: userDataAtom *udta; sl@0: metaAtom *meta; sl@0: } movieAtom; sl@0: sl@0: sl@0: typedef struct mediaDataAtom sl@0: { sl@0: atomHeader *atomhdr; sl@0: mp4_u8 *data; sl@0: } mediaDataAtom; sl@0: sl@0: sl@0: typedef struct sampleTable sl@0: { sl@0: mp4_u32 currentChunk; sl@0: sl@0: /* Decoding time to sample */ sl@0: mp4_u32 sttsEntryCount; sl@0: mp4_u32 *sttsSampleCount; sl@0: mp4_u32 *sttsSampleDelta; sl@0: mp4_u32 sttsMaxEntryCount; sl@0: mp4_u32 sttsCurrentEntryCount; sl@0: sl@0: /* Sample size */ sl@0: mp4_u32 stszSampleSize; sl@0: mp4_u32 stszSampleCount; sl@0: mp4_u32 *stszEntrySize; sl@0: mp4_u32 stszMaxSampleCount; sl@0: mp4_u32 stszCurrentSampleCount; sl@0: sl@0: /* Sample to chunk */ sl@0: mp4_u32 stscEntryCount; sl@0: mp4_u32 *stscFirstChunk; sl@0: mp4_u32 *stscSamplesPerChunk; sl@0: mp4_u32 *stscSampleDescriptionIndex; sl@0: mp4_u32 stscMaxEntryCount; sl@0: mp4_u32 stscCurrentEntryCount; sl@0: sl@0: /* Chunk offset */ sl@0: mp4_u32 stcoEntryCount; sl@0: mp4_u64 *stcoChunkOffset; sl@0: mp4_u32 stcoMaxEntryCount; sl@0: mp4_u32 stcoCurrentEntryCount; sl@0: mp4_bool stcoNeed64Bits; sl@0: sl@0: /* Sync sample */ sl@0: mp4_u32 stssEntryCount; sl@0: mp4_u32 *stssSampleNumber; sl@0: mp4_u32 stssMaxEntryCount; sl@0: mp4_u32 stssCurrentEntryCount; sl@0: /* Sample Dependency */ sl@0: mp4_u32 sdtpEntryCount; sl@0: mp4_u8 *sdtpSampleDependency; sl@0: mp4_u32 sdtpMaxEntryCount; sl@0: mp4_u32 sdtpCurrentEntryCount; sl@0: } sampleTable; sl@0: sl@0: sl@0: typedef struct MP4HandleStruct sl@0: { sl@0: mp4_u8 sourceType; /* Determines the type of the source file (CAF or RFile64) */ sl@0: void *file; /* FILE * of possible file */ sl@0: void *fs; /* File server */ sl@0: void *rfile; /* File handle */ sl@0: ContentAccess::CData *cfile; /* used when reading via the CAF and not the file based interfaces */ sl@0: mp4_i32 cafError; /* variable to store possible CAF error to be reported to client */ sl@0: void *tmpfile; /* FILE * of temporary output file */ sl@0: void *metaDataFile[NUM_MDF]; /* File handles for metadata files */ sl@0: MP4FileName metaDataFileName[NUM_MDF]; /* Names of the temporary meta data files */ sl@0: MP4FileName fileName; /* Name of the file */ sl@0: MP4FileName tmpFileName; /* Name of the temporary file */ sl@0: mp4_u64 bytesInTmpFile; /* Number of bytes in temporary file */ sl@0: mp4_u64 mediaDataBytes; /* Number of media data bytes */ sl@0: mp4_bool ftypWritten; /* Has FTYP been written */ sl@0: mp4_u32 flags; /* Composing flags */ sl@0: mp4_u32 type; /* Type of audio/video */ sl@0: list_s *mem; /* Memory list */ sl@0: mp4_u32 position; /* Current position in memory */ sl@0: mp4_u32 absPosition; /* Current absolute position in memory */ sl@0: mp4_u64 lastAccessedPosInFile; /* Last accessed position in a file */ sl@0: mp4_u8 *buf; /* Temporary buffer space */ sl@0: mp4_u8 *diskReadBuf; /* Memory for file buffering */ sl@0: mp4_u32 diskReadPos; /* Reading position in the file */ sl@0: mp4_u64 diskReadBufStart; /* Position of the start of the buffer */ sl@0: mp4_u32 diskReadBufPos; /* Reading position inside buffer */ sl@0: mp4_u32 diskReadSize; /* Number of bytes in buffer */ sl@0: mp4_u8 *diskWriteBuf; /* Memory for file buffering */ sl@0: mp4_bool ftypRead; /* FTYP atom has been read */ sl@0: fileTypeAtom *ftyp; /* Pointer to file type atom structure */ sl@0: mp4_bool metaDataComplete; /* Metadata has been completeley read */ sl@0: movieAtom *moov; /* Pointer to movie atom structure */ sl@0: mp4_u32 videoSampleNum; /* Current video sample number */ sl@0: mp4_u64 videoFrameOffset; /* Absolute position of current video frame */ sl@0: mp4_u32 videoFrameSize; /* Size of current video frame in bytes */ sl@0: mp4_bool videoLast; /* Has last video sample been read */ sl@0: mp4_u32 videoTimeScale; /* Video timescale */ sl@0: mp4_u64 videoDuration; /* Duration of video when composing */ sl@0: mp4_u16 videoWidth; /* Video image width */ sl@0: mp4_u16 videoHeight; /* Video image height */ sl@0: mp4_u32 videoMaxBitrate; /* MPEG-4 video maximum bitrate */ sl@0: mp4_u32 videoAvgBitrate; /* MPEG-4 video average bitrate */ sl@0: mp4_u8 *videoDecSpecificInfo; /* MPEG-4 video DecoderSpecificInfo */ sl@0: mp4_u32 videoDecSpecificInfoSize; /* MPEG-4 video DecoderSpecificInfo size in bytes */ sl@0: sampleTable *videoSampleTable; /* Video sample table */ sl@0: mp4_u8 videoLevel; /* Video codec level, default is H.263 level 10 */ sl@0: mp4_u32 audioSampleNum; /* Current audio sample number */ sl@0: mp4_u32 audioSampleSize; /* Size of current audio sample in bytes */ sl@0: mp4_u64 audioSampleOffset; /* Absolute position of current audio frame (in MP4 file) */ sl@0: mp4_u32 audioFrameCount; /* Number of audio frames when composing */ sl@0: mp4_u32 audioTimeScale; /* Audio timescale */ sl@0: mp4_u64 audioDuration; /* Duration of audio when composing */ sl@0: mp4_bool audioLast; /* Has last audio sample been read */ sl@0: mp4_u8 *audioDecSpecificInfo; /* MPEG audio DecoderSpecificInfo */ sl@0: mp4_u32 audioDecSpecificInfoSize; /* MPEG audio DecoderSpecificInfo size in bytes */ sl@0: sampleTable *audioSampleTable; /* Audio sample table */ sl@0: mp4_u8 audioFramesPerSample; /* AMR frames per sample value */ sl@0: mp4_u16 audioModeSet; /* AMR mode set */ sl@0: mp4_u32 metaDataBlocks; /* Number of metadata blocks in memory */ sl@0: mp4_bool metaDataOnDisk; /* Is (a part of) metadata on the disk */ sl@0: mp4_u32 metaDataSize; /* Size of metadata */ sl@0: mp4_u32 videoSampleEntryIndex; /* SampleEntry index of the video frame being read */ sl@0: mp4_u32 audioSampleEntryIndex; /* SampleEntry index of the audio frame being read */ sl@0: mp4_u8 avcNalUnitLengthSize; /* byte size of the length field */ sl@0: mp4_bool generate3G2; /* 3GPP2 File Format Generation is Selected: default:FALSE (Generate 3GP)*/ sl@0: mp4_bool generateMP4; /* MPEG-4 File Format Generation is Selected: defailt:FALSE (Generate 3GP)*/ sl@0: mp4_bool qcelpStoredAsMPEGAudio; /* QCELP 13K is registered as MPEG4 Audio: default: FALSE (in QCELPSampleEntry)*/ sl@0: mp4_u64 audioMediaDataSize; /* Total byte size of the written audio data. This is used to calculate the max and avg bitrates */ sl@0: mp4_u32 ES_DescriptorSize; /* size of the ES_Descriptor inside the ESDS box */ sl@0: sl@0: // composeToBuffer: sl@0: mp4_u8 *composeBuffer; sl@0: mp4_bool bufferWrite; sl@0: mp4_u32 bytesProgressed; sl@0: mp4_u32 ftypdelta; sl@0: mp4_u32 *composedSize; sl@0: sl@0: CFileWriter* filewriter; /* Async buffering filewriter */ sl@0: CMetaDataFileWriter* metadatafilewriter; /* Async buffering metadata temp file writer */ sl@0: sl@0: mp4_bool LastWriteDataCalled; /* When TRUE, it indicates that ParseWriteData() function is called for the last time */ sl@0: mp4_bool FileHandleFromOutside; /* When TRUE file handle is passed to library instead of file name, don't close file in end */ sl@0: sl@0: mp4_bool metaDataFileEmpty[NUM_MDF]; /* when TRUE it indicates that metadata file has been read and rest of data is in readbuffer of metadatafilewriter */ sl@0: sl@0: userDataAtom* moovUDTA; // used to compose MOOV UDTA (User Data) sl@0: userDataAtom* audioUDTA; // used to compose AudioTrack UDTA (User Data) sl@0: userDataAtom* videoUDTA; // used to compose VideoTrack UDTA (User Data) sl@0: sl@0: TDriveNumber fileHandleDrive; /* Used when we get file handle to library from outside. Used to indicate which drive are metadata temp files written.*/ sl@0: sl@0: // Custom buffer size additions: sl@0: mp4_u32 mediaWriteBufferSize; sl@0: mp4_u32 metaWriteBufferSize; sl@0: mp4_u32 writeBufferMaxCount; sl@0: mp4_u32 readBufferSize; sl@0: sl@0: // Async parsing observer sl@0: M3GPMP4LibAsyncObserver* asyncObserver; sl@0: CFileAsyncParser* asyncReader; sl@0: M3GPMP4LibAsyncTempFileRemoverObserver* tempFileRemoverObserver; sl@0: sl@0: void *file32Duplicate; //this is a RFile64 duplicate of the RFile used in Open sl@0: } MP4HandleStruct; sl@0: sl@0: sl@0: typedef MP4HandleStruct *MP4HandleImp; sl@0: sl@0: sl@0: mp4_i32 metaDataAvailable(MP4HandleImp handle); sl@0: mp4_i32 readFTYP(MP4HandleImp handle, fileTypeAtom *ftyp); sl@0: mp4_i32 readMetaData(MP4HandleImp handle); sl@0: mp4_i32 readMoov(MP4HandleImp handle, movieAtom *moov); sl@0: mp4_i32 readAtomHeader(MP4HandleImp handle, atomHeader *ah); sl@0: mp4_i32 readFullAtomHeader(MP4HandleImp handle, atomHeader *ah); sl@0: mp4_i32 readMVHD(MP4HandleImp handle, movieHeaderAtom *mvhd); sl@0: mp4_i32 readIODS(MP4HandleImp handle, objectDescriptorAtom *iods); sl@0: mp4_i32 readTRAK(MP4HandleImp handle, trackAtom *trak); sl@0: mp4_i32 readUnknown(MP4HandleImp handle); sl@0: mp4_i32 readTKHD(MP4HandleImp handle, trackHeaderAtom *tkhd); sl@0: mp4_i32 readTREF(MP4HandleImp handle, trackReferenceAtom *tref); sl@0: mp4_i32 readEDTS(MP4HandleImp handle, editListContainerAtom *edts); sl@0: mp4_i32 readMDIA(MP4HandleImp handle, mediaAtom *mdia); sl@0: mp4_i32 readMDHD(MP4HandleImp handle, mediaHeaderAtom *mdhd); sl@0: mp4_i32 readHDLR(MP4HandleImp handle, handlerAtom *hdlr); sl@0: mp4_i32 readMINF(MP4HandleImp handle, mediaInformationAtom *minf); sl@0: mp4_i32 readVMHD(MP4HandleImp handle, videoMediaHeaderAtom *vmhd); sl@0: mp4_i32 readSMHD(MP4HandleImp handle, soundMediaHeaderAtom *smhd); sl@0: mp4_i32 readDINF(MP4HandleImp handle, dataInformationAtom *dinf); sl@0: mp4_i32 readDREF(MP4HandleImp handle, dataReferenceAtom *dref); sl@0: mp4_i32 readURL(MP4HandleImp handle, dataEntryURLAtom *url); sl@0: mp4_i32 readURN(MP4HandleImp handle, dataEntryURNAtom *urn); sl@0: mp4_i32 readSTBL(MP4HandleImp handle, sampleTableAtom *stbl); sl@0: mp4_i32 readSTTS(MP4HandleImp handle, timeToSampleAtom *stts); sl@0: mp4_i32 readCTTS(MP4HandleImp handle, compositionTimeToSampleAtom *ctts); sl@0: mp4_i32 readSTSS(MP4HandleImp handle, syncSampleAtom *stss); sl@0: mp4_i32 readSTSD(MP4HandleImp handle, sampleDescriptionAtom *stsd); sl@0: mp4_i32 readSTSZ(MP4HandleImp handle, sampleSizeAtom *stsz); sl@0: mp4_i32 readSTZ2(MP4HandleImp handle, sampleSizeAtom *stsz); sl@0: mp4_i32 readSTSC(MP4HandleImp handle, sampleToChunkAtom *stsc); sl@0: mp4_i32 readSTCO(MP4HandleImp handle, chunkOffsetAtom *stco); sl@0: mp4_i32 readCO64(MP4HandleImp handle, chunkOffset64Atom *stco64); sl@0: mp4_i32 readMP4V(MP4HandleImp handle, visualSampleEntry *mp4v); sl@0: mp4_i32 readMP4A(MP4HandleImp handle, audioSampleEntry *mp4a); sl@0: mp4_i32 readMP4S(MP4HandleImp handle, mpegSampleEntry *mp4s); sl@0: mp4_i32 readS263(MP4HandleImp handle, h263SampleEntry *s263); sl@0: mp4_i32 readSAMR(MP4HandleImp handle, amrSampleEntry *samr); sl@0: mp4_i32 readSAWB(MP4HandleImp handle, amrSampleEntry *sawb); sl@0: mp4_i32 readESD(MP4HandleImp handle, ESDAtom *esd); sl@0: mp4_i32 readD263(MP4HandleImp handle, h263SpecificAtom *d263); sl@0: mp4_i32 readBITR(MP4HandleImp handle, bitrateAtom *bitr); sl@0: mp4_i32 readDAMR(MP4HandleImp handle, amrDecSpecStruc *damr); sl@0: mp4_i32 readMeta(MP4HandleImp handle, metaAtom *meta); sl@0: /* avc inclusions*/ sl@0: mp4_i32 readAVC1(MP4HandleImp handle, avcSampleEntry *avc1); sl@0: mp4_i32 readSDTP(MP4HandleImp handle, sampleDependencyAtom *sdtp, mp4_i32 sample_count); sl@0: /* QCELP 13k inclusions */ sl@0: mp4_i32 readSQCP(MP4HandleImp handle, qcelpSampleEntry *sqcp); sl@0: mp4_i32 readDQCP(MP4HandleImp handle, qcelpDecSpecStruc *dqcp); sl@0: /* inline related */ sl@0: mp4_i32 readID32(MP4HandleImp handle, ID32Atom *ID32); sl@0: sl@0: mp4_i32 freeFTYP(fileTypeAtom *ftyp); sl@0: mp4_i32 freeMOOV(movieAtom *moov); sl@0: mp4_i32 freeAtomHeader(atomHeader *atomhdr); sl@0: mp4_i32 freeMVHD(movieHeaderAtom *mvhd); sl@0: mp4_i32 freeTRAK(trackAtom *trak); sl@0: mp4_i32 freeTKHD(trackHeaderAtom *tkhd); sl@0: mp4_i32 freeTREF(trackReferenceAtom *tref); sl@0: mp4_i32 freeEDTS(editListContainerAtom *edts); sl@0: mp4_i32 freeMDIA(mediaAtom *mdia); sl@0: mp4_i32 freeMDHD(mediaHeaderAtom *mdhd); sl@0: mp4_i32 freeHDLR(handlerAtom *hdlr); sl@0: mp4_i32 freeMINF(mediaInformationAtom *minf); sl@0: mp4_i32 freeVMHD(videoMediaHeaderAtom *vmhd); sl@0: mp4_i32 freeSMHD(soundMediaHeaderAtom *smhd); sl@0: mp4_i32 freeDINF(dataInformationAtom *dinf); sl@0: mp4_i32 freeDREF(dataReferenceAtom *dref); sl@0: mp4_i32 freeURL(dataEntryURLAtom *url); sl@0: mp4_i32 freeURN(dataEntryURNAtom *urn); sl@0: mp4_i32 freeSTBL(sampleTableAtom *stbl); sl@0: mp4_i32 freeSTTS(timeToSampleAtom *stts); sl@0: mp4_i32 freeCTTS(compositionTimeToSampleAtom *ctts); sl@0: mp4_i32 freeSTSD(sampleDescriptionAtom *stsd); sl@0: mp4_i32 freeMP4V(visualSampleEntry *mp4v); sl@0: mp4_i32 freeESD(ESDAtom *esd); sl@0: mp4_i32 freeMP4A(audioSampleEntry *mp4a); sl@0: mp4_i32 freeMP4S(mpegSampleEntry *mp4s); sl@0: mp4_i32 freeS263(h263SampleEntry *s263); sl@0: mp4_i32 freeD263(h263SpecificAtom *d263); sl@0: mp4_i32 freeBITR(bitrateAtom *bitr); sl@0: mp4_i32 freeSAMR(amrSampleEntry *samr); sl@0: mp4_i32 freeSAWB(amrSampleEntry *sawb); sl@0: mp4_i32 freeDAMR(amrDecSpecStruc *damr); sl@0: mp4_i32 freeSTSZ(sampleSizeAtom *stsz); sl@0: mp4_i32 freeSTSC(sampleToChunkAtom *stsc); sl@0: mp4_i32 freeSTCO(chunkOffsetAtom *stco); sl@0: mp4_i32 freeSTCO64(chunkOffset64Atom *stco64); sl@0: mp4_i32 freeSTSS(syncSampleAtom *stss); sl@0: mp4_i32 freeSTSH(shadowSyncSampleAtom *stsh); sl@0: mp4_i32 freeIODS(objectDescriptorAtom *iods); sl@0: mp4_i32 readUDTA(MP4HandleImp handle, userDataAtom *udta); sl@0: mp4_i32 freeUDTA(userDataAtom *udta); sl@0: mp4_i32 freeSDTP(sampleDependencyAtom* sdtp); sl@0: mp4_i32 freeMETA(metaAtom *meta); sl@0: /* The following and AVC related */ sl@0: mp4_i32 freeAVC1(avcSampleEntry *avc1); sl@0: mp4_i32 freeM4DS(mpeg4ExtensionDescriptorsAtom *m4ds); sl@0: mp4_i32 freeBTRT(mpeg4BitrateAtom *btrt); sl@0: mp4_i32 freeAVCC(avcConfigurationAtom *avcc); sl@0: /* QCELP 13K related */ sl@0: mp4_i32 freeSQCP(qcelpSampleEntry *sqcp); sl@0: mp4_i32 freeDQCP(qcelpDecSpecStruc *dqcp); sl@0: /* inline related */ sl@0: mp4_i32 freeID32(ID32Atom *ID32); sl@0: sl@0: mp4_i32 determineVideoLength(MP4HandleImp handle, mp4_u32 *videolength); sl@0: mp4_i32 determineFrameRate(MP4HandleImp handle, mp4_double *framerate); sl@0: mp4_i32 determineVideoType(MP4HandleImp handle, mp4_u32 *videotype); sl@0: mp4_i32 determineVideoResolution(MP4HandleImp handle, mp4_u32 *videowidth, mp4_u32 *videoheight); sl@0: mp4_i32 determineVideoTimeScale(MP4HandleImp handle, mp4_u32 *timescale); sl@0: mp4_i32 determineAudioLength(MP4HandleImp handle, mp4_u32 *audiolength); sl@0: mp4_i32 determineAudioType(MP4HandleImp handle, mp4_u32 *audiotype); sl@0: mp4_i32 determineAudioFramesPerSample(MP4HandleImp handle, mp4_u8 *framespersample); sl@0: mp4_i32 determineAudioTimeScale(MP4HandleImp handle, mp4_u32 *timescale); sl@0: mp4_i32 determineAudioAverageBitRate(MP4HandleImp handle, mp4_u32 *averagebitrate); sl@0: mp4_i32 determineStreamSize(MP4HandleImp handle, mp4_u32 *streamsize); sl@0: mp4_i32 determineStreamAverageBitRate(MP4HandleImp handle, mp4_u32 *streamaveragebitrate, mp4_u32 streamsize); sl@0: mp4_i32 advanceVideoFrame(MP4HandleImp handle, trackAtom *trak); sl@0: mp4_i32 resolveVideoSampleOffset(MP4HandleImp handle, sampleTableAtom *stbl); sl@0: mp4_i32 resolveVideoSampleSize(MP4HandleImp handle, sampleSizeAtom *stsz); sl@0: mp4_i32 fetchVideoFrame(MP4HandleImp handle, trackAtom *trak, mp4_u8 *buffer, mp4_u32 buffersize, mp4_u32 *framesize, mp4_u32 *framenumber, mp4_bool *keyframe, mp4_u32 *timestamp2); sl@0: mp4_i32 isVideoFrameKeyFrame(MP4HandleImp handle, trackAtom *trak, mp4_bool *keyframe); sl@0: mp4_i32 convertVideoSampleToTime(MP4HandleImp handle, mediaAtom *mdia, mp4_u32 *framenumber, mp4_u32 *timestamp2); sl@0: mp4_i32 advanceAudioSample(MP4HandleImp handle, trackAtom *trak); sl@0: mp4_i32 resolveAudioSampleOffset(MP4HandleImp handle, sampleTableAtom *stbl); sl@0: mp4_i32 resolveAudioSampleSize(MP4HandleImp handle, sampleSizeAtom *stsz); sl@0: mp4_i32 fetchAudioSample(MP4HandleImp handle, trackAtom *trak, mp4_u8 *buffer, mp4_u32 buffersize, mp4_u32 *framesize, mp4_u32 *timestamp, mp4_u32 *returnedframes, mp4_u32 *timestamp2); sl@0: mp4_i32 convertAudioSampleToTime(MP4HandleImp handle, mediaAtom *mdia, mp4_u32 *timestamp, mp4_u32 *timestamp2); sl@0: mp4_i32 convertTimeToSample(MP4HandleImp handle, trackAtom *trak, mp4_u32 position, mp4_u32 *sample); sl@0: mp4_i32 goToVideoSample(MP4HandleImp handle, trackAtom *trak, mp4_u32 sample); sl@0: mp4_i32 goToAudioSample(MP4HandleImp handle, trackAtom *trak, mp4_u32 sample); sl@0: mp4_i32 findVideoKeyFrame(MP4HandleImp handle, trackAtom *trak, mp4_u32 sample, mp4_u32 *newsample); sl@0: mp4_i32 fetchAudioSampleAsync(MP4HandleImp handle, trackAtom *trak, mp4_u8 *buffer, mp4_u32* buffersize); sl@0: mp4_i32 fetchVideoFrameAsync(MP4HandleImp handle, trackAtom *trak, mp4_u8 *buffer, mp4_u32* buffersize); sl@0: mp4_i64 getChunkOffset(sampleTableAtom *stbl, mp4_u32 index); sl@0: #endif sl@0: sl@0: sl@0: // End of File