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