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