* cinepak: add a new fourcc
[vlc.git] / plugins / 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.8 2002/07/23 17:19:02 fenrir 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 /* H263 and H263i */        
90 #define FOURCC_H263         VLC_FOURCC('H','2','6','3')
91 #define FOURCC_h263         VLC_FOURCC('h','2','6','3')
92 #define FOURCC_U263         VLC_FOURCC('U','2','6','3')
93 #define FOURCC_I263         VLC_FOURCC('I','2','6','3')
94 #define FOURCC_i263         VLC_FOURCC('i','2','6','3')
95
96 /* Sorenson v1 */
97 #define FOURCC_SVQ1 VLC_FOURCC( 'S', 'V', 'Q', '1' )
98
99 static int ffmpeg_GetFfmpegCodec( vlc_fourcc_t i_fourcc,
100                                   int *pi_ffmpeg_codec,
101                                   char **ppsz_name )
102 {
103     int i_codec = 0;
104     char *psz_name = NULL;
105
106     switch( i_fourcc )
107     {
108 #if LIBAVCODEC_BUILD >= 4608 
109         case FOURCC_DIV1:
110         case FOURCC_div1:
111         case FOURCC_MPG4:
112         case FOURCC_mpg4:
113             i_codec = CODEC_ID_MSMPEG4V1;
114             psz_name = "MS MPEG-4 v1";
115             break;
116
117         case FOURCC_DIV2:
118         case FOURCC_div2:
119         case FOURCC_MP42:
120         case FOURCC_mp42:
121             i_codec = CODEC_ID_MSMPEG4V2;
122             psz_name = "MS MPEG-4 v2";
123             break;
124 #endif
125
126         case FOURCC_MPG3:
127         case FOURCC_mpg3:
128         case FOURCC_div3:
129         case FOURCC_MP43:
130         case FOURCC_mp43:
131         case FOURCC_DIV3:
132         case FOURCC_DIV4:
133         case FOURCC_div4:
134         case FOURCC_DIV5:
135         case FOURCC_div5:
136         case FOURCC_DIV6:
137         case FOURCC_div6:
138         case FOURCC_AP41:
139         case FOURCC_3IV1:
140 #if LIBAVCODEC_BUILD >= 4608 
141             i_codec = CODEC_ID_MSMPEG4V3;
142 #else
143             i_codec = CODEC_ID_MSMPEG4;
144 #endif
145             psz_name = "MS MPEG-4 v3";
146             break;
147
148 #if LIBAVCODEC_BUILD >= 4615
149         case FOURCC_SVQ1:
150             i_codec = CODEC_ID_SVQ1;
151             psz_name = "SVQ-1 (Sorenson Video v1)";
152             break;
153 #endif
154
155         case FOURCC_DIVX:
156         case FOURCC_divx:
157         case FOURCC_MP4S:
158         case FOURCC_mp4s:
159         case FOURCC_M4S2:
160         case FOURCC_m4s2:
161         case FOURCC_xvid:
162         case FOURCC_XVID:
163         case FOURCC_XviD:
164         case FOURCC_DX50:
165         case FOURCC_mp4v:
166         case FOURCC_4:
167             i_codec = CODEC_ID_MPEG4;
168             psz_name = "MPEG-4";
169             break;
170
171         case FOURCC_H263:
172         case FOURCC_h263:
173         case FOURCC_U263:
174             i_codec = CODEC_ID_H263;
175             psz_name = "H263";
176             break;
177
178         case FOURCC_I263:
179         case FOURCC_i263:
180             i_codec = CODEC_ID_H263I;
181             psz_name = "I263.I";
182             break;
183     }
184
185     if( i_codec )
186     {
187         if( pi_ffmpeg_codec ) *pi_ffmpeg_codec = i_codec;
188         if( ppsz_name ) *ppsz_name = psz_name;
189         return VLC_TRUE;
190     }
191
192     return VLC_FALSE;
193 }
194
195
196 typedef struct videodec_thread_s
197 {
198     decoder_fifo_t      *p_fifo;    
199
200     bitmapinfoheader_t  format;
201
202     AVCodecContext      context, *p_context;
203     AVCodec             *p_codec;
204     vout_thread_t       *p_vout; 
205
206     char *psz_namecodec;
207     /* private */
208     mtime_t i_pts;
209     int     i_framesize;
210     byte_t  *p_framedata;
211
212     int i_frame_error;
213     int i_frame_skip;
214     int i_frame_late;  /* how may frame decoded are in late */
215     
216 } videodec_thread_t;