]> git.sesse.net Git - vlc/blobdiff - modules/control/rc/rc.c
* include/configuration.h: added a new flag to the configuration stucture to
[vlc] / modules / control / rc / rc.c
index a66c8c8871bb5976e1cc42a9714c38b272663baa..814dfd6d3601e829dfd3a05b56b67088431971a7 100644 (file)
@@ -2,7 +2,7 @@
  * rc.c : remote control stdin/stdout plugin for vlc
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: rc.c,v 1.22 2003/01/23 09:53:55 gbazin Exp $
+ * $Id: rc.c,v 1.27 2003/02/20 01:52:46 sigmunau Exp $
  *
  * Authors: Peter Surda <shurdeek@panorama.sth.ac.at>
  *
 #endif
 #include <sys/types.h>
 
-#if defined( WIN32 )
-#include <winsock2.h>                                            /* select() */
-#endif
-
 #include "error.h"
 
 #define MAX_LINE_LENGTH 256
@@ -85,10 +81,10 @@ static int  AudioConfig  ( vlc_object_t *, char const *,
 #define TTY_LONGTEXT N_("Force the rc plugin to use stdin as if it was a TTY.")
 
 vlc_module_begin();
-    add_category_hint( N_("Remote control"), NULL );
-    add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT );
+    add_category_hint( N_("Remote control"), NULL, VLC_TRUE );
+    add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
 #ifdef HAVE_ISATTY
-    add_bool( "fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT );
+    add_bool( "fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
 #endif
     set_description( _("remote control interface module") );
     set_capability( "interface", 20 );
@@ -147,6 +143,12 @@ static void Run( intf_thread_t *p_intf )
     p_input = NULL;
     p_playlist = NULL;
 
+#ifdef WIN32
+    HANDLE hConsoleIn;
+    INPUT_RECORD input_record;
+    DWORD i_dummy2;
+#endif
+
     /* Register commands that will be cleaned up upon object destruction */
     var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
     var_AddCallback( p_intf, "quit", Quit, NULL );
@@ -196,10 +198,11 @@ static void Run( intf_thread_t *p_intf )
 
 #ifdef WIN32
     /* Get the file descriptor of the console input */
-    i_dummy = _open( "CONIN$", 0 );
-    if( i_dummy == -1 )
+    hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
+    if( hConsoleIn == INVALID_HANDLE_VALUE )
     {
-        msg_Err( p_intf, "Couldn't open CONIN$" ); 
+        msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" ); 
+        p_intf->b_die = VLC_TRUE;
     }
 #endif
 
@@ -208,33 +211,52 @@ static void Run( intf_thread_t *p_intf )
         vlc_bool_t     b_complete = VLC_FALSE;
 
 #ifndef WIN32
-        /* On Win32, select() only works on socket descriptors */
-
         fd_set         fds;
         struct timeval tv;
 
         /* Check stdin */
         tv.tv_sec = 0;
-        tv.tv_usec = 50000;
+        tv.tv_usec = (long)INTF_IDLE_SLEEP;
         FD_ZERO( &fds );
-        FD_SET( descr_stdin, &fds );
+        FD_SET( STDIN_FILENO, &fds );
 
         i_dummy = select( STDIN_FILENO + 1, &fds, NULL, NULL, &tv );
-        if( i_dummy > 0 )
+#else
+        /* On Win32, select() only works on socket descriptors */
+        i_dummy = ( WaitForSingleObject( hConsoleIn, INTF_IDLE_SLEEP/1000 )
+                    == WAIT_OBJECT_0 );
 #endif
+        if( i_dummy > 0 )
         {
             int i_size = 0;
 
             while( !p_intf->b_die
                     && i_size < MAX_LINE_LENGTH
-#ifdef WIN32
-                    && read( i_dummy, p_buffer + i_size, 1 ) > 0
-#else
+#ifndef WIN32
                     && read( STDIN_FILENO, p_buffer + i_size, 1 ) > 0
+#else
+                    && ReadConsoleInput( hConsoleIn, &input_record, 1,
+                                         &i_dummy2 )
 #endif
-                    && p_buffer[ i_size ] != '\r'
-                    && p_buffer[ i_size ] != '\n' )
+                   )
             {
+#ifdef WIN32
+                if( input_record.EventType != KEY_EVENT ||
+                    !input_record.Event.KeyEvent.bKeyDown )
+                {
+                    /* nothing interesting */
+                    continue;
+                }
+
+                p_buffer[ i_size ] =
+                    input_record.Event.KeyEvent.uChar.AsciiChar;
+#endif
+
+                if( p_buffer[ i_size ] == '\r' || p_buffer[ i_size ] == '\n' )
+                {
+                    break;
+                }
+
                 i_size++;
             }
 
@@ -662,16 +684,8 @@ static int Intf( vlc_object_t *p_this, char const *psz_cmd,
                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
     intf_thread_t *p_newintf;
-    char *psz_oldmodule = config_GetPsz( p_this->p_vlc, "intf" );
-
-    config_PutPsz( p_this->p_vlc, "intf", newval.psz_string );
-    p_newintf = intf_Create( p_this->p_vlc );
-    config_PutPsz( p_this->p_vlc, "intf", psz_oldmodule );
 
-    if( psz_oldmodule )
-    {
-        free( psz_oldmodule );
-    }
+    p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
 
     if( p_newintf )
     {
@@ -689,10 +703,7 @@ static int Intf( vlc_object_t *p_this, char const *psz_cmd,
 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
                    vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
-    aout_instance_t * p_aout;
     int i_error;
-    p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
-    if ( p_aout == NULL ) return VLC_ENOOBJ;
 
     if ( *newval.psz_string )
     {
@@ -704,13 +715,13 @@ static int Volume( vlc_object_t *p_this, char const *psz_cmd,
                     AOUT_VOLUME_MAX );
             i_error = VLC_EBADVAR;
         }
-        else i_error = aout_VolumeSet( p_aout, i_volume );
+        else i_error = aout_VolumeSet( p_this, i_volume );
     }
     else
     {
         /* Get. */
         audio_volume_t i_volume;
-        if ( aout_VolumeGet( p_aout, &i_volume ) < 0 )
+        if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
         {
             i_error = VLC_EGENERIC;
         }
@@ -720,7 +731,6 @@ static int Volume( vlc_object_t *p_this, char const *psz_cmd,
             i_error = VLC_SUCCESS;
         }
     }
-    vlc_object_release( (vlc_object_t *)p_aout );
 
     return i_error;
 }
@@ -728,7 +738,6 @@ static int Volume( vlc_object_t *p_this, char const *psz_cmd,
 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
-    aout_instance_t * p_aout;
     audio_volume_t i_volume;
     int i_nb_steps = atoi(newval.psz_string);
     int i_error = VLC_SUCCESS;
@@ -738,20 +747,16 @@ static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
         i_nb_steps = 1;
     }
 
-    p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
-    if ( p_aout == NULL ) return VLC_ENOOBJ;
-
     if ( !strcmp(psz_cmd, "volup") )
     {
-        if ( aout_VolumeUp( p_aout, i_nb_steps, &i_volume ) < 0 )
+        if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
             i_error = VLC_EGENERIC;
     }
     else
     {
-        if ( aout_VolumeDown( p_aout, i_nb_steps, &i_volume ) < 0 )
+        if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
             i_error = VLC_EGENERIC;
     }
-    vlc_object_release( (vlc_object_t *)p_aout );
 
     if ( !i_error ) printf( "Volume is %d\n", i_volume );
     return i_error;