]> git.sesse.net Git - vlc/blob - modules/demux/mp4/libmp4.h
f9e89dca740c59a63e8d7c735cca1b1038ba0c0e
[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 #define ATOM_root VLC_FOURCC( 'r', 'o', 'o', 't' )
27 #define ATOM_uuid VLC_FOURCC( 'u', 'u', 'i', 'd' )
28
29 #define ATOM_ftyp VLC_FOURCC( 'f', 't', 'y', 'p' )
30 #define ATOM_moov VLC_FOURCC( 'm', 'o', 'o', 'v' )
31 #define ATOM_foov VLC_FOURCC( 'f', 'o', 'o', 'v' )
32 #define ATOM_cmov VLC_FOURCC( 'c', 'm', 'o', 'v' )
33 #define ATOM_dcom VLC_FOURCC( 'd', 'c', 'o', 'm' )
34 #define ATOM_cmvd VLC_FOURCC( 'c', 'm', 'v', 'd' )
35
36 #define ATOM_moof VLC_FOURCC( 'm', 'o', 'o', 'f' )
37 #define ATOM_mdat VLC_FOURCC( 'm', 'd', 'a', 't' )
38 #define ATOM_skip VLC_FOURCC( 's', 'k', 'i', 'p' )
39 #define ATOM_free VLC_FOURCC( 'f', 'r', 'e', 'e' )
40 #define ATOM_udta VLC_FOURCC( 'u', 'd', 't', 'a' )
41 #define ATOM_wide VLC_FOURCC( 'w', 'i', 'd', 'e' )
42
43 #define ATOM_data VLC_FOURCC( 'd', 'a', 't', 'a' )
44
45 #define ATOM_trak VLC_FOURCC( 't', 'r', 'a', 'k' )
46 #define ATOM_mvhd VLC_FOURCC( 'm', 'v', 'h', 'd' )
47 #define ATOM_tkhd VLC_FOURCC( 't', 'k', 'h', 'd' )
48 #define ATOM_tref VLC_FOURCC( 't', 'r', 'e', 'f' )
49 #define ATOM_mdia VLC_FOURCC( 'm', 'd', 'i', 'a' )
50 #define ATOM_mdhd VLC_FOURCC( 'm', 'd', 'h', 'd' )
51 #define ATOM_hdlr VLC_FOURCC( 'h', 'd', 'l', 'r' )
52 #define ATOM_minf VLC_FOURCC( 'm', 'i', 'n', 'f' )
53 #define ATOM_vmhd VLC_FOURCC( 'v', 'm', 'h', 'd' )
54 #define ATOM_smhd VLC_FOURCC( 's', 'm', 'h', 'd' )
55 #define ATOM_hmhd VLC_FOURCC( 'h', 'm', 'h', 'd' )
56 #define ATOM_dinf VLC_FOURCC( 'd', 'i', 'n', 'f' )
57 #define ATOM_url  VLC_FOURCC( 'u', 'r', 'l', ' ' )
58 #define ATOM_urn  VLC_FOURCC( 'u', 'r', 'n', ' ' )
59 #define ATOM_dref VLC_FOURCC( 'd', 'r', 'e', 'f' )
60 #define ATOM_stbl VLC_FOURCC( 's', 't', 'b', 'l' )
61 #define ATOM_stts VLC_FOURCC( 's', 't', 't', 's' )
62 #define ATOM_ctts VLC_FOURCC( 'c', 't', 't', 's' )
63 #define ATOM_stsd VLC_FOURCC( 's', 't', 's', 'd' )
64 #define ATOM_stsz VLC_FOURCC( 's', 't', 's', 'z' )
65 #define ATOM_stz2 VLC_FOURCC( 's', 't', 'z', '2' )
66 #define ATOM_stsc VLC_FOURCC( 's', 't', 's', 'c' )
67 #define ATOM_stco VLC_FOURCC( 's', 't', 'c', 'o' )
68 #define ATOM_co64 VLC_FOURCC( 'c', 'o', '6', '4' )
69 #define ATOM_stss VLC_FOURCC( 's', 't', 's', 's' )
70 #define ATOM_stsh VLC_FOURCC( 's', 't', 's', 'h' )
71 #define ATOM_stdp VLC_FOURCC( 's', 't', 'd', 'p' )
72 #define ATOM_padb VLC_FOURCC( 'p', 'a', 'd', 'b' )
73 #define ATOM_edts VLC_FOURCC( 'e', 'd', 't', 's' )
74 #define ATOM_elst VLC_FOURCC( 'e', 'l', 's', 't' )
75 #define ATOM_mvex VLC_FOURCC( 'm', 'v', 'e', 'x' )
76 #define ATOM_trex VLC_FOURCC( 't', 'r', 'e', 'x' )
77 #define ATOM_mfhd VLC_FOURCC( 'm', 'f', 'h', 'd' )
78 #define ATOM_traf VLC_FOURCC( 't', 'r', 'a', 'f' )
79 #define ATOM_tfhd VLC_FOURCC( 't', 'f', 'h', 'd' )
80 #define ATOM_trun VLC_FOURCC( 't', 'r', 'u', 'n' )
81 #define ATOM_cprt VLC_FOURCC( 'c', 'p', 'r', 't' )
82 #define ATOM_iods VLC_FOURCC( 'i', 'o', 'd', 's' )
83
84 #define ATOM_nmhd VLC_FOURCC( 'n', 'm', 'h', 'd' )
85 #define ATOM_mp2v VLC_FOURCC( 'm', 'p', '2', 'v' )
86 #define ATOM_mp4v VLC_FOURCC( 'm', 'p', '4', 'v' )
87 #define ATOM_mp4a VLC_FOURCC( 'm', 'p', '4', 'a' )
88 #define ATOM_mp4s VLC_FOURCC( 'm', 'p', '4', 's' )
89 #define ATOM_vide VLC_FOURCC( 'v', 'i', 'd', 'e' )
90 #define ATOM_soun VLC_FOURCC( 's', 'o', 'u', 'n' )
91 #define ATOM_hint VLC_FOURCC( 'h', 'i', 'n', 't' )
92 #define ATOM_hdv2 VLC_FOURCC( 'h', 'd', 'v', '2' )
93
94 #define ATOM_dpnd VLC_FOURCC( 'd', 'p', 'n', 'd' )
95 #define ATOM_ipir VLC_FOURCC( 'i', 'p', 'i', 'r' )
96 #define ATOM_mpod VLC_FOURCC( 'm', 'p', 'o', 'd' )
97 #define ATOM_hnti VLC_FOURCC( 'h', 'n', 't', 'i' )
98 #define ATOM_rtp  VLC_FOURCC( 'r', 't', 'p', ' ' )
99
100 #define ATOM_isom VLC_FOURCC( 'i', 's', 'o', 'm' )
101 #define ATOM_3gp4 VLC_FOURCC( '3', 'g', 'p', '4' )
102 #define ATOM_esds VLC_FOURCC( 'e', 's', 'd', 's' )
103
104 #define ATOM__mp3 VLC_FOURCC( '.', 'm', 'p', '3' )
105 #define ATOM_ms02 VLC_FOURCC( 'm', 's', 0x0, 0x02 )
106 #define ATOM_ms11 VLC_FOURCC( 'm', 's', 0x0, 0x11 )
107 #define ATOM_ms55 VLC_FOURCC( 'm', 's', 0x0, 0x55 )
108 #define ATOM_twos VLC_FOURCC( 't', 'w', 'o', 's' )
109 #define ATOM_sowt VLC_FOURCC( 's', 'o', 'w', 't' )
110 #define ATOM_QDMC VLC_FOURCC( 'Q', 'D', 'M', 'C' )
111 #define ATOM_QDM2 VLC_FOURCC( 'Q', 'D', 'M', '2' )
112 #define ATOM_ima4 VLC_FOURCC( 'i', 'm', 'a', '4' )
113 #define ATOM_IMA4 VLC_FOURCC( 'I', 'M', 'A', '4' )
114 #define ATOM_dvi  VLC_FOURCC( 'd', 'v', 'i', ' ' )
115 #define ATOM_MAC3 VLC_FOURCC( 'M', 'A', 'C', '3' )
116 #define ATOM_MAC6 VLC_FOURCC( 'M', 'A', 'C', '6' )
117 #define ATOM_alaw VLC_FOURCC( 'a', 'l', 'a', 'w' )
118 #define ATOM_ulaw VLC_FOURCC( 'u', 'l', 'a', 'w' )
119 #define ATOM_Qclp VLC_FOURCC( 'Q', 'c', 'l', 'p' )
120 #define ATOM_samr VLC_FOURCC( 's', 'a', 'm', 'r' )
121 #define ATOM_sawb VLC_FOURCC( 's', 'a', 'w', 'b' )
122 #define ATOM_OggS VLC_FOURCC( 'O', 'g', 'g', 'S' )
123 #define ATOM_alac VLC_FOURCC( 'a', 'l', 'a', 'c' )
124 #define ATOM_dac3 VLC_FOURCC( 'd', 'a', 'c', '3' )
125 #define ATOM_dec3 VLC_FOURCC( 'd', 'e', 'c', '3' )
126 #define ATOM_enda VLC_FOURCC( 'e', 'n', 'd', 'a' )
127 #define ATOM_gnre VLC_FOURCC( 'g', 'n', 'r', 'e' )
128 #define ATOM_trkn VLC_FOURCC( 't', 'r', 'k', 'n' )
129
130 #define ATOM_zlib VLC_FOURCC( 'z', 'l', 'i', 'b' )
131 #define ATOM_SVQ1 VLC_FOURCC( 'S', 'V', 'Q', '1' )
132 #define ATOM_SVQ3 VLC_FOURCC( 'S', 'V', 'Q', '3' )
133 #define ATOM_ZyGo VLC_FOURCC( 'Z', 'y', 'G', 'o' )
134 #define ATOM_3IV1 VLC_FOURCC( '3', 'I', 'V', '1' )
135 #define ATOM_3iv1 VLC_FOURCC( '3', 'i', 'v', '1' )
136 #define ATOM_3IV2 VLC_FOURCC( '3', 'I', 'V', '2' )
137 #define ATOM_3iv2 VLC_FOURCC( '3', 'i', 'v', '2' )
138 #define ATOM_3IVD VLC_FOURCC( '3', 'I', 'V', 'D' )
139 #define ATOM_3ivd VLC_FOURCC( '3', 'i', 'v', 'd' )
140 #define ATOM_3VID VLC_FOURCC( '3', 'V', 'I', 'D' )
141 #define ATOM_3vid VLC_FOURCC( '3', 'v', 'i', 'd' )
142 #define ATOM_h263 VLC_FOURCC( 'h', '2', '6', '3' )
143 #define ATOM_s263 VLC_FOURCC( 's', '2', '6', '3' )
144 #define ATOM_DIVX VLC_FOURCC( 'D', 'I', 'V', 'X' )
145 #define ATOM_XVID VLC_FOURCC( 'X', 'V', 'I', 'D' )
146 #define ATOM_cvid VLC_FOURCC( 'c', 'v', 'i', 'd' )
147 #define ATOM_mjpa VLC_FOURCC( 'm', 'j', 'p', 'a' )
148 #define ATOM_mjpb VLC_FOURCC( 'm', 'j', 'q', 't' )
149 #define ATOM_mjqt VLC_FOURCC( 'm', 'j', 'h', 't' )
150 #define ATOM_mjht VLC_FOURCC( 'm', 'j', 'p', 'b' )
151 #define ATOM_VP31 VLC_FOURCC( 'V', 'P', '3', '1' )
152 #define ATOM_vp31 VLC_FOURCC( 'v', 'p', '3', '1' )
153 #define ATOM_h264 VLC_FOURCC( 'h', '2', '6', '4' )
154 #define ATOM_qdrw VLC_FOURCC( 'q', 'd', 'r', 'w' )
155
156 #define ATOM_avc1 VLC_FOURCC( 'a', 'v', 'c', '1' )
157 #define ATOM_avcC VLC_FOURCC( 'a', 'v', 'c', 'C' )
158 #define ATOM_m4ds VLC_FOURCC( 'm', '4', 'd', 's' )
159
160 #define ATOM_dvc  VLC_FOURCC( 'd', 'v', 'c', ' ' )
161 #define ATOM_dvp  VLC_FOURCC( 'd', 'v', 'p', ' ' )
162 #define ATOM_dv5n VLC_FOURCC( 'd', 'v', '5', 'n' )
163 #define ATOM_dv5p VLC_FOURCC( 'd', 'v', '5', 'p' )
164 #define ATOM_raw  VLC_FOURCC( 'r', 'a', 'w', ' ' )
165
166 #define ATOM_jpeg VLC_FOURCC( 'j', 'p', 'e', 'g' )
167
168 #define ATOM_yv12 VLC_FOURCC( 'y', 'v', '1', '2' )
169 #define ATOM_yuv2 VLC_FOURCC( 'y', 'u', 'v', '2' )
170
171 #define ATOM_rmra VLC_FOURCC( 'r', 'm', 'r', 'a' )
172 #define ATOM_rmda VLC_FOURCC( 'r', 'm', 'd', 'a' )
173 #define ATOM_rdrf VLC_FOURCC( 'r', 'd', 'r', 'f' )
174 #define ATOM_rmdr VLC_FOURCC( 'r', 'm', 'd', 'r' )
175 #define ATOM_rmvc VLC_FOURCC( 'r', 'm', 'v', 'c' )
176 #define ATOM_rmcd VLC_FOURCC( 'r', 'm', 'c', 'd' )
177 #define ATOM_rmqu VLC_FOURCC( 'r', 'm', 'q', 'u' )
178 #define ATOM_alis VLC_FOURCC( 'a', 'l', 'i', 's' )
179
180 #define ATOM_gmhd VLC_FOURCC( 'g', 'm', 'h', 'd' )
181 #define ATOM_wave VLC_FOURCC( 'w', 'a', 'v', 'e' )
182
183 #define ATOM_drms VLC_FOURCC( 'd', 'r', 'm', 's' )
184 #define ATOM_sinf VLC_FOURCC( 's', 'i', 'n', 'f' )
185 #define ATOM_schi VLC_FOURCC( 's', 'c', 'h', 'i' )
186 #define ATOM_user VLC_FOURCC( 'u', 's', 'e', 'r' )
187 #define ATOM_key  VLC_FOURCC( 'k', 'e', 'y', ' ' )
188 #define ATOM_iviv VLC_FOURCC( 'i', 'v', 'i', 'v' )
189 #define ATOM_name VLC_FOURCC( 'n', 'a', 'm', 'e' )
190 #define ATOM_priv VLC_FOURCC( 'p', 'r', 'i', 'v' )
191 #define ATOM_drmi VLC_FOURCC( 'd', 'r', 'm', 'i' )
192 #define ATOM_frma VLC_FOURCC( 'f', 'r', 'm', 'a' )
193 #define ATOM_skcr VLC_FOURCC( 's', 'k', 'c', 'r' )
194
195 #define ATOM_text VLC_FOURCC( 't', 'e', 'x', 't' )
196 #define ATOM_tx3g VLC_FOURCC( 't', 'x', '3', 'g' )
197 #define ATOM_subp VLC_FOURCC( 's', 'u', 'b', 'p' )
198 #define ATOM_sbtl VLC_FOURCC( 's', 'b', 't', 'l' )
199
200 #define ATOM_0xa9nam VLC_FOURCC( 0xa9, 'n', 'a', 'm' )
201 #define ATOM_0xa9aut VLC_FOURCC( 0xa9, 'a', 'u', 't' )
202 #define ATOM_0xa9cpy VLC_FOURCC( 0xa9, 'c', 'p', 'y' )
203 #define ATOM_0xa9inf VLC_FOURCC( 0xa9, 'i', 'n', 'f' )
204 #define ATOM_0xa9ART VLC_FOURCC( 0xa9, 'A', 'R', 'T' )
205 #define ATOM_0xa9des VLC_FOURCC( 0xa9, 'd', 'e', 's' )
206 #define ATOM_0xa9dir VLC_FOURCC( 0xa9, 'd', 'i', 'r' )
207 #define ATOM_0xa9cmt VLC_FOURCC( 0xa9, 'c', 'm', 't' )
208 #define ATOM_0xa9req VLC_FOURCC( 0xa9, 'r', 'e', 'q' )
209 #define ATOM_0xa9day VLC_FOURCC( 0xa9, 'd', 'a', 'y' )
210 #define ATOM_0xa9fmt VLC_FOURCC( 0xa9, 'f', 'm', 't' )
211 #define ATOM_0xa9prd VLC_FOURCC( 0xa9, 'p', 'r', 'd' )
212 #define ATOM_0xa9prf VLC_FOURCC( 0xa9, 'p', 'r', 'f' )
213 #define ATOM_0xa9src VLC_FOURCC( 0xa9, 's', 'r', 'c' )
214 #define ATOM_0xa9alb VLC_FOURCC( 0xa9, 'a', 'l', 'b' )
215 #define ATOM_0xa9dis VLC_FOURCC( 0xa9, 'd', 'i', 's' )
216 #define ATOM_0xa9enc VLC_FOURCC( 0xa9, 'e', 'n', 'c' )
217 #define ATOM_0xa9trk VLC_FOURCC( 0xa9, 't', 'r', 'k' )
218 #define ATOM_0xa9url VLC_FOURCC( 0xa9, 'u', 'r', 'l' )
219 #define ATOM_0xa9dsa VLC_FOURCC( 0xa9, 'd', 's', 'a' )
220 #define ATOM_0xa9hst VLC_FOURCC( 0xa9, 'h', 's', 't' )
221 #define ATOM_0xa9ope VLC_FOURCC( 0xa9, 'o', 'p', 'e' )
222 #define ATOM_0xa9wrt VLC_FOURCC( 0xa9, 'w', 'r', 't' )
223 #define ATOM_0xa9com VLC_FOURCC( 0xa9, 'c', 'o', 'm' )
224 #define ATOM_0xa9gen VLC_FOURCC( 0xa9, 'g', 'e', 'n' )
225 #define ATOM_0xa9too VLC_FOURCC( 0xa9, 't', 'o', 'o' )
226 #define ATOM_0xa9wrn VLC_FOURCC( 0xa9, 'w', 'r', 'n' )
227 #define ATOM_0xa9swr VLC_FOURCC( 0xa9, 's', 'w', 'r' )
228 #define ATOM_0xa9mak VLC_FOURCC( 0xa9, 'm', 'a', 'k' )
229 #define ATOM_0xa9mod VLC_FOURCC( 0xa9, 'm', 'o', 'd' )
230 #define ATOM_0xa9PRD VLC_FOURCC( 0xa9, 'P', 'R', 'D' )
231 #define ATOM_0xa9grp VLC_FOURCC( 0xa9, 'g', 'r', 'p' )
232 #define ATOM_0xa9lyr VLC_FOURCC( 0xa9, 'g', 'r', 'p' )
233 #define ATOM_chpl VLC_FOURCC( 'c', 'h', 'p', 'l' )
234 #define ATOM_WLOC VLC_FOURCC( 'W', 'L', 'O', 'C' )
235
236 #define ATOM_meta VLC_FOURCC( 'm', 'e', 't', 'a' )
237 #define ATOM_ilst VLC_FOURCC( 'i', 'l', 's', 't' )
238
239 #define ATOM_chap VLC_FOURCC( 'c', 'h', 'a', 'p' )
240
241 /* Do you want some debug information on all read boxes ? */
242 //#define MP4_VERBOSE  1
243
244
245 struct MP4_Box_s;
246
247
248 /* uuid Universal Unique IDentifiers */
249 typedef struct UUID_s
250 {
251     uint8_t b[16];
252 } UUID_t;
253
254 /* specific structure for all boxes */
255
256 typedef struct MP4_Box_data_ftyp_s
257 {
258     uint32_t i_major_brand;
259     uint32_t i_minor_version;
260
261     uint32_t i_compatible_brands_count;
262     uint32_t *i_compatible_brands;
263
264 } MP4_Box_data_ftyp_t;
265
266 typedef struct MP4_Box_data_mvhd_s
267 {
268     uint8_t  i_version;
269     uint32_t i_flags;
270
271     uint64_t i_creation_time;
272     uint64_t i_modification_time;
273     uint32_t i_timescale;
274     uint64_t i_duration;
275
276     int32_t  i_rate;
277     int16_t  i_volume;
278     int16_t  i_reserved1;
279     uint32_t i_reserved2[2];
280     int32_t  i_matrix[9];
281     uint32_t i_predefined[6];
282     uint32_t i_next_track_id;
283
284 } MP4_Box_data_mvhd_t;
285
286 #define MP4_TRACK_ENABLED    0x000001
287 #define MP4_TRACK_IN_MOVIE   0x000002
288 #define MP4_TRACK_IN_PREVIEW 0x000004
289 typedef struct MP4_Box_data_tkhd_s
290 {
291     uint8_t  i_version;
292     uint32_t i_flags;
293
294     uint64_t i_creation_time;
295     uint64_t i_modification_time;
296     uint32_t i_track_ID;
297     uint32_t i_reserved;
298     uint64_t i_duration;
299
300     uint32_t i_reserved2[2];
301     int16_t  i_layer;
302     int16_t  i_predefined;
303
304     int16_t  i_volume;
305     uint16_t i_reserved3;
306     int32_t  i_matrix[9];
307     int32_t  i_width;
308     int32_t  i_height;
309
310 } MP4_Box_data_tkhd_t;
311
312 typedef struct MP4_Box_data_mdhd_s
313 {
314     uint8_t  i_version;
315     uint32_t i_flags;
316
317     uint64_t i_creation_time;
318     uint64_t i_modification_time;
319     uint32_t i_timescale;
320     uint64_t i_duration;
321
322     /* one bit for pad */
323     uint16_t      i_language_code;
324     /* unsigned int(5)[3] language difference with 0x60*/
325     unsigned char i_language[3];
326     uint16_t i_predefined;
327
328 } MP4_Box_data_mdhd_t;
329
330 typedef struct MP4_Box_data_hdlr_s
331 {
332     uint8_t  i_version;
333     uint32_t i_flags;
334
335     uint32_t i_predefined;
336     uint32_t i_handler_type; /* "vide" "soun" "hint" "odsm"
337                            "crsm" "sdsm" "m7sm" "ocsm"
338                            "ipsm" "mjsm" */
339
340     unsigned char *psz_name; /* in UTF-8 */
341
342 } MP4_Box_data_hdlr_t;
343
344 typedef struct MP4_Box_data_vmhd_s
345 {
346     uint8_t  i_version;
347     uint32_t i_flags;
348
349     int16_t  i_graphics_mode;
350     int16_t  i_opcolor[3];
351
352 } MP4_Box_data_vmhd_t;
353
354 typedef struct MP4_Box_data_smhd_s
355 {
356     uint8_t  i_version;
357     uint32_t i_flags;
358
359     int16_t  i_balance;
360     int16_t  i_reserved;
361
362 } MP4_Box_data_smhd_t;
363
364 typedef struct MP4_Box_data_hmhd_s
365 {
366     uint8_t  i_version;
367     uint32_t i_flags;
368
369     uint16_t i_max_PDU_size;
370     uint16_t i_avg_PDU_size;
371     uint32_t i_max_bitrate;
372     uint32_t i_avg_bitrate;
373     uint32_t i_reserved;
374
375 } MP4_Box_data_hmhd_t;
376
377 typedef struct MP4_Box_data_url_s
378 {
379     uint8_t  i_version;
380     uint32_t i_flags;
381
382     char *psz_location;
383
384 } MP4_Box_data_url_t;
385
386 typedef struct MP4_Box_data_urn_s
387 {
388     uint8_t  i_version;
389     uint32_t i_flags;
390
391     char *psz_name;
392     char *psz_location;
393
394 } MP4_Box_data_urn_t;
395
396 typedef struct MP4_Box_data_dref_s
397 {
398     uint8_t  i_version;
399     uint32_t i_flags;
400
401     uint32_t i_entry_count;
402 /* XXX it's also a container with i_entry_count entry */
403 } MP4_Box_data_dref_t;
404
405 typedef struct MP4_Box_data_stts_s
406 {
407     uint8_t  i_version;
408     uint32_t i_flags;
409
410     uint32_t i_entry_count;
411     uint32_t *i_sample_count; /* these are array */
412     int32_t  *i_sample_delta;
413
414 } MP4_Box_data_stts_t;
415
416 typedef struct MP4_Box_data_ctts_s
417 {
418     uint8_t  i_version;
419     uint32_t i_flags;
420
421     uint32_t i_entry_count;
422
423     uint32_t *i_sample_count; /* these are array */
424     int32_t  *i_sample_offset;
425
426 } MP4_Box_data_ctts_t;
427
428
429 typedef struct MP4_Box_data_sample_soun_s
430 {
431     uint8_t  i_reserved1[6];
432     uint16_t i_data_reference_index;
433
434     //uint32_t i_reserved2[2];
435     uint16_t i_qt_version;
436     uint16_t i_qt_revision_level;
437     uint32_t i_qt_vendor;
438
439     uint16_t i_channelcount;
440     uint16_t i_samplesize;
441     uint16_t i_predefined;
442     uint16_t i_reserved3;
443     uint16_t i_sampleratehi; /* timescale of track */
444     uint16_t i_sampleratelo;
445
446     /* for version 1 (i_reserved1[0] == 1) */
447     uint32_t i_sample_per_packet;
448     uint32_t i_bytes_per_packet;
449     uint32_t i_bytes_per_frame;
450     uint32_t i_bytes_per_sample;
451
452     /* XXX hack */
453     int     i_qt_description;
454     uint8_t *p_qt_description;
455
456     void    *p_drms;
457
458 } MP4_Box_data_sample_soun_t;
459
460 typedef struct MP4_Box_data_sample_vide_s
461 {
462     uint8_t  i_reserved1[6];
463     uint16_t i_data_reference_index;
464
465     uint16_t i_qt_version;
466     uint16_t i_qt_revision_level;
467     uint32_t i_qt_vendor;
468
469     uint32_t i_qt_temporal_quality;
470     uint32_t i_qt_spatial_quality;
471
472     int16_t  i_width;
473     int16_t  i_height;
474
475     uint32_t i_horizresolution;
476     uint32_t i_vertresolution;
477
478     uint32_t i_qt_data_size;
479     uint16_t i_qt_frame_count;
480
481     uint8_t  i_compressorname[32];
482     int16_t  i_depth;
483
484     int16_t  i_qt_color_table;
485
486     /* XXX hack ImageDescription */
487     int     i_qt_image_description;
488     uint8_t *p_qt_image_description;
489
490     void    *p_drms;
491
492 } MP4_Box_data_sample_vide_t;
493
494 #define MP4_TEXT_DISPLAY_FLAG_DONT_DISPLAY       (1<<0)
495 #define MP4_TEXT_DISPLAY_FLAG_AUTO_SCALE         (1<<1)
496 #define MP4_TEXT_DISPLAY_FLAG_CLIP_TO_TEXT_BOX   (1<<2)
497 #define MP4_TEXT_DISPLAY_FLAG_USE_MOVIE_BG_COLOR (1<<3)
498 #define MP4_TEXT_DISPLAY_FLAG_SHRINK_TEXT_BOX_TO_FIT (1<<4)
499 #define MP4_TEXT_DISPLAY_FLAG_SCROLL_IN          (1<<5)
500 #define MP4_TEXT_DISPLAY_FLAG_SCROLL_OUT         (1<<6)
501 #define MP4_TEXT_DISPLAY_FLAG_HORIZONTAL_SCROLL  (1<<7)
502 #define MP4_TEXT_DISPLAY_FLAG_REVERSE_SCROLL     (1<<8)
503 #define MP4_TEXT_DISPLAY_FLAG_CONTINUOUS_SCROLL  (1<<9)
504 #define MP4_TEXT_DISPLAY_FLAG_FLOW_HORIZONTAL    (1<<10)
505 #define MP4_TEXT_DISPLAY_FLAG_CONTINUOUS_KARAOKE (1<<11)
506 #define MP4_TEXT_DISPLAY_FLAG_DROP_SHADOW        (1<<12)
507 #define MP4_TEXT_DISPLAY_FLAG_ANTI_ALIAS         (1<<13)
508 #define MP4_TEXT_DISPLAY_FLAG_KEYED_TEXT         (1<<14)
509 #define MP4_TEXT_DISPLAY_FLAG_INVERSE_HILITE     (1<<15)
510 #define MP4_TEXT_DISPLAY_FLAG_COLOR_HILITE       (1<<16)
511 #define MP4_TEXT_DISPLAY_FLAG_WRITE_VERTICALLY   (1<<17)
512
513 typedef struct
514 {
515     uint32_t i_reserved1;
516     uint16_t i_reserved2;
517
518     uint16_t i_data_reference_index;
519
520     uint32_t i_display_flags;   // TextDescription and Tx3gDescription
521
522     int8_t i_justification_horizontal; // left(0), centered(1), right(-1)
523     int8_t i_justification_vertical;   // top(0), centered(1), bottom(-1)
524
525     uint16_t i_background_color[4];
526
527     uint16_t i_text_box_top;
528     uint16_t i_text_box_left;
529     uint16_t i_text_box_bottom;
530     uint16_t i_text_box_right;
531
532     // TODO to complete
533 } MP4_Box_data_sample_text_t;
534
535 typedef struct MP4_Box_data_sample_hint_s
536 {
537     uint8_t  i_reserved1[6];
538     uint16_t i_data_reference_index;
539
540     uint8_t *p_data;
541
542 } MP4_Box_data_sample_hint_t;
543
544 typedef struct MP4_Box_data_moviehintinformation_rtp_s
545 {
546     uint32_t i_description_format;
547     unsigned char *psz_text;
548
549 } MP4_Box_data_moviehintinformation_rtp_t;
550
551
552
553 typedef struct MP4_Box_data_stsd_s
554 {
555     uint8_t  i_version;
556     uint32_t i_flags;
557
558     uint32_t i_entry_count;
559
560     /* it contains SampleEntry handled as if it was Box */
561
562 } MP4_Box_data_stsd_t;
563
564
565 typedef struct MP4_Box_data_stsz_s
566 {
567     uint8_t  i_version;
568     uint32_t i_flags;
569
570     uint32_t i_sample_size;
571     uint32_t i_sample_count;
572
573     uint32_t *i_entry_size; /* array , empty if i_sample_size != 0 */
574
575 } MP4_Box_data_stsz_t;
576
577 typedef struct MP4_Box_data_stz2_s
578 {
579     uint8_t  i_version;
580     uint32_t i_flags;
581
582     uint32_t i_sample_size; /* 24 bits */
583     uint8_t  i_field_size;
584     uint32_t i_sample_count;
585
586     uint32_t *i_entry_size; /* array: unsigned int(i_field_size) entry_size */
587
588 } MP4_Box_data_stz2_t;
589
590 typedef struct MP4_Box_data_stsc_s
591 {
592     uint8_t  i_version;
593     uint32_t i_flags;
594
595     uint32_t i_entry_count;
596
597     uint32_t *i_first_chunk; /* theses are arrays */
598     uint32_t *i_samples_per_chunk;
599     uint32_t *i_sample_description_index;
600
601 } MP4_Box_data_stsc_t;
602
603
604 typedef struct MP4_Box_data_co64_s
605 {
606     uint8_t  i_version;
607     uint32_t i_flags;
608
609     uint32_t i_entry_count;
610
611     uint64_t *i_chunk_offset;
612
613 } MP4_Box_data_co64_t;
614
615
616 typedef struct MP4_Box_data_stss_s
617 {
618     uint8_t  i_version;
619     uint32_t i_flags;
620
621     uint32_t i_entry_count;
622
623     uint32_t *i_sample_number;
624
625 } MP4_Box_data_stss_t;
626
627 typedef struct MP4_Box_data_stsh_s
628 {
629     uint8_t  i_version;
630     uint32_t i_flags;
631
632     uint32_t i_entry_count;
633
634     uint32_t *i_shadowed_sample_number;
635     uint32_t *i_sync_sample_number;
636
637 } MP4_Box_data_stsh_t;
638
639 typedef struct MP4_Box_data_stdp_s
640 {
641     uint8_t  i_version;
642     uint32_t i_flags;
643
644     uint16_t *i_priority;
645
646 } MP4_Box_data_stdp_t;
647
648 typedef struct MP4_Box_data_padb_s
649 {
650     uint8_t  i_version;
651     uint32_t i_flags;
652
653     uint32_t i_sample_count;
654
655     uint16_t *i_reserved1;   /* 1bit  */
656     uint16_t *i_pad2;        /* 3bits */
657     uint16_t *i_reserved2;   /* 1bit  */
658     uint16_t *i_pad1;        /* 3bits */
659
660
661 } MP4_Box_data_padb_t;
662
663
664 typedef struct MP4_Box_data_elst_s
665 {
666     uint8_t  i_version;
667     uint32_t i_flags;
668
669     uint32_t i_entry_count;
670
671     uint64_t *i_segment_duration;
672     int64_t  *i_media_time;
673     uint16_t *i_media_rate_integer;
674     uint16_t *i_media_rate_fraction;
675
676
677 } MP4_Box_data_elst_t;
678
679 typedef struct MP4_Box_data_cprt_s
680 {
681     uint8_t  i_version;
682     uint32_t i_flags;
683     /* 1 pad bit */
684     unsigned char i_language[3];
685
686     char *psz_notice;
687 } MP4_Box_data_cprt_t;
688
689
690 /* DecoderConfigDescriptor */
691 typedef struct MP4_descriptor_decoder_config_s
692 {
693     uint8_t i_objectTypeIndication;
694     uint8_t i_streamType;
695     int     b_upStream;
696     int     i_buffer_sizeDB;
697     int     i_max_bitrate;
698     int     i_avg_bitrate;
699
700     int     i_decoder_specific_info_len;
701     uint8_t *p_decoder_specific_info;
702     /* some other stuff */
703
704 } MP4_descriptor_decoder_config_t;
705
706 typedef struct MP4_descriptor_SL_config_s
707 {
708
709     int i_dummy; /* ANSI C forbids empty structures */
710
711 } MP4_descriptor_SL_config_t;
712
713
714 typedef struct MP4_descriptor_ES_s
715 {
716     uint16_t i_ES_ID;
717     int      b_stream_dependence;
718     int      b_url;
719     int      b_OCRstream;
720     int      i_stream_priority;
721
722     int      i_depend_on_ES_ID; /* if b_stream_dependence set */
723
724     unsigned char *psz_URL;
725
726     uint16_t i_OCR_ES_ID;       /* if b_OCRstream */
727     MP4_descriptor_decoder_config_t *p_decConfigDescr;
728
729     MP4_descriptor_SL_config_t *p_slConfigDescr;
730
731     /* some other stuff ... */
732
733 } MP4_descriptor_ES_t;
734
735 /* ES descriptor */
736 typedef struct MP4_Box_data_esds_s
737 {
738     uint8_t  i_version;
739     uint32_t i_flags;
740
741     MP4_descriptor_ES_t es_descriptor;
742
743 } MP4_Box_data_esds_t;
744
745
746 typedef struct MP4_Box_data_dcom_s
747 {
748     uint32_t i_algorithm; /* fourcc */
749
750 } MP4_Box_data_dcom_t;
751
752 typedef struct MP4_Box_data_cmvd_s
753 {
754     uint32_t i_uncompressed_size;
755     uint32_t i_compressed_size;
756
757     int     b_compressed; /* Set to 1 if compressed data, 0 if uncompressed */
758     uint8_t *p_data;
759
760 } MP4_Box_data_cmvd_t;
761
762 typedef struct MP4_Box_data_cmov_s
763 {
764     struct MP4_Box_s *p_moov; /* uncompressed moov */
765
766 } MP4_Box_data_cmov_t;
767
768 typedef struct
769 {
770     uint32_t i_type;
771 } MP4_Box_data_frma_t;
772
773 typedef struct
774 {
775     uint32_t i_init;
776     uint32_t i_encr;
777     uint32_t i_decr;
778 } MP4_Box_data_skcr_t;
779
780 typedef struct
781 {
782     uint8_t  i_version;
783     uint32_t i_flags;
784
785     uint32_t i_ref_type;
786     char     *psz_ref;
787
788 } MP4_Box_data_rdrf_t;
789
790 typedef struct
791 {
792     uint8_t  i_version;
793     uint32_t i_flags;
794
795     uint32_t i_rate;
796
797 } MP4_Box_data_rmdr_t;
798
799 typedef struct
800 {
801     uint8_t  i_version;
802     uint32_t i_flags;
803
804     uint32_t i_gestaltType;
805     uint32_t i_val1;
806     uint32_t i_val2;
807     uint16_t i_checkType;   /* 0: val1 is version min
808                                1: gestalt value & val2 == val1 */
809
810 } MP4_Box_data_rmvc_t;
811
812 typedef struct
813 {
814     uint8_t  i_version;
815     uint32_t i_flags;
816
817
818 } MP4_Box_data_rmcd_t;
819
820 typedef struct
821 {
822     uint32_t i_quality;
823
824 } MP4_Box_data_rmqu_t;
825
826 typedef struct MP4_Box_data_mfhd_s
827 {
828     uint32_t i_sequence_number;
829
830     uint8_t *p_vendor_extension;
831
832 } MP4_Box_data_mfhd_t;
833
834 #define MP4_TFHD_BASE_DATA_OFFSET     (1LL<<0)
835 #define MP4_TFHD_SAMPLE_DESC_INDEX    (1LL<<1)
836 #define MP4_TFHD_DFLT_SAMPLE_DURATION (1LL<<3)
837 #define MP4_TFHD_DFLT_SAMPLE_SIZE     (1LL<<4)
838 #define MP4_TFHD_DFLT_SAMPLE_FLAGS    (1LL<<5)
839 typedef struct MP4_Box_data_tfhd_s
840 {
841     uint8_t  i_version;
842     uint32_t i_flags;
843     uint32_t i_track_ID;
844
845     /* optional fields */
846     uint64_t i_base_data_offset;
847     uint32_t i_sample_description_index;
848     uint32_t i_default_sample_duration;
849     uint32_t i_default_sample_size;
850     uint32_t i_default_sample_flags;
851
852 } MP4_Box_data_tfhd_t;
853
854 #define MP4_TRUN_DATA_OFFSET         (1<<0)
855 #define MP4_TRUN_FIRST_FLAGS         (1<<2)
856 #define MP4_TRUN_SAMPLE_DURATION     (1<<8)
857 #define MP4_TRUN_SAMPLE_SIZE         (1<<9)
858 #define MP4_TRUN_SAMPLE_FLAGS        (1<<10)
859 #define MP4_TRUN_SAMPLE_TIME_OFFSET  (1<<11)
860 typedef struct MP4_descriptor_trun_sample_t
861 {
862     uint32_t i_duration;
863     uint32_t i_size;
864     uint32_t i_flags;
865     uint32_t i_composition_time_offset;
866 } MP4_descriptor_trun_sample_t;
867
868 typedef struct MP4_Box_data_trun_s
869 {
870     uint8_t  i_version;
871     uint32_t i_flags;
872     uint32_t i_sample_count;
873
874     /* optional fields */
875     uint32_t i_data_offset;
876     uint32_t i_first_sample_flags;
877
878     MP4_descriptor_trun_sample_t *p_samples;
879
880 } MP4_Box_data_trun_t;
881
882
883 typedef struct
884 {
885     char *psz_text;
886
887 } MP4_Box_data_0xa9xxx_t;
888
889 typedef struct
890 {
891     char *psz_text;
892
893 } MP4_Box_data_name_t;
894
895 typedef struct
896 {
897     uint32_t i_entry_count;
898     uint32_t *i_track_ID;
899
900 } MP4_Box_data_tref_generic_t;
901
902 typedef struct
903 {
904     uint8_t  i_version;
905     uint32_t i_flags;
906
907     uint8_t i_chapter;
908     struct
909     {
910         char    *psz_name;
911         int64_t  i_start;
912     } chapter[256];
913 } MP4_Box_data_chpl_t;
914
915 typedef struct
916 {
917     uint8_t i_version;
918     uint8_t i_profile;
919     uint8_t i_profile_compatibility;
920     uint8_t i_level;
921
922     uint8_t i_reserved1;     /* 6 bits */
923     uint8_t i_length_size;
924
925     uint8_t i_reserved2;    /* 3 bits */
926     uint8_t  i_sps;
927     uint16_t *i_sps_length;
928     uint8_t  **sps;
929
930     uint8_t  i_pps;
931     uint16_t *i_pps_length;
932     uint8_t  **pps;
933
934     /* XXX: Hack raw avcC atom payload */
935     int     i_avcC;
936     uint8_t *p_avcC;
937
938 } MP4_Box_data_avcC_t;
939
940 typedef struct
941 {
942     uint8_t i_fscod;
943     uint8_t i_bsid;
944     uint8_t i_bsmod;
945     uint8_t i_acmod;
946     uint8_t i_lfeon;
947     uint8_t i_bitrate_code;
948
949 } MP4_Box_data_dac3_t;
950
951 typedef struct
952 {
953     uint16_t i_little_endian;
954
955 } MP4_Box_data_enda_t;
956
957 typedef struct
958 {
959     uint16_t i_genre;
960
961 } MP4_Box_data_gnre_t;
962
963 typedef struct
964 {
965     uint32_t i_track_number;
966     uint32_t i_track_total;
967
968 } MP4_Box_data_trkn_t;
969
970 typedef struct
971 {
972     uint8_t  i_version;
973     uint32_t i_flags;
974
975     uint16_t i_object_descriptor;
976     uint8_t i_OD_profile_level;
977     uint8_t i_scene_profile_level;
978     uint8_t i_audio_profile_level;
979     uint8_t i_visual_profile_level;
980     uint8_t i_graphics_profile_level;
981
982 } MP4_Box_data_iods_t;
983
984 /*
985 typedef struct MP4_Box_data__s
986 {
987     uint8_t  i_version;
988     uint32_t i_flags;
989
990 } MP4_Box_data__t;
991
992 */
993
994 typedef union MP4_Box_data_s
995 {
996     MP4_Box_data_ftyp_t *p_ftyp;
997     MP4_Box_data_mvhd_t *p_mvhd;
998     MP4_Box_data_mfhd_t *p_mfhd;
999     MP4_Box_data_tfhd_t *p_tfhd;
1000     MP4_Box_data_trun_t *p_trun;
1001     MP4_Box_data_tkhd_t *p_tkhd;
1002     MP4_Box_data_mdhd_t *p_mdhd;
1003     MP4_Box_data_hdlr_t *p_hdlr;
1004     MP4_Box_data_vmhd_t *p_vmhd;
1005     MP4_Box_data_smhd_t *p_smhd;
1006     MP4_Box_data_hmhd_t *p_hmhd;
1007     MP4_Box_data_url_t  *p_url;
1008     MP4_Box_data_urn_t  *p_urn;
1009     MP4_Box_data_dref_t *p_dref;
1010     MP4_Box_data_stts_t *p_stts;
1011     MP4_Box_data_ctts_t *p_ctts;
1012     MP4_Box_data_stsd_t *p_stsd;
1013     MP4_Box_data_sample_vide_t *p_sample_vide;
1014     MP4_Box_data_sample_soun_t *p_sample_soun;
1015     MP4_Box_data_sample_text_t *p_sample_text;
1016     MP4_Box_data_sample_hint_t *p_sample_hint;
1017
1018     MP4_Box_data_esds_t *p_esds;
1019     MP4_Box_data_avcC_t *p_avcC;
1020     MP4_Box_data_dac3_t *p_dac3;
1021     MP4_Box_data_enda_t *p_enda;
1022     MP4_Box_data_gnre_t *p_gnre;
1023     MP4_Box_data_trkn_t *p_trkn;
1024     MP4_Box_data_iods_t *p_iods;
1025
1026     MP4_Box_data_stsz_t *p_stsz;
1027     MP4_Box_data_stz2_t *p_stz2;
1028     MP4_Box_data_stsc_t *p_stsc;
1029     MP4_Box_data_co64_t *p_co64;
1030     MP4_Box_data_stss_t *p_stss;
1031     MP4_Box_data_stsh_t *p_stsh;
1032     MP4_Box_data_stdp_t *p_stdp;
1033     MP4_Box_data_padb_t *p_padb;
1034     MP4_Box_data_elst_t *p_elst;
1035     MP4_Box_data_cprt_t *p_cprt;
1036
1037     MP4_Box_data_dcom_t *p_dcom;
1038     MP4_Box_data_cmvd_t *p_cmvd;
1039     MP4_Box_data_cmov_t *p_cmov;
1040
1041     MP4_Box_data_moviehintinformation_rtp_t p_moviehintinformation_rtp;
1042
1043     MP4_Box_data_frma_t *p_frma;
1044     MP4_Box_data_skcr_t *p_skcr;
1045
1046     MP4_Box_data_rdrf_t *p_rdrf;
1047     MP4_Box_data_rmdr_t *p_rmdr;
1048     MP4_Box_data_rmqu_t *p_rmqu;
1049     MP4_Box_data_rmvc_t *p_rmvc;
1050
1051     MP4_Box_data_0xa9xxx_t *p_0xa9xxx;
1052     MP4_Box_data_chpl_t *p_chpl;
1053     MP4_Box_data_tref_generic_t *p_tref_generic;
1054     MP4_Box_data_name_t *p_name;
1055
1056     void                *p_data; /* for unknow type */
1057 } MP4_Box_data_t;
1058
1059
1060
1061 /* the most basic structure */
1062 typedef struct MP4_Box_s
1063 {
1064     off_t        i_pos;      /* absolute position */
1065
1066     uint32_t     i_type;
1067     uint32_t     i_shortsize;
1068
1069     UUID_t       i_uuid;  /* Set if i_type == "uuid" */
1070
1071     uint64_t     i_size; /* always set so use it */
1072
1073     MP4_Box_data_t   data;   /* union of pointers on extended data depending
1074                                 on i_type (or i_usertype) */
1075
1076     struct MP4_Box_s *p_father; /* pointer on the father Box */
1077
1078     struct MP4_Box_s *p_first;  /* pointer on the first child Box */
1079     struct MP4_Box_s *p_last;
1080
1081     struct MP4_Box_s *p_next;   /* pointer on the next boxes at the same level */
1082
1083 } MP4_Box_t;
1084
1085
1086
1087 /*****************************************************************************
1088  * MP4_BoxGetRoot : Parse the entire file, and create all boxes in memory
1089  *****************************************************************************
1090  *  The first box is a virtual box "root" and is the father for all first
1091  *  level boxes
1092  *****************************************************************************/
1093 MP4_Box_t *MP4_BoxGetRoot( stream_t * );
1094
1095 /*****************************************************************************
1096  * MP4_FreeBox : free memory allocated after read with MP4_ReadBox
1097  *               or MP4_BoxGetRoot, this means also children boxes
1098  * XXX : all children have to be allocated by a malloc !! and
1099  *         p_box is freed
1100  *****************************************************************************/
1101 void MP4_BoxFree( stream_t *, MP4_Box_t *p_box );
1102
1103 /*****************************************************************************
1104  * MP4_DumpBoxStructure: print the structure of the p_box
1105  *****************************************************************************
1106  * Useful while debugging
1107  *****************************************************************************/
1108 void MP4_BoxDumpStructure( stream_t *p_input, MP4_Box_t *p_box );
1109
1110 /*****************************************************************************
1111  * MP4_BoxGet: find a box given a path relative to p_box
1112  *****************************************************************************
1113  * Path Format: . .. / as usual
1114  *              [number] to specifie box number ex: trak[12]
1115  *
1116  * ex: /moov/trak[12]
1117  *     ../mdia
1118  *****************************************************************************/
1119 MP4_Box_t *MP4_BoxGet( MP4_Box_t *p_box, const char *psz_fmt, ... );
1120
1121 /*****************************************************************************
1122  * MP4_BoxCount: find number of box given a path relative to p_box
1123  *****************************************************************************
1124  * Path Format: . .. / as usual
1125  *              [number] to specifie box number ex: trak[12]
1126  *
1127  * ex: /moov/trak
1128  *     ../mdia
1129  *****************************************************************************/
1130 int MP4_BoxCount( MP4_Box_t *p_box, const char *psz_fmt, ... );
1131
1132 /* Internal functions exposed for MKV demux */
1133 int MP4_ReadBoxCommon( stream_t *p_stream, MP4_Box_t *p_box );
1134 int MP4_ReadBox_sample_vide( stream_t *p_stream, MP4_Box_t *p_box );
1135 void MP4_FreeBox_sample_vide( MP4_Box_t *p_box );
1136
1137 #endif