]> git.sesse.net Git - vlc/blob - modules/demux/mp4/libmp4.h
* modules/demux/mp4/*: bug fix for MP4_TrackNextSample() + added fourcc for amr-wb.
[vlc] / modules / demux / mp4 / libmp4.h
1 /*****************************************************************************
2  * libmp4.h : LibMP4 library for mp4 module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001-2004 VideoLAN
5  * $Id$
6  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 #define FOURCC_uuid VLC_FOURCC( 'u', 'u', 'i', 'd' )
24
25 #define FOURCC_ftyp VLC_FOURCC( 'f', 't', 'y', 'p' )
26 #define FOURCC_moov VLC_FOURCC( 'm', 'o', 'o', 'v' )
27 #define FOURCC_foov VLC_FOURCC( 'f', 'o', 'o', 'v' )
28 #define FOURCC_cmov VLC_FOURCC( 'c', 'm', 'o', 'v' )
29 #define FOURCC_dcom VLC_FOURCC( 'd', 'c', 'o', 'm' )
30 #define FOURCC_cmvd VLC_FOURCC( 'c', 'm', 'v', 'd' )
31
32 #define FOURCC_moof VLC_FOURCC( 'm', 'o', 'o', 'f' )
33 #define FOURCC_mdat VLC_FOURCC( 'm', 'd', 'a', 't' )
34 #define FOURCC_skip VLC_FOURCC( 's', 'k', 'i', 'p' )
35 #define FOURCC_free VLC_FOURCC( 'f', 'r', 'e', 'e' )
36 #define FOURCC_udta VLC_FOURCC( 'u', 'd', 't', 'a' )
37 #define FOURCC_wide VLC_FOURCC( 'w', 'i', 'd', 'e' )
38
39 #define FOURCC_trak VLC_FOURCC( 't', 'r', 'a', 'k' )
40 #define FOURCC_mvhd VLC_FOURCC( 'm', 'v', 'h', 'd' )
41 #define FOURCC_tkhd VLC_FOURCC( 't', 'k', 'h', 'd' )
42 #define FOURCC_tref VLC_FOURCC( 't', 'r', 'e', 'f' )
43 #define FOURCC_mdia VLC_FOURCC( 'm', 'd', 'i', 'a' )
44 #define FOURCC_mdhd VLC_FOURCC( 'm', 'd', 'h', 'd' )
45 #define FOURCC_hdlr VLC_FOURCC( 'h', 'd', 'l', 'r' )
46 #define FOURCC_minf VLC_FOURCC( 'm', 'i', 'n', 'f' )
47 #define FOURCC_vmhd VLC_FOURCC( 'v', 'm', 'h', 'd' )
48 #define FOURCC_smhd VLC_FOURCC( 's', 'm', 'h', 'd' )
49 #define FOURCC_hmhd VLC_FOURCC( 'h', 'm', 'h', 'd' )
50 #define FOURCC_dinf VLC_FOURCC( 'd', 'i', 'n', 'f' )
51 #define FOURCC_url  VLC_FOURCC( 'u', 'r', 'l', ' ' )
52 #define FOURCC_urn  VLC_FOURCC( 'u', 'r', 'n', ' ' )
53 #define FOURCC_dref VLC_FOURCC( 'd', 'r', 'e', 'f' )
54 #define FOURCC_stbl VLC_FOURCC( 's', 't', 'b', 'l' )
55 #define FOURCC_stts VLC_FOURCC( 's', 't', 't', 's' )
56 #define FOURCC_ctts VLC_FOURCC( 'c', 't', 't', 's' )
57 #define FOURCC_stsd VLC_FOURCC( 's', 't', 's', 'd' )
58 #define FOURCC_stsz VLC_FOURCC( 's', 't', 's', 'z' )
59 #define FOURCC_stz2 VLC_FOURCC( 's', 't', 'z', '2' )
60 #define FOURCC_stsc VLC_FOURCC( 's', 't', 's', 'c' )
61 #define FOURCC_stco VLC_FOURCC( 's', 't', 'c', 'o' )
62 #define FOURCC_co64 VLC_FOURCC( 'c', 'o', '6', '4' )
63 #define FOURCC_stss VLC_FOURCC( 's', 't', 's', 's' )
64 #define FOURCC_stsh VLC_FOURCC( 's', 't', 's', 'h' )
65 #define FOURCC_stdp VLC_FOURCC( 's', 't', 'd', 'p' )
66 #define FOURCC_padb VLC_FOURCC( 'p', 'a', 'd', 'b' )
67 #define FOURCC_edts VLC_FOURCC( 'e', 'd', 't', 's' )
68 #define FOURCC_elst VLC_FOURCC( 'e', 'l', 's', 't' )
69 #define FOURCC_udta VLC_FOURCC( 'u', 'd', 't', 'a' )
70 #define FOURCC_mvex VLC_FOURCC( 'm', 'v', 'e', 'x' )
71 #define FOURCC_trex VLC_FOURCC( 't', 'r', 'e', 'x' )
72 #define FOURCC_mfhd VLC_FOURCC( 'm', 'f', 'h', 'd' )
73 #define FOURCC_traf VLC_FOURCC( 't', 'r', 'a', 'f' )
74 #define FOURCC_tfhd VLC_FOURCC( 't', 'f', 'h', 'd' )
75 #define FOURCC_trun VLC_FOURCC( 't', 'r', 'u', 'n' )
76 #define FOURCC_cprt VLC_FOURCC( 'c', 'p', 'r', 't' )
77 #define FOURCC_iods VLC_FOURCC( 'i', 'o', 'd', 's' )
78
79 #define FOURCC_nmhd VLC_FOURCC( 'n', 'm', 'h', 'd' )
80 #define FOURCC_mp4v VLC_FOURCC( 'm', 'p', '4', 'v' )
81 #define FOURCC_mp4a VLC_FOURCC( 'm', 'p', '4', 'a' )
82 #define FOURCC_mp4s VLC_FOURCC( 'm', 'p', '4', 's' )
83 #define FOURCC_vide VLC_FOURCC( 'v', 'i', 'd', 'e' )
84 #define FOURCC_soun VLC_FOURCC( 's', 'o', 'u', 'n' )
85 #define FOURCC_hint VLC_FOURCC( 'h', 'i', 'n', 't' )
86
87 #define FOURCC_dpnd VLC_FOURCC( 'd', 'p', 'n', 'd' )
88 #define FOURCC_ipir VLC_FOURCC( 'i', 'p', 'i', 'r' )
89 #define FOURCC_mpod VLC_FOURCC( 'm', 'p', 'o', 'd' )
90 #define FOURCC_hnti VLC_FOURCC( 'h', 'n', 't', 'i' )
91 #define FOURCC_rtp  VLC_FOURCC( 'r', 't', 'p', ' ' )
92
93 #define FOURCC_isom VLC_FOURCC( 'i', 's', 'o', 'm' )
94 #define FOURCC_esds VLC_FOURCC( 'e', 's', 'd', 's' )
95
96 #define FOURCC__mp3 VLC_FOURCC( '.', 'm', 'p', '3' )
97 #define FOURCC_ms02 VLC_FOURCC( 'm', 's', 0x0, 0x02 )
98 #define FOURCC_ms11 VLC_FOURCC( 'm', 's', 0x0, 0x11 )
99 #define FOURCC_ms55 VLC_FOURCC( 'm', 's', 0x0, 0x55 )
100 #define FOURCC_twos VLC_FOURCC( 't', 'w', 'o', 's' )
101 #define FOURCC_sowt VLC_FOURCC( 's', 'o', 'w', 't' )
102 #define FOURCC_QDMC VLC_FOURCC( 'Q', 'D', 'M', 'C' )
103 #define FOURCC_QDM2 VLC_FOURCC( 'Q', 'D', 'M', '2' )
104 #define FOURCC_ima4 VLC_FOURCC( 'i', 'm', 'a', '4' )
105 #define FOURCC_IMA4 VLC_FOURCC( 'I', 'M', 'A', '4' )
106 #define FOURCC_dvi  VLC_FOURCC( 'd', 'v', 'i', ' ' )
107 #define FOURCC_MAC3 VLC_FOURCC( 'M', 'A', 'C', '3' )
108 #define FOURCC_MAC6 VLC_FOURCC( 'M', 'A', 'C', '6' )
109 #define FOURCC_alaw VLC_FOURCC( 'a', 'l', 'a', 'w' )
110 #define FOURCC_ulaw VLC_FOURCC( 'u', 'l', 'a', 'w' )
111 #define FOURCC_Qclp VLC_FOURCC( 'Q', 'c', 'l', 'p' )
112 #define FOURCC_samr VLC_FOURCC( 's', 'a', 'm', 'r' )
113 #define FOURCC_sawb VLC_FOURCC( 's', 'a', 'w', 'b' )
114 #define FOURCC_OggS VLC_FOURCC( 'O', 'g', 'g', 'S' )
115
116 #define FOURCC_zlib VLC_FOURCC( 'z', 'l', 'i', 'b' )
117 #define FOURCC_SVQ1 VLC_FOURCC( 'S', 'V', 'Q', '1' )
118 #define FOURCC_SVQ3 VLC_FOURCC( 'S', 'V', 'Q', '3' )
119 #define FOURCC_ZyGo VLC_FOURCC( 'Z', 'y', 'G', 'o' )
120 #define FOURCC_3IV1 VLC_FOURCC( '3', 'I', 'V', '1' )
121 #define FOURCC_3iv1 VLC_FOURCC( '3', 'i', 'v', '1' )
122 #define FOURCC_3IV2 VLC_FOURCC( '3', 'I', 'V', '2' )
123 #define FOURCC_3iv2 VLC_FOURCC( '3', 'i', 'v', '2' )
124 #define FOURCC_3IVD VLC_FOURCC( '3', 'I', 'V', 'D' )
125 #define FOURCC_3ivd VLC_FOURCC( '3', 'i', 'v', 'd' )
126 #define FOURCC_3VID VLC_FOURCC( '3', 'V', 'I', 'D' )
127 #define FOURCC_3vid VLC_FOURCC( '3', 'v', 'i', 'd' )
128 #define FOURCC_h263 VLC_FOURCC( 'h', '2', '6', '3' )
129 #define FOURCC_s263 VLC_FOURCC( 's', '2', '6', '3' )
130 #define FOURCC_DIVX VLC_FOURCC( 'D', 'I', 'V', 'X' )
131 #define FOURCC_XVID VLC_FOURCC( 'X', 'V', 'I', 'D' )
132 #define FOURCC_cvid VLC_FOURCC( 'c', 'v', 'i', 'd' )
133 #define FOURCC_mjpa VLC_FOURCC( 'm', 'j', 'p', 'a' )
134 #define FOURCC_mjpb VLC_FOURCC( 'm', 'j', 'q', 't' )
135 #define FOURCC_mjqt VLC_FOURCC( 'm', 'j', 'h', 't' )
136 #define FOURCC_mjht VLC_FOURCC( 'm', 'j', 'p', 'b' )
137 #define FOURCC_VP31 VLC_FOURCC( 'V', 'P', '3', '1' )
138 #define FOURCC_vp31 VLC_FOURCC( 'v', 'p', '3', '1' )
139 #define FOURCC_h264 VLC_FOURCC( 'h', '2', '6', '4' )
140
141 #define FOURCC_avc1 VLC_FOURCC( 'a', 'v', 'c', '1' )
142 #define FOURCC_avcC VLC_FOURCC( 'a', 'v', 'c', 'C' )
143 #define FOURCC_m4ds VLC_FOURCC( 'm', '4', 'd', 's' )
144
145 #define FOURCC_dvc  VLC_FOURCC( 'd', 'v', 'c', ' ' )
146 #define FOURCC_dvp  VLC_FOURCC( 'd', 'v', 'p', ' ' )
147 #define FOURCC_raw  VLC_FOURCC( 'r', 'a', 'w', ' ' )
148
149 #define FOURCC_jpeg VLC_FOURCC( 'j', 'p', 'e', 'g' )
150
151
152 #define FOURCC_rmra VLC_FOURCC( 'r', 'm', 'r', 'a' )
153 #define FOURCC_rmda VLC_FOURCC( 'r', 'm', 'd', 'a' )
154 #define FOURCC_rdrf VLC_FOURCC( 'r', 'd', 'r', 'f' )
155 #define FOURCC_rmdr VLC_FOURCC( 'r', 'm', 'd', 'r' )
156 #define FOURCC_rmvc VLC_FOURCC( 'r', 'm', 'v', 'c' )
157 #define FOURCC_rmcd VLC_FOURCC( 'r', 'm', 'c', 'd' )
158 #define FOURCC_rmqu VLC_FOURCC( 'r', 'm', 'q', 'u' )
159 #define FOURCC_alis VLC_FOURCC( 'a', 'l', 'i', 's' )
160
161 #define FOURCC_gmhd VLC_FOURCC( 'g', 'm', 'h', 'd' )
162 #define FOURCC_wave VLC_FOURCC( 'w', 'a', 'v', 'e' )
163
164 #define FOURCC_drms VLC_FOURCC( 'd', 'r', 'm', 's' )
165 #define FOURCC_sinf VLC_FOURCC( 's', 'i', 'n', 'f' )
166 #define FOURCC_schi VLC_FOURCC( 's', 'c', 'h', 'i' )
167 #define FOURCC_user VLC_FOURCC( 'u', 's', 'e', 'r' )
168 #define FOURCC_key  VLC_FOURCC( 'k', 'e', 'y', ' ' )
169 #define FOURCC_iviv VLC_FOURCC( 'i', 'v', 'i', 'v' )
170 #define FOURCC_name VLC_FOURCC( 'n', 'a', 'm', 'e' )
171 #define FOURCC_priv VLC_FOURCC( 'p', 'r', 'i', 'v' )
172
173 #define FOURCC_text VLC_FOURCC( 't', 'e', 'x', 't' )
174 #define FOURCC_subp VLC_FOURCC( 's', 'u', 'b', 'p' )
175
176 #define FOURCC_0xa9nam VLC_FOURCC( 0xa9, 'n', 'a', 'm' )
177 #define FOURCC_0xa9aut VLC_FOURCC( 0xa9, 'a', 'u', 't' )
178 #define FOURCC_0xa9swr VLC_FOURCC( 0xa9, 's', 'w', 'r' )
179 #define FOURCC_0xa9cpy VLC_FOURCC( 0xa9, 'c', 'p', 'y' )
180 #define FOURCC_0xa9inf VLC_FOURCC( 0xa9, 'i', 'n', 'f' )
181 #define FOURCC_0xa9ART VLC_FOURCC( 0xa9, 'A', 'R', 'T' )
182 #define FOURCC_0xa9des VLC_FOURCC( 0xa9, 'd', 'e', 's' )
183 #define FOURCC_0xa9dir VLC_FOURCC( 0xa9, 'd', 'i', 'r' )
184 #define FOURCC_0xa9cmt VLC_FOURCC( 0xa9, 'c', 'm', 't' )
185 #define FOURCC_0xa9req VLC_FOURCC( 0xa9, 'r', 'e', 'q' )
186 #define FOURCC_0xa9day VLC_FOURCC( 0xa9, 'd', 'a', 'y' )
187 #define FOURCC_0xa9fmt VLC_FOURCC( 0xa9, 'f', 'm', 't' )
188 #define FOURCC_0xa9prd VLC_FOURCC( 0xa9, 'p', 'r', 'd' )
189 #define FOURCC_0xa9prf VLC_FOURCC( 0xa9, 'p', 'r', 'f' )
190 #define FOURCC_0xa9src VLC_FOURCC( 0xa9, 's', 'r', 'c' )
191 #define FOURCC_0xa9alb VLC_FOURCC( 0xa9, 'a', 'l', 'b' )
192 #define FOURCC_0xa9dis VLC_FOURCC( 0xa9, 'd', 'i', 's' )
193 #define FOURCC_0xa9enc VLC_FOURCC( 0xa9, 'e', 'n', 'c' )
194 #define FOURCC_0xa9trk VLC_FOURCC( 0xa9, 't', 'r', 'k' )
195 #define FOURCC_0xa9url VLC_FOURCC( 0xa9, 'u', 'r', 'l' )
196 #define FOURCC_0xa9dsa VLC_FOURCC( 0xa9, 'd', 's', 'a' )
197 #define FOURCC_0xa9hst VLC_FOURCC( 0xa9, 'h', 's', 't' )
198 #define FOURCC_0xa9ope VLC_FOURCC( 0xa9, 'o', 'p', 'e' )
199 #define FOURCC_0xa9wrt VLC_FOURCC( 0xa9, 'w', 'r', 't' )
200 #define FOURCC_0xa9com VLC_FOURCC( 0xa9, 'c', 'o', 'm' )
201 #define FOURCC_0xa9gen VLC_FOURCC( 0xa9, 'g', 'e', 'n' )
202 #define FOURCC_WLOC VLC_FOURCC( 'W', 'L', 'O', 'C' )
203
204 /* Do you want some debug information on all read boxes ? */
205 #define MP4_VERBOSE  1
206
207
208 struct MP4_Box_s;
209
210
211 /* uuid Universal Unique IDentifiers */
212 typedef struct UUID_s
213 {
214     uint8_t b[16];
215 } UUID_t;
216
217 /* specific structure for all boxes */
218
219 typedef struct MP4_Box_data_ftyp_s
220 {
221     uint32_t i_major_brand;
222     uint32_t i_minor_version;
223
224     uint32_t i_compatible_brands_count;
225     uint32_t *i_compatible_brands;
226
227 } MP4_Box_data_ftyp_t;
228
229 typedef struct MP4_Box_data_mvhd_s
230 {
231     uint8_t  i_version;
232     uint32_t i_flags;
233
234     uint64_t i_creation_time;
235     uint64_t i_modification_time;
236     uint32_t i_timescale;
237     uint64_t i_duration;
238
239     int32_t  i_rate;
240     int16_t  i_volume;
241     int16_t  i_reserved1;
242     uint32_t i_reserved2[2];
243     int32_t  i_matrix[9];
244     uint32_t i_predefined[6];
245     uint32_t i_next_track_id;
246
247 } MP4_Box_data_mvhd_t;
248
249 #define MP4_TRACK_ENABLED    0x000001
250 #define MP4_TRACK_IN_MOVIE   0x000002
251 #define MP4_TRACK_IN_PREVIEW 0x000004
252 typedef struct MP4_Box_data_tkhd_s
253 {
254     uint8_t  i_version;
255     uint32_t i_flags;
256
257     uint64_t i_creation_time;
258     uint64_t i_modification_time;
259     uint32_t i_track_ID;
260     uint32_t i_reserved;
261     uint64_t i_duration;
262
263     uint32_t i_reserved2[2];
264     int16_t  i_layer;
265     int16_t  i_predefined;
266
267     int16_t  i_volume;
268     uint16_t i_reserved3;
269     int32_t  i_matrix[9];
270     int32_t  i_width;
271     int32_t  i_height;
272
273 } MP4_Box_data_tkhd_t;
274
275 typedef struct MP4_Box_data_mdhd_s
276 {
277     uint8_t  i_version;
278     uint32_t i_flags;
279
280     uint64_t i_creation_time;
281     uint64_t i_modification_time;
282     uint32_t i_timescale;
283     uint64_t i_duration;
284
285     /* one bit for pad */
286     /* unsigned int(5)[3] language difference with 0x60*/
287     unsigned char i_language[3];
288     uint16_t i_predefined;
289
290 } MP4_Box_data_mdhd_t;
291
292 typedef struct MP4_Box_data_hdlr_s
293 {
294     uint8_t  i_version;
295     uint32_t i_flags;
296
297     uint32_t i_predefined;
298     uint32_t i_handler_type; /* "vide" "soun" "hint" "odsm"
299                            "crsm" "sdsm" "m7sm" "ocsm"
300                            "ipsm" "mjsm" */
301
302     unsigned char *psz_name; /* in UTF-8 */
303
304 } MP4_Box_data_hdlr_t;
305
306 typedef struct MP4_Box_data_vmhd_s
307 {
308     uint8_t  i_version;
309     uint32_t i_flags;
310
311     int16_t  i_graphics_mode;
312     int16_t  i_opcolor[3];
313
314 } MP4_Box_data_vmhd_t;
315
316 typedef struct MP4_Box_data_smhd_s
317 {
318     uint8_t  i_version;
319     uint32_t i_flags;
320
321     int16_t  i_balance;
322     int16_t  i_reserved;
323
324 } MP4_Box_data_smhd_t;
325
326 typedef struct MP4_Box_data_hmhd_s
327 {
328     uint8_t  i_version;
329     uint32_t i_flags;
330
331     uint16_t i_max_PDU_size;
332     uint16_t i_avg_PDU_size;
333     uint32_t i_max_bitrate;
334     uint32_t i_avg_bitrate;
335     uint32_t i_reserved;
336
337 } MP4_Box_data_hmhd_t;
338
339 typedef struct MP4_Box_data_url_s
340 {
341     uint8_t  i_version;
342     uint32_t i_flags;
343
344     unsigned char *psz_location;
345
346 } MP4_Box_data_url_t;
347
348 typedef struct MP4_Box_data_urn_s
349 {
350     uint8_t  i_version;
351     uint32_t i_flags;
352
353     unsigned char *psz_name;
354     unsigned char *psz_location;
355
356 } MP4_Box_data_urn_t;
357
358 typedef struct MP4_Box_data_dref_s
359 {
360     uint8_t  i_version;
361     uint32_t i_flags;
362
363     uint32_t i_entry_count;
364 /* XXX it's also a container with i_entry_count entry */
365 } MP4_Box_data_dref_t;
366
367 typedef struct MP4_Box_data_stts_s
368 {
369     uint8_t  i_version;
370     uint32_t i_flags;
371
372     uint32_t i_entry_count;
373     uint32_t *i_sample_count; /* these are array */
374     int32_t  *i_sample_delta;
375
376 } MP4_Box_data_stts_t;
377
378 typedef struct MP4_Box_data_ctts_s
379 {
380     uint8_t  i_version;
381     uint32_t i_flags;
382
383     uint32_t i_entry_count;
384
385     uint32_t *i_sample_count; /* these are array */
386     int32_t  *i_sample_offset;
387
388 } MP4_Box_data_ctts_t;
389
390
391 typedef struct MP4_Box_data_sample_soun_s
392 {
393     uint8_t  i_reserved1[6];
394     uint16_t i_data_reference_index;
395
396     //uint32_t i_reserved2[2];
397     uint16_t i_qt_version;
398     uint16_t i_qt_revision_level;
399     uint32_t i_qt_vendor;
400
401     uint16_t i_channelcount;
402     uint16_t i_samplesize;
403     uint16_t i_predefined;
404     uint16_t i_reserved3;
405     uint16_t i_sampleratehi; /* timescale of track */
406     uint16_t i_sampleratelo;
407
408     /* for version 1 (i_reserved1[0] == 1) */
409     uint32_t i_sample_per_packet;
410     uint32_t i_bytes_per_packet;
411     uint32_t i_bytes_per_frame;
412     uint32_t i_bytes_per_sample;
413
414     /* XXX hack */
415     int     i_qt_description;
416     uint8_t *p_qt_description;
417
418     void    *p_drms;
419
420 } MP4_Box_data_sample_soun_t;
421
422 typedef struct MP4_Box_data_sample_vide_s
423 {
424     uint8_t  i_reserved1[6];
425     uint16_t i_data_reference_index;
426
427     uint16_t i_qt_version;
428     uint16_t i_qt_revision_level;
429     uint32_t i_qt_vendor;
430
431     uint32_t i_qt_temporal_quality;
432     uint32_t i_qt_spatial_quality;
433
434     int16_t  i_width;
435     int16_t  i_height;
436
437     uint32_t i_horizresolution;
438     uint32_t i_vertresolution;
439
440     uint32_t i_qt_data_size;
441     uint16_t i_qt_frame_count;
442
443     uint8_t  i_compressorname[32];
444     int16_t  i_depth;
445
446     int16_t  i_qt_color_table;
447
448     /* XXX hack ImageDescription */
449     int     i_qt_image_description;
450     uint8_t *p_qt_image_description;
451
452 } MP4_Box_data_sample_vide_t;
453
454 typedef struct
455 {
456     uint8_t  i_reserved1[6];
457     uint16_t i_data_reference_index;
458
459     uint32_t i_display_flags;
460     uint32_t i_justification;
461     uint16_t i_background_color[3];
462     uint64_t i_text_box;
463     uint64_t i_reserved2;
464     uint16_t i_font_number;
465     uint16_t i_font_face;
466     uint16_t i_reserved3;
467
468     uint16_t i_foreground_color[3];
469
470     char    *psz_text_name;
471 } MP4_Box_data_sample_text_t;
472
473 typedef struct MP4_Box_data_sample_hint_s
474 {
475     uint8_t  i_reserved1[6];
476     uint16_t i_data_reference_index;
477
478     uint8_t *p_data;
479
480 } MP4_Box_data_sample_hint_t;
481
482 typedef struct MP4_Box_data_moviehintinformation_rtp_s
483 {
484     uint32_t i_description_format;
485     unsigned char *psz_text;
486
487 } MP4_Box_data_moviehintinformation_rtp_t;
488
489
490
491 typedef struct MP4_Box_data_stsd_s
492 {
493     uint8_t  i_version;
494     uint32_t i_flags;
495
496     uint32_t i_entry_count;
497
498     /* it contains SampleEntry handled as if it was Box */
499
500 } MP4_Box_data_stsd_t;
501
502
503 typedef struct MP4_Box_data_stsz_s
504 {
505     uint8_t  i_version;
506     uint32_t i_flags;
507
508     uint32_t i_sample_size;
509     uint32_t i_sample_count;
510
511     uint32_t *i_entry_size; /* array , empty if i_sample_size != 0 */
512
513 } MP4_Box_data_stsz_t;
514
515 typedef struct MP4_Box_data_stz2_s
516 {
517     uint8_t  i_version;
518     uint32_t i_flags;
519
520     uint32_t i_sample_size; /* 24 bits */
521     uint8_t  i_field_size;
522     uint32_t i_sample_count;
523
524     uint32_t *i_entry_size; /* array: unsigned int(i_field_size) entry_size */
525
526 } MP4_Box_data_stz2_t;
527
528 typedef struct MP4_Box_data_stsc_s
529 {
530     uint8_t  i_version;
531     uint32_t i_flags;
532
533     uint32_t i_entry_count;
534
535     uint32_t *i_first_chunk; /* theses are arrays */
536     uint32_t *i_samples_per_chunk;
537     uint32_t *i_sample_description_index;
538
539 } MP4_Box_data_stsc_t;
540
541
542 typedef struct MP4_Box_data_co64_s
543 {
544     uint8_t  i_version;
545     uint32_t i_flags;
546
547     uint32_t i_entry_count;
548
549     uint64_t *i_chunk_offset;
550
551 } MP4_Box_data_co64_t;
552
553
554 typedef struct MP4_Box_data_stss_s
555 {
556     uint8_t  i_version;
557     uint32_t i_flags;
558
559     uint32_t i_entry_count;
560
561     uint32_t *i_sample_number;
562
563 } MP4_Box_data_stss_t;
564
565 typedef struct MP4_Box_data_stsh_s
566 {
567     uint8_t  i_version;
568     uint32_t i_flags;
569
570     uint32_t i_entry_count;
571
572     uint32_t *i_shadowed_sample_number;
573     uint32_t *i_sync_sample_number;
574
575 } MP4_Box_data_stsh_t;
576
577 typedef struct MP4_Box_data_stdp_s
578 {
579     uint8_t  i_version;
580     uint32_t i_flags;
581
582     uint16_t *i_priority;
583
584 } MP4_Box_data_stdp_t;
585
586 typedef struct MP4_Box_data_padb_s
587 {
588     uint8_t  i_version;
589     uint32_t i_flags;
590
591     uint32_t i_sample_count;
592
593     uint16_t *i_reserved1;   /* 1bit  */
594     uint16_t *i_pad2;        /* 3bits */
595     uint16_t *i_reserved2;   /* 1bit  */
596     uint16_t *i_pad1;        /* 3bits */
597
598
599 } MP4_Box_data_padb_t;
600
601
602 typedef struct MP4_Box_data_elst_s
603 {
604     uint8_t  i_version;
605     uint32_t i_flags;
606
607     uint32_t i_entry_count;
608
609     uint64_t *i_segment_duration;
610     int64_t  *i_media_time;
611     uint16_t *i_media_rate_integer;
612     uint16_t *i_media_rate_fraction;
613
614
615 } MP4_Box_data_elst_t;
616
617 typedef struct MP4_Box_data_cprt_s
618 {
619     uint8_t  i_version;
620     uint32_t i_flags;
621     /* 1 pad bit */
622     unsigned char i_language[3];
623
624     unsigned char *psz_notice;
625 } MP4_Box_data_cprt_t;
626
627
628 /* DecoderConfigDescriptor */
629 typedef struct MP4_descriptor_decoder_config_s
630 {
631     uint8_t i_objectTypeIndication;
632     uint8_t i_streamType;
633     int     b_upStream;
634     int     i_buffer_sizeDB;
635     int     i_max_bitrate;
636     int     i_avg_bitrate;
637
638     int     i_decoder_specific_info_len;
639     uint8_t *p_decoder_specific_info;
640     /* some other stuff */
641
642 } MP4_descriptor_decoder_config_t;
643
644 typedef struct MP4_descriptor_SL_config_s
645 {
646
647     int i_dummy; /* ANSI C forbids empty structures */
648
649 } MP4_descriptor_SL_config_t;
650
651
652 typedef struct MP4_descriptor_ES_s
653 {
654     uint16_t i_ES_ID;
655     int      b_stream_dependence;
656     int      b_url;
657     int      b_OCRstream;
658     int      i_stream_priority;
659
660     int      i_depend_on_ES_ID; /* if b_stream_dependence set */
661
662     unsigned char *psz_URL;
663
664     uint16_t i_OCR_ES_ID;       /* if b_OCRstream */
665     MP4_descriptor_decoder_config_t *p_decConfigDescr;
666
667     MP4_descriptor_SL_config_t *p_slConfigDescr;
668
669     /* some other stuff ... */
670
671 } MP4_descriptor_ES_t;
672
673 /* ES descriptor */
674 typedef struct MP4_Box_data_esds_s
675 {
676     uint8_t  i_version;
677     uint32_t i_flags;
678
679     MP4_descriptor_ES_t es_descriptor;
680
681 } MP4_Box_data_esds_t;
682
683
684 typedef struct MP4_Box_data_dcom_s
685 {
686     uint32_t i_algorithm; /* fourcc */
687
688 } MP4_Box_data_dcom_t;
689
690 typedef struct MP4_Box_data_cmvd_s
691 {
692     uint32_t i_uncompressed_size;
693     uint32_t i_compressed_size;
694
695     int     b_compressed; /* Set to 1 if compressed data, 0 if uncompressed */
696     uint8_t *p_data;
697
698 } MP4_Box_data_cmvd_t;
699
700 typedef struct MP4_Box_data_cmov_s
701 {
702     struct MP4_Box_s *p_moov; /* uncompressed moov */
703
704 } MP4_Box_data_cmov_t;
705
706 typedef struct
707 {
708     uint8_t  i_version;
709     uint32_t i_flags;
710
711     uint32_t i_ref_type;
712     char     *psz_ref;
713
714 } MP4_Box_data_rdrf_t;
715
716 typedef struct
717 {
718     uint8_t  i_version;
719     uint32_t i_flags;
720
721     uint32_t i_rate;
722
723 } MP4_Box_data_rmdr_t;
724
725 typedef struct
726 {
727     uint8_t  i_version;
728     uint32_t i_flags;
729
730     uint32_t i_gestaltType;
731     uint32_t i_val1;
732     uint32_t i_val2;
733     uint16_t i_checkType;   /* 0: val1 is version min
734                                1: gestalt value & val2 == val1 */
735
736 } MP4_Box_data_rmvc_t;
737
738 typedef struct
739 {
740     uint8_t  i_version;
741     uint32_t i_flags;
742
743
744 } MP4_Box_data_rmcd_t;
745
746 typedef struct
747 {
748     uint32_t i_quality;
749
750 } MP4_Box_data_rmqu_t;
751
752 typedef struct
753 {
754     char *psz_text;
755
756 } MP4_Box_data_0xa9xxx_t;
757
758 typedef struct
759 {
760     uint8_t i_version;
761     uint8_t i_profile;
762     uint8_t i_profile_compatibility;
763     uint8_t i_level;
764
765     uint8_t i_reserved1;     /* 6 bits */
766     uint8_t i_length_size;
767
768     uint8_t i_reserved2;    /* 3 bits */
769     uint8_t  i_sps;
770     uint16_t *i_sps_length;
771     uint8_t  **sps;
772
773     uint8_t  i_pps;
774     uint16_t *i_pps_length;
775     uint8_t  **pps;
776
777     /* XXX: Hack raw avcC atom payload */
778     int     i_avcC;
779     uint8_t *p_avcC;
780
781 } MP4_Box_data_avcC_t;
782
783 /*
784 typedef struct MP4_Box_data__s
785 {
786     uint8_t  i_version;
787     uint32_t i_flags;
788
789 } MP4_Box_data__t;
790
791 */
792
793 typedef union MP4_Box_data_s
794 {
795     MP4_Box_data_ftyp_t *p_ftyp;
796     MP4_Box_data_mvhd_t *p_mvhd;
797     MP4_Box_data_tkhd_t *p_tkhd;
798     MP4_Box_data_mdhd_t *p_mdhd;
799     MP4_Box_data_hdlr_t *p_hdlr;
800     MP4_Box_data_vmhd_t *p_vmhd;
801     MP4_Box_data_smhd_t *p_smhd;
802     MP4_Box_data_hmhd_t *p_hmhd;
803     MP4_Box_data_url_t  *p_url;
804     MP4_Box_data_urn_t  *p_urn;
805     MP4_Box_data_dref_t *p_dref;
806     MP4_Box_data_stts_t *p_stts;
807     MP4_Box_data_ctts_t *p_ctts;
808     MP4_Box_data_stsd_t *p_stsd;
809         MP4_Box_data_sample_vide_t *p_sample_vide;
810         MP4_Box_data_sample_soun_t *p_sample_soun;
811         MP4_Box_data_sample_text_t *p_sample_text;
812         MP4_Box_data_sample_hint_t *p_sample_hint;
813
814         MP4_Box_data_esds_t *p_esds;
815         MP4_Box_data_avcC_t *p_avcC;
816
817     MP4_Box_data_stsz_t *p_stsz;
818     MP4_Box_data_stz2_t *p_stz2;
819     MP4_Box_data_stsc_t *p_stsc;
820     MP4_Box_data_co64_t *p_co64;
821     MP4_Box_data_stss_t *p_stss;
822     MP4_Box_data_stsh_t *p_stsh;
823     MP4_Box_data_stdp_t *p_stdp;
824     MP4_Box_data_padb_t *p_padb;
825     MP4_Box_data_elst_t *p_elst;
826     MP4_Box_data_cprt_t *p_cprt;
827
828     MP4_Box_data_dcom_t *p_dcom;
829     MP4_Box_data_cmvd_t *p_cmvd;
830     MP4_Box_data_cmov_t *p_cmov;
831
832     MP4_Box_data_moviehintinformation_rtp_t p_moviehintinformation_rtp;
833
834     MP4_Box_data_rdrf_t *p_rdrf;
835     MP4_Box_data_rmdr_t *p_rmdr;
836     MP4_Box_data_rmqu_t *p_rmqu;
837     MP4_Box_data_rmvc_t *p_rmvc;
838
839     MP4_Box_data_0xa9xxx_t *p_0xa9xxx;
840
841     void                *p_data; /* for unknow type */
842 } MP4_Box_data_t;
843
844
845
846 /* the most basic structure */
847 typedef struct MP4_Box_s
848 {
849     off_t        i_pos;      /* absolute position */
850
851     uint32_t     i_type;
852     uint32_t     i_shortsize;
853
854     UUID_t       i_uuid;  /* Set if i_type == "uuid" */
855
856     uint64_t     i_size; /* always set so use it */
857
858     MP4_Box_data_t   data;   /* union of pointers on extended data depending
859                                 on i_type (or i_usertype) */
860
861     struct MP4_Box_s *p_father; /* pointer on the father Box */
862
863     struct MP4_Box_s *p_first;  /* pointer on the first child Box */
864     struct MP4_Box_s *p_last;
865
866     struct MP4_Box_s *p_next;   /* pointer on the next boxes at the same level */
867
868 } MP4_Box_t;
869
870
871
872 /*****************************************************************************
873  * MP4_BoxGetRoot : Parse the entire file, and create all boxes in memory
874  *****************************************************************************
875  *  The first box is a virtual box "root" and is the father for all first
876  *  level boxes
877  *****************************************************************************/
878 MP4_Box_t *MP4_BoxGetRoot( stream_t * );
879
880 /*****************************************************************************
881  * MP4_FreeBox : free memory allocated after read with MP4_ReadBox
882  *               or MP4_BoxGetRoot, this means also children boxes
883  * XXX : all children have to be allocated by a malloc !! and
884  *         p_box is freed
885  *****************************************************************************/
886 void MP4_BoxFree( stream_t *, MP4_Box_t *p_box );
887
888 /*****************************************************************************
889  * MP4_DumpBoxStructure: print the structure of the p_box
890  *****************************************************************************
891  * Usefull while debugging
892  *****************************************************************************/
893 void MP4_BoxDumpStructure( stream_t *p_input, MP4_Box_t *p_box );
894
895
896 /*****************************************************************************
897  * MP4_BoxGet: find a box given a path relative to p_box
898  *****************************************************************************
899  * Path Format: . .. / as usual
900  *              [number] to specifie box number ex: trak[12]
901  *
902  * ex: /moov/trak[12]
903  *     ../mdia
904  *****************************************************************************/
905 MP4_Box_t *MP4_BoxGet( MP4_Box_t *p_box, char *psz_fmt, ... );
906
907 /*****************************************************************************
908  * MP4_BoxCount: find number of box given a path relative to p_box
909  *****************************************************************************
910  * Path Format: . .. / as usual
911  *              [number] to specifie box number ex: trak[12]
912  *
913  * ex: /moov/trak
914  *     ../mdia
915  *****************************************************************************/
916 int MP4_BoxCount( MP4_Box_t *p_box, char *psz_fmt, ... );
917
918 int MP4_ReadBoxCommon( stream_t *p_stream, MP4_Box_t *p_box );
919 int MP4_ReadBox_sample_vide( stream_t *p_stream, MP4_Box_t *p_box );
920 void MP4_FreeBox_sample_vide( MP4_Box_t *p_box );