1 /*****************************************************************************
2 * postprocess.c: video postprocessing using the ffmpeg library
3 *****************************************************************************
4 * Copyright (C) 1999-2001 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Gildas Bazin <gbazin@netcourrier.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
31 #include <vlc_codec.h>
34 #ifdef HAVE_LIBAVCODEC_AVCODEC_H
35 # include <libavcodec/avcodec.h>
36 #elif defined(HAVE_FFMPEG_AVCODEC_H)
37 # include <ffmpeg/avcodec.h>
44 #ifdef HAVE_POSTPROC_POSTPROCESS_H
45 # include <postproc/postprocess.h>
47 # include <libpostproc/postprocess.h>
50 #ifndef PP_CPU_CAPS_ALTIVEC
51 # define PP_CPU_CAPS_ALTIVEC 0
54 /*****************************************************************************
55 * video_postproc_sys_t : ffmpeg video postprocessing descriptor
56 *****************************************************************************/
57 typedef struct video_postproc_sys_t
59 pp_context_t *pp_context;
67 } video_postproc_sys_t;
69 static int PPQCallback( vlc_object_t *p_this, char const *psz_cmd,
70 vlc_value_t oldval, vlc_value_t newval, void *p_data );
72 /*****************************************************************************
73 * OpenPostproc: probe and open the postproc
74 *****************************************************************************/
75 void *E_(OpenPostproc)( decoder_t *p_dec, vlc_bool_t *pb_pp )
77 video_postproc_sys_t *p_sys;
78 vlc_value_t val, val_orig, text;
80 p_sys = malloc( sizeof(video_postproc_sys_t) );
81 p_sys->pp_context = NULL;
82 p_sys->pp_mode = NULL;
87 /* Create object variable if not already done */
88 if( var_Type( p_dec, "ffmpeg-pp-q" ) == 0 )
90 var_Create( p_dec, "ffmpeg-pp-q",
91 VLC_VAR_INTEGER | VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
92 text.psz_string = _("Post processing");
93 var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_SETTEXT, &text, NULL );
95 var_Get( p_dec, "ffmpeg-pp-q", &val_orig );
96 var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_DELCHOICE, &val_orig, NULL );
98 val.i_int = 0; text.psz_string = _("Disable");
99 var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_ADDCHOICE, &val, &text );
100 val.i_int = 1; text.psz_string = _("1 (Lowest)");
101 var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_ADDCHOICE, &val, &text );
103 var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_ADDCHOICE, &val, NULL );
105 var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_ADDCHOICE, &val, NULL );
107 var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_ADDCHOICE, &val, NULL );
109 var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_ADDCHOICE, &val, NULL );
110 val.i_int = 6; text.psz_string = _("6 (Highest)");
111 var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_ADDCHOICE, &val, &text );
112 var_AddCallback( p_dec, "ffmpeg-pp-q", PPQCallback, p_sys );
115 /* ***** Load post processing if enabled ***** */
116 var_Get( p_dec, "ffmpeg-pp-q", &val );
117 var_Set( p_dec, "ffmpeg-pp-q", val_orig );
124 /*****************************************************************************
126 *****************************************************************************/
127 int E_(InitPostproc)( void *p_data, int i_width, int i_height, int pix_fmt )
129 video_postproc_sys_t *p_sys = (video_postproc_sys_t *)p_data;
130 unsigned i_cpu = vlc_CPU();
133 /* Set CPU capabilities */
134 if( i_cpu & CPU_CAPABILITY_MMX )
136 i_flags |= PP_CPU_CAPS_MMX;
138 if( i_cpu & CPU_CAPABILITY_MMXEXT )
140 i_flags |= PP_CPU_CAPS_MMX2;
142 if( i_cpu & CPU_CAPABILITY_3DNOW )
144 i_flags |= PP_CPU_CAPS_3DNOW;
146 if( i_cpu & CPU_CAPABILITY_ALTIVEC )
148 i_flags |= PP_CPU_CAPS_ALTIVEC;
153 case PIX_FMT_YUV444P:
154 i_flags |= PP_FORMAT_444;
156 case PIX_FMT_YUV422P:
157 i_flags |= PP_FORMAT_422;
159 case PIX_FMT_YUV411P:
160 i_flags |= PP_FORMAT_411;
163 i_flags |= PP_FORMAT_420;
167 p_sys->pp_context = pp_get_context( i_width, i_height, i_flags );
168 p_sys->i_width = i_width;
169 p_sys->i_height = i_height;
174 /*****************************************************************************
176 *****************************************************************************/
177 int E_(PostprocPict)( void *p_data, picture_t *p_pic, AVFrame *p_ff_pic )
179 video_postproc_sys_t *p_sys = (video_postproc_sys_t *)p_data;
181 uint8_t *src[3], *dst[3];
182 int i_plane, i_src_stride[3], i_dst_stride[3];
184 for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
186 src[i_plane] = p_ff_pic->data[i_plane];
187 dst[i_plane] = p_pic->p[i_plane].p_pixels;
189 i_src_stride[i_plane] = p_ff_pic->linesize[i_plane];
190 i_dst_stride[i_plane] = p_pic->p[i_plane].i_pitch;
193 pp_postprocess( src, i_src_stride, dst, i_dst_stride,
194 p_sys->i_width, p_sys->i_height,
195 p_ff_pic->qscale_table, p_ff_pic->qstride,
196 p_sys->pp_mode, p_sys->pp_context,
197 p_ff_pic->pict_type );
202 /*****************************************************************************
204 *****************************************************************************/
205 void E_(ClosePostproc)( decoder_t *p_dec, void *p_data )
207 video_postproc_sys_t *p_sys = (video_postproc_sys_t *)p_data;
209 if( p_sys && p_sys->pp_mode )
211 pp_free_mode( p_sys->pp_mode );
212 if( p_sys->pp_context ) pp_free_context( p_sys->pp_context );
215 var_DelCallback( p_dec, "ffmpeg-pp-q", PPQCallback, p_sys );
220 /*****************************************************************************
221 * object variables callbacks: a bunch of object variables are used by the
222 * interfaces to interact with the decoder.
223 *****************************************************************************/
224 static int PPQCallback( vlc_object_t *p_this, char const *psz_cmd,
225 vlc_value_t oldval, vlc_value_t newval, void *p_data )
227 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
228 decoder_t *p_dec = (decoder_t *)p_this;
229 video_postproc_sys_t *p_sys = (video_postproc_sys_t *)p_data;
231 if( newval.i_int > 0 )
233 int i_quality = newval.i_int;
234 char *psz_name = config_GetPsz( p_dec, "ffmpeg-pp-name" );
239 psz_name = strdup( "default" );
241 else if( *psz_name == '\0' )
244 psz_name = strdup( "default" );
247 pp_mode = pp_get_mode_by_name_and_quality( psz_name, i_quality );
251 msg_Err( p_dec, "failed getting mode for postproc" );
256 msg_Dbg( p_dec, "postprocessing enabled" );
260 p_sys->pp_mode = pp_mode;
264 msg_Dbg( p_dec, "postprocessing disabled" );
267 *p_sys->pb_pp = newval.i_int;