Coverage Report

Created: 2025-08-29 07:30

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