]> git.sesse.net Git - vlc/blobdiff - modules/control/showintf.c
showintf: privatize the callback lock
[vlc] / modules / control / showintf.c
index a9321c9689dbb08030183a394c369b0a669ec06a..c93fa3f567c04b02e1057baabb8247d85ad27c4c 100644 (file)
@@ -29,7 +29,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_interface.h>
 #include <vlc_vout.h>
 #include <vlc_playlist.h>
  *****************************************************************************/
 struct intf_sys_t
 {
+    vlc_mutex_t lock;
     vlc_object_t * p_vout;
-    vlc_bool_t     b_button_pressed;
-    vlc_bool_t     b_triggered;
+    bool     b_button_pressed;
+    bool     b_triggered;
     int            i_threshold;
 };
 
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
-int  E_(Open) ( vlc_object_t * );
-void E_(Close)( vlc_object_t * );
+int  Open ( vlc_object_t * );
+void Close( vlc_object_t * );
 static void RunIntf( intf_thread_t *p_intf );
 static int  InitThread( intf_thread_t *p_intf );
 static int  MouseEvent( vlc_object_t *, char const *,
@@ -65,19 +67,19 @@ static int  MouseEvent( vlc_object_t *, char const *,
 #define THRESHOLD_TEXT N_( "Threshold" )
 #define THRESHOLD_LONGTEXT N_( "Height of the zone triggering the interface." )
 
-vlc_module_begin();
-    set_shortname( "Showintf" );
-    add_integer( "showintf-threshold", 10, NULL, THRESHOLD_TEXT, THRESHOLD_LONGTEXT, VLC_TRUE );
-    set_description( _("Show interface with mouse") );
+vlc_module_begin ()
+    set_shortname( "Showintf" )
+    add_integer( "showintf-threshold", 10, NULL, THRESHOLD_TEXT, THRESHOLD_LONGTEXT, true )
+    set_description( N_("Show interface with mouse") )
 
-    set_capability( "interface", 0 );
-    set_callbacks( E_(Open), E_(Close) );
-vlc_module_end();
+    set_capability( "interface", 0 )
+    set_callbacks( Open, Close )
+vlc_module_end ()
 
 /*****************************************************************************
  * Open: initialize interface
  *****************************************************************************/
-int E_(Open)( vlc_object_t *p_this )
+int Open( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
 
@@ -88,6 +90,7 @@ int E_(Open)( vlc_object_t *p_this )
         return( 1 );
     };
 
+    vlc_mutex_init( &p_intf->p_sys->lock );
     p_intf->pf_run = RunIntf;
 
     return( 0 );
@@ -96,11 +99,12 @@ int E_(Open)( vlc_object_t *p_this )
 /*****************************************************************************
  * Close: destroy interface
  *****************************************************************************/
-void E_(Close)( vlc_object_t *p_this )
+void Close( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
 
     /* Destroy structure */
+    vlc_mutex_destroy( &p_intf->p_sys->lock );
     free( p_intf->p_sys );
 }
 
@@ -110,6 +114,7 @@ void E_(Close)( vlc_object_t *p_this )
  *****************************************************************************/
 static void RunIntf( intf_thread_t *p_intf )
 {
+    int canc = vlc_savecancel( );
     p_intf->p_sys->p_vout = NULL;
 
     if( InitThread( p_intf ) < 0 )
@@ -119,24 +124,22 @@ static void RunIntf( intf_thread_t *p_intf )
     }
 
     /* Main loop */
-    while( !intf_ShouldDie( p_intf ) )
+    while( vlc_object_alive( p_intf ) )
     {
-        vlc_mutex_lock( &p_intf->change_lock );
+        vlc_mutex_lock( &p_intf->p_sys->lock );
 
         /* Notify the interfaces */
         if( p_intf->p_sys->b_triggered )
         {
-            playlist_t *p_playlist = pl_Yield( p_intf );
-            var_SetBool( p_playlist, "intf-show", VLC_TRUE );
-            vlc_object_release( p_playlist );
-            p_intf->p_sys->b_triggered = VLC_FALSE;
+            var_SetBool( p_intf->p_libvlc, "intf-show", true );
+            p_intf->p_sys->b_triggered = false;
         }
 
-        vlc_mutex_unlock( &p_intf->change_lock );
+        vlc_mutex_unlock( &p_intf->p_sys->lock );
 
 
         /* Take care of the video output */
-        if( p_intf->p_sys->p_vout && p_intf->p_sys->p_vout->b_die )
+        if( p_intf->p_sys->p_vout && !vlc_object_alive (p_intf->p_sys->p_vout) )
         {
             var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
                              MouseEvent, p_intf );
@@ -171,6 +174,7 @@ static void RunIntf( intf_thread_t *p_intf )
                          MouseEvent, p_intf );
         vlc_object_release( p_intf->p_sys->p_vout );
     }
+    vlc_restorecancel( canc );
 }
 
 /*****************************************************************************
@@ -178,16 +182,16 @@ static void RunIntf( intf_thread_t *p_intf )
  *****************************************************************************/
 static int InitThread( intf_thread_t * p_intf )
 {
-    if( !intf_ShouldDie( p_intf ) )
+    if( vlc_object_alive( p_intf ) )
     {
-        vlc_mutex_lock( &p_intf->change_lock );
+        vlc_mutex_lock( &p_intf->p_sys->lock );
 
-        p_intf->p_sys->b_triggered = VLC_FALSE;
-        p_intf->p_sys->b_button_pressed = VLC_FALSE;
+        p_intf->p_sys->b_triggered = false;
+        p_intf->p_sys->b_button_pressed = false;
         p_intf->p_sys->i_threshold =
             config_GetInt( p_intf, "showintf-threshold" );
 
-        vlc_mutex_unlock( &p_intf->change_lock );
+        vlc_mutex_unlock( &p_intf->p_sys->lock );
 
         return 0;
     }
@@ -218,7 +222,7 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
     if( !val.i_int )
         return VLC_SUCCESS;
 
-    vlc_mutex_lock( &p_intf->change_lock );
+    vlc_mutex_lock( &p_intf->p_sys->lock );
     if( !strcmp( psz_var, "mouse-moved" ) && !p_intf->p_sys->b_button_pressed )
     {
         var_Get( p_intf->p_sys->p_vout, "mouse-x", &val );
@@ -230,7 +234,7 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
         if ( i_mouse_y < p_intf->p_sys->i_threshold )
         {
             msg_Dbg( p_intf, "interface showing requested" );
-            p_intf->p_sys->b_triggered = VLC_TRUE;
+            p_intf->p_sys->b_triggered = true;
         }
     }
 
@@ -239,15 +243,15 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
     if( !p_intf->p_sys->b_button_pressed &&
         !strcmp( psz_var, "mouse-button-down" ) )
     {
-        p_intf->p_sys->b_button_pressed = VLC_TRUE;
+        p_intf->p_sys->b_button_pressed = true;
     }
     if( p_intf->p_sys->b_button_pressed &&
         !strcmp( psz_var, "mouse-button-down" ) )
     {
-        p_intf->p_sys->b_button_pressed = VLC_FALSE;
+        p_intf->p_sys->b_button_pressed = false;
     }
 
-    vlc_mutex_unlock( &p_intf->change_lock );
+    vlc_mutex_unlock( &p_intf->p_sys->lock );
 
     return VLC_SUCCESS;
 }