postproc: reduce lock contention in callback
[vlc.git] / modules / video_filter / postproc.c
index 3ee8882..454c79c 100644 (file)
@@ -331,28 +331,27 @@ static void PPChangeMode( filter_t *p_filter, const char *psz_name,
                           int i_quality )
 {
     filter_sys_t *p_sys = p_filter->p_sys;
+    pp_mode *newmode = NULL, *oldmode;
+
     vlc_mutex_lock( &p_sys->lock );
     if( i_quality > 0 )
     {
-        pp_mode *pp_mode = pp_get_mode_by_name_and_quality( psz_name ?
-                                                              psz_name :
-                                                              "default",
-                                                              i_quality );
-        if( pp_mode )
-        {
-            pp_free_mode( p_sys->pp_mode );
-            p_sys->pp_mode = pp_mode;
+         newmode = pp_get_mode_by_name_and_quality( psz_name ? psz_name :
+                                                    "default", i_quality );
+         if( newmode == NULL )
+         {
+             msg_Warn( p_filter, "Error while changing post processing mode. "
+                       "Keeping previous mode." );
+             return;
         }
-        else
-            msg_Warn( p_filter, "Error while changing post processing mode. "
-                      "Keeping previous mode." );
-    }
-    else
-    {
-        pp_free_mode( p_sys->pp_mode );
-        p_sys->pp_mode = NULL;
     }
+
+    vlc_mutex_lock( &p_sys->lock );
+    oldmode = p_sys->pp_mode;
+    p_sys->pp_mode = newmode;
     vlc_mutex_unlock( &p_sys->lock );
+
+    pp_free_mode( oldmode );
 }
 
 static int PPQCallback( vlc_object_t *p_this, const char *psz_var,