]> git.sesse.net Git - vlc/blobdiff - modules/control/gestures.c
Removes trailing spaces. Removes tabs.
[vlc] / modules / control / gestures.c
index f772b5abd21ca9fec8ba1117ac38aa56bfc243b1..d81b4e9446eb9900dd601412a05d9ad504ea15ef 100644 (file)
@@ -24,8 +24,6 @@
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>
 
 #include <vlc/vlc.h>
 #include <vlc_interface.h>
@@ -43,7 +41,6 @@
 struct intf_sys_t
 {
     vlc_object_t *      p_vout;
-    input_thread_t *    p_input;
     vlc_bool_t          b_got_gesture;
     vlc_bool_t          b_button_pressed;
     int                 i_mouse_x, i_mouse_y;
@@ -131,6 +128,23 @@ static int gesture( int i_pattern, int i_num )
     return ( i_pattern >> ( i_num * 4 ) ) & 0xF;
 }
 
+/*****************************************************************************
+ * input_from_playlist: don't forget to release the return value
+ *  Also this function should really be available from core.
+ *****************************************************************************/
+static input_thread_t * input_from_playlist ( playlist_t *p_playlist )
+{
+    input_thread_t * p_input;
+
+    PL_LOCK;
+    p_input = p_playlist->p_input;
+    if( p_input )
+        vlc_object_yield( p_input );
+    PL_UNLOCK;
+
+    return p_input;
+}
+
 /*****************************************************************************
  * CloseIntf: destroy dummy interface
  *****************************************************************************/
@@ -154,8 +168,6 @@ static void RunIntf( intf_thread_t *p_intf )
     p_intf->p_sys->p_vout = NULL;
     vlc_mutex_unlock( &p_intf->change_lock );
 
-    input_thread_t * p_input = p_intf->p_sys->p_input;
-
     if( InitThread( p_intf ) < 0 )
     {
         msg_Err( p_intf, "can't initialize interface thread" );
@@ -207,21 +219,37 @@ static void RunIntf( intf_thread_t *p_intf )
                 break;
             case GESTURE(LEFT,RIGHT,NONE,NONE):
             case GESTURE(RIGHT,LEFT,NONE,NONE):
-                val.i_int = PLAYING_S;
-                if( p_input )
                 {
-                    var_Get( p_input, "state", &val);
-                    if( val.i_int == PAUSE_S )
-                    {
-                        val.i_int = PLAYING_S;
-                    }
-                    else
+                    input_thread_t * p_input;
+                    p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+                                              FIND_ANYWHERE );
+
+                   if( !p_playlist )
+                        break;
+
+                    p_input = input_from_playlist( p_playlist );
+                    vlc_object_release( p_playlist );
+                    if( !p_input )
+                        break;
+                    val.i_int = PLAYING_S;
+                    if( p_input )
                     {
-                        val.i_int = PAUSE_S;
+                        var_Get( p_input, "state", &val);
+                        if( val.i_int == PAUSE_S )
+                        {
+                            val.i_int = PLAYING_S;
+                        }
+                        else
+                        {
+                            val.i_int = PAUSE_S;
+                        }
+                        var_Set( p_input, "state", val);
                     }
-                    var_Set( p_input, "state", val);
+                    msg_Dbg(p_intf, "Play/Pause");
+                    vlc_object_release( p_input );
                 }
-                msg_Dbg(p_intf, "Play/Pause");
                 break;
             case GESTURE(LEFT,DOWN,NONE,NONE):
                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
@@ -269,15 +297,31 @@ static void RunIntf( intf_thread_t *p_intf )
                 break;
             case GESTURE(UP,RIGHT,NONE,NONE):
                 {
+                   input_thread_t * p_input;
                    vlc_value_t val, list, list2;
                    int i_count, i;
+
+                    p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+                                              FIND_ANYWHERE );
+
+                   if( !p_playlist )
+                        break;
+
+                    p_input = input_from_playlist( p_playlist );
+
+                    vlc_object_release( p_playlist );
+
+                    if( !p_input )
+                        break;
+
                    var_Get( p_input, "audio-es", &val );
                    var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
                                &list, &list2 );
                    i_count = list.p_list->i_count;
                    if( i_count <= 1 )
                    {
-                       continue;
+                       vlc_object_release( p_input );
+                       break;
                    }
                    for( i = 0; i < i_count; i++ )
                    {
@@ -307,12 +351,27 @@ static void RunIntf( intf_thread_t *p_intf )
                                list.p_list->p_values[i+1] );
                        i++;
                    }
+                   vlc_object_release( p_input );
                 }
                 break;
             case GESTURE(DOWN,RIGHT,NONE,NONE):
                 {
+                    input_thread_t * p_input;
                     vlc_value_t val, list, list2;
                     int i_count, i;
+
+                    p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+                                              FIND_ANYWHERE );
+
+                    if( !p_playlist )
+                        break;
+
+                    p_input = input_from_playlist( p_playlist );
+                    vlc_object_release( p_playlist );
+
+                    if( !p_input )
+                        break;
+
                     var_Get( p_input, "spu-es", &val );
 
                     var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
@@ -320,7 +379,8 @@ static void RunIntf( intf_thread_t *p_intf )
                     i_count = list.p_list->i_count;
                     if( i_count <= 1 )
                     {
-                        continue;
+                        vlc_object_release( p_input );
+                        break;
                     }
                     for( i = 0; i < i_count; i++ )
                     {
@@ -344,10 +404,11 @@ static void RunIntf( intf_thread_t *p_intf )
                     }
                     else
                     {
-                        var_Set( p_input, "spu-es", 
+                        var_Set( p_input, "spu-es",
                                 list.p_list->p_values[i+1] );
                         i = i + 1;
                     }
+                    vlc_object_release( p_input );
                 }
                 break;
             case GESTURE(UP,LEFT,NONE,NONE):
@@ -359,7 +420,7 @@ static void RunIntf( intf_thread_t *p_intf )
                 break;
             case GESTURE(DOWN,LEFT,NONE,NONE):
                 /* FIXME: Should close the vout!"*/
-                p_intf->p_libvlc->b_die = VLC_TRUE;
+                vlc_object_kill( p_intf->p_libvlc );
                 break;
             case GESTURE(DOWN,LEFT,UP,RIGHT):
             case GESTURE(UP,RIGHT,DOWN,LEFT):
@@ -424,12 +485,6 @@ static int InitThread( intf_thread_t * p_intf )
          *   during those operations */
         vlc_mutex_lock( &p_intf->change_lock );
 
-        /* p_intf->p_sys->p_input references counting strategy:
-         * - InitThread is responsible for only one ref count retaining
-         * - EndThread is responsible for the corresponding release */
-        p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
-                                                  FIND_PARENT );
-
         p_intf->p_sys->b_got_gesture = VLC_FALSE;
         p_intf->p_sys->b_button_pressed = VLC_FALSE;
         p_intf->p_sys->i_threshold =
@@ -476,11 +531,6 @@ static void EndThread( intf_thread_t * 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);
-    }
-
     vlc_mutex_unlock( &p_intf->change_lock );
 }