]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/motionblur.c
Spell preferred
[vlc] / modules / video_filter / motionblur.c
index cc45b5c6ab64dab5b29be84c76ffc416eb11b3b4..aad8946b0710e680060e009330d974d7c214cbde 100644 (file)
@@ -33,7 +33,6 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_sout.h>
-#include <vlc_vout.h>
 #include <vlc_filter.h>
 #include "filter_picture.h"
 
@@ -56,20 +55,20 @@ static int MotionBlurCallback( vlc_object_t *, char const *,
 
 #define FILTER_PREFIX "blur-"
 
-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 );
+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, 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 *const ppsz_filter_options[] = {
     "factor", NULL
@@ -80,6 +79,7 @@ static const char *const ppsz_filter_options[] = {
  *****************************************************************************/
 struct filter_sys_t
 {
+    vlc_spinlock_t lock;
     int        i_factor;
 
     uint8_t  **pp_planes;
@@ -96,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;
 
@@ -108,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 );
 
@@ -124,6 +122,10 @@ 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 );
@@ -140,12 +142,10 @@ 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" );
-        if( p_pic->pf_release )
-            p_pic->pf_release( p_pic );
+        picture_Release( p_pic );
         return NULL;
     }
 
@@ -178,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;
@@ -225,7 +228,12 @@ static int MotionBlurCallback( vlc_object_t *p_this, char const *psz_var,
 {
     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;
 }