]> git.sesse.net Git - vlc/blobdiff - modules/control/gestures.c
Gestures: Make sure p_intf->p_sys->p_input gets released.
[vlc] / modules / control / gestures.c
index 4a37955d1b651f11a4413c3ae423a3ba7ce7778d..9bfa5a3b9cf43ebef5380534883edd17d20ba858 100644 (file)
@@ -28,8 +28,9 @@
 #include <string.h>
 
 #include <vlc/vlc.h>
-#include <vlc/intf.h>
-#include <vlc/vout.h>
+#include <vlc_interface.h>
+#include <vlc_vout.h>
+#include <vlc_playlist.h>
 
 #ifdef HAVE_UNISTD_H
 #    include <unistd.h>
@@ -65,6 +66,7 @@ struct intf_sys_t
 int  E_(Open)   ( vlc_object_t * );
 void E_(Close)  ( vlc_object_t * );
 static int  InitThread     ( intf_thread_t *p_intf );
+static void EndThread      ( intf_thread_t *p_intf );
 static int  MouseEvent     ( vlc_object_t *, char const *,
                              vlc_value_t, vlc_value_t, void * );
 
@@ -80,10 +82,11 @@ static void RunIntf        ( intf_thread_t *p_intf );
 
 #define BUTTON_TEXT N_( "Trigger button" )
 #define BUTTON_LONGTEXT N_( \
-    "You can set the trigger button for mouse gestures here." )
+    "Trigger button for mouse gestures." )
 
-static char *button_list[] = { "left", "middle", "right" };
-static char *button_list_text[] = { N_("Left"), N_("Middle"), N_("Right") };
+static const char *button_list[] = { "left", "middle", "right" };
+static const char *button_list_text[] =
+                                   { N_("Left"), N_("Middle"), N_("Right") };
 
 vlc_module_begin();
     set_shortname( _("Gestures"));
@@ -155,7 +158,7 @@ static void RunIntf( intf_thread_t *p_intf )
     msg_Dbg( p_intf, "interface thread initialized" );
 
     /* Main loop */
-    while( !p_intf->b_die )
+    while( !intf_ShouldDie( p_intf ) )
     {
         vlc_mutex_lock( &p_intf->change_lock );
 
@@ -198,7 +201,7 @@ static void RunIntf( intf_thread_t *p_intf )
                 break;
             case GESTURE(DOWN,RIGHT,NONE,NONE):
                 /* FIXME: Should close the vout!"*/
-                p_intf->p_vlc->b_die = VLC_TRUE;
+                p_intf->p_libvlc->b_die = VLC_TRUE;
                 break;
             case GESTURE(DOWN,LEFT,UP,RIGHT):
                 msg_Dbg(p_intf, "a square was drawn!" );
@@ -244,14 +247,7 @@ static void RunIntf( intf_thread_t *p_intf )
         msleep( INTF_IDLE_SLEEP );
     }
 
-    if( p_intf->p_sys->p_vout )
-    {
-        var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
-                         MouseEvent, p_intf );
-        var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
-                         MouseEvent, p_intf );
-        vlc_object_release( p_intf->p_sys->p_vout );
-    }
+    EndThread( p_intf );
 }
 
 /*****************************************************************************
@@ -261,10 +257,13 @@ static int InitThread( intf_thread_t * p_intf )
 {
     char *psz_button;
     /* we might need some locking here */
-    if( !p_intf->b_die )
+    if( !intf_ShouldDie( p_intf ) )
     {
         input_thread_t * p_input;
 
+        /* p_intf->p_sys->p_input references counting strategy:
+         * - InitThread is responsible for only one ref count retaining
+         * - EndThread is responsible for the correspondinf release */
         p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
 
         vlc_mutex_lock( &p_intf->change_lock );
@@ -300,6 +299,26 @@ static int InitThread( intf_thread_t * p_intf )
     }
 }
 
+/*****************************************************************************
+ * EndThread:
+ *****************************************************************************/
+static void EndThread( intf_thread_t * p_intf )
+{
+    if( p_intf->p_sys->p_vout )
+    {
+        var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
+                         MouseEvent, p_intf );
+        var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
+                         MouseEvent, p_intf );
+        vlc_object_release( p_intf->p_sys->p_vout );
+    }
+
+    if( p_intf->p_sys->p_input )
+    {
+        vlc_object_release(p_intf->p_sys->p_input);
+    }
+}
+
 /*****************************************************************************
  * MouseEvent: callback for mouse events
  *****************************************************************************/