]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/colorthres.c
deinterlace: privatize two functions
[vlc] / modules / video_filter / colorthres.c
index c6c44e071cc8aee2338068cd7a8061bd77aedc66..3778639e32f59fae27ab4516d7a8d35d347a7c42 100644 (file)
@@ -1,25 +1,25 @@
 /*****************************************************************************
  * colorthres.c: Threshold color based on similarity to reference color
  *****************************************************************************
- * Copyright (C) 2000-2009 the VideoLAN team
+ * Copyright (C) 2000-2009 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Sigmund Augdal <dnumgis@videolan.org>
  *          Antoine Cellerier <dionoea at videolan dot org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -35,7 +35,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_sout.h>
-
+#include <vlc_atomic.h>
 #include <vlc_filter.h>
 #include "filter_picture.h"
 
@@ -72,12 +72,12 @@ vlc_module_begin ()
     set_category( CAT_VIDEO )
     set_subcategory( SUBCAT_VIDEO_VFILTER )
     set_capability( "video filter2", 0 )
-    add_integer( CFG_PREFIX "color", 0x00FF0000, NULL, COLOR_TEXT,
+    add_rgb( CFG_PREFIX "color", 0x00FF0000, COLOR_TEXT,
                  COLOR_LONGTEXT, false )
-        change_integer_list( pi_color_values, ppsz_color_descriptions, NULL )
-    add_integer( CFG_PREFIX "saturationthres", 20, NULL,
-                 N_("Saturaton threshold"), "", false )
-    add_integer( CFG_PREFIX "similaritythres", 15, NULL,
+        change_integer_list( pi_color_values, ppsz_color_descriptions )
+    add_integer( CFG_PREFIX "saturationthres", 20,
+                 N_("Saturation threshold"), "", false )
+    add_integer( CFG_PREFIX "similaritythres", 15,
                  N_("Similarity threshold"), "", false )
     set_callbacks( Create, Destroy )
 vlc_module_end ()
@@ -98,10 +98,9 @@ static int FilterCallback( vlc_object_t *, char const *,
  *****************************************************************************/
 struct filter_sys_t
 {
-    int i_simthres;
-    int i_satthres;
-    int i_color;
-    vlc_mutex_t lock;
+    atomic_int i_simthres;
+    atomic_int i_satthres;
+    atomic_int i_color;
 };
 
 /*****************************************************************************
@@ -143,17 +142,16 @@ static int Create( vlc_object_t *p_this )
 
     config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
                        p_filter->p_cfg );
-    p_sys->i_color = var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "color" );
-    p_sys->i_simthres = var_CreateGetIntegerCommand( p_filter,
-                                                     CFG_PREFIX "similaritythres" );
-    p_sys->i_satthres = var_CreateGetIntegerCommand( p_filter,
-                                                     CFG_PREFIX "saturationthres" );
-
-    vlc_mutex_init( &p_sys->lock );
+    atomic_init( &p_sys->i_color,
+                 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "color" ) );
+    atomic_init( &p_sys->i_simthres,
+       var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "similaritythres" ) );
+    atomic_init( &p_sys->i_satthres,
+       var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "saturationthres" ) );
 
-    var_AddCallback( p_filter, CFG_PREFIX "color", FilterCallback, NULL );
-    var_AddCallback( p_filter, CFG_PREFIX "similaritythres", FilterCallback, NULL );
-    var_AddCallback( p_filter, CFG_PREFIX "saturationthres", FilterCallback, NULL );
+    var_AddCallback( p_filter, CFG_PREFIX "color", FilterCallback, p_sys );
+    var_AddCallback( p_filter, CFG_PREFIX "similaritythres", FilterCallback, p_sys );
+    var_AddCallback( p_filter, CFG_PREFIX "saturationthres", FilterCallback, p_sys );
 
     return VLC_SUCCESS;
 }
@@ -166,13 +164,12 @@ static int Create( vlc_object_t *p_this )
 static void Destroy( vlc_object_t *p_this )
 {
     filter_t *p_filter = (filter_t *)p_this;
+    filter_sys_t *p_sys = p_filter->p_sys;
 
-    var_DelCallback( p_filter, CFG_PREFIX "color", FilterCallback, NULL );
-    var_DelCallback( p_filter, CFG_PREFIX "similaritythres", FilterCallback, NULL );
-    var_DelCallback( p_filter, CFG_PREFIX "saturationthres", FilterCallback, NULL );
-
-    vlc_mutex_destroy( &p_filter->p_sys->lock );
-    free( p_filter->p_sys );
+    var_DelCallback( p_filter, CFG_PREFIX "color", FilterCallback, p_sys );
+    var_DelCallback( p_filter, CFG_PREFIX "similaritythres", FilterCallback, p_sys );
+    var_DelCallback( p_filter, CFG_PREFIX "saturationthres", FilterCallback, p_sys );
+    free( p_sys );
 }
 
 static void GetReference( int *refu, int *refv, int *reflength,
@@ -212,12 +209,9 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
 {
     picture_t *p_outpic;
     filter_sys_t *p_sys = p_filter->p_sys;
-
-    vlc_mutex_lock( &p_sys->lock );
-    int i_simthres = p_sys->i_simthres;
-    int i_satthres = p_sys->i_satthres;
-    int i_color = p_sys->i_color;
-    vlc_mutex_unlock( &p_sys->lock );
+    int i_simthres = atomic_load( &p_sys->i_simthres );
+    int i_satthres = atomic_load( &p_sys->i_satthres );
+    int i_color = atomic_load( &p_sys->i_color );
 
     if( !p_pic ) return NULL;
 
@@ -271,12 +265,9 @@ static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic )
 {
     picture_t *p_outpic;
     filter_sys_t *p_sys = p_filter->p_sys;
-
-    vlc_mutex_lock( &p_sys->lock );
-    int i_simthres = p_sys->i_simthres;
-    int i_satthres = p_sys->i_satthres;
-    int i_color = p_sys->i_color;
-    vlc_mutex_unlock( &p_sys->lock );
+    int i_simthres = atomic_load( &p_sys->i_simthres );
+    int i_satthres = atomic_load( &p_sys->i_satthres );
+    int i_color = atomic_load( &p_sys->i_color );
 
     if( !p_pic ) return NULL;
 
@@ -287,9 +278,14 @@ static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic )
         return NULL;
     }
 
-    int i_y_offset = 0, i_u_offset = 0, i_v_offset = 0;
-    GetPackedYuvOffsets( p_filter->fmt_in.video.i_chroma,
-                         &i_y_offset, &i_u_offset, &i_v_offset );
+    int i_y_offset, i_u_offset, i_v_offset;
+    int i_ret = GetPackedYuvOffsets( p_filter->fmt_in.video.i_chroma,
+                                     &i_y_offset, &i_u_offset, &i_v_offset );
+    if( i_ret == VLC_EGENERIC )
+    {
+        picture_Release( p_pic );
+        return NULL;
+    }
 
     /*
      * Copy Y and do the U and V planes
@@ -329,30 +325,17 @@ static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic )
 }
 
 static int FilterCallback ( vlc_object_t *p_this, char const *psz_var,
-                            vlc_value_t oldval, vlc_value_t newval, void *p_data )
+                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
-    (void)oldval;    (void)p_data;
-    filter_t *p_filter = (filter_t*)p_this;
-    filter_sys_t *p_sys = p_filter->p_sys;
+    filter_sys_t *p_sys = p_data;
 
     if( !strcmp( psz_var, CFG_PREFIX "color" ) )
-    {
-        vlc_mutex_lock( &p_sys->lock );
-        p_sys->i_color = newval.i_int;
-        vlc_mutex_unlock( &p_sys->lock );
-    }
+        atomic_store( &p_sys->i_color, newval.i_int );
     else if( !strcmp( psz_var, CFG_PREFIX "similaritythres" ) )
-    {
-        vlc_mutex_lock( &p_sys->lock );
-        p_sys->i_simthres = newval.i_int;
-        vlc_mutex_unlock( &p_sys->lock );
-    }
+        atomic_store( &p_sys->i_simthres, newval.i_int );
     else /* CFG_PREFIX "saturationthres" */
-    {
-        vlc_mutex_lock( &p_sys->lock );
-        p_sys->i_satthres = newval.i_int;
-        vlc_mutex_unlock( &p_sys->lock );
-    }
+        atomic_store( &p_sys->i_satthres, newval.i_int );
 
+    (void)p_this; (void)oldval;
     return VLC_SUCCESS;
 }