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