1 /*****************************************************************************
2 * libmp4.h : LibMP4 library for mp4 module for vlc
3 *****************************************************************************
4 * Copyright (C) 2001-2004, 2010 the VideoLAN team
6 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
26 #define ATOM_root VLC_FOURCC( 'r', 'o', 'o', 't' )
27 #define ATOM_uuid VLC_FOURCC( 'u', 'u', 'i', 'd' )
29 #define ATOM_ftyp VLC_FOURCC( 'f', 't', 'y', 'p' )
30 #define ATOM_moov VLC_FOURCC( 'm', 'o', 'o', 'v' )
31 #define ATOM_foov VLC_FOURCC( 'f', 'o', 'o', 'v' )
32 #define ATOM_cmov VLC_FOURCC( 'c', 'm', 'o', 'v' )
33 #define ATOM_dcom VLC_FOURCC( 'd', 'c', 'o', 'm' )
34 #define ATOM_cmvd VLC_FOURCC( 'c', 'm', 'v', 'd' )
36 #define ATOM_moof VLC_FOURCC( 'm', 'o', 'o', 'f' )
37 #define ATOM_mdat VLC_FOURCC( 'm', 'd', 'a', 't' )
38 #define ATOM_skip VLC_FOURCC( 's', 'k', 'i', 'p' )
39 #define ATOM_free VLC_FOURCC( 'f', 'r', 'e', 'e' )
40 #define ATOM_udta VLC_FOURCC( 'u', 'd', 't', 'a' )
41 #define ATOM_wide VLC_FOURCC( 'w', 'i', 'd', 'e' )
43 #define ATOM_data VLC_FOURCC( 'd', 'a', 't', 'a' )
45 #define ATOM_trak VLC_FOURCC( 't', 'r', 'a', 'k' )
46 #define ATOM_mvhd VLC_FOURCC( 'm', 'v', 'h', 'd' )
47 #define ATOM_tkhd VLC_FOURCC( 't', 'k', 'h', 'd' )
48 #define ATOM_tref VLC_FOURCC( 't', 'r', 'e', 'f' )
49 #define ATOM_mdia VLC_FOURCC( 'm', 'd', 'i', 'a' )
50 #define ATOM_mdhd VLC_FOURCC( 'm', 'd', 'h', 'd' )
51 #define ATOM_hdlr VLC_FOURCC( 'h', 'd', 'l', 'r' )
52 #define ATOM_minf VLC_FOURCC( 'm', 'i', 'n', 'f' )
53 #define ATOM_vmhd VLC_FOURCC( 'v', 'm', 'h', 'd' )
54 #define ATOM_smhd VLC_FOURCC( 's', 'm', 'h', 'd' )
55 #define ATOM_hmhd VLC_FOURCC( 'h', 'm', 'h', 'd' )
56 #define ATOM_dinf VLC_FOURCC( 'd', 'i', 'n', 'f' )
57 #define ATOM_url VLC_FOURCC( 'u', 'r', 'l', ' ' )
58 #define ATOM_urn VLC_FOURCC( 'u', 'r', 'n', ' ' )
59 #define ATOM_dref VLC_FOURCC( 'd', 'r', 'e', 'f' )
60 #define ATOM_stbl VLC_FOURCC( 's', 't', 'b', 'l' )
61 #define ATOM_stts VLC_FOURCC( 's', 't', 't', 's' )
62 #define ATOM_ctts VLC_FOURCC( 'c', 't', 't', 's' )
63 #define ATOM_stsd VLC_FOURCC( 's', 't', 's', 'd' )
64 #define ATOM_stsz VLC_FOURCC( 's', 't', 's', 'z' )
65 #define ATOM_stz2 VLC_FOURCC( 's', 't', 'z', '2' )
66 #define ATOM_stsc VLC_FOURCC( 's', 't', 's', 'c' )
67 #define ATOM_stco VLC_FOURCC( 's', 't', 'c', 'o' )
68 #define ATOM_co64 VLC_FOURCC( 'c', 'o', '6', '4' )
69 #define ATOM_stss VLC_FOURCC( 's', 't', 's', 's' )
70 #define ATOM_stsh VLC_FOURCC( 's', 't', 's', 'h' )
71 #define ATOM_stdp VLC_FOURCC( 's', 't', 'd', 'p' )
72 #define ATOM_padb VLC_FOURCC( 'p', 'a', 'd', 'b' )
73 #define ATOM_edts VLC_FOURCC( 'e', 'd', 't', 's' )
74 #define ATOM_elst VLC_FOURCC( 'e', 'l', 's', 't' )
75 #define ATOM_mvex VLC_FOURCC( 'm', 'v', 'e', 'x' )
76 #define ATOM_trex VLC_FOURCC( 't', 'r', 'e', 'x' )
77 #define ATOM_mfhd VLC_FOURCC( 'm', 'f', 'h', 'd' )
78 #define ATOM_traf VLC_FOURCC( 't', 'r', 'a', 'f' )
79 #define ATOM_tfhd VLC_FOURCC( 't', 'f', 'h', 'd' )
80 #define ATOM_trun VLC_FOURCC( 't', 'r', 'u', 'n' )
81 #define ATOM_cprt VLC_FOURCC( 'c', 'p', 'r', 't' )
82 #define ATOM_iods VLC_FOURCC( 'i', 'o', 'd', 's' )
84 #define ATOM_nmhd VLC_FOURCC( 'n', 'm', 'h', 'd' )
85 #define ATOM_mp2v VLC_FOURCC( 'm', 'p', '2', 'v' )
86 #define ATOM_mp4v VLC_FOURCC( 'm', 'p', '4', 'v' )
87 #define ATOM_mp4a VLC_FOURCC( 'm', 'p', '4', 'a' )
88 #define ATOM_mp4s VLC_FOURCC( 'm', 'p', '4', 's' )
89 #define ATOM_vide VLC_FOURCC( 'v', 'i', 'd', 'e' )
90 #define ATOM_soun VLC_FOURCC( 's', 'o', 'u', 'n' )
91 #define ATOM_hint VLC_FOURCC( 'h', 'i', 'n', 't' )
92 #define ATOM_hdv2 VLC_FOURCC( 'h', 'd', 'v', '2' )
94 #define ATOM_dpnd VLC_FOURCC( 'd', 'p', 'n', 'd' )
95 #define ATOM_ipir VLC_FOURCC( 'i', 'p', 'i', 'r' )
96 #define ATOM_mpod VLC_FOURCC( 'm', 'p', 'o', 'd' )
97 #define ATOM_hnti VLC_FOURCC( 'h', 'n', 't', 'i' )
98 #define ATOM_rtp VLC_FOURCC( 'r', 't', 'p', ' ' )
100 #define ATOM_isom VLC_FOURCC( 'i', 's', 'o', 'm' )
101 #define ATOM_3gp4 VLC_FOURCC( '3', 'g', 'p', '4' )
102 #define ATOM_esds VLC_FOURCC( 'e', 's', 'd', 's' )
104 #define ATOM__mp3 VLC_FOURCC( '.', 'm', 'p', '3' )
105 #define ATOM_ms02 VLC_FOURCC( 'm', 's', 0x0, 0x02 )
106 #define ATOM_ms11 VLC_FOURCC( 'm', 's', 0x0, 0x11 )
107 #define ATOM_ms55 VLC_FOURCC( 'm', 's', 0x0, 0x55 )
108 #define ATOM_twos VLC_FOURCC( 't', 'w', 'o', 's' )
109 #define ATOM_sowt VLC_FOURCC( 's', 'o', 'w', 't' )
110 #define ATOM_QDMC VLC_FOURCC( 'Q', 'D', 'M', 'C' )
111 #define ATOM_QDM2 VLC_FOURCC( 'Q', 'D', 'M', '2' )
112 #define ATOM_ima4 VLC_FOURCC( 'i', 'm', 'a', '4' )
113 #define ATOM_IMA4 VLC_FOURCC( 'I', 'M', 'A', '4' )
114 #define ATOM_dvi VLC_FOURCC( 'd', 'v', 'i', ' ' )
115 #define ATOM_MAC3 VLC_FOURCC( 'M', 'A', 'C', '3' )
116 #define ATOM_MAC6 VLC_FOURCC( 'M', 'A', 'C', '6' )
117 #define ATOM_alaw VLC_FOURCC( 'a', 'l', 'a', 'w' )
118 #define ATOM_ulaw VLC_FOURCC( 'u', 'l', 'a', 'w' )
119 #define ATOM_Qclp VLC_FOURCC( 'Q', 'c', 'l', 'p' )
120 #define ATOM_samr VLC_FOURCC( 's', 'a', 'm', 'r' )
121 #define ATOM_sawb VLC_FOURCC( 's', 'a', 'w', 'b' )
122 #define ATOM_OggS VLC_FOURCC( 'O', 'g', 'g', 'S' )
123 #define ATOM_alac VLC_FOURCC( 'a', 'l', 'a', 'c' )
124 #define ATOM_dac3 VLC_FOURCC( 'd', 'a', 'c', '3' )
125 #define ATOM_dec3 VLC_FOURCC( 'd', 'e', 'c', '3' )
126 #define ATOM_enda VLC_FOURCC( 'e', 'n', 'd', 'a' )
127 #define ATOM_gnre VLC_FOURCC( 'g', 'n', 'r', 'e' )
128 #define ATOM_trkn VLC_FOURCC( 't', 'r', 'k', 'n' )
130 #define ATOM_zlib VLC_FOURCC( 'z', 'l', 'i', 'b' )
131 #define ATOM_SVQ1 VLC_FOURCC( 'S', 'V', 'Q', '1' )
132 #define ATOM_SVQ3 VLC_FOURCC( 'S', 'V', 'Q', '3' )
133 #define ATOM_ZyGo VLC_FOURCC( 'Z', 'y', 'G', 'o' )
134 #define ATOM_3IV1 VLC_FOURCC( '3', 'I', 'V', '1' )
135 #define ATOM_3iv1 VLC_FOURCC( '3', 'i', 'v', '1' )
136 #define ATOM_3IV2 VLC_FOURCC( '3', 'I', 'V', '2' )
137 #define ATOM_3iv2 VLC_FOURCC( '3', 'i', 'v', '2' )
138 #define ATOM_3IVD VLC_FOURCC( '3', 'I', 'V', 'D' )
139 #define ATOM_3ivd VLC_FOURCC( '3', 'i', 'v', 'd' )
140 #define ATOM_3VID VLC_FOURCC( '3', 'V', 'I', 'D' )
141 #define ATOM_3vid VLC_FOURCC( '3', 'v', 'i', 'd' )
142 #define ATOM_h263 VLC_FOURCC( 'h', '2', '6', '3' )
143 #define ATOM_s263 VLC_FOURCC( 's', '2', '6', '3' )
144 #define ATOM_DIVX VLC_FOURCC( 'D', 'I', 'V', 'X' )
145 #define ATOM_XVID VLC_FOURCC( 'X', 'V', 'I', 'D' )
146 #define ATOM_cvid VLC_FOURCC( 'c', 'v', 'i', 'd' )
147 #define ATOM_mjpa VLC_FOURCC( 'm', 'j', 'p', 'a' )
148 #define ATOM_mjpb VLC_FOURCC( 'm', 'j', 'q', 't' )
149 #define ATOM_mjqt VLC_FOURCC( 'm', 'j', 'h', 't' )
150 #define ATOM_mjht VLC_FOURCC( 'm', 'j', 'p', 'b' )
151 #define ATOM_VP31 VLC_FOURCC( 'V', 'P', '3', '1' )
152 #define ATOM_vp31 VLC_FOURCC( 'v', 'p', '3', '1' )
153 #define ATOM_h264 VLC_FOURCC( 'h', '2', '6', '4' )
154 #define ATOM_qdrw VLC_FOURCC( 'q', 'd', 'r', 'w' )
156 #define ATOM_avc1 VLC_FOURCC( 'a', 'v', 'c', '1' )
157 #define ATOM_avcC VLC_FOURCC( 'a', 'v', 'c', 'C' )
158 #define ATOM_m4ds VLC_FOURCC( 'm', '4', 'd', 's' )
160 #define ATOM_dvc VLC_FOURCC( 'd', 'v', 'c', ' ' )
161 #define ATOM_dvp VLC_FOURCC( 'd', 'v', 'p', ' ' )
162 #define ATOM_dv5n VLC_FOURCC( 'd', 'v', '5', 'n' )
163 #define ATOM_dv5p VLC_FOURCC( 'd', 'v', '5', 'p' )
164 #define ATOM_raw VLC_FOURCC( 'r', 'a', 'w', ' ' )
166 #define ATOM_jpeg VLC_FOURCC( 'j', 'p', 'e', 'g' )
168 #define ATOM_yv12 VLC_FOURCC( 'y', 'v', '1', '2' )
169 #define ATOM_yuv2 VLC_FOURCC( 'y', 'u', 'v', '2' )
171 #define ATOM_rmra VLC_FOURCC( 'r', 'm', 'r', 'a' )
172 #define ATOM_rmda VLC_FOURCC( 'r', 'm', 'd', 'a' )
173 #define ATOM_rdrf VLC_FOURCC( 'r', 'd', 'r', 'f' )
174 #define ATOM_rmdr VLC_FOURCC( 'r', 'm', 'd', 'r' )
175 #define ATOM_rmvc VLC_FOURCC( 'r', 'm', 'v', 'c' )
176 #define ATOM_rmcd VLC_FOURCC( 'r', 'm', 'c', 'd' )
177 #define ATOM_rmqu VLC_FOURCC( 'r', 'm', 'q', 'u' )
178 #define ATOM_alis VLC_FOURCC( 'a', 'l', 'i', 's' )
180 #define ATOM_gmhd VLC_FOURCC( 'g', 'm', 'h', 'd' )
181 #define ATOM_wave VLC_FOURCC( 'w', 'a', 'v', 'e' )
183 #define ATOM_drms VLC_FOURCC( 'd', 'r', 'm', 's' )
184 #define ATOM_sinf VLC_FOURCC( 's', 'i', 'n', 'f' )
185 #define ATOM_schi VLC_FOURCC( 's', 'c', 'h', 'i' )
186 #define ATOM_user VLC_FOURCC( 'u', 's', 'e', 'r' )
187 #define ATOM_key VLC_FOURCC( 'k', 'e', 'y', ' ' )
188 #define ATOM_iviv VLC_FOURCC( 'i', 'v', 'i', 'v' )
189 #define ATOM_name VLC_FOURCC( 'n', 'a', 'm', 'e' )
190 #define ATOM_priv VLC_FOURCC( 'p', 'r', 'i', 'v' )
191 #define ATOM_drmi VLC_FOURCC( 'd', 'r', 'm', 'i' )
192 #define ATOM_frma VLC_FOURCC( 'f', 'r', 'm', 'a' )
193 #define ATOM_skcr VLC_FOURCC( 's', 'k', 'c', 'r' )
195 #define ATOM_text VLC_FOURCC( 't', 'e', 'x', 't' )
196 #define ATOM_tx3g VLC_FOURCC( 't', 'x', '3', 'g' )
197 #define ATOM_subp VLC_FOURCC( 's', 'u', 'b', 'p' )
198 #define ATOM_sbtl VLC_FOURCC( 's', 'b', 't', 'l' )
200 #define ATOM_0xa9nam VLC_FOURCC( 0xa9, 'n', 'a', 'm' )
201 #define ATOM_0xa9aut VLC_FOURCC( 0xa9, 'a', 'u', 't' )
202 #define ATOM_0xa9cpy VLC_FOURCC( 0xa9, 'c', 'p', 'y' )
203 #define ATOM_0xa9inf VLC_FOURCC( 0xa9, 'i', 'n', 'f' )
204 #define ATOM_0xa9ART VLC_FOURCC( 0xa9, 'A', 'R', 'T' )
205 #define ATOM_0xa9des VLC_FOURCC( 0xa9, 'd', 'e', 's' )
206 #define ATOM_0xa9dir VLC_FOURCC( 0xa9, 'd', 'i', 'r' )
207 #define ATOM_0xa9cmt VLC_FOURCC( 0xa9, 'c', 'm', 't' )
208 #define ATOM_0xa9req VLC_FOURCC( 0xa9, 'r', 'e', 'q' )
209 #define ATOM_0xa9day VLC_FOURCC( 0xa9, 'd', 'a', 'y' )
210 #define ATOM_0xa9fmt VLC_FOURCC( 0xa9, 'f', 'm', 't' )
211 #define ATOM_0xa9prd VLC_FOURCC( 0xa9, 'p', 'r', 'd' )
212 #define ATOM_0xa9prf VLC_FOURCC( 0xa9, 'p', 'r', 'f' )
213 #define ATOM_0xa9src VLC_FOURCC( 0xa9, 's', 'r', 'c' )
214 #define ATOM_0xa9alb VLC_FOURCC( 0xa9, 'a', 'l', 'b' )
215 #define ATOM_0xa9dis VLC_FOURCC( 0xa9, 'd', 'i', 's' )
216 #define ATOM_0xa9enc VLC_FOURCC( 0xa9, 'e', 'n', 'c' )
217 #define ATOM_0xa9trk VLC_FOURCC( 0xa9, 't', 'r', 'k' )
218 #define ATOM_0xa9url VLC_FOURCC( 0xa9, 'u', 'r', 'l' )
219 #define ATOM_0xa9dsa VLC_FOURCC( 0xa9, 'd', 's', 'a' )
220 #define ATOM_0xa9hst VLC_FOURCC( 0xa9, 'h', 's', 't' )
221 #define ATOM_0xa9ope VLC_FOURCC( 0xa9, 'o', 'p', 'e' )
222 #define ATOM_0xa9wrt VLC_FOURCC( 0xa9, 'w', 'r', 't' )
223 #define ATOM_0xa9com VLC_FOURCC( 0xa9, 'c', 'o', 'm' )
224 #define ATOM_0xa9gen VLC_FOURCC( 0xa9, 'g', 'e', 'n' )
225 #define ATOM_0xa9too VLC_FOURCC( 0xa9, 't', 'o', 'o' )
226 #define ATOM_0xa9wrn VLC_FOURCC( 0xa9, 'w', 'r', 'n' )
227 #define ATOM_0xa9swr VLC_FOURCC( 0xa9, 's', 'w', 'r' )
228 #define ATOM_0xa9mak VLC_FOURCC( 0xa9, 'm', 'a', 'k' )
229 #define ATOM_0xa9mod VLC_FOURCC( 0xa9, 'm', 'o', 'd' )
230 #define ATOM_0xa9PRD VLC_FOURCC( 0xa9, 'P', 'R', 'D' )
231 #define ATOM_0xa9grp VLC_FOURCC( 0xa9, 'g', 'r', 'p' )
232 #define ATOM_0xa9lyr VLC_FOURCC( 0xa9, 'g', 'r', 'p' )
233 #define ATOM_chpl VLC_FOURCC( 'c', 'h', 'p', 'l' )
234 #define ATOM_WLOC VLC_FOURCC( 'W', 'L', 'O', 'C' )
236 #define ATOM_meta VLC_FOURCC( 'm', 'e', 't', 'a' )
237 #define ATOM_ilst VLC_FOURCC( 'i', 'l', 's', 't' )
239 #define ATOM_chap VLC_FOURCC( 'c', 'h', 'a', 'p' )
241 /* Do you want some debug information on all read boxes ? */
242 //#define MP4_VERBOSE 1
248 /* uuid Universal Unique IDentifiers */
249 typedef struct UUID_s
254 /* specific structure for all boxes */
256 typedef struct MP4_Box_data_ftyp_s
258 uint32_t i_major_brand;
259 uint32_t i_minor_version;
261 uint32_t i_compatible_brands_count;
262 uint32_t *i_compatible_brands;
264 } MP4_Box_data_ftyp_t;
266 typedef struct MP4_Box_data_mvhd_s
271 uint64_t i_creation_time;
272 uint64_t i_modification_time;
273 uint32_t i_timescale;
279 uint32_t i_reserved2[2];
281 uint32_t i_predefined[6];
282 uint32_t i_next_track_id;
284 } MP4_Box_data_mvhd_t;
286 #define MP4_TRACK_ENABLED 0x000001
287 #define MP4_TRACK_IN_MOVIE 0x000002
288 #define MP4_TRACK_IN_PREVIEW 0x000004
289 typedef struct MP4_Box_data_tkhd_s
294 uint64_t i_creation_time;
295 uint64_t i_modification_time;
300 uint32_t i_reserved2[2];
302 int16_t i_predefined;
305 uint16_t i_reserved3;
310 } MP4_Box_data_tkhd_t;
312 typedef struct MP4_Box_data_mdhd_s
317 uint64_t i_creation_time;
318 uint64_t i_modification_time;
319 uint32_t i_timescale;
322 /* one bit for pad */
323 uint16_t i_language_code;
324 /* unsigned int(5)[3] language difference with 0x60*/
325 unsigned char i_language[3];
326 uint16_t i_predefined;
328 } MP4_Box_data_mdhd_t;
330 typedef struct MP4_Box_data_hdlr_s
335 uint32_t i_predefined;
336 uint32_t i_handler_type; /* "vide" "soun" "hint" "odsm"
337 "crsm" "sdsm" "m7sm" "ocsm"
340 unsigned char *psz_name; /* in UTF-8 */
342 } MP4_Box_data_hdlr_t;
344 typedef struct MP4_Box_data_vmhd_s
349 int16_t i_graphics_mode;
350 int16_t i_opcolor[3];
352 } MP4_Box_data_vmhd_t;
354 typedef struct MP4_Box_data_smhd_s
362 } MP4_Box_data_smhd_t;
364 typedef struct MP4_Box_data_hmhd_s
369 uint16_t i_max_PDU_size;
370 uint16_t i_avg_PDU_size;
371 uint32_t i_max_bitrate;
372 uint32_t i_avg_bitrate;
375 } MP4_Box_data_hmhd_t;
377 typedef struct MP4_Box_data_url_s
384 } MP4_Box_data_url_t;
386 typedef struct MP4_Box_data_urn_s
394 } MP4_Box_data_urn_t;
396 typedef struct MP4_Box_data_dref_s
401 uint32_t i_entry_count;
402 /* XXX it's also a container with i_entry_count entry */
403 } MP4_Box_data_dref_t;
405 typedef struct MP4_Box_data_stts_s
410 uint32_t i_entry_count;
411 uint32_t *i_sample_count; /* these are array */
412 int32_t *i_sample_delta;
414 } MP4_Box_data_stts_t;
416 typedef struct MP4_Box_data_ctts_s
421 uint32_t i_entry_count;
423 uint32_t *i_sample_count; /* these are array */
424 int32_t *i_sample_offset;
426 } MP4_Box_data_ctts_t;
429 typedef struct MP4_Box_data_sample_soun_s
431 uint8_t i_reserved1[6];
432 uint16_t i_data_reference_index;
434 //uint32_t i_reserved2[2];
435 uint16_t i_qt_version;
436 uint16_t i_qt_revision_level;
437 uint32_t i_qt_vendor;
439 uint16_t i_channelcount;
440 uint16_t i_samplesize;
441 uint16_t i_predefined;
442 uint16_t i_reserved3;
443 uint16_t i_sampleratehi; /* timescale of track */
444 uint16_t i_sampleratelo;
446 /* for version 1 (i_reserved1[0] == 1) */
447 uint32_t i_sample_per_packet;
448 uint32_t i_bytes_per_packet;
449 uint32_t i_bytes_per_frame;
450 uint32_t i_bytes_per_sample;
453 int i_qt_description;
454 uint8_t *p_qt_description;
458 } MP4_Box_data_sample_soun_t;
460 typedef struct MP4_Box_data_sample_vide_s
462 uint8_t i_reserved1[6];
463 uint16_t i_data_reference_index;
465 uint16_t i_qt_version;
466 uint16_t i_qt_revision_level;
467 uint32_t i_qt_vendor;
469 uint32_t i_qt_temporal_quality;
470 uint32_t i_qt_spatial_quality;
475 uint32_t i_horizresolution;
476 uint32_t i_vertresolution;
478 uint32_t i_qt_data_size;
479 uint16_t i_qt_frame_count;
481 uint8_t i_compressorname[32];
484 int16_t i_qt_color_table;
486 /* XXX hack ImageDescription */
487 int i_qt_image_description;
488 uint8_t *p_qt_image_description;
492 } MP4_Box_data_sample_vide_t;
494 #define MP4_TEXT_DISPLAY_FLAG_DONT_DISPLAY (1<<0)
495 #define MP4_TEXT_DISPLAY_FLAG_AUTO_SCALE (1<<1)
496 #define MP4_TEXT_DISPLAY_FLAG_CLIP_TO_TEXT_BOX (1<<2)
497 #define MP4_TEXT_DISPLAY_FLAG_USE_MOVIE_BG_COLOR (1<<3)
498 #define MP4_TEXT_DISPLAY_FLAG_SHRINK_TEXT_BOX_TO_FIT (1<<4)
499 #define MP4_TEXT_DISPLAY_FLAG_SCROLL_IN (1<<5)
500 #define MP4_TEXT_DISPLAY_FLAG_SCROLL_OUT (1<<6)
501 #define MP4_TEXT_DISPLAY_FLAG_HORIZONTAL_SCROLL (1<<7)
502 #define MP4_TEXT_DISPLAY_FLAG_REVERSE_SCROLL (1<<8)
503 #define MP4_TEXT_DISPLAY_FLAG_CONTINUOUS_SCROLL (1<<9)
504 #define MP4_TEXT_DISPLAY_FLAG_FLOW_HORIZONTAL (1<<10)
505 #define MP4_TEXT_DISPLAY_FLAG_CONTINUOUS_KARAOKE (1<<11)
506 #define MP4_TEXT_DISPLAY_FLAG_DROP_SHADOW (1<<12)
507 #define MP4_TEXT_DISPLAY_FLAG_ANTI_ALIAS (1<<13)
508 #define MP4_TEXT_DISPLAY_FLAG_KEYED_TEXT (1<<14)
509 #define MP4_TEXT_DISPLAY_FLAG_INVERSE_HILITE (1<<15)
510 #define MP4_TEXT_DISPLAY_FLAG_COLOR_HILITE (1<<16)
511 #define MP4_TEXT_DISPLAY_FLAG_WRITE_VERTICALLY (1<<17)
515 uint32_t i_reserved1;
516 uint16_t i_reserved2;
518 uint16_t i_data_reference_index;
520 uint32_t i_display_flags; // TextDescription and Tx3gDescription
522 int8_t i_justification_horizontal; // left(0), centered(1), right(-1)
523 int8_t i_justification_vertical; // top(0), centered(1), bottom(-1)
525 uint16_t i_background_color[4];
527 uint16_t i_text_box_top;
528 uint16_t i_text_box_left;
529 uint16_t i_text_box_bottom;
530 uint16_t i_text_box_right;
533 } MP4_Box_data_sample_text_t;
535 typedef struct MP4_Box_data_sample_hint_s
537 uint8_t i_reserved1[6];
538 uint16_t i_data_reference_index;
542 } MP4_Box_data_sample_hint_t;
544 typedef struct MP4_Box_data_moviehintinformation_rtp_s
546 uint32_t i_description_format;
547 unsigned char *psz_text;
549 } MP4_Box_data_moviehintinformation_rtp_t;
553 typedef struct MP4_Box_data_stsd_s
558 uint32_t i_entry_count;
560 /* it contains SampleEntry handled as if it was Box */
562 } MP4_Box_data_stsd_t;
565 typedef struct MP4_Box_data_stsz_s
570 uint32_t i_sample_size;
571 uint32_t i_sample_count;
573 uint32_t *i_entry_size; /* array , empty if i_sample_size != 0 */
575 } MP4_Box_data_stsz_t;
577 typedef struct MP4_Box_data_stz2_s
582 uint32_t i_sample_size; /* 24 bits */
583 uint8_t i_field_size;
584 uint32_t i_sample_count;
586 uint32_t *i_entry_size; /* array: unsigned int(i_field_size) entry_size */
588 } MP4_Box_data_stz2_t;
590 typedef struct MP4_Box_data_stsc_s
595 uint32_t i_entry_count;
597 uint32_t *i_first_chunk; /* theses are arrays */
598 uint32_t *i_samples_per_chunk;
599 uint32_t *i_sample_description_index;
601 } MP4_Box_data_stsc_t;
604 typedef struct MP4_Box_data_co64_s
609 uint32_t i_entry_count;
611 uint64_t *i_chunk_offset;
613 } MP4_Box_data_co64_t;
616 typedef struct MP4_Box_data_stss_s
621 uint32_t i_entry_count;
623 uint32_t *i_sample_number;
625 } MP4_Box_data_stss_t;
627 typedef struct MP4_Box_data_stsh_s
632 uint32_t i_entry_count;
634 uint32_t *i_shadowed_sample_number;
635 uint32_t *i_sync_sample_number;
637 } MP4_Box_data_stsh_t;
639 typedef struct MP4_Box_data_stdp_s
644 uint16_t *i_priority;
646 } MP4_Box_data_stdp_t;
648 typedef struct MP4_Box_data_padb_s
653 uint32_t i_sample_count;
655 uint16_t *i_reserved1; /* 1bit */
656 uint16_t *i_pad2; /* 3bits */
657 uint16_t *i_reserved2; /* 1bit */
658 uint16_t *i_pad1; /* 3bits */
661 } MP4_Box_data_padb_t;
664 typedef struct MP4_Box_data_elst_s
669 uint32_t i_entry_count;
671 uint64_t *i_segment_duration;
672 int64_t *i_media_time;
673 uint16_t *i_media_rate_integer;
674 uint16_t *i_media_rate_fraction;
677 } MP4_Box_data_elst_t;
679 typedef struct MP4_Box_data_cprt_s
684 unsigned char i_language[3];
687 } MP4_Box_data_cprt_t;
690 /* DecoderConfigDescriptor */
691 typedef struct MP4_descriptor_decoder_config_s
693 uint8_t i_objectTypeIndication;
694 uint8_t i_streamType;
700 int i_decoder_specific_info_len;
701 uint8_t *p_decoder_specific_info;
702 /* some other stuff */
704 } MP4_descriptor_decoder_config_t;
706 typedef struct MP4_descriptor_SL_config_s
709 int i_dummy; /* ANSI C forbids empty structures */
711 } MP4_descriptor_SL_config_t;
714 typedef struct MP4_descriptor_ES_s
717 int b_stream_dependence;
720 int i_stream_priority;
722 int i_depend_on_ES_ID; /* if b_stream_dependence set */
724 unsigned char *psz_URL;
726 uint16_t i_OCR_ES_ID; /* if b_OCRstream */
727 MP4_descriptor_decoder_config_t *p_decConfigDescr;
729 MP4_descriptor_SL_config_t *p_slConfigDescr;
731 /* some other stuff ... */
733 } MP4_descriptor_ES_t;
736 typedef struct MP4_Box_data_esds_s
741 MP4_descriptor_ES_t es_descriptor;
743 } MP4_Box_data_esds_t;
746 typedef struct MP4_Box_data_dcom_s
748 uint32_t i_algorithm; /* fourcc */
750 } MP4_Box_data_dcom_t;
752 typedef struct MP4_Box_data_cmvd_s
754 uint32_t i_uncompressed_size;
755 uint32_t i_compressed_size;
757 int b_compressed; /* Set to 1 if compressed data, 0 if uncompressed */
760 } MP4_Box_data_cmvd_t;
762 typedef struct MP4_Box_data_cmov_s
764 struct MP4_Box_s *p_moov; /* uncompressed moov */
766 } MP4_Box_data_cmov_t;
771 } MP4_Box_data_frma_t;
778 } MP4_Box_data_skcr_t;
788 } MP4_Box_data_rdrf_t;
797 } MP4_Box_data_rmdr_t;
804 uint32_t i_gestaltType;
807 uint16_t i_checkType; /* 0: val1 is version min
808 1: gestalt value & val2 == val1 */
810 } MP4_Box_data_rmvc_t;
818 } MP4_Box_data_rmcd_t;
824 } MP4_Box_data_rmqu_t;
826 typedef struct MP4_Box_data_mfhd_s
828 uint32_t i_sequence_number;
830 uint8_t *p_vendor_extension;
832 } MP4_Box_data_mfhd_t;
834 #define MP4_TFHD_BASE_DATA_OFFSET (1LL<<0)
835 #define MP4_TFHD_SAMPLE_DESC_INDEX (1LL<<1)
836 #define MP4_TFHD_DFLT_SAMPLE_DURATION (1LL<<3)
837 #define MP4_TFHD_DFLT_SAMPLE_SIZE (1LL<<4)
838 #define MP4_TFHD_DFLT_SAMPLE_FLAGS (1LL<<5)
839 typedef struct MP4_Box_data_tfhd_s
845 /* optional fields */
846 uint64_t i_base_data_offset;
847 uint32_t i_sample_description_index;
848 uint32_t i_default_sample_duration;
849 uint32_t i_default_sample_size;
850 uint32_t i_default_sample_flags;
852 } MP4_Box_data_tfhd_t;
854 #define MP4_TRUN_DATA_OFFSET (1<<0)
855 #define MP4_TRUN_FIRST_FLAGS (1<<2)
856 #define MP4_TRUN_SAMPLE_DURATION (1<<8)
857 #define MP4_TRUN_SAMPLE_SIZE (1<<9)
858 #define MP4_TRUN_SAMPLE_FLAGS (1<<10)
859 #define MP4_TRUN_SAMPLE_TIME_OFFSET (1<<11)
860 typedef struct MP4_descriptor_trun_sample_t
865 uint32_t i_composition_time_offset;
866 } MP4_descriptor_trun_sample_t;
868 typedef struct MP4_Box_data_trun_s
872 uint32_t i_sample_count;
874 /* optional fields */
875 uint32_t i_data_offset;
876 uint32_t i_first_sample_flags;
878 MP4_descriptor_trun_sample_t *p_samples;
880 } MP4_Box_data_trun_t;
887 } MP4_Box_data_0xa9xxx_t;
893 } MP4_Box_data_name_t;
897 uint32_t i_entry_count;
898 uint32_t *i_track_ID;
900 } MP4_Box_data_tref_generic_t;
913 } MP4_Box_data_chpl_t;
919 uint8_t i_profile_compatibility;
922 uint8_t i_reserved1; /* 6 bits */
923 uint8_t i_length_size;
925 uint8_t i_reserved2; /* 3 bits */
927 uint16_t *i_sps_length;
931 uint16_t *i_pps_length;
934 /* XXX: Hack raw avcC atom payload */
938 } MP4_Box_data_avcC_t;
947 uint8_t i_bitrate_code;
949 } MP4_Box_data_dac3_t;
953 uint16_t i_little_endian;
955 } MP4_Box_data_enda_t;
961 } MP4_Box_data_gnre_t;
965 uint32_t i_track_number;
966 uint32_t i_track_total;
968 } MP4_Box_data_trkn_t;
975 uint16_t i_object_descriptor;
976 uint8_t i_OD_profile_level;
977 uint8_t i_scene_profile_level;
978 uint8_t i_audio_profile_level;
979 uint8_t i_visual_profile_level;
980 uint8_t i_graphics_profile_level;
982 } MP4_Box_data_iods_t;
985 typedef struct MP4_Box_data__s
994 typedef union MP4_Box_data_s
996 MP4_Box_data_ftyp_t *p_ftyp;
997 MP4_Box_data_mvhd_t *p_mvhd;
998 MP4_Box_data_mfhd_t *p_mfhd;
999 MP4_Box_data_tfhd_t *p_tfhd;
1000 MP4_Box_data_trun_t *p_trun;
1001 MP4_Box_data_tkhd_t *p_tkhd;
1002 MP4_Box_data_mdhd_t *p_mdhd;
1003 MP4_Box_data_hdlr_t *p_hdlr;
1004 MP4_Box_data_vmhd_t *p_vmhd;
1005 MP4_Box_data_smhd_t *p_smhd;
1006 MP4_Box_data_hmhd_t *p_hmhd;
1007 MP4_Box_data_url_t *p_url;
1008 MP4_Box_data_urn_t *p_urn;
1009 MP4_Box_data_dref_t *p_dref;
1010 MP4_Box_data_stts_t *p_stts;
1011 MP4_Box_data_ctts_t *p_ctts;
1012 MP4_Box_data_stsd_t *p_stsd;
1013 MP4_Box_data_sample_vide_t *p_sample_vide;
1014 MP4_Box_data_sample_soun_t *p_sample_soun;
1015 MP4_Box_data_sample_text_t *p_sample_text;
1016 MP4_Box_data_sample_hint_t *p_sample_hint;
1018 MP4_Box_data_esds_t *p_esds;
1019 MP4_Box_data_avcC_t *p_avcC;
1020 MP4_Box_data_dac3_t *p_dac3;
1021 MP4_Box_data_enda_t *p_enda;
1022 MP4_Box_data_gnre_t *p_gnre;
1023 MP4_Box_data_trkn_t *p_trkn;
1024 MP4_Box_data_iods_t *p_iods;
1026 MP4_Box_data_stsz_t *p_stsz;
1027 MP4_Box_data_stz2_t *p_stz2;
1028 MP4_Box_data_stsc_t *p_stsc;
1029 MP4_Box_data_co64_t *p_co64;
1030 MP4_Box_data_stss_t *p_stss;
1031 MP4_Box_data_stsh_t *p_stsh;
1032 MP4_Box_data_stdp_t *p_stdp;
1033 MP4_Box_data_padb_t *p_padb;
1034 MP4_Box_data_elst_t *p_elst;
1035 MP4_Box_data_cprt_t *p_cprt;
1037 MP4_Box_data_dcom_t *p_dcom;
1038 MP4_Box_data_cmvd_t *p_cmvd;
1039 MP4_Box_data_cmov_t *p_cmov;
1041 MP4_Box_data_moviehintinformation_rtp_t p_moviehintinformation_rtp;
1043 MP4_Box_data_frma_t *p_frma;
1044 MP4_Box_data_skcr_t *p_skcr;
1046 MP4_Box_data_rdrf_t *p_rdrf;
1047 MP4_Box_data_rmdr_t *p_rmdr;
1048 MP4_Box_data_rmqu_t *p_rmqu;
1049 MP4_Box_data_rmvc_t *p_rmvc;
1051 MP4_Box_data_0xa9xxx_t *p_0xa9xxx;
1052 MP4_Box_data_chpl_t *p_chpl;
1053 MP4_Box_data_tref_generic_t *p_tref_generic;
1054 MP4_Box_data_name_t *p_name;
1056 void *p_data; /* for unknow type */
1061 /* the most basic structure */
1062 typedef struct MP4_Box_s
1064 off_t i_pos; /* absolute position */
1067 uint32_t i_shortsize;
1069 UUID_t i_uuid; /* Set if i_type == "uuid" */
1071 uint64_t i_size; /* always set so use it */
1073 MP4_Box_data_t data; /* union of pointers on extended data depending
1074 on i_type (or i_usertype) */
1076 struct MP4_Box_s *p_father; /* pointer on the father Box */
1078 struct MP4_Box_s *p_first; /* pointer on the first child Box */
1079 struct MP4_Box_s *p_last;
1081 struct MP4_Box_s *p_next; /* pointer on the next boxes at the same level */
1087 /*****************************************************************************
1088 * MP4_BoxGetRoot : Parse the entire file, and create all boxes in memory
1089 *****************************************************************************
1090 * The first box is a virtual box "root" and is the father for all first
1092 *****************************************************************************/
1093 MP4_Box_t *MP4_BoxGetRoot( stream_t * );
1095 /*****************************************************************************
1096 * MP4_FreeBox : free memory allocated after read with MP4_ReadBox
1097 * or MP4_BoxGetRoot, this means also children boxes
1098 * XXX : all children have to be allocated by a malloc !! and
1100 *****************************************************************************/
1101 void MP4_BoxFree( stream_t *, MP4_Box_t *p_box );
1103 /*****************************************************************************
1104 * MP4_DumpBoxStructure: print the structure of the p_box
1105 *****************************************************************************
1106 * Useful while debugging
1107 *****************************************************************************/
1108 void MP4_BoxDumpStructure( stream_t *p_input, MP4_Box_t *p_box );
1110 /*****************************************************************************
1111 * MP4_BoxGet: find a box given a path relative to p_box
1112 *****************************************************************************
1113 * Path Format: . .. / as usual
1114 * [number] to specifie box number ex: trak[12]
1116 * ex: /moov/trak[12]
1118 *****************************************************************************/
1119 MP4_Box_t *MP4_BoxGet( MP4_Box_t *p_box, const char *psz_fmt, ... );
1121 /*****************************************************************************
1122 * MP4_BoxCount: find number of box given a path relative to p_box
1123 *****************************************************************************
1124 * Path Format: . .. / as usual
1125 * [number] to specifie box number ex: trak[12]
1129 *****************************************************************************/
1130 int MP4_BoxCount( MP4_Box_t *p_box, const char *psz_fmt, ... );
1132 /* Internal functions exposed for MKV demux */
1133 int MP4_ReadBoxCommon( stream_t *p_stream, MP4_Box_t *p_box );
1134 int MP4_ReadBox_sample_vide( stream_t *p_stream, MP4_Box_t *p_box );
1135 void MP4_FreeBox_sample_vide( MP4_Box_t *p_box );