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