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