]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/adjust.c
Use var_InheritString for --decklink-video-connection.
[vlc] / modules / video_filter / adjust.c
index 8492fb6fb3c0e6dbdbe4633c276957b5db02ca81..dfc287f4f578a144506e98b824007b86bd9cc926 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <errno.h>
-#include <math.h>
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <math.h>
+
+#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"
 
 #ifndef M_PI
@@ -77,30 +76,30 @@ static int AdjustCallback( vlc_object_t *p_this, char const *psz_var,
 #define GAMMA_TEXT N_("Image gamma (0-10)")
 #define GAMMA_LONGTEXT N_("Set the image gamma, between 0.01 and 10. Defaults to 1.")
 
-vlc_module_begin();
-    set_description( N_("Image properties filter") );
-    set_shortname( N_("Image adjust" ));
-    set_category( CAT_VIDEO );
-    set_subcategory( SUBCAT_VIDEO_VFILTER );
-    set_capability( "video filter2", 0 );
+vlc_module_begin ()
+    set_description( N_("Image properties filter") )
+    set_shortname( N_("Image adjust" ))
+    set_category( CAT_VIDEO )
+    set_subcategory( SUBCAT_VIDEO_VFILTER )
+    set_capability( "video filter2", 0 )
 
     add_float_with_range( "contrast", 1.0, 0.0, 2.0, NULL,
-                          CONT_TEXT, CONT_LONGTEXT, false );
+                          CONT_TEXT, CONT_LONGTEXT, false )
     add_float_with_range( "brightness", 1.0, 0.0, 2.0, NULL,
-                           LUM_TEXT, LUM_LONGTEXT, false );
+                           LUM_TEXT, LUM_LONGTEXT, false )
     add_integer_with_range( "hue", 0, 0, 360, NULL,
-                            HUE_TEXT, HUE_LONGTEXT, false );
+                            HUE_TEXT, HUE_LONGTEXT, false )
     add_float_with_range( "saturation", 1.0, 0.0, 3.0, NULL,
-                          SAT_TEXT, SAT_LONGTEXT, false );
+                          SAT_TEXT, SAT_LONGTEXT, false )
     add_float_with_range( "gamma", 1.0, 0.01, 10.0, NULL,
-                          GAMMA_TEXT, GAMMA_LONGTEXT, false );
+                          GAMMA_TEXT, GAMMA_LONGTEXT, false )
 
-    add_bool( "brightness-threshold", 0, NULL,
-              THRES_TEXT, THRES_LONGTEXT, false );
+    add_bool( "brightness-threshold", false, NULL,
+              THRES_TEXT, THRES_LONGTEXT, false )
 
