]> git.sesse.net Git - vlc/blob - plugins/avi/avi.h
* avi.c : quick hack to read file created by ffmpeg. I think it should
[vlc] / plugins / avi / avi.h
1 /*****************************************************************************
2  * avi.h : AVI file Stream input module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: avi.h,v 1.9 2002/07/15 19:33:02 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 #define         MAX_PACKETS_IN_FIFO     2
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 /* Sound formats */
44 #define WAVE_FORMAT_UNKNOWN         0x0000
45 #define WAVE_FORMAT_PCM             0x0001
46 #define WAVE_FORMAT_MPEG            0x0050
47 #define WAVE_FORMAT_MPEGLAYER3      0x0055
48 #define WAVE_FORMAT_AC3             0x2000
49
50 typedef struct bitmapinfoheader_s
51 {
52     u32 i_size; /* size of header */
53     u32 i_width;
54     u32 i_height;
55     u16 i_planes;
56     u16 i_bitcount;
57     u32 i_compression;
58     u32 i_sizeimage;
59     u32 i_xpelspermeter;
60     u32 i_ypelspermeter;
61     u32 i_clrused;
62     u32 i_clrimportant;
63 } bitmapinfoheader_t;
64
65 typedef struct waveformatex_s
66 {
67     u16 i_formattag;
68     u16 i_channels;
69     u32 i_samplespersec;
70     u32 i_avgbytespersec;
71     u16 i_blockalign;
72     u16 i_bitspersample;
73     u16 i_size; /* the extra size in bytes */
74 } waveformatex_t;
75
76
77 typedef struct MainAVIHeader_s
78 {
79     u32 i_microsecperframe;
80     u32 i_maxbytespersec;
81     u32 i_reserved1; /* dwPaddingGranularity;    pad to multiples of this
82                          size; normally 2K */
83     u32 i_flags;
84     u32 i_totalframes;
85     u32 i_initialframes;
86     u32 i_streams;
87     u32 i_suggestedbuffersize;
88     u32 i_width;
89     u32 i_height;
90     u32 i_scale;
91     u32 i_rate;
92     u32 i_start;
93     u32 i_length;
94
95 } MainAVIHeader_t;
96
97 typedef struct AVIStreamHeader_s
98 {
99     u32 i_type;
100     u32 i_handler;
101     u32 i_flags;
102     u32 i_reserved1;    /* wPriority wLanguage */
103     u32 i_initialframes;
104     u32 i_scale;
105     u32 i_rate;
106     u32 i_start;
107     u32 i_length;       /* In units above... */
108     u32 i_suggestedbuffersize;
109     u32 i_quality;
110     u32 i_samplesize;
111
112 } AVIStreamHeader_t;
113
114 typedef struct AVIIndexEntry_s
115 {
116     u32 i_id;
117     u32 i_flags;
118     u32 i_pos;
119     u32 i_length;
120     u32 i_lengthtotal;
121 } AVIIndexEntry_t;
122
123 typedef struct AVIESBuffer_s
124 {
125     struct AVIESBuffer_s *p_next;
126
127     pes_packet_t *p_pes;
128     int i_posc;
129     int i_posb;
130 } AVIESBuffer_t;
131
132
133 typedef struct AVIStreamInfo_s
134 {
135
136     riffchunk_t *p_strl;
137     riffchunk_t *p_strh;
138     riffchunk_t *p_strf;
139     riffchunk_t *p_strd; /* not used */
140     
141     AVIStreamHeader_t header;
142     
143     u8 i_cat;           /* AUDIO_ES, VIDEO_ES */
144     bitmapinfoheader_t  video_format;
145     waveformatex_t      audio_format;
146     es_descriptor_t     *p_es;   
147     int                 b_selected; /* newly selected */
148     AVIIndexEntry_t     *p_index;
149     int                 i_idxnb;
150     int                 i_idxmax; 
151
152     int                 i_idxposc;  /* numero of chunk */
153     int                 i_idxposb;  /* byte in the current chunk */
154
155     /* add some buffering */
156     AVIESBuffer_t       *p_pes_first;
157     AVIESBuffer_t       *p_pes_last;
158     int                 i_pes_count;
159     int                 i_pes_totalsize;
160 } AVIStreamInfo_t;
161
162 typedef struct demux_data_avi_file_s
163 {
164     mtime_t i_pcr; 
165     int     i_rate;
166     riffchunk_t *p_riff;
167     riffchunk_t *p_hdrl;
168     riffchunk_t *p_movi;
169     riffchunk_t *p_idx1;
170
171     int     b_seekable;
172
173     /* Info extrated from avih */
174     MainAVIHeader_t avih;
175
176     /* number of stream and informations*/
177     int i_streams;
178     AVIStreamInfo_t   **pp_info; 
179
180     /* current audio and video es */
181     AVIStreamInfo_t *p_info_video;
182     AVIStreamInfo_t *p_info_audio;
183
184 } demux_data_avi_file_t;
185
186 /* current codec */
187 static struct
188 {
189     int i_fourcc;
190     int i_vlc_codec;
191     char *psz_name;
192
193 } AVI_VideoCodecs [] = {
194     { FOURCC_DIV1,  MSMPEG4v1_VIDEO_ES, "MS MPEG-4 v1" },
195     { FOURCC_div1,  MSMPEG4v1_VIDEO_ES, "MS MPEG-4 v1" },
196     { FOURCC_MPG4,  MSMPEG4v1_VIDEO_ES, "MS MPEG-4 v1" },
197     { FOURCC_mpg4,  MSMPEG4v1_VIDEO_ES, "MS MPEG-4 v1" },
198
199     { FOURCC_DIV2,  MSMPEG4v2_VIDEO_ES, "MS MPEG-4 v2" },
200     { FOURCC_div2,  MSMPEG4v2_VIDEO_ES, "MS MPEG-4 v2" },
201     { FOURCC_MP42,  MSMPEG4v2_VIDEO_ES, "MS MPEG-4 v2" },
202     { FOURCC_mp42,  MSMPEG4v2_VIDEO_ES, "MS MPEG-4 v2" },
203     
204     { FOURCC_MPG3,  MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
205     { FOURCC_mpg3,  MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
206     { FOURCC_div3,  MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
207     { FOURCC_MP43,  MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
208     { FOURCC_mp43,  MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
209     { FOURCC_DIV3,  MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
210     { FOURCC_DIV4,  MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
211     { FOURCC_div4,  MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
212     { FOURCC_DIV5,  MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
213     { FOURCC_div5,  MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
214     { FOURCC_DIV6,  MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
215     { FOURCC_div6,  MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
216     { FOURCC_AP41,  MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
217     { FOURCC_3IV1,  MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" }, /* wrong */
218
219     { FOURCC_DIVX,  MPEG4_VIDEO_ES, "MPEG-4" },
220     { FOURCC_divx,  MPEG4_VIDEO_ES, "MPEG-4" },
221     { FOURCC_MP4S,  MPEG4_VIDEO_ES, "MPEG-4" },
222     { FOURCC_mp4s,  MPEG4_VIDEO_ES, "MPEG-4" },
223     { FOURCC_M4S2,  MPEG4_VIDEO_ES, "MPEG-4" },
224     { FOURCC_m4s2,  MPEG4_VIDEO_ES, "MPEG-4" },
225     { FOURCC_xvid,  MPEG4_VIDEO_ES, "MPEG-4" },
226     { FOURCC_XVID,  MPEG4_VIDEO_ES, "MPEG-4" },
227     { FOURCC_XviD,  MPEG4_VIDEO_ES, "MPEG-4" },
228     { FOURCC_DX50,  MPEG4_VIDEO_ES, "MPEG-4" },
229     { FOURCC_mp4v,  MPEG4_VIDEO_ES, "MPEG-4" },
230     { FOURCC_4,     MPEG4_VIDEO_ES, "MPEG-4" },
231     
232     { FOURCC_H263,  H263_VIDEO_ES, "H263" },
233     { FOURCC_h263,  H263_VIDEO_ES, "H263" },
234     { FOURCC_U263,  H263_VIDEO_ES, "H263" },
235
236     { FOURCC_I263,  I263_VIDEO_ES, "H263.I" },
237     { FOURCC_i263,  I263_VIDEO_ES, "H263.I" },
238
239     { 0,            UNKNOWN_ES,     "Unknown" }
240 };
241
242 static int AVI_GetVideoCodec( int i_fourcc,
243                               int *pi_vlc_codec,
244                               char **ppsz_name )
245 {
246     int i_codec;
247
248     for( i_codec = 0; ; i_codec++ )
249     {
250         if( ( AVI_VideoCodecs[i_codec].i_fourcc == i_fourcc )||
251             ( AVI_VideoCodecs[i_codec].i_fourcc == 0 ) )
252         {
253             break;
254         }
255     }
256     if( pi_vlc_codec )
257         *pi_vlc_codec = AVI_VideoCodecs[i_codec].i_vlc_codec;
258     if( ppsz_name )
259         *ppsz_name = AVI_VideoCodecs[i_codec].psz_name;
260
261     return( AVI_VideoCodecs[i_codec].i_fourcc == 0 ? 0 : 1 );
262 }                        
263