1 /*****************************************************************************
2 * postprocess.c: video postprocessing using the ffmpeg library
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: postprocess.c,v 1.2 2003/10/28 14:17:51 gbazin Exp $
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
24 #include <stdlib.h> /* malloc(), free() */
29 #include <vlc/decoder.h>
32 #ifdef HAVE_FFMPEG_AVCODEC_H
33 # include <ffmpeg/avcodec.h>
42 #ifdef HAVE_POSTPROC_POSTPROCESS_H
43 # include <postproc/postprocess.h>
45 # include <libpostproc/postprocess.h>
48 /*****************************************************************************
49 * video_postproc_sys_t : ffmpeg video postprocessing descriptor
50 *****************************************************************************/
51 typedef struct video_postproc_sys_t
53 pp_context_t *pp_context;
59 } video_postproc_sys_t;
61 /*****************************************************************************
62 * OpenPostproc: probe and open the postproc
63 *****************************************************************************/
64 int E_(OpenPostproc)( decoder_t *p_dec, void **pp_data )
66 video_postproc_sys_t **pp_sys = (video_postproc_sys_t **)pp_data;
70 /* ***** Load post processing if enabled ***** */
71 var_Create( p_dec, "ffmpeg-pp-q", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
72 var_Get( p_dec, "ffmpeg-pp-q", &val );
75 int i_quality = val.i_int;
76 char *psz_name = config_GetPsz( p_dec, "ffmpeg-pp-name" );
80 psz_name = strdup( "default" );
82 else if( *psz_name == '\0' )
85 psz_name = strdup( "default" );
88 pp_mode = pp_get_mode_by_name_and_quality( psz_name, i_quality );
92 msg_Err( p_dec, "failed geting mode for postproc" );
96 msg_Info( p_dec, "postprocessing activated" );
100 *pp_sys = malloc( sizeof(video_postproc_sys_t) );
101 (*pp_sys)->pp_context = NULL;
102 (*pp_sys)->pp_mode = pp_mode;
108 msg_Dbg( p_dec, "no postprocessing enabled" );
113 /*****************************************************************************
115 *****************************************************************************/
116 int E_(InitPostproc)( decoder_t *p_dec, void *p_data,
117 int i_width, int i_height, int pix_fmt )
119 video_postproc_sys_t *p_sys = (video_postproc_sys_t *)p_data;
120 int32_t i_cpu = p_dec->p_libvlc->i_cpu;
123 if( i_cpu & CPU_CAPABILITY_MMX )
125 i_flags |= PP_CPU_CAPS_MMX;
127 if( i_cpu & CPU_CAPABILITY_MMXEXT )
129 i_flags |= PP_CPU_CAPS_MMX2;
131 if( i_cpu & CPU_CAPABILITY_3DNOW )
133 i_flags |= PP_CPU_CAPS_3DNOW;
138 case PIX_FMT_YUV444P:
139 i_flags |= PP_FORMAT_444;
141 case PIX_FMT_YUV422P:
142 i_flags |= PP_FORMAT_422;
144 case PIX_FMT_YUV411P:
145 i_flags |= PP_FORMAT_411;
148 i_flags |= PP_FORMAT_420;
152 p_sys->pp_context = pp_get_context( i_width, i_height, i_flags );
153 p_sys->i_width = i_width;
154 p_sys->i_height = i_height;
159 /*****************************************************************************
161 *****************************************************************************/
162 int E_(PostprocPict)( decoder_t *p_dec, void *p_data,
163 picture_t *p_pic, AVFrame *p_ff_pic )
165 video_postproc_sys_t *p_sys = (video_postproc_sys_t *)p_data;
167 uint8_t *src[3], *dst[3];
168 int i_plane, i_src_stride[3], i_dst_stride[3];
170 for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
172 src[i_plane] = p_ff_pic->data[i_plane];
173 dst[i_plane] = p_pic->p[i_plane].p_pixels;
175 i_src_stride[i_plane] = p_ff_pic->linesize[i_plane];
176 i_dst_stride[i_plane] = p_pic->p[i_plane].i_pitch;
179 pp_postprocess( src, i_src_stride, dst, i_dst_stride,
180 p_sys->i_width, p_sys->i_height,
181 p_ff_pic->qscale_table, p_ff_pic->qstride,
182 p_sys->pp_mode, p_sys->pp_context,
183 p_ff_pic->pict_type );
188 /*****************************************************************************
190 *****************************************************************************/
191 void E_(ClosePostproc)( decoder_t *p_dec, void *p_data )
193 video_postproc_sys_t *p_sys = (video_postproc_sys_t *)p_data;
195 if( p_sys && p_sys->pp_mode )
197 pp_free_mode( p_sys->pp_mode );
198 if( p_sys->pp_context ) pp_free_context( p_sys->pp_context );
202 #endif /* LIBAVCODEC_PP */