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