Commit cc872f33 authored by Antoine Cellerier's avatar Antoine Cellerier

Revive postprocessing. It is now a video filter (the interface code

needs to be changed accordingly). It "works" but I can't spot any
difference between postproc-q 6 and postproc-q 0 using the
redefined-nintendo.mpg test video ... I'd appreciate feedback on that
point.
parent 13d659d2
......@@ -49,22 +49,17 @@ SOURCES_imgresample = \
chroma.h \
$(NULL)
SOURCES_postproc = \
$(NULL)
libvlc_LTLIBRARIES += \
$(LTLIBavcodec) \
$(LTLIBavformat) \
$(LTLIBswscale) \
$(LTLIBimgresample) \
$(LTLIBpostproc)
$(LTLIBimgresample)
EXTRA_LTLIBRARIES += \
libavcodec_plugin.la \
libavformat_plugin.la \
libswscale_plugin.la \
libimgresample_plugin.la \
libpostproc_plugin.la
libimgresample_plugin.la
# FIXME SOURCES_ffmpegaltivec = \
# FIXME ffmpeg.c \
......
......@@ -125,9 +125,6 @@ vlc_module_begin();
SKIPLOOPF_LONGTEXT, true );
change_integer_list( nloopf_list, nloopf_list_text, 0 );
add_integer( "ffmpeg-pp-q", 0, NULL, PP_Q_TEXT, PP_Q_LONGTEXT, false );
add_string( "ffmpeg-pp-name", "default", NULL, LIBAVCODEC_PP_TEXT,
LIBAVCODEC_PP_LONGTEXT, true );
add_integer( "ffmpeg-debug", 0, NULL, DEBUG_TEXT, DEBUG_LONGTEXT,
true );
......
......@@ -91,12 +91,6 @@ void EndAudioDec( decoder_t *p_dec );
"Force skipping of idct to speed up decoding for frame types" \
"(-1=None, 0=Default, 1=B-frames, 2=P-frames, 3=B+P frames, 4=all frames)." )
#define PP_Q_TEXT N_("Post processing quality")
#define PP_Q_LONGTEXT N_( \
"Quality of post processing. Valid range is 0 to 6\n" \
"Higher levels require considerable more CPU power, but produce " \
"better looking pictures." )
#define DEBUG_TEXT N_( "Debug mask" )
#define DEBUG_LONGTEXT N_( "Set ffmpeg debug mask" )
......@@ -119,43 +113,6 @@ void EndAudioDec( decoder_t *p_dec );
"usually has a detrimental effect on quality. However it provides a big " \
"speedup for high definition streams." )
#define LIBAVCODEC_PP_TEXT N_("FFmpeg post processing filter chains")
/* FIXME (cut/past from ffmpeg */
#define LIBAVCODEC_PP_LONGTEXT \
N_("<filterName>[:<option>[:<option>...]][[,|/][-]<filterName>[:<option>...]]...\n" \
"long form example:\n" \
"vdeblock:autoq/hdeblock:autoq/linblenddeint default,-vdeblock\n" \
"short form example:\n" \
"vb:a/hb:a/lb de,-vb\n" \
"more examples:\n" \
"tn:64:128:256\n" \
"Filters Options\n" \
"short long name short long option Description\n" \
"* * a autoq cpu power dependent enabler\n" \
" c chrom chrominance filtring enabled\n" \
" y nochrom chrominance filtring disabled\n" \
"hb hdeblock (2 Threshold) horizontal deblocking filter\n" \
" 1. difference factor: default=64, higher -> more deblocking\n" \
" 2. flatness threshold: default=40, lower -> more deblocking\n" \
" the h & v deblocking filters share these\n" \
" so u cant set different thresholds for h / v\n" \
"vb vdeblock (2 Threshold) vertical deblocking filter\n" \
"h1 x1hdeblock Experimental h deblock filter 1\n" \
"v1 x1vdeblock Experimental v deblock filter 1\n" \
"dr dering Deringing filter\n" \
"al autolevels automatic brightness / contrast\n" \
" f fullyrange stretch luminance to (0..255)\n" \
"lb linblenddeint linear blend deinterlacer\n" \
"li linipoldeint linear interpolating deinterlace\n" \
"ci cubicipoldeint cubic interpolating deinterlacer\n" \
"md mediandeint median deinterlacer\n" \
"fd ffmpegdeint ffmpeg deinterlacer\n" \
"de default hb:a,vb:a,dr:a,al\n" \
"fa fast h1:a,v1:a,dr:a,al\n" \
"tn tmpnoise (3 Thresholds) Temporal Noise Reducer\n" \
" 1. <= 2. <= 3. larger -> stronger filtering\n" \
"fq forceQuant <quantizer> Force quantizer\n")
/*
* Encoder options
*/
......
/*****************************************************************************
* postprocess.c: video postprocessing using the ffmpeg library
*****************************************************************************
* Copyright (C) 1999-2001 the VideoLAN team
* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Gildas Bazin <gbazin@netcourrier.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_vout.h>
#include <vlc_codec.h>
/* ffmpeg header */
#ifdef HAVE_LIBAVCODEC_AVCODEC_H
# include <libavcodec/avcodec.h>
#elif defined(HAVE_FFMPEG_AVCODEC_H)
# include <ffmpeg/avcodec.h>
#else
# include <avcodec.h>
#endif
#ifdef HAVE_POSTPROC_POSTPROCESS_H
# include <postproc/postprocess.h>
#else
# include <libpostproc/postprocess.h>
#endif
#ifndef PP_CPU_CAPS_ALTIVEC
# define PP_CPU_CAPS_ALTIVEC 0
#endif
/*****************************************************************************
* video_postproc_sys_t : ffmpeg video postprocessing descriptor
*****************************************************************************/
typedef struct video_postproc_sys_t
{
pp_context_t *pp_context;
pp_mode_t *pp_mode;
bool *pb_pp;
int i_width;
int i_height;
} video_postproc_sys_t;
static int PPQCallback( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data );
/*****************************************************************************
* OpenPostproc: probe and open the postproc
*****************************************************************************/
void *OpenPostproc( decoder_t *p_dec, bool *pb_pp )
{
video_postproc_sys_t *p_sys;
vlc_value_t val, val_orig, text;
p_sys = malloc( sizeof(video_postproc_sys_t) );
p_sys->pp_context = NULL;
p_sys->pp_mode = NULL;
*pb_pp = false;
p_sys->pb_pp = pb_pp;
/* Create object variable if not already done */
if( var_Type( p_dec, "ffmpeg-pp-q" ) == 0 )
{
var_Create( p_dec, "ffmpeg-pp-q",
VLC_VAR_INTEGER | VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
text.psz_string = _("Post processing");
var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_SETTEXT, &text, NULL );
var_Get( p_dec, "ffmpeg-pp-q", &val_orig );
var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_DELCHOICE, &val_orig, NULL );
val.i_int = 0; text.psz_string = _("Disable");
var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_ADDCHOICE, &val, &text );
val.i_int = 1; text.psz_string = _("1 (Lowest)");
var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_ADDCHOICE, &val, &text );
val.i_int = 2;
var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_ADDCHOICE, &val, NULL );
val.i_int = 3;
var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_ADDCHOICE, &val, NULL );
val.i_int = 4;
var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_ADDCHOICE, &val, NULL );
val.i_int = 5;
var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_ADDCHOICE, &val, NULL );
val.i_int = 6; text.psz_string = _("6 (Highest)");
var_Change( p_dec, "ffmpeg-pp-q", VLC_VAR_ADDCHOICE, &val, &text );
var_AddCallback( p_dec, "ffmpeg-pp-q", PPQCallback, p_sys );
}
/* ***** Load post processing if enabled ***** */
var_Get( p_dec, "ffmpeg-pp-q", &val );
var_Set( p_dec, "ffmpeg-pp-q", val_orig );
if( val_orig.i_int )
*pb_pp = true;
return p_sys;
}
/*****************************************************************************
* InitPostproc:
*****************************************************************************/
int InitPostproc( void *p_data, int i_width, int i_height, int pix_fmt )
{
video_postproc_sys_t *p_sys = (video_postproc_sys_t *)p_data;
unsigned i_cpu = vlc_CPU();
int i_flags = 0;
/* Set CPU capabilities */
if( i_cpu & CPU_CAPABILITY_MMX )
{
i_flags |= PP_CPU_CAPS_MMX;
}
if( i_cpu & CPU_CAPABILITY_MMXEXT )
{
i_flags |= PP_CPU_CAPS_MMX2;
}
if( i_cpu & CPU_CAPABILITY_3DNOW )
{
i_flags |= PP_CPU_CAPS_3DNOW;
}
if( i_cpu & CPU_CAPABILITY_ALTIVEC )
{
i_flags |= PP_CPU_CAPS_ALTIVEC;
}
switch( pix_fmt )
{
case PIX_FMT_YUV444P:
i_flags |= PP_FORMAT_444;
break;
case PIX_FMT_YUV422P:
i_flags |= PP_FORMAT_422;
break;
case PIX_FMT_YUV411P:
i_flags |= PP_FORMAT_411;
break;
default:
i_flags |= PP_FORMAT_420;
break;
}
p_sys->pp_context = pp_get_context( i_width, i_height, i_flags );
p_sys->i_width = i_width;
p_sys->i_height = i_height;
return VLC_SUCCESS;
}
/*****************************************************************************
* PostprocPict:
*****************************************************************************/
int PostprocPict( void *p_data, picture_t *p_pic, AVFrame *p_ff_pic )
{
video_postproc_sys_t *p_sys = (video_postproc_sys_t *)p_data;
uint8_t *src[3], *dst[3];
int i_plane, i_src_stride[3], i_dst_stride[3];
for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
{
src[i_plane] = p_ff_pic->data[i_plane];
dst[i_plane] = p_pic->p[i_plane].p_pixels;
i_src_stride[i_plane] = p_ff_pic->linesize[i_plane];
i_dst_stride[i_plane] = p_pic->p[i_plane].i_pitch;
}
pp_postprocess( src, i_src_stride, dst, i_dst_stride,
p_sys->i_width, p_sys->i_height,
p_ff_pic->qscale_table, p_ff_pic->qstride,
p_sys->pp_mode, p_sys->pp_context,
p_ff_pic->pict_type );
return VLC_SUCCESS;
}
/*****************************************************************************
* ClosePostproc:
*****************************************************************************/
void ClosePostproc( decoder_t *p_dec, void *p_data )
{
video_postproc_sys_t *p_sys = (video_postproc_sys_t *)p_data;
if( p_sys && p_sys->pp_mode )
{
pp_free_mode( p_sys->pp_mode );
if( p_sys->pp_context ) pp_free_context( p_sys->pp_context );
}
var_DelCallback( p_dec, "ffmpeg-pp-q", PPQCallback, p_sys );
free( p_sys );
}
/*****************************************************************************
* object variables callbacks: a bunch of object variables are used by the
* interfaces to interact with the decoder.
*****************************************************************************/
static int PPQCallback( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
decoder_t *p_dec = (decoder_t *)p_this;
video_postproc_sys_t *p_sys = (video_postproc_sys_t *)p_data;
if( newval.i_int > 0 )
{
int i_quality = newval.i_int;
char *psz_name = config_GetPsz( p_dec, "ffmpeg-pp-name" );
pp_mode_t *pp_mode;
if( !psz_name )
{
psz_name = strdup( "default" );
}
else if( *psz_name == '\0' )
{
free( psz_name );
psz_name = strdup( "default" );
}
pp_mode = pp_get_mode_by_name_and_quality( psz_name, i_quality );
if( !pp_mode )
{
msg_Err( p_dec, "failed getting mode for postproc" );
newval.i_int = 0;
}
else
{
msg_Dbg( p_dec, "postprocessing enabled" );
}
free( psz_name );
p_sys->pp_mode = pp_mode;
}
else
{
msg_Dbg( p_dec, "postprocessing disabled" );
}
*p_sys->pb_pp = newval.i_int;
return VLC_SUCCESS;
}
......@@ -40,4 +40,5 @@ SOURCES_seamcarving = seamcarving.c
SOURCES_croppadd = croppadd.c
SOURCES_blendbench = blendbench.c
SOURCES_chain = chain.c
SOURCES_postproc = postproc.c
noinst_HEADERS = filter_common.h filter_picture.h
/*****************************************************************************
* postproc.c: video postprocessing using libpostproc
*****************************************************************************
* Copyright (C) 1999-2008 the VideoLAN team
* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Gildas Bazin <gbazin@netcourrier.com>
* Antoine Cellerier <dionoea at videolan dot org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_vout.h>
#include "filter_picture.h"
#ifdef HAVE_POSTPROC_POSTPROCESS_H
# include <postproc/postprocess.h>
#else
# include <libpostproc/postprocess.h>
#endif
#ifndef PP_CPU_CAPS_ALTIVEC
# define PP_CPU_CAPS_ALTIVEC 0
#endif
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int OpenPostproc( vlc_object_t * );
static void ClosePostproc( vlc_object_t * );
static picture_t *PostprocPict( filter_t *, picture_t * );
static int PPQCallback( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
static int PPNameCallback( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
#define Q_TEXT N_("Post processing quality")
#define Q_LONGTEXT N_( \
"Quality of post processing. Valid range is 0 to 6\n" \
"Higher levels require considerable more CPU power, but produce " \
"better looking pictures." )
#define NAME_TEXT N_("FFmpeg post processing filter chains")
/* defined by libpostproc */
#define NAME_LONGTEXT pp_help
#define FILTER_PREFIX "postproc-"
/*****************************************************************************
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( N_("Video post processing filter") );
add_shortcut( "postprocess" ); /* name is "postproc" */
add_shortcut( "pp" );
set_category( CAT_VIDEO );
set_subcategory( SUBCAT_VIDEO_VFILTER );
set_capability( "video filter2", 0 );
set_callbacks( OpenPostproc, ClosePostproc );
add_integer_with_range( FILTER_PREFIX "q", PP_QUALITY_MAX, 0,
PP_QUALITY_MAX, NULL, Q_TEXT, Q_LONGTEXT, false );
add_deprecated_alias( "ffmpeg-pp-q" );
add_string( FILTER_PREFIX "name", "default", NULL, NAME_TEXT,
NAME_LONGTEXT, true );
add_deprecated_alias( "ffmpeg-pp-name" );
vlc_module_end();
static const char *const ppsz_filter_options[] = {
"q", "name", NULL
};
/*****************************************************************************
* filter_sys_t : libpostproc video postprocessing descriptor
*****************************************************************************/
struct filter_sys_t
{
pp_context_t *pp_context; /* Never changes after init */
pp_mode_t *pp_mode; /* Set to NULL if post processing is disabled */
vlc_mutex_t lock; /* Lock when using or changing pp_mode */
};
/*****************************************************************************
* OpenPostproc: probe and open the postproc
*****************************************************************************/
static int OpenPostproc( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys;
vlc_value_t val, val_orig, text;
unsigned i_cpu = vlc_CPU();
int i_flags = 0;
if( p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma ||
p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height ||
p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width )
{
msg_Err( p_filter, "Filter input and output formats must be identical" );
return VLC_EGENERIC;
}
/* Set CPU capabilities */
if( i_cpu & CPU_CAPABILITY_MMX )
i_flags |= PP_CPU_CAPS_MMX;
if( i_cpu & CPU_CAPABILITY_MMXEXT )
i_flags |= PP_CPU_CAPS_MMX2;
if( i_cpu & CPU_CAPABILITY_3DNOW )
i_flags |= PP_CPU_CAPS_3DNOW;
if( i_cpu & CPU_CAPABILITY_ALTIVEC )
i_flags |= PP_CPU_CAPS_ALTIVEC;
switch( p_filter->fmt_in.video.i_chroma )
{
case VLC_FOURCC('I','4','4','4'):
case VLC_FOURCC('J','4','4','4'):
i_flags |= PP_FORMAT_444;
break;
case VLC_FOURCC('I','4','2','2'):
case VLC_FOURCC('J','4','2','2'):
i_flags |= PP_FORMAT_422;
break;
case VLC_FOURCC('I','4','1','1'):
i_flags |= PP_FORMAT_411;
break;
case VLC_FOURCC('I','4','2','0'):
case VLC_FOURCC('I','Y','U','V'):
case VLC_FOURCC('J','4','2','0'):
case VLC_FOURCC('Y','V','1','2'):
/* case VLC_FOURCC('Y','U','V','A'): FIXME Should work but alpha plane needs to be copied manually and I'm kind of feeling too lazy to write the code to do that ATM (i_pitch vs i_visible_pitch...). */
i_flags |= PP_FORMAT_420;
break;
default:
msg_Err( p_filter, "Unsupported input chroma (%4s)",
(char*)&p_filter->fmt_in.video.i_chroma );
return VLC_EGENERIC;
}
p_sys = malloc( sizeof( filter_sys_t ) );
if( !p_sys ) return VLC_ENOMEM;
p_filter->p_sys = p_sys;
p_sys->pp_context = pp_get_context( p_filter->fmt_in.video.i_width,
p_filter->fmt_in.video.i_height,
i_flags );
if( !p_sys->pp_context )
{
msg_Err( p_filter, "Error while creating post processing context." );
free( p_sys );
return VLC_EGENERIC;
}
config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options,
p_filter->p_cfg );
var_Create( p_filter, FILTER_PREFIX "q",
VLC_VAR_INTEGER | VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT |
VLC_VAR_ISCOMMAND );
var_Change( p_filter, FILTER_PREFIX "q", VLC_VAR_SETISCOMMAND, NULL, NULL ); /* For some obscure reason the VLC_VAR_ISCOMMAND isn't taken into account in during var_Create */
var_AddCallback( p_filter, FILTER_PREFIX "q", PPQCallback, NULL );
text.psz_string = _("Post processing");
var_Change( p_filter, FILTER_PREFIX "q", VLC_VAR_SETTEXT, &text, NULL );
var_Get( p_filter, FILTER_PREFIX "q", &val_orig );
var_Change( p_filter, FILTER_PREFIX "q", VLC_VAR_DELCHOICE, &val_orig, NULL );
val.psz_string = var_CreateGetNonEmptyStringCommand(
p_filter, FILTER_PREFIX "name" );
var_AddCallback( p_filter, FILTER_PREFIX "name", PPNameCallback, NULL );
if( val_orig.i_int )
{
p_sys->pp_mode = pp_get_mode_by_name_and_quality( val.psz_string?:
"default",
val_orig.i_int );
if( !p_sys->pp_mode )
{
msg_Err( p_filter, "Error while creating post processing mode." );
free( val.psz_string );
var_Destroy( p_filter, FILTER_PREFIX "q" );
pp_free_context( p_sys->pp_context );
free( p_sys );
return VLC_EGENERIC;
}
}
else
{
p_sys->pp_mode = NULL;
}
free( val.psz_string );
for( val.i_int = 0; val.i_int <= PP_QUALITY_MAX; val.i_int++ )
{
switch( val.i_int )
{
case 0:
text.psz_string = _("Disable");
break;
case 1:
text.psz_string = _("Lowest");
break;
case PP_QUALITY_MAX:
text.psz_string = _("Highest");
break;
default:
text.psz_string = NULL;
break;
}
var_Change( p_filter, FILTER_PREFIX "q", VLC_VAR_ADDCHOICE,
&val, text.psz_string?&text:NULL );
}
vlc_mutex_init( &p_sys->lock );
p_filter->pf_video_filter = PostprocPict;
return VLC_SUCCESS;
}
/*****************************************************************************
* ClosePostproc
*****************************************************************************/
static void ClosePostproc( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t *)p_this;