]> git.sesse.net Git - vlc/blobdiff - modules/control/rc.c
vlc_plugin: fix non-LGPL plugins meta infos
[vlc] / modules / control / rc.c
index b36f3c74371ec265503141aaa082fadc9288a6c9..bd3417a199ba998098dabeb4d77ca9272fb4cb07 100644 (file)
 # include "config.h"
 #endif
 
-#include <vlc_common.h>
-#include <vlc_plugin.h>
-
 #include <errno.h>                                                 /* ENOMEM */
 #include <signal.h>
 #include <assert.h>
 #include <math.h>
 
+#define VLC_MODULE_LICENSE VLC_LICENSE_GPL_2_PLUS
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_interface.h>
+#include <vlc_input.h>
 #include <vlc_aout.h>
 #include <vlc_vout.h>
 #include <vlc_playlist.h>
 #include <vlc_keys.h>
 
-#ifdef HAVE_UNISTD_H
-#    include <unistd.h>
-#endif
 #include <sys/types.h>
+#include <unistd.h>
+
 
 #include <vlc_network.h>
 #include <vlc_url.h>
-
 #include <vlc_charset.h>
 
 #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 <sys/un.h>
 #endif
 
@@ -82,7 +81,7 @@ static int  Activate     ( vlc_object_t * );
 static void Deactivate   ( vlc_object_t * );
 static void *Run         ( void * );
 
-static void Help         ( intf_thread_t *, bool );
+static void Help         ( intf_thread_t * );
 static void RegisterCallbacks( intf_thread_t * );
 
 static bool ReadCommand( intf_thread_t *, char *, int * );
@@ -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();
@@ -361,6 +366,7 @@ static void Deactivate( vlc_object_t *p_this )
     intf_thread_t *p_intf = (intf_thread_t*)p_this;
     intf_sys_t *p_sys = p_intf->p_sys;
 
+    vlc_cancel( p_sys->thread );
     var_DelCallback( p_sys->p_playlist, "volume", VolumeChanged, p_intf );
     vlc_join( p_sys->thread, NULL );
 
@@ -375,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 );
@@ -464,21 +470,21 @@ static void *Run( void *data )
 
     char p_buffer[ MAX_LINE_LENGTH + 1 ];
     bool b_showpos = var_InheritBool( p_intf, "rc-show-pos" );
-    bool b_longhelp = false;
 
     int  i_size = 0;
     int  i_oldpos = 0;
     int  i_newpos;
+    int  canc = vlc_savecancel( );
 
     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
 
@@ -492,6 +498,8 @@ static void *Run( void *data )
         char *psz_cmd, *psz_arg;
         bool b_complete;
 
+        vlc_restorecancel( canc );
+
         if( p_sys->pi_socket_listen != NULL && p_sys->i_socket == -1 )
         {
             p_sys->i_socket =
@@ -500,6 +508,7 @@ static void *Run( void *data )
         }
 
         b_complete = ReadCommand( p_intf, p_buffer, &i_size );
+        canc = vlc_savecancel( );
 
         /* Manage the input part */
         if( p_sys->p_input == NULL )
@@ -590,37 +599,8 @@ static void *Run( void *data )
             psz_arg = (char*)"";
         }
 
-        /* module specfic commands: @<module name> <command> <args...> */
-        if( *psz_cmd == '@' && *psz_arg )
-        {
-            /* Parse miscellaneous commands */
-            char *psz_alias = psz_cmd + 1;
-            char *psz_mycmd = strdup( psz_arg );
-            char *psz_myarg = strchr( psz_mycmd, ' ' );
-            char *psz_msg;
-
-            if( !psz_myarg )
-            {
-                msg_rc( "Not enough parameters." );
-            }
-            else
-            {
-                *psz_myarg = '\0';
-                psz_myarg ++;
-
-                var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
-                             &psz_msg );
-
-                if( psz_msg )
-                {
-                    msg_rc( "%s", psz_msg );
-                    free( psz_msg );
-                }
-            }
-            free( psz_mycmd );
-        }
         /* If the user typed a registered local command, try it */
