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