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