1 /*****************************************************************************
2 * libmp4.h : LibMP4 library for mp4 module for vlc
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: libmp4.h,v 1.13 2003/05/10 11:05:52 hartman Exp $
6 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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.
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.
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 *****************************************************************************/
23 #define FOURCC_uuid VLC_FOURCC( 'u', 'u', 'i', 'd' )
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' )
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' )
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' )
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' )
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', ' ' )
93 #define FOURCC_isom VLC_FOURCC( 'i', 's', 'o', 'm' )
94 #define FOURCC_esds VLC_FOURCC( 'e', 's', 'd', 's' )
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' )
114 #define FOURCC_zlib VLC_FOURCC( 'z', 'l', 'i', 'b' )
115 #define FOURCC_SVQ1 VLC_FOURCC( 'S', 'V', 'Q', '1' )
116 #define FOURCC_SVQ3 VLC_FOURCC( 'S', 'V', 'Q', '3' )
117 #define FOURCC_ZyGo VLC_FOURCC( 'Z', 'y', 'G', 'o' )
118 #define FOURCC_3IV1 VLC_FOURCC( '3', 'I', 'V', '1' )
119 #define FOURCC_3iv1 VLC_FOURCC( '3', 'i', 'v', '1' )
120 #define FOURCC_3IV2 VLC_FOURCC( '3', 'I', 'V', '2' )
121 #define FOURCC_3iv2 VLC_FOURCC( '3', 'i', 'v', '2' )
122 #define FOURCC_3IVD VLC_FOURCC( '3', 'I', 'V', 'D' )
123 #define FOURCC_3ivd VLC_FOURCC( '3', 'i', 'v', 'd' )
124 #define FOURCC_3VID VLC_FOURCC( '3', 'V', 'I', 'D' )
125 #define FOURCC_3vid VLC_FOURCC( '3', 'v', 'i', 'd' )
126 #define FOURCC_h263 VLC_FOURCC( 'h', '2', '6', '3' )
127 #define FOURCC_s263 VLC_FOURCC( 's', '2', '6', '3' )
128 #define FOURCC_DIVX VLC_FOURCC( 'D', 'I', 'V', 'X' )
129 #define FOURCC_cvid VLC_FOURCC( 'c', 'v', 'i', 'd' )
130 #define FOURCC_mjpa VLC_FOURCC( 'm', 'j', 'p', 'a' )
131 #define FOURCC_mjpb VLC_FOURCC( 'm', 'j', 'q', 't' )
132 #define FOURCC_mjqt VLC_FOURCC( 'm', 'j', 'h', 't' )
133 #define FOURCC_mjht VLC_FOURCC( 'm', 'j', 'p', 'b' )
134 #define FOURCC_VP31 VLC_FOURCC( 'V', 'P', '3', '1' )
135 #define FOURCC_vp31 VLC_FOURCC( 'v', 'p', '3', '1' )
137 #define FOURCC_dvc VLC_FOURCC( 'd', 'v', 'c', ' ' )
138 #define FOURCC_dvp VLC_FOURCC( 'd', 'v', 'p', ' ' )
139 #define FOURCC_raw VLC_FOURCC( 'r', 'a', 'w', ' ' )
141 #define FOURCC_jpeg VLC_FOURCC( 'j', 'p', 'e', 'g' )
144 #define FOURCC_rmra VLC_FOURCC( 'r', 'm', 'r', 'a' )
145 #define FOURCC_rmda VLC_FOURCC( 'r', 'm', 'd', 'a' )
146 #define FOURCC_rdrf VLC_FOURCC( 'r', 'd', 'r', 'f' )
147 #define FOURCC_rmdr VLC_FOURCC( 'r', 'm', 'd', 'r' )
148 #define FOURCC_rmvc VLC_FOURCC( 'r', 'm', 'v', 'c' )
149 #define FOURCC_rmcd VLC_FOURCC( 'r', 'm', 'c', 'd' )
150 #define FOURCC_rmqu VLC_FOURCC( 'r', 'm', 'q', 'u' )
151 #define FOURCC_alis VLC_FOURCC( 'a', 'l', 'i', 's' )
153 /* Do you want some debug information on all read boxes ? */
154 #define MP4_VERBOSE 1
156 /* memory stream and file stream object */
158 typedef struct MP4_Stream_s
160 int b_memory; /* do we uses a memory buffer */
162 input_thread_t *p_input;
164 off_t i_start; /* in the buffer position for memory stream */
173 /* uuid Universal Unique IDentifiers */
174 typedef struct UUID_s
179 /* specific structure for all boxes */
181 typedef struct MP4_Box_data_ftyp_s
183 uint32_t i_major_brand;
184 uint32_t i_minor_version;
186 uint32_t i_compatible_brands_count;
187 uint32_t *i_compatible_brands;
189 } MP4_Box_data_ftyp_t;
191 typedef struct MP4_Box_data_mvhd_s
196 uint64_t i_creation_time;
197 uint64_t i_modification_time;
198 uint32_t i_timescale;
204 uint32_t i_reserved2[2];
206 uint32_t i_predefined[6];
207 uint32_t i_next_track_id;
209 } MP4_Box_data_mvhd_t;
211 #define MP4_TRACK_ENABLED 0x000001
212 #define MP4_TRACK_IN_MOVIE 0x000002
213 #define MP4_TRACK_IN_PREVIEW 0x000004
214 typedef struct MP4_Box_data_tkhd_s
219 uint64_t i_creation_time;
220 uint64_t i_modification_time;
225 uint32_t i_reserved2[2];
227 int16_t i_predefined;
230 uint16_t i_reserved3;
235 } MP4_Box_data_tkhd_t;
237 typedef struct MP4_Box_data_mdhd_s
242 uint64_t i_creation_time;
243 uint64_t i_modification_time;
244 uint32_t i_timescale;
247 /* one bit for pad */
248 /* unsigned int(5)[3] language difference with 0x60*/
249 unsigned char i_language[3];
250 uint16_t i_predefined;
252 } MP4_Box_data_mdhd_t;
254 typedef struct MP4_Box_data_hdlr_s
259 uint32_t i_predefined;
260 uint32_t i_handler_type; /* "vide" "soun" "hint" "odsm"
261 "crsm" "sdsm" "m7sm" "ocsm"
264 unsigned char *psz_name; /* in UTF-8 */
266 } MP4_Box_data_hdlr_t;
268 typedef struct MP4_Box_data_vmhd_s
273 int16_t i_graphics_mode;
274 int16_t i_opcolor[3];
276 } MP4_Box_data_vmhd_t;
278 typedef struct MP4_Box_data_smhd_s
286 } MP4_Box_data_smhd_t;
288 typedef struct MP4_Box_data_hmhd_s
293 uint16_t i_max_PDU_size;
294 uint16_t i_avg_PDU_size;
295 uint32_t i_max_bitrate;
296 uint32_t i_avg_bitrate;
299 } MP4_Box_data_hmhd_t;
301 typedef struct MP4_Box_data_url_s
306 unsigned char *psz_location;
308 } MP4_Box_data_url_t;
310 typedef struct MP4_Box_data_urn_s
315 unsigned char *psz_name;
316 unsigned char *psz_location;
318 } MP4_Box_data_urn_t;
320 typedef struct MP4_Box_data_dref_s
325 uint32_t i_entry_count;
326 /* XXX it's also a container with i_entry_count entry */
327 } MP4_Box_data_dref_t;
329 typedef struct MP4_Box_data_stts_s
334 uint32_t i_entry_count;
335 uint32_t *i_sample_count; /* these are array */
336 int32_t *i_sample_delta;
338 } MP4_Box_data_stts_t;
340 typedef struct MP4_Box_data_ctts_s
345 uint32_t i_entry_count;
347 uint32_t *i_sample_count; /* these are array */
348 int32_t *i_sample_offset;
350 } MP4_Box_data_ctts_t;
353 typedef struct MP4_Box_data_sample_soun_s
355 uint8_t i_reserved1[6];
356 uint16_t i_data_reference_index;
358 //uint32_t i_reserved2[2];
359 uint16_t i_qt_version;
360 uint16_t i_qt_revision_level;
361 uint32_t i_qt_vendor;
363 uint16_t i_channelcount;
364 uint16_t i_samplesize;
365 uint16_t i_predefined;
366 uint16_t i_reserved3;
367 uint16_t i_sampleratehi; /* timescale of track */
368 uint16_t i_sampleratelo;
370 /* for version 1 (i_reserved1[0] == 1) */
371 uint32_t i_sample_per_packet;
372 uint32_t i_bytes_per_packet;
373 uint32_t i_bytes_per_frame;
374 uint32_t i_bytes_per_sample;
377 int i_qt_description;
378 uint8_t *p_qt_description;
380 } MP4_Box_data_sample_soun_t;
382 typedef struct MP4_Box_data_sample_vide_s
384 uint8_t i_reserved1[6];
385 uint16_t i_data_reference_index;
387 uint16_t i_qt_version;
388 uint16_t i_qt_revision_level;
389 uint32_t i_qt_vendor;
391 uint32_t i_qt_temporal_quality;
392 uint32_t i_qt_spatial_quality;
397 uint32_t i_horizresolution;
398 uint32_t i_vertresolution;
400 uint32_t i_qt_data_size;
401 uint16_t i_qt_frame_count;
403 uint8_t i_compressorname[32];
406 int16_t i_qt_color_table;
408 /* XXX hack ImageDescription */
409 int i_qt_image_description;
410 uint8_t *p_qt_image_description;
412 } MP4_Box_data_sample_vide_t;
414 typedef struct MP4_Box_data_sample_hint_s
416 uint8_t i_reserved1[6];
417 uint16_t i_data_reference_index;
421 } MP4_Box_data_sample_hint_t;
423 typedef struct MP4_Box_data_moviehintinformation_rtp_s
425 uint32_t i_description_format;
426 unsigned char *psz_text;
428 } MP4_Box_data_moviehintinformation_rtp_t;
432 typedef struct MP4_Box_data_stsd_s
437 uint32_t i_entry_count;
439 /* it contains SampleEntry handled as if it was Box */
441 } MP4_Box_data_stsd_t;
444 typedef struct MP4_Box_data_stsz_s
449 uint32_t i_sample_size;
450 uint32_t i_sample_count;
452 uint32_t *i_entry_size; /* array , empty if i_sample_size != 0 */
454 } MP4_Box_data_stsz_t;
456 typedef struct MP4_Box_data_stz2_s
461 uint32_t i_sample_size; /* 24 bits */
462 uint8_t i_field_size;
463 uint32_t i_sample_count;
465 uint32_t *i_entry_size; /* array: unsigned int(i_field_size) entry_size */
467 } MP4_Box_data_stz2_t;
469 typedef struct MP4_Box_data_stsc_s
474 uint32_t i_entry_count;
476 uint32_t *i_first_chunk; /* theses are arrays */
477 uint32_t *i_samples_per_chunk;
478 uint32_t *i_sample_description_index;
480 } MP4_Box_data_stsc_t;
483 typedef struct MP4_Box_data_co64_s
488 uint32_t i_entry_count;
490 uint64_t *i_chunk_offset;
492 } MP4_Box_data_co64_t;
495 typedef struct MP4_Box_data_stss_s
500 uint32_t i_entry_count;
502 uint32_t *i_sample_number;
504 } MP4_Box_data_stss_t;
506 typedef struct MP4_Box_data_stsh_s
511 uint32_t i_entry_count;
513 uint32_t *i_shadowed_sample_number;
514 uint32_t *i_sync_sample_number;
516 } MP4_Box_data_stsh_t;
518 typedef struct MP4_Box_data_stdp_s
523 uint16_t *i_priority;
525 } MP4_Box_data_stdp_t;
527 typedef struct MP4_Box_data_padb_s
532 uint32_t i_sample_count;
534 uint16_t *i_reserved1; /* 1bit */
535 uint16_t *i_pad2; /* 3bits */
536 uint16_t *i_reserved2; /* 1bit */
537 uint16_t *i_pad1; /* 3bits */
540 } MP4_Box_data_padb_t;
543 typedef struct MP4_Box_data_elst_s
548 uint32_t i_entry_count;
550 uint64_t *i_segment_duration;
551 int64_t *i_media_time;
552 uint16_t *i_media_rate_integer;
553 uint16_t *i_media_rate_fraction;
556 } MP4_Box_data_elst_t;
558 typedef struct MP4_Box_data_cprt_s
563 unsigned char i_language[3];
565 unsigned char *psz_notice;
566 } MP4_Box_data_cprt_t;
569 /* DecoderConfigDescriptor */
570 typedef struct MP4_descriptor_decoder_config_s
572 uint8_t i_objectTypeIndication;
573 uint8_t i_streamType;
579 int i_decoder_specific_info_len;
580 uint8_t *p_decoder_specific_info;
581 /* some other stuff */
583 } MP4_descriptor_decoder_config_t;
585 typedef struct MP4_descriptor_SL_config_s
588 int i_dummy; /* ANSI C forbids empty structures */
590 } MP4_descriptor_SL_config_t;
593 typedef struct MP4_descriptor_ES_s
596 int b_stream_dependence;
599 int i_stream_priority;
601 int i_depend_on_ES_ID; /* if b_stream_dependence set */
603 unsigned char *psz_URL;
605 uint16_t i_OCR_ES_ID; /* if b_OCRstream */
606 MP4_descriptor_decoder_config_t *p_decConfigDescr;
608 MP4_descriptor_SL_config_t *p_slConfigDescr;
610 /* some other stuff ... */
612 } MP4_descriptor_ES_t;
615 typedef struct MP4_Box_data_esds_s
620 MP4_descriptor_ES_t es_descriptor;
622 } MP4_Box_data_esds_t;
625 typedef struct MP4_Box_data_dcom_s
627 uint32_t i_algorithm; /* fourcc */
629 } MP4_Box_data_dcom_t;
631 typedef struct MP4_Box_data_cmvd_s
633 uint32_t i_uncompressed_size;
634 uint32_t i_compressed_size;
636 int b_compressed; /* Set to 1 if compressed data, 0 if uncompressed */
639 } MP4_Box_data_cmvd_t;
641 typedef struct MP4_Box_data_cmov_s
643 struct MP4_Box_s *p_moov; /* uncompressed moov */
645 } MP4_Box_data_cmov_t;
647 typedef struct MP4_Box_data_rdrf_s
655 } MP4_Box_data_rdrf_t;
657 typedef struct MP4_Box_data_rmdr_s
664 } MP4_Box_data_rmdr_t;
666 typedef struct MP4_Box_data_rmvc_s
671 uint32_t i_gestaltType;
674 uint16_t i_checkType; /* 0: val1 is version min
675 1: gestalt value & val2 == val1 */
677 } MP4_Box_data_rmvc_t;
679 typedef struct MP4_Box_data_rmcd_s
685 } MP4_Box_data_rmcd_t;
687 typedef struct MP4_Box_data_rmqu_s
691 } MP4_Box_data_rmqu_t;
694 typedef struct MP4_Box_data__s
703 typedef union MP4_Box_data_s
705 MP4_Box_data_ftyp_t *p_ftyp;
706 MP4_Box_data_mvhd_t *p_mvhd;
707 MP4_Box_data_tkhd_t *p_tkhd;
708 MP4_Box_data_mdhd_t *p_mdhd;
709 MP4_Box_data_hdlr_t *p_hdlr;
710 MP4_Box_data_vmhd_t *p_vmhd;
711 MP4_Box_data_smhd_t *p_smhd;
712 MP4_Box_data_hmhd_t *p_hmhd;
713 MP4_Box_data_url_t *p_url;
714 MP4_Box_data_urn_t *p_urn;
715 MP4_Box_data_dref_t *p_dref;
716 MP4_Box_data_stts_t *p_stts;
717 MP4_Box_data_ctts_t *p_ctts;
718 MP4_Box_data_stsd_t *p_stsd;
719 MP4_Box_data_sample_vide_t *p_sample_vide;
720 MP4_Box_data_sample_soun_t *p_sample_soun;
721 MP4_Box_data_sample_hint_t *p_sample_hint;
723 MP4_Box_data_esds_t *p_esds;
725 MP4_Box_data_stsz_t *p_stsz;
726 MP4_Box_data_stz2_t *p_stz2;
727 MP4_Box_data_stsc_t *p_stsc;
728 MP4_Box_data_co64_t *p_co64;
729 MP4_Box_data_stss_t *p_stss;
730 MP4_Box_data_stsh_t *p_stsh;
731 MP4_Box_data_stdp_t *p_stdp;
732 MP4_Box_data_padb_t *p_padb;
733 MP4_Box_data_elst_t *p_elst;
734 MP4_Box_data_cprt_t *p_cprt;
736 MP4_Box_data_dcom_t *p_dcom;
737 MP4_Box_data_cmvd_t *p_cmvd;
738 MP4_Box_data_cmov_t *p_cmov;
740 MP4_Box_data_moviehintinformation_rtp_t p_moviehintinformation_rtp;
742 MP4_Box_data_rdrf_t *p_rdrf;
743 MP4_Box_data_rmdr_t *p_rmdr;
744 MP4_Box_data_rmqu_t *p_rmqu;
745 MP4_Box_data_rmvc_t *p_rmvc;
747 void *p_data; /* for unknow type */
752 /* the most basic structure */
753 typedef struct MP4_Box_s
755 off_t i_pos; /* absolute position */
758 uint32_t i_shortsize;
760 UUID_t i_uuid; /* Set if i_type == "uuid" */
762 uint64_t i_size; /* always set so use it */
764 MP4_Box_data_t data; /* union of pointers on extended data depending
765 on i_type (or i_usertype) */
767 struct MP4_Box_s *p_father; /* pointer on the father Box */
769 struct MP4_Box_s *p_first; /* pointer on the first child Box */
770 struct MP4_Box_s *p_last;
772 struct MP4_Box_s *p_next; /* pointer on the next boxes at the same level */
776 /*---------------------------------------------------------------------------*/
778 /****----------------------- High level functions ------------------------****/
780 /*---------------------------------------------------------------------------*/
782 /*****************************************************************************
783 * Function for manipulate stream easily
784 *****************************************************************************/
786 off_t MP4_TellAbsolute( input_thread_t *p_input );
787 int MP4_SeekAbsolute( input_thread_t *p_input, off_t i_pos);
788 int MP4_ReadData( input_thread_t *p_input, uint8_t *p_buff, int i_size );
790 /*****************************************************************************
791 * MP4_BoxGetRoot : Parse the entire file, and create all boxes in memory
792 *****************************************************************************
793 * The first box is a virtual box "root" and is the father for all first
796 * RETURN : 1 if succes and 0 if it failed
797 *****************************************************************************/
798 int MP4_BoxGetRoot( input_thread_t *p_input, MP4_Box_t *p_root );
800 /*****************************************************************************
801 * MP4_FreeBox : free memory allocated after read with MP4_ReadBox
802 * or MP4_BoxGetRoot, this means also children boxes
803 * XXX : all children have to be allocated by a malloc !! and
804 * p_box isn't freeing
805 *****************************************************************************/
806 void MP4_BoxFree( input_thread_t *p_input, MP4_Box_t *p_box );
808 /*****************************************************************************
809 * MP4_DumpBoxStructure: print the structure of the p_box
810 *****************************************************************************
811 * Usefull while debugging
812 *****************************************************************************/
813 void MP4_BoxDumpStructure( input_thread_t *p_input, MP4_Box_t *p_box );
816 /*****************************************************************************
817 * MP4_BoxGet: find a box given a path relative to p_box
818 *****************************************************************************
819 * Path Format: . .. / as usual
820 * [number] to specifie box number ex: trak[12]
824 *****************************************************************************/
825 MP4_Box_t *MP4_BoxGet( MP4_Box_t *p_box, char *psz_fmt, ... );
827 /*****************************************************************************
828 * MP4_BoxCount: find number of box given a path relative to p_box
829 *****************************************************************************
830 * Path Format: . .. / as usual
831 * [number] to specifie box number ex: trak[12]
835 *****************************************************************************/
836 int MP4_BoxCount( MP4_Box_t *p_box, char *psz_fmt, ... );
840 /*---------------------------------------------------------------------------*/
842 /****---------------------- Medium level functions -----------------------****/
844 /*---------------------------------------------------------------------------*/
847 /*****************************************************************************
848 * MP4_CountBox: given a box, count how many child have the requested type
849 * FIXME : support GUUID
850 *****************************************************************************/
851 int MP4_CountBox( MP4_Box_t *p_box, uint32_t i_type );
854 /*****************************************************************************
855 * MP4_FindBox: find first box with i_type child of p_box
856 * return NULL if not found
857 *****************************************************************************/
858 MP4_Box_t *MP4_FindBox( MP4_Box_t *p_box, uint32_t i_type );
861 /*****************************************************************************
862 * MP4_FindNextBox: find next box with thesame type and at the same level
864 *****************************************************************************/
865 MP4_Box_t *MP4_FindNextBox( MP4_Box_t *p_box );
867 /*****************************************************************************
868 * MP4_FindNbBox: find the box i_number
869 *****************************************************************************/
870 MP4_Box_t *MP4_FindNbBox( MP4_Box_t *p_box, uint32_t i_number );
873 /*---------------------------------------------------------------------------*/
874 /****----------------------- Lower level functions -----------------------****/
876 /****------Use them only when you known what they really do and need------****/
878 /****---------------------------------------------------------------------****/
879 /*---------------------------------------------------------------------------*/
882 /**** ------- First some function to make abstract from input -------- */
884 /****************************************************************************
885 * MP4_InputStream create an stram with an input
887 ****************************************************************************/
888 MP4_Stream_t *MP4_InputStream( input_thread_t *p_input );
890 /****************************************************************************
891 * MP4_MemoryStream create a memory stream
892 * if p_buffer == NULL, will allocate a buffer of i_size, else
893 * it uses p_buffer XXX you have to unallocate yourself !
895 ****************************************************************************/
896 MP4_Stream_t *MP4_MemoryStream( input_thread_t *p_input,
897 int i_size, uint8_t *p_buffer );
899 /****************************************************************************
900 * MP4_ReadStream read from a MP4_Stream_t
902 ****************************************************************************/
903 int MP4_ReadStream( MP4_Stream_t *p_stream, uint8_t *p_buff, int i_size );
905 /****************************************************************************
906 * MP4_PeekStream guess it ;)
908 ****************************************************************************/
909 int MP4_PeekStream( MP4_Stream_t *p_stream, uint8_t **pp_peek, int i_size );
911 /****************************************************************************
912 * MP4_TellStream give absolute position in the stream
913 * XXX for a memory stream give position from begining of the buffer
914 ****************************************************************************/
915 off_t MP4_TellStream( MP4_Stream_t *p_stream );
917 /****************************************************************************
918 * MP4_SeekStream seek in a MP4_Stream_t
920 ****************************************************************************/
921 int MP4_SeekStream( MP4_Stream_t *p_stream, off_t i_pos);
925 /*****************************************************************************
926 * MP4_ReadBox : parse the actual box and the children if they exist
928 * RETURN : 1 if succes and 0 if it failed
929 *****************************************************************************/
930 int MP4_ReadBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box, MP4_Box_t *p_father );
933 /*****************************************************************************
934 * MP4_ReadBoxCommon : Load only common parameters for all boxes
935 *****************************************************************************
936 * p_box need to be an already allocated MP4_Box_t, and all data
937 * will only be peek not read
939 * RETURN : 0 if it fail, 1 otherwise
940 *****************************************************************************/
941 int MP4_ReadBoxCommon( MP4_Stream_t *p_stream, MP4_Box_t *p_box );
944 /*****************************************************************************
945 * MP4_MP4_GotoBox : Go to this particular box
946 *****************************************************************************
947 * RETURN : 0 if it fail, 1 otherwise
948 *****************************************************************************/
949 int MP4_GotoBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box );
952 /*****************************************************************************
953 * MP4_MP4_NextBox : Go to the next box wiithin p_box->p_father
954 *****************************************************************************
955 * if p_box == NULL, go to the next box in witch we are( at the begining ).
956 *****************************************************************************/
957 int MP4_NextBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box );