-    add_shortcut( "adjust" );
-    set_callbacks( Create, Destroy );
-vlc_module_end();
+    add_shortcut( "adjust" )
+    set_callbacks( Create, Destroy )
+vlc_module_end ()
 
 static const char *const ppsz_filter_options[] = {
     "contrast", "brightness", "hue", "saturation", "gamma",
@@ -112,6 +111,7 @@ static const char *const ppsz_filter_options[] = {
  *****************************************************************************/
 struct filter_sys_t
 {
+    vlc_mutex_t lock;
     double     f_contrast;
     double     f_brightness;
     int        i_hue;
@@ -141,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;
     }
@@ -155,10 +155,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_sys = p_filter->p_sys;
 
     /* needed to get options passed in transcode using the
@@ -174,6 +171,7 @@ static int Create( vlc_object_t *p_this )
     p_sys->b_brightness_threshold =
         var_CreateGetBoolCommand( p_filter, "brightness-threshold" );
 
+    vlc_mutex_init( &p_sys->lock );
     var_AddCallback( p_filter, "contrast",   AdjustCallback, p_sys );
     var_AddCallback( p_filter, "brightness", AdjustCallback, p_sys );
     var_AddCallback( p_filter, "hue",        AdjustCallback, p_sys );
@@ -191,7 +189,18 @@ 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 );
+    filter_sys_t *p_sys = p_filter->p_sys;
+
+    var_DelCallback( p_filter, "contrast",   AdjustCallback, p_sys );
+    var_DelCallback( p_filter, "brightness", AdjustCallback, p_sys );
+    var_DelCallback( p_filter, "hue",        AdjustCallback, p_sys );
+    var_DelCallback( p_filter, "saturation", AdjustCallback, p_sys );
+    var_DelCallback( p_filter, "gamma",      AdjustCallback, p_sys );
+    var_DelCallback( p_filter, "brightness-threshold",
+                                             AdjustCallback, p_sys );
+
+    vlc_mutex_destroy( &p_sys->lock );
+    free( p_sys );
 }
 
 /*****************************************************************************
@@ -217,22 +226,22 @@ static picture_t *FilterPlanar( 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;
     }
 
-    /* Getvariables */
+    /* Get variables */
+    vlc_mutex_lock( &p_sys->lock );
     i_cont = (int)( p_sys->f_contrast * 255 );
     i_lum = (int)( (p_sys->f_brightness - 1.0)*255 );
     f_hue = (float)( p_sys->i_hue * M_PI / 180 );
     i_sat = (int)( p_sys->f_saturation * 256 );
     f_gamma = 1.0 / p_sys->f_gamma;
     b_thres = p_sys->b_brightness_threshold;
+    vlc_mutex_unlock( &p_sys->lock );
 
     /*
      * Threshold mode drops out everything about luma, contrast and gamma.
@@ -247,7 +256,7 @@ static picture_t *FilterPlanar( filter_t *p_filter, picture_t *p_pic )
         /* Fill the gamma lookup table */
         for( i = 0 ; i < 256 ; i++ )
         {
-          pi_gamma[ i ] = clip_uint8_vlc( pow(i / 255.0, f_gamma) * 255.0);
+            pi_gamma[ i ] = clip_uint8_vlc( pow(i / 255.0, f_gamma) * 255.0);
         }
 
         /* Fill the luma lookup table */
@@ -410,16 +419,7 @@ static picture_t *FilterPlanar( filter_t *p_filter, picture_t *p_pic )
 #undef WRITE_UV
     }
 
-    p_outpic->date = p_pic->date;
-    p_outpic->b_force = p_pic->b_force;
-    p_outpic->i_nb_fields = p_pic->i_nb_fields;
-    p_outpic->b_progressive = p_pic->b_progressive;
-    p_outpic->b_top_field_first = p_pic->b_top_field_first;
-
-    if( p_pic->pf_release )
-        p_pic->pf_release( p_pic );
-
-    return p_outpic;
+    return CopyInfoAndRelease( p_outpic, p_pic );
 }
 
 /*****************************************************************************
@@ -456,29 +456,31 @@ static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic )
     if( GetPackedYuvOffsets( p_pic->format.i_chroma, &i_y_offset,
                              &i_u_offset, &i_v_offset ) != VLC_SUCCESS )
     {
-        msg_Warn( p_filter, "Unsupported input chroma (%4s)",
+        msg_Warn( p_filter, "Unsupported input chroma (%4.4s)",
                   (char*)&(p_pic->format.i_chroma) );
-        if( p_pic->pf_release )
-            p_pic->pf_release( p_pic );
+
+        picture_Release( 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;
     }
 
-    /* Getvariables */
+    /* Get variables */
+    vlc_mutex_lock( &p_sys->lock );
     i_cont = (int)( p_sys->f_contrast * 255 );
     i_lum = (int)( (p_sys->f_brightness - 1.0)*255 );
     f_hue = (float)( p_sys->i_hue * M_PI / 180 );
     i_sat = (int)( p_sys->f_saturation * 256 );
     f_gamma = 1.0 / p_sys->f_gamma;
     b_thres = p_sys->b_brightness_threshold;
+    vlc_mutex_unlock( &p_sys->lock );
 
     /*
      * Threshold mode drops out everything about luma, contrast and gamma.
@@ -652,16 +654,7 @@ static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic )
 #undef WRITE_UV
     }
 
-    p_outpic->date = p_pic->date;
-    p_outpic->b_force = p_pic->b_force;
-    p_outpic->i_nb_fields = p_pic->i_nb_fields;
-    p_outpic->b_progressive = p_pic->b_progressive;
-    p_outpic->b_top_field_first = p_pic->b_top_field_first;
-
-    if( p_pic->pf_release )
-        p_pic->pf_release( p_pic );
-
-    return p_outpic;
+    return CopyInfoAndRelease( p_outpic, p_pic );
 }
 
 static int AdjustCallback( vlc_object_t *p_this, char const *psz_var,
@@ -671,6 +664,7 @@ static int AdjustCallback( 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;
 
+    vlc_mutex_lock( &p_sys->lock );
     if( !strcmp( psz_var, "contrast" ) )
         p_sys->f_contrast = newval.f_float;
     else if( !strcmp( psz_var, "brightness" ) )
@@ -683,7 +677,7 @@ static int AdjustCallback( vlc_object_t *p_this, char const *psz_var,
         p_sys->f_gamma = newval.f_float;
     else if( !strcmp( psz_var, "brightness-threshold" ) )
         p_sys->b_brightness_threshold = newval.b_bool;
-    else
-        return VLC_EGENERIC;
+    vlc_mutex_unlock( &p_sys->lock );
+
     return VLC_SUCCESS;
 }