X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Fmotionblur.c;h=aad8946b0710e680060e009330d974d7c214cbde;hb=b9c5a440d6458b9b2e50450293b9aa3e20865ad6;hp=3acf3cb15aa3580717c7d2c727667967222214a7;hpb=81c5ac29fa2e80426c1b1dfcc941a1aabe8bc808;p=vlc diff --git a/modules/video_filter/motionblur.c b/modules/video_filter/motionblur.c index 3acf3cb15a..aad8946b07 100644 --- a/modules/video_filter/motionblur.c +++ b/modules/video_filter/motionblur.c @@ -25,12 +25,16 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include -#include #include +#include "filter_picture.h" /***************************************************************************** * Local protypes @@ -39,7 +43,7 @@ static int Create ( vlc_object_t * ); static void Destroy ( vlc_object_t * ); static picture_t *Filter ( filter_t *, picture_t * ); static void RenderBlur ( filter_sys_t *, picture_t *, picture_t * ); -static void Copy ( filter_t *, uint8_t **, picture_t * ); +static void Copy ( filter_t *, picture_t * ); static int MotionBlurCallback( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * ); @@ -51,22 +55,22 @@ static int MotionBlurCallback( vlc_object_t *, char const *, #define FILTER_PREFIX "blur-" -vlc_module_begin(); - set_shortname( _("Motion blur") ); - set_description( _("Motion blur filter") ); - set_capability( "video filter2", 0 ); - set_category( CAT_VIDEO ); - set_subcategory( SUBCAT_VIDEO_VFILTER ); +vlc_module_begin () + set_shortname( N_("Motion blur") ) + set_description( N_("Motion blur filter") ) + set_capability( "video filter2", 0 ) + set_category( CAT_VIDEO ) + set_subcategory( SUBCAT_VIDEO_VFILTER ) add_integer_with_range( FILTER_PREFIX "factor", 80, 1, 127, NULL, - FACTOR_TEXT, FACTOR_LONGTEXT, VLC_FALSE ); + FACTOR_TEXT, FACTOR_LONGTEXT, false ) - add_shortcut( "blur" ); + add_shortcut( "blur" ) - set_callbacks( Create, Destroy ); -vlc_module_end(); + set_callbacks( Create, Destroy ) +vlc_module_end () -static const char *ppsz_filter_options[] = { +static const char *const ppsz_filter_options[] = { "factor", NULL }; @@ -75,6 +79,7 @@ static const char *ppsz_filter_options[] = { *****************************************************************************/ struct filter_sys_t { + vlc_spinlock_t lock; int i_factor; uint8_t **pp_planes; @@ -91,10 +96,7 @@ static int Create( vlc_object_t *p_this ) /* Allocate structure */ p_filter->p_sys = malloc( sizeof( filter_sys_t ) ); if( p_filter->p_sys == NULL ) - { - msg_Err( p_filter, "out of memory" ); return VLC_ENOMEM; - } p_filter->pf_video_filter = Filter; @@ -103,6 +105,7 @@ static int Create( vlc_object_t *p_this ) p_filter->p_sys->i_factor = var_CreateGetIntegerCommand( p_filter, FILTER_PREFIX "factor" ); + vlc_spin_init( &p_filter->p_sys->lock ); var_AddCallback( p_filter, FILTER_PREFIX "factor", MotionBlurCallback, p_filter->p_sys ); @@ -119,23 +122,16 @@ static void Destroy( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t *)p_this; + var_DelCallback( p_filter, FILTER_PREFIX "factor", + MotionBlurCallback, p_filter->p_sys ); + vlc_spin_destroy( &p_filter->p_sys->lock ); + while( p_filter->p_sys->i_planes-- ) free( p_filter->p_sys->pp_planes[p_filter->p_sys->i_planes] ); free( p_filter->p_sys->pp_planes ); free( p_filter->p_sys ); } -#define RELEASE( pic ) \ - if( pic ->pf_release ) \ - pic ->pf_release( pic ); - -#define INITPIC( dst, src ) \ - dst ->date = src ->date; \ - dst ->b_force = src ->b_force; \ - dst ->i_nb_fields = src ->i_nb_fields; \ - dst ->b_progressive = src->b_progressive; \ - dst ->b_top_field_first = src ->b_top_field_first; - /***************************************************************************** * Filter *****************************************************************************/ @@ -146,14 +142,12 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) if( !p_pic ) return NULL; - p_outpic = p_filter->pf_vout_buffer_new( p_filter ); + p_outpic = filter_NewPicture( p_filter ); if( !p_outpic ) { - msg_Warn( p_filter, "can't get output picture" ); - RELEASE( p_pic ); + picture_Release( p_pic ); return NULL; } - INITPIC( p_outpic, p_pic ); if( !p_sys->pp_planes ) { @@ -167,15 +161,14 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) p_sys->pp_planes[i_plane] = (uint8_t*)malloc( p_pic->p[i_plane].i_pitch * p_pic->p[i_plane].i_visible_lines ); } - Copy( p_filter, p_sys->pp_planes, p_pic ); + Copy( p_filter, p_pic ); } /* Get a new picture */ RenderBlur( p_sys, p_pic, p_outpic ); - Copy( p_filter, p_sys->pp_planes, p_outpic ); + Copy( p_filter, p_outpic ); - RELEASE( p_pic ); - return p_outpic; + return CopyInfoAndRelease( p_outpic, p_pic ); } /***************************************************************************** @@ -185,8 +178,11 @@ static void RenderBlur( filter_sys_t *p_sys, picture_t *p_newpic, picture_t *p_outpic ) { int i_plane; - int i_oldfactor = p_sys->i_factor; + vlc_spin_lock( &p_sys->lock ); + const int i_oldfactor = p_sys->i_factor; + vlc_spin_unlock( &p_sys->lock ); int i_newfactor = 128 - i_oldfactor; + for( i_plane = 0; i_plane < p_outpic->i_planes; i_plane++ ) { uint8_t *p_old, *p_new, *p_out, *p_out_end, *p_out_line_end; @@ -215,12 +211,12 @@ static void RenderBlur( filter_sys_t *p_sys, picture_t *p_newpic, } } -static void Copy( filter_t *p_filter, uint8_t **pp_planes, picture_t *p_pic ) +static void Copy( filter_t *p_filter, picture_t *p_pic ) { int i_plane; for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ ) { - p_filter->p_libvlc->pf_memcpy( + vlc_memcpy( p_filter->p_sys->pp_planes[i_plane], p_pic->p[i_plane].p_pixels, p_pic->p[i_plane].i_pitch * p_pic->p[i_plane].i_visible_lines ); } @@ -230,8 +226,14 @@ static int MotionBlurCallback( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + VLC_UNUSED(p_this); VLC_UNUSED(oldval); filter_sys_t *p_sys = (filter_sys_t *)p_data; + if( !strcmp( psz_var, FILTER_PREFIX "factor" ) ) + { + vlc_spin_lock( &p_sys->lock ); p_sys->i_factor = __MIN( 127, __MAX( 1, newval.i_int ) ); + vlc_spin_unlock( &p_sys->lock ); + } return VLC_SUCCESS; }