]> git.sesse.net Git - vlc/blob - modules/demux/mp4/libmp4.h
* mp4: prevent float exeption with some truncated file.
[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.4 2002/11/17 06:46:56 fenrir 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_cmov VLC_FOURCC( 'c', 'm', 'o', 'v' )
28 #define FOURCC_dcom VLC_FOURCC( 'd', 'c', 'o', 'm' )
29 #define FOURCC_cmvd VLC_FOURCC( 'c', 'm', 'v', 'd' )
30     
31 #define FOURCC_moof VLC_FOURCC( 'm', 'o', 'o', 'f' )
32 #define FOURCC_mdat VLC_FOURCC( 'm', 'd', 'a', 't' )
33 #define FOURCC_skip VLC_FOURCC( 's', 'k', 'i', 'p' )
34 #define FOURCC_free VLC_FOURCC( 'f', 'r', 'e', 'e' )
35 #define FOURCC_udta VLC_FOURCC( 'u', 'd', 't', 'a' )
36 #define FOURCC_wide VLC_FOURCC( 'w', 'i', 'd', 'e' )
37
38 #define FOURCC_trak VLC_FOURCC( 't', 'r', 'a', 'k' )
39 #define FOURCC_mvhd VLC_FOURCC( 'm', 'v', 'h', 'd' )
40 #define FOURCC_tkhd VLC_FOURCC( 't', 'k', 'h', 'd' )
41 #define FOURCC_tref VLC_FOURCC( 't', 'r', 'e', 'f' )
42 #define FOURCC_mdia VLC_FOURCC( 'm', 'd', 'i', 'a' )
43 #define FOURCC_mdhd VLC_FOURCC( 'm', 'd', 'h', 'd' )
44 #define FOURCC_hdlr VLC_FOURCC( 'h', 'd', 'l', 'r' )
45 #define FOURCC_minf VLC_FOURCC( 'm', 'i', 'n', 'f' )
46 #define FOURCC_vmhd VLC_FOURCC( 'v', 'm', 'h', 'd' )
47 #define FOURCC_smhd VLC_FOURCC( 's', 'm', 'h', 'd' )
48 #define FOURCC_hmhd VLC_FOURCC( 'h', 'm', 'h', 'd' )
49 #define FOURCC_dinf VLC_FOURCC( 'd', 'i', 'n', 'f' )
50 #define FOURCC_url  VLC_FOURCC( 'u', 'r', 'l', ' ' )
51 #define FOURCC_urn  VLC_FOURCC( 'u', 'r', 'n', ' ' )
52 #define FOURCC_dref VLC_FOURCC( 'd', 'r', 'e', 'f' )
53 #define FOURCC_stbl VLC_FOURCC( 's', 't', 'b', 'l' )
54 #define FOURCC_stts VLC_FOURCC( 's', 't', 't', 's' )
55 #define FOURCC_ctts VLC_FOURCC( 'c', 't', 't', 's' )
56 #define FOURCC_stsd VLC_FOURCC( 's', 't', 's', 'd' )
57 #define FOURCC_stsz VLC_FOURCC( 's', 't', 's', 'z' )
58 #define FOURCC_stz2 VLC_FOURCC( 's', 't', 'z', '2' )
59 #define FOURCC_stsc VLC_FOURCC( 's', 't', 's', 'c' )
60 #define FOURCC_stco VLC_FOURCC( 's', 't', 'c', 'o' )
61 #define FOURCC_co64 VLC_FOURCC( 'c', 'o', '6', '4' )
62 #define FOURCC_stss VLC_FOURCC( 's', 't', 's', 's' )
63 #define FOURCC_stsh VLC_FOURCC( 's', 't', 's', 'h' )
64 #define FOURCC_stdp VLC_FOURCC( 's', 't', 'd', 'p' )
65 #define FOURCC_padb VLC_FOURCC( 'p', 'a', 'd', 'b' )
66 #define FOURCC_edts VLC_FOURCC( 'e', 'd', 't', 's' )
67 #define FOURCC_elst VLC_FOURCC( 'e', 'l', 's', 't' )
68 #define FOURCC_udta VLC_FOURCC( 'u', 'd', 't', 'a' )
69 #define FOURCC_mvex VLC_FOURCC( 'm', 'v', 'e', 'x' )
70 #define FOURCC_trex VLC_FOURCC( 't', 'r', 'e', 'x' )
71 #define FOURCC_mfhd VLC_FOURCC( 'm', 'f', 'h', 'd' )
72 #define FOURCC_traf VLC_FOURCC( 't', 'r', 'a', 'f' )
73 #define FOURCC_tfhd VLC_FOURCC( 't', 'f', 'h', 'd' )
74 #define FOURCC_trun VLC_FOURCC( 't', 'r', 'u', 'n' )
75 #define FOURCC_cprt VLC_FOURCC( 'c', 'p', 'r', 't' )
76 #define FOURCC_iods VLC_FOURCC( 'i', 'o', 'd', 's' )
77
78 #define FOURCC_nmhd VLC_FOURCC( 'n', 'm', 'h', 'd' )
79 #define FOURCC_mp4v VLC_FOURCC( 'm', 'p', '4', 'v' )
80 #define FOURCC_mp4a VLC_FOURCC( 'm', 'p', '4', 'a' )
81 #define FOURCC_mp4s VLC_FOURCC( 'm', 'p', '4', 's' )
82 #define FOURCC_vide VLC_FOURCC( 'v', 'i', 'd', 'e' )
83 #define FOURCC_soun VLC_FOURCC( 's', 'o', 'u', 'n' )
84 #define FOURCC_hint VLC_FOURCC( 'h', 'i', 'n', 't' )
85     
86 #define FOURCC_dpnd VLC_FOURCC( 'd', 'p', 'n', 'd' )
87 #define FOURCC_ipir VLC_FOURCC( 'i', 'p', 'i', 'r' )
88 #define FOURCC_mpod VLC_FOURCC( 'm', 'p', 'o', 'd' )
89 #define FOURCC_hnti VLC_FOURCC( 'h', 'n', 't', 'i' )
90 #define FOURCC_rtp  VLC_FOURCC( 'r', 't', 'p', ' ' )
91
92 #define FOURCC_isom VLC_FOURCC( 'i', 's', 'o', 'm' )
93 #define FOURCC_esds VLC_FOURCC( 'e', 's', 'd', 's' )
94
95 #define FOURCC_zlib VLC_FOURCC( 'z', 'l', 'i', 'b' )
96 #define FOURCC_SVQ1 VLC_FOURCC( 'S', 'V', 'Q', '1' )
97 #define FOURCC__mp3 VLC_FOURCC( '.', 'm', 'p', '3' )
98 #define FOURCC_ms55 VLC_FOURCC( 'm', 's', 0x0, 0x55 )
99 #define FOURCC_3IV1 VLC_FOURCC( '3', 'I', 'V', '1' )
100 #define FOURCC_3IV2 VLC_FOURCC( '3', 'I', 'V', '2' )
101 #define FOURCC_h263 VLC_FOURCC( 'h', '2', '6', '3' )
102 #define FOURCC_DIVX VLC_FOURCC( 'D', 'I', 'V', 'X' )
103 #define FOURCC_cvid VLC_FOURCC( 'c', 'v', 'i', 'd' )
104 #define FOURCC_mjpa VLC_FOURCC( 'm', 'j', 'p', 'a' )
105 #define FOURCC_mjpb VLC_FOURCC( 'm', 'j', 'q', 't' )
106 #define FOURCC_mjqt VLC_FOURCC( 'm', 'j', 'h', 't' )
107 #define FOURCC_mjht VLC_FOURCC( 'm', 'j', 'p', 'b' )
108  
109 #define FOURCC_jpeg VLC_FOURCC( 'j', 'p', 'e', 'g' )
110
111 /* Do you want some debug information on all read boxes ? */
112 #define MP4_VERBOSE  1
113
114 /* memory stream and file stream object */
115
116 typedef struct MP4_Stream_s
117 {
118     int     b_memory;   /* do we uses a memory buffer */
119
120     input_thread_t *p_input;
121     
122     off_t   i_start; /* in the buffer position for memory stream */
123     off_t   i_stop;
124     uint8_t *p_buffer;
125
126 } MP4_Stream_t;
127     
128 struct MP4_Box_s;
129
130
131 /* uuid Universal Unique IDentifiers */
132 typedef struct UUID_s 
133 {
134     uint8_t b[16];
135 } UUID_t;
136
137 /* specific structure for all boxes */
138
139 typedef struct MP4_Box_data_ftyp_s
140 {
141     uint32_t i_major_brand;
142     uint32_t i_minor_version;
143
144     uint32_t i_compatible_brands_count;
145     uint32_t *i_compatible_brands;
146
147 } MP4_Box_data_ftyp_t;
148
149 typedef struct MP4_Box_data_mvhd_s
150 {
151     uint8_t  i_version;
152     uint32_t i_flags;
153         
154     uint64_t i_creation_time;
155     uint64_t i_modification_time;
156     uint32_t i_timescale;
157     uint64_t i_duration;
158
159     int32_t  i_rate;
160     int16_t  i_volume;
161     int16_t  i_reserved1;
162     uint32_t i_reserved2[2];
163     int32_t  i_matrix[9];
164     uint32_t i_predefined[6];
165     uint32_t i_next_track_id;
166
167 } MP4_Box_data_mvhd_t;
168
169 #define MP4_TRACK_ENABLED    0x000001
170 #define MP4_TRACK_IN_MOVIE   0x000002
171 #define MP4_TRACK_IN_PREVIEW 0x000004
172 typedef struct MP4_Box_data_tkhd_s
173 {
174     uint8_t  i_version;
175     uint32_t i_flags;
176         
177     uint64_t i_creation_time;
178     uint64_t i_modification_time;
179     uint32_t i_track_ID;
180     uint32_t i_reserved;
181     uint64_t i_duration;
182     
183     uint32_t i_reserved2[2];
184     int16_t  i_layer;
185     int16_t  i_predefined;
186     
187     int16_t  i_volume;
188     uint16_t i_reserved3;
189     int32_t  i_matrix[9];
190     int32_t  i_width;
191     int32_t  i_height;
192     
193 } MP4_Box_data_tkhd_t;
194
195 typedef struct MP4_Box_data_mdhd_s
196 {
197     uint8_t  i_version;
198     uint32_t i_flags;
199         
200     uint64_t i_creation_time;
201     uint64_t i_modification_time;
202     uint32_t i_timescale;
203     uint64_t i_duration;
204
205     /* one bit for pad */
206     /* unsigned int(5)[3] language difference with 0x60*/
207     unsigned char i_language[3]; 
208     uint16_t i_predefined;
209
210 } MP4_Box_data_mdhd_t;
211
212 typedef struct MP4_Box_data_hdlr_s
213 {
214     uint8_t  i_version;
215     uint32_t i_flags;
216     
217     uint32_t i_predefined;
218     uint32_t i_handler_type; /* "vide" "soun" "hint" "odsm" 
219                            "crsm" "sdsm" "m7sm" "ocsm" 
220                            "ipsm" "mjsm" */
221     
222     unsigned char *psz_name; /* in UTF-8 */
223
224 } MP4_Box_data_hdlr_t;
225
226 typedef struct MP4_Box_data_vmhd_s
227 {
228     uint8_t  i_version;
229     uint32_t i_flags;
230     
231     int16_t  i_graphics_mode;
232     int16_t  i_opcolor[3];    
233
234 } MP4_Box_data_vmhd_t;
235
236 typedef struct MP4_Box_data_smhd_s
237 {
238     uint8_t  i_version;
239     uint32_t i_flags;
240     
241     int16_t  i_balance;
242     int16_t  i_reserved;
243
244 } MP4_Box_data_smhd_t;
245
246 typedef struct MP4_Box_data_hmhd_s
247 {
248     uint8_t  i_version;
249     uint32_t i_flags;
250        
251     uint16_t i_max_PDU_size;
252     uint16_t i_avg_PDU_size;
253     uint32_t i_max_bitrate;
254     uint32_t i_avg_bitrate;
255     uint32_t i_reserved;
256
257 } MP4_Box_data_hmhd_t;
258
259 typedef struct MP4_Box_data_url_s
260 {
261     uint8_t  i_version;
262     uint32_t i_flags;
263     
264     unsigned char *psz_location;
265     
266 } MP4_Box_data_url_t;
267
268 typedef struct MP4_Box_data_urn_s
269 {
270     uint8_t  i_version;
271     uint32_t i_flags;
272
273     unsigned char *psz_name;
274     unsigned char *psz_location;
275     
276 } MP4_Box_data_urn_t;
277
278 typedef struct MP4_Box_data_dref_s
279 {
280     uint8_t  i_version;
281     uint32_t i_flags;
282
283     uint32_t i_entry_count;
284 /* XXX it's also a container with i_entry_count entry */
285 } MP4_Box_data_dref_t;
286
287 typedef struct MP4_Box_data_stts_s
288 {
289     uint8_t  i_version;
290     uint32_t i_flags;
291
292     uint32_t i_entry_count;
293     uint32_t *i_sample_count; /* these are array */
294     int32_t  *i_sample_delta;
295
296 } MP4_Box_data_stts_t;
297
298 typedef struct MP4_Box_data_ctts_s
299 {
300     uint8_t  i_version;
301     uint32_t i_flags;
302     
303     uint32_t i_entry_count;
304
305     uint32_t *i_sample_count; /* these are array */
306     int32_t  *i_sample_offset;
307
308 } MP4_Box_data_ctts_t;
309
310
311 typedef struct MP4_Box_data_sample_soun_s
312 {
313     uint8_t  i_reserved1[6];
314     uint16_t i_data_reference_index;
315
316     uint32_t i_reserved2[2];
317     uint16_t i_channelcount;
318     uint16_t i_samplesize;
319     uint16_t i_predefined;
320     uint16_t i_reserved3;
321     uint16_t i_sampleratehi; /* timescale of track */
322     uint16_t i_sampleratelo;
323     
324 } MP4_Box_data_sample_soun_t;
325
326 typedef struct MP4_Box_data_sample_vide_s
327 {
328     uint8_t  i_reserved1[6];
329     uint16_t i_data_reference_index;
330
331     uint16_t i_predefined1;
332     uint16_t i_reserved2;
333     uint32_t i_predefined2[3];
334
335     int16_t  i_width;
336     int16_t  i_height;
337
338     uint32_t i_horizresolution;
339     uint32_t i_vertresolution;
340
341     uint32_t i_reserved3;
342     uint16_t i_predefined3;
343     
344     uint8_t  i_compressorname[32];
345     int16_t  i_depth;
346
347     int16_t  i_predefined4;
348     
349 } MP4_Box_data_sample_vide_t;
350
351 typedef struct MP4_Box_data_sample_hint_s
352 {
353     uint8_t  i_reserved1[6];
354     uint16_t i_data_reference_index;
355
356     uint8_t *p_data;
357
358 } MP4_Box_data_sample_hint_t;
359
360 typedef struct MP4_Box_data_moviehintinformation_rtp_s
361 {
362     uint32_t i_description_format;
363     unsigned char *psz_text;
364
365 } MP4_Box_data_moviehintinformation_rtp_t;
366
367
368
369 typedef struct MP4_Box_data_stsd_s
370 {
371     uint8_t  i_version;
372     uint32_t i_flags;
373     
374     uint32_t i_entry_count;
375
376     /* it contains SampleEntry handled as if it was Box */
377     
378 } MP4_Box_data_stsd_t;
379
380
381 typedef struct MP4_Box_data_stsz_s
382 {
383     uint8_t  i_version;
384     uint32_t i_flags;
385
386     uint32_t i_sample_size;
387     uint32_t i_sample_count;
388    
389     uint32_t *i_entry_size; /* array , empty if i_sample_size != 0 */
390
391 } MP4_Box_data_stsz_t;
392
393 typedef struct MP4_Box_data_stz2_s
394 {
395     uint8_t  i_version;
396     uint32_t i_flags;
397
398     uint32_t i_sample_size; /* 24 bits */
399     uint8_t  i_field_size;
400     uint32_t i_sample_count;
401
402     uint32_t *i_entry_size; /* array: unsigned int(i_field_size) entry_size */
403
404 } MP4_Box_data_stz2_t;
405
406 typedef struct MP4_Box_data_stsc_s
407 {
408     uint8_t  i_version;
409     uint32_t i_flags;
410
411     uint32_t i_entry_count;
412
413     uint32_t *i_first_chunk; /* theses are arrays */
414     uint32_t *i_samples_per_chunk;
415     uint32_t *i_sample_description_index;
416     
417 } MP4_Box_data_stsc_t;
418
419
420 typedef struct MP4_Box_data_co64_s
421 {
422     uint8_t  i_version;
423     uint32_t i_flags;
424
425     uint32_t i_entry_count;
426     
427     uint64_t *i_chunk_offset;
428
429 } MP4_Box_data_co64_t;
430
431
432 typedef struct MP4_Box_data_stss_s
433 {
434     uint8_t  i_version;
435     uint32_t i_flags;
436     
437     uint32_t i_entry_count;
438     
439     uint32_t *i_sample_number;
440     
441 } MP4_Box_data_stss_t;
442
443 typedef struct MP4_Box_data_stsh_s
444 {
445     uint8_t  i_version;
446     uint32_t i_flags;
447
448     uint32_t i_entry_count;
449     
450     uint32_t *i_shadowed_sample_number;
451     uint32_t *i_sync_sample_number;
452
453 } MP4_Box_data_stsh_t;
454
455 typedef struct MP4_Box_data_stdp_s
456 {
457     uint8_t  i_version;
458     uint32_t i_flags;
459
460     uint16_t *i_priority;
461
462 } MP4_Box_data_stdp_t;
463
464 typedef struct MP4_Box_data_padb_s
465 {
466     uint8_t  i_version;
467     uint32_t i_flags;
468
469     uint32_t i_sample_count;
470
471     uint16_t *i_reserved1;   /* 1bit  */
472     uint16_t *i_pad2;        /* 3bits */
473     uint16_t *i_reserved2;   /* 1bit  */
474     uint16_t *i_pad1;        /* 3bits */
475     
476
477 } MP4_Box_data_padb_t;
478
479
480 typedef struct MP4_Box_data_elst_s
481 {
482     uint8_t  i_version;
483     uint32_t i_flags;
484
485     uint32_t i_entry_count;
486
487     uint64_t *i_segment_duration;
488     int64_t  *i_media_time;
489     uint16_t *i_media_rate_integer;
490     uint16_t *i_media_rate_fraction;
491
492     
493 } MP4_Box_data_elst_t;
494
495 typedef struct MP4_Box_data_cprt_s
496 {
497     uint8_t  i_version;
498     uint32_t i_flags;
499     /* 1 pad bit */
500     unsigned char i_language[3];
501     
502     unsigned char *psz_notice;
503 } MP4_Box_data_cprt_t;
504
505
506 /* DecoderConfigDescriptor */
507 typedef struct MP4_descriptor_decoder_config_s
508 {
509     uint8_t i_objectTypeIndication;
510     uint8_t i_streamType;
511     int     b_upStream;
512     int     i_buffer_sizeDB;
513     int     i_max_bitrate;
514     int     i_avg_bitrate;
515     
516     int     i_decoder_specific_info_len;
517     uint8_t *p_decoder_specific_info;
518     /* some other stuff */
519     
520 } MP4_descriptor_decoder_config_t;
521
522 typedef struct MP4_descriptor_SL_config_s
523 {
524
525     int i_dummy; /* ANSI C forbids empty structures */
526     
527 } MP4_descriptor_SL_config_t;
528
529
530 typedef struct MP4_descriptor_ES_s
531 {
532     uint16_t i_ES_ID;
533     int      b_stream_dependence;
534     int      b_url;
535     int      b_OCRstream;
536     int      i_stream_priority;
537
538     int      i_depend_on_ES_ID; /* if b_stream_dependence set */
539
540     unsigned char *psz_URL;
541
542     uint16_t i_OCR_ES_ID;       /* if b_OCRstream */
543     MP4_descriptor_decoder_config_t *p_decConfigDescr;
544     
545     MP4_descriptor_SL_config_t *p_slConfigDescr;
546
547     /* some other stuff ... */
548
549 } MP4_descriptor_ES_t;
550
551 /* ES descriptor */
552 typedef struct MP4_Box_data_esds_s
553 {
554     uint8_t  i_version;
555     uint32_t i_flags;
556     
557     MP4_descriptor_ES_t es_descriptor;
558     
559 } MP4_Box_data_esds_t;
560
561
562 typedef struct MP4_Box_data_dcom_s
563 {
564     uint32_t i_algorithm; /* fourcc */
565     
566 } MP4_Box_data_dcom_t;
567
568 typedef struct MP4_Box_data_cmvd_s
569 {
570     uint32_t i_uncompressed_size;
571     uint32_t i_compressed_size;
572
573     int     b_compressed; /* Set to 1 if compressed data, 0 if uncompressed */
574     uint8_t *p_data;
575
576 } MP4_Box_data_cmvd_t;
577
578 typedef struct MP4_Box_data_cmov_s
579 {
580     struct MP4_Box_s *p_moov; /* uncompressed moov */
581     
582 } MP4_Box_data_cmov_t;
583
584 /*
585 typedef struct MP4_Box_data_cmov_s
586 {
587     uint8_t  i_version;
588     uint32_t i_flags;
589
590 } MP4_Box_data__t;
591
592 */
593
594 typedef union MP4_Box_data_s
595 {
596     MP4_Box_data_ftyp_t *p_ftyp;
597     MP4_Box_data_mvhd_t *p_mvhd;
598     MP4_Box_data_tkhd_t *p_tkhd;
599     MP4_Box_data_mdhd_t *p_mdhd;
600     MP4_Box_data_hdlr_t *p_hdlr;
601     MP4_Box_data_vmhd_t *p_vmhd;
602     MP4_Box_data_smhd_t *p_smhd;
603     MP4_Box_data_hmhd_t *p_hmhd;
604     MP4_Box_data_url_t  *p_url;
605     MP4_Box_data_urn_t  *p_urn;
606     MP4_Box_data_dref_t *p_dref;
607     MP4_Box_data_stts_t *p_stts;
608     MP4_Box_data_ctts_t *p_ctts;
609     MP4_Box_data_stsd_t *p_stsd;
610         MP4_Box_data_sample_vide_t *p_sample_vide;
611         MP4_Box_data_sample_soun_t *p_sample_soun;
612         MP4_Box_data_sample_hint_t *p_sample_hint;
613
614         MP4_Box_data_esds_t *p_esds;
615
616     MP4_Box_data_stsz_t *p_stsz;
617     MP4_Box_data_stz2_t *p_stz2;
618     MP4_Box_data_stsc_t *p_stsc;
619     MP4_Box_data_co64_t *p_co64;
620     MP4_Box_data_stss_t *p_stss;
621     MP4_Box_data_stsh_t *p_stsh;
622     MP4_Box_data_stdp_t *p_stdp;
623     MP4_Box_data_padb_t *p_padb;
624     MP4_Box_data_elst_t *p_elst;
625     MP4_Box_data_cprt_t *p_cprt;
626
627     MP4_Box_data_dcom_t *p_dcom;
628     MP4_Box_data_cmvd_t *p_cmvd;
629     MP4_Box_data_cmov_t *p_cmov;
630
631     MP4_Box_data_moviehintinformation_rtp_t p_moviehintinformation_rtp;
632     
633     void                *p_data; /* for unknow type */
634 } MP4_Box_data_t;
635
636
637
638 /* the most basic structure */
639 typedef struct MP4_Box_s
640 {
641     off_t        i_pos;      /* absolute position */
642     
643     uint32_t     i_type;
644     uint32_t     i_shortsize;
645
646     UUID_t       i_uuid;  /* Set if i_type == "uuid" */
647     
648     uint64_t     i_size; /* always set so use it */
649
650     MP4_Box_data_t   data;   /* union of pointers on extended data depending    
651                                 on i_type (or i_usertype) */
652
653     struct MP4_Box_s *p_father; /* pointer on the father Box */
654
655     struct MP4_Box_s *p_first;  /* pointer on the first child Box */
656     struct MP4_Box_s *p_last;
657
658     struct MP4_Box_s *p_next;   /* pointer on the next boxes at the same level */
659
660 } MP4_Box_t;
661
662 /*---------------------------------------------------------------------------*/
663 /*                                                                           */
664 /****----------------------- High level functions ------------------------****/
665 /*                                                                           */
666 /*---------------------------------------------------------------------------*/
667
668 /*****************************************************************************
669  * Function for manipulate stream easily
670  *****************************************************************************/
671
672 off_t MP4_TellAbsolute( input_thread_t *p_input );
673 int   MP4_SeekAbsolute( input_thread_t *p_input, off_t i_pos);
674 int   MP4_ReadData( input_thread_t *p_input, uint8_t *p_buff, int i_size );
675
676 /*****************************************************************************
677  * MP4_BoxGetRoot : Parse the entire file, and create all boxes in memory
678  *****************************************************************************
679  *  The first box is a virtual box "root" and is the father for all first 
680  *  level boxes 
681  *
682  *  RETURN : 1 if succes and 0 if it failed
683  *****************************************************************************/
684 int MP4_BoxGetRoot( input_thread_t *p_input, MP4_Box_t *p_root );
685
686 /*****************************************************************************
687  * MP4_FreeBox : free memory allocated after read with MP4_ReadBox
688  *               or MP4_BoxGetRoot, this means also children boxes
689  * XXX : all children have to be allocated by a malloc !! and 
690  *         p_box isn't freeing  
691  *****************************************************************************/
692 void MP4_BoxFree( input_thread_t *p_input, MP4_Box_t *p_box );
693
694 /*****************************************************************************
695  * MP4_DumpBoxStructure: print the structure of the p_box
696  *****************************************************************************
697  * Usefull while debugging
698  *****************************************************************************/
699 void MP4_BoxDumpStructure( input_thread_t *p_input, MP4_Box_t *p_box );
700
701
702 /*****************************************************************************
703  * MP4_BoxGet: find a box given a path relative to p_box
704  *****************************************************************************
705  * Path Format: . .. / as usual
706  *              [number] to specifie box number ex: trak[12]
707  *              
708  * ex: /moov/trak[12]
709  *     ../mdia 
710  *****************************************************************************/
711 MP4_Box_t *MP4_BoxGet( MP4_Box_t *p_box, char *psz_fmt, ... );
712     
713 /*****************************************************************************
714  * MP4_BoxCount: find number of box given a path relative to p_box
715  *****************************************************************************
716  * Path Format: . .. / as usual
717  *              [number] to specifie box number ex: trak[12]
718  *              
719  * ex: /moov/trak
720  *     ../mdia 
721  *****************************************************************************/
722 int MP4_BoxCount( MP4_Box_t *p_box, char *psz_fmt, ... );
723
724
725
726 /*---------------------------------------------------------------------------*/
727 /*                                                                           */
728 /****---------------------- Medium level functions -----------------------****/
729 /*                                                                           */
730 /*---------------------------------------------------------------------------*/
731
732 #if 0
733 /*****************************************************************************
734  * MP4_CountBox: given a box, count how many child have the requested type 
735  * FIXME : support GUUID 
736  *****************************************************************************/
737 int MP4_CountBox( MP4_Box_t *p_box, uint32_t i_type );
738 #endif
739
740 /*****************************************************************************
741  * MP4_FindBox:  find first box with i_type child of p_box
742  *      return NULL if not found
743  *****************************************************************************/
744 MP4_Box_t *MP4_FindBox( MP4_Box_t *p_box, uint32_t i_type );
745
746 #if 0
747 /*****************************************************************************
748  * MP4_FindNextBox:  find next box with thesame type and at the same level 
749  *                  than p_box
750  *****************************************************************************/
751 MP4_Box_t *MP4_FindNextBox( MP4_Box_t *p_box );
752
753 /*****************************************************************************
754  * MP4_FindNbBox:  find the box i_number 
755  *****************************************************************************/
756 MP4_Box_t *MP4_FindNbBox( MP4_Box_t *p_box, uint32_t i_number );
757 #endif
758
759 /*---------------------------------------------------------------------------*/
760 /****----------------------- Lower level functions -----------------------****/
761 /****                                                                     ****/
762 /****------Use them only when you known what they really do and need------****/
763 /****                                                                     ****/
764 /****---------------------------------------------------------------------****/
765 /*---------------------------------------------------------------------------*/
766
767
768 /****  ------- First some function to make abstract from input --------  */
769
770 /****************************************************************************
771  * MP4_InputStream create an stram with an input
772  *
773  ****************************************************************************/
774 MP4_Stream_t *MP4_InputStream( input_thread_t *p_input );
775
776 /****************************************************************************
777  * MP4_MemoryStream create a memory stream
778  * if p_buffer == NULL, will allocate a buffer of i_size, else 
779  *     it uses p_buffer XXX you have to unallocate yourself !
780  *
781  ****************************************************************************/
782 MP4_Stream_t *MP4_MemoryStream( input_thread_t *p_input,
783                                 int i_size, uint8_t *p_buffer );
784
785 /****************************************************************************
786  * MP4_ReadStream read from a MP4_Stream_t
787  *
788  ****************************************************************************/
789 int MP4_ReadStream( MP4_Stream_t *p_stream, uint8_t *p_buff, int i_size );
790
791 /****************************************************************************
792  * MP4_PeekStream guess it ;)
793  *
794  ****************************************************************************/
795 int MP4_PeekStream( MP4_Stream_t *p_stream, uint8_t **pp_peek, int i_size );
796     
797 /****************************************************************************
798  * MP4_TellStream give absolute position in the stream
799  * XXX for a memory stream give position from begining of the buffer
800  ****************************************************************************/
801 off_t MP4_TellStream( MP4_Stream_t *p_stream );
802
803 /****************************************************************************
804  * MP4_SeekStream seek in a MP4_Stream_t
805  *
806  ****************************************************************************/
807 int MP4_SeekStream( MP4_Stream_t *p_stream, off_t i_pos);
808
809
810
811 /*****************************************************************************
812  * MP4_ReadBox : parse the actual box and the children if they exist
813  *  
814  *  RETURN : 1 if succes and 0 if it failed
815  *****************************************************************************/
816 int MP4_ReadBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box, MP4_Box_t *p_father );
817
818
819 /*****************************************************************************
820  * MP4_ReadBoxCommon : Load only common parameters for all boxes 
821  *****************************************************************************
822  * p_box need to be an already allocated MP4_Box_t, and all data 
823  *  will only be peek not read
824  *
825  * RETURN : 0 if it fail, 1 otherwise
826  *****************************************************************************/
827 int MP4_ReadBoxCommon( MP4_Stream_t *p_stream, MP4_Box_t *p_box );
828
829
830 /*****************************************************************************
831  * MP4_MP4_GotoBox : Go to this particular box 
832  *****************************************************************************
833  * RETURN : 0 if it fail, 1 otherwise
834  *****************************************************************************/
835 int MP4_GotoBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box );
836
837     
838 /*****************************************************************************
839  * MP4_MP4_NextBox : Go to the next box wiithin p_box->p_father 
840  *****************************************************************************
841  * if p_box == NULL, go to the next box in witch we are( at the begining ).
842  *****************************************************************************/
843 int MP4_NextBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box );
844
845