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