]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/gradient.c
Use %4.4s instead of %4s for fourccs cast to char *.
[vlc] / modules / video_filter / gradient.c
index f1c57cdeefe761bdfa96ba2b255b5f1bf54c1f56..b0585dcdb2a39a5b81f2fe29b116ce55787c8d4b 100644 (file)
@@ -35,9 +35,8 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_sout.h>
-#include <vlc_vout.h>
 
-#include "vlc_filter.h"
+#include <vlc_filter.h>
 #include "filter_picture.h"
 
 enum { GRADIENT, EDGE, HOUGH };
@@ -71,43 +70,47 @@ static void FilterHough   ( filter_t *, picture_t *, picture_t * );
 #define CARTOON_LONGTEXT N_("Apply cartoon effect. It is only used by " \
     "\"gradient\" and \"edge\".")
 
+#define GRADIENT_HELP N_("Apply color gradient or edge detection effects")
+
 static const char *const mode_list[] = { "gradient", "edge", "hough" };
 static const char *const mode_list_text[] = { N_("Gradient"), N_("Edge"), N_("Hough") };
 
 #define FILTER_PREFIX "gradient-"
 
-vlc_module_begin();
-    set_description( N_("Gradient video filter") );
-    set_shortname( N_( "Gradient" ));
-    set_capability( "video filter2", 0 );
-    set_category( CAT_VIDEO );
-    set_subcategory( SUBCAT_VIDEO_VFILTER );
+vlc_module_begin ()
+    set_description( N_("Gradient video filter") )
+    set_shortname( N_( "Gradient" ))
+    set_help(GRADIENT_HELP)
+    set_capability( "video filter2", 0 )
+    set_category( CAT_VIDEO )
+    set_subcategory( SUBCAT_VIDEO_VFILTER )
 
     add_string( FILTER_PREFIX "mode", "gradient", NULL,
-                MODE_TEXT, MODE_LONGTEXT, false );
-        change_string_list( mode_list, mode_list_text, 0 );
+                MODE_TEXT, MODE_LONGTEXT, false )
+        change_string_list( mode_list, mode_list_text, 0 )
 
     add_integer_with_range( FILTER_PREFIX "type", 0, 0, 1, NULL,
-                GRADIENT_TEXT, GRADIENT_LONGTEXT, false );
-    add_bool( FILTER_PREFIX "cartoon", 1, NULL,
-                CARTOON_TEXT, CARTOON_LONGTEXT, false );
+                GRADIENT_TEXT, GRADIENT_LONGTEXT, false )
+    add_bool( FILTER_PREFIX "cartoon", true, NULL,
+                CARTOON_TEXT, CARTOON_LONGTEXT, false )
 
