X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Fdeinterlace.c;h=af6bb8c606d99b0b3b1496773ded0ebcc36a5530;hb=bdcee1948728fa600f992c29be0b63dd905c5678;hp=0460fd952eeb2bc0b45117ed2c9846602846f2c2;hpb=14f37b2101842fa6e427f962f689db74eff6faba;p=vlc diff --git a/modules/video_filter/deinterlace.c b/modules/video_filter/deinterlace.c index 0460fd952e..af6bb8c606 100644 --- a/modules/video_filter/deinterlace.c +++ b/modules/video_filter/deinterlace.c @@ -1,7 +1,7 @@ /***************************************************************************** * 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 @@ -29,7 +29,7 @@ # include "config.h" #endif -#include +#include #ifdef HAVE_ALTIVEC_H # include @@ -38,8 +38,8 @@ #include #include #include -#include -#include "vlc_filter.h" +#include +#include #ifdef CAN_COMPILE_MMXEXT # include "mmx.h" @@ -53,6 +53,8 @@ #define DEINTERLACE_BOB 4 #define DEINTERLACE_LINEAR 5 #define DEINTERLACE_X 6 +#define DEINTERLACE_YADIF 7 +#define DEINTERLACE_YADIF2X 8 /***************************************************************************** * Local protypes @@ -73,6 +75,7 @@ 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 RenderX ( picture_t *, picture_t * ); +static void RenderYadif ( vout_thread_t *, picture_t *, picture_t *, int, int ); static void MergeGeneric ( void *, const void *, const void *, size_t ); #if defined(CAN_COMPILE_C_ALTIVEC) @@ -93,8 +96,11 @@ static void EndMMX ( void ); #if defined(CAN_COMPILE_3DNOW) static void End3DNow ( void ); #endif +#if defined __ARM_NEON__ +static void MergeNEON (void *, const void *, const void *, size_t); +#endif -static void SetFilterMethod( vout_thread_t *p_vout, char *psz_method ); +static void SetFilterMethod( vout_thread_t *p_vout, const char *psz_method ); static vout_thread_t *SpawnRealVout( vout_thread_t *p_vout ); static int OpenFilter( vlc_object_t *p_this ); @@ -118,9 +124,9 @@ static int FilterCallback( vlc_object_t *, char const *, #define FILTER_CFG_PREFIX "sout-deinterlace-" static const char *const mode_list[] = { - "discard", "blend", "mean", "bob", "linear", "x" }; + "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" }; + N_("Discard"), N_("Blend"), N_("Mean"), N_("Bob"), N_("Linear"), "X", "Yadif", "Yadif (2x)" }; vlc_module_begin () set_description( N_("Deinterlacing video filter") ) @@ -130,7 +136,7 @@ vlc_module_begin () set_subcategory( SUBCAT_VIDEO_VFILTER ) set_section( N_("Display"),NULL) - add_string( "deinterlace-mode", "discard", NULL, MODE_TEXT, + add_string( "filter-deinterlace-mode", "discard", NULL, MODE_TEXT, MODE_LONGTEXT, false ) change_string_list( mode_list, mode_list_text, 0 ) change_safe () @@ -158,6 +164,7 @@ static const char *const ppsz_filter_options[] = { * This structure is part of the video output thread descriptor. * It describes the Deinterlace specific properties of an output thread. *****************************************************************************/ +#define HISTORY_SIZE (3) struct vout_sys_t { int i_mode; /* Deinterlace mode */ @@ -173,6 +180,9 @@ struct vout_sys_t void (*pf_merge) ( void *, const void *, const void *, size_t ); void (*pf_end_merge) ( void ); + + /* Yadif */ + picture_t *pp_history[HISTORY_SIZE]; }; /***************************************************************************** @@ -191,10 +201,11 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args ) static int Create( vlc_object_t *p_this ) { vout_thread_t *p_vout = (vout_thread_t *)p_this; - vlc_value_t val; + vout_sys_t *p_sys; + char *psz_mode; /* Allocate structure */ - p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); + p_sys = p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) return VLC_ENOMEM; @@ -205,67 +216,72 @@ static int Create( vlc_object_t *p_this ) 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->b_half_height = true; - p_vout->p_sys->last_date = 0; - p_vout->p_sys->p_vout = 0; - vlc_mutex_init( &p_vout->p_sys->filter_lock ); + p_sys->i_mode = DEINTERLACE_DISCARD; + p_sys->b_double_rate = false; + p_sys->b_half_height = true; + p_sys->last_date = 0; + p_sys->p_vout = 0; + vlc_mutex_init( &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; + 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_vout->p_sys->pf_merge = MergeSSE2; - p_vout->p_sys->pf_end_merge = EndMMX; + 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_vout->p_sys->pf_merge = MergeMMXEXT; - p_vout->p_sys->pf_end_merge = EndMMX; + 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_vout->p_sys->pf_merge = Merge3DNow; - p_vout->p_sys->pf_end_merge = End3DNow; + 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_vout->p_sys->pf_merge = MergeGeneric; - p_vout->p_sys->pf_end_merge = NULL; + p_sys->pf_merge = MergeGeneric; + 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 ); + psz_mode = var_CreateGetString( p_vout, "filter-deinterlace-mode" ); - if( val.psz_string == NULL ) + if( !psz_mode ) { - msg_Err( p_vout, "configuration variable deinterlace-mode empty" ); + msg_Err( p_vout, "configuration variable filter-deinterlace-mode empty" ); msg_Err( p_vout, "no deinterlace mode provided, using \"discard\"" ); - val.psz_string = strdup( "discard" ); + psz_mode = strdup( "discard" ); } - msg_Dbg( p_vout, "using %s deinterlace mode", val.psz_string ); - - SetFilterMethod( p_vout, val.psz_string ); + SetFilterMethod( p_vout, psz_mode ); - free( val.psz_string ); + free( psz_mode ); return VLC_SUCCESS; } @@ -273,51 +289,65 @@ static int Create( vlc_object_t *p_this ) /***************************************************************************** * SetFilterMethod: setup the deinterlace method to use. *****************************************************************************/ -static void SetFilterMethod( vout_thread_t *p_vout, char *psz_method ) +static void SetFilterMethod( vout_thread_t *p_vout, const char *psz_method ) { + vout_sys_t *p_sys = p_vout->p_sys; if( !strcmp( psz_method, "mean" ) ) { - p_vout->p_sys->i_mode = DEINTERLACE_MEAN; - p_vout->p_sys->b_double_rate = false; - p_vout->p_sys->b_half_height = true; + p_sys->i_mode = DEINTERLACE_MEAN; + p_sys->b_double_rate = false; + p_sys->b_half_height = true; } else if( !strcmp( psz_method, "blend" ) || !strcmp( psz_method, "average" ) || !strcmp( psz_method, "combine-fields" ) ) { - p_vout->p_sys->i_mode = DEINTERLACE_BLEND; - p_vout->p_sys->b_double_rate = false; - p_vout->p_sys->b_half_height = false; + p_sys->i_mode = DEINTERLACE_BLEND; + p_sys->b_double_rate = false; + p_sys->b_half_height = false; } 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_vout->p_sys->b_half_height = false; + 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_vout->p_sys->b_half_height = false; + 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_vout->p_sys->b_half_height = false; + p_sys->i_mode = DEINTERLACE_X; + p_sys->b_double_rate = false; + p_sys->b_half_height = false; + } + else if( !strcmp( psz_method, "yadif" ) ) + { + p_sys->i_mode = DEINTERLACE_YADIF; + p_sys->b_double_rate = false; + p_sys->b_half_height = false; + } + else if( !strcmp( psz_method, "yadif2x" ) ) + { + p_sys->i_mode = DEINTERLACE_YADIF2X; + p_sys->b_double_rate = true; + p_sys->b_half_height = false; } else { - const bool b_i422 = p_vout->render.i_chroma == VLC_CODEC_I422; + const bool b_i422 = p_vout->render.i_chroma == VLC_CODEC_I422 || + p_vout->render.i_chroma == VLC_CODEC_J422; if( strcmp( psz_method, "discard" ) ) msg_Err( p_vout, "no valid deinterlace mode provided, " "using \"discard\"" ); - p_vout->p_sys->i_mode = DEINTERLACE_DISCARD; - p_vout->p_sys->b_double_rate = false; - p_vout->p_sys->b_half_height = !b_i422; + p_sys->i_mode = DEINTERLACE_DISCARD; + p_sys->b_double_rate = false; + p_sys->b_half_height = !b_i422; } msg_Dbg( p_vout, "using %s deinterlace method", psz_method ); @@ -336,17 +366,21 @@ static void GetOutputFormat( vout_thread_t *p_vout, p_dst->i_sar_den *= 2; } - if( p_src->i_chroma == VLC_CODEC_I422 ) + if( p_src->i_chroma == VLC_CODEC_I422 || + p_src->i_chroma == VLC_CODEC_J422 ) { switch( p_vout->p_sys->i_mode ) { case DEINTERLACE_MEAN: case DEINTERLACE_LINEAR: case DEINTERLACE_X: - p_dst->i_chroma = VLC_CODEC_I422; + case DEINTERLACE_YADIF: + case DEINTERLACE_YADIF2X: + p_dst->i_chroma = p_src->i_chroma; break; default: - p_dst->i_chroma = VLC_CODEC_I420; + p_dst->i_chroma = p_src->i_chroma == VLC_CODEC_I422 ? VLC_CODEC_I420 : + VLC_CODEC_J420; break; } } @@ -355,8 +389,10 @@ static void GetOutputFormat( vout_thread_t *p_vout, static bool IsChromaSupported( vlc_fourcc_t i_chroma ) { 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_I422 || + i_chroma == VLC_CODEC_J422; } /***************************************************************************** @@ -388,12 +424,15 @@ static int Init( vout_thread_t *p_vout ) return VLC_EGENERIC; } - var_AddCallback( p_vout, "deinterlace-mode", FilterCallback, NULL ); + for( int i = 0; i < HISTORY_SIZE; i++ ) + p_vout->p_sys->pp_history[i] = NULL; vout_filter_AllocateDirectBuffers( p_vout, VOUT_MAX_PICTURES ); vout_filter_AddChild( p_vout, p_vout->p_sys->p_vout, MouseEvent ); + var_AddCallback( p_vout, "filter-deinterlace-mode", FilterCallback, NULL ); + return VLC_SUCCESS; } @@ -417,6 +456,14 @@ static void End( vout_thread_t *p_vout ) { vout_sys_t *p_sys = p_vout->p_sys; + var_DelCallback( p_vout, "filter-deinterlace-mode", FilterCallback, NULL ); + + for( int i = 0; i < HISTORY_SIZE; i++ ) + { + if( p_sys->pp_history[i] ) + picture_Release( p_sys->pp_history[i] ); + } + if( p_sys->p_vout ) { vout_filter_DelChild( p_vout, p_sys->p_vout, MouseEvent ); @@ -447,10 +494,12 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var, vout_thread_t *p_vout = p_data; VLC_UNUSED(p_this); VLC_UNUSED(oldval); - if( !strcmp( psz_var, "mouse-y" ) && p_vout->p_sys->b_half_height ) - newval.i_int *= 2; + if( !strcmp( psz_var, "mouse-button-down" ) ) + return var_SetChecked( p_vout, psz_var, VLC_VAR_INTEGER, newval ); - return var_Set( p_vout, psz_var, newval ); + if( p_vout->p_sys->b_half_height ) + newval.coords.y *= 2; + return var_SetChecked( p_vout, psz_var, VLC_VAR_COORDS, newval ); } /***************************************************************************** @@ -486,7 +535,6 @@ static void Render ( vout_thread_t *p_vout, picture_t *p_pic ) { p_vout->i_changes &= ~VOUT_ASPECT_CHANGE; - p_vout->fmt_out.i_aspect = p_vout->fmt_in.i_aspect; p_vout->fmt_out.i_sar_num = p_vout->fmt_in.i_sar_num; p_vout->fmt_out.i_sar_den = p_vout->fmt_in.i_sar_den; @@ -580,6 +628,18 @@ static void Render ( vout_thread_t *p_vout, picture_t *p_pic ) RenderX( pp_outpic[0], p_pic ); vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] ); break; + + case DEINTERLACE_YADIF: + RenderYadif( p_vout, pp_outpic[0], p_pic, 0, 0 ); + vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] ); + break; + + case DEINTERLACE_YADIF2X: + RenderYadif( p_vout, pp_outpic[0], p_pic, 0, p_pic->b_top_field_first ? 0 : 1 ); + vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] ); + RenderYadif( p_vout, pp_outpic[1], p_pic, 1, p_pic->b_top_field_first ? 1 : 0 ); + vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[1] ); + break; } vlc_mutex_unlock( &p_vout->p_sys->filter_lock ); } @@ -608,6 +668,7 @@ static void RenderDiscard( vout_thread_t *p_vout, switch( p_vout->render.i_chroma ) { case VLC_CODEC_I420: + case VLC_CODEC_J420: case VLC_CODEC_YV12: for( ; p_out < p_out_end ; ) @@ -620,6 +681,7 @@ static void RenderDiscard( vout_thread_t *p_vout, break; case VLC_CODEC_I422: + case VLC_CODEC_J422: i_increment = 2 * p_pic->p[i_plane].i_pitch; @@ -672,6 +734,7 @@ static void RenderBob( vout_thread_t *p_vout, switch( p_vout->render.i_chroma ) { 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 ) @@ -707,6 +770,7 @@ static void RenderBob( vout_thread_t *p_vout, break; case VLC_CODEC_I422: + case VLC_CODEC_J422: /* For BOTTOM field we need to add the first line */ if( i_field == 1 ) { @@ -861,6 +925,7 @@ static void RenderBlend( vout_thread_t *p_vout, switch( p_vout->render.i_chroma ) { 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 ); @@ -878,6 +943,7 @@ static void RenderBlend( vout_thread_t *p_vout, break; 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; @@ -1058,7 +1124,7 @@ static void MergeAltivec( void *_p_dest, const void *_p_s1, 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; } @@ -1118,6 +1184,64 @@ static void MergeAltivec( void *_p_dest, const void *_p_s1, } #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", "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", "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 : @@ -1670,6 +1794,126 @@ static void RenderX( picture_t *p_outpic, picture_t *p_pic ) #endif } +/***************************************************************************** + * Yadif (Yet Another DeInterlacing Filter). + *****************************************************************************/ +/* */ +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; +}; + +/* I am unsure it is the right one */ +typedef intptr_t x86_reg; + +#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) + +/* yadif.h comes from vf_yadif.c of mplayer project */ +#include "yadif.h" + +static void RenderYadif( vout_thread_t *p_vout, picture_t *p_dst, picture_t *p_src, int i_order, int i_field ) +{ + vout_sys_t *p_sys = p_vout->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; + + for( int n = 0; n < p_dst->i_planes; n++ ) + { + 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]; + + for( int y = 1; y < dstp->i_visible_lines - 1; y++ ) + { + 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); + } + } + + /* */ + p_dst->date = (p_next->date - p_cur->date) * i_order / 2 + p_cur->date; + } + else + { + /* Fallback to something simple + * XXX it is wrong when we have 2 pictures, we should not output a picture */ + RenderX( p_dst, p_src ); + } +} + /***************************************************************************** * FilterCallback: called when changing the deinterlace method on the fly. *****************************************************************************/ @@ -1679,42 +1923,43 @@ static int FilterCallback( vlc_object_t *p_this, char const *psz_cmd, { VLC_UNUSED(psz_cmd); VLC_UNUSED(p_data); VLC_UNUSED(oldval); vout_thread_t * p_vout = (vout_thread_t *)p_this; + vout_sys_t *p_sys = p_vout->p_sys; msg_Dbg( p_vout, "using %s deinterlace mode", newval.psz_string ); - vlc_mutex_lock( &p_vout->p_sys->filter_lock ); - const bool b_old_half_height = p_vout->p_sys->b_half_height; + vlc_mutex_lock( &p_sys->filter_lock ); + const bool b_old_half_height = p_sys->b_half_height; SetFilterMethod( p_vout, newval.psz_string ); - if( !b_old_half_height == !p_vout->p_sys->b_half_height ) + if( !b_old_half_height == !p_sys->b_half_height ) { - vlc_mutex_unlock( &p_vout->p_sys->filter_lock ); + vlc_mutex_unlock( &p_sys->filter_lock ); return VLC_SUCCESS; } /* We need to kill the old vout */ - if( p_vout->p_sys->p_vout ) + if( p_sys->p_vout ) { - vout_filter_DelChild( p_vout, p_vout->p_sys->p_vout, MouseEvent ); - vout_CloseAndRelease( p_vout->p_sys->p_vout ); + vout_filter_DelChild( p_vout, p_sys->p_vout, MouseEvent ); + vout_CloseAndRelease( p_sys->p_vout ); } /* Try to open a new video output */ - p_vout->p_sys->p_vout = SpawnRealVout( p_vout ); + p_sys->p_vout = SpawnRealVout( p_vout ); - if( p_vout->p_sys->p_vout == NULL ) + if( p_sys->p_vout == NULL ) { /* Everything failed */ msg_Err( p_vout, "cannot open vout, aborting" ); - vlc_mutex_unlock( &p_vout->p_sys->filter_lock ); + vlc_mutex_unlock( &p_sys->filter_lock ); return VLC_EGENERIC; } - vout_filter_AddChild( p_vout, p_vout->p_sys->p_vout, MouseEvent ); + vout_filter_AddChild( p_vout, p_sys->p_vout, MouseEvent ); - vlc_mutex_unlock( &p_vout->p_sys->filter_lock ); + vlc_mutex_unlock( &p_sys->filter_lock ); return VLC_SUCCESS; } @@ -1768,6 +2013,18 @@ static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic ) case DEINTERLACE_X: RenderX( p_pic_dst, p_pic ); break; + + case DEINTERLACE_YADIF: + msg_Err( p_vout, "delaying frames is not supported yet" ); + picture_Release( p_pic_dst ); + picture_Release( p_pic ); + return NULL; + + case DEINTERLACE_YADIF2X: + msg_Err( p_vout, "doubling the frame rate is not supported yet" ); + picture_Release( p_pic_dst ); + picture_Release( p_pic ); + return NULL; } picture_CopyProperties( p_pic_dst, p_pic ); @@ -1800,13 +2057,12 @@ static int OpenFilter( vlc_object_t *p_this ) 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 ); + var_Create( p_filter, "filter-deinterlace-mode", VLC_VAR_STRING ); + var_Set( p_filter, "filter-deinterlace-mode", val ); free( val.psz_string ); if( Create( VLC_OBJECT(p_vout) ) != VLC_SUCCESS ) { - vlc_object_detach( p_vout ); vlc_object_release( p_vout ); return VLC_EGENERIC; } @@ -1838,7 +2094,6 @@ static void CloseFilter( vlc_object_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 ); }