]> git.sesse.net Git - vlc/blob - modules/demux/mp4/libmp4.h
demux: mp4: fix buffer overflow in parsing of string boxes.
[vlc] / modules / demux / mp4 / libmp4.h
1 /*****************************************************************************
2  * libmp4.h : LibMP4 library for mp4 module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001-2004, 2010 VLC authors and VideoLAN
5  *
6  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 #ifndef _VLC_LIBMP4_H
24 #define _VLC_LIBMP4_H 1
25
26 #include <vlc_es.h>
27 #include <vlc_codecs.h>
28
29 #define BLOCK16x16 (1<<16)
30
31 #define MAJOR_3gp4 VLC_FOURCC( '3', 'g', 'p', '4' )
32 #define MAJOR_3gp5 VLC_FOURCC( '3', 'g', 'p', '5' )
33 #define MAJOR_3gp6 VLC_FOURCC( '3', 'g', 'p', '6' )
34 #define MAJOR_3gp7 VLC_FOURCC( '3', 'g', 'p', '7' )
35 #define MAJOR_isml VLC_FOURCC( 'i', 's', 'm', 'l' )
36 #define MAJOR_isom VLC_FOURCC( 'i', 's', 'o', 'm' )
37 #define MAJOR_qt__ VLC_FOURCC( 'q', 't', ' ', ' ' )
38
39 #define ATOM_root VLC_FOURCC( 'r', 'o', 'o', 't' )
40 #define ATOM_uuid VLC_FOURCC( 'u', 'u', 'i', 'd' )
41
42 #define ATOM_ftyp VLC_FOURCC( 'f', 't', 'y', 'p' )
43 #define ATOM_moov VLC_FOURCC( 'm', 'o', 'o', 'v' )
44 #define ATOM_foov VLC_FOURCC( 'f', 'o', 'o', 'v' )
45 #define ATOM_cmov VLC_FOURCC( 'c', 'm', 'o', 'v' )
46 #define ATOM_dcom VLC_FOURCC( 'd', 'c', 'o', 'm' )
47 #define ATOM_cmvd VLC_FOURCC( 'c', 'm', 'v', 'd' )
48
49 #define ATOM_moof VLC_FOURCC( 'm', 'o', 'o', 'f' )
50 #define ATOM_mdat VLC_FOURCC( 'm', 'd', 'a', 't' )
51 #define ATOM_skip VLC_FOURCC( 's', 'k', 'i', 'p' )
52 #define ATOM_free VLC_FOURCC( 'f', 'r', 'e', 'e' )
53 #define ATOM_udta VLC_FOURCC( 'u', 'd', 't', 'a' )
54 #define ATOM_wide VLC_FOURCC( 'w', 'i', 'd', 'e' )
55 #define ATOM_binm VLC_FOURCC( 0x82, 0x82, 0x7f, 0x7d ) /* binary Computer Graphics Metafile */
56
57 /* Quicktime preview */
58 #define ATOM_pnot VLC_FOURCC( 'p', 'n', 'o', 't' )
59 #define ATOM_pict VLC_FOURCC( 'p', 'i', 'c', 't' )
60 #define ATOM_PICT VLC_FOURCC( 'P', 'I', 'C', 'T' )
61
62 #define ATOM_data VLC_FOURCC( 'd', 'a', 't', 'a' )
63
64 #define ATOM_trak VLC_FOURCC( 't', 'r', 'a', 'k' )
65 #define ATOM_mvhd VLC_FOURCC( 'm', 'v', 'h', 'd' )
66 #define ATOM_tkhd VLC_FOURCC( 't', 'k', 'h', 'd' )
67 #define ATOM_tref VLC_FOURCC( 't', 'r', 'e', 'f' )
68 #define ATOM_load VLC_FOURCC( 'l', 'o', 'a', 'd' )
69 #define ATOM_mdia VLC_FOURCC( 'm', 'd', 'i', 'a' )
70 #define ATOM_mdhd VLC_FOURCC( 'm', 'd', 'h', 'd' )
71 #define ATOM_hdlr VLC_FOURCC( 'h', 'd', 'l', 'r' )
72 #define ATOM_minf VLC_FOURCC( 'm', 'i', 'n', 'f' )
73 #define ATOM_vmhd VLC_FOURCC( 'v', 'm', 'h', 'd' )
74 #define ATOM_smhd VLC_FOURCC( 's', 'm', 'h', 'd' )
75 #define ATOM_hmhd VLC_FOURCC( 'h', 'm', 'h', 'd' )
76 #define ATOM_dinf VLC_FOURCC( 'd', 'i', 'n', 'f' )
77 #define ATOM_url  VLC_FOURCC( 'u', 'r', 'l', ' ' )
78 #define ATOM_urn  VLC_FOURCC( 'u', 'r', 'n', ' ' )
79 #define ATOM_dref VLC_FOURCC( 'd', 'r', 'e', 'f' )
80 #define ATOM_stbl VLC_FOURCC( 's', 't', 'b', 'l' )
81 #define ATOM_stts VLC_FOURCC( 's', 't', 't', 's' )
82 #define ATOM_ctts VLC_FOURCC( 'c', 't', 't', 's' )
83 #define ATOM_stsd VLC_FOURCC( 's', 't', 's', 'd' )
84 #define ATOM_stsz VLC_FOURCC( 's', 't', 's', 'z' )
85 #define ATOM_stz2 VLC_FOURCC( 's', 't', 'z', '2' )
86 #define ATOM_stsc VLC_FOURCC( 's', 't', 's', 'c' )
87 #define ATOM_stco VLC_FOURCC( 's', 't', 'c', 'o' )
88 #define ATOM_co64 VLC_FOURCC( 'c', 'o', '6', '4' )
89 #define ATOM_stss VLC_FOURCC( 's', 't', 's', 's' )
90 #define ATOM_stsh VLC_FOURCC( 's', 't', 's', 'h' )
91 #define ATOM_stdp VLC_FOURCC( 's', 't', 'd', 'p' )
92 #define ATOM_padb VLC_FOURCC( 'p', 'a', 'd', 'b' )
93 #define ATOM_edts VLC_FOURCC( 'e', 'd', 't', 's' )
94 #define ATOM_elst VLC_FOURCC( 'e', 'l', 's', 't' )
95 #define ATOM_mvex VLC_FOURCC( 'm', 'v', 'e', 'x' )
96 #define ATOM_sdtp VLC_FOURCC( 's', 'd', 't', 'p' )
97 #define ATOM_trex VLC_FOURCC( 't', 'r', 'e', 'x' )
98 #define ATOM_mehd VLC_FOURCC( 'm', 'e', 'h', 'd' )
99 #define ATOM_mfhd VLC_FOURCC( 'm', 'f', 'h', 'd' )
100 #define ATOM_traf VLC_FOURCC( 't', 'r', 'a', 'f' )
101 #define ATOM_sidx VLC_FOURCC( 's', 'i', 'd', 'x' )
102 #define ATOM_tfhd VLC_FOURCC( 't', 'f', 'h', 'd' )
103 #define ATOM_trun VLC_FOURCC( 't', 'r', 'u', 'n' )
104 #define ATOM_cprt VLC_FOURCC( 'c', 'p', 'r', 't' )
105 #define ATOM_iods VLC_FOURCC( 'i', 'o', 'd', 's' )
106 #define ATOM_pasp VLC_FOURCC( 'p', 'a', 's', 'p' )
107 #define ATOM_mfra VLC_FOURCC( 'm', 'f', 'r', 'a' )
108 #define ATOM_mfro VLC_FOURCC( 'm', 'f', 'r', 'o' )
109 #define ATOM_tfra VLC_FOURCC( 't', 'f', 'r', 'a' )
110 #define ATOM_keys VLC_FOURCC( 'k', 'e', 'y', 's' )
111
112 #define ATOM_nmhd VLC_FOURCC( 'n', 'm', 'h', 'd' )
113 #define ATOM_mp2v VLC_FOURCC( 'm', 'p', '2', 'v' )
114 #define ATOM_mp4v VLC_FOURCC( 'm', 'p', '4', 'v' )
115 #define ATOM_mp4a VLC_FOURCC( 'm', 'p', '4', 'a' )
116 #define ATOM_mp4s VLC_FOURCC( 'm', 'p', '4', 's' )
117 #define ATOM_vide VLC_FOURCC( 'v', 'i', 'd', 'e' )
118 #define ATOM_soun VLC_FOURCC( 's', 'o', 'u', 'n' )
119 #define ATOM_hint VLC_FOURCC( 'h', 'i', 'n', 't' )
120 #define ATOM_hdv2 VLC_FOURCC( 'h', 'd', 'v', '2' )
121
122 #define ATOM_dpnd VLC_FOURCC( 'd', 'p', 'n', 'd' )
123 #define ATOM_ipir VLC_FOURCC( 'i', 'p', 'i', 'r' )
124 #define ATOM_mpod VLC_FOURCC( 'm', 'p', 'o', 'd' )
125 #define ATOM_hnti VLC_FOURCC( 'h', 'n', 't', 'i' )
126 #define ATOM_rtp  VLC_FOURCC( 'r', 't', 'p', ' ' )
127
128 #define ATOM_esds VLC_FOURCC( 'e', 's', 'd', 's' )
129
130 #define ATOM_lpcm VLC_FOURCC( 'l', 'p', 'c', 'm' )
131 #define ATOM__mp3 VLC_FOURCC( '.', 'm', 'p', '3' )
132 #define ATOM_ms02 VLC_FOURCC( 'm', 's', 0x0, 0x02 )
133 #define ATOM_ms11 VLC_FOURCC( 'm', 's', 0x0, 0x11 )
134 #define ATOM_ms55 VLC_FOURCC( 'm', 's', 0x0, 0x55 )
135 #define ATOM_twos VLC_FOURCC( 't', 'w', 'o', 's' )
136 #define ATOM_sowt VLC_FOURCC( 's', 'o', 'w', 't' )
137 #define ATOM_QDMC VLC_FOURCC( 'Q', 'D', 'M', 'C' )
138 #define ATOM_QDM2 VLC_FOURCC( 'Q', 'D', 'M', '2' )
139 #define ATOM_ima4 VLC_FOURCC( 'i', 'm', 'a', '4' )
140 #define ATOM_IMA4 VLC_FOURCC( 'I', 'M', 'A', '4' )
141 #define ATOM_dvi  VLC_FOURCC( 'd', 'v', 'i', ' ' )
142 #define ATOM_MAC3 VLC_FOURCC( 'M', 'A', 'C', '3' )
143 #define ATOM_MAC6 VLC_FOURCC( 'M', 'A', 'C', '6' )
144 #define ATOM_alaw VLC_FOURCC( 'a', 'l', 'a', 'w' )
145 #define ATOM_ulaw VLC_FOURCC( 'u', 'l', 'a', 'w' )
146 #define ATOM_Qclp VLC_FOURCC( 'Q', 'c', 'l', 'p' )
147 #define ATOM_samr VLC_FOURCC( 's', 'a', 'm', 'r' )
148 #define ATOM_sawb VLC_FOURCC( 's', 'a', 'w', 'b' )
149 #define ATOM_OggS VLC_FOURCC( 'O', 'g', 'g', 'S' )
150 #define ATOM_alac VLC_FOURCC( 'a', 'l', 'a', 'c' )
151 #define ATOM_ac3  VLC_FOURCC( 'a', 'c', '-', '3' )
152 #define ATOM_eac3 VLC_FOURCC( 'e', 'c', '-', '3' )
153 #define ATOM_dac3 VLC_FOURCC( 'd', 'a', 'c', '3' )
154 #define ATOM_dec3 VLC_FOURCC( 'd', 'e', 'c', '3' )
155 #define ATOM_dvc1 VLC_FOURCC( 'd', 'v', 'c', '1' )
156 #define ATOM_WMA2 VLC_FOURCC( 'W', 'M', 'A', '2' )
157 #define ATOM_enda VLC_FOURCC( 'e', 'n', 'd', 'a' )
158 #define ATOM_gnre VLC_FOURCC( 'g', 'n', 'r', 'e' )
159 #define ATOM_trkn VLC_FOURCC( 't', 'r', 'k', 'n' )
160 #define ATOM_chan VLC_FOURCC( 'c', 'h', 'a', 'n' )
161 #define ATOM_in24 VLC_FOURCC( 'i', 'n', '2', '4' )
162 #define ATOM_in32 VLC_FOURCC( 'i', 'n', '3', '2' )
163 #define ATOM_fl32 VLC_FOURCC( 'f', 'l', '3', '2' )
164 #define ATOM_fl64 VLC_FOURCC( 'f', 'l', '6', '4' )
165
166 #define ATOM_zlib VLC_FOURCC( 'z', 'l', 'i', 'b' )
167 #define ATOM_SVQ1 VLC_FOURCC( 'S', 'V', 'Q', '1' )
168 #define ATOM_SVQ3 VLC_FOURCC( 'S', 'V', 'Q', '3' )
169 #define ATOM_ZyGo VLC_FOURCC( 'Z', 'y', 'G', 'o' )
170 #define ATOM_3IV1 VLC_FOURCC( '3', 'I', 'V', '1' )
171 #define ATOM_3iv1 VLC_FOURCC( '3', 'i', 'v', '1' )
172 #define ATOM_3IV2 VLC_FOURCC( '3', 'I', 'V', '2' )
173 #define ATOM_3iv2 VLC_FOURCC( '3', 'i', 'v', '2' )
174 #define ATOM_3IVD VLC_FOURCC( '3', 'I', 'V', 'D' )
175 #define ATOM_3ivd VLC_FOURCC( '3', 'i', 'v', 'd' )
176 #define ATOM_3VID VLC_FOURCC( '3', 'V', 'I', 'D' )
177 #define ATOM_3vid VLC_FOURCC( '3', 'v', 'i', 'd' )
178 #define ATOM_h263 VLC_FOURCC( 'h', '2', '6', '3' )
179 #define ATOM_s263 VLC_FOURCC( 's', '2', '6', '3' )
180 #define ATOM_DIVX VLC_FOURCC( 'D', 'I', 'V', 'X' )
181 #define ATOM_XVID VLC_FOURCC( 'X', 'V', 'I', 'D' )
182 #define ATOM_cvid VLC_FOURCC( 'c', 'v', 'i', 'd' )
183 #define ATOM_mjpa VLC_FOURCC( 'm', 'j', 'p', 'a' )
184 #define ATOM_mjpb VLC_FOURCC( 'm', 'j', 'q', 't' )
185 #define ATOM_mjqt VLC_FOURCC( 'm', 'j', 'h', 't' )
186 #define ATOM_mjht VLC_FOURCC( 'm', 'j', 'p', 'b' )
187 #define ATOM_VP31 VLC_FOURCC( 'V', 'P', '3', '1' )
188 #define ATOM_vp31 VLC_FOURCC( 'v', 'p', '3', '1' )
189 #define ATOM_h264 VLC_FOURCC( 'h', '2', '6', '4' )
190 #define ATOM_qdrw VLC_FOURCC( 'q', 'd', 'r', 'w' )
191 #define ATOM_WMV3 VLC_FOURCC( 'W', 'M', 'V', '3' )
192
193 #define ATOM_avc1 VLC_FOURCC( 'a', 'v', 'c', '1' )
194 #define ATOM_avcC VLC_FOURCC( 'a', 'v', 'c', 'C' )
195 #define ATOM_m4ds VLC_FOURCC( 'm', '4', 'd', 's' )
196
197 #define ATOM_hvcC VLC_FOURCC( 'h', 'v', 'c', 'C' )
198
199 #define ATOM_dvc  VLC_FOURCC( 'd', 'v', 'c', ' ' )
200 #define ATOM_dvp  VLC_FOURCC( 'd', 'v', 'p', ' ' )
201 #define ATOM_dv5n VLC_FOURCC( 'd', 'v', '5', 'n' )
202 #define ATOM_dv5p VLC_FOURCC( 'd', 'v', '5', 'p' )
203 #define ATOM_raw  VLC_FOURCC( 'r', 'a', 'w', ' ' )
204
205 #define ATOM_jpeg VLC_FOURCC( 'j', 'p', 'e', 'g' )
206
207 #define ATOM_yv12 VLC_FOURCC( 'y', 'v', '1', '2' )
208 #define ATOM_yuv2 VLC_FOURCC( 'y', 'u', 'v', '2' )
209
210 #define ATOM_rmra VLC_FOURCC( 'r', 'm', 'r', 'a' )
211 #define ATOM_rmda VLC_FOURCC( 'r', 'm', 'd', 'a' )
212 #define ATOM_rdrf VLC_FOURCC( 'r', 'd', 'r', 'f' )
213 #define ATOM_rmdr VLC_FOURCC( 'r', 'm', 'd', 'r' )
214 #define ATOM_rmvc VLC_FOURCC( 'r', 'm', 'v', 'c' )
215 #define ATOM_rmcd VLC_FOURCC( 'r', 'm', 'c', 'd' )
216 #define ATOM_rmqu VLC_FOURCC( 'r', 'm', 'q', 'u' )
217 #define ATOM_alis VLC_FOURCC( 'a', 'l', 'i', 's' )
218
219 #define ATOM_gmhd VLC_FOURCC( 'g', 'm', 'h', 'd' )
220 #define ATOM_wave VLC_FOURCC( 'w', 'a', 'v', 'e' )
221 #define ATOM_strf VLC_FOURCC( 's', 't', 'r', 'f' )
222
223 #define ATOM_drms VLC_FOURCC( 'd', 'r', 'm', 's' )
224 #define ATOM_sinf VLC_FOURCC( 's', 'i', 'n', 'f' )
225 #define ATOM_schi VLC_FOURCC( 's', 'c', 'h', 'i' )
226 #define ATOM_user VLC_FOURCC( 'u', 's', 'e', 'r' )
227 #define ATOM_key  VLC_FOURCC( 'k', 'e', 'y', ' ' )
228 #define ATOM_iviv VLC_FOURCC( 'i', 'v', 'i', 'v' )
229 #define ATOM_name VLC_FOURCC( 'n', 'a', 'm', 'e' )
230 #define ATOM_priv VLC_FOURCC( 'p', 'r', 'i', 'v' )
231 #define ATOM_drmi VLC_FOURCC( 'd', 'r', 'm', 'i' )
232 #define ATOM_frma VLC_FOURCC( 'f', 'r', 'm', 'a' )
233 #define ATOM_skcr VLC_FOURCC( 's', 'k', 'c', 'r' )
234 #define ATOM_ASF  VLC_FOURCC( 'A', 'S', 'F', ' ' )
235
236 #define ATOM_text VLC_FOURCC( 't', 'e', 'x', 't' )
237 #define ATOM_tx3g VLC_FOURCC( 't', 'x', '3', 'g' )
238 #define ATOM_subp VLC_FOURCC( 's', 'u', 'b', 'p' )
239 #define ATOM_sbtl VLC_FOURCC( 's', 'b', 't', 'l' )
240 #define ATOM_clcp VLC_FOURCC( 'c', 'l', 'c', 'p' )
241 #define ATOM_c608 VLC_FOURCC( 'c', '6', '0', '8' )
242 #define ATOM_c708 VLC_FOURCC( 'c', '7', '0', '8' )
243
244 #define ATOM_0xa9nam VLC_FOURCC( 0xa9, 'n', 'a', 'm' )
245 #define ATOM_0xa9aut VLC_FOURCC( 0xa9, 'a', 'u', 't' )
246 #define ATOM_0xa9cpy VLC_FOURCC( 0xa9, 'c', 'p', 'y' )
247 #define ATOM_0xa9inf VLC_FOURCC( 0xa9, 'i', 'n', 'f' )
248 #define ATOM_0xa9isr VLC_FOURCC( 0xa9, 'i', 's', 'r' )
249 #define ATOM_0xa9lab VLC_FOURCC( 0xa9, 'l', 'a', 'b' )
250 #define ATOM_0xa9lal VLC_FOURCC( 0xa9, 'l', 'a', 'l' )
251 #define ATOM_0xa9ART VLC_FOURCC( 0xa9, 'A', 'R', 'T' )
252 #define ATOM_0xa9des VLC_FOURCC( 0xa9, 'd', 'e', 's' )
253 #define ATOM_0xa9dir VLC_FOURCC( 0xa9, 'd', 'i', 'r' )
254 #define ATOM_0xa9cmt VLC_FOURCC( 0xa9, 'c', 'm', 't' )
255 #define ATOM_0xa9req VLC_FOURCC( 0xa9, 'r', 'e', 'q' )
256 #define ATOM_0xa9day VLC_FOURCC( 0xa9, 'd', 'a', 'y' )
257 #define ATOM_0xa9fmt VLC_FOURCC( 0xa9, 'f', 'm', 't' )
258 #define ATOM_0xa9prd VLC_FOURCC( 0xa9, 'p', 'r', 'd' )
259 #define ATOM_0xa9prf VLC_FOURCC( 0xa9, 'p', 'r', 'f' )
260 #define ATOM_0xa9src VLC_FOURCC( 0xa9, 's', 'r', 'c' )
261 #define ATOM_0xa9alb VLC_FOURCC( 0xa9, 'a', 'l', 'b' )
262 #define ATOM_0xa9dis VLC_FOURCC( 0xa9, 'd', 'i', 's' )
263 #define ATOM_0xa9enc VLC_FOURCC( 0xa9, 'e', 'n', 'c' )
264 #define ATOM_0xa9trk VLC_FOURCC( 0xa9, 't', 'r', 'k' )
265 #define ATOM_0xa9url VLC_FOURCC( 0xa9, 'u', 'r', 'l' )
266 #define ATOM_0xa9dsa VLC_FOURCC( 0xa9, 'd', 's', 'a' )
267 #define ATOM_0xa9hst VLC_FOURCC( 0xa9, 'h', 's', 't' )
268 #define ATOM_0xa9ope VLC_FOURCC( 0xa9, 'o', 'p', 'e' )
269 #define ATOM_0xa9wrt VLC_FOURCC( 0xa9, 'w', 'r', 't' )
270 #define ATOM_0xa9com VLC_FOURCC( 0xa9, 'c', 'o', 'm' )
271 #define ATOM_0xa9gen VLC_FOURCC( 0xa9, 'g', 'e', 'n' )
272 #define ATOM_0xa9too VLC_FOURCC( 0xa9, 't', 'o', 'o' )
273 #define ATOM_0xa9wrn VLC_FOURCC( 0xa9, 'w', 'r', 'n' )
274 #define ATOM_0xa9swr VLC_FOURCC( 0xa9, 's', 'w', 'r' )
275 #define ATOM_0xa9mak VLC_FOURCC( 0xa9, 'm', 'a', 'k' )
276 #define ATOM_0xa9mal VLC_FOURCC( 0xa9, 'm', 'a', 'l' )
277 #define ATOM_0xa9mod VLC_FOURCC( 0xa9, 'm', 'o', 'd' )
278 #define ATOM_0xa9PRD VLC_FOURCC( 0xa9, 'P', 'R', 'D' )
279 #define ATOM_0xa9grp VLC_FOURCC( 0xa9, 'g', 'r', 'p' )
280 #define ATOM_0xa9lyr VLC_FOURCC( 0xa9, 'l', 'y', 'r' )
281 #define ATOM_0xa9gen VLC_FOURCC( 0xa9, 'g', 'e', 'n' )
282 #define ATOM_0xa9st3 VLC_FOURCC( 0xa9, 's', 't', '3' )
283 #define ATOM_0xa9ard VLC_FOURCC( 0xa9, 'a', 'r', 'd' )
284 #define ATOM_0xa9arg VLC_FOURCC( 0xa9, 'a', 'r', 'g' )
285 #define ATOM_0xa9cak VLC_FOURCC( 0xa9, 'c', 'a', 'k' )
286 #define ATOM_0xa9con VLC_FOURCC( 0xa9, 'c', 'o', 'n' )
287 #define ATOM_0xa9des VLC_FOURCC( 0xa9, 'd', 'e', 's' )
288 #define ATOM_0xa9lnt VLC_FOURCC( 0xa9, 'l', 'n', 't' )
289 #define ATOM_0xa9phg VLC_FOURCC( 0xa9, 'p', 'h', 'g' )
290 #define ATOM_0xa9pub VLC_FOURCC( 0xa9, 'p', 'u', 'b' )
291 #define ATOM_0xa9sne VLC_FOURCC( 0xa9, 's', 'n', 'e' )
292 #define ATOM_0xa9snm VLC_FOURCC( 0xa9, 's', 'n', 'm' )
293 #define ATOM_0xa9sol VLC_FOURCC( 0xa9, 's', 'o', 'l' )
294 #define ATOM_0xa9thx VLC_FOURCC( 0xa9, 't', 'h', 'x' )
295 #define ATOM_0xa9xpd VLC_FOURCC( 0xa9, 'x', 'p', 'd' )
296 #define ATOM_0xa9xyz VLC_FOURCC( 0xa9, 'x', 'y', 'z' )
297 #define ATOM_aART VLC_FOURCC( 'a', 'A', 'R', 'T' )
298 #define ATOM_chpl VLC_FOURCC( 'c', 'h', 'p', 'l' )
299 #define ATOM_disk VLC_FOURCC( 'd', 'i', 's', 'k' )
300 #define ATOM_WLOC VLC_FOURCC( 'W', 'L', 'O', 'C' )
301
302 #define ATOM_meta VLC_FOURCC( 'm', 'e', 't', 'a' )
303 #define ATOM_atID VLC_FOURCC( 'a', 't', 'I', 'D' )
304 #define ATOM_ilst VLC_FOURCC( 'i', 'l', 's', 't' )
305 #define ATOM_cnID VLC_FOURCC( 'c', 'n', 'I', 'D' )
306 #define ATOM_covr VLC_FOURCC( 'c', 'o', 'v', 'r' )
307 #define ATOM_flvr VLC_FOURCC( 'f', 'l', 'v', 'r' )
308 #define ATOM_rtng VLC_FOURCC( 'r', 't', 'n', 'g' )
309 #define ATOM_tsel VLC_FOURCC( 't', 's', 'e', 'l' )
310 #define ATOM_xid_ VLC_FOURCC( 'x', 'i', 'd', ' ' )
311
312 #define ATOM_0x40PRM VLC_FOURCC( '@', 'P', 'R', 'M' )
313 #define ATOM_0x40PRQ VLC_FOURCC( '@', 'P', 'R', 'Q' )
314 #define ATOM_chap VLC_FOURCC( 'c', 'h', 'a', 'p' )
315 #define ATOM_MCPS VLC_FOURCC( 'M', 'C', 'P', 'S' )
316 #define ATOM_SDLN VLC_FOURCC( 'S', 'D', 'L', 'N' )
317 #define ATOM_vndr VLC_FOURCC( 'v', 'n', 'd', 'r' )
318
319 #define HANDLER_mdta VLC_FOURCC('m', 'd', 't', 'a')
320 #define HANDLER_mdir VLC_FOURCC('m', 'd', 'i', 'r')
321
322 /* Do you want some debug information on all read boxes ? */
323 #ifndef NDEBUG
324 # define MP4_VERBOSE  1
325 //# define MP4_ULTRA_VERBOSE  1
326 #endif
327
328 struct MP4_Box_s;
329
330 #define MP4_MFRO_BOXSIZE 16
331
332 /* uuid Universal Unique IDentifiers */
333 typedef struct UUID_s
334 {
335     uint8_t b[16];
336 } UUID_t;
337
338 /* specific structure for all boxes */
339
340 typedef struct MP4_Box_data_tfxd_s
341 {
342     uint8_t  i_version;
343     uint32_t i_flags;
344
345     uint64_t i_fragment_duration;
346     uint64_t i_fragment_abs_time;
347
348 } MP4_Box_data_tfxd_t;
349
350 typedef struct TfrfBoxDataFields_s
351 {
352     uint64_t i_fragment_duration;
353     uint64_t i_fragment_abs_time;
354
355 } TfrfBoxDataFields_t;
356
357 typedef struct MP4_Box_data_tfrf_s
358 {
359     uint8_t  i_version;
360     uint8_t  i_fragment_count;
361     uint32_t i_flags;
362
363     TfrfBoxDataFields_t *p_tfrf_data_fields;
364
365 } MP4_Box_data_tfrf_t;
366
367 typedef struct MP4_Box_data_ftyp_s
368 {
369     uint32_t i_major_brand;
370     uint32_t i_minor_version;
371
372     uint32_t i_compatible_brands_count;
373     uint32_t *i_compatible_brands;
374
375 } MP4_Box_data_ftyp_t;
376
377 typedef struct MP4_Box_data_mvhd_s
378 {
379     uint8_t  i_version;
380     uint32_t i_flags;
381
382     uint64_t i_creation_time;
383     uint64_t i_modification_time;
384     uint32_t i_timescale;
385     uint64_t i_duration;
386
387     int32_t  i_rate;
388     int16_t  i_volume;
389     int16_t  i_reserved1;
390     uint32_t i_reserved2[2];
391     int32_t  i_matrix[9];
392     uint32_t i_predefined[6];
393     uint32_t i_next_track_id;
394
395 } MP4_Box_data_mvhd_t;
396
397 #define MP4_TRACK_ENABLED    0x000001
398 #define MP4_TRACK_IN_MOVIE   0x000002
399 #define MP4_TRACK_IN_PREVIEW 0x000004
400 typedef struct MP4_Box_data_tkhd_s
401 {
402     uint8_t  i_version;
403     uint32_t i_flags;
404
405     uint64_t i_creation_time;
406     uint64_t i_modification_time;
407     uint32_t i_track_ID;
408     uint32_t i_reserved;
409     uint64_t i_duration;
410
411     uint32_t i_reserved2[2];
412     int16_t  i_layer;
413     int16_t  i_predefined;
414
415     int16_t  i_volume;
416     uint16_t i_reserved3;
417     int32_t  i_matrix[9];
418     int32_t  i_width;
419     int32_t  i_height;
420     float    f_rotation;
421
422 } MP4_Box_data_tkhd_t;
423
424 typedef struct
425 {
426     uint32_t i_start_time;
427     int32_t  i_duration;
428     uint32_t i_flags;
429     uint32_t i_hints;
430 } MP4_Box_data_load_t;
431
432 typedef struct MP4_Box_data_mdhd_s
433 {
434     uint8_t  i_version;
435     uint32_t i_flags;
436
437     uint64_t i_creation_time;
438     uint64_t i_modification_time;
439     uint32_t i_timescale;
440     uint64_t i_duration;
441
442     char     rgs_language[3]; /* ISO-639-2/T or Mac lang table */
443     bool     b_mac_encoding;  /* media using mac encoding */
444
445     uint16_t i_quality;
446
447 } MP4_Box_data_mdhd_t;
448
449 typedef struct MP4_Box_data_hdlr_s
450 {
451     uint8_t  i_version;
452     uint32_t i_flags;
453
454     uint32_t i_predefined;
455     uint32_t i_handler_type; /* "vide" "soun" "hint" "odsm"
456                            "crsm" "sdsm" "m7sm" "ocsm"
457                            "ipsm" "mjsm" */
458
459     unsigned char *psz_name; /* in UTF-8 */
460
461 } MP4_Box_data_hdlr_t;
462
463 typedef struct MP4_Box_data_vmhd_s
464 {
465     uint8_t  i_version;
466     uint32_t i_flags;
467
468     int16_t  i_graphics_mode;
469     int16_t  i_opcolor[3];
470
471 } MP4_Box_data_vmhd_t;
472
473 typedef struct MP4_Box_data_smhd_s
474 {
475     uint8_t  i_version;
476     uint32_t i_flags;
477
478     int16_t  i_balance;
479     int16_t  i_reserved;
480
481 } MP4_Box_data_smhd_t;
482
483 typedef struct MP4_Box_data_hmhd_s
484 {
485     uint8_t  i_version;
486     uint32_t i_flags;
487
488     uint16_t i_max_PDU_size;
489     uint16_t i_avg_PDU_size;
490     uint32_t i_max_bitrate;
491     uint32_t i_avg_bitrate;
492     uint32_t i_reserved;
493
494 } MP4_Box_data_hmhd_t;
495
496 typedef struct MP4_Box_data_url_s
497 {
498     uint8_t  i_version;
499     uint32_t i_flags;
500
501     char *psz_location;
502
503 } MP4_Box_data_url_t;
504
505 typedef struct MP4_Box_data_urn_s
506 {
507     uint8_t  i_version;
508     uint32_t i_flags;
509
510     char *psz_name;
511     char *psz_location;
512
513 } MP4_Box_data_urn_t;
514
515 typedef struct MP4_Box_data_dref_s
516 {
517     uint8_t  i_version;
518     uint32_t i_flags;
519
520     uint32_t i_entry_count;
521 /* XXX it's also a container with i_entry_count entry */
522 } MP4_Box_data_dref_t;
523
524 typedef struct MP4_Box_data_stts_s
525 {
526     uint8_t  i_version;
527     uint32_t i_flags;
528
529     uint32_t i_entry_count;
530     uint32_t *pi_sample_count; /* these are array */
531     int32_t  *pi_sample_delta;
532
533 } MP4_Box_data_stts_t;
534
535 typedef struct MP4_Box_data_ctts_s
536 {
537     uint8_t  i_version;
538     uint32_t i_flags;
539
540     uint32_t i_entry_count;
541
542     uint32_t *pi_sample_count; /* these are array */
543     int32_t *pi_sample_offset;
544
545 } MP4_Box_data_ctts_t;
546
547
548 typedef struct MP4_Box_data_sample_soun_s
549 {
550     uint8_t  i_reserved1[6];
551     uint16_t i_data_reference_index;
552
553     //uint32_t i_reserved2[2];
554     uint16_t i_qt_version;
555     uint16_t i_qt_revision_level;
556     uint32_t i_qt_vendor;
557
558     uint16_t i_channelcount;
559     uint16_t i_samplesize;
560     uint16_t i_compressionid;
561     uint16_t i_reserved3;
562     uint16_t i_sampleratehi; /* timescale of track */
563     uint16_t i_sampleratelo;
564
565     /* for version 1 (i_reserved1[0] == 1) */
566     uint32_t i_sample_per_packet;
567     uint32_t i_bytes_per_packet;
568     uint32_t i_bytes_per_frame;
569     uint32_t i_bytes_per_sample;
570
571     /* v2 */
572     uint32_t i_constbitsperchannel; /* consts are nonzero only if constant */
573     uint32_t i_formatflags;
574     uint32_t i_constbytesperaudiopacket;
575     uint32_t i_constLPCMframesperaudiopacket;
576
577     /* XXX hack */
578     int     i_qt_description;
579     uint8_t *p_qt_description;
580
581 } MP4_Box_data_sample_soun_t;
582
583 typedef struct MP4_Box_data_sample_vide_s
584 {
585     uint8_t  i_reserved1[6];
586     uint16_t i_data_reference_index;
587
588     uint16_t i_qt_version;
589     uint16_t i_qt_revision_level;
590     uint32_t i_qt_vendor;
591
592     uint32_t i_qt_temporal_quality;
593     uint32_t i_qt_spatial_quality;
594
595     int16_t  i_width;
596     int16_t  i_height;
597
598     uint32_t i_horizresolution;
599     uint32_t i_vertresolution;
600
601     uint32_t i_qt_data_size;
602     uint16_t i_qt_frame_count;
603
604     uint8_t  i_compressorname[32];
605     int16_t  i_depth;
606
607     int16_t  i_qt_color_table;
608
609     /* XXX hack ImageDescription */
610     int     i_qt_image_description;
611     uint8_t *p_qt_image_description;
612
613 } MP4_Box_data_sample_vide_t;
614
615 #define MP4_TEXT_DISPLAY_FLAG_DONT_DISPLAY       (1<<0)
616 #define MP4_TEXT_DISPLAY_FLAG_AUTO_SCALE         (1<<1)
617 #define MP4_TEXT_DISPLAY_FLAG_CLIP_TO_TEXT_BOX   (1<<2)
618 #define MP4_TEXT_DISPLAY_FLAG_USE_MOVIE_BG_COLOR (1<<3)
619 #define MP4_TEXT_DISPLAY_FLAG_SHRINK_TEXT_BOX_TO_FIT (1<<4)
620 #define MP4_TEXT_DISPLAY_FLAG_SCROLL_IN          (1<<5)
621 #define MP4_TEXT_DISPLAY_FLAG_SCROLL_OUT         (1<<6)
622 #define MP4_TEXT_DISPLAY_FLAG_HORIZONTAL_SCROLL  (1<<7)
623 #define MP4_TEXT_DISPLAY_FLAG_REVERSE_SCROLL     (1<<8)
624 #define MP4_TEXT_DISPLAY_FLAG_CONTINUOUS_SCROLL  (1<<9)
625 #define MP4_TEXT_DISPLAY_FLAG_FLOW_HORIZONTAL    (1<<10)
626 #define MP4_TEXT_DISPLAY_FLAG_CONTINUOUS_KARAOKE (1<<11)
627 #define MP4_TEXT_DISPLAY_FLAG_DROP_SHADOW        (1<<12)
628 #define MP4_TEXT_DISPLAY_FLAG_ANTI_ALIAS         (1<<13)
629 #define MP4_TEXT_DISPLAY_FLAG_KEYED_TEXT         (1<<14)
630 #define MP4_TEXT_DISPLAY_FLAG_INVERSE_HILITE     (1<<15)
631 #define MP4_TEXT_DISPLAY_FLAG_COLOR_HILITE       (1<<16)
632 #define MP4_TEXT_DISPLAY_FLAG_WRITE_VERTICALLY   (1<<17)
633
634 typedef struct
635 {
636     uint32_t i_reserved1;
637     uint16_t i_reserved2;
638
639     uint16_t i_data_reference_index;
640
641     uint32_t i_display_flags;   // TextDescription and Tx3gDescription
642
643     int8_t i_justification_horizontal; // left(0), centered(1), right(-1)
644     int8_t i_justification_vertical;   // top(0), centered(1), bottom(-1)
645
646     uint16_t i_background_color[4];
647
648     uint16_t i_text_box_top;
649     uint16_t i_text_box_left;
650     uint16_t i_text_box_bottom;
651     uint16_t i_text_box_right;
652
653     uint32_t i_reserved3;
654
655     uint16_t i_font_id;
656     uint8_t  i_font_face;
657     uint8_t  i_font_size;
658     uint32_t i_font_color; //RGBA
659
660     // TODO to complete
661 } MP4_Box_data_sample_text_t;
662
663 typedef struct MP4_Box_data_sample_hint_s
664 {
665     uint8_t  i_reserved1[6];
666     uint16_t i_data_reference_index;
667
668     uint8_t *p_data;
669
670 } MP4_Box_data_sample_hint_t;
671
672 typedef struct MP4_Box_data_moviehintinformation_rtp_s
673 {
674     uint32_t i_description_format;
675     unsigned char *psz_text;
676
677 } MP4_Box_data_moviehintinformation_rtp_t;
678
679
680
681 typedef struct MP4_Box_data_stsd_s
682 {
683     uint8_t  i_version;
684     uint32_t i_flags;
685
686     uint32_t i_entry_count;
687
688     /* it contains SampleEntry handled as if it was Box */
689
690 } MP4_Box_data_stsd_t;
691
692
693 typedef struct MP4_Box_data_stsz_s
694 {
695     uint8_t  i_version;
696     uint32_t i_flags;
697
698     uint32_t i_sample_size;
699     uint32_t i_sample_count;
700
701     uint32_t *i_entry_size; /* array , empty if i_sample_size != 0 */
702
703 } MP4_Box_data_stsz_t;
704
705 typedef struct MP4_Box_data_stz2_s
706 {
707     uint8_t  i_version;
708     uint32_t i_flags;
709
710     uint32_t i_sample_size; /* 24 bits */
711     uint8_t  i_field_size;
712     uint32_t i_sample_count;
713
714     uint32_t *i_entry_size; /* array: unsigned int(i_field_size) entry_size */
715
716 } MP4_Box_data_stz2_t;
717
718 typedef struct MP4_Box_data_stsc_s
719 {
720     uint8_t  i_version;
721     uint32_t i_flags;
722
723     uint32_t i_entry_count;
724
725     uint32_t *i_first_chunk; /* theses are arrays */
726     uint32_t *i_samples_per_chunk;
727     uint32_t *i_sample_description_index;
728
729 } MP4_Box_data_stsc_t;
730
731
732 typedef struct MP4_Box_data_co64_s
733 {
734     uint8_t  i_version;
735     uint32_t i_flags;
736
737     uint32_t i_entry_count;
738
739     uint64_t *i_chunk_offset;
740
741 } MP4_Box_data_co64_t;
742
743
744 typedef struct MP4_Box_data_stss_s
745 {
746     uint8_t  i_version;
747     uint32_t i_flags;
748
749     uint32_t i_entry_count;
750
751     uint32_t *i_sample_number;
752
753 } MP4_Box_data_stss_t;
754
755 typedef struct MP4_Box_data_stsh_s
756 {
757     uint8_t  i_version;
758     uint32_t i_flags;
759
760     uint32_t i_entry_count;
761
762     uint32_t *i_shadowed_sample_number;
763     uint32_t *i_sync_sample_number;
764
765 } MP4_Box_data_stsh_t;
766
767 typedef struct MP4_Box_data_stdp_s
768 {
769     uint8_t  i_version;
770     uint32_t i_flags;
771
772     uint16_t *i_priority;
773
774 } MP4_Box_data_stdp_t;
775
776 typedef struct MP4_Box_data_padb_s
777 {
778     uint8_t  i_version;
779     uint32_t i_flags;
780
781     uint32_t i_sample_count;
782
783     uint16_t *i_reserved1;   /* 1bit  */
784     uint16_t *i_pad2;        /* 3bits */
785     uint16_t *i_reserved2;   /* 1bit  */
786     uint16_t *i_pad1;        /* 3bits */
787
788
789 } MP4_Box_data_padb_t;
790
791
792 typedef struct MP4_Box_data_elst_s
793 {
794     uint8_t  i_version;
795     uint32_t i_flags;
796
797     uint32_t i_entry_count;
798
799     uint64_t *i_segment_duration;
800     int64_t  *i_media_time;
801     uint16_t *i_media_rate_integer;
802     uint16_t *i_media_rate_fraction;
803
804
805 } MP4_Box_data_elst_t;
806
807 typedef struct MP4_Box_data_cprt_s
808 {
809     uint8_t  i_version;
810     uint32_t i_flags;
811
812     char     rgs_language[3]; /* ISO-639-2/T */
813
814     char *psz_notice;
815 } MP4_Box_data_cprt_t;
816
817
818 /* DecoderConfigDescriptor */
819 typedef struct MP4_descriptor_decoder_config_s
820 {
821     uint8_t i_objectProfileIndication;
822     uint8_t i_streamType;
823     int     b_upStream;
824     int     i_buffer_sizeDB;
825     int     i_max_bitrate;
826     int     i_avg_bitrate;
827
828     int     i_decoder_specific_info_len;
829     uint8_t *p_decoder_specific_info;
830     /* some other stuff */
831
832 } MP4_descriptor_decoder_config_t;
833
834 typedef struct MP4_descriptor_SL_config_s
835 {
836
837     int i_dummy; /* ANSI C forbids empty structures */
838
839 } MP4_descriptor_SL_config_t;
840
841
842 typedef struct MP4_descriptor_ES_s
843 {
844     uint16_t i_ES_ID;
845     int      b_stream_dependence;
846     int      b_url;
847     int      b_OCRstream;
848     int      i_stream_priority;
849
850     int      i_depend_on_ES_ID; /* if b_stream_dependence set */
851
852     unsigned char *psz_URL;
853
854     uint16_t i_OCR_ES_ID;       /* if b_OCRstream */
855     MP4_descriptor_decoder_config_t *p_decConfigDescr;
856
857     MP4_descriptor_SL_config_t *p_slConfigDescr;
858
859     /* some other stuff ... */
860
861 } MP4_descriptor_ES_t;
862
863 /* ES descriptor */
864 typedef struct MP4_Box_data_esds_s
865 {
866     uint8_t  i_version;
867     uint32_t i_flags;
868
869     MP4_descriptor_ES_t es_descriptor;
870
871 } MP4_Box_data_esds_t;
872
873
874 typedef struct MP4_Box_data_dcom_s
875 {
876     uint32_t i_algorithm; /* fourcc */
877
878 } MP4_Box_data_dcom_t;
879
880 typedef struct MP4_Box_data_cmvd_s
881 {
882     uint32_t i_uncompressed_size;
883     uint32_t i_compressed_size;
884
885     int     b_compressed; /* Set to 1 if compressed data, 0 if uncompressed */
886     uint8_t *p_data;
887
888 } MP4_Box_data_cmvd_t;
889
890 typedef struct MP4_Box_data_cmov_s
891 {
892     struct MP4_Box_s *p_moov; /* uncompressed moov */
893
894 } MP4_Box_data_cmov_t;
895
896 typedef struct
897 {
898     uint32_t i_type;
899 } MP4_Box_data_frma_t;
900
901 typedef struct
902 {
903     uint32_t i_init;
904     uint32_t i_encr;
905     uint32_t i_decr;
906 } MP4_Box_data_skcr_t;
907
908 typedef struct
909 {
910     uint8_t  i_version;
911     uint32_t i_flags;
912
913     uint32_t i_ref_type;
914     char     *psz_ref;
915
916 } MP4_Box_data_rdrf_t;
917
918 typedef struct
919 {
920     uint8_t  i_version;
921     uint32_t i_flags;
922
923     uint32_t i_rate;
924
925 } MP4_Box_data_rmdr_t;
926
927 typedef struct
928 {
929     uint8_t  i_version;
930     uint32_t i_flags;
931
932     uint32_t i_gestaltType;
933     uint32_t i_val1;
934     uint32_t i_val2;
935     uint16_t i_checkType;   /* 0: val1 is version min
936                                1: gestalt value & val2 == val1 */
937
938 } MP4_Box_data_rmvc_t;
939
940 typedef struct
941 {
942     uint8_t  i_version;
943     uint32_t i_flags;
944
945
946 } MP4_Box_data_rmcd_t;
947
948 typedef struct
949 {
950     uint32_t i_quality;
951
952 } MP4_Box_data_rmqu_t;
953
954 typedef struct MP4_Box_data_mfhd_s
955 {
956     uint8_t  i_version;
957     uint32_t i_flags;
958
959     uint32_t i_sequence_number;
960
961 } MP4_Box_data_mfhd_t;
962
963 typedef struct MP4_Box_sidx_item_s
964 {
965     bool     b_reference_type;
966     uint32_t i_referenced_size;
967     uint32_t i_subsegment_duration;
968     bool     b_starts_with_SAP;
969     uint8_t  i_SAP_type;
970     uint32_t i_SAP_delta_time;
971
972 } MP4_Box_sidx_item_t;
973
974 typedef struct MP4_Box_data_sidx_s
975 {
976     uint8_t  i_version;
977     uint32_t i_flags;
978
979     uint32_t i_reference_ID;
980     uint32_t i_timescale;
981     uint64_t i_earliest_presentation_time;
982     uint64_t i_first_offset;
983     uint16_t i_reference_count;
984
985     MP4_Box_sidx_item_t *p_items;
986
987 } MP4_Box_data_sidx_t;
988
989 #define MP4_TFHD_BASE_DATA_OFFSET     (1LL<<0)
990 #define MP4_TFHD_SAMPLE_DESC_INDEX    (1LL<<1)
991 #define MP4_TFHD_DFLT_SAMPLE_DURATION (1LL<<3)
992 #define MP4_TFHD_DFLT_SAMPLE_SIZE     (1LL<<4)
993 #define MP4_TFHD_DFLT_SAMPLE_FLAGS    (1LL<<5)
994 #define MP4_TFHD_DURATION_IS_EMPTY    (1LL<<16)
995 #define MP4_TFHD_DEFAULT_BASE_IS_MOOF (1LL<<17)
996 typedef struct MP4_Box_data_tfhd_s
997 {
998     uint8_t  i_version;
999     bool     b_empty;
1000     uint32_t i_flags;
1001     uint32_t i_track_ID;
1002
1003     /* optional fields */
1004     uint64_t i_base_data_offset;
1005     uint32_t i_sample_description_index;
1006     uint32_t i_default_sample_duration;
1007     uint32_t i_default_sample_size;
1008     uint32_t i_default_sample_flags;
1009
1010 } MP4_Box_data_tfhd_t;
1011
1012 #define MP4_TRUN_DATA_OFFSET         (1<<0)
1013 #define MP4_TRUN_FIRST_FLAGS         (1<<2)
1014 #define MP4_TRUN_SAMPLE_DURATION     (1<<8)
1015 #define MP4_TRUN_SAMPLE_SIZE         (1<<9)
1016 #define MP4_TRUN_SAMPLE_FLAGS        (1<<10)
1017 #define MP4_TRUN_SAMPLE_TIME_OFFSET  (1<<11)
1018 typedef struct MP4_descriptor_trun_sample_t
1019 {
1020     uint32_t i_duration;
1021     uint32_t i_size;
1022     uint32_t i_flags;
1023     uint32_t i_composition_time_offset; /* version == 0 ? signed : unsigned */
1024 } MP4_descriptor_trun_sample_t;
1025
1026 typedef struct MP4_Box_data_trun_s
1027 {
1028     uint8_t  i_version;
1029     uint32_t i_flags;
1030     uint32_t i_sample_count;
1031
1032     /* optional fields */
1033     int32_t i_data_offset;
1034     uint32_t i_first_sample_flags;
1035
1036     MP4_descriptor_trun_sample_t *p_samples;
1037
1038 } MP4_Box_data_trun_t;
1039
1040 typedef struct
1041 {
1042     uint32_t i_date;
1043     uint32_t i_type;
1044     uint16_t i_index;
1045 } MP4_Box_data_pnot_t;
1046
1047 typedef struct
1048 {
1049     char *psz_text;
1050
1051 } MP4_Box_data_string_t;
1052
1053 typedef struct
1054 {
1055     uint8_t *p_blob;
1056     uint32_t i_blob;
1057 } MP4_Box_data_binary_t;
1058
1059 typedef struct
1060 {
1061     uint32_t i_entry_count;
1062     uint32_t *i_track_ID;
1063
1064 } MP4_Box_data_tref_generic_t;
1065
1066 typedef struct
1067 {
1068     uint8_t  i_version;
1069     uint32_t i_flags;
1070
1071     uint8_t i_chapter;
1072     struct
1073     {
1074         char    *psz_name;
1075         int64_t  i_start;
1076     } chapter[256];
1077 } MP4_Box_data_chpl_t;
1078
1079 typedef struct
1080 {
1081     uint8_t i_version;
1082     uint8_t i_profile;
1083     uint8_t i_profile_compatibility;
1084     uint8_t i_level;
1085
1086     uint8_t i_reserved1;     /* 6 bits */
1087     uint8_t i_length_size;
1088
1089     uint8_t i_reserved2;    /* 3 bits */
1090     uint8_t  i_sps;
1091     uint16_t *i_sps_length;
1092     uint8_t  **sps;
1093
1094     uint8_t  i_pps;
1095     uint16_t *i_pps_length;
1096     uint8_t  **pps;
1097
1098     /* XXX: Hack raw avcC atom payload */
1099     int     i_avcC;
1100     uint8_t *p_avcC;
1101
1102 } MP4_Box_data_avcC_t;
1103
1104 typedef struct
1105 {
1106     WAVEFORMATEX Format;
1107     uint32_t i_extra;
1108     char    *p_extra;
1109 } MP4_Box_data_WMA2_t;
1110
1111 typedef struct
1112 {
1113     VLC_BITMAPINFOHEADER bmiHeader;
1114     uint32_t i_extra;
1115     char    *p_extra;
1116 } MP4_Box_data_strf_t;
1117
1118 typedef struct
1119 {
1120     uint8_t i_stream_number;
1121 } MP4_Box_data_ASF_t;
1122
1123 /* According to Apple's CoreAudio/CoreAudioTypes.h */
1124 #define MP4_CHAN_USE_CHANNELS_DESC           0
1125 #define MP4_CHAN_USE_CHANNELS_BITMAP         (1<<16)
1126
1127 #define MP4_CHAN_BITMAP_LEFT                 (1<<0)
1128 #define MP4_CHAN_BITMAP_RIGHT                (1<<1)
1129 #define MP4_CHAN_BITMAP_CENTER               (1<<2)
1130 #define MP4_CHAN_BITMAP_LFESCREEN            (1<<3)
1131 #define MP4_CHAN_BITMAP_BACKLEFT             (1<<4)
1132 #define MP4_CHAN_BITMAP_BACKRIGHT            (1<<5)
1133 #define MP4_CHAN_BITMAP_LEFTCENTER           (1<<6)
1134 #define MP4_CHAN_BITMAP_RIGHTCENTER          (1<<7)
1135 #define MP4_CHAN_BITMAP_BACKCENTER           (1<<8)
1136 #define MP4_CHAN_BITMAP_SIDELEFT             (1<<9)
1137 #define MP4_CHAN_BITMAP_SIDERIGHT            (1<<10)
1138 #define MP4_CHAN_BITMAP_TOPCENTER            (1<<11)
1139 #define MP4_CHAN_BITMAP_TOPFRONTLEFT         (1<<12)
1140 #define MP4_CHAN_BITMAP_TOPFRONTENTER        (1<<13)
1141 #define MP4_CHAN_BITMAP_TOPFRONTRIGHT        (1<<14)
1142 #define MP4_CHAN_BITMAP_TOPBACKLEFT          (1<<15)
1143 #define MP4_CHAN_BITMAP_TOPBACKCENTER        (1<<16)
1144 #define MP4_CHAN_BITMAP_TOPBACKRIGHT         (1<<17)
1145
1146 #define MP4_CHAN_BITMAP_MAPPING_COUNT 18
1147 static const struct
1148 {
1149     uint32_t i_bitmap;
1150     uint32_t i_vlc;
1151 } chan_bitmap_mapping[MP4_CHAN_BITMAP_MAPPING_COUNT] = {
1152     { MP4_CHAN_BITMAP_LEFT,         AOUT_CHAN_LEFT },
1153     { MP4_CHAN_BITMAP_RIGHT,        AOUT_CHAN_RIGHT },
1154     { MP4_CHAN_BITMAP_CENTER,       AOUT_CHAN_CENTER },
1155     { MP4_CHAN_BITMAP_LFESCREEN,    AOUT_CHAN_LFE },
1156     { MP4_CHAN_BITMAP_BACKLEFT,     AOUT_CHAN_REARLEFT },
1157     { MP4_CHAN_BITMAP_BACKRIGHT,    AOUT_CHAN_REARRIGHT },
1158     { MP4_CHAN_BITMAP_LEFTCENTER,   AOUT_CHAN_MIDDLELEFT },
1159     { MP4_CHAN_BITMAP_RIGHTCENTER,  AOUT_CHAN_MIDDLERIGHT },
1160     { MP4_CHAN_BITMAP_BACKCENTER,   AOUT_CHAN_REARCENTER },
1161     { MP4_CHAN_BITMAP_SIDELEFT,     AOUT_CHAN_LEFT },
1162     { MP4_CHAN_BITMAP_SIDERIGHT,    AOUT_CHAN_RIGHT },
1163     { MP4_CHAN_BITMAP_TOPCENTER,    AOUT_CHAN_CENTER },
1164     { MP4_CHAN_BITMAP_TOPFRONTLEFT, AOUT_CHAN_LEFT },
1165     { MP4_CHAN_BITMAP_TOPFRONTENTER,AOUT_CHAN_CENTER },
1166     { MP4_CHAN_BITMAP_TOPFRONTRIGHT,AOUT_CHAN_RIGHT },
1167     { MP4_CHAN_BITMAP_TOPBACKLEFT,  AOUT_CHAN_REARLEFT },
1168     { MP4_CHAN_BITMAP_TOPBACKCENTER,AOUT_CHAN_REARCENTER },
1169     { MP4_CHAN_BITMAP_TOPBACKRIGHT, AOUT_CHAN_REARRIGHT },
1170 };
1171
1172 typedef struct
1173 {
1174     uint8_t i_version;
1175     uint32_t i_channels_flags; /* 24 bits */
1176     struct
1177     {
1178         uint32_t i_channels_layout_tag;
1179         uint32_t i_channels_bitmap;
1180         uint32_t i_channels_description_count;
1181         struct
1182         {
1183             uint32_t i_channel_label;
1184             uint32_t i_channel_flags;
1185             float    f_coordinates[3];
1186         } *p_descriptions;
1187     } layout;
1188 } MP4_Box_data_chan_t;
1189
1190 typedef struct
1191 {
1192     uint16_t i_data_rate;
1193     uint8_t i_num_ind_sub;
1194     struct
1195     {
1196         uint8_t i_fscod;
1197         uint8_t i_bsid;
1198         uint8_t i_bsmod;
1199         uint8_t i_acmod;
1200         uint8_t i_lfeon;
1201         uint8_t i_num_dep_sub;
1202         uint16_t i_chan_loc;
1203     } stream[8];
1204
1205 } MP4_Box_data_dec3_t;
1206
1207 typedef struct
1208 {
1209     uint8_t i_fscod;
1210     uint8_t i_bsid;
1211     uint8_t i_bsmod;
1212     uint8_t i_acmod;
1213     uint8_t i_lfeon;
1214     uint8_t i_bitrate_code;
1215
1216 } MP4_Box_data_dac3_t;
1217
1218 typedef struct
1219 {
1220     uint8_t i_profile_level;
1221
1222     int i_vc1;
1223     uint8_t *p_vc1;
1224
1225 } MP4_Box_data_dvc1_t;
1226
1227 typedef struct
1228 {
1229     uint16_t i_little_endian;
1230
1231 } MP4_Box_data_enda_t;
1232
1233 typedef struct
1234 {
1235     uint32_t i_entry_count;
1236     struct
1237     {
1238         uint32_t i_namespace;
1239         char    *psz_value;
1240     } *p_entries;
1241 } MP4_Box_data_keys_t;
1242
1243 typedef struct
1244 {
1245     uint8_t  i_version;
1246     uint32_t i_flags;
1247
1248     uint16_t i_object_descriptor;
1249     uint8_t i_OD_profile_level;
1250     uint8_t i_scene_profile_level;
1251     uint8_t i_audio_profile_level;
1252     uint8_t i_visual_profile_level;
1253     uint8_t i_graphics_profile_level;
1254
1255 } MP4_Box_data_iods_t;
1256
1257 typedef struct
1258 {
1259     uint32_t i_horizontal_spacing;
1260     uint32_t i_vertical_spacing;
1261 } MP4_Box_data_pasp_t;
1262
1263 typedef struct
1264 {
1265     uint8_t  i_version;
1266     uint32_t i_flags;
1267
1268     uint64_t i_fragment_duration;
1269 } MP4_Box_data_mehd_t;
1270
1271 typedef struct
1272 {
1273     uint8_t  i_version;
1274     uint32_t i_flags;
1275
1276     uint32_t i_track_ID;
1277     uint32_t i_default_sample_description_index;
1278     uint32_t i_default_sample_duration;
1279     uint32_t i_default_sample_size;
1280     uint32_t i_default_sample_flags;
1281 } MP4_Box_data_trex_t;
1282
1283 typedef struct
1284 {
1285     uint8_t  i_version;
1286     uint32_t i_flags;
1287
1288     uint8_t *p_sample_table;
1289 } MP4_Box_data_sdtp_t;
1290
1291 typedef struct
1292 {
1293     uint32_t i_switch_group;
1294 } MP4_Box_data_tsel_t;
1295
1296 typedef struct
1297 {
1298     uint8_t  i_version;
1299     uint32_t i_flags;
1300
1301     uint32_t i_size;
1302 } MP4_Box_data_mfro_t;
1303
1304 typedef struct
1305 {
1306     uint8_t  i_version;
1307     uint32_t i_flags;
1308
1309     uint32_t i_track_ID;
1310     uint32_t i_number_of_entries;
1311
1312     uint8_t i_length_size_of_traf_num;
1313     uint8_t i_length_size_of_trun_num;
1314     uint8_t i_length_size_of_sample_num;
1315
1316     uint32_t *p_time;
1317     uint32_t *p_moof_offset;
1318     uint8_t *p_traf_number;
1319     uint8_t *p_trun_number;
1320     uint8_t *p_sample_number;
1321 } MP4_Box_data_tfra_t;
1322
1323 typedef struct
1324 {
1325     uint64_t i_duration;
1326     uint32_t i_timescale;
1327     uint16_t i_track_ID;
1328     uint8_t  i_es_cat;
1329
1330     uint32_t FourCC;
1331     uint32_t Bitrate;
1332     uint32_t MaxWidth;
1333     uint32_t MaxHeight;
1334     uint32_t SamplingRate;
1335     uint32_t Channels;
1336     uint32_t BitsPerSample;
1337     uint32_t AudioTag;
1338     uint16_t nBlockAlign;
1339     uint8_t  cpd_len;
1340     uint8_t  *CodecPrivateData;
1341 } MP4_Box_data_stra_t;
1342
1343 typedef struct
1344 {
1345     uint32_t i_hvcC;
1346     uint8_t *p_hvcC;
1347 } MP4_Box_data_hvcC_t;
1348
1349 typedef struct
1350 {
1351     enum
1352     {
1353         DATA_WKT_RESERVED = 0,
1354         DATA_WKT_UTF8 = 1,
1355         DATA_WKT_UTF16 = 2,
1356         DATA_WKT_SJIS = 3,
1357         DATA_WKT_UTF8_SORT = 4,
1358         DATA_WKT_UTF16_SORT = 5,
1359         DATA_WKT_JPEG = 13,
1360         DATA_WKT_PNG = 14,
1361         DATA_WKT_BE_SIGNED = 21,
1362         DATA_WKT_BE_UNSIGNED = 22,
1363         DATA_WKT_BE_FLOAT32 = 23,
1364         DATA_WKT_BE_FLOAT64 = 24,
1365         DATA_WKT_BMP = 27,
1366         DATA_WKT_QUICKTIME_METADATA_ATOM = 28,
1367     } e_wellknowntype;
1368     struct
1369     {
1370         uint16_t i_country;
1371         uint16_t i_language;
1372     } locale;
1373     uint8_t *p_blob;
1374     uint32_t i_blob;
1375 } MP4_Box_data_data_t;
1376
1377 /*
1378 typedef struct MP4_Box_data__s
1379 {
1380     uint8_t  i_version;
1381     uint32_t i_flags;
1382
1383 } MP4_Box_data__t;
1384
1385 */
1386
1387 typedef union MP4_Box_data_s
1388 {
1389     MP4_Box_data_ftyp_t *p_ftyp;
1390     MP4_Box_data_mvhd_t *p_mvhd;
1391     MP4_Box_data_mfhd_t *p_mfhd;
1392     MP4_Box_data_sidx_t *p_sidx;
1393     MP4_Box_data_tfhd_t *p_tfhd;
1394     MP4_Box_data_trun_t *p_trun;
1395     MP4_Box_data_tkhd_t *p_tkhd;
1396     MP4_Box_data_mdhd_t *p_mdhd;
1397     MP4_Box_data_hdlr_t *p_hdlr;
1398     MP4_Box_data_vmhd_t *p_vmhd;
1399     MP4_Box_data_smhd_t *p_smhd;
1400     MP4_Box_data_hmhd_t *p_hmhd;
1401     MP4_Box_data_url_t  *p_url;
1402     MP4_Box_data_urn_t  *p_urn;
1403     MP4_Box_data_dref_t *p_dref;
1404     MP4_Box_data_stts_t *p_stts;
1405     MP4_Box_data_ctts_t *p_ctts;
1406     MP4_Box_data_stsd_t *p_stsd;
1407     MP4_Box_data_sample_vide_t *p_sample_vide;
1408     MP4_Box_data_sample_soun_t *p_sample_soun;
1409     MP4_Box_data_sample_text_t *p_sample_text;
1410     MP4_Box_data_sample_hint_t *p_sample_hint;
1411
1412     MP4_Box_data_esds_t *p_esds;
1413     MP4_Box_data_avcC_t *p_avcC;
1414     MP4_Box_data_dac3_t *p_dac3;
1415     MP4_Box_data_dec3_t *p_dec3;
1416     MP4_Box_data_dvc1_t *p_dvc1;
1417     MP4_Box_data_chan_t *p_chan;
1418     MP4_Box_data_enda_t *p_enda;
1419     MP4_Box_data_keys_t *p_keys;
1420     MP4_Box_data_iods_t *p_iods;
1421     MP4_Box_data_pasp_t *p_pasp;
1422     MP4_Box_data_trex_t *p_trex;
1423     MP4_Box_data_mehd_t *p_mehd;
1424     MP4_Box_data_sdtp_t *p_sdtp;
1425     MP4_Box_data_tsel_t *p_tsel;
1426     MP4_Box_data_load_t *p_load;
1427
1428     MP4_Box_data_tfra_t *p_tfra;
1429     MP4_Box_data_mfro_t *p_mfro;
1430     MP4_Box_data_stra_t *p_stra;
1431
1432     MP4_Box_data_stsz_t *p_stsz;
1433     MP4_Box_data_stz2_t *p_stz2;
1434     MP4_Box_data_stsc_t *p_stsc;
1435     MP4_Box_data_co64_t *p_co64;
1436     MP4_Box_data_stss_t *p_stss;
1437     MP4_Box_data_stsh_t *p_stsh;
1438     MP4_Box_data_stdp_t *p_stdp;
1439     MP4_Box_data_padb_t *p_padb;
1440     MP4_Box_data_elst_t *p_elst;
1441     MP4_Box_data_cprt_t *p_cprt;
1442
1443     MP4_Box_data_dcom_t *p_dcom;
1444     MP4_Box_data_cmvd_t *p_cmvd;
1445     MP4_Box_data_cmov_t *p_cmov;
1446
1447     MP4_Box_data_moviehintinformation_rtp_t p_moviehintinformation_rtp;
1448
1449     MP4_Box_data_frma_t *p_frma;
1450     MP4_Box_data_skcr_t *p_skcr;
1451
1452     MP4_Box_data_rdrf_t *p_rdrf;
1453     MP4_Box_data_rmdr_t *p_rmdr;
1454     MP4_Box_data_rmqu_t *p_rmqu;
1455     MP4_Box_data_rmvc_t *p_rmvc;
1456
1457     MP4_Box_data_pnot_t *p_pnot;
1458     MP4_Box_data_chpl_t *p_chpl;
1459     MP4_Box_data_tref_generic_t *p_tref_generic;
1460
1461     MP4_Box_data_tfrf_t *p_tfrf;
1462     MP4_Box_data_tfxd_t *p_tfxd;
1463     MP4_Box_data_hvcC_t *p_hvcC;
1464     MP4_Box_data_WMA2_t *p_WMA2; /* flip4mac Little endian audio config */
1465     MP4_Box_data_strf_t *p_strf; /* flip4mac Little endian video config */
1466     MP4_Box_data_ASF_t  *p_asf;  /* flip4mac asf streams indicator */
1467
1468     /* for generic handlers */
1469     MP4_Box_data_string_t *p_string;
1470     MP4_Box_data_binary_t *p_binary;
1471     MP4_Box_data_data_t *p_data;
1472
1473     void                *p_payload; /* for unknow type */
1474 } MP4_Box_data_t;
1475
1476 #define BOXDATA(type) type->data.type
1477
1478 typedef struct MP4_Box_s MP4_Box_t;
1479 /* the most basic structure */
1480 struct MP4_Box_s
1481 {
1482     off_t        i_pos;      /* absolute position */
1483
1484     uint32_t     i_type;
1485     uint32_t     i_shortsize;
1486     uint32_t     i_handler;  /**/
1487     uint32_t     i_index;    /* indexed list (ilst) */
1488
1489     enum
1490     {
1491         BOX_FLAG_NONE = 0,
1492         BOX_FLAG_INCOMPLETE,
1493     }            e_flags;
1494
1495     UUID_t       i_uuid;  /* Set if i_type == "uuid" */
1496
1497     uint64_t     i_size; /* always set so use it */
1498
1499     MP4_Box_t *p_father; /* pointer on the father Box */
1500     MP4_Box_t *p_first;  /* pointer on the first child Box */
1501     MP4_Box_t *p_last;
1502     MP4_Box_t *p_next;   /* pointer on the next boxes at the same level */
1503
1504     void (*pf_free)( MP4_Box_t *p_box ); /* pointer to free function for this box */
1505
1506     MP4_Box_data_t   data;   /* union of pointers on extended data depending
1507                                 on i_type (or i_usertype) */
1508 };
1509
1510 static inline size_t mp4_box_headersize( MP4_Box_t *p_box )
1511 {
1512     return 8
1513         + ( p_box->i_shortsize == 1 ? 8 : 0 )
1514         + ( p_box->i_type == ATOM_uuid ? 16 : 0 );
1515 }
1516
1517 #define MP4_GETX_PRIVATE(dst, code, size) do { \
1518     if( (i_read) >= (size) ) { dst = (code); p_peek += (size); } \
1519     else { dst = 0; }   \
1520     i_read -= (size);   \
1521   } while(0)
1522
1523 #define MP4_GET1BYTE( dst )  MP4_GETX_PRIVATE( dst, *p_peek, 1 )
1524 #define MP4_GET2BYTES( dst ) MP4_GETX_PRIVATE( dst, GetWBE(p_peek), 2 )
1525 #define MP4_GET3BYTES( dst ) MP4_GETX_PRIVATE( dst, Get24bBE(p_peek), 3 )
1526 #define MP4_GET4BYTES( dst ) MP4_GETX_PRIVATE( dst, GetDWBE(p_peek), 4 )
1527 #define MP4_GET8BYTES( dst ) MP4_GETX_PRIVATE( dst, GetQWBE(p_peek), 8 )
1528 #define MP4_GETFOURCC( dst ) MP4_GETX_PRIVATE( dst, \
1529                 VLC_FOURCC(p_peek[0],p_peek[1],p_peek[2],p_peek[3]), 4)
1530
1531 #define MP4_GET2BYTESLE( dst ) MP4_GETX_PRIVATE( dst, GetWLE(p_peek), 2 )
1532 #define MP4_GET4BYTESLE( dst ) MP4_GETX_PRIVATE( dst, GetDWLE(p_peek), 4 )
1533 #define MP4_GET8BYTESLE( dst ) MP4_GETX_PRIVATE( dst, GetQWLE(p_peek), 8 )
1534
1535 #define MP4_GETVERSIONFLAGS( p_void ) \
1536     MP4_GET1BYTE( p_void->i_version ); \
1537     MP4_GET3BYTES( p_void->i_flags )
1538
1539 #define MP4_GETSTRINGZ( p_str )         \
1540     if( (i_read > 0) && (p_peek[0]) )   \
1541     {       \
1542         const int __i_copy__ = strnlen( (char*)p_peek, i_read-1 );  \
1543         p_str = malloc( __i_copy__+1 );               \
1544         if( p_str ) \
1545         { \
1546              memcpy( p_str, p_peek, __i_copy__ ); \
1547              p_str[__i_copy__] = 0; \
1548         } \
1549         p_peek += __i_copy__ + 1;   \
1550         i_read -= __i_copy__ + 1;   \
1551     }       \
1552     else    \
1553     {       \
1554         p_str = NULL; \
1555     }
1556
1557 #define MP4_READBOX_ENTER( MP4_Box_data_TYPE_t ) \
1558     int64_t  i_read = p_box->i_size; \
1559     uint8_t *p_peek, *p_buff; \
1560     int i_actually_read; \
1561     if( !( p_peek = p_buff = malloc( i_read ) ) ) \
1562     { \
1563         return( 0 ); \
1564     } \
1565     i_actually_read = stream_Read( p_stream, p_peek, i_read ); \
1566     if( i_actually_read < 0 || (int64_t)i_actually_read < i_read )\
1567     { \
1568         msg_Warn( p_stream, "MP4_READBOX_ENTER: I got %i bytes, "\
1569         "but I requested %" PRId64, i_actually_read, i_read );\
1570         free( p_buff ); \
1571         return( 0 ); \
1572     } \
1573     p_peek += mp4_box_headersize( p_box ); \
1574     i_read -= mp4_box_headersize( p_box ); \
1575     if( !( p_box->data.p_payload = calloc( 1, sizeof( MP4_Box_data_TYPE_t ) ) ) ) \
1576     { \
1577         free( p_buff ); \
1578         return( 0 ); \
1579     }
1580
1581 #define MP4_READBOX_EXIT( i_code ) \
1582     do \
1583     { \
1584         free( p_buff ); \
1585         if( i_read < 0 ) \
1586             msg_Warn( p_stream, "Not enough data" ); \
1587         return( i_code ); \
1588     } while (0)
1589
1590
1591 /* This macro is used when we want to printf the box type
1592  * APPLE annotation box is :
1593  *  either 0xA9 + 24-bit ASCII text string (and 0xA9 isn't printable)
1594  *  either 32-bit ASCII text string
1595  */
1596 #define MP4_BOX_TYPE_ASCII() ( ((char*)&p_box->i_type)[0] != (char)0xA9 )
1597
1598 static inline uint32_t Get24bBE( const uint8_t *p )
1599 {
1600     return( ( p[0] <<16 ) + ( p[1] <<8 ) + p[2] );
1601 }
1602
1603 static inline void GetUUID( UUID_t *p_uuid, const uint8_t *p_buff )
1604 {
1605     memcpy( p_uuid, p_buff, 16 );
1606 }
1607
1608 static inline int CmpUUID( const UUID_t *u1, const UUID_t *u2 )
1609 {
1610     return memcmp( u1, u2, 16 );
1611 }
1612
1613 static inline void CreateUUID( UUID_t *p_uuid, uint32_t i_fourcc )
1614 {
1615     /* made by 0xXXXXXXXX-0011-0010-8000-00aa00389b71
1616             where XXXXXXXX is the fourcc */
1617     /* FIXME implement this */
1618     (void)p_uuid;
1619     (void)i_fourcc;
1620 }
1621
1622 static const UUID_t TfrfBoxUUID = {
1623                 { 0xd4, 0x80, 0x7e, 0xf2, 0xca, 0x39, 0x46, 0x95,
1624                   0x8e, 0x54, 0x26, 0xcb, 0x9e, 0x46, 0xa7, 0x9f } };
1625
1626 static const UUID_t TfxdBoxUUID = {
1627                 { 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
1628                   0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2 } };
1629
1630 static const UUID_t SmooBoxUUID = {
1631                 { 0xe1, 0xda, 0x72, 0xba, 0x24, 0xd7, 0x43, 0xc3,
1632                   0xa6, 0xa5, 0x1b, 0x57, 0x59, 0xa1, 0xa9, 0x2c } };
1633
1634 static const UUID_t StraBoxUUID = {
1635                 { 0xb0, 0x3e, 0xf7, 0x70, 0x33, 0xbd, 0x4b, 0xac,
1636                   0x96, 0xc7, 0xbf, 0x25, 0xf9, 0x7e, 0x24, 0x47 } };
1637
1638 MP4_Box_t *MP4_BoxGetSmooBox( stream_t * );
1639
1640 /*****************************************************************************
1641  * MP4_BoxGetNextChunk : Parse the entire moof box.
1642  *****************************************************************************
1643  *  The first box is a virtual box "root" and is the father of the boxes
1644  *  'moof' and, possibly, 'sidx'.
1645  *****************************************************************************/
1646 MP4_Box_t *MP4_BoxGetNextChunk( stream_t * );
1647
1648 /*****************************************************************************
1649  * MP4_BoxGetRoot : Parse the entire file, and create all boxes in memory
1650  *****************************************************************************
1651  *  The first box is a virtual box "root" and is the father for all first
1652  *  level boxes
1653  *****************************************************************************/
1654 MP4_Box_t *MP4_BoxGetRoot( stream_t * );
1655
1656 /*****************************************************************************
1657  * MP4_FreeBox : free memory allocated after read with MP4_ReadBox
1658  *               or MP4_BoxGetRoot, this means also children boxes
1659  * XXX : all children have to be allocated by a malloc !! and
1660  *         p_box is freed
1661  *****************************************************************************/
1662 void MP4_BoxFree( stream_t *, MP4_Box_t *p_box );
1663
1664 /*****************************************************************************
1665  * MP4_DumpBoxStructure: print the structure of the p_box
1666  *****************************************************************************
1667  * Useful while debugging
1668  *****************************************************************************/
1669 void MP4_BoxDumpStructure( stream_t *p_input, MP4_Box_t *p_box );
1670
1671 /*****************************************************************************
1672  * MP4_BoxGet: find a box given a path relative to p_box
1673  *****************************************************************************
1674  * Path Format: . .. / as usual
1675  *              [number] to specifie box number ex: trak[12]
1676  *
1677  * ex: /moov/trak[12]
1678  *     ../mdia
1679  *****************************************************************************/
1680 MP4_Box_t *MP4_BoxGet( MP4_Box_t *p_box, const char *psz_fmt, ... );
1681
1682 /*****************************************************************************
1683  * MP4_BoxCount: find number of box given a path relative to p_box
1684  *****************************************************************************
1685  * Path Format: . .. / as usual
1686  *              [number] to specifie box number ex: trak[12]
1687  *
1688  * ex: /moov/trak
1689  *     ../mdia
1690  *****************************************************************************/
1691 int MP4_BoxCount( MP4_Box_t *p_box, const char *psz_fmt, ... );
1692
1693 /* Internal functions exposed for MKV demux */
1694 int MP4_ReadBoxCommon( stream_t *p_stream, MP4_Box_t *p_box );
1695 int MP4_ReadBoxContainerChildren( stream_t *p_stream, MP4_Box_t *p_container,
1696                                   uint32_t i_last_child );
1697 int MP4_ReadBox_sample_vide( stream_t *p_stream, MP4_Box_t *p_box );
1698 void MP4_FreeBox_sample_vide( MP4_Box_t *p_box );
1699
1700 #endif