-    add_shortcut( "gradient" );
-    set_callbacks( Create, Destroy );
-vlc_module_end();
+    add_shortcut( "gradient" )
+    set_callbacks( Create, Destroy )
+vlc_module_end ()
 
 static const char *const ppsz_filter_options[] = {
     "mode", "type", "cartoon", NULL
 };
 
 /*****************************************************************************
- * vout_sys_t: Distort video output method descriptor
+ * filter_sys_t: Distort video output method descriptor
  *****************************************************************************
  * This structure is part of the video output thread descriptor.
  * It describes the Distort specific properties of an output thread.
  *****************************************************************************/
 struct filter_sys_t
 {
+    vlc_mutex_t lock;
     int i_mode;
 
     /* For the gradient mode */
@@ -138,7 +141,7 @@ static int Create( vlc_object_t *p_this )
             break;
 
         default:
-             msg_Err( p_filter, "Unsupported input chroma (%4s)",
+             msg_Err( p_filter, "Unsupported input chroma (%4.4s)",
                       (char*)&(p_filter->fmt_in.video.i_chroma) );
             return VLC_EGENERIC;
     }
@@ -189,6 +192,7 @@ static int Create( vlc_object_t *p_this )
     p_filter->p_sys->b_cartoon =
         var_CreateGetBoolCommand( p_filter, FILTER_PREFIX "cartoon" );
 
+    vlc_mutex_init( &p_filter->p_sys->lock );
     var_AddCallback( p_filter, FILTER_PREFIX "mode",
                      GradientCallback, p_filter->p_sys );
     var_AddCallback( p_filter, FILTER_PREFIX "type",
@@ -211,13 +215,22 @@ static int Create( vlc_object_t *p_this )
 static void Destroy( vlc_object_t *p_this )
 {
     filter_t *p_filter = (filter_t *)p_this;
-
-    free( p_filter->p_sys->p_buf32 );
-    free( p_filter->p_sys->p_buf32_bis );
-    free( p_filter->p_sys->p_buf8 );
-    free( p_filter->p_sys->p_pre_hough );
-
-    free( p_filter->p_sys );
+    filter_sys_t *p_sys = p_filter->p_sys;
+
+    var_DelCallback( p_filter, FILTER_PREFIX "mode",
+                     GradientCallback, p_sys );
+    var_DelCallback( p_filter, FILTER_PREFIX "type",
+                     GradientCallback, p_sys );
+    var_DelCallback( p_filter, FILTER_PREFIX "cartoon",
+                     GradientCallback, p_sys );
+    vlc_mutex_destroy( &p_sys->lock );
+
+    free( p_sys->p_buf32 );
+    free( p_sys->p_buf32_bis );
+    free( p_sys->p_buf8 );
+    free( p_sys->p_pre_hough );
+
+    free( p_sys );
 }
 
 /*****************************************************************************
@@ -240,6 +253,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
         return NULL;
     }
 
+    vlc_mutex_lock( &p_filter->p_sys->lock );
     switch( p_filter->p_sys->i_mode )
     {
         case EDGE:
@@ -257,6 +271,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
         default:
             break;
     }
+    vlc_mutex_unlock( &p_filter->p_sys->lock );
 
     return CopyInfoAndRelease( p_outpic, p_pic );
 }
@@ -635,16 +650,27 @@ static void FilterHough( filter_t *p_filter, picture_t *p_inpic,
     double d_sin;
     double d_cos;
     uint32_t *p_smooth;
+
     int *p_hough = malloc( i_diag * i_nb_steps * sizeof(int) );
     if( ! p_hough ) return;
+
     p_smooth = (uint32_t *)malloc( i_num_lines*i_src_visible*sizeof(uint32_t));
-    if( !p_smooth ) return;
+    if( !p_smooth )
+    {
+        free( p_hough );
+        return;
+    }
 
     if( ! p_pre_hough )
     {
         msg_Dbg(p_filter, "Starting precalculation");
         p_pre_hough = malloc( i_num_lines*i_src_visible*i_nb_steps*sizeof(int));
-        if( ! p_pre_hough ) return;
+        if( ! p_pre_hough )
+        {
+            free( p_smooth );
+            free( p_hough );
+            return;
+        }
         for( i = 0 ; i < i_nb_steps ; i++)
         {
             d_sin = sin(d_step * i);
@@ -746,6 +772,8 @@ static int GradientCallback( vlc_object_t *p_this, char const *psz_var,
 {
     VLC_UNUSED(oldval);
     filter_sys_t *p_sys = (filter_sys_t *)p_data;
+
+    vlc_mutex_lock( &p_sys->lock );
     if( !strcmp( psz_var, FILTER_PREFIX "mode" ) )
     {
         if( !strcmp( newval.psz_string, "gradient" ) )
@@ -774,5 +802,7 @@ static int GradientCallback( vlc_object_t *p_this, char const *psz_var,
     {
         p_sys->b_cartoon = newval.b_bool;
     }
+    vlc_mutex_unlock( &p_sys->lock );
+
     return VLC_SUCCESS;
 }