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