-        else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
+        if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
         {
             vlc_value_t val;
             int i_ret;
@@ -741,11 +721,7 @@ static void *Run( void *data )
         else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
                  || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
         {
-            if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
-                 b_longhelp = true;
-            else b_longhelp = false;
-
-            Help( p_intf, b_longhelp );
+            Help( p_intf );
         }
         else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
         {
@@ -766,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 )
@@ -798,10 +774,12 @@ static void *Run( void *data )
     msg_rc( STATUS_CHANGE "( stop state: 0 )" );
     msg_rc( STATUS_CHANGE "( quit )" );
 
+    vlc_restorecancel( canc );
+
     return NULL;
 }
 
-static void Help( intf_thread_t *p_intf, bool b_longhelp)
+static void Help( intf_thread_t *p_intf)
 {
     msg_rc("%s", _("+----[ Remote control commands ]"));
     msg_rc(  "| ");
@@ -854,44 +832,8 @@ static void Help( intf_thread_t *p_intf, bool b_longhelp)
     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(  "| ");
-
-    if (b_longhelp)
-    {
-        msg_rc("%s", _("| @name marq-marquee  STRING  . . overlay STRING in video"));
-        msg_rc("%s", _("| @name marq-x X . . . . . . . . . . . .offset from left"));
-        msg_rc("%s", _("| @name marq-y Y . . . . . . . . . . . . offset from top"));
-        msg_rc("%s", _("| @name marq-position #. . .  .relative position control"));
-        msg_rc("%s", _("| @name marq-color # . . . . . . . . . . font color, RGB"));
-        msg_rc("%s", _("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
-        msg_rc("%s", _("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
-        msg_rc("%s", _("| @name marq-size # . . . . . . . . font size, in pixels"));
-        msg_rc(  "| ");
-        msg_rc("%s", _("| @name logo-file STRING . . .the overlay file path/name"));
-        msg_rc("%s", _("| @name logo-x X . . . . . . . . . . . .offset from left"));
-        msg_rc("%s", _("| @name logo-y Y . . . . . . . . . . . . offset from top"));
-        msg_rc("%s", _("| @name logo-position #. . . . . . . . relative position"));
-        msg_rc("%s", _("| @name logo-transparency #. . . . . . . . .transparency"));
-        msg_rc(  "| ");
-        msg_rc("%s", _("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
-        msg_rc("%s", _("| @name mosaic-height #. . . . . . . . . . . . . .height"));
-        msg_rc("%s", _("| @name mosaic-width # . . . . . . . . . . . . . . width"));
-        msg_rc("%s", _("| @name mosaic-xoffset # . . . .top left corner position"));
-        msg_rc("%s", _("| @name mosaic-yoffset # . . . .top left corner position"));
-        msg_rc("%s", _("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
-        msg_rc("%s", _("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
-        msg_rc("%s", _("| @name mosaic-vborder # . . . . . . . . vertical border"));
-        msg_rc("%s", _("| @name mosaic-hborder # . . . . . . . horizontal border"));
-        msg_rc("%s", _("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
-        msg_rc("%s", _("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
-        msg_rc("%s", _("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
-        msg_rc("%s", _("| @name mosaic-order id(,id)* . . . . order of pictures "));
-        msg_rc("%s", _("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
-        msg_rc(  "| ");
-    }
     msg_rc("%s", _("| help . . . . . . . . . . . . . . . this help message"));
-    msg_rc("%s", _("| longhelp . . . . . . . . . . . a longer help message"));
     msg_rc("%s", _("| logout . . . . . . .  exit (if in socket connection)"));
     msg_rc("%s", _("| quit . . . . . . . . . . . . . . . . . . .  quit vlc"));
     msg_rc(  "| ");
@@ -1022,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" ) )
@@ -1187,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 );
@@ -1248,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;
         }
     }
@@ -1479,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,
@@ -1502,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;
         }
     }
@@ -1546,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;
     }
 
@@ -1599,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 )
     {
@@ -1643,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 );
@@ -1748,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;
@@ -1850,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,
@@ -1912,6 +1855,8 @@ static bool ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
         }
     }
 
+    vlc_testcancel ();
+
     return false;
 }
 #endif
@@ -1920,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 )