[vlc-devel] commit: crop: thread-safety for FilterCallback ( Rémi Denis-Courmont )

git version control git at videolan.org
Tue May 19 19:59:18 CEST 2009


vlc | branch: 1.0-bugfix | Rémi Denis-Courmont <remi at remlab.net> | Tue May 19 20:05:39 2009 +0300| [8c1c227dc2b4f5a9280e56154efb9b5e19d6da07] | committer: Rémi Denis-Courmont 

crop: thread-safety for FilterCallback

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8c1c227dc2b4f5a9280e56154efb9b5e19d6da07
---

 modules/video_filter/crop.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/modules/video_filter/crop.c b/modules/video_filter/crop.c
index 0c026ff..b7a63ad 100644
--- a/modules/video_filter/crop.c
+++ b/modules/video_filter/crop.c
@@ -145,6 +145,7 @@ vlc_module_end ()
  *****************************************************************************/
 struct vout_sys_t
 {
+    vlc_mutex_t lock;
     vout_thread_t *p_vout;
 
     unsigned int i_x, i_y;
@@ -376,6 +377,7 @@ static int Init( vout_thread_t *p_vout )
     }
 
 #ifdef BEST_AUTOCROP
+    vlc_mutex_init( &p_vout->p_sys->lock );
     var_AddCallback( p_vout, "ratio-crop", FilterCallback, NULL );
 #endif
 
@@ -400,6 +402,8 @@ static void End( vout_thread_t *p_vout )
     }
 
     vout_filter_ReleaseDirectBuffers( p_vout );
+    var_DelCallback( p_vout, "ratio-crop", FilterCallback, NULL );
+    vlc_mutex_destroy( &p_sys->lock );
 }
 
 /*****************************************************************************
@@ -432,6 +436,7 @@ static int Manage( vout_thread_t *p_vout )
     memset( &fmt, 0, sizeof(video_format_t) );
 
 #ifdef BEST_AUTOCROP
+    /* XXX: not thread-safe with FilterCallback */
     msg_Dbg( p_vout, "cropping at %ix%i+%i+%i, %sautocropping",
                      p_vout->p_sys->i_width, p_vout->p_sys->i_height,
                      p_vout->p_sys->i_x, p_vout->p_sys->i_y,
@@ -465,7 +470,9 @@ static int Manage( vout_thread_t *p_vout )
     vout_filter_AddChild( p_vout, p_vout->p_sys->p_vout, MouseEvent );
 
     p_vout->p_sys->b_changed = false;
+    vlc_mutex_lock( &p_vout->p_sys->lock );
     p_vout->p_sys->i_lastchange = 0;
+    vlc_mutex_unlock( &p_vout->p_sys->lock );
 
     return VLC_SUCCESS;
 }
@@ -532,10 +539,10 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic )
     vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic );
 
     /* The source image may still be in the cache ... parse it! */
+    vlc_mutex_lock( &p_vout->p_sys->lock );
     if( p_vout->p_sys->b_autocrop )
-    {
         UpdateStats( p_vout, p_pic );
-    }
+    vlc_mutex_unlock( &p_vout->p_sys->lock );
 }
 
 #ifdef BEST_AUTOCROP
@@ -848,6 +855,7 @@ static int FilterCallback( vlc_object_t *p_this, char const *psz_var,
 
     if( !strcmp( psz_var, "ratio-crop" ) )
     {
+        vlc_mutex_lock( &p_vout->p_sys->lock );
         if ( !strcmp( newval.psz_string, "Auto" ) )
             p_vout->p_sys->i_ratio = 0;
         else
@@ -865,6 +873,7 @@ static int FilterCallback( vlc_object_t *p_this, char const *psz_var,
             if (p_vout->p_sys->i_ratio < p_vout->output.i_aspect / 432)
                 p_vout->p_sys->i_ratio = p_vout->output.i_aspect / 432;
         }
+        vlc_mutex_unlock( &p_vout->p_sys->lock );
      }
     return VLC_SUCCESS;
 }




More information about the vlc-devel mailing list