]> git.sesse.net Git - vlc/blobdiff - modules/access/dvdplay/intf.c
modules/gui/wxwindows/iteminfo.cpp:
[vlc] / modules / access / dvdplay / intf.c
index 4a64683172008f2bcea74e51176624cb009c1670..15b1cb4c58ca4fbea336ef8e4baf24b1d9f89be2 100644 (file)
@@ -2,7 +2,7 @@
  * intf.c: interface for DVD video manager
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: intf.c,v 1.3 2002/11/06 18:07:57 sam Exp $
+ * $Id: intf.c,v 1.9 2003/10/29 01:33:27 gbazin Exp $
  *
  * Authors: Stéphane Borel <stef@via.ecp.fr>
  *
@@ -35,6 +35,8 @@
 #include "input_ext-intf.h"
 #include "input_ext-dec.h"
 
+#include "vlc_keys.h"
+
 #include "dvd.h"
 
 /*****************************************************************************
@@ -50,7 +52,7 @@ struct intf_sys_t
     mtime_t             m_still_time;
 
     dvdplay_ctrl_t      control;
-    vlc_bool_t          b_click, b_move;
+    vlc_bool_t          b_click, b_move, b_key_pressed;
 };
 
 /*****************************************************************************
@@ -59,6 +61,8 @@ struct intf_sys_t
 static int  InitThread     ( intf_thread_t *p_intf );
 static int  MouseEvent     ( vlc_object_t *, char const *,
                              vlc_value_t, vlc_value_t, void * );
+static int  KeyEvent       ( vlc_object_t *, char const *,
+                             vlc_value_t, vlc_value_t, void * );
 
 /* Exported functions */
 static void RunIntf        ( intf_thread_t *p_intf );
@@ -78,7 +82,8 @@ int E_(OpenIntf) ( vlc_object_t *p_this )
     };
 
     p_intf->pf_run = RunIntf;
-
+    
+    var_AddCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
     p_intf->p_sys->m_still_time = 0;
     p_intf->p_sys->b_inf_still = 0;
     p_intf->p_sys->b_still = 0;
@@ -92,7 +97,7 @@ int E_(OpenIntf) ( vlc_object_t *p_this )
 void E_(CloseIntf) ( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
-
+    var_DelCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
     /* Destroy structure */
     free( p_intf->p_sys );
 }
@@ -209,6 +214,69 @@ static void RunIntf( intf_thread_t *p_intf )
             }
         }
 
+        /*
+         * keyboard event
+         */
+        if( p_intf->p_sys->b_key_pressed )
+        {
+            vlc_value_t val;
+            int i, i_activate, i_action = -1;
+            struct hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
+
+            p_intf->p_sys->b_key_pressed = VLC_FALSE;
+            
+            /* Find action triggered by hotkey (if any) */
+            var_Get( p_intf->p_vlc, "key-pressed", &val );
+            for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
+            {
+                if( p_hotkeys[i].i_key == val.i_int )
+                {
+                    i_action = p_hotkeys[i].i_action;
+                }
+            }
+
+            if( i_action )
+            {
+                if( i_action == ACTIONID_NAV_LEFT )
+                {
+                    p_intf->p_sys->control.type = DVDCtrlLeftButtonSelect;
+                }
+                else if( i_action == ACTIONID_NAV_RIGHT )
+                {
+                    p_intf->p_sys->control.type = DVDCtrlRightButtonSelect;
+                }
+                else if( i_action == ACTIONID_NAV_UP )
+                {
+                    p_intf->p_sys->control.type = DVDCtrlUpperButtonSelect;
+                }
+                else if( i_action == ACTIONID_NAV_DOWN )
+                {
+                    p_intf->p_sys->control.type = DVDCtrlLowerButtonSelect;
+                }
+                else if( i_action == ACTIONID_NAV_ACTIVATE )
+                {
+                    p_intf->p_sys->control.type = DVDCtrlButtonActivate;
+                }
+                /* we can safely interact with libdvdplay
+                 * with the stream lock */
+                vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
+                
+                i_activate = dvdplay_button( p_intf->p_sys->p_dvd->vmg,
+                                             &p_intf->p_sys->control );
+                
+                vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
+                
+                if( i_activate && p_intf->p_sys->b_still )
+                {
+                    input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
+                    p_intf->p_sys->b_still = 0;
+                    p_intf->p_sys->b_inf_still = 0;
+                    p_intf->p_sys->m_still_time = 0;
+                }
+            }
+        }
+                
+
         vlc_mutex_unlock( &p_intf->change_lock );
 
         /* 
@@ -252,15 +320,21 @@ static void RunIntf( intf_thread_t *p_intf )
  *****************************************************************************/
 static int InitThread( intf_thread_t * p_intf )
 {
-    /* we might need some locking here */
+    /* We might need some locking here */
     if( !p_intf->b_die )
     {
         input_thread_t * p_input;
         dvd_data_t * p_dvd;
 
         p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
-        p_dvd = (dvd_data_t*)p_input->p_access_data;
 
+        /* Maybe the input just died */
+        if( p_input == NULL )
+        {
+            return VLC_EGENERIC;
+        }
+
+        p_dvd = (dvd_data_t*)p_input->p_access_data;
         p_dvd->p_intf = p_intf;
 
         vlc_mutex_lock( &p_intf->change_lock );
@@ -270,14 +344,15 @@ static int InitThread( intf_thread_t * p_intf )
 
         p_intf->p_sys->b_move = VLC_FALSE;
         p_intf->p_sys->b_click = VLC_FALSE;
+        p_intf->p_sys->b_key_pressed = VLC_FALSE;
 
         vlc_mutex_unlock( &p_intf->change_lock );
 
-        return 0;
+        return VLC_SUCCESS;
     }
     else
     {
-        return -1;
+        return VLC_EGENERIC;
     }
 }
 
@@ -305,6 +380,22 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
     return VLC_SUCCESS;
 }
 
+/*****************************************************************************
+ * KeyEvent: callback for keyboard events
+ *****************************************************************************/
+static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
+                       vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    intf_thread_t *p_intf = (intf_thread_t *)p_data;
+    vlc_mutex_lock( &p_intf->change_lock );
+
+    p_intf->p_sys->b_key_pressed = VLC_TRUE;
+    
+    vlc_mutex_unlock( &p_intf->change_lock );
+
+    return VLC_SUCCESS;
+}
+
 /*****************************************************************************
  * dvdIntfStillTime: function provided to demux plugin to request
  * still images
@@ -330,7 +421,7 @@ int dvdIntfStillTime( intf_thread_t *p_intf, int i_sec )
         if( i_sec == 0xff )
         {
             p_intf->p_sys->m_still_time = (mtime_t)(-1);
-            msg_Warn( p_intf, "%lld", p_intf->p_sys->m_still_time );
+            msg_Warn( p_intf, I64Fd, p_intf->p_sys->m_still_time );
         }
         else
         {
@@ -343,3 +434,15 @@ int dvdIntfStillTime( intf_thread_t *p_intf, int i_sec )
     return VLC_SUCCESS;
 }
 
+/*****************************************************************************
+ * dvdIntfStillTime: function provided to reset still image
+ *****************************************************************************/
+int dvdIntfResetStillTime( intf_thread_t *p_intf )
+{
+    vlc_mutex_lock( &p_intf->change_lock );
+    p_intf->p_sys->m_still_time = 0;
+    input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
+    vlc_mutex_unlock( &p_intf->change_lock );
+
+    return VLC_SUCCESS;
+}