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