1/* 2 * Copyright (c) 2005, David McPaul 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * * Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 21 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 22 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 23 * OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25#ifndef MP4_STRUCTS_H 26#define MP4_STRUCTS_H 27 28 29#include <SupportDefs.h> 30 31 32#define AUDIO_NONE 'NONE' 33#define AUDIO_RAW 'raw ' 34#define AUDIO_TWOS1 'twos' 35#define AUDIO_TWOS2 'sowt' 36#define AUDIO_IMA4 'ima4' 37#define AUDIO_MS_PCM02 0x6D730002 38#define AUDIO_INTEL_PCM17 0x6D730011 39#define AUDIO_MPEG3_CBR 0x6D730055 40 41// this is all from the avi reader. we rework it for mp4 42struct mp4_main_header { 43 uint32 micro_sec_per_frame; 44 uint32 max_bytes_per_sec; 45 uint32 padding_granularity; 46 uint32 flags; 47 uint32 total_frames; 48 uint32 initial_frames; 49 uint32 streams; 50 uint32 suggested_buffer_size; 51 uint32 width; 52 uint32 height; 53}; 54 55struct mp4_stream_header 56{ 57 uint32 fourcc_type; 58 uint32 fourcc_handler; 59 uint32 flags; 60 uint16 priority; 61 uint16 language; 62 uint32 initial_frames; 63 uint32 scale; 64 uint32 rate; 65 uint32 start; 66 uint32 length; 67 uint32 suggested_buffer_size; 68 uint32 quality; 69 uint32 sample_size; 70 int16 rect_left; 71 int16 rect_top; 72 int16 rect_right; 73 int16 rect_bottom; 74}; 75 76struct VideoMetaData 77{ 78 uint32 compression; 79 uint32 codecSubType; 80 uint32 BufferSize; 81 uint32 width; 82 uint32 height; 83 uint16 planes; 84 uint16 bit_count; 85 uint32 image_size; 86 uint32 HorizontalResolution; 87 uint32 VerticalResolution; 88 uint32 FrameCount; 89 float FrameRate; // Frames per second 90 uint8 *theDecoderConfig; 91 size_t DecoderConfigSize; 92}; 93 94struct AudioMetaData 95{ 96 uint32 compression; // compression used (ie codecid) 97 uint32 codecSubType; // Additional codecid 98 uint16 NoOfChannels; // 1 = mono, 2 = stereo 99 uint16 SampleSize; // bits per sample 100 float SampleRate; // Samples per second 101 uint32 BufferSize; // (Sample Rate * NoOfchannels * SampleSize * SamplesPerFrame) / 8 = bytes per second 102 uint32 FrameSize; // No Of Samples in 1 frame of audio (SamplesPerFrame) 103 uint32 BitRate; // Average Bitrate 104 uint8 *theDecoderConfig; 105 size_t DecoderConfigSize; 106}; 107 108struct TimeToSample { 109 uint32 Count; 110 uint32 Duration; 111}; 112 113struct CompTimeToSample { 114 uint32 Count; 115 uint32 Offset; 116}; 117 118struct SampleToChunk { 119 uint32 FirstChunk; 120 uint32 SamplesPerChunk; 121 uint32 SampleDescriptionID; 122 uint32 TotalPrevSamples; 123}; 124 125// Note standard is 32bits offsets but later is 64 126// We standardise on 64 and convert older formats upwards 127struct ChunkToOffset { 128 uint64 Offset; 129}; 130 131struct SyncSample { 132 uint32 SyncSampleNo; 133}; 134 135struct SampleSizeEntry { 136 uint32 EntrySize; 137}; 138 139struct mvhdV0 { 140 uint32 CreationTime; 141 uint32 ModificationTime; 142 uint32 TimeScale; 143 uint32 Duration; 144 uint32 PreferredRate; // Fixed point 16.16 145 uint16 PreferredVolume; // Fixed point 8.8 146 uint16 Reserved1; 147 uint32 Reserved2[2]; 148 uint32 Matrix[9]; 149 uint32 pre_defined[6]; 150 uint32 NextTrackID; 151}; 152 153struct mvhdV1 { 154 uint64 CreationTime; 155 uint64 ModificationTime; 156 uint32 TimeScale; 157 uint64 Duration; 158 uint32 PreferredRate; // Fixed point 16.16 159 uint16 PreferredVolume; // Fixed point 8.8 160 uint16 Reserved1; 161 uint32 Reserved2[2]; 162 uint32 Matrix[9]; 163 uint32 pre_defined[6]; 164 uint32 NextTrackID; 165}; 166 167struct tkhdV0 { 168 uint32 CreationTime; 169 uint32 ModificationTime; 170 uint32 TrackID; 171 uint32 Reserved1; 172 uint32 Duration; 173 uint32 Reserved2[2]; 174 uint16 Layer; 175 uint16 AlternateGroup; 176 uint16 Volume; // Fixed 8.8 177 uint16 Reserved3; 178 int32 MatrixStructure[9]; 179 uint32 TrackWidth; // Fixed 16.16 180 uint32 TrackHeight; // Fixed 16.16 181}; 182 183struct tkhdV1 { 184 uint64 CreationTime; 185 uint64 ModificationTime; 186 uint32 TrackID; 187 uint32 Reserved1; 188 uint64 Duration; 189 uint32 Reserved2[2]; 190 uint16 Layer; 191 uint16 AlternateGroup; 192 uint16 Volume; // Fixed 8.8 193 uint16 Reserved3; 194 int32 MatrixStructure[9]; 195 uint32 TrackWidth; // Fixed 16.16 196 uint32 TrackHeight; // Fixed 16.16 197}; 198 199struct mdhdV0 { 200 uint32 CreationTime; 201 uint32 ModificationTime; 202 uint32 TimeScale; 203 uint32 Duration; 204 uint16 Language; // Actually should be 1 bit followed by int(5)[3] 205 uint16 Reserved; 206}; 207 208struct mdhdV1 { 209 uint64 CreationTime; 210 uint64 ModificationTime; 211 uint32 TimeScale; 212 uint64 Duration; 213 uint16 Language; // Actually should be 1 bit followed by int(5)[3] 214 uint16 Reserved; 215}; 216 217struct hdlr { 218 uint32 pre_defined; 219 uint32 handler_type; 220 uint32 Reserved[3]; 221}; 222 223struct vmhd { 224 uint16 GraphicsMode; 225 uint16 OpColour[3]; 226}; 227 228struct smhd { 229 uint16 Balance; 230 uint16 Reserved; 231}; 232 233struct array_header { 234 uint32 NoEntries; 235}; 236 237struct SampleEntry { 238 uint8 Reserved[6]; 239 uint16 DataReference; 240}; 241 242struct AudioSampleEntry { 243 uint32 Reserved[2]; 244 uint16 ChannelCount; 245 uint16 SampleSize; 246 uint16 pre_defined; 247 uint16 reserved; 248 uint32 SampleRate; // 16.16 249}; 250 251struct AudioDescription { 252 AudioSampleEntry theAudioSampleEntry; 253 uint32 codecid; 254 uint32 codecSubType; 255 uint32 FrameSize; 256 uint32 BufferSize; 257 uint32 BitRate; 258 uint8 *theDecoderConfig; 259 size_t DecoderConfigSize; 260}; 261 262struct VideoSampleEntry { 263 uint16 pre_defined1; 264 uint16 reserved1; 265 uint32 pre_defined2[3]; 266 uint16 Width; 267 uint16 Height; 268 uint32 HorizontalResolution; 269 uint32 VerticalResolution; 270 uint32 reserved2; 271 uint16 FrameCount; 272 char CompressorName[32]; 273 uint16 Depth; 274 uint16 pre_defined3; 275}; 276 277struct VideoDescription { 278 VideoSampleEntry theVideoSampleEntry; 279 uint32 codecid; 280 uint32 codecSubType; 281 uint8 *theDecoderConfig; 282 size_t DecoderConfigSize; 283}; 284 285// The parts of the AAC ESDS we care about 286struct AACHeader { 287 uint8 objTypeIndex; 288 uint8 sampleRateIndex; 289 uint8 totalChannels; 290 uint16 frameSize; 291 uint16 adtsBuffer; 292 uint8 totalDataBlocksInFrame; 293}; 294 295#endif // MP4_STRUCTS_H 296