X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcontrol%2Frc.c;h=bd3417a199ba998098dabeb4d77ca9272fb4cb07;hb=56220f86120b3d7b7d8c7b2957befede19f669b6;hp=e8ede5f2442028c7891afe73425103e3a63a587d;hpb=548a2f6933073b9f08b6634a9adbaf1ffb700d4e;p=vlc diff --git a/modules/control/rc.c b/modules/control/rc.c index e8ede5f244..bd3417a199 100644 --- a/modules/control/rc.c +++ b/modules/control/rc.c @@ -30,35 +30,34 @@ # include "config.h" #endif -#include -#include - #include /* ENOMEM */ #include #include #include +#define VLC_MODULE_LICENSE VLC_LICENSE_GPL_2_PLUS +#include +#include #include +#include #include #include #include #include -#ifdef HAVE_UNISTD_H -# include -#endif #include +#include + #include #include - #include #if defined(PF_UNIX) && !defined(PF_LOCAL) # define PF_LOCAL PF_UNIX #endif -#if defined(AF_LOCAL) && ! defined(WIN32) +#if defined(AF_LOCAL) && ! defined(_WIN32) # include #endif @@ -132,7 +131,7 @@ struct intf_sys_t input_thread_t *p_input; bool b_input_buffering; -#ifdef WIN32 +#ifdef _WIN32 HANDLE hConsoleIn; bool b_quiet; #endif @@ -173,13 +172,14 @@ static void msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... ) #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \ "You can set the address and port the interface will bind to." ) -#ifdef WIN32 +#ifdef _WIN32 #define QUIET_TEXT N_("Do not open a DOS command box interface") #define QUIET_LONGTEXT N_( \ "By default the rc interface plugin will start a DOS command box. " \ "Enabling the quiet mode will not bring this command box but can also " \ "be pretty annoying when you want to stop VLC and no video window is " \ "open." ) +#include "intromsg.h" #endif vlc_module_begin () @@ -189,7 +189,7 @@ vlc_module_begin () set_description( N_("Remote control interface") ) add_bool( "rc-show-pos", false, POS_TEXT, POS_LONGTEXT, true ) -#ifdef WIN32 +#ifdef _WIN32 add_bool( "rc-quiet", false, QUIET_TEXT, QUIET_LONGTEXT, false ) #else #if defined (HAVE_ISATTY) @@ -202,7 +202,7 @@ vlc_module_begin () set_capability( "interface", 20 ) set_callbacks( Activate, Deactivate ) -#ifdef WIN32 +#ifdef _WIN32 add_shortcut( "rc" ) #endif vlc_module_end () @@ -218,7 +218,7 @@ static int Activate( vlc_object_t *p_this ) char *psz_host, *psz_unix_path = NULL; int *pi_socket = NULL; -#ifndef WIN32 +#ifndef _WIN32 #if defined(HAVE_ISATTY) /* Check that stdin is a TTY */ if( !var_InheritBool( p_intf, "rc-fake-tty" ) && !isatty( 0 ) ) @@ -246,7 +246,7 @@ static int Activate( vlc_object_t *p_this ) if( (i_socket = vlc_socket( PF_LOCAL, SOCK_STREAM, 0, false ) ) < 0 ) { - msg_Warn( p_intf, "can't open socket: %m" ); + msg_Warn( p_intf, "can't open socket: %s", vlc_strerror_c(errno) ); free( psz_unix_path ); return VLC_EGENERIC; } @@ -265,8 +265,8 @@ static int Activate( vlc_object_t *p_this ) if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))) { - msg_Err (p_intf, "cannot bind UNIX socket at %s: %m", - psz_unix_path); + msg_Err (p_intf, "cannot bind UNIX socket at %s: %s", + psz_unix_path, vlc_strerror_c(errno)); free (psz_unix_path); net_Close (i_socket); return VLC_EGENERIC; @@ -275,7 +275,8 @@ static int Activate( vlc_object_t *p_this ) if( listen( i_socket, 1 ) ) { - msg_Warn( p_intf, "can't listen on socket: %m"); + msg_Warn (p_intf, "can't listen on socket: %s", + vlc_strerror_c(errno)); free( psz_unix_path ); net_Close( i_socket ); return VLC_EGENERIC; @@ -293,7 +294,7 @@ static int Activate( vlc_object_t *p_this ) pi_socket[1] = -1; #endif /* AF_LOCAL */ } -#endif /* !WIN32 */ +#endif /* !_WIN32 */ if( ( pi_socket == NULL ) && ( psz_host = var_InheritString( p_intf, "rc-host" ) ) != NULL ) @@ -320,7 +321,11 @@ static int Activate( vlc_object_t *p_this ) intf_sys_t *p_sys = malloc( sizeof( *p_sys ) ); if( unlikely(p_sys == NULL) ) + { + net_ListenClose( pi_socket ); + free( psz_unix_path ); return VLC_ENOMEM; + } p_intf->p_sys = p_sys; p_sys->pi_socket_listen = pi_socket; @@ -335,13 +340,13 @@ static int Activate( vlc_object_t *p_this ) /* Non-buffered stdout */ setvbuf( stdout, (char *)NULL, _IOLBF, 0 ); -#ifdef WIN32 +#ifdef _WIN32 p_sys->b_quiet = var_InheritBool( p_intf, "rc-quiet" ); +# if !VLC_WINSTORE_APP if( !p_sys->b_quiet ) + intf_consoleIntroMsg( p_intf ); +# endif #endif - { - CONSOLE_INTRO_MSG; - } if( vlc_clone( &p_sys->thread, Run, p_intf, VLC_THREAD_PRIORITY_LOW ) ) abort(); @@ -376,7 +381,7 @@ static void Deactivate( vlc_object_t *p_this ) net_Close( p_sys->i_socket ); if( p_sys->psz_unix_path != NULL ) { -#if defined(AF_LOCAL) && !defined(WIN32) +#if defined(AF_LOCAL) && !defined(_WIN32) unlink( p_sys->psz_unix_path ); #endif free( p_sys->psz_unix_path ); @@ -473,13 +478,13 @@ static void *Run( void *data ) p_buffer[0] = 0; -#ifdef WIN32 +#ifdef _WIN32 /* Get the file descriptor of the console input */ p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE); if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE ) { msg_Err( p_intf, "couldn't find user input handle" ); - return; + return NULL; } #endif @@ -737,7 +742,7 @@ static void *Run( void *data ) else fs = var_ToggleBool( p_sys->p_playlist, "fullscreen" ); - if( p_sys->p_input == NULL ) + if( p_sys->p_input != NULL ) { vout_thread_t *p_vout = input_GetVout( p_sys->p_input ); if( p_vout ) @@ -827,7 +832,6 @@ static void Help( intf_thread_t *p_intf) msg_rc("%s", _("| snapshot . . . . . . . . . . . . take video snapshot")); msg_rc("%s", _("| strack [X] . . . . . . . . . set/get subtitle track")); msg_rc("%s", _("| key [hotkey name] . . . . . . simulate hotkey press")); - msg_rc("%s", _("| menu . . [on|off|up|down|left|right|select] use menu")); msg_rc( "| "); msg_rc("%s", _("| help . . . . . . . . . . . . . . . this help message")); msg_rc("%s", _("| logout . . . . . . . exit (if in socket connection)")); @@ -960,13 +964,13 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd, if( ( state == PAUSE_S ) && ( strcmp( psz_cmd, "pause" ) != 0 ) && (strcmp( psz_cmd,"frame") != 0 ) ) { - msg_rc( "%s", _("Press menu select or pause to continue.") ); + msg_rc( "%s", _("Press pause to continue.") ); } else /* Parse commands that only require an input */ if( !strcmp( psz_cmd, "pause" ) ) { - playlist_Pause( p_intf->p_sys->p_playlist ); + playlist_TogglePause( p_intf->p_sys->p_playlist ); i_error = VLC_SUCCESS; } else if( !strcmp( psz_cmd, "seek" ) ) @@ -1125,7 +1129,7 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd, i_value = val.i_int; if ( var_Change( p_input, psz_variable, - VLC_VAR_GETLIST, &val, &text ) < 0 ) + VLC_VAR_GETCHOICES, &val, &text ) < 0 ) goto out; msg_rc( "+----[ %s ]", val_name.psz_string ); @@ -1186,7 +1190,7 @@ static int Playlist( vlc_object_t *p_this, char const *psz_cmd, if( state == PAUSE_S ) { - msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") ); + msg_rc( "%s", _("Type 'pause' to continue.") ); return VLC_EGENERIC; } } @@ -1417,9 +1421,10 @@ static int Quit( vlc_object_t *p_this, char const *psz_cmd, static int Intf( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { - VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data); + intf_thread_t *intf = (intf_thread_t *)p_this; - return intf_Create( p_this->p_libvlc, newval.psz_string ); + VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data); + return intf_Create(pl_Get(intf), newval.psz_string ); } static int Volume( vlc_object_t *p_this, char const *psz_cmd, @@ -1440,7 +1445,7 @@ static int Volume( vlc_object_t *p_this, char const *psz_cmd, vlc_object_release( p_input ); if( state == PAUSE_S ) { - msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") ); + msg_rc( "%s", _("Type 'pause' to continue.") ); return VLC_EGENERIC; } } @@ -1484,7 +1489,7 @@ static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd, vlc_object_release( p_input ); if( state == PAUSE_S ) { - msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") ); + msg_rc( "%s", _("Type 'pause' to continue.") ); return VLC_EGENERIC; } @@ -1537,7 +1542,7 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd, } else /* This case can't happen */ - assert( 0 ); + vlc_assert_unreachable(); if( newval.psz_string && *newval.psz_string ) { @@ -1581,7 +1586,7 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd, } if ( var_Change( p_vout, psz_variable, - VLC_VAR_GETLIST, &val, &text ) < 0 ) + VLC_VAR_GETCHOICES, &val, &text ) < 0 ) { vlc_object_release( p_vout ); free( psz_value ); @@ -1686,7 +1691,7 @@ static int AudioChannel( vlc_object_t *obj, char const *cmd, /* Retrieve all registered ***. */ vlc_value_t val, text; if ( var_Change( p_aout, "stereo-mode", - VLC_VAR_GETLIST, &val, &text ) < 0 ) + VLC_VAR_GETCHOICES, &val, &text ) < 0 ) { ret = VLC_ENOVAR; goto out; @@ -1788,15 +1793,15 @@ static int updateStatistics( intf_thread_t *p_intf, input_item_t *p_item ) return VLC_SUCCESS; } -#ifdef WIN32 +#ifdef _WIN32 static bool ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size ) { INPUT_RECORD input_record; DWORD i_dw; /* On Win32, select() only works on socket descriptors */ - while( WaitForSingleObject( p_intf->p_sys->hConsoleIn, - INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 ) + while( WaitForSingleObjectEx( p_intf->p_sys->hConsoleIn, + INTF_IDLE_SLEEP/1000, TRUE ) == WAIT_OBJECT_0 ) { while( *pi_size < MAX_LINE_LENGTH && ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record, @@ -1850,6 +1855,8 @@ static bool ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size ) } } + vlc_testcancel (); + return false; } #endif @@ -1858,7 +1865,7 @@ bool ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size ) { int i_read = 0; -#ifdef WIN32 +#ifdef _WIN32 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet ) return ReadWin32( p_intf, p_buffer, pi_size ); else if( p_intf->p_sys->i_socket == -1 )