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