09b3a7e83b2ccd8de99b9424de9b888e5b220304
[vlc.git] / modules / codec / ffmpeg / ffmpeg.h
1 /*****************************************************************************
2  * ffmpeg_vdec.h: video decoder using ffmpeg library
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: ffmpeg.h,v 1.1 2002/08/04 17:23:42 sam Exp $
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  * 
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /* Pour un flux video */
25 typedef struct bitmapinfoheader_s
26 {
27     u32 i_size; /* size of header */
28     u32 i_width;
29     u32 i_height;
30     u16 i_planes;
31     u16 i_bitcount;
32     u32 i_compression;
33     u32 i_sizeimage;
34     u32 i_xpelspermeter;
35     u32 i_ypelspermeter;
36     u32 i_clrused;
37     u32 i_clrimportant;
38
39     int i_data;
40     u8  *p_data;
41
42 } bitmapinfoheader_t;
43
44 /* MPEG4 video */
45 #define FOURCC_DIVX         VLC_FOURCC('D','I','V','X')
46 #define FOURCC_divx         VLC_FOURCC('d','i','v','x')
47 #define FOURCC_DIV1         VLC_FOURCC('D','I','V','1')
48 #define FOURCC_div1         VLC_FOURCC('d','i','v','1')
49 #define FOURCC_MP4S         VLC_FOURCC('M','P','4','S')
50 #define FOURCC_mp4s         VLC_FOURCC('m','p','4','s')
51 #define FOURCC_M4S2         VLC_FOURCC('M','4','S','2')
52 #define FOURCC_m4s2         VLC_FOURCC('m','4','s','2')
53 #define FOURCC_xvid         VLC_FOURCC('x','v','i','d')
54 #define FOURCC_XVID         VLC_FOURCC('X','V','I','D')
55 #define FOURCC_XviD         VLC_FOURCC('X','v','i','D')
56 #define FOURCC_DX50         VLC_FOURCC('D','X','5','0')
57 #define FOURCC_mp4v         VLC_FOURCC('m','p','4','v')
58 #define FOURCC_4            VLC_FOURCC( 4,  0,  0,  0 )
59
60 /* MSMPEG4 v2 */
61 #define FOURCC_MPG4         VLC_FOURCC('M','P','G','4')
62 #define FOURCC_mpg4         VLC_FOURCC('m','p','g','4')
63 #define FOURCC_DIV2         VLC_FOURCC('D','I','V','2')
64 #define FOURCC_div2         VLC_FOURCC('d','i','v','2')
65 #define FOURCC_MP42         VLC_FOURCC('M','P','4','2')
66 #define FOURCC_mp42         VLC_FOURCC('m','p','4','2')
67
68 /* MSMPEG4 v3 / M$ mpeg4 v3 */
69 #define FOURCC_MPG3         VLC_FOURCC('M','P','G','3')
70 #define FOURCC_mpg3         VLC_FOURCC('m','p','g','3')
71 #define FOURCC_div3         VLC_FOURCC('d','i','v','3')
72 #define FOURCC_MP43         VLC_FOURCC('M','P','4','3')
73 #define FOURCC_mp43         VLC_FOURCC('m','p','4','3')
74
75 /* DivX 3.20 */
76 #define FOURCC_DIV3         VLC_FOURCC('D','I','V','3')
77 #define FOURCC_DIV4         VLC_FOURCC('D','I','V','4')
78 #define FOURCC_div4         VLC_FOURCC('d','i','v','4')
79 #define FOURCC_DIV5         VLC_FOURCC('D','I','V','5')
80 #define FOURCC_div5         VLC_FOURCC('d','i','v','5')
81 #define FOURCC_DIV6         VLC_FOURCC('D','I','V','6')
82 #define FOURCC_div6         VLC_FOURCC('d','i','v','6')
83
84 /* AngelPotion stuff */
85 #define FOURCC_AP41         VLC_FOURCC('A','P','4','1')
86
87 /* ?? */
88 #define FOURCC_3IV1         VLC_FOURCC('3','I','V','1')
89 #define FOURCC_3IV2         VLC_FOURCC('3','I','V','2')
90
91 /* H263 and H263i */        
92 #define FOURCC_H263         VLC_FOURCC('H','2','6','3')
93 #define FOURCC_h263         VLC_FOURCC('h','2','6','3')
94 #define FOURCC_U263         VLC_FOURCC('U','2','6','3')
95 #define FOURCC_I263         VLC_FOURCC('I','2','6','3')
96 #define FOURCC_i263         VLC_FOURCC('i','2','6','3')
97
98 /* Sorenson v1 */
99 #define FOURCC_SVQ1 VLC_FOURCC( 'S', 'V', 'Q', '1' )
100
101 static int ffmpeg_GetFfmpegCodec( vlc_fourcc_t i_fourcc,
102                                   int *pi_ffmpeg_codec,
103                                   char **ppsz_name )
104 {
105     int i_codec = 0;
106     char *psz_name = NULL;
107
108     switch( i_fourcc )
109     {
110 #if LIBAVCODEC_BUILD >= 4608 
111         case FOURCC_DIV1:
112         case FOURCC_div1:
113         case FOURCC_MPG4:
114         case FOURCC_mpg4:
115             i_codec = CODEC_ID_MSMPEG4V1;
116             psz_name = "MS MPEG-4 v1";
117             break;
118
119         case FOURCC_DIV2:
120         case FOURCC_div2:
121         case FOURCC_MP42:
122         case FOURCC_mp42:
123             i_codec = CODEC_ID_MSMPEG4V2;
124             psz_name = "MS MPEG-4 v2";
125             break;
126 #endif
127
128         case FOURCC_MPG3:
129         case FOURCC_mpg3:
130         case FOURCC_div3:
131         case FOURCC_MP43:
132         case FOURCC_mp43:
133         case FOURCC_DIV3:
134         case FOURCC_DIV4:
135         case FOURCC_div4:
136         case FOURCC_DIV5:
137         case FOURCC_div5:
138         case FOURCC_DIV6:
139         case FOURCC_div6:
140         case FOURCC_AP41:
141         case FOURCC_3IV1:
142 #if LIBAVCODEC_BUILD >= 4608 
143             i_codec = CODEC_ID_MSMPEG4V3;
144 #else
145             i_codec = CODEC_ID_MSMPEG4;
146 #endif
147             psz_name = "MS MPEG-4 v3";
148             break;
149
150 #if LIBAVCODEC_BUILD >= 4615
151         case FOURCC_SVQ1:
152             i_codec = CODEC_ID_SVQ1;
153             psz_name = "SVQ-1 (Sorenson Video v1)";
154             break;
155 #endif
156
157         case FOURCC_DIVX:
158         case FOURCC_divx:
159         case FOURCC_MP4S:
160         case FOURCC_mp4s:
161         case FOURCC_M4S2:
162         case FOURCC_m4s2:
163         case FOURCC_xvid:
164         case FOURCC_XVID:
165         case FOURCC_XviD:
166         case FOURCC_DX50:
167         case FOURCC_mp4v:
168         case FOURCC_4:
169         case FOURCC_3IV2:
170
171             i_codec = CODEC_ID_MPEG4;
172             psz_name = "MPEG-4";
173             break;
174
175         case FOURCC_H263:
176         case FOURCC_h263:
177         case FOURCC_U263:
178             i_codec = CODEC_ID_H263;
179             psz_name = "H263";
180             break;
181
182         case FOURCC_I263:
183         case FOURCC_i263:
184             i_codec = CODEC_ID_H263I;
185             psz_name = "I263.I";
186             break;
187     }
188
189     if( i_codec )
190     {
191         if( pi_ffmpeg_codec ) *pi_ffmpeg_codec = i_codec;
192         if( ppsz_name ) *ppsz_name = psz_name;
193         return VLC_TRUE;
194     }
195
196     return VLC_FALSE;
197 }
198
199
200 typedef struct videodec_thread_s
201 {
202     decoder_fifo_t      *p_fifo;    
203
204     bitmapinfoheader_t  format;
205
206     AVCodecContext      context, *p_context;
207     AVCodec             *p_codec;
208     vout_thread_t       *p_vout; 
209
210     char *psz_namecodec;
211     /* private */
212     mtime_t i_pts;
213     int     i_framesize;
214     byte_t  *p_framedata;
215
216     int i_frame_error;
217     int i_frame_skip;
218     int i_frame_late;  /* how may frame decoded are in late */
219     
220 } videodec_thread_t;