/*****************************************************************************
* deinterlace.c : deinterlacer plugin for vlc
*****************************************************************************
- * Copyright (C) 2000, 2001, 2002, 2003 the VideoLAN team
+ * Copyright (C) 2000-2009 the VideoLAN team
* $Id$
*
* Author: Sam Hocevar <sam@zoy.org>
# include "config.h"
#endif
-#include <errno.h>
+#include <assert.h>
#ifdef HAVE_ALTIVEC_H
# include <altivec.h>
#include <vlc_common.h>
#include <vlc_plugin.h>
-#include <vlc_vout.h>
-#include <vlc_sout.h>
-#include "vlc_filter.h"
+#include <vlc_filter.h>
+#include <vlc_cpu.h>
#ifdef CAN_COMPILE_MMXEXT
# include "mmx.h"
#endif
-#include "filter_common.h"
-
#define DEINTERLACE_DISCARD 1
#define DEINTERLACE_MEAN 2
#define DEINTERLACE_BLEND 3
#define DEINTERLACE_BOB 4
#define DEINTERLACE_LINEAR 5
#define DEINTERLACE_X 6
+#define DEINTERLACE_YADIF 7
+#define DEINTERLACE_YADIF2X 8
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+static int Open ( vlc_object_t * );
+static void Close( vlc_object_t * );
+
+#define MODE_TEXT N_("Deinterlace mode")
+#define MODE_LONGTEXT N_("Deinterlace method to use for local playback.")
+
+#define SOUT_MODE_TEXT N_("Streaming deinterlace mode")
+#define SOUT_MODE_LONGTEXT N_("Deinterlace method to use for streaming.")
+
+#define FILTER_CFG_PREFIX "sout-deinterlace-"
+
+static const char *const mode_list[] = {
+ "discard", "blend", "mean", "bob", "linear", "x", "yadif", "yadif2x" };
+static const char *const mode_list_text[] = {
+ N_("Discard"), N_("Blend"), N_("Mean"), N_("Bob"), N_("Linear"), "X", "Yadif", "Yadif (2x)" };
+
+vlc_module_begin ()
+ set_description( N_("Deinterlacing video filter") )
+ set_shortname( N_("Deinterlace" ))
+ set_capability( "video filter", 0 )
+ set_category( CAT_VIDEO )
+ set_subcategory( SUBCAT_VIDEO_VFILTER )
+
+ set_capability( "video filter2", 0 )
+ add_string( FILTER_CFG_PREFIX "mode", "blend", NULL, SOUT_MODE_TEXT,
+ SOUT_MODE_LONGTEXT, false )
+ change_string_list( mode_list, mode_list_text, 0 )
+ change_safe ()
+ add_shortcut( "deinterlace" )
+ set_callbacks( Open, Close )
+vlc_module_end ()
+
/*****************************************************************************
* Local protypes
*****************************************************************************/
-static int Create ( vlc_object_t * );
-static void Destroy ( vlc_object_t * );
-
-static int Init ( vout_thread_t * );
-static void End ( vout_thread_t * );
-static void Render ( vout_thread_t *, picture_t * );
-
-static void RenderDiscard( vout_thread_t *, picture_t *, picture_t *, int );
-static void RenderBob ( vout_thread_t *, picture_t *, picture_t *, int );
-static void RenderMean ( vout_thread_t *, picture_t *, picture_t * );
-static void RenderBlend ( vout_thread_t *, picture_t *, picture_t * );
-static void RenderLinear ( vout_thread_t *, picture_t *, picture_t *, int );
+static void RenderDiscard( filter_t *, picture_t *, picture_t *, int );
+static void RenderBob ( filter_t *, picture_t *, picture_t *, int );
+static void RenderMean ( filter_t *, picture_t *, picture_t * );
+static void RenderBlend ( filter_t *, picture_t *, picture_t * );
+static void RenderLinear ( filter_t *, picture_t *, picture_t *, int );
static void RenderX ( picture_t *, picture_t * );
+static int RenderYadif ( filter_t *, picture_t *, picture_t *, int, int );
static void MergeGeneric ( void *, const void *, const void *, size_t );
#if defined(CAN_COMPILE_C_ALTIVEC)
#if defined(CAN_COMPILE_3DNOW)
static void End3DNow ( void );
#endif
-
-static int SendEvents ( vlc_object_t *, char const *,
- vlc_value_t, vlc_value_t, void * );
-
-static void SetFilterMethod( vout_thread_t *p_vout, char *psz_method );
-static vout_thread_t *SpawnRealVout( vout_thread_t *p_vout );
-
-static int OpenFilter( vlc_object_t *p_this );
-static void CloseFilter( vlc_object_t *p_this );
-
-/*****************************************************************************
- * Callback prototypes
- *****************************************************************************/
-static int FilterCallback ( vlc_object_t *, char const *,
- vlc_value_t, vlc_value_t, void * );
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
-#define MODE_TEXT N_("Deinterlace mode")
-#define MODE_LONGTEXT N_("Deinterlace method to use for local playback.")
-
-#define SOUT_MODE_TEXT N_("Streaming deinterlace mode")
-#define SOUT_MODE_LONGTEXT N_("Deinterlace method to use for streaming.")
-
-#define FILTER_CFG_PREFIX "sout-deinterlace-"
-
-static const char *const mode_list[] = {
- "discard", "blend", "mean", "bob", "linear", "x" };
-static const char *const mode_list_text[] = {
- N_("Discard"), N_("Blend"), N_("Mean"), N_("Bob"), N_("Linear"), "X" };
-
-vlc_module_begin();
- set_description( N_("Deinterlacing video filter") );
- set_shortname( N_("Deinterlace" ));
- set_capability( "video filter", 0 );
- set_category( CAT_VIDEO );
- set_subcategory( SUBCAT_VIDEO_VFILTER );
-
- set_section( N_("Display"),NULL);
- add_string( "deinterlace-mode", "discard", NULL, MODE_TEXT,
- MODE_LONGTEXT, false );
- change_string_list( mode_list, mode_list_text, 0 );
-
- add_shortcut( "deinterlace" );
- set_callbacks( Create, Destroy );
-
- add_submodule();
- set_capability( "video filter2", 0 );
- set_section( N_("Streaming"),NULL);
- add_string( FILTER_CFG_PREFIX "mode", "blend", NULL, SOUT_MODE_TEXT,
- SOUT_MODE_LONGTEXT, false );
- change_string_list( mode_list, mode_list_text, 0 );
- set_callbacks( OpenFilter, CloseFilter );
-vlc_module_end();
+#if defined __ARM_NEON__
+static void MergeNEON (void *, const void *, const void *, size_t);
+#endif
static const char *const ppsz_filter_options[] = {
"mode", NULL
};
-/*****************************************************************************
- * vout_sys_t: Deinterlace video output method descriptor
- *****************************************************************************
- * This structure is part of the video output thread descriptor.
- * It describes the Deinterlace specific properties of an output thread.
- *****************************************************************************/
-struct vout_sys_t
+#define HISTORY_SIZE (3)
+struct filter_sys_t
{
- int i_mode; /* Deinterlace mode */
+ int i_mode; /* Deinterlace mode */
bool b_double_rate; /* Shall we double the framerate? */
-
- mtime_t last_date;
- mtime_t next_date;
-
- vout_thread_t *p_vout;
-
- vlc_mutex_t filter_lock;
+ bool b_half_height; /* Shall be divide the height by 2 */
void (*pf_merge) ( void *, const void *, const void *, size_t );
void (*pf_end_merge) ( void );
-};
-
-/*****************************************************************************
- * Control: control facility for the vout (forwards to child vout)
- *****************************************************************************/
-static int Control( vout_thread_t *p_vout, int i_query, va_list args )
-{
- return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
-}
-
-/*****************************************************************************
- * Create: allocates Deinterlace video thread output method
- *****************************************************************************
- * This function allocates and initializes a Deinterlace vout method.
- *****************************************************************************/
-static int Create( vlc_object_t *p_this )
-{
- vout_thread_t *p_vout = (vout_thread_t *)p_this;
- vlc_value_t val;
-
- /* Allocate structure */
- p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
- if( p_vout->p_sys == NULL )
- return VLC_ENOMEM;
-
- p_vout->pf_init = Init;
- p_vout->pf_end = End;
- p_vout->pf_manage = NULL;
- p_vout->pf_render = Render;
- p_vout->pf_display = NULL;
- p_vout->pf_control = Control;
-
- p_vout->p_sys->i_mode = DEINTERLACE_DISCARD;
- p_vout->p_sys->b_double_rate = false;
- p_vout->p_sys->last_date = 0;
- p_vout->p_sys->p_vout = 0;
- vlc_mutex_init( &p_vout->p_sys->filter_lock );
-
-#if defined(CAN_COMPILE_C_ALTIVEC)
- if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC )
- {
- p_vout->p_sys->pf_merge = MergeAltivec;
- p_vout->p_sys->pf_end_merge = NULL;
- }
- else
-#endif
-#if defined(CAN_COMPILE_SSE)
- if( vlc_CPU() & CPU_CAPABILITY_SSE2 )
- {
- p_vout->p_sys->pf_merge = MergeSSE2;
- p_vout->p_sys->pf_end_merge = EndMMX;
- }
- else
-#endif
-#if defined(CAN_COMPILE_MMXEXT)
- if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
- {
- p_vout->p_sys->pf_merge = MergeMMXEXT;
- p_vout->p_sys->pf_end_merge = EndMMX;
- }
- else
-#endif
-#if defined(CAN_COMPILE_3DNOW)
- if( vlc_CPU() & CPU_CAPABILITY_3DNOW )
- {
- p_vout->p_sys->pf_merge = Merge3DNow;
- p_vout->p_sys->pf_end_merge = End3DNow;
- }
- else
-#endif
- {
- p_vout->p_sys->pf_merge = MergeGeneric;
- p_vout->p_sys->pf_end_merge = NULL;
- }
- /* Look what method was requested */
- var_Create( p_vout, "deinterlace-mode", VLC_VAR_STRING );
- var_Change( p_vout, "deinterlace-mode", VLC_VAR_INHERITVALUE, &val, NULL );
+ mtime_t i_last_date;
- if( val.psz_string == NULL )
- {
- msg_Err( p_vout, "configuration variable deinterlace-mode empty" );
- msg_Err( p_vout, "no deinterlace mode provided, using \"discard\"" );
-
- val.psz_string = strdup( "discard" );
- }
-
- msg_Dbg( p_vout, "using %s deinterlace mode", val.psz_string );
-
- SetFilterMethod( p_vout, val.psz_string );
-
- free( val.psz_string );
-
- return VLC_SUCCESS;
-}
+ /* Yadif */
+ picture_t *pp_history[HISTORY_SIZE];
+};
/*****************************************************************************
* SetFilterMethod: setup the deinterlace method to use.
*****************************************************************************/
-static void SetFilterMethod( vout_thread_t *p_vout, char *psz_method )
+static void SetFilterMethod( filter_t *p_filter, const char *psz_method, vlc_fourcc_t i_chroma )
{
- if( !strcmp( psz_method, "discard" ) )
- {
- p_vout->p_sys->i_mode = DEINTERLACE_DISCARD;
- p_vout->p_sys->b_double_rate = false;
- }
- else if( !strcmp( psz_method, "mean" ) )
- {
- p_vout->p_sys->i_mode = DEINTERLACE_MEAN;
- p_vout->p_sys->b_double_rate = false;
- }
- else if( !strcmp( psz_method, "blend" )
- || !strcmp( psz_method, "average" )
- || !strcmp( psz_method, "combine-fields" ) )
+ filter_sys_t *p_sys = p_filter->p_sys;
+
+ if( !psz_method )
+ psz_method = "";
+
+ if( !strcmp( psz_method, "mean" ) )
{
- p_vout->p_sys->i_mode = DEINTERLACE_BLEND;
- p_vout->p_sys->b_double_rate = false;
+ p_sys->i_mode = DEINTERLACE_MEAN;
+ p_sys->b_double_rate = false;
+ p_sys->b_half_height = true;
}
else if( !strcmp( psz_method, "bob" )
|| !strcmp( psz_method, "progressive-scan" ) )
{
- p_vout->p_sys->i_mode = DEINTERLACE_BOB;
- p_vout->p_sys->b_double_rate = true;
+ p_sys->i_mode = DEINTERLACE_BOB;
+ p_sys->b_double_rate = true;
+ p_sys->b_half_height = false;
}
else if( !strcmp( psz_method, "linear" ) )
{
- p_vout->p_sys->i_mode = DEINTERLACE_LINEAR;
- p_vout->p_sys->b_double_rate = true;
+ p_sys->i_mode = DEINTERLACE_LINEAR;
+ p_sys->b_double_rate = true;
+ p_sys->b_half_height = false;
}
else if( !strcmp( psz_method, "x" ) )
{
- p_vout->p_sys->i_mode = DEINTERLACE_X;
- p_vout->p_sys->b_double_rate = false;
+ p_sys->i_mode = DEINTERLACE_X;
+ p_sys->b_double_rate = false;
+ p_sys->b_half_height = false;
}
- else
+ else if( !strcmp( psz_method, "yadif" ) )
{
- msg_Err( p_vout, "no valid deinterlace mode provided, "
- "using \"discard\"" );
+ p_sys->i_mode = DEINTERLACE_YADIF;
+ p_sys->b_double_rate = false;
+ p_sys->b_half_height = false;
}
-
- msg_Dbg( p_vout, "using %s deinterlace method", psz_method );
-}
-
-/*****************************************************************************
- * Init: initialize Deinterlace video thread output method
- *****************************************************************************/
-static int Init( vout_thread_t *p_vout )
-{
- int i_index;
- picture_t *p_pic;
-
- I_OUTPUTPICTURES = 0;
-
- /* Initialize the output structure, full of directbuffers since we want
- * the decoder to output directly to our structures. */
- switch( p_vout->render.i_chroma )
+ else if( !strcmp( psz_method, "yadif2x" ) )
{
- case VLC_FOURCC('I','4','2','0'):
- case VLC_FOURCC('I','Y','U','V'):
- case VLC_FOURCC('Y','V','1','2'):
- case VLC_FOURCC('I','4','2','2'):
- p_vout->output.i_chroma = p_vout->render.i_chroma;
- p_vout->output.i_width = p_vout->render.i_width;
- p_vout->output.i_height = p_vout->render.i_height;
- p_vout->output.i_aspect = p_vout->render.i_aspect;
- p_vout->fmt_out = p_vout->fmt_in;
- break;
-
- default:
- return VLC_EGENERIC; /* unknown chroma */
- break;
+ p_sys->i_mode = DEINTERLACE_YADIF2X;
+ p_sys->b_double_rate = true;
+ p_sys->b_half_height = false;
}
-
- /* Try to open the real video output */
- p_vout->p_sys->p_vout = SpawnRealVout( p_vout );
-
- if( p_vout->p_sys->p_vout == NULL )
+ else if( !strcmp( psz_method, "discard" ) )
{
- /* Everything failed */
- msg_Err( p_vout, "cannot open vout, aborting" );
+ const bool b_i422 = i_chroma == VLC_CODEC_I422 ||
+ i_chroma == VLC_CODEC_J422;
- return VLC_EGENERIC;
+ p_sys->i_mode = DEINTERLACE_DISCARD;
+ p_sys->b_double_rate = false;
+ p_sys->b_half_height = !b_i422;
}
+ else
+ {
+ if( strcmp( psz_method, "blend" ) )
+ msg_Err( p_filter,
+ "no valid deinterlace mode provided, using \"blend\"" );
- var_AddCallback( p_vout, "deinterlace-mode", FilterCallback, NULL );
-
- ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
-
- ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
-
- ADD_PARENT_CALLBACKS( SendEventsToChild );
+ p_sys->i_mode = DEINTERLACE_BLEND;
+ p_sys->b_double_rate = false;
+ p_sys->b_half_height = false;
+ }
- return VLC_SUCCESS;
+ msg_Dbg( p_filter, "using %s deinterlace method", psz_method );
}
-/*****************************************************************************
- * SpawnRealVout: spawn the real video output.
- *****************************************************************************/
-static vout_thread_t *SpawnRealVout( vout_thread_t *p_vout )
+static void GetOutputFormat( filter_t *p_filter,
+ video_format_t *p_dst, const video_format_t *p_src )
{
- vout_thread_t *p_real_vout = NULL;
- video_format_t fmt;
- memset( &fmt, 0, sizeof( video_format_t ) );
+ filter_sys_t *p_sys = p_filter->p_sys;
+ *p_dst = *p_src;
- msg_Dbg( p_vout, "spawning the real video output" );
-
- fmt = p_vout->fmt_out;
+ if( p_sys->b_half_height )
+ {
+ p_dst->i_height /= 2;
+ p_dst->i_visible_height /= 2;
+ p_dst->i_y_offset /= 2;
+ p_dst->i_sar_den *= 2;
+ }
- switch( p_vout->render.i_chroma )
+ if( p_src->i_chroma == VLC_CODEC_I422 ||
+ p_src->i_chroma == VLC_CODEC_J422 )
{
- case VLC_FOURCC('I','4','2','0'):
- case VLC_FOURCC('I','Y','U','V'):
- case VLC_FOURCC('Y','V','1','2'):
- switch( p_vout->p_sys->i_mode )
+ switch( p_sys->i_mode )
{
case DEINTERLACE_MEAN:
- case DEINTERLACE_DISCARD:
- fmt.i_height /= 2; fmt.i_visible_height /= 2; fmt.i_y_offset /= 2;
- fmt.i_sar_den *= 2;
- p_real_vout = vout_Create( p_vout, &fmt );
- break;
-
- case DEINTERLACE_BOB:
- case DEINTERLACE_BLEND:
case DEINTERLACE_LINEAR:
case DEINTERLACE_X:
- p_real_vout = vout_Create( p_vout, &fmt );
+ case DEINTERLACE_YADIF:
+ case DEINTERLACE_YADIF2X:
+ p_dst->i_chroma = p_src->i_chroma;
+ break;
+ default:
+ p_dst->i_chroma = p_src->i_chroma == VLC_CODEC_I422 ? VLC_CODEC_I420 :
+ VLC_CODEC_J420;
break;
}
- break;
-
- case VLC_FOURCC('I','4','2','2'):
- fmt.i_chroma = VLC_FOURCC('I','4','2','0');
- p_real_vout = vout_Create( p_vout, &fmt );
- break;
-
- default:
- break;
- }
-
- return p_real_vout;
-}
-
-/*****************************************************************************
- * End: terminate Deinterlace video thread output method
- *****************************************************************************/
-static void End( vout_thread_t *p_vout )
-{
- int i_index;
-
- DEL_PARENT_CALLBACKS( SendEventsToChild );
-
- if( p_vout->p_sys->p_vout )
- DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
-
- /* Free the fake output buffers we allocated */
- for( i_index = I_OUTPUTPICTURES ; i_index ; )
- {
- i_index--;
- free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
}
-
- if( p_vout->p_sys->p_vout )
- vout_CloseAndRelease( p_vout->p_sys->p_vout );
}
-/*****************************************************************************
- * Destroy: destroy Deinterlace video thread output method
- *****************************************************************************
- * Terminate an output method created by DeinterlaceCreateOutputMethod
- *****************************************************************************/
-static void Destroy( vlc_object_t *p_this )
-{
- vout_thread_t *p_vout = (vout_thread_t *)p_this;
- vlc_mutex_destroy( &p_vout->p_sys->filter_lock );
- free( p_vout->p_sys );
-}
-
-/*****************************************************************************
- * Render: displays previously rendered output
- *****************************************************************************
- * This function send the currently rendered image to Deinterlace image,
- * waits until it is displayed and switch the two rendering buffers, preparing
- * next frame.
- *****************************************************************************/
-static void Render ( vout_thread_t *p_vout, picture_t *p_pic )
+static bool IsChromaSupported( vlc_fourcc_t i_chroma )
{
- vout_sys_t *p_sys = p_vout->p_sys;
- picture_t *pp_outpic[2];
-
- p_vout->fmt_out.i_x_offset = p_sys->p_vout->fmt_in.i_x_offset =
- p_vout->fmt_in.i_x_offset;
- p_vout->fmt_out.i_y_offset = p_sys->p_vout->fmt_in.i_y_offset =
- p_vout->fmt_in.i_y_offset;
- p_vout->fmt_out.i_visible_width = p_sys->p_vout->fmt_in.i_visible_width =
- p_vout->fmt_in.i_visible_width;
- p_vout->fmt_out.i_visible_height = p_sys->p_vout->fmt_in.i_visible_height =
- p_vout->fmt_in.i_visible_height;
- if( p_vout->p_sys->i_mode == DEINTERLACE_MEAN ||
- p_vout->p_sys->i_mode == DEINTERLACE_DISCARD )
- {
- p_vout->fmt_out.i_y_offset /= 2; p_sys->p_vout->fmt_in.i_y_offset /= 2;
- p_vout->fmt_out.i_visible_height /= 2;
- p_sys->p_vout->fmt_in.i_visible_height /= 2;
- }
-
- pp_outpic[0] = pp_outpic[1] = NULL;
-
- vlc_mutex_lock( &p_vout->p_sys->filter_lock );
-
- /* Get a new picture */
- while( ( pp_outpic[0] = vout_CreatePicture( p_vout->p_sys->p_vout,
- 0, 0, 0 ) )
- == NULL )
- {
- if( !vlc_object_alive (p_vout) || p_vout->b_error )
- {
- vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
- return;
- }
- msleep( VOUT_OUTMEM_SLEEP );
- }
-
- vout_DatePicture( p_vout->p_sys->p_vout, pp_outpic[0], p_pic->date );
-
- /* If we are using double rate, get an additional new picture */
- if( p_vout->p_sys->b_double_rate )
- {
- while( ( pp_outpic[1] = vout_CreatePicture( p_vout->p_sys->p_vout,
- 0, 0, 0 ) )
- == NULL )
- {
- if( !vlc_object_alive (p_vout) || p_vout->b_error )
- {
- vout_DestroyPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
- vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
- return;
- }
- msleep( VOUT_OUTMEM_SLEEP );
- }
-
- /* 20ms is a bit arbitrary, but it's only for the first image we get */
- if( !p_vout->p_sys->last_date )
- {
- vout_DatePicture( p_vout->p_sys->p_vout, pp_outpic[1],
- p_pic->date + 20000 );
- }
- else
- {
- vout_DatePicture( p_vout->p_sys->p_vout, pp_outpic[1],
- (3 * p_pic->date - p_vout->p_sys->last_date) / 2 );
- }
- p_vout->p_sys->last_date = p_pic->date;
- }
-
- switch( p_vout->p_sys->i_mode )
- {
- case DEINTERLACE_DISCARD:
- RenderDiscard( p_vout, pp_outpic[0], p_pic, 0 );
- vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
- break;
-
- case DEINTERLACE_BOB:
- RenderBob( p_vout, pp_outpic[0], p_pic, p_pic->b_top_field_first ? 0 : 1 );
- vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
- RenderBob( p_vout, pp_outpic[1], p_pic, p_pic->b_top_field_first ? 1 : 0 );
- vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[1] );
- break;
-
- case DEINTERLACE_LINEAR:
- RenderLinear( p_vout, pp_outpic[0], p_pic, p_pic->b_top_field_first ? 0 : 1 );
- vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
- RenderLinear( p_vout, pp_outpic[1], p_pic, p_pic->b_top_field_first ? 1 : 0 );
- vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[1] );
- break;
-
- case DEINTERLACE_MEAN:
- RenderMean( p_vout, pp_outpic[0], p_pic );
- vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
- break;
-
- case DEINTERLACE_BLEND:
- RenderBlend( p_vout, pp_outpic[0], p_pic );
- vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
- break;
-
- case DEINTERLACE_X:
- RenderX( pp_outpic[0], p_pic );
- vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
- break;
- }
- vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
+ return i_chroma == VLC_CODEC_I420 ||
+ i_chroma == VLC_CODEC_J420 ||
+ i_chroma == VLC_CODEC_YV12 ||
+ i_chroma == VLC_CODEC_I422 ||
+ i_chroma == VLC_CODEC_J422;
}
/*****************************************************************************
* RenderDiscard: only keep TOP or BOTTOM field, discard the other.
*****************************************************************************/
-static void RenderDiscard( vout_thread_t *p_vout,
+static void RenderDiscard( filter_t *p_filter,
picture_t *p_outpic, picture_t *p_pic, int i_field )
{
int i_plane;
p_out_end = p_out + p_outpic->p[i_plane].i_pitch
* p_outpic->p[i_plane].i_visible_lines;
- switch( p_vout->render.i_chroma )
+ switch( p_filter->fmt_in.video.i_chroma )
{
- case VLC_FOURCC('I','4','2','0'):
- case VLC_FOURCC('I','Y','U','V'):
- case VLC_FOURCC('Y','V','1','2'):
+ case VLC_CODEC_I420:
+ case VLC_CODEC_J420:
+ case VLC_CODEC_YV12:
for( ; p_out < p_out_end ; )
{
}
break;
- case VLC_FOURCC('I','4','2','2'):
+ case VLC_CODEC_I422:
+ case VLC_CODEC_J422:
i_increment = 2 * p_pic->p[i_plane].i_pitch;
/*****************************************************************************
* RenderBob: renders a BOB picture - simple copy
*****************************************************************************/
-static void RenderBob( vout_thread_t *p_vout,
+static void RenderBob( filter_t *p_filter,
picture_t *p_outpic, picture_t *p_pic, int i_field )
{
int i_plane;
p_out_end = p_out + p_outpic->p[i_plane].i_pitch
* p_outpic->p[i_plane].i_visible_lines;
- switch( p_vout->render.i_chroma )
+ switch( p_filter->fmt_in.video.i_chroma )
{
- case VLC_FOURCC('I','4','2','0'):
- case VLC_FOURCC('I','Y','U','V'):
- case VLC_FOURCC('Y','V','1','2'):
+ case VLC_CODEC_I420:
+ case VLC_CODEC_J420:
+ case VLC_CODEC_YV12:
/* For BOTTOM field we need to add the first line */
if( i_field == 1 )
{
}
break;
- case VLC_FOURCC('I','4','2','2'):
+ case VLC_CODEC_I422:
+ case VLC_CODEC_J422:
/* For BOTTOM field we need to add the first line */
if( i_field == 1 )
{
}
}
-#define Merge p_vout->p_sys->pf_merge
-#define EndMerge if(p_vout->p_sys->pf_end_merge) p_vout->p_sys->pf_end_merge
+#define Merge p_filter->p_sys->pf_merge
+#define EndMerge if(p_filter->p_sys->pf_end_merge) p_filter->p_sys->pf_end_merge
/*****************************************************************************
* RenderLinear: BOB with linear interpolation
*****************************************************************************/
-static void RenderLinear( vout_thread_t *p_vout,
+static void RenderLinear( filter_t *p_filter,
picture_t *p_outpic, picture_t *p_pic, int i_field )
{
int i_plane;
EndMerge();
}
-static void RenderMean( vout_thread_t *p_vout,
+static void RenderMean( filter_t *p_filter,
picture_t *p_outpic, picture_t *p_pic )
{
int i_plane;
EndMerge();
}
-static void RenderBlend( vout_thread_t *p_vout,
+static void RenderBlend( filter_t *p_filter,
picture_t *p_outpic, picture_t *p_pic )
{
int i_plane;
p_out_end = p_out + p_outpic->p[i_plane].i_pitch
* p_outpic->p[i_plane].i_visible_lines;
- switch( p_vout->render.i_chroma )
+ switch( p_filter->fmt_in.video.i_chroma )
{
- case VLC_FOURCC('I','4','2','0'):
- case VLC_FOURCC('I','Y','U','V'):
- case VLC_FOURCC('Y','V','1','2'):
+ case VLC_CODEC_I420:
+ case VLC_CODEC_J420:
+ case VLC_CODEC_YV12:
/* First line: simple copy */
vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
p_out += p_outpic->p[i_plane].i_pitch;
}
break;
- case VLC_FOURCC('I','4','2','2'):
+ case VLC_CODEC_I422:
+ case VLC_CODEC_J422:
/* First line: simple copy */
vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
p_out += p_outpic->p[i_plane].i_pitch;
uint8_t *p_end = p_dest + i_bytes - 15;
/* Use C until the first 16-bytes aligned destination pixel */
- while( (int)p_dest & 0xF )
+ while( (uintptr_t)p_dest & 0xF )
{
*p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
}
}
#endif
+#ifdef __ARM_NEON__
+static void MergeNEON (void *restrict out, const void *in1,
+ const void *in2, size_t n)
+{
+ uint8_t *outp = out;
+ const uint8_t *in1p = in1;
+ const uint8_t *in2p = in2;
+ size_t mis = ((uintptr_t)outp) & 15;
+
+ if (mis)
+ {
+ MergeGeneric (outp, in1p, in2p, mis);
+ outp += mis;
+ in1p += mis;
+ in2p += mis;
+ n -= mis;
+ }
+
+ uint8_t *end = outp + (n & ~15);
+
+ if ((((uintptr_t)in1p)|((uintptr_t)in2p)) & 15)
+ while (outp < end)
+ asm volatile (
+ "vld1.u8 {q0-q1}, [%[in1]]!\n"
+ "vld1.u8 {q2-q3}, [%[in2]]!\n"
+ "vhadd.u8 q4, q0, q2\n"
+ "vld1.u8 {q6-q7}, [%[in1]]!\n"
+ "vhadd.u8 q5, q1, q3\n"
+ "vld1.u8 {q8-q9}, [%[in2]]!\n"
+ "vhadd.u8 q10, q6, q8\n"
+ "vhadd.u8 q11, q7, q9\n"
+ "vst1.u8 {q4-q5}, [%[out],:128]!\n"
+ "vst1.u8 {q10-q11}, [%[out],:128]!\n"
+ : [out] "+r" (outp), [in1] "+r" (in1p), [in2] "+r" (in2p)
+ :
+ : "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7",
+ "q8", "q9", "q10", "q11", "memory");
+ else
+ while (outp < end)
+ asm volatile (
+ "vld1.u8 {q0-q1}, [%[in1],:128]!\n"
+ "vld1.u8 {q2-q3}, [%[in2],:128]!\n"
+ "vhadd.u8 q4, q0, q2\n"
+ "vld1.u8 {q6-q7}, [%[in1],:128]!\n"
+ "vhadd.u8 q5, q1, q3\n"
+ "vld1.u8 {q8-q9}, [%[in2],:128]!\n"
+ "vhadd.u8 q10, q6, q8\n"
+ "vhadd.u8 q11, q7, q9\n"
+ "vst1.u8 {q4-q5}, [%[out],:128]!\n"
+ "vst1.u8 {q10-q11}, [%[out],:128]!\n"
+ : [out] "+r" (outp), [in1] "+r" (in1p), [in2] "+r" (in2p)
+ :
+ : "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7",
+ "q8", "q9", "q10", "q11", "memory");
+ n &= 15;
+ if (n)
+ MergeGeneric (outp, in1p, in2p, n);
+}
+#endif
+
/*****************************************************************************
* RenderX: This algo works on a 8x8 block basic, it copies the top field
* and apply a process to recreate the bottom field :
}
#endif
-/* XDeint8x8Frame: apply a small blend between field (1,6,1).
- * This won't destroy details, and help if there is a bit of interlacing.
- * (It helps with paning to avoid flickers)
- * (Use 8x9 pixels)
- */
-#if 0
-static inline void XDeint8x8FrameC( uint8_t *dst, int i_dst,
- uint8_t *src, int i_src )
-{
- int y, x;
-
- /* Progressive */
- for( y = 0; y < 8; y += 2 )
- {
- memcpy( dst, src, 8 );
- dst += i_dst;
-
- for( x = 0; x < 8; x++ )
- dst[x] = (src[x] + 6*src[1*i_src+x] + src[2*i_src+x] + 4 ) >> 3;
- dst += 1*i_dst;
- src += 2*i_src;
- }
-}
-#endif
static inline void XDeint8x8MergeC( uint8_t *dst, int i_dst,
uint8_t *src1, int i_src1,
uint8_t *src2, int i_src2 )
}
#endif
-#if 0
-static inline int XDeint8x8SsdC( uint8_t *pix1, int i_pix1,
- uint8_t *pix2, int i_pix2 )
-{
- int y, x;
- int s = 0;
-
- for( y = 0; y < 8; y++ )
- for( x = 0; x < 8; x++ )
- s += ssd( pix1[y*i_pix1+x] - pix2[y*i_pix2+x] );
- return s;
-}
-
-#ifdef CAN_COMPILE_MMXEXT
-static inline int XDeint8x8SsdMMXEXT( uint8_t *pix1, int i_pix1,
- uint8_t *pix2, int i_pix2 )
-{
- int y;
- int32_t s;
-
- pxor_r2r( mm7, mm7 );
- pxor_r2r( mm6, mm6 );
-
- for( y = 0; y < 8; y++ )
- {
- movq_m2r( pix1[0], mm0 );
- movq_m2r( pix2[0], mm1 );
-
- movq_r2r( mm0, mm2 );
- movq_r2r( mm1, mm3 );
-
- punpcklbw_r2r( mm7, mm0 );
- punpckhbw_r2r( mm7, mm2 );
- punpcklbw_r2r( mm7, mm1 );
- punpckhbw_r2r( mm7, mm3 );
-
- psubw_r2r( mm1, mm0 );
- psubw_r2r( mm3, mm2 );
-
- pmaddwd_r2r( mm0, mm0 );
- pmaddwd_r2r( mm2, mm2 );
-
- paddd_r2r( mm2, mm0 );
- paddd_r2r( mm0, mm6 );
-
- pix1 += i_pix1;
- pix2 += i_pix2;
- }
-
- movq_r2r( mm6, mm7 );
- psrlq_i2r( 32, mm7 );
- paddd_r2r( mm6, mm7 );
- movd_r2m( mm7, s );
-
- return s;
-}
-#endif
-#endif
-
-#if 0
-/* A little try with motion, but doesn't work better that pure intra (and slow) */
-#ifdef CAN_COMPILE_MMXEXT
-/* XDeintMC:
- * Bilinear MC QPel
- * TODO: mmx version (easier in sse2)
- */
-static inline void XDeintMC( uint8_t *dst, int i_dst,
- uint8_t *src, int i_src,
- int mvx, int mvy,
- int i_width, int i_height )
-{
- const int d4x = mvx&0x03;
- const int d4y = mvy&0x03;
-
- const int cA = (4-d4x)*(4-d4y);
- const int cB = d4x *(4-d4y);
- const int cC = (4-d4x)*d4y;
- const int cD = d4x *d4y;
-
- int y, x;
- uint8_t *srcp;
-
-
- src += (mvy >> 2) * i_src + (mvx >> 2);
- srcp = &src[i_src];
-
- for( y = 0; y < i_height; y++ )
- {
- for( x = 0; x < i_width; x++ )
- {
- dst[x] = ( cA*src[x] + cB*src[x+1] +
- cC*srcp[x] + cD*srcp[x+1] + 8 ) >> 4;
- }
- dst += i_dst;
-
- src = srcp;
- srcp += i_src;
- }
-}
-static int XDeint8x4SadMMXEXT( uint8_t *pix1, int i_pix1,
- uint8_t *pix2, int i_pix2 )
-{
- int32_t s;
-
- movq_m2r( pix1[0*i_pix1], mm0 );
- movq_m2r( pix1[1*i_pix1], mm1 );
-
- psadbw_m2r( pix2[0*i_pix2], mm0 );
- psadbw_m2r( pix2[1*i_pix2], mm1 );
-
- movq_m2r( pix1[2*i_pix1], mm2 );
- movq_m2r( pix1[3*i_pix1], mm3 );
- psadbw_m2r( pix2[2*i_pix2], mm2 );
- psadbw_m2r( pix2[3*i_pix2], mm3 );
-
- paddd_r2r( mm1, mm0 );
- paddd_r2r( mm3, mm2 );
- paddd_r2r( mm2, mm0 );
- movd_r2m( mm0, s );
-
- return s;
-}
-
-static inline int XDeint8x4TestQpel( uint8_t *src, int i_src,
- uint8_t *ref, int i_stride,
- int mx, int my,
- int xmax, int ymax )
-{
- uint8_t buffer[8*4];
-
- if( abs(mx) >= 4*xmax || abs(my) >= 4*ymax )
- return 255*255*255;
-
- XDeintMC( buffer, 8, ref, i_stride, mx, my, 8, 4 );
- return XDeint8x4SadMMXEXT( src, i_src, buffer, 8 );
-}
-static inline int XDeint8x4TestInt( uint8_t *src, int i_src,
- uint8_t *ref, int i_stride,
- int mx, int my,
- int xmax, int ymax )
-{
- if( abs(mx) >= xmax || abs(my) >= ymax )
- return 255*255*255;
-
- return XDeint8x4SadMMXEXT( src, i_src, &ref[my*i_stride+mx], i_stride );
-}
-
-static inline void XDeint8x8FieldMotion( uint8_t *dst, int i_dst,
- uint8_t *src, int i_src,
- int *mpx, int *mpy,
- int xmax, int ymax )
-{
- static const int dx[8] = { 0, 0, -1, 1, -1, -1, 1, 1 };
- static const int dy[8] = {-1, 1, 0, 0, -1, 1, -1, 1 };
- uint8_t *next = &src[i_src];
- const int i_src2 = 2*i_src;
- int mvx, mvy;
- int mvs, s;
- int i_step;
-
- uint8_t *rec = &dst[i_dst];
-
- /* We construct with intra method the missing field */
- XDeint8x8FieldMMXEXT( dst, i_dst, src, i_src );
-
- /* Now we will try to find a match with ME with the other field */
-
- /* ME: A small/partial EPZS
- * We search only for small MV (with high motion intra will be perfect */
- if( xmax > 4 ) xmax = 4;
- if( ymax > 4 ) ymax = 4;
-
- /* Init with NULL Mv */
- mvx = mvy = 0;
- mvs = XDeint8x4SadMMXEXT( rec, i_src2, next, i_src2 );
-
- /* Try predicted Mv */
- if( (s=XDeint8x4TestInt( rec, i_src2, next, i_src2, *mpx, *mpy, xmax, ymax)) < mvs )
- {
- mvs = s;
- mvx = *mpx;
- mvy = *mpy;
- }
- /* Search interger pel (small mv) */
- for( i_step = 0; i_step < 4; i_step++ )
- {
- int c = 4;
- int s;
- int i;
-
- for( i = 0; i < 4; i++ )
- {
- s = XDeint8x4TestInt( rec, i_src2,
- next, i_src2, mvx+dx[i], mvy+dy[i],
- xmax, ymax );
- if( s < mvs )
- {
- mvs = s;
- c = i;
- }
- }
- if( c == 4 )
- break;
-
- mvx += dx[c];
- mvy += dy[c];
- }
- *mpx = mvx;
- *mpy = mvy;
-
- mvx <<= 2;
- mvy <<= 2;
-
- if( mvs > 4 && mvs < 256 )
- {
- /* Search Qpel */
- /* XXX: for now only HPEL (too slow) */
- for( i_step = 0; i_step < 4; i_step++ )
- {
- int c = 8;
- int s;
- int i;
-
- for( i = 0; i < 8; i++ )
- {
- s = XDeint8x4TestQpel( rec, i_src2, next, i_src2,
- mvx+dx[i], mvy+dy[i],
- xmax, ymax );
- if( s < mvs )
- {
- mvs = s;
- c = i;
- }
- }
- if( c == 8 )
- break;
-
- mvx += dx[c];
- mvy += dy[c];
- }
- }
-
- if( mvs < 128 )
- {
- uint8_t buffer[8*4];
- XDeintMC( buffer, 8, next, i_src2, mvx, mvy, 8, 4 );
- XDeint8x8MergeMMXEXT( dst, i_dst, src, 2*i_src, buffer, 8 );
-
- //XDeint8x8Set( dst, i_dst, 0 );
- }
-}
-#endif
-#endif
-
-#if 0
-/* Kernel interpolation (1,-5,20,20,-5,1)
- * Lose a bit more details+add aliasing than edge interpol but avoid
- * more artifacts
- */
-static inline uint8_t clip1( int a )
-{
- if( a <= 0 )
- return 0;
- else if( a >= 255 )
- return 255;
- else
- return a;
-}
-static inline void XDeint8x8Field( uint8_t *dst, int i_dst,
- uint8_t *src, int i_src )
-{
- int y, x;
-
- /* Interlaced */
- for( y = 0; y < 8; y += 2 )
- {
- const int i_src2 = i_src*2;
-
- memcpy( dst, src, 8 );
- dst += i_dst;
-
- for( x = 0; x < 8; x++ )
- {
- int pix;
-
- pix = 1*(src[-2*i_src2+x]+src[3*i_src2+x]) +
- -5*(src[-1*i_src2+x]+src[2*i_src2+x])
- +20*(src[ 0*i_src2+x]+src[1*i_src2+x]);
-
- dst[x] = clip1( ( pix + 16 ) >> 5 );
- }
-
- dst += 1*i_dst;
- src += 2*i_src;
- }
-}
-
-#endif
-
/* NxN arbitray size (and then only use pixel in the NxN block)
*/
static inline int XDeintNxNDetect( uint8_t *src, int i_src,
}
/*****************************************************************************
- * SendEvents: forward mouse and keyboard events to the parent p_vout
+ * Yadif (Yet Another DeInterlacing Filter).
*****************************************************************************/
-static int SendEvents( vlc_object_t *p_this, char const *psz_var,
- vlc_value_t oldval, vlc_value_t newval, void *_p_vout )
-{
- VLC_UNUSED(p_this); VLC_UNUSED(oldval);
- vout_thread_t *p_vout = (vout_thread_t *)_p_vout;
- vlc_value_t sentval = newval;
+/* */
+struct vf_priv_s {
+ /*
+ * 0: Output 1 frame for each frame.
+ * 1: Output 1 frame for each field.
+ * 2: Like 0 but skips spatial interlacing check.
+ * 3: Like 1 but skips spatial interlacing check.
+ *
+ * In vlc, only & 0x02 has meaning, as we do the & 0x01 ourself.
+ */
+ int mode;
+};
- if( !strcmp( psz_var, "mouse-y" ) )
- {
- switch( p_vout->p_sys->i_mode )
- {
- case DEINTERLACE_MEAN:
- case DEINTERLACE_DISCARD:
- sentval.i_int *= 2;
- break;
- }
- }
+/* I am unsure it is the right one */
+typedef intptr_t x86_reg;
- var_Set( p_vout, psz_var, sentval );
+#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
+#define FFMAX(a,b) __MAX(a,b)
+#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
+#define FFMIN(a,b) __MIN(a,b)
+#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
- return VLC_SUCCESS;
-}
+/* yadif.h comes from vf_yadif.c of mplayer project */
+#include "yadif.h"
-/*****************************************************************************
- * FilterCallback: called when changing the deinterlace method on the fly.
- *****************************************************************************/
-static int FilterCallback( vlc_object_t *p_this, char const *psz_cmd,
- vlc_value_t oldval, vlc_value_t newval,
- void *p_data )
+static int RenderYadif( filter_t *p_filter, picture_t *p_dst, picture_t *p_src, int i_order, int i_field )
{
- VLC_UNUSED(psz_cmd); VLC_UNUSED(p_data); VLC_UNUSED(oldval);
- vout_thread_t * p_vout = (vout_thread_t *)p_this;
- int i_old_mode = p_vout->p_sys->i_mode;
-
- msg_Dbg( p_vout, "using %s deinterlace mode", newval.psz_string );
-
- vlc_mutex_lock( &p_vout->p_sys->filter_lock );
-
- SetFilterMethod( p_vout, newval.psz_string );
-
- switch( p_vout->render.i_chroma )
- {
- case VLC_FOURCC('I','4','2','2'):
- vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
- return VLC_SUCCESS;
- break;
+ filter_sys_t *p_sys = p_filter->p_sys;
+
+ /* */
+ assert( i_order == 0 || i_order == 1 );
+ assert( i_field == 0 || i_field == 1 );
+
+ if( i_order == 0 )
+ {
+ /* Duplicate the picture
+ * TODO when the vout rework is finished, picture_Hold() might be enough
+ * but becarefull, the pitches must match */
+ picture_t *p_dup = picture_NewFromFormat( &p_src->format );
+ if( p_dup )
+ picture_Copy( p_dup, p_src );
+
+ /* Slide the history */
+ if( p_sys->pp_history[0] )
+ picture_Release( p_sys->pp_history[0] );
+ for( int i = 1; i < HISTORY_SIZE; i++ )
+ p_sys->pp_history[i-1] = p_sys->pp_history[i];
+ p_sys->pp_history[HISTORY_SIZE-1] = p_dup;
+ }
+
+ /* As the pitches must match, use ONLY pictures coming from picture_New()! */
+ picture_t *p_prev = p_sys->pp_history[0];
+ picture_t *p_cur = p_sys->pp_history[1];
+ picture_t *p_next = p_sys->pp_history[2];
+
+ /* Filter if we have all the pictures we need */
+ if( p_prev && p_cur && p_next )
+ {
+ /* */
+ void (*filter)(struct vf_priv_s *p, uint8_t *dst, uint8_t *prev, uint8_t *cur, uint8_t *next, int w, int refs, int parity);
+#if defined(HAVE_YADIF_SSE2)
+ if( vlc_CPU() & CPU_CAPABILITY_SSE2 )
+ filter = yadif_filter_line_mmx2;
+ else
+#endif
+ filter = yadif_filter_line_c;
- case VLC_FOURCC('I','4','2','0'):
- case VLC_FOURCC('I','Y','U','V'):
- case VLC_FOURCC('Y','V','1','2'):
- switch( p_vout->p_sys->i_mode )
+ for( int n = 0; n < p_dst->i_planes; n++ )
{
- case DEINTERLACE_MEAN:
- case DEINTERLACE_DISCARD:
- if( ( i_old_mode == DEINTERLACE_MEAN )
- || ( i_old_mode == DEINTERLACE_DISCARD ) )
- {
- vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
- return VLC_SUCCESS;
- }
- break;
+ const plane_t *prevp = &p_prev->p[n];
+ const plane_t *curp = &p_cur->p[n];
+ const plane_t *nextp = &p_next->p[n];
+ plane_t *dstp = &p_dst->p[n];
- case DEINTERLACE_BOB:
- case DEINTERLACE_BLEND:
- case DEINTERLACE_LINEAR:
- if( ( i_old_mode == DEINTERLACE_BOB )
- || ( i_old_mode == DEINTERLACE_BLEND )
- || ( i_old_mode == DEINTERLACE_LINEAR ) )
+ for( int y = 1; y < dstp->i_visible_lines - 1; y++ )
{
- vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
- return VLC_SUCCESS;
+ if( (y % 2) == i_field )
+ {
+ vlc_memcpy( &dstp->p_pixels[y * dstp->i_pitch],
+ &curp->p_pixels[y * curp->i_pitch], dstp->i_visible_pitch );
+ }
+ else
+ {
+ struct vf_priv_s cfg;
+ /* Spatial checks only when enough data */
+ cfg.mode = (y >= 2 && y < dstp->i_visible_lines - 2) ? 0 : 2;
+
+ assert( prevp->i_pitch == curp->i_pitch && curp->i_pitch == nextp->i_pitch );
+ filter( &cfg,
+ &dstp->p_pixels[y * dstp->i_pitch],
+ &prevp->p_pixels[y * prevp->i_pitch],
+ &curp->p_pixels[y * curp->i_pitch],
+ &nextp->p_pixels[y * nextp->i_pitch],
+ dstp->i_visible_pitch,
+ curp->i_pitch,
+ (i_field ^ (i_order == i_field)) & 1 );
+ }
+
+ /* We duplicate the first and last lines */
+ if( y == 1 )
+ vlc_memcpy(&dstp->p_pixels[(y-1) * dstp->i_pitch], &dstp->p_pixels[y * dstp->i_pitch], dstp->i_pitch);
+ else if( y == dstp->i_visible_lines - 2 )
+ vlc_memcpy(&dstp->p_pixels[(y+1) * dstp->i_pitch], &dstp->p_pixels[y * dstp->i_pitch], dstp->i_pitch);
}
- break;
}
- break;
- default:
- break;
+ /* */
+ p_dst->date = (p_next->date - p_cur->date) * i_order / 2 + p_cur->date;
+ return VLC_SUCCESS;
}
-
- /* We need to kill the old vout */
- if( p_vout->p_sys->p_vout )
+ else if( !p_prev && !p_cur && p_next )
{
- DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
- vout_CloseAndRelease( p_vout->p_sys->p_vout );
+ /* FIXME not good as it does not use i_order/i_field */
+ RenderX( p_dst, p_next );
+ return VLC_SUCCESS;
}
-
- /* Try to open a new video output */
- p_vout->p_sys->p_vout = SpawnRealVout( p_vout );
-
- if( p_vout->p_sys->p_vout == NULL )
+ else
{
- /* Everything failed */
- msg_Err( p_vout, "cannot open vout, aborting" );
-
- vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
return VLC_EGENERIC;
}
-
- ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
-
- vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
- return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * SendEventsToChild: forward events to the child/children vout
- *****************************************************************************/
-static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
- vlc_value_t oldval, vlc_value_t newval, void *p_data )
-{
- VLC_UNUSED(p_data); VLC_UNUSED(oldval);
- vout_thread_t *p_vout = (vout_thread_t *)p_this;
- var_Set( p_vout->p_sys->p_vout, psz_var, newval );
- return VLC_SUCCESS;
}
-
/*****************************************************************************
* video filter2 functions
*****************************************************************************/
static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic )
{
- vout_thread_t *p_vout = (vout_thread_t *)p_filter->p_sys;
- picture_t *p_pic_dst;
+ filter_sys_t *p_sys = p_filter->p_sys;
+ picture_t *p_dst[2];
/* Request output picture */
- p_pic_dst = filter_NewPicture( p_filter );
- if( p_pic_dst == NULL )
- return p_pic;
+ p_dst[0] = filter_NewPicture( p_filter );
+ if( p_dst[0] == NULL )
+ {
+ picture_Release( p_pic );
+ return NULL;
+ }
+ picture_CopyProperties( p_dst[0], p_pic );
+
+ if( p_sys->b_double_rate )
+ {
+ p_dst[0]->p_next =
+ p_dst[1] = filter_NewPicture( p_filter );
+ if( p_dst[1] )
+ {
+ picture_CopyProperties( p_dst[1], p_pic );
+ /* XXX it's not really good especially for the first picture, but
+ * I don't think that delaying by one frame is worth it */
+ if( p_sys->i_last_date > VLC_TS_INVALID && p_pic->date > VLC_TS_INVALID )
+ p_dst[1]->date = p_pic->date + (p_pic->date - p_sys->i_last_date) / 2;
+ }
+ p_sys->i_last_date = p_pic->date;
+ }
+ else
+ {
+ p_dst[1] = NULL;
+ }
- switch( p_vout->p_sys->i_mode )
+ switch( p_sys->i_mode )
{
case DEINTERLACE_DISCARD:
-#if 0
- RenderDiscard( p_vout, p_pic_dst, p_pic, 0 );
-#endif
- msg_Err( p_vout, "discarding lines is not supported yet" );
- picture_Release( p_pic_dst );
- return p_pic;
+ RenderDiscard( p_filter, p_dst[0], p_pic, 0 );
break;
case DEINTERLACE_BOB:
-#if 0
- RenderBob( p_vout, pp_outpic[0], p_pic, 0 );
- RenderBob( p_vout, pp_outpic[1], p_pic, 1 );
- break;
-#endif
+ RenderBob( p_filter, p_dst[0], p_pic, !p_pic->b_top_field_first );
+ if( p_dst[1] )
+ RenderBob( p_filter, p_dst[1], p_pic, p_pic->b_top_field_first );
+ break;;
case DEINTERLACE_LINEAR:
-#if 0
- RenderLinear( p_vout, pp_outpic[0], p_pic, 0 );
- RenderLinear( p_vout, pp_outpic[1], p_pic, 1 );
-#endif
- msg_Err( p_vout, "doubling the frame rate is not supported yet" );
- picture_Release( p_pic_dst );
- return p_pic;
+ RenderLinear( p_filter, p_dst[0], p_pic, !p_pic->b_top_field_first );
+ if( p_dst[1] )
+ RenderLinear( p_filter, p_dst[1], p_pic, p_pic->b_top_field_first );
break;
case DEINTERLACE_MEAN:
- RenderMean( p_vout, p_pic_dst, p_pic );
+ RenderMean( p_filter, p_dst[0], p_pic );
break;
case DEINTERLACE_BLEND:
- RenderBlend( p_vout, p_pic_dst, p_pic );
+ RenderBlend( p_filter, p_dst[0], p_pic );
break;
case DEINTERLACE_X:
- RenderX( p_pic_dst, p_pic );
+ RenderX( p_dst[0], p_pic );
+ break;
+
+ case DEINTERLACE_YADIF:
+ if( RenderYadif( p_filter, p_dst[0], p_pic, 0, 0 ) )
+ goto drop;
+ break;
+
+ case DEINTERLACE_YADIF2X:
+ if( RenderYadif( p_filter, p_dst[0], p_pic, 0, !p_pic->b_top_field_first ) )
+ goto drop;
+ if( p_dst[1] )
+ RenderYadif( p_filter, p_dst[1], p_pic, 1, p_pic->b_top_field_first );
break;
}
- picture_CopyProperties( p_pic_dst, p_pic );
- p_pic_dst->b_progressive = true;
+ p_dst[0]->b_progressive = true;
+ if( p_dst[1] )
+ p_dst[1]->b_progressive = true;
picture_Release( p_pic );
- return p_pic_dst;
+ return p_dst[0];
+
+drop:
+ picture_Release( p_dst[0] );
+ if( p_dst[1] )
+ picture_Release( p_dst[1] );
+ picture_Release( p_pic );
+ return NULL;
+}
+
+static void Flush( filter_t *p_filter )
+{
+ filter_sys_t *p_sys = p_filter->p_sys;
+
+ p_sys->i_last_date = VLC_TS_INVALID;
+ for( int i = 0; i < HISTORY_SIZE; i++ )
+ {
+ if( p_sys->pp_history[i] )
+ picture_Release( p_sys->pp_history[i] );
+ p_sys->pp_history[i] = NULL;
+ }
+}
+
+static int Mouse( filter_t *p_filter,
+ vlc_mouse_t *p_mouse, const vlc_mouse_t *p_old, const vlc_mouse_t *p_new )
+{
+ VLC_UNUSED(p_old);
+ *p_mouse = *p_new;
+ if( p_filter->p_sys->b_half_height )
+ p_mouse->i_y *= 2;
+ return VLC_SUCCESS;
}
+
/*****************************************************************************
- * OpenFilter:
+ * Open
*****************************************************************************/
-static int OpenFilter( vlc_object_t *p_this )
+static int Open( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t*)p_this;
- vout_thread_t *p_vout;
- vlc_value_t val;
+ filter_sys_t *p_sys;
- if( ( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('I','4','2','0') &&
- p_filter->fmt_in.video.i_chroma != VLC_FOURCC('I','Y','U','V') &&
- p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','V','1','2') ) ||
- p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma )
- {
+ if( !IsChromaSupported( p_filter->fmt_in.video.i_chroma ) )
return VLC_EGENERIC;
- }
- /* Impossible to use VLC_OBJECT_VOUT here because it would be used
- * by spu filters */
- p_vout = vlc_object_create( p_filter, sizeof(vout_thread_t) );
- vlc_object_attach( p_vout, p_filter );
- p_filter->p_sys = (filter_sys_t *)p_vout;
- p_vout->render.i_chroma = p_filter->fmt_in.video.i_chroma;
+ /* */
+ p_sys = p_filter->p_sys = malloc( sizeof( *p_sys ) );
+ if( !p_sys )
+ return VLC_ENOMEM;
+
+ p_sys->i_mode = DEINTERLACE_BLEND;
+ p_sys->b_double_rate = false;
+ p_sys->b_half_height = true;
+ p_sys->i_last_date = VLC_TS_INVALID;
+ for( int i = 0; i < HISTORY_SIZE; i++ )
+ p_sys->pp_history[i] = NULL;
+#if defined(CAN_COMPILE_C_ALTIVEC)
+ if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC )
+ {
+ p_sys->pf_merge = MergeAltivec;
+ p_sys->pf_end_merge = NULL;
+ }
+ else
+#endif
+#if defined(CAN_COMPILE_SSE)
+ if( vlc_CPU() & CPU_CAPABILITY_SSE2 )
+ {
+ p_sys->pf_merge = MergeSSE2;
+ p_sys->pf_end_merge = EndMMX;
+ }
+ else
+#endif
+#if defined(CAN_COMPILE_MMXEXT)
+ if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
+ {
+ p_sys->pf_merge = MergeMMXEXT;
+ p_sys->pf_end_merge = EndMMX;
+ }
+ else
+#endif
+#if defined(CAN_COMPILE_3DNOW)
+ if( vlc_CPU() & CPU_CAPABILITY_3DNOW )
+ {
+ p_sys->pf_merge = Merge3DNow;
+ p_sys->pf_end_merge = End3DNow;
+ }
+ else
+#endif
+#if defined __ARM_NEON__
+ if( vlc_CPU() & CPU_CAPABILITY_NEON )
+ {
+ p_sys->pf_merge = MergeNEON;
+ p_sys->pf_end_merge = NULL;
+ }
+ else
+#endif
+ {
+ p_sys->pf_merge = MergeGeneric;
+ p_sys->pf_end_merge = NULL;
+ }
+
+ /* */
config_ChainParse( p_filter, FILTER_CFG_PREFIX, ppsz_filter_options,
- p_filter->p_cfg );
- var_Get( p_filter, FILTER_CFG_PREFIX "mode", &val );
- var_Create( p_filter, "deinterlace-mode", VLC_VAR_STRING );
- var_Set( p_filter, "deinterlace-mode", val );
+ p_filter->p_cfg );
- if ( Create( VLC_OBJECT(p_vout) ) != VLC_SUCCESS )
+ char *psz_mode = var_GetNonEmptyString( p_filter, FILTER_CFG_PREFIX "mode" );
+ SetFilterMethod( p_filter, psz_mode, p_filter->fmt_in.video.i_chroma );
+ free( psz_mode );
+
+ /* */
+ video_format_t fmt;
+ GetOutputFormat( p_filter, &fmt, &p_filter->fmt_in.video );
+ if( !p_filter->b_allow_fmt_out_change &&
+ ( fmt.i_chroma != p_filter->fmt_in.video.i_chroma ||
+ fmt.i_height != p_filter->fmt_in.video.i_height ) )
{
- vlc_object_detach( p_vout );
- vlc_object_release( p_vout );
+ Close( VLC_OBJECT(p_filter) );
return VLC_EGENERIC;
}
-
+ p_filter->fmt_out.video = fmt;
+ p_filter->fmt_out.i_codec = fmt.i_chroma;
p_filter->pf_video_filter = Deinterlace;
+ p_filter->pf_video_flush = Flush;
+ p_filter->pf_video_mouse = Mouse;
msg_Dbg( p_filter, "deinterlacing" );
}
/*****************************************************************************
- * CloseFilter: clean up the filter
+ * Close: clean up the filter
*****************************************************************************/
-static void CloseFilter( vlc_object_t *p_this )
+static void Close( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t*)p_this;
- vout_thread_t *p_vout = (vout_thread_t *)p_filter->p_sys;
- Destroy( VLC_OBJECT(p_vout) );
- vlc_object_detach( p_vout );
- vlc_object_release( p_vout );
+ Flush( p_filter );
+ free( p_filter->p_sys );
}