]> git.sesse.net Git - vlc/blob - modules/demux/mp4/libmp4.h
Added apple chapter support (used by HandBrake, close #808)
[vlc] / modules / demux / mp4 / libmp4.h
1 /*****************************************************************************
2  * libmp4.h : LibMP4 library for mp4 module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001-2004 the VideoLAN team
5  * $Id$
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 #ifndef _VLC_MP4_H
23 #define _VLC_MP4_H 1
24
25
26 #define FOURCC_uuid VLC_FOURCC( 'u', 'u', 'i', 'd' )
27
28 #define FOURCC_ftyp VLC_FOURCC( 'f', 't', 'y', 'p' )
29 #define FOURCC_moov VLC_FOURCC( 'm', 'o', 'o', 'v' )
30 #define FOURCC_foov VLC_FOURCC( 'f', 'o', 'o', 'v' )
31 #define FOURCC_cmov VLC_FOURCC( 'c', 'm', 'o', 'v' )
32 #define FOURCC_dcom VLC_FOURCC( 'd', 'c', 'o', 'm' )
33 #define FOURCC_cmvd VLC_FOURCC( 'c', 'm', 'v', 'd' )
34
35 #define FOURCC_moof VLC_FOURCC( 'm', 'o', 'o', 'f' )
36 #define FOURCC_mdat VLC_FOURCC( 'm', 'd', 'a', 't' )
37 #define FOURCC_skip VLC_FOURCC( 's', 'k', 'i', 'p' )
38 #define FOURCC_free VLC_FOURCC( 'f', 'r', 'e', 'e' )
39 #define FOURCC_udta VLC_FOURCC( 'u', 'd', 't', 'a' )
40 #define FOURCC_wide VLC_FOURCC( 'w', 'i', 'd', 'e' )
41
42 #define FOURCC_trak VLC_FOURCC( 't', 'r', 'a', 'k' )
43 #define FOURCC_mvhd VLC_FOURCC( 'm', 'v', 'h', 'd' )
44 #define FOURCC_tkhd VLC_FOURCC( 't', 'k', 'h', 'd' )
45 #define FOURCC_tref VLC_FOURCC( 't', 'r', 'e', 'f' )
46 #define FOURCC_mdia VLC_FOURCC( 'm', 'd', 'i', 'a' )
47 #define FOURCC_mdhd VLC_FOURCC( 'm', 'd', 'h', 'd' )
48 #define FOURCC_hdlr VLC_FOURCC( 'h', 'd', 'l', 'r' )
49 #define FOURCC_minf VLC_FOURCC( 'm', 'i', 'n', 'f' )
50 #define FOURCC_vmhd VLC_FOURCC( 'v', 'm', 'h', 'd' )
51 #define FOURCC_smhd VLC_FOURCC( 's', 'm', 'h', 'd' )
52 #define FOURCC_hmhd VLC_FOURCC( 'h', 'm', 'h', 'd' )
53 #define FOURCC_dinf VLC_FOURCC( 'd', 'i', 'n', 'f' )
54 #define FOURCC_url  VLC_FOURCC( 'u', 'r', 'l', ' ' )
55 #define FOURCC_urn  VLC_FOURCC( 'u', 'r', 'n', ' ' )
56 #define FOURCC_dref VLC_FOURCC( 'd', 'r', 'e', 'f' )
57 #define FOURCC_stbl VLC_FOURCC( 's', 't', 'b', 'l' )
58 #define FOURCC_stts VLC_FOURCC( 's', 't', 't', 's' )
59 #define FOURCC_ctts VLC_FOURCC( 'c', 't', 't', 's' )
60 #define FOURCC_stsd VLC_FOURCC( 's', 't', 's', 'd' )
61 #define FOURCC_stsz VLC_FOURCC( 's', 't', 's', 'z' )
62 #define FOURCC_stz2 VLC_FOURCC( 's', 't', 'z', '2' )
63 #define FOURCC_stsc VLC_FOURCC( 's', 't', 's', 'c' )
64 #define FOURCC_stco VLC_FOURCC( 's', 't', 'c', 'o' )
65 #define FOURCC_co64 VLC_FOURCC( 'c', 'o', '6', '4' )
66 #define FOURCC_stss VLC_FOURCC( 's', 't', 's', 's' )
67 #define FOURCC_stsh VLC_FOURCC( 's', 't', 's', 'h' )
68 #define FOURCC_stdp VLC_FOURCC( 's', 't', 'd', 'p' )
69 #define FOURCC_padb VLC_FOURCC( 'p', 'a', 'd', 'b' )
70 #define FOURCC_edts VLC_FOURCC( 'e', 'd', 't', 's' )
71 #define FOURCC_elst VLC_FOURCC( 'e', 'l', 's', 't' )
72 #define FOURCC_udta VLC_FOURCC( 'u', 'd', 't', 'a' )
73 #define FOURCC_mvex VLC_FOURCC( 'm', 'v', 'e', 'x' )
74 #define FOURCC_trex VLC_FOURCC( 't', 'r', 'e', 'x' )
75 #define FOURCC_mfhd VLC_FOURCC( 'm', 'f', 'h', 'd' )
76 #define FOURCC_traf VLC_FOURCC( 't', 'r', 'a', 'f' )
77 #define FOURCC_tfhd VLC_FOURCC( 't', 'f', 'h', 'd' )
78 #define FOURCC_trun VLC_FOURCC( 't', 'r', 'u', 'n' )
79 #define FOURCC_cprt VLC_FOURCC( 'c', 'p', 'r', 't' )
80 #define FOURCC_iods VLC_FOURCC( 'i', 'o', 'd', 's' )
81
82 #define FOURCC_nmhd VLC_FOURCC( 'n', 'm', 'h', 'd' )
83 #define FOURCC_mp2v VLC_FOURCC( 'm', 'p', '2', 'v' )
84 #define FOURCC_mp4v VLC_FOURCC( 'm', 'p', '4', 'v' )
85 #define FOURCC_mp4a VLC_FOURCC( 'm', 'p', '4', 'a' )
86 #define FOURCC_mp4s VLC_FOURCC( 'm', 'p', '4', 's' )
87 #define FOURCC_vide VLC_FOURCC( 'v', 'i', 'd', 'e' )
88 #define FOURCC_soun VLC_FOURCC( 's', 'o', 'u', 'n' )
89 #define FOURCC_hint VLC_FOURCC( 'h', 'i', 'n', 't' )
90 #define FOURCC_hdv2 VLC_FOURCC( 'h', 'd', 'v', '2' )
91
92 #define FOURCC_dpnd VLC_FOURCC( 'd', 'p', 'n', 'd' )
93 #define FOURCC_ipir VLC_FOURCC( 'i', 'p', 'i', 'r' )
94 #define FOURCC_mpod VLC_FOURCC( 'm', 'p', 'o', 'd' )
95 #define FOURCC_hnti VLC_FOURCC( 'h', 'n', 't', 'i' )
96 #define FOURCC_rtp  VLC_FOURCC( 'r', 't', 'p', ' ' )
97
98 #define FOURCC_isom VLC_FOURCC( 'i', 's', 'o', 'm' )
99 #define FOURCC_esds VLC_FOURCC( 'e', 's', 'd', 's' )
100
101 #define FOURCC__mp3 VLC_FOURCC( '.', 'm', 'p', '3' )
102 #define FOURCC_ms02 VLC_FOURCC( 'm', 's', 0x0, 0x02 )
103 #define FOURCC_ms11 VLC_FOURCC( 'm', 's', 0x0, 0x11 )
104 #define FOURCC_ms55 VLC_FOURCC( 'm', 's', 0x0, 0x55 )
105 #define FOURCC_twos VLC_FOURCC( 't', 'w', 'o', 's' )
106 #define FOURCC_sowt VLC_FOURCC( 's', 'o', 'w', 't' )
107 #define FOURCC_QDMC VLC_FOURCC( 'Q', 'D', 'M', 'C' )
108 #define FOURCC_QDM2 VLC_FOURCC( 'Q', 'D', 'M', '2' )
109 #define FOURCC_ima4 VLC_FOURCC( 'i', 'm', 'a', '4' )
110 #define FOURCC_IMA4 VLC_FOURCC( 'I', 'M', 'A', '4' )
111 #define FOURCC_dvi  VLC_FOURCC( 'd', 'v', 'i', ' ' )
112 #define FOURCC_MAC3 VLC_FOURCC( 'M', 'A', 'C', '3' )
113 #define FOURCC_MAC6 VLC_FOURCC( 'M', 'A', 'C', '6' )
114 #define FOURCC_alaw VLC_FOURCC( 'a', 'l', 'a', 'w' )
115 #define FOURCC_ulaw VLC_FOURCC( 'u', 'l', 'a', 'w' )
116 #define FOURCC_Qclp VLC_FOURCC( 'Q', 'c', 'l', 'p' )
117 #define FOURCC_samr VLC_FOURCC( 's', 'a', 'm', 'r' )
118 #define FOURCC_sawb VLC_FOURCC( 's', 'a', 'w', 'b' )
119 #define FOURCC_OggS VLC_FOURCC( 'O', 'g', 'g', 'S' )
120 #define FOURCC_alac VLC_FOURCC( 'a', 'l', 'a', 'c' )
121
122 #define FOURCC_zlib VLC_FOURCC( 'z', 'l', 'i', 'b' )
123 #define FOURCC_SVQ1 VLC_FOURCC( 'S', 'V', 'Q', '1' )
124 #define FOURCC_SVQ3 VLC_FOURCC( 'S', 'V', 'Q', '3' )
125 #define FOURCC_ZyGo VLC_FOURCC( 'Z', 'y', 'G', 'o' )
126 #define FOURCC_3IV1 VLC_FOURCC( '3', 'I', 'V', '1' )
127 #define FOURCC_3iv1 VLC_FOURCC( '3', 'i', 'v', '1' )
128 #define FOURCC_3IV2 VLC_FOURCC( '3', 'I', 'V', '2' )
129 #define FOURCC_3iv2 VLC_FOURCC( '3', 'i', 'v', '2' )
130 #define FOURCC_3IVD VLC_FOURCC( '3', 'I', 'V', 'D' )
131 #define FOURCC_3ivd VLC_FOURCC( '3', 'i', 'v', 'd' )
132 #define FOURCC_3VID VLC_FOURCC( '3', 'V', 'I', 'D' )
133 #define FOURCC_3vid VLC_FOURCC( '3', 'v', 'i', 'd' )
134 #define FOURCC_h263 VLC_FOURCC( 'h', '2', '6', '3' )
135 #define FOURCC_s263 VLC_FOURCC( 's', '2', '6', '3' )
136 #define FOURCC_DIVX VLC_FOURCC( 'D', 'I', 'V', 'X' )
137 #define FOURCC_XVID VLC_FOURCC( 'X', 'V', 'I', 'D' )
138 #define FOURCC_cvid VLC_FOURCC( 'c', 'v', 'i', 'd' )
139 #define FOURCC_mjpa VLC_FOURCC( 'm', 'j', 'p', 'a' )
140 #define FOURCC_mjpb VLC_FOURCC( 'm', 'j', 'q', 't' )
141 #define FOURCC_mjqt VLC_FOURCC( 'm', 'j', 'h', 't' )
142 #define FOURCC_mjht VLC_FOURCC( 'm', 'j', 'p', 'b' )
143 #define FOURCC_VP31 VLC_FOURCC( 'V', 'P', '3', '1' )
144 #define FOURCC_vp31 VLC_FOURCC( 'v', 'p', '3', '1' )
145 #define FOURCC_h264 VLC_FOURCC( 'h', '2', '6', '4' )
146 #define FOURCC_qdrw VLC_FOURCC( 'q', 'd', 'r', 'w' )
147
148 #define FOURCC_avc1 VLC_FOURCC( 'a', 'v', 'c', '1' )
149 #define FOURCC_avcC VLC_FOURCC( 'a', 'v', 'c', 'C' )
150 #define FOURCC_m4ds VLC_FOURCC( 'm', '4', 'd', 's' )
151
152 #define FOURCC_dvc  VLC_FOURCC( 'd', 'v', 'c', ' ' )
153 #define FOURCC_dvp  VLC_FOURCC( 'd', 'v', 'p', ' ' )
154 #define FOURCC_raw  VLC_FOURCC( 'r', 'a', 'w', ' ' )
155
156 #define FOURCC_jpeg VLC_FOURCC( 'j', 'p', 'e', 'g' )
157
158 #define FOURCC_yv12 VLC_FOURCC( 'y', 'v', '1', '2' )
159 #define FOURCC_yuv2 VLC_FOURCC( 'y', 'u', 'v', '2' )
160
161 #define FOURCC_rmra VLC_FOURCC( 'r', 'm', 'r', 'a' )
162 #define FOURCC_rmda VLC_FOURCC( 'r', 'm', 'd', 'a' )
163 #define FOURCC_rdrf VLC_FOURCC( 'r', 'd', 'r', 'f' )
164 #define FOURCC_rmdr VLC_FOURCC( 'r', 'm', 'd', 'r' )
165 #define FOURCC_rmvc VLC_FOURCC( 'r', 'm', 'v', 'c' )
166 #define FOURCC_rmcd VLC_FOURCC( 'r', 'm', 'c', 'd' )
167 #define FOURCC_rmqu VLC_FOURCC( 'r', 'm', 'q', 'u' )
168 #define FOURCC_alis VLC_FOURCC( 'a', 'l', 'i', 's' )
169
170 #define FOURCC_gmhd VLC_FOURCC( 'g', 'm', 'h', 'd' )
171 #define FOURCC_wave VLC_FOURCC( 'w', 'a', 'v', 'e' )
172
173 #define FOURCC_drms VLC_FOURCC( 'd', 'r', 'm', 's' )
174 #define FOURCC_sinf VLC_FOURCC( 's', 'i', 'n', 'f' )
175 #define FOURCC_schi VLC_FOURCC( 's', 'c', 'h', 'i' )
176 #define FOURCC_user VLC_FOURCC( 'u', 's', 'e', 'r' )
177 #define FOURCC_key  VLC_FOURCC( 'k', 'e', 'y', ' ' )
178 #define FOURCC_iviv VLC_FOURCC( 'i', 'v', 'i', 'v' )
179 #define FOURCC_name VLC_FOURCC( 'n', 'a', 'm', 'e' )
180 #define FOURCC_priv VLC_FOURCC( 'p', 'r', 'i', 'v' )
181
182 #define FOURCC_text VLC_FOURCC( 't', 'e', 'x', 't' )
183 #define FOURCC_tx3g VLC_FOURCC( 't', 'x', '3', 'g' )
184 #define FOURCC_subp VLC_FOURCC( 's', 'u', 'b', 'p' )
185
186 #define FOURCC_0xa9nam VLC_FOURCC( 0xa9, 'n', 'a', 'm' )
187 #define FOURCC_0xa9aut VLC_FOURCC( 0xa9, 'a', 'u', 't' )
188 #define FOURCC_0xa9swr VLC_FOURCC( 0xa9, 's', 'w', 'r' )
189 #define FOURCC_0xa9cpy VLC_FOURCC( 0xa9, 'c', 'p', 'y' )
190 #define FOURCC_0xa9inf VLC_FOURCC( 0xa9, 'i', 'n', 'f' )
191 #define FOURCC_0xa9ART VLC_FOURCC( 0xa9, 'A', 'R', 'T' )
192 #define FOURCC_0xa9des VLC_FOURCC( 0xa9, 'd', 'e', 's' )
193 #define FOURCC_0xa9dir VLC_FOURCC( 0xa9, 'd', 'i', 'r' )
194 #define FOURCC_0xa9cmt VLC_FOURCC( 0xa9, 'c', 'm', 't' )
195 #define FOURCC_0xa9req VLC_FOURCC( 0xa9, 'r', 'e', 'q' )
196 #define FOURCC_0xa9day VLC_FOURCC( 0xa9, 'd', 'a', 'y' )
197 #define FOURCC_0xa9fmt VLC_FOURCC( 0xa9, 'f', 'm', 't' )
198 #define FOURCC_0xa9prd VLC_FOURCC( 0xa9, 'p', 'r', 'd' )
199 #define FOURCC_0xa9prf VLC_FOURCC( 0xa9, 'p', 'r', 'f' )
200 #define FOURCC_0xa9src VLC_FOURCC( 0xa9, 's', 'r', 'c' )
201 #define FOURCC_0xa9alb VLC_FOURCC( 0xa9, 'a', 'l', 'b' )
202 #define FOURCC_0xa9dis VLC_FOURCC( 0xa9, 'd', 'i', 's' )
203 #define FOURCC_0xa9enc VLC_FOURCC( 0xa9, 'e', 'n', 'c' )
204 #define FOURCC_0xa9trk VLC_FOURCC( 0xa9, 't', 'r', 'k' )
205 #define FOURCC_0xa9url VLC_FOURCC( 0xa9, 'u', 'r', 'l' )
206 #define FOURCC_0xa9dsa VLC_FOURCC( 0xa9, 'd', 's', 'a' )
207 #define FOURCC_0xa9hst VLC_FOURCC( 0xa9, 'h', 's', 't' )
208 #define FOURCC_0xa9ope VLC_FOURCC( 0xa9, 'o', 'p', 'e' )
209 #define FOURCC_0xa9wrt VLC_FOURCC( 0xa9, 'w', 'r', 't' )
210 #define FOURCC_0xa9com VLC_FOURCC( 0xa9, 'c', 'o', 'm' )
211 #define FOURCC_0xa9gen VLC_FOURCC( 0xa9, 'g', 'e', 'n' )
212 #define FOURCC_chpl VLC_FOURCC( 'c', 'h', 'p', 'l' )
213 #define FOURCC_WLOC VLC_FOURCC( 'W', 'L', 'O', 'C' )
214
215 #define FOURCC_meta VLC_FOURCC( 'm', 'e', 't', 'a' )
216 #define FOURCC_ilst VLC_FOURCC( 'i', 'l', 's', 't' )
217
218 #define FOURCC_chap VLC_FOURCC( 'c', 'h', 'a', 'p' )
219
220 /* Do you want some debug information on all read boxes ? */
221 #define MP4_VERBOSE  1
222
223
224 struct MP4_Box_s;
225
226
227 /* uuid Universal Unique IDentifiers */
228 typedef struct UUID_s
229 {
230     uint8_t b[16];
231 } UUID_t;
232
233 /* specific structure for all boxes */
234
235 typedef struct MP4_Box_data_ftyp_s
236 {
237     uint32_t i_major_brand;
238     uint32_t i_minor_version;
239
240     uint32_t i_compatible_brands_count;
241     uint32_t *i_compatible_brands;
242
243 } MP4_Box_data_ftyp_t;
244
245 typedef struct MP4_Box_data_mvhd_s
246 {
247     uint8_t  i_version;
248     uint32_t i_flags;
249
250     uint64_t i_creation_time;
251     uint64_t i_modification_time;
252     uint32_t i_timescale;
253     uint64_t i_duration;
254
255     int32_t  i_rate;
256     int16_t  i_volume;
257     int16_t  i_reserved1;
258     uint32_t i_reserved2[2];
259     int32_t  i_matrix[9];
260     uint32_t i_predefined[6];
261     uint32_t i_next_track_id;
262
263 } MP4_Box_data_mvhd_t;
264
265 #define MP4_TRACK_ENABLED    0x000001
266 #define MP4_TRACK_IN_MOVIE   0x000002
267 #define MP4_TRACK_IN_PREVIEW 0x000004
268 typedef struct MP4_Box_data_tkhd_s
269 {
270     uint8_t  i_version;
271     uint32_t i_flags;
272
273     uint64_t i_creation_time;
274     uint64_t i_modification_time;
275     uint32_t i_track_ID;
276     uint32_t i_reserved;
277     uint64_t i_duration;
278
279     uint32_t i_reserved2[2];
280     int16_t  i_layer;
281     int16_t  i_predefined;
282
283     int16_t  i_volume;
284     uint16_t i_reserved3;
285     int32_t  i_matrix[9];
286     int32_t  i_width;
287     int32_t  i_height;
288
289 } MP4_Box_data_tkhd_t;
290
291 typedef struct MP4_Box_data_mdhd_s
292 {
293     uint8_t  i_version;
294     uint32_t i_flags;
295
296     uint64_t i_creation_time;
297     uint64_t i_modification_time;
298     uint32_t i_timescale;
299     uint64_t i_duration;
300
301     /* one bit for pad */
302     /* unsigned int(5)[3] language difference with 0x60*/
303     unsigned char i_language[3];
304     uint16_t i_predefined;
305
306 } MP4_Box_data_mdhd_t;
307
308 typedef struct MP4_Box_data_hdlr_s
309 {
310     uint8_t  i_version;
311     uint32_t i_flags;
312
313     uint32_t i_predefined;
314     uint32_t i_handler_type; /* "vide" "soun" "hint" "odsm"
315                            "crsm" "sdsm" "m7sm" "ocsm"
316                            "ipsm" "mjsm" */
317
318     unsigned char *psz_name; /* in UTF-8 */
319
320 } MP4_Box_data_hdlr_t;
321
322 typedef struct MP4_Box_data_vmhd_s
323 {
324     uint8_t  i_version;
325     uint32_t i_flags;
326
327     int16_t  i_graphics_mode;
328     int16_t  i_opcolor[3];
329
330 } MP4_Box_data_vmhd_t;
331
332 typedef struct MP4_Box_data_smhd_s
333 {
334     uint8_t  i_version;
335     uint32_t i_flags;
336
337     int16_t  i_balance;
338     int16_t  i_reserved;
339
340 } MP4_Box_data_smhd_t;
341
342 typedef struct MP4_Box_data_hmhd_s
343 {
344     uint8_t  i_version;
345     uint32_t i_flags;
346
347     uint16_t i_max_PDU_size;
348     uint16_t i_avg_PDU_size;
349     uint32_t i_max_bitrate;
350     uint32_t i_avg_bitrate;
351     uint32_t i_reserved;
352
353 } MP4_Box_data_hmhd_t;
354
355 typedef struct MP4_Box_data_url_s
356 {
357     uint8_t  i_version;
358     uint32_t i_flags;
359
360     char *psz_location;
361
362 } MP4_Box_data_url_t;
363
364 typedef struct MP4_Box_data_urn_s
365 {
366     uint8_t  i_version;
367     uint32_t i_flags;
368
369     char *psz_name;
370     char *psz_location;
371
372 } MP4_Box_data_urn_t;
373
374 typedef struct MP4_Box_data_dref_s
375 {
376     uint8_t  i_version;
377     uint32_t i_flags;
378
379     uint32_t i_entry_count;
380 /* XXX it's also a container with i_entry_count entry */
381 } MP4_Box_data_dref_t;
382
383 typedef struct MP4_Box_data_stts_s
384 {
385     uint8_t  i_version;
386     uint32_t i_flags;
387
388     uint32_t i_entry_count;
389     uint32_t *i_sample_count; /* these are array */
390     int32_t  *i_sample_delta;
391
392 } MP4_Box_data_stts_t;
393
394 typedef struct MP4_Box_data_ctts_s
395 {
396     uint8_t  i_version;
397     uint32_t i_flags;
398
399     uint32_t i_entry_count;
400
401     uint32_t *i_sample_count; /* these are array */
402     int32_t  *i_sample_offset;
403
404 } MP4_Box_data_ctts_t;
405
406
407 typedef struct MP4_Box_data_sample_soun_s
408 {
409     uint8_t  i_reserved1[6];
410     uint16_t i_data_reference_index;
411
412     //uint32_t i_reserved2[2];
413     uint16_t i_qt_version;
414     uint16_t i_qt_revision_level;
415     uint32_t i_qt_vendor;
416
417     uint16_t i_channelcount;
418     uint16_t i_samplesize;
419     uint16_t i_predefined;
420     uint16_t i_reserved3;
421     uint16_t i_sampleratehi; /* timescale of track */
422     uint16_t i_sampleratelo;
423
424     /* for version 1 (i_reserved1[0] == 1) */
425     uint32_t i_sample_per_packet;
426     uint32_t i_bytes_per_packet;
427     uint32_t i_bytes_per_frame;
428     uint32_t i_bytes_per_sample;
429
430     /* XXX hack */
431     int     i_qt_description;
432     uint8_t *p_qt_description;
433
434     void    *p_drms;
435
436 } MP4_Box_data_sample_soun_t;
437
438 typedef struct MP4_Box_data_sample_vide_s
439 {
440     uint8_t  i_reserved1[6];
441     uint16_t i_data_reference_index;
442
443     uint16_t i_qt_version;
444     uint16_t i_qt_revision_level;
445     uint32_t i_qt_vendor;
446
447     uint32_t i_qt_temporal_quality;
448     uint32_t i_qt_spatial_quality;
449
450     int16_t  i_width;
451     int16_t  i_height;
452
453     uint32_t i_horizresolution;
454     uint32_t i_vertresolution;
455
456     uint32_t i_qt_data_size;
457     uint16_t i_qt_frame_count;
458
459     uint8_t  i_compressorname[32];
460     int16_t  i_depth;
461
462     int16_t  i_qt_color_table;
463
464     /* XXX hack ImageDescription */
465     int     i_qt_image_description;
466     uint8_t *p_qt_image_description;
467
468 } MP4_Box_data_sample_vide_t;
469
470 #define MP4_TEXT_DISPLAY_FLAG_DONT_DISPLAY       (1<<0)
471 #define MP4_TEXT_DISPLAY_FLAG_AUTO_SCALE         (1<<1)
472 #define MP4_TEXT_DISPLAY_FLAG_CLIP_TO_TEXT_BOX   (1<<2)
473 #define MP4_TEXT_DISPLAY_FLAG_USE_MOVIE_BG_COLOR (1<<3)
474 #define MP4_TEXT_DISPLAY_FLAG_SHRINK_TEXT_BOX_TO_FIT (1<<4)
475 #define MP4_TEXT_DISPLAY_FLAG_SCROLL_IN          (1<<5)
476 #define MP4_TEXT_DISPLAY_FLAG_SCROLL_OUT         (1<<6)
477 #define MP4_TEXT_DISPLAY_FLAG_HORIZONTAL_SCROLL  (1<<7)
478 #define MP4_TEXT_DISPLAY_FLAG_REVERSE_SCROLL     (1<<8)
479 #define MP4_TEXT_DISPLAY_FLAG_CONTINUOUS_SCROLL  (1<<9)
480 #define MP4_TEXT_DISPLAY_FLAG_FLOW_HORIZONTAL    (1<<10)
481 #define MP4_TEXT_DISPLAY_FLAG_CONTINUOUS_KARAOKE (1<<11)
482 #define MP4_TEXT_DISPLAY_FLAG_DROP_SHADOW        (1<<12)
483 #define MP4_TEXT_DISPLAY_FLAG_ANTI_ALIAS         (1<<13)
484 #define MP4_TEXT_DISPLAY_FLAG_KEYED_TEXT         (1<<14)
485 #define MP4_TEXT_DISPLAY_FLAG_INVERSE_HILITE     (1<<15)
486 #define MP4_TEXT_DISPLAY_FLAG_COLOR_HILITE       (1<<16)
487 #define MP4_TEXT_DISPLAY_FLAG_WRITE_VERTICALLY   (1<<17)
488
489 typedef struct
490 {
491     uint32_t i_reserved1;
492     uint16_t i_reserved2;
493
494     uint16_t i_data_reference_index;
495
496     uint32_t i_display_flags;   // TextDescription and Tx3gDescription
497
498     int8_t i_justification_horizontal; // left(0), centered(1), right(-1)
499     int8_t i_justification_vertical;   // top(0), centered(1), bottom(-1)
500
501     uint16_t i_background_color[4];
502
503     uint16_t i_text_box_top;
504     uint16_t i_text_box_left;
505     uint16_t i_text_box_bottom;
506     uint16_t i_text_box_right;
507
508     // TODO to complete
509 } MP4_Box_data_sample_text_t;
510
511 typedef struct MP4_Box_data_sample_hint_s
512 {
513     uint8_t  i_reserved1[6];
514     uint16_t i_data_reference_index;
515
516     uint8_t *p_data;
517
518 } MP4_Box_data_sample_hint_t;
519
520 typedef struct MP4_Box_data_moviehintinformation_rtp_s
521 {
522     uint32_t i_description_format;
523     unsigned char *psz_text;
524
525 } MP4_Box_data_moviehintinformation_rtp_t;
526
527
528
529 typedef struct MP4_Box_data_stsd_s
530 {
531     uint8_t  i_version;
532     uint32_t i_flags;
533
534     uint32_t i_entry_count;
535
536     /* it contains SampleEntry handled as if it was Box */
537
538 } MP4_Box_data_stsd_t;
539
540
541 typedef struct MP4_Box_data_stsz_s
542 {
543     uint8_t  i_version;
544     uint32_t i_flags;
545
546     uint32_t i_sample_size;
547     uint32_t i_sample_count;
548
549     uint32_t *i_entry_size; /* array , empty if i_sample_size != 0 */
550
551 } MP4_Box_data_stsz_t;
552
553 typedef struct MP4_Box_data_stz2_s
554 {
555     uint8_t  i_version;
556     uint32_t i_flags;
557
558     uint32_t i_sample_size; /* 24 bits */
559     uint8_t  i_field_size;
560     uint32_t i_sample_count;
561
562     uint32_t *i_entry_size; /* array: unsigned int(i_field_size) entry_size */
563
564 } MP4_Box_data_stz2_t;
565
566 typedef struct MP4_Box_data_stsc_s
567 {
568     uint8_t  i_version;
569     uint32_t i_flags;
570
571     uint32_t i_entry_count;
572
573     uint32_t *i_first_chunk; /* theses are arrays */
574     uint32_t *i_samples_per_chunk;
575     uint32_t *i_sample_description_index;
576
577 } MP4_Box_data_stsc_t;
578
579
580 typedef struct MP4_Box_data_co64_s
581 {
582     uint8_t  i_version;
583     uint32_t i_flags;
584
585     uint32_t i_entry_count;
586
587     uint64_t *i_chunk_offset;
588
589 } MP4_Box_data_co64_t;
590
591
592 typedef struct MP4_Box_data_stss_s
593 {
594     uint8_t  i_version;
595     uint32_t i_flags;
596
597     uint32_t i_entry_count;
598
599     uint32_t *i_sample_number;
600
601 } MP4_Box_data_stss_t;
602
603 typedef struct MP4_Box_data_stsh_s
604 {
605     uint8_t  i_version;
606     uint32_t i_flags;
607
608     uint32_t i_entry_count;
609
610     uint32_t *i_shadowed_sample_number;
611     uint32_t *i_sync_sample_number;
612
613 } MP4_Box_data_stsh_t;
614
615 typedef struct MP4_Box_data_stdp_s
616 {
617     uint8_t  i_version;
618     uint32_t i_flags;
619
620     uint16_t *i_priority;
621
622 } MP4_Box_data_stdp_t;
623
624 typedef struct MP4_Box_data_padb_s
625 {
626     uint8_t  i_version;
627     uint32_t i_flags;
628
629     uint32_t i_sample_count;
630
631     uint16_t *i_reserved1;   /* 1bit  */
632     uint16_t *i_pad2;        /* 3bits */
633     uint16_t *i_reserved2;   /* 1bit  */
634     uint16_t *i_pad1;        /* 3bits */
635
636
637 } MP4_Box_data_padb_t;
638
639
640 typedef struct MP4_Box_data_elst_s
641 {
642     uint8_t  i_version;
643     uint32_t i_flags;
644
645     uint32_t i_entry_count;
646
647     uint64_t *i_segment_duration;
648     int64_t  *i_media_time;
649     uint16_t *i_media_rate_integer;
650     uint16_t *i_media_rate_fraction;
651
652
653 } MP4_Box_data_elst_t;
654
655 typedef struct MP4_Box_data_cprt_s
656 {
657     uint8_t  i_version;
658     uint32_t i_flags;
659     /* 1 pad bit */
660     unsigned char i_language[3];
661
662     char *psz_notice;
663 } MP4_Box_data_cprt_t;
664
665
666 /* DecoderConfigDescriptor */
667 typedef struct MP4_descriptor_decoder_config_s
668 {
669     uint8_t i_objectTypeIndication;
670     uint8_t i_streamType;
671     int     b_upStream;
672     int     i_buffer_sizeDB;
673     int     i_max_bitrate;
674     int     i_avg_bitrate;
675
676     int     i_decoder_specific_info_len;
677     uint8_t *p_decoder_specific_info;
678     /* some other stuff */
679
680 } MP4_descriptor_decoder_config_t;
681
682 typedef struct MP4_descriptor_SL_config_s
683 {
684
685     int i_dummy; /* ANSI C forbids empty structures */
686
687 } MP4_descriptor_SL_config_t;
688
689
690 typedef struct MP4_descriptor_ES_s
691 {
692     uint16_t i_ES_ID;
693     int      b_stream_dependence;
694     int      b_url;
695     int      b_OCRstream;
696     int      i_stream_priority;
697
698     int      i_depend_on_ES_ID; /* if b_stream_dependence set */
699
700     unsigned char *psz_URL;
701
702     uint16_t i_OCR_ES_ID;       /* if b_OCRstream */
703     MP4_descriptor_decoder_config_t *p_decConfigDescr;
704
705     MP4_descriptor_SL_config_t *p_slConfigDescr;
706
707     /* some other stuff ... */
708
709 } MP4_descriptor_ES_t;
710
711 /* ES descriptor */
712 typedef struct MP4_Box_data_esds_s
713 {
714     uint8_t  i_version;
715     uint32_t i_flags;
716
717     MP4_descriptor_ES_t es_descriptor;
718
719 } MP4_Box_data_esds_t;
720
721
722 typedef struct MP4_Box_data_dcom_s
723 {
724     uint32_t i_algorithm; /* fourcc */
725
726 } MP4_Box_data_dcom_t;
727
728 typedef struct MP4_Box_data_cmvd_s
729 {
730     uint32_t i_uncompressed_size;
731     uint32_t i_compressed_size;
732
733     int     b_compressed; /* Set to 1 if compressed data, 0 if uncompressed */
734     uint8_t *p_data;
735
736 } MP4_Box_data_cmvd_t;
737
738 typedef struct MP4_Box_data_cmov_s
739 {
740     struct MP4_Box_s *p_moov; /* uncompressed moov */
741
742 } MP4_Box_data_cmov_t;
743
744 typedef struct
745 {
746     uint8_t  i_version;
747     uint32_t i_flags;
748
749     uint32_t i_ref_type;
750     char     *psz_ref;
751
752 } MP4_Box_data_rdrf_t;
753
754 typedef struct
755 {
756     uint8_t  i_version;
757     uint32_t i_flags;
758
759     uint32_t i_rate;
760
761 } MP4_Box_data_rmdr_t;
762
763 typedef struct
764 {
765     uint8_t  i_version;
766     uint32_t i_flags;
767
768     uint32_t i_gestaltType;
769     uint32_t i_val1;
770     uint32_t i_val2;
771     uint16_t i_checkType;   /* 0: val1 is version min
772                                1: gestalt value & val2 == val1 */
773
774 } MP4_Box_data_rmvc_t;
775
776 typedef struct
777 {
778     uint8_t  i_version;
779     uint32_t i_flags;
780
781
782 } MP4_Box_data_rmcd_t;
783
784 typedef struct
785 {
786     uint32_t i_quality;
787
788 } MP4_Box_data_rmqu_t;
789
790 typedef struct
791 {
792     char *psz_text;
793
794 } MP4_Box_data_0xa9xxx_t;
795
796 typedef struct
797 {
798     uint32_t i_entry_count;
799     uint32_t *i_track_ID;
800
801 } MP4_Box_data_tref_generic_t;
802
803 typedef struct
804 {
805     uint8_t  i_version;
806     uint32_t i_flags;
807
808     uint8_t i_chapter;
809     struct
810     {
811         char    *psz_name;
812         int64_t  i_start;
813     } chapter[256];
814 } MP4_Box_data_chpl_t;
815
816 typedef struct
817 {
818     uint8_t i_version;
819     uint8_t i_profile;
820     uint8_t i_profile_compatibility;
821     uint8_t i_level;
822
823     uint8_t i_reserved1;     /* 6 bits */
824     uint8_t i_length_size;
825
826     uint8_t i_reserved2;    /* 3 bits */
827     uint8_t  i_sps;
828     uint16_t *i_sps_length;
829     uint8_t  **sps;
830
831     uint8_t  i_pps;
832     uint16_t *i_pps_length;
833     uint8_t  **pps;
834
835     /* XXX: Hack raw avcC atom payload */
836     int     i_avcC;
837     uint8_t *p_avcC;
838
839 } MP4_Box_data_avcC_t;
840
841 /*
842 typedef struct MP4_Box_data__s
843 {
844     uint8_t  i_version;
845     uint32_t i_flags;
846
847 } MP4_Box_data__t;
848
849 */
850
851 typedef union MP4_Box_data_s
852 {
853     MP4_Box_data_ftyp_t *p_ftyp;
854     MP4_Box_data_mvhd_t *p_mvhd;
855     MP4_Box_data_tkhd_t *p_tkhd;
856     MP4_Box_data_mdhd_t *p_mdhd;
857     MP4_Box_data_hdlr_t *p_hdlr;
858     MP4_Box_data_vmhd_t *p_vmhd;
859     MP4_Box_data_smhd_t *p_smhd;
860     MP4_Box_data_hmhd_t *p_hmhd;
861     MP4_Box_data_url_t  *p_url;
862     MP4_Box_data_urn_t  *p_urn;
863     MP4_Box_data_dref_t *p_dref;
864     MP4_Box_data_stts_t *p_stts;
865     MP4_Box_data_ctts_t *p_ctts;
866     MP4_Box_data_stsd_t *p_stsd;
867         MP4_Box_data_sample_vide_t *p_sample_vide;
868         MP4_Box_data_sample_soun_t *p_sample_soun;
869         MP4_Box_data_sample_text_t *p_sample_text;
870         MP4_Box_data_sample_hint_t *p_sample_hint;
871
872         MP4_Box_data_esds_t *p_esds;
873         MP4_Box_data_avcC_t *p_avcC;
874
875     MP4_Box_data_stsz_t *p_stsz;
876     MP4_Box_data_stz2_t *p_stz2;
877     MP4_Box_data_stsc_t *p_stsc;
878     MP4_Box_data_co64_t *p_co64;
879     MP4_Box_data_stss_t *p_stss;
880     MP4_Box_data_stsh_t *p_stsh;
881     MP4_Box_data_stdp_t *p_stdp;
882     MP4_Box_data_padb_t *p_padb;
883     MP4_Box_data_elst_t *p_elst;
884     MP4_Box_data_cprt_t *p_cprt;
885
886     MP4_Box_data_dcom_t *p_dcom;
887     MP4_Box_data_cmvd_t *p_cmvd;
888     MP4_Box_data_cmov_t *p_cmov;
889
890     MP4_Box_data_moviehintinformation_rtp_t p_moviehintinformation_rtp;
891
892     MP4_Box_data_rdrf_t *p_rdrf;
893     MP4_Box_data_rmdr_t *p_rmdr;
894     MP4_Box_data_rmqu_t *p_rmqu;
895     MP4_Box_data_rmvc_t *p_rmvc;
896
897     MP4_Box_data_0xa9xxx_t *p_0xa9xxx;
898     MP4_Box_data_chpl_t *p_chpl;
899     MP4_Box_data_tref_generic_t *p_tref_generic;
900
901     void                *p_data; /* for unknow type */
902 } MP4_Box_data_t;
903
904
905
906 /* the most basic structure */
907 typedef struct MP4_Box_s
908 {
909     off_t        i_pos;      /* absolute position */
910
911     uint32_t     i_type;
912     uint32_t     i_shortsize;
913
914     UUID_t       i_uuid;  /* Set if i_type == "uuid" */
915
916     uint64_t     i_size; /* always set so use it */
917
918     MP4_Box_data_t   data;   /* union of pointers on extended data depending
919                                 on i_type (or i_usertype) */
920
921     struct MP4_Box_s *p_father; /* pointer on the father Box */
922
923     struct MP4_Box_s *p_first;  /* pointer on the first child Box */
924     struct MP4_Box_s *p_last;
925
926     struct MP4_Box_s *p_next;   /* pointer on the next boxes at the same level */
927
928 } MP4_Box_t;
929
930
931
932 /*****************************************************************************
933  * MP4_BoxGetRoot : Parse the entire file, and create all boxes in memory
934  *****************************************************************************
935  *  The first box is a virtual box "root" and is the father for all first
936  *  level boxes
937  *****************************************************************************/
938 MP4_Box_t *MP4_BoxGetRoot( stream_t * );
939
940 /*****************************************************************************
941  * MP4_FreeBox : free memory allocated after read with MP4_ReadBox
942  *               or MP4_BoxGetRoot, this means also children boxes
943  * XXX : all children have to be allocated by a malloc !! and
944  *         p_box is freed
945  *****************************************************************************/
946 void MP4_BoxFree( stream_t *, MP4_Box_t *p_box );
947
948 /*****************************************************************************
949  * MP4_DumpBoxStructure: print the structure of the p_box
950  *****************************************************************************
951  * Usefull while debugging
952  *****************************************************************************/
953 void MP4_BoxDumpStructure( stream_t *p_input, MP4_Box_t *p_box );
954
955
956 /*****************************************************************************
957  * MP4_BoxGet: find a box given a path relative to p_box
958  *****************************************************************************
959  * Path Format: . .. / as usual
960  *              [number] to specifie box number ex: trak[12]
961  *
962  * ex: /moov/trak[12]
963  *     ../mdia
964  *****************************************************************************/
965 MP4_Box_t *MP4_BoxGet( MP4_Box_t *p_box, const char *psz_fmt, ... );
966
967 /*****************************************************************************
968  * MP4_BoxCount: find number of box given a path relative to p_box
969  *****************************************************************************
970  * Path Format: . .. / as usual
971  *              [number] to specifie box number ex: trak[12]
972  *
973  * ex: /moov/trak
974  *     ../mdia
975  *****************************************************************************/
976 int MP4_BoxCount( MP4_Box_t *p_box, const char *psz_fmt, ... );
977
978 int MP4_ReadBoxCommon( stream_t *p_stream, MP4_Box_t *p_box );
979 int MP4_ReadBox_sample_vide( stream_t *p_stream, MP4_Box_t *p_box );
980 void MP4_FreeBox_sample_vide( MP4_Box_t *p_box );
981
982 #endif