1 /*****************************************************************************
2 * ffmpeg_vdec.h: video decoder using ffmpeg library
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: ffmpeg.h,v 1.3 2002/08/10 20:05:21 fenrir Exp $
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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.
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.
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 *****************************************************************************/
24 /* Pour un flux video */
25 typedef struct bitmapinfoheader_s
27 u32 i_size; /* size of header */
45 typedef struct statistic_s
47 mtime_t i_frame_time[3]; /* total time to decode frame */
48 int i_frame_count[3]; /* number of frame to calculate frame_time */
50 int i_frame_late[3]; /* number of frame consecutively late */
51 int i_frame_skip[3]; /* number of frame skip */
56 typedef struct videodec_thread_s
58 decoder_fifo_t *p_fifo;
60 bitmapinfoheader_t format;
62 AVCodecContext context, *p_context;
64 vout_thread_t *p_vout;
66 /* for post processing */
67 u32 i_pp_mode; /* valid only with I420 and YV12 */
68 postprocessing_t *p_pp;
72 /* for frame skipping algo */
73 // statistic_s statistic;
78 int i_frame_late; /* how may frame decoded are in late */
85 u8 *p_buffer; /* buffer for gather pes */
86 int i_buffer_size; /* size of allocated p_framedata */
91 #define FOURCC_DIVX VLC_FOURCC('D','I','V','X')
92 #define FOURCC_divx VLC_FOURCC('d','i','v','x')
93 #define FOURCC_DIV1 VLC_FOURCC('D','I','V','1')
94 #define FOURCC_div1 VLC_FOURCC('d','i','v','1')
95 #define FOURCC_MP4S VLC_FOURCC('M','P','4','S')
96 #define FOURCC_mp4s VLC_FOURCC('m','p','4','s')
97 #define FOURCC_M4S2 VLC_FOURCC('M','4','S','2')
98 #define FOURCC_m4s2 VLC_FOURCC('m','4','s','2')
99 #define FOURCC_xvid VLC_FOURCC('x','v','i','d')
100 #define FOURCC_XVID VLC_FOURCC('X','V','I','D')
101 #define FOURCC_XviD VLC_FOURCC('X','v','i','D')
102 #define FOURCC_DX50 VLC_FOURCC('D','X','5','0')
103 #define FOURCC_mp4v VLC_FOURCC('m','p','4','v')
104 #define FOURCC_4 VLC_FOURCC( 4, 0, 0, 0 )
107 #define FOURCC_MPG4 VLC_FOURCC('M','P','G','4')
108 #define FOURCC_mpg4 VLC_FOURCC('m','p','g','4')
109 #define FOURCC_DIV2 VLC_FOURCC('D','I','V','2')
110 #define FOURCC_div2 VLC_FOURCC('d','i','v','2')
111 #define FOURCC_MP42 VLC_FOURCC('M','P','4','2')
112 #define FOURCC_mp42 VLC_FOURCC('m','p','4','2')
114 /* MSMPEG4 v3 / M$ mpeg4 v3 */
115 #define FOURCC_MPG3 VLC_FOURCC('M','P','G','3')
116 #define FOURCC_mpg3 VLC_FOURCC('m','p','g','3')
117 #define FOURCC_div3 VLC_FOURCC('d','i','v','3')
118 #define FOURCC_MP43 VLC_FOURCC('M','P','4','3')
119 #define FOURCC_mp43 VLC_FOURCC('m','p','4','3')
122 #define FOURCC_DIV3 VLC_FOURCC('D','I','V','3')
123 #define FOURCC_DIV4 VLC_FOURCC('D','I','V','4')
124 #define FOURCC_div4 VLC_FOURCC('d','i','v','4')
125 #define FOURCC_DIV5 VLC_FOURCC('D','I','V','5')
126 #define FOURCC_div5 VLC_FOURCC('d','i','v','5')
127 #define FOURCC_DIV6 VLC_FOURCC('D','I','V','6')
128 #define FOURCC_div6 VLC_FOURCC('d','i','v','6')
130 /* AngelPotion stuff */
131 #define FOURCC_AP41 VLC_FOURCC('A','P','4','1')
134 #define FOURCC_3IV1 VLC_FOURCC('3','I','V','1')
135 #define FOURCC_3IV2 VLC_FOURCC('3','I','V','2')
138 #define FOURCC_H263 VLC_FOURCC('H','2','6','3')
139 #define FOURCC_h263 VLC_FOURCC('h','2','6','3')
140 #define FOURCC_U263 VLC_FOURCC('U','2','6','3')
141 #define FOURCC_I263 VLC_FOURCC('I','2','6','3')
142 #define FOURCC_i263 VLC_FOURCC('i','2','6','3')
145 #define FOURCC_SVQ1 VLC_FOURCC( 'S', 'V', 'Q', '1' )
147 static int ffmpeg_GetFfmpegCodec( vlc_fourcc_t i_fourcc,
148 int *pi_ffmpeg_codec,
152 char *psz_name = NULL;
156 #if LIBAVCODEC_BUILD >= 4608
161 i_codec = CODEC_ID_MSMPEG4V1;
162 psz_name = "MS MPEG-4 v1";
169 i_codec = CODEC_ID_MSMPEG4V2;
170 psz_name = "MS MPEG-4 v2";
188 #if LIBAVCODEC_BUILD >= 4608
189 i_codec = CODEC_ID_MSMPEG4V3;
191 i_codec = CODEC_ID_MSMPEG4;
193 psz_name = "MS MPEG-4 v3";
196 #if LIBAVCODEC_BUILD >= 4615
198 i_codec = CODEC_ID_SVQ1;
199 psz_name = "SVQ-1 (Sorenson Video v1)";
217 i_codec = CODEC_ID_MPEG4;
220 /* FIXME FOURCC_H263P exist but what fourcc ? */
224 i_codec = CODEC_ID_H263;
230 i_codec = CODEC_ID_H263I;
237 if( pi_ffmpeg_codec ) *pi_ffmpeg_codec = i_codec;
238 if( ppsz_name ) *ppsz_name = psz_name;
245 /* FIXME FIXME some of them are wrong */
246 static int i_ffmpeg_PixFmtToChroma[] =
248 /* PIX_FMT_ANY = -1, PIX_FMT_YUV420P,
249 PIX_FMT_YUV422, PIX_FMT_RGB24,
250 PIX_FMT_BGR24, PIX_FMT_YUV422P,
251 PIX_FMT_YUV444P, PIX_FMT_YUV410P
253 0, VLC_FOURCC('I','4','2','0'),
254 VLC_FOURCC('I','4','2','0'), VLC_FOURCC('R','V','2','4'),
255 0, VLC_FOURCC('Y','4','2','2'),
256 VLC_FOURCC('I','4','4','4'), 0
259 static inline u32 ffmpeg_PixFmtToChroma( int i_ffmpegchroma )
261 if( ++i_ffmpegchroma > 7 )
267 return( i_ffmpeg_PixFmtToChroma[i_ffmpegchroma] );
271 static inline int ffmpeg_FfAspect( int i_width, int i_height, int i_ffaspect )
275 case( FF_ASPECT_4_3_625 ):
276 case( FF_ASPECT_4_3_525 ):
277 return( VOUT_ASPECT_FACTOR * 4 / 3);
278 case( FF_ASPECT_16_9_625 ):
279 case( FF_ASPECT_16_9_525 ):
280 return( VOUT_ASPECT_FACTOR * 16 / 9 );
281 case( FF_ASPECT_SQUARE ):
283 return( VOUT_ASPECT_FACTOR * i_width / i_height );