9f01ca6cc36d62e3b305b8f4744cd614080f7692
[vlc.git] / modules / demux / avi / libavi.h
1 /*****************************************************************************
2  * libavi.h : LibAVI library
3  ******************************************************************************
4  * Copyright (C) 2001-2003 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
23 /* flags for use in <dwFlags> in AVIFileHdr */
24 #define AVIF_HASINDEX       0x00000010  /* Index at end of file? */
25 #define AVIF_MUSTUSEINDEX   0x00000020
26 #define AVIF_ISINTERLEAVED  0x00000100
27 #define AVIF_TRUSTCKTYPE    0x00000800  /* Use CKType to find key frames? */
28 #define AVIF_WASCAPTUREFILE 0x00010000
29 #define AVIF_COPYRIGHTED    0x00020000
30
31 /* Flags for index */
32 #define AVIIF_LIST          0x00000001L /* chunk is a 'LIST' */
33 #define AVIIF_KEYFRAME      0x00000010L /* this frame is a key frame.*/
34 #define AVIIF_NOTIME        0x00000100L /* this frame doesn't take any time */
35 #define AVIIF_COMPUSE       0x0FFF0000L /* these bits are for compressor use */
36
37 #define AVIIF_FIXKEYFRAME   0x00001000L /* invented; used to say that */
38                                         /* the keyframe flag isn't a true flag */
39                                         /* but have to be verified */
40
41 #define AVI_CHUNK_COMMON            \
42     vlc_fourcc_t i_chunk_fourcc;    \
43     uint64_t i_chunk_size;          \
44     uint64_t i_chunk_pos;           \
45     union  avi_chunk_u *p_next;    \
46     union  avi_chunk_u *p_father;  \
47     union  avi_chunk_u *p_first;   \
48     union  avi_chunk_u *p_last;
49
50 #define AVI_CHUNK( p_chk ) (avi_chunk_t*)(p_chk)
51
52 typedef struct idx1_entry_s
53 {
54     vlc_fourcc_t i_fourcc;
55     uint32_t i_flags;
56     uint32_t i_pos;
57     uint32_t i_length;
58
59 } idx1_entry_t;
60 typedef struct avi_chunk_common_s
61 {
62     AVI_CHUNK_COMMON
63 } avi_chunk_common_t;
64
65 typedef struct avi_chunk_list_s
66 {
67     AVI_CHUNK_COMMON
68     vlc_fourcc_t i_type;
69 } avi_chunk_list_t;
70
71 typedef struct avi_chunk_idx1_s
72 {
73     AVI_CHUNK_COMMON
74     unsigned int i_entry_count;
75     unsigned int i_entry_max;
76     idx1_entry_t *entry;
77
78 } avi_chunk_idx1_t;
79
80 typedef struct avi_chunk_avih_s
81 {
82     AVI_CHUNK_COMMON
83     uint32_t i_microsecperframe;
84     uint32_t i_maxbytespersec;
85     uint32_t i_reserved1; /* dwPaddingGranularity;    pad to multiples of this
86                              size; normally 2K */
87     uint32_t i_flags;
88     uint32_t i_totalframes;
89     uint32_t i_initialframes;
90     uint32_t i_streams;
91     uint32_t i_suggestedbuffersize;
92     uint32_t i_width;
93     uint32_t i_height;
94     uint32_t i_scale;
95     uint32_t i_rate;
96     uint32_t i_start;
97     uint32_t i_length;
98 } avi_chunk_avih_t;
99
100 typedef struct avi_chunk_strh_s
101 {
102     AVI_CHUNK_COMMON
103     vlc_fourcc_t i_type;
104     uint32_t i_handler;
105     uint32_t i_flags;
106     uint32_t i_reserved1;    /* wPriority wLanguage */
107     uint32_t i_initialframes;
108     uint32_t i_scale;
109     uint32_t i_rate;
110     uint32_t i_start;
111     uint32_t i_length;       /* In units above... */
112     uint32_t i_suggestedbuffersize;
113     uint32_t i_quality;
114     uint32_t i_samplesize;
115 } avi_chunk_strh_t;
116
117 typedef struct avi_chunk_strf_auds_s
118 {
119     AVI_CHUNK_COMMON
120     int             i_cat;
121     WAVEFORMATEX    *p_wf;
122 } avi_chunk_strf_auds_t;
123
124 typedef struct avi_chunk_strf_vids_s
125 {
126     AVI_CHUNK_COMMON
127     int              i_cat;
128     BITMAPINFOHEADER *p_bih;
129 } avi_chunk_strf_vids_t;
130
131 typedef union avi_chunk_strf_u
132 {
133     avi_chunk_strf_auds_t   auds;
134     avi_chunk_strf_vids_t   vids;
135     struct
136     {
137         AVI_CHUNK_COMMON
138         int i_cat;
139     }                       common;
140 } avi_chunk_strf_t;
141
142 typedef struct avi_chunk_strd_s
143 {
144     AVI_CHUNK_COMMON
145     uint8_t  *p_data;
146 } avi_chunk_strd_t;
147
148
149 #define AVI_INDEX_OF_INDEXES    0x00
150 #define AVI_INDEX_OF_CHUNKS     0x01
151 #define AVI_INDEX_IS_DATA       0x80
152
153 #define AVI_INDEX_2FIELD        0x01
154 typedef struct
155 {
156     uint32_t i_offset;
157     uint32_t i_size;
158 } indx_std_entry_t;
159
160 typedef struct
161 {
162     uint32_t i_offset;
163     uint32_t i_size;
164     uint32_t i_offsetfield2;
165 } indx_field_entry_t;
166
167 typedef struct
168 {
169     uint64_t i_offset;
170     uint32_t i_size;
171     uint32_t i_duration;
172 } indx_super_entry_t;
173
174 typedef struct avi_chunk_indx_s
175 {
176     AVI_CHUNK_COMMON
177     int16_t i_longsperentry;
178     int8_t  i_indexsubtype;
179     int8_t  i_indextype;
180     int32_t i_entriesinuse;
181     vlc_fourcc_t i_id;
182
183     int64_t i_baseoffset;
184
185     union
186     {
187         indx_std_entry_t    *std;
188         indx_field_entry_t  *field;
189         indx_super_entry_t  *super;
190     } idx;
191 } avi_chunk_indx_t;
192
193 typedef struct avi_chunk_STRING_s
194 {
195     AVI_CHUNK_COMMON
196     char *p_type;
197     char *p_str;
198 } avi_chunk_STRING_t;
199
200 typedef union avi_chunk_u
201 {
202     avi_chunk_common_t  common;
203     avi_chunk_list_t    list;
204     avi_chunk_idx1_t    idx1;
205     avi_chunk_avih_t    avih;
206     avi_chunk_strh_t    strh;
207     avi_chunk_strf_t    strf;
208     avi_chunk_strd_t    strd;
209     avi_chunk_indx_t    indx;
210     avi_chunk_STRING_t  strz;
211 } avi_chunk_t;
212
213 /****************************************************************************
214  * Stream(input) access functions
215  ****************************************************************************/
216 int     _AVI_ChunkRead( stream_t *,
217                         avi_chunk_t *p_chk,
218                         avi_chunk_t *p_father );
219
220 int     _AVI_ChunkCount( avi_chunk_t *, vlc_fourcc_t );
221 void   *_AVI_ChunkFind ( avi_chunk_t *, vlc_fourcc_t, int );
222
223 int     AVI_ChunkReadRoot( stream_t *, avi_chunk_t *p_root );
224 void    AVI_ChunkFreeRoot( stream_t *, avi_chunk_t  *p_chk );
225
226 #define AVI_ChunkRead( s, p_chk, p_father ) \
227     _AVI_ChunkRead( s, p_chk, (avi_chunk_t*)p_father )
228 #define AVI_ChunkCount( p_chk, i_fourcc ) \
229     _AVI_ChunkCount( (avi_chunk_t*)p_chk, i_fourcc )
230 #define AVI_ChunkFind( p_chk, i_fourcc, i_number ) \
231     _AVI_ChunkFind( (avi_chunk_t*)p_chk, i_fourcc, i_number )
232
233
234     /* *** avi stuff *** */
235
236 #define AVIFOURCC_RIFF         VLC_FOURCC('R','I','F','F')
237 #define AVIFOURCC_LIST         VLC_FOURCC('L','I','S','T')
238 #define AVIFOURCC_JUNK         VLC_FOURCC('J','U','N','K')
239 #define AVIFOURCC_AVI          VLC_FOURCC('A','V','I',' ')
240 #define AVIFOURCC_AVIX         VLC_FOURCC('A','V','I','X')
241 #define AVIFOURCC_WAVE         VLC_FOURCC('W','A','V','E')
242 #define AVIFOURCC_INFO         VLC_FOURCC('I','N','F','O')
243
244 #define AVIFOURCC_avih         VLC_FOURCC('a','v','i','h')
245 #define AVIFOURCC_hdrl         VLC_FOURCC('h','d','r','l')
246 #define AVIFOURCC_movi         VLC_FOURCC('m','o','v','i')
247 #define AVIFOURCC_idx1         VLC_FOURCC('i','d','x','1')
248
249 #define AVIFOURCC_strl         VLC_FOURCC('s','t','r','l')
250 #define AVIFOURCC_strh         VLC_FOURCC('s','t','r','h')
251 #define AVIFOURCC_strf         VLC_FOURCC('s','t','r','f')
252 #define AVIFOURCC_strd         VLC_FOURCC('s','t','r','d')
253 #define AVIFOURCC_strn         VLC_FOURCC('s','t','r','n')
254 #define AVIFOURCC_indx         VLC_FOURCC('i','n','d','x')
255
256 #define AVIFOURCC_rec          VLC_FOURCC('r','e','c',' ')
257 #define AVIFOURCC_auds         VLC_FOURCC('a','u','d','s')
258 #define AVIFOURCC_vids         VLC_FOURCC('v','i','d','s')
259 #define AVIFOURCC_txts         VLC_FOURCC('t','x','t','s')
260 #define AVIFOURCC_mids         VLC_FOURCC('m','i','d','s')
261 #define AVIFOURCC_iavs         VLC_FOURCC('i','a','v','s')
262 #define AVIFOURCC_ivas         VLC_FOURCC('i','v','a','s')
263
264 #define AVIFOURCC_IARL         VLC_FOURCC('I','A','R','L')
265 #define AVIFOURCC_IART         VLC_FOURCC('I','A','R','T')
266 #define AVIFOURCC_ICMS         VLC_FOURCC('I','C','M','S')
267 #define AVIFOURCC_ICMT         VLC_FOURCC('I','C','M','T')
268 #define AVIFOURCC_ICOP         VLC_FOURCC('I','C','O','P')
269 #define AVIFOURCC_ICRD         VLC_FOURCC('I','C','R','D')
270 #define AVIFOURCC_ICRP         VLC_FOURCC('I','C','R','P')
271 #define AVIFOURCC_IDIM         VLC_FOURCC('I','D','I','M')
272 #define AVIFOURCC_IDPI         VLC_FOURCC('I','D','P','I')
273 #define AVIFOURCC_IENG         VLC_FOURCC('I','E','N','G')
274 #define AVIFOURCC_IGNR         VLC_FOURCC('I','G','N','R')
275 #define AVIFOURCC_IKEY         VLC_FOURCC('I','K','E','Y')
276 #define AVIFOURCC_ILGT         VLC_FOURCC('I','L','G','T')
277 #define AVIFOURCC_IMED         VLC_FOURCC('I','M','E','D')
278 #define AVIFOURCC_INAM         VLC_FOURCC('I','N','A','M')
279 #define AVIFOURCC_IPLT         VLC_FOURCC('I','P','L','T')
280 #define AVIFOURCC_IPRD         VLC_FOURCC('I','P','R','D')
281 #define AVIFOURCC_ISBJ         VLC_FOURCC('I','S','B','J')
282 #define AVIFOURCC_ISFT         VLC_FOURCC('I','S','F','T')
283 #define AVIFOURCC_ISHP         VLC_FOURCC('I','S','H','P')
284 #define AVIFOURCC_ISRC         VLC_FOURCC('I','S','R','C')
285 #define AVIFOURCC_ISRF         VLC_FOURCC('I','S','R','F')
286 #define AVIFOURCC_ITCH         VLC_FOURCC('I','T','C','H')
287 #define AVIFOURCC_ISMP         VLC_FOURCC('I','S','M','P')
288 #define AVIFOURCC_IDIT         VLC_FOURCC('I','D','I','T')
289
290  
291 #define AVITWOCC_wb            VLC_TWOCC('w','b')
292 #define AVITWOCC_db            VLC_TWOCC('d','b')
293 #define AVITWOCC_dc            VLC_TWOCC('d','c')
294 #define AVITWOCC_pc            VLC_TWOCC('p','c')
295     /* *** codex stuff ***  */
296
297     /* Microsoft RLE video */
298 #define FOURCC_1            VLC_FOURCC( 1,  0,  0,  0 )
299
300     /* MPEG4 video */
301 #define FOURCC_DIVX         VLC_FOURCC('D','I','V','X')
302 #define FOURCC_divx         VLC_FOURCC('d','i','v','x')
303 #define FOURCC_DIV1         VLC_FOURCC('D','I','V','1')
304 #define FOURCC_div1         VLC_FOURCC('d','i','v','1')
305 #define FOURCC_MP4S         VLC_FOURCC('M','P','4','S')
306 #define FOURCC_mp4s         VLC_FOURCC('m','p','4','s')
307 #define FOURCC_M4S2         VLC_FOURCC('M','4','S','2')
308 #define FOURCC_m4s2         VLC_FOURCC('m','4','s','2')
309 #define FOURCC_xvid         VLC_FOURCC('x','v','i','d')
310 #define FOURCC_XVID         VLC_FOURCC('X','V','I','D')
311 #define FOURCC_XviD         VLC_FOURCC('X','v','i','D')
312 #define FOURCC_DX50         VLC_FOURCC('D','X','5','0')
313 #define FOURCC_dx50         VLC_FOURCC('d','x','5','0')
314 #define FOURCC_mp4v         VLC_FOURCC('m','p','4','v')
315 #define FOURCC_4            VLC_FOURCC( 4,  0,  0,  0 )
316
317     /* MSMPEG4 v2 */
318 #define FOURCC_MPG4         VLC_FOURCC('M','P','G','4')
319 #define FOURCC_mpg4         VLC_FOURCC('m','p','g','4')
320 #define FOURCC_DIV2         VLC_FOURCC('D','I','V','2')
321 #define FOURCC_div2         VLC_FOURCC('d','i','v','2')
322 #define FOURCC_MP42         VLC_FOURCC('M','P','4','2')
323 #define FOURCC_mp42         VLC_FOURCC('m','p','4','2')
324
325     /* MSMPEG4 v3 / M$ mpeg4 v3 */
326 #define FOURCC_MPG3         VLC_FOURCC('M','P','G','3')
327 #define FOURCC_mpg3         VLC_FOURCC('m','p','g','3')
328 #define FOURCC_div3         VLC_FOURCC('d','i','v','3')
329 #define FOURCC_MP43         VLC_FOURCC('M','P','4','3')
330 #define FOURCC_mp43         VLC_FOURCC('m','p','4','3')
331
332     /* DivX 3.20 */
333 #define FOURCC_DIV3         VLC_FOURCC('D','I','V','3')
334 #define FOURCC_DIV4         VLC_FOURCC('D','I','V','4')
335 #define FOURCC_div4         VLC_FOURCC('d','i','v','4')
336 #define FOURCC_DIV5         VLC_FOURCC('D','I','V','5')
337 #define FOURCC_div5         VLC_FOURCC('d','i','v','5')
338 #define FOURCC_DIV6         VLC_FOURCC('D','I','V','6')
339 #define FOURCC_div6         VLC_FOURCC('d','i','v','6')
340
341     /* AngelPotion stuff */
342 #define FOURCC_AP41         VLC_FOURCC('A','P','4','1')
343
344     /* 3IVX */
345 #define FOURCC_3IV1         VLC_FOURCC('3','I','V','1')
346 #define FOURCC_3iv1         VLC_FOURCC('2','i','v','1')
347 #define FOURCC_3IV2         VLC_FOURCC('3','I','V','2')
348 #define FOURCC_3iv2         VLC_FOURCC('3','i','v','2')
349 #define FOURCC_3IVD         VLC_FOURCC('3','I','V','D')
350 #define FOURCC_3ivd         VLC_FOURCC('3','i','v','d')
351 #define FOURCC_3VID         VLC_FOURCC('3','V','I','D')
352 #define FOURCC_3vid         VLC_FOURCC('3','v','i','d')
353
354     /* H263 and H263i */
355 #define FOURCC_H263         VLC_FOURCC('H','2','6','3')
356 #define FOURCC_h263         VLC_FOURCC('h','2','6','3')
357 #define FOURCC_U263         VLC_FOURCC('U','2','6','3')
358 #define FOURCC_I263         VLC_FOURCC('I','2','6','3')
359 #define FOURCC_i263         VLC_FOURCC('i','2','6','3')
360
361     /* H264 */
362 #define FOURCC_H264         VLC_FOURCC('H','2','6','4')
363 #define FOURCC_h264         VLC_FOURCC('h','2','6','4')
364 #define FOURCC_VSSH         VLC_FOURCC('V','S','S','H')
365
366     /* DV */
367 #define FOURCC_dvsd         VLC_FOURCC('d','v','s','d')
368 #define FOURCC_dvhd         VLC_FOURCC('d','v','h','d')
369 #define FOURCC_dvsl         VLC_FOURCC('d','v','s','l')