]> git.sesse.net Git - vlc/blob - modules/demux/mp4/libmp4.h
mp4: don't use the VERBOSE mode by default
[vlc] / modules / demux / mp4 / libmp4.h
1 /*****************************************************************************
2  * libmp4.h : LibMP4 library for mp4 module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001-2004, 2010 the VideoLAN team
5  * $Id$
6  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
7  *
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.
12  *
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.
17  *
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  *****************************************************************************/
22 #ifndef _VLC_MP4_H
23 #define _VLC_MP4_H 1
24
25
26 #define FOURCC_uuid VLC_FOURCC( 'u', 'u', 'i', 'd' )
27
28 #define FOURCC_ftyp VLC_FOURCC( 'f', 't', 'y', 'p' )
29 #define FOURCC_moov VLC_FOURCC( 'm', 'o', 'o', 'v' )
30 #define FOURCC_foov VLC_FOURCC( 'f', 'o', 'o', 'v' )
31 #define FOURCC_cmov VLC_FOURCC( 'c', 'm', 'o', 'v' )
32 #define FOURCC_dcom VLC_FOURCC( 'd', 'c', 'o', 'm' )
33 #define FOURCC_cmvd VLC_FOURCC( 'c', 'm', 'v', 'd' )
34
35 #define FOURCC_moof VLC_FOURCC( 'm', 'o', 'o', 'f' )
36 #define FOURCC_mdat VLC_FOURCC( 'm', 'd', 'a', 't' )
37 #define FOURCC_skip VLC_FOURCC( 's', 'k', 'i', 'p' )
38 #define FOURCC_free VLC_FOURCC( 'f', 'r', 'e', 'e' )
39 #define FOURCC_udta VLC_FOURCC( 'u', 'd', 't', 'a' )
40 #define FOURCC_wide VLC_FOURCC( 'w', 'i', 'd', 'e' )
41
42 #define FOURCC_trak VLC_FOURCC( 't', 'r', 'a', 'k' )
43 #define FOURCC_mvhd VLC_FOURCC( 'm', 'v', 'h', 'd' )
44 #define FOURCC_tkhd VLC_FOURCC( 't', 'k', 'h', 'd' )
45 #define FOURCC_tref VLC_FOURCC( 't', 'r', 'e', 'f' )
46 #define FOURCC_mdia VLC_FOURCC( 'm', 'd', 'i', 'a' )
47 #define FOURCC_mdhd VLC_FOURCC( 'm', 'd', 'h', 'd' )
48 #define FOURCC_hdlr VLC_FOURCC( 'h', 'd', 'l', 'r' )
49 #define FOURCC_minf VLC_FOURCC( 'm', 'i', 'n', 'f' )
50 #define FOURCC_vmhd VLC_FOURCC( 'v', 'm', 'h', 'd' )
51 #define FOURCC_smhd VLC_FOURCC( 's', 'm', 'h', 'd' )
52 #define FOURCC_hmhd VLC_FOURCC( 'h', 'm', 'h', 'd' )
53 #define FOURCC_dinf VLC_FOURCC( 'd', 'i', 'n', 'f' )
54 #define FOURCC_url  VLC_FOURCC( 'u', 'r', 'l', ' ' )
55 #define FOURCC_urn  VLC_FOURCC( 'u', 'r', 'n', ' ' )
56 #define FOURCC_dref VLC_FOURCC( 'd', 'r', 'e', 'f' )
57 #define FOURCC_stbl VLC_FOURCC( 's', 't', 'b', 'l' )
58 #define FOURCC_stts VLC_FOURCC( 's', 't', 't', 's' )
59 #define FOURCC_ctts VLC_FOURCC( 'c', 't', 't', 's' )
60 #define FOURCC_stsd VLC_FOURCC( 's', 't', 's', 'd' )
61 #define FOURCC_stsz VLC_FOURCC( 's', 't', 's', 'z' )
62 #define FOURCC_stz2 VLC_FOURCC( 's', 't', 'z', '2' )
63 #define FOURCC_stsc VLC_FOURCC( 's', 't', 's', 'c' )
64 #define FOURCC_stco VLC_FOURCC( 's', 't', 'c', 'o' )
65 #define FOURCC_co64 VLC_FOURCC( 'c', 'o', '6', '4' )
66 #define FOURCC_stss VLC_FOURCC( 's', 't', 's', 's' )
67 #define FOURCC_stsh VLC_FOURCC( 's', 't', 's', 'h' )
68 #define FOURCC_stdp VLC_FOURCC( 's', 't', 'd', 'p' )
69 #define FOURCC_padb VLC_FOURCC( 'p', 'a', 'd', 'b' )
70 #define FOURCC_edts VLC_FOURCC( 'e', 'd', 't', 's' )
71 #define FOURCC_elst VLC_FOURCC( 'e', 'l', 's', 't' )
72 #define FOURCC_udta VLC_FOURCC( 'u', 'd', 't', 'a' )
73 #define FOURCC_mvex VLC_FOURCC( 'm', 'v', 'e', 'x' )
74 #define FOURCC_trex VLC_FOURCC( 't', 'r', 'e', 'x' )
75 #define FOURCC_mfhd VLC_FOURCC( 'm', 'f', 'h', 'd' )
76 #define FOURCC_traf VLC_FOURCC( 't', 'r', 'a', 'f' )
77 #define FOURCC_tfhd VLC_FOURCC( 't', 'f', 'h', 'd' )
78 #define FOURCC_trun VLC_FOURCC( 't', 'r', 'u', 'n' )
79 #define FOURCC_cprt VLC_FOURCC( 'c', 'p', 'r', 't' )
80 #define FOURCC_iods VLC_FOURCC( 'i', 'o', 'd', 's' )
81
82 #define FOURCC_nmhd VLC_FOURCC( 'n', 'm', 'h', 'd' )
83 #define FOURCC_mp2v VLC_FOURCC( 'm', 'p', '2', 'v' )
84 #define FOURCC_mp4v VLC_FOURCC( 'm', 'p', '4', 'v' )
85 #define FOURCC_mp4a VLC_FOURCC( 'm', 'p', '4', 'a' )
86 #define FOURCC_mp4s VLC_FOURCC( 'm', 'p', '4', 's' )
87 #define FOURCC_vide VLC_FOURCC( 'v', 'i', 'd', 'e' )
88 #define FOURCC_soun VLC_FOURCC( 's', 'o', 'u', 'n' )
89 #define FOURCC_hint VLC_FOURCC( 'h', 'i', 'n', 't' )
90 #define FOURCC_hdv2 VLC_FOURCC( 'h', 'd', 'v', '2' )
91
92 #define FOURCC_dpnd VLC_FOURCC( 'd', 'p', 'n', 'd' )
93 #define FOURCC_ipir VLC_FOURCC( 'i', 'p', 'i', 'r' )
94 #define FOURCC_mpod VLC_FOURCC( 'm', 'p', 'o', 'd' )
95 #define FOURCC_hnti VLC_FOURCC( 'h', 'n', 't', 'i' )
96 #define FOURCC_rtp  VLC_FOURCC( 'r', 't', 'p', ' ' )
97
98 #define FOURCC_isom VLC_FOURCC( 'i', 's', 'o', 'm' )
99 #define FOURCC_3gp4 VLC_FOURCC( '3', 'g', 'p', '4' )
100 #define FOURCC_esds VLC_FOURCC( 'e', 's', 'd', 's' )
101
102 #define FOURCC__mp3 VLC_FOURCC( '.', 'm', 'p', '3' )
103 #define FOURCC_ms02 VLC_FOURCC( 'm', 's', 0x0, 0x02 )
104 #define FOURCC_ms11 VLC_FOURCC( 'm', 's', 0x0, 0x11 )
105 #define FOURCC_ms55 VLC_FOURCC( 'm', 's', 0x0, 0x55 )
106 #define FOURCC_twos VLC_FOURCC( 't', 'w', 'o', 's' )
107 #define FOURCC_sowt VLC_FOURCC( 's', 'o', 'w', 't' )
108 #define FOURCC_QDMC VLC_FOURCC( 'Q', 'D', 'M', 'C' )
109 #define FOURCC_QDM2 VLC_FOURCC( 'Q', 'D', 'M', '2' )
110 #define FOURCC_ima4 VLC_FOURCC( 'i', 'm', 'a', '4' )
111 #define FOURCC_IMA4 VLC_FOURCC( 'I', 'M', 'A', '4' )
112 #define FOURCC_dvi  VLC_FOURCC( 'd', 'v', 'i', ' ' )
113 #define FOURCC_MAC3 VLC_FOURCC( 'M', 'A', 'C', '3' )
114 #define FOURCC_MAC6 VLC_FOURCC( 'M', 'A', 'C', '6' )
115 #define FOURCC_alaw VLC_FOURCC( 'a', 'l', 'a', 'w' )
116 #define FOURCC_ulaw VLC_FOURCC( 'u', 'l', 'a', 'w' )
117 #define FOURCC_Qclp VLC_FOURCC( 'Q', 'c', 'l', 'p' )
118 #define FOURCC_samr VLC_FOURCC( 's', 'a', 'm', 'r' )
119 #define FOURCC_sawb VLC_FOURCC( 's', 'a', 'w', 'b' )
120 #define FOURCC_OggS VLC_FOURCC( 'O', 'g', 'g', 'S' )
121 #define FOURCC_alac VLC_FOURCC( 'a', 'l', 'a', 'c' )
122 #define FOURCC_dac3 VLC_FOURCC( 'd', 'a', 'c', '3' )
123 #define FOURCC_dec3 VLC_FOURCC( 'd', 'e', 'c', '3' )
124 #define FOURCC_enda VLC_FOURCC( 'e', 'n', 'd', 'a' )
125 #define FOURCC_gnre VLC_FOURCC( 'g', 'n', 'r', 'e' )
126 #define FOURCC_trkn VLC_FOURCC( 't', 'r', 'k', 'n' )
127
128 #define FOURCC_zlib VLC_FOURCC( 'z', 'l', 'i', 'b' )
129 #define FOURCC_SVQ1 VLC_FOURCC( 'S', 'V', 'Q', '1' )
130 #define FOURCC_SVQ3 VLC_FOURCC( 'S', 'V', 'Q', '3' )
131 #define FOURCC_ZyGo VLC_FOURCC( 'Z', 'y', 'G', 'o' )
132 #define FOURCC_3IV1 VLC_FOURCC( '3', 'I', 'V', '1' )
133 #define FOURCC_3iv1 VLC_FOURCC( '3', 'i', 'v', '1' )
134 #define FOURCC_3IV2 VLC_FOURCC( '3', 'I', 'V', '2' )
135 #define FOURCC_3iv2 VLC_FOURCC( '3', 'i', 'v', '2' )
136 #define FOURCC_3IVD VLC_FOURCC( '3', 'I', 'V', 'D' )
137 #define FOURCC_3ivd VLC_FOURCC( '3', 'i', 'v', 'd' )
138 #define FOURCC_3VID VLC_FOURCC( '3', 'V', 'I', 'D' )
139 #define FOURCC_3vid VLC_FOURCC( '3', 'v', 'i', 'd' )
140 #define FOURCC_h263 VLC_FOURCC( 'h', '2', '6', '3' )
141 #define FOURCC_s263 VLC_FOURCC( 's', '2', '6', '3' )
142 #define FOURCC_DIVX VLC_FOURCC( 'D', 'I', 'V', 'X' )
143 #define FOURCC_XVID VLC_FOURCC( 'X', 'V', 'I', 'D' )
144 #define FOURCC_cvid VLC_FOURCC( 'c', 'v', 'i', 'd' )
145 #define FOURCC_mjpa VLC_FOURCC( 'm', 'j', 'p', 'a' )
146 #define FOURCC_mjpb VLC_FOURCC( 'm', 'j', 'q', 't' )
147 #define FOURCC_mjqt VLC_FOURCC( 'm', 'j', 'h', 't' )
148 #define FOURCC_mjht VLC_FOURCC( 'm', 'j', 'p', 'b' )
149 #define FOURCC_VP31 VLC_FOURCC( 'V', 'P', '3', '1' )
150 #define FOURCC_vp31 VLC_FOURCC( 'v', 'p', '3', '1' )
151 #define FOURCC_h264 VLC_FOURCC( 'h', '2', '6', '4' )
152 #define FOURCC_qdrw VLC_FOURCC( 'q', 'd', 'r', 'w' )
153
154 #define FOURCC_avc1 VLC_FOURCC( 'a', 'v', 'c', '1' )
155 #define FOURCC_avcC VLC_FOURCC( 'a', 'v', 'c', 'C' )
156 #define FOURCC_m4ds VLC_FOURCC( 'm', '4', 'd', 's' )
157
158 #define FOURCC_dvc  VLC_FOURCC( 'd', 'v', 'c', ' ' )
159 #define FOURCC_dvp  VLC_FOURCC( 'd', 'v', 'p', ' ' )
160 #define FOURCC_dv5n VLC_FOURCC( 'd', 'v', '5', 'n' )
161 #define FOURCC_dv5p VLC_FOURCC( 'd', 'v', '5', 'p' )
162 #define FOURCC_raw  VLC_FOURCC( 'r', 'a', 'w', ' ' )
163
164 #define FOURCC_jpeg VLC_FOURCC( 'j', 'p', 'e', 'g' )
165
166 #define FOURCC_yv12 VLC_FOURCC( 'y', 'v', '1', '2' )
167 #define FOURCC_yuv2 VLC_FOURCC( 'y', 'u', 'v', '2' )
168
169 #define FOURCC_rmra VLC_FOURCC( 'r', 'm', 'r', 'a' )
170 #define FOURCC_rmda VLC_FOURCC( 'r', 'm', 'd', 'a' )
171 #define FOURCC_rdrf VLC_FOURCC( 'r', 'd', 'r', 'f' )
172 #define FOURCC_rmdr VLC_FOURCC( 'r', 'm', 'd', 'r' )
173 #define FOURCC_rmvc VLC_FOURCC( 'r', 'm', 'v', 'c' )
174 #define FOURCC_rmcd VLC_FOURCC( 'r', 'm', 'c', 'd' )
175 #define FOURCC_rmqu VLC_FOURCC( 'r', 'm', 'q', 'u' )
176 #define FOURCC_alis VLC_FOURCC( 'a', 'l', 'i', 's' )
177
178 #define FOURCC_gmhd VLC_FOURCC( 'g', 'm', 'h', 'd' )
179 #define FOURCC_wave VLC_FOURCC( 'w', 'a', 'v', 'e' )
180
181 #define FOURCC_drms VLC_FOURCC( 'd', 'r', 'm', 's' )
182 #define FOURCC_sinf VLC_FOURCC( 's', 'i', 'n', 'f' )
183 #define FOURCC_schi VLC_FOURCC( 's', 'c', 'h', 'i' )
184 #define FOURCC_user VLC_FOURCC( 'u', 's', 'e', 'r' )
185 #define FOURCC_key  VLC_FOURCC( 'k', 'e', 'y', ' ' )
186 #define FOURCC_iviv VLC_FOURCC( 'i', 'v', 'i', 'v' )
187 #define FOURCC_name VLC_FOURCC( 'n', 'a', 'm', 'e' )
188 #define FOURCC_priv VLC_FOURCC( 'p', 'r', 'i', 'v' )
189 #define FOURCC_drmi VLC_FOURCC( 'd', 'r', 'm', 'i' )
190 #define FOURCC_frma VLC_FOURCC( 'f', 'r', 'm', 'a' )
191 #define FOURCC_skcr VLC_FOURCC( 's', 'k', 'c', 'r' )
192
193 #define FOURCC_text VLC_FOURCC( 't', 'e', 'x', 't' )
194 #define FOURCC_tx3g VLC_FOURCC( 't', 'x', '3', 'g' )
195 #define FOURCC_subp VLC_FOURCC( 's', 'u', 'b', 'p' )
196 #define FOURCC_sbtl VLC_FOURCC( 's', 'b', 't', 'l' )
197
198 #define FOURCC_0xa9nam VLC_FOURCC( 0xa9, 'n', 'a', 'm' )
199 #define FOURCC_0xa9aut VLC_FOURCC( 0xa9, 'a', 'u', 't' )
200 #define FOURCC_0xa9cpy VLC_FOURCC( 0xa9, 'c', 'p', 'y' )
201 #define FOURCC_0xa9inf VLC_FOURCC( 0xa9, 'i', 'n', 'f' )
202 #define FOURCC_0xa9ART VLC_FOURCC( 0xa9, 'A', 'R', 'T' )
203 #define FOURCC_0xa9des VLC_FOURCC( 0xa9, 'd', 'e', 's' )
204 #define FOURCC_0xa9dir VLC_FOURCC( 0xa9, 'd', 'i', 'r' )
205 #define FOURCC_0xa9cmt VLC_FOURCC( 0xa9, 'c', 'm', 't' )
206 #define FOURCC_0xa9req VLC_FOURCC( 0xa9, 'r', 'e', 'q' )
207 #define FOURCC_0xa9day VLC_FOURCC( 0xa9, 'd', 'a', 'y' )
208 #define FOURCC_0xa9fmt VLC_FOURCC( 0xa9, 'f', 'm', 't' )
209 #define FOURCC_0xa9prd VLC_FOURCC( 0xa9, 'p', 'r', 'd' )
210 #define FOURCC_0xa9prf VLC_FOURCC( 0xa9, 'p', 'r', 'f' )
211 #define FOURCC_0xa9src VLC_FOURCC( 0xa9, 's', 'r', 'c' )
212 #define FOURCC_0xa9alb VLC_FOURCC( 0xa9, 'a', 'l', 'b' )
213 #define FOURCC_0xa9dis VLC_FOURCC( 0xa9, 'd', 'i', 's' )
214 #define FOURCC_0xa9enc VLC_FOURCC( 0xa9, 'e', 'n', 'c' )
215 #define FOURCC_0xa9trk VLC_FOURCC( 0xa9, 't', 'r', 'k' )
216 #define FOURCC_0xa9url VLC_FOURCC( 0xa9, 'u', 'r', 'l' )
217 #define FOURCC_0xa9dsa VLC_FOURCC( 0xa9, 'd', 's', 'a' )
218 #define FOURCC_0xa9hst VLC_FOURCC( 0xa9, 'h', 's', 't' )
219 #define FOURCC_0xa9ope VLC_FOURCC( 0xa9, 'o', 'p', 'e' )
220 #define FOURCC_0xa9wrt VLC_FOURCC( 0xa9, 'w', 'r', 't' )
221 #define FOURCC_0xa9com VLC_FOURCC( 0xa9, 'c', 'o', 'm' )
222 #define FOURCC_0xa9gen VLC_FOURCC( 0xa9, 'g', 'e', 'n' )
223 #define FOURCC_0xa9too VLC_FOURCC( 0xa9, 't', 'o', 'o' )
224 #define FOURCC_0xa9wrn VLC_FOURCC( 0xa9, 'w', 'r', 'n' )
225 #define FOURCC_0xa9swr VLC_FOURCC( 0xa9, 's', 'w', 'r' )
226 #define FOURCC_0xa9mak VLC_FOURCC( 0xa9, 'm', 'a', 'k' )
227 #define FOURCC_0xa9mod VLC_FOURCC( 0xa9, 'm', 'o', 'd' )
228 #define FOURCC_0xa9PRD VLC_FOURCC( 0xa9, 'P', 'R', 'D' )
229 #define FOURCC_0xa9grp VLC_FOURCC( 0xa9, 'g', 'r', 'p' )
230 #define FOURCC_0xa9lyr VLC_FOURCC( 0xa9, 'g', 'r', 'p' )
231 #define FOURCC_chpl VLC_FOURCC( 'c', 'h', 'p', 'l' )
232 #define FOURCC_WLOC VLC_FOURCC( 'W', 'L', 'O', 'C' )
233
234 #define FOURCC_meta VLC_FOURCC( 'm', 'e', 't', 'a' )
235 #define FOURCC_ilst VLC_FOURCC( 'i', 'l', 's', 't' )
236
237 #define FOURCC_chap VLC_FOURCC( 'c', 'h', 'a', 'p' )
238
239 /* Do you want some debug information on all read boxes ? */
240 //#define MP4_VERBOSE  1
241
242
243 struct MP4_Box_s;
244
245
246 /* uuid Universal Unique IDentifiers */
247 typedef struct UUID_s
248 {
249     uint8_t b[16];
250 } UUID_t;
251
252 /* specific structure for all boxes */
253
254 typedef struct MP4_Box_data_ftyp_s
255 {
256     uint32_t i_major_brand;
257     uint32_t i_minor_version;
258
259     uint32_t i_compatible_brands_count;
260     uint32_t *i_compatible_brands;
261
262 } MP4_Box_data_ftyp_t;
263
264 typedef struct MP4_Box_data_mvhd_s
265 {
266     uint8_t  i_version;
267     uint32_t i_flags;
268
269     uint64_t i_creation_time;
270     uint64_t i_modification_time;
271     uint32_t i_timescale;
272     uint64_t i_duration;
273
274     int32_t  i_rate;
275     int16_t  i_volume;
276     int16_t  i_reserved1;
277     uint32_t i_reserved2[2];
278     int32_t  i_matrix[9];
279     uint32_t i_predefined[6];
280     uint32_t i_next_track_id;
281
282 } MP4_Box_data_mvhd_t;
283
284 #define MP4_TRACK_ENABLED    0x000001
285 #define MP4_TRACK_IN_MOVIE   0x000002
286 #define MP4_TRACK_IN_PREVIEW 0x000004
287 typedef struct MP4_Box_data_tkhd_s
288 {
289     uint8_t  i_version;
290     uint32_t i_flags;
291
292     uint64_t i_creation_time;
293     uint64_t i_modification_time;
294     uint32_t i_track_ID;
295     uint32_t i_reserved;
296     uint64_t i_duration;
297
298     uint32_t i_reserved2[2];
299     int16_t  i_layer;
300     int16_t  i_predefined;
301
302     int16_t  i_volume;
303     uint16_t i_reserved3;
304     int32_t  i_matrix[9];
305     int32_t  i_width;
306     int32_t  i_height;
307
308 } MP4_Box_data_tkhd_t;
309
310 typedef struct MP4_Box_data_mdhd_s
311 {
312     uint8_t  i_version;
313     uint32_t i_flags;
314
315     uint64_t i_creation_time;
316     uint64_t i_modification_time;
317     uint32_t i_timescale;
318     uint64_t i_duration;
319
320     /* one bit for pad */
321     uint16_t      i_language_code;
322     /* unsigned int(5)[3] language difference with 0x60*/
323     unsigned char i_language[3];
324     uint16_t i_predefined;
325
326 } MP4_Box_data_mdhd_t;
327
328 typedef struct MP4_Box_data_hdlr_s
329 {
330     uint8_t  i_version;
331     uint32_t i_flags;
332
333     uint32_t i_predefined;
334     uint32_t i_handler_type; /* "vide" "soun" "hint" "odsm"
335                            "crsm" "sdsm" "m7sm" "ocsm"
336                            "ipsm" "mjsm" */
337
338     unsigned char *psz_name; /* in UTF-8 */
339
340 } MP4_Box_data_hdlr_t;
341
342 typedef struct MP4_Box_data_vmhd_s
343 {
344     uint8_t  i_version;
345     uint32_t i_flags;
346
347     int16_t  i_graphics_mode;
348     int16_t  i_opcolor[3];
349
350 } MP4_Box_data_vmhd_t;
351
352 typedef struct MP4_Box_data_smhd_s
353 {
354     uint8_t  i_version;
355     uint32_t i_flags;
356
357     int16_t  i_balance;
358     int16_t  i_reserved;
359
360 } MP4_Box_data_smhd_t;
361
362 typedef struct MP4_Box_data_hmhd_s
363 {
364     uint8_t  i_version;
365     uint32_t i_flags;
366
367     uint16_t i_max_PDU_size;
368     uint16_t i_avg_PDU_size;
369     uint32_t i_max_bitrate;
370     uint32_t i_avg_bitrate;
371     uint32_t i_reserved;
372
373 } MP4_Box_data_hmhd_t;
374
375 typedef struct MP4_Box_data_url_s
376 {
377     uint8_t  i_version;
378     uint32_t i_flags;
379
380     char *psz_location;
381
382 } MP4_Box_data_url_t;
383
384 typedef struct MP4_Box_data_urn_s
385 {
386     uint8_t  i_version;
387     uint32_t i_flags;
388
389     char *psz_name;
390     char *psz_location;
391
392 } MP4_Box_data_urn_t;
393
394 typedef struct MP4_Box_data_dref_s
395 {
396     uint8_t  i_version;
397     uint32_t i_flags;
398
399     uint32_t i_entry_count;
400 /* XXX it's also a container with i_entry_count entry */
401 } MP4_Box_data_dref_t;
402
403 typedef struct MP4_Box_data_stts_s
404 {
405     uint8_t  i_version;
406     uint32_t i_flags;
407
408     uint32_t i_entry_count;
409     uint32_t *i_sample_count; /* these are array */
410     int32_t  *i_sample_delta;
411
412 } MP4_Box_data_stts_t;
413
414 typedef struct MP4_Box_data_ctts_s
415 {
416     uint8_t  i_version;
417     uint32_t i_flags;
418
419     uint32_t i_entry_count;
420
421     uint32_t *i_sample_count; /* these are array */
422     int32_t  *i_sample_offset;
423
424 } MP4_Box_data_ctts_t;
425
426
427 typedef struct MP4_Box_data_sample_soun_s
428 {
429     uint8_t  i_reserved1[6];
430     uint16_t i_data_reference_index;
431
432     //uint32_t i_reserved2[2];
433     uint16_t i_qt_version;
434     uint16_t i_qt_revision_level;
435     uint32_t i_qt_vendor;
436
437     uint16_t i_channelcount;
438     uint16_t i_samplesize;
439     uint16_t i_predefined;
440     uint16_t i_reserved3;
441     uint16_t i_sampleratehi; /* timescale of track */
442     uint16_t i_sampleratelo;
443
444     /* for version 1 (i_reserved1[0] == 1) */
445     uint32_t i_sample_per_packet;
446     uint32_t i_bytes_per_packet;
447     uint32_t i_bytes_per_frame;
448     uint32_t i_bytes_per_sample;
449
450     /* XXX hack */
451     int     i_qt_description;
452     uint8_t *p_qt_description;
453
454     void    *p_drms;
455
456 } MP4_Box_data_sample_soun_t;
457
458 typedef struct MP4_Box_data_sample_vide_s
459 {
460     uint8_t  i_reserved1[6];
461     uint16_t i_data_reference_index;
462
463     uint16_t i_qt_version;
464     uint16_t i_qt_revision_level;
465     uint32_t i_qt_vendor;
466
467     uint32_t i_qt_temporal_quality;
468     uint32_t i_qt_spatial_quality;
469
470     int16_t  i_width;
471     int16_t  i_height;
472
473     uint32_t i_horizresolution;
474     uint32_t i_vertresolution;
475
476     uint32_t i_qt_data_size;
477     uint16_t i_qt_frame_count;
478
479     uint8_t  i_compressorname[32];
480     int16_t  i_depth;
481
482     int16_t  i_qt_color_table;
483
484     /* XXX hack ImageDescription */
485     int     i_qt_image_description;
486     uint8_t *p_qt_image_description;
487
488     void    *p_drms;
489
490 } MP4_Box_data_sample_vide_t;
491
492 #define MP4_TEXT_DISPLAY_FLAG_DONT_DISPLAY       (1<<0)
493 #define MP4_TEXT_DISPLAY_FLAG_AUTO_SCALE         (1<<1)
494 #define MP4_TEXT_DISPLAY_FLAG_CLIP_TO_TEXT_BOX   (1<<2)
495 #define MP4_TEXT_DISPLAY_FLAG_USE_MOVIE_BG_COLOR (1<<3)
496 #define MP4_TEXT_DISPLAY_FLAG_SHRINK_TEXT_BOX_TO_FIT (1<<4)
497 #define MP4_TEXT_DISPLAY_FLAG_SCROLL_IN          (1<<5)
498 #define MP4_TEXT_DISPLAY_FLAG_SCROLL_OUT         (1<<6)
499 #define MP4_TEXT_DISPLAY_FLAG_HORIZONTAL_SCROLL  (1<<7)
500 #define MP4_TEXT_DISPLAY_FLAG_REVERSE_SCROLL     (1<<8)
501 #define MP4_TEXT_DISPLAY_FLAG_CONTINUOUS_SCROLL  (1<<9)
502 #define MP4_TEXT_DISPLAY_FLAG_FLOW_HORIZONTAL    (1<<10)
503 #define MP4_TEXT_DISPLAY_FLAG_CONTINUOUS_KARAOKE (1<<11)
504 #define MP4_TEXT_DISPLAY_FLAG_DROP_SHADOW        (1<<12)
505 #define MP4_TEXT_DISPLAY_FLAG_ANTI_ALIAS         (1<<13)
506 #define MP4_TEXT_DISPLAY_FLAG_KEYED_TEXT         (1<<14)
507 #define MP4_TEXT_DISPLAY_FLAG_INVERSE_HILITE     (1<<15)
508 #define MP4_TEXT_DISPLAY_FLAG_COLOR_HILITE       (1<<16)
509 #define MP4_TEXT_DISPLAY_FLAG_WRITE_VERTICALLY   (1<<17)
510
511 typedef struct
512 {
513     uint32_t i_reserved1;
514     uint16_t i_reserved2;
515
516     uint16_t i_data_reference_index;
517
518     uint32_t i_display_flags;   // TextDescription and Tx3gDescription
519
520     int8_t i_justification_horizontal; // left(0), centered(1), right(-1)
521     int8_t i_justification_vertical;   // top(0), centered(1), bottom(-1)
522
523     uint16_t i_background_color[4];
524
525     uint16_t i_text_box_top;
526     uint16_t i_text_box_left;
527     uint16_t i_text_box_bottom;
528     uint16_t i_text_box_right;
529
530     // TODO to complete
531 } MP4_Box_data_sample_text_t;
532
533 typedef struct MP4_Box_data_sample_hint_s
534 {
535     uint8_t  i_reserved1[6];
536     uint16_t i_data_reference_index;
537
538     uint8_t *p_data;
539
540 } MP4_Box_data_sample_hint_t;
541
542 typedef struct MP4_Box_data_moviehintinformation_rtp_s
543 {
544     uint32_t i_description_format;
545     unsigned char *psz_text;
546
547 } MP4_Box_data_moviehintinformation_rtp_t;
548
549
550
551 typedef struct MP4_Box_data_stsd_s
552 {
553     uint8_t  i_version;
554     uint32_t i_flags;
555
556     uint32_t i_entry_count;
557
558     /* it contains SampleEntry handled as if it was Box */
559
560 } MP4_Box_data_stsd_t;
561
562
563 typedef struct MP4_Box_data_stsz_s
564 {
565     uint8_t  i_version;
566     uint32_t i_flags;
567
568     uint32_t i_sample_size;
569     uint32_t i_sample_count;
570
571     uint32_t *i_entry_size; /* array , empty if i_sample_size != 0 */
572
573 } MP4_Box_data_stsz_t;
574
575 typedef struct MP4_Box_data_stz2_s
576 {
577     uint8_t  i_version;
578     uint32_t i_flags;
579
580     uint32_t i_sample_size; /* 24 bits */
581     uint8_t  i_field_size;
582     uint32_t i_sample_count;
583
584     uint32_t *i_entry_size; /* array: unsigned int(i_field_size) entry_size */
585
586 } MP4_Box_data_stz2_t;
587
588 typedef struct MP4_Box_data_stsc_s
589 {
590     uint8_t  i_version;
591     uint32_t i_flags;
592
593     uint32_t i_entry_count;
594
595     uint32_t *i_first_chunk; /* theses are arrays */
596     uint32_t *i_samples_per_chunk;
597     uint32_t *i_sample_description_index;
598
599 } MP4_Box_data_stsc_t;
600
601
602 typedef struct MP4_Box_data_co64_s
603 {
604     uint8_t  i_version;
605     uint32_t i_flags;
606
607     uint32_t i_entry_count;
608
609     uint64_t *i_chunk_offset;
610
611 } MP4_Box_data_co64_t;
612
613
614 typedef struct MP4_Box_data_stss_s
615 {
616     uint8_t  i_version;
617     uint32_t i_flags;
618
619     uint32_t i_entry_count;
620
621     uint32_t *i_sample_number;
622
623 } MP4_Box_data_stss_t;
624
625 typedef struct MP4_Box_data_stsh_s
626 {
627     uint8_t  i_version;
628     uint32_t i_flags;
629
630     uint32_t i_entry_count;
631
632     uint32_t *i_shadowed_sample_number;
633     uint32_t *i_sync_sample_number;
634
635 } MP4_Box_data_stsh_t;
636
637 typedef struct MP4_Box_data_stdp_s
638 {
639     uint8_t  i_version;
640     uint32_t i_flags;
641
642     uint16_t *i_priority;
643
644 } MP4_Box_data_stdp_t;
645
646 typedef struct MP4_Box_data_padb_s
647 {
648     uint8_t  i_version;
649     uint32_t i_flags;
650
651     uint32_t i_sample_count;
652
653     uint16_t *i_reserved1;   /* 1bit  */
654     uint16_t *i_pad2;        /* 3bits */
655     uint16_t *i_reserved2;   /* 1bit  */
656     uint16_t *i_pad1;        /* 3bits */
657
658
659 } MP4_Box_data_padb_t;
660
661
662 typedef struct MP4_Box_data_elst_s
663 {
664     uint8_t  i_version;
665     uint32_t i_flags;
666
667     uint32_t i_entry_count;
668
669     uint64_t *i_segment_duration;
670     int64_t  *i_media_time;
671     uint16_t *i_media_rate_integer;
672     uint16_t *i_media_rate_fraction;
673
674
675 } MP4_Box_data_elst_t;
676
677 typedef struct MP4_Box_data_cprt_s
678 {
679     uint8_t  i_version;
680     uint32_t i_flags;
681     /* 1 pad bit */
682     unsigned char i_language[3];
683
684     char *psz_notice;
685 } MP4_Box_data_cprt_t;
686
687
688 /* DecoderConfigDescriptor */
689 typedef struct MP4_descriptor_decoder_config_s
690 {
691     uint8_t i_objectTypeIndication;
692     uint8_t i_streamType;
693     int     b_upStream;
694     int     i_buffer_sizeDB;
695     int     i_max_bitrate;
696     int     i_avg_bitrate;
697
698     int     i_decoder_specific_info_len;
699     uint8_t *p_decoder_specific_info;
700     /* some other stuff */
701
702 } MP4_descriptor_decoder_config_t;
703
704 typedef struct MP4_descriptor_SL_config_s
705 {
706
707     int i_dummy; /* ANSI C forbids empty structures */
708
709 } MP4_descriptor_SL_config_t;
710
711
712 typedef struct MP4_descriptor_ES_s
713 {
714     uint16_t i_ES_ID;
715     int      b_stream_dependence;
716     int      b_url;
717     int      b_OCRstream;
718     int      i_stream_priority;
719
720     int      i_depend_on_ES_ID; /* if b_stream_dependence set */
721
722     unsigned char *psz_URL;
723
724     uint16_t i_OCR_ES_ID;       /* if b_OCRstream */
725     MP4_descriptor_decoder_config_t *p_decConfigDescr;
726
727     MP4_descriptor_SL_config_t *p_slConfigDescr;
728
729     /* some other stuff ... */
730
731 } MP4_descriptor_ES_t;
732
733 /* ES descriptor */
734 typedef struct MP4_Box_data_esds_s
735 {
736     uint8_t  i_version;
737     uint32_t i_flags;
738
739     MP4_descriptor_ES_t es_descriptor;
740
741 } MP4_Box_data_esds_t;
742
743
744 typedef struct MP4_Box_data_dcom_s
745 {
746     uint32_t i_algorithm; /* fourcc */
747
748 } MP4_Box_data_dcom_t;
749
750 typedef struct MP4_Box_data_cmvd_s
751 {
752     uint32_t i_uncompressed_size;
753     uint32_t i_compressed_size;
754
755     int     b_compressed; /* Set to 1 if compressed data, 0 if uncompressed */
756     uint8_t *p_data;
757
758 } MP4_Box_data_cmvd_t;
759
760 typedef struct MP4_Box_data_cmov_s
761 {
762     struct MP4_Box_s *p_moov; /* uncompressed moov */
763
764 } MP4_Box_data_cmov_t;
765
766 typedef struct
767 {
768     uint32_t i_type;
769 } MP4_Box_data_frma_t;
770
771 typedef struct
772 {
773     uint32_t i_init;
774     uint32_t i_encr;
775     uint32_t i_decr;
776 } MP4_Box_data_skcr_t;
777
778 typedef struct
779 {
780     uint8_t  i_version;
781     uint32_t i_flags;
782
783     uint32_t i_ref_type;
784     char     *psz_ref;
785
786 } MP4_Box_data_rdrf_t;
787
788 typedef struct
789 {
790     uint8_t  i_version;
791     uint32_t i_flags;
792
793     uint32_t i_rate;
794
795 } MP4_Box_data_rmdr_t;
796
797 typedef struct
798 {
799     uint8_t  i_version;
800     uint32_t i_flags;
801
802     uint32_t i_gestaltType;
803     uint32_t i_val1;
804     uint32_t i_val2;
805     uint16_t i_checkType;   /* 0: val1 is version min
806                                1: gestalt value & val2 == val1 */
807
808 } MP4_Box_data_rmvc_t;
809
810 typedef struct
811 {
812     uint8_t  i_version;
813     uint32_t i_flags;
814
815
816 } MP4_Box_data_rmcd_t;
817
818 typedef struct
819 {
820     uint32_t i_quality;
821
822 } MP4_Box_data_rmqu_t;
823
824 typedef struct MP4_Box_data_mfhd_s
825 {
826     uint32_t i_sequence_number;
827
828     uint8_t *p_vendor_extension;
829
830 } MP4_Box_data_mfhd_t;
831
832 #define MP4_TFHD_BASE_DATA_OFFSET     (1LL<<0)
833 #define MP4_TFHD_SAMPLE_DESC_INDEX    (1LL<<1)
834 #define MP4_TFHD_DFLT_SAMPLE_DURATION (1LL<<3)
835 #define MP4_TFHD_DFLT_SAMPLE_SIZE     (1LL<<4)
836 #define MP4_TFHD_DFLT_SAMPLE_FLAGS    (1LL<<5)
837 typedef struct MP4_Box_data_tfhd_s
838 {
839     uint8_t  i_version;
840     uint32_t i_flags;
841     uint32_t i_track_ID;
842
843     /* optional fields */
844     uint64_t i_base_data_offset;
845     uint32_t i_sample_description_index;
846     uint32_t i_default_sample_duration;
847     uint32_t i_default_sample_size;
848     uint32_t i_default_sample_flags;
849
850 } MP4_Box_data_tfhd_t;
851
852 #define MP4_TRUN_DATA_OFFSET         (1<<0)
853 #define MP4_TRUN_FIRST_FLAGS         (1<<2)
854 #define MP4_TRUN_SAMPLE_DURATION     (1<<8)
855 #define MP4_TRUN_SAMPLE_SIZE         (1<<9)
856 #define MP4_TRUN_SAMPLE_FLAGS        (1<<10)
857 #define MP4_TRUN_SAMPLE_TIME_OFFSET  (1<<11)
858 typedef struct MP4_descriptor_trun_sample_t
859 {
860     uint32_t i_duration;
861     uint32_t i_size;
862     uint32_t i_flags;
863     uint32_t i_composition_time_offset;
864 } MP4_descriptor_trun_sample_t;
865
866 typedef struct MP4_Box_data_trun_s
867 {
868     uint8_t  i_version;
869     uint32_t i_flags;
870     uint32_t i_sample_count;
871
872     /* optional fields */
873     uint32_t i_data_offset;
874     uint32_t i_first_sample_flags;
875
876     MP4_descriptor_trun_sample_t *p_samples;
877
878 } MP4_Box_data_trun_t;
879
880
881 typedef struct
882 {
883     char *psz_text;
884
885 } MP4_Box_data_0xa9xxx_t;
886
887 typedef struct
888 {
889     uint32_t i_entry_count;
890     uint32_t *i_track_ID;
891
892 } MP4_Box_data_tref_generic_t;
893
894 typedef struct
895 {
896     uint8_t  i_version;
897     uint32_t i_flags;
898
899     uint8_t i_chapter;
900     struct
901     {
902         char    *psz_name;
903         int64_t  i_start;
904     } chapter[256];
905 } MP4_Box_data_chpl_t;
906
907 typedef struct
908 {
909     uint8_t i_version;
910     uint8_t i_profile;
911     uint8_t i_profile_compatibility;
912     uint8_t i_level;
913
914     uint8_t i_reserved1;     /* 6 bits */
915     uint8_t i_length_size;
916
917     uint8_t i_reserved2;    /* 3 bits */
918     uint8_t  i_sps;
919     uint16_t *i_sps_length;
920     uint8_t  **sps;
921
922     uint8_t  i_pps;
923     uint16_t *i_pps_length;
924     uint8_t  **pps;
925
926     /* XXX: Hack raw avcC atom payload */
927     int     i_avcC;
928     uint8_t *p_avcC;
929
930 } MP4_Box_data_avcC_t;
931
932 typedef struct
933 {
934     uint8_t i_fscod;
935     uint8_t i_bsid;
936     uint8_t i_bsmod;
937     uint8_t i_acmod;
938     uint8_t i_lfeon;
939     uint8_t i_bitrate_code;
940
941 } MP4_Box_data_dac3_t;
942
943 typedef struct
944 {
945     uint16_t i_little_endian;
946
947 } MP4_Box_data_enda_t;
948
949 typedef struct
950 {
951     uint16_t i_genre;
952
953 } MP4_Box_data_gnre_t;
954
955 typedef struct
956 {
957     uint32_t i_track_number;
958     uint32_t i_track_total;
959
960 } MP4_Box_data_trkn_t;
961
962 /*
963 typedef struct MP4_Box_data__s
964 {
965     uint8_t  i_version;
966     uint32_t i_flags;
967
968 } MP4_Box_data__t;
969
970 */
971
972 typedef union MP4_Box_data_s
973 {
974     MP4_Box_data_ftyp_t *p_ftyp;
975     MP4_Box_data_mvhd_t *p_mvhd;
976     MP4_Box_data_mfhd_t *p_mfhd;
977     MP4_Box_data_tfhd_t *p_tfhd;
978     MP4_Box_data_trun_t *p_trun;
979     MP4_Box_data_tkhd_t *p_tkhd;
980     MP4_Box_data_mdhd_t *p_mdhd;
981     MP4_Box_data_hdlr_t *p_hdlr;
982     MP4_Box_data_vmhd_t *p_vmhd;
983     MP4_Box_data_smhd_t *p_smhd;
984     MP4_Box_data_hmhd_t *p_hmhd;
985     MP4_Box_data_url_t  *p_url;
986     MP4_Box_data_urn_t  *p_urn;
987     MP4_Box_data_dref_t *p_dref;
988     MP4_Box_data_stts_t *p_stts;
989     MP4_Box_data_ctts_t *p_ctts;
990     MP4_Box_data_stsd_t *p_stsd;
991     MP4_Box_data_sample_vide_t *p_sample_vide;
992     MP4_Box_data_sample_soun_t *p_sample_soun;
993     MP4_Box_data_sample_text_t *p_sample_text;
994     MP4_Box_data_sample_hint_t *p_sample_hint;
995
996     MP4_Box_data_esds_t *p_esds;
997     MP4_Box_data_avcC_t *p_avcC;
998     MP4_Box_data_dac3_t *p_dac3;
999     MP4_Box_data_enda_t *p_enda;
1000     MP4_Box_data_gnre_t *p_gnre;
1001     MP4_Box_data_trkn_t *p_trkn;
1002
1003     MP4_Box_data_stsz_t *p_stsz;
1004     MP4_Box_data_stz2_t *p_stz2;
1005     MP4_Box_data_stsc_t *p_stsc;
1006     MP4_Box_data_co64_t *p_co64;
1007     MP4_Box_data_stss_t *p_stss;
1008     MP4_Box_data_stsh_t *p_stsh;
1009     MP4_Box_data_stdp_t *p_stdp;
1010     MP4_Box_data_padb_t *p_padb;
1011     MP4_Box_data_elst_t *p_elst;
1012     MP4_Box_data_cprt_t *p_cprt;
1013
1014     MP4_Box_data_dcom_t *p_dcom;
1015     MP4_Box_data_cmvd_t *p_cmvd;
1016     MP4_Box_data_cmov_t *p_cmov;
1017
1018     MP4_Box_data_moviehintinformation_rtp_t p_moviehintinformation_rtp;
1019
1020     MP4_Box_data_frma_t *p_frma;
1021     MP4_Box_data_skcr_t *p_skcr;
1022
1023     MP4_Box_data_rdrf_t *p_rdrf;
1024     MP4_Box_data_rmdr_t *p_rmdr;
1025     MP4_Box_data_rmqu_t *p_rmqu;
1026     MP4_Box_data_rmvc_t *p_rmvc;
1027
1028     MP4_Box_data_0xa9xxx_t *p_0xa9xxx;
1029     MP4_Box_data_chpl_t *p_chpl;
1030     MP4_Box_data_tref_generic_t *p_tref_generic;
1031
1032     void                *p_data; /* for unknow type */
1033 } MP4_Box_data_t;
1034
1035
1036
1037 /* the most basic structure */
1038 typedef struct MP4_Box_s
1039 {
1040     off_t        i_pos;      /* absolute position */
1041
1042     uint32_t     i_type;
1043     uint32_t     i_shortsize;
1044
1045     UUID_t       i_uuid;  /* Set if i_type == "uuid" */
1046
1047     uint64_t     i_size; /* always set so use it */
1048
1049     MP4_Box_data_t   data;   /* union of pointers on extended data depending
1050                                 on i_type (or i_usertype) */
1051
1052     struct MP4_Box_s *p_father; /* pointer on the father Box */
1053
1054     struct MP4_Box_s *p_first;  /* pointer on the first child Box */
1055     struct MP4_Box_s *p_last;
1056
1057     struct MP4_Box_s *p_next;   /* pointer on the next boxes at the same level */
1058
1059 } MP4_Box_t;
1060
1061
1062
1063 /*****************************************************************************
1064  * MP4_BoxGetRoot : Parse the entire file, and create all boxes in memory
1065  *****************************************************************************
1066  *  The first box is a virtual box "root" and is the father for all first
1067  *  level boxes
1068  *****************************************************************************/
1069 MP4_Box_t *MP4_BoxGetRoot( stream_t * );
1070
1071 /*****************************************************************************
1072  * MP4_FreeBox : free memory allocated after read with MP4_ReadBox
1073  *               or MP4_BoxGetRoot, this means also children boxes
1074  * XXX : all children have to be allocated by a malloc !! and
1075  *         p_box is freed
1076  *****************************************************************************/
1077 void MP4_BoxFree( stream_t *, MP4_Box_t *p_box );
1078
1079 /*****************************************************************************
1080  * MP4_DumpBoxStructure: print the structure of the p_box
1081  *****************************************************************************
1082  * Useful while debugging
1083  *****************************************************************************/
1084 void MP4_BoxDumpStructure( stream_t *p_input, MP4_Box_t *p_box );
1085
1086
1087 /*****************************************************************************
1088  * MP4_BoxGet: find a box given a path relative to p_box
1089  *****************************************************************************
1090  * Path Format: . .. / as usual
1091  *              [number] to specifie box number ex: trak[12]
1092  *
1093  * ex: /moov/trak[12]
1094  *     ../mdia
1095  *****************************************************************************/
1096 MP4_Box_t *MP4_BoxGet( MP4_Box_t *p_box, const char *psz_fmt, ... );
1097
1098 /*****************************************************************************
1099  * MP4_BoxCount: find number of box given a path relative to p_box
1100  *****************************************************************************
1101  * Path Format: . .. / as usual
1102  *              [number] to specifie box number ex: trak[12]
1103  *
1104  * ex: /moov/trak
1105  *     ../mdia
1106  *****************************************************************************/
1107 int MP4_BoxCount( MP4_Box_t *p_box, const char *psz_fmt, ... );
1108
1109 int MP4_ReadBoxCommon( stream_t *p_stream, MP4_Box_t *p_box );
1110 int MP4_ReadBox_sample_vide( stream_t *p_stream, MP4_Box_t *p_box );
1111 void MP4_FreeBox_sample_vide( MP4_Box_t *p_box );
1112
1113 #endif