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