]> git.sesse.net Git - vlc/blob - modules/control/rc.c
Force RC interface in standard playlist mode
[vlc] / modules / control / rc.c
1 /*****************************************************************************
2  * rc.c : remote control stdin/stdout module for vlc
3  *****************************************************************************
4  * Copyright (C) 2004 VideoLAN
5  * $Id$
6  *
7  * Author: Peter Surda <shurdeek@panorama.sth.ac.at>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>
29
30 #include <errno.h>                                                 /* ENOMEM */
31 #include <stdio.h>
32 #include <ctype.h>
33 #include <signal.h>
34
35 #include <vlc/vlc.h>
36 #include <vlc/intf.h>
37 #include <vlc/aout.h>
38 #include <vlc/vout.h>
39
40 #ifdef HAVE_UNISTD_H
41 #    include <unistd.h>
42 #endif
43
44 #ifdef HAVE_SYS_TIME_H
45 #    include <sys/time.h>
46 #endif
47 #include <sys/types.h>
48
49 #include "vlc_error.h"
50 #include "network.h"
51
52 #if defined(PF_UNIX) && !defined(PF_LOCAL)
53 #    define PF_LOCAL PF_UNIX
54 #endif
55 #if defined(AF_UNIX) && !defined(AF_LOCAL)
56 #    define AF_LOCAL AF_UNIX
57 #endif
58
59 #ifdef PF_LOCAL
60 #    include <sys/un.h>
61 #endif
62
63 #define MAX_LINE_LENGTH 256
64
65 /*****************************************************************************
66  * Local prototypes
67  *****************************************************************************/
68 static int  Activate     ( vlc_object_t * );
69 static void Deactivate   ( vlc_object_t * );
70 static void Run          ( intf_thread_t * );
71
72 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
73
74 static playlist_item_t *parse_MRL( intf_thread_t *, char * );
75
76 static int  Input        ( vlc_object_t *, char const *,
77                            vlc_value_t, vlc_value_t, void * );
78 static int  Playlist     ( vlc_object_t *, char const *,
79                            vlc_value_t, vlc_value_t, void * );
80 static int  Other        ( vlc_object_t *, char const *,
81                            vlc_value_t, vlc_value_t, void * );
82 static int  Quit         ( vlc_object_t *, char const *,
83                            vlc_value_t, vlc_value_t, void * );
84 static int  Intf         ( vlc_object_t *, char const *,
85                            vlc_value_t, vlc_value_t, void * );
86 static int  Volume       ( vlc_object_t *, char const *,
87                            vlc_value_t, vlc_value_t, void * );
88 static int  VolumeMove   ( vlc_object_t *, char const *,
89                            vlc_value_t, vlc_value_t, void * );
90 static int  AudioConfig  ( vlc_object_t *, char const *,
91                            vlc_value_t, vlc_value_t, void * );
92
93 struct intf_sys_t
94 {
95     int i_socket_listen;
96     int i_socket;
97     char *psz_unix_path;
98     vlc_bool_t b_extend;
99
100 #ifdef WIN32
101     HANDLE hConsoleIn;
102     vlc_bool_t b_quiet;
103 #endif
104 };
105
106 #ifdef HAVE_VARIADIC_MACROS
107 #   define msg_rc( psz_format, args... ) \
108       __msg_rc( p_intf, psz_format, ## args )
109 #endif
110
111 void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
112 {
113     va_list args;
114     va_start( args, psz_fmt );
115     if( p_intf->p_sys->i_socket == -1 ) vprintf( psz_fmt, args );
116     else
117     { net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
118       net_Printf( VLC_OBJECT(p_intf), p_intf->p_sys->i_socket, NULL, "\r" ); }
119     va_end( args );
120 }
121
122 /*****************************************************************************
123  * Module descriptor
124  *****************************************************************************/
125 #define POS_TEXT N_("Show stream position")
126 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
127                         "stream from time to time." )
128
129 #define TTY_TEXT N_("Fake TTY")
130 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
131
132 #define UNIX_TEXT N_("UNIX socket command input")
133 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
134                          "stdin." )
135
136 #define HOST_TEXT N_("TCP command input")
137 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
138             "You can set the address and port the interface will bind to." )
139 #define EXTEND_TEXT N_("Extended help")
140 #define EXTEND_LONGTEXT N_("List additional commands.")
141
142 #ifdef WIN32
143 #define QUIET_TEXT N_("Do not open a DOS command box interface")
144 #define QUIET_LONGTEXT N_( \
145     "By default the rc interface plugin will start a DOS command box. " \
146     "Enabling the quiet mode will not bring this command box but can also " \
147     "be pretty annoying when you want to stop VLC and no video window is " \
148     "open." )
149 #endif
150
151 vlc_module_begin();
152     set_category( CAT_INTERFACE );
153     set_subcategory( SUBCAT_INTERFACE_GENERAL );
154     set_description( _("Remote control interface") );
155     add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
156 #ifdef HAVE_ISATTY
157     add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
158 #endif
159     add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
160     add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
161
162 #ifdef WIN32
163     add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
164 #endif
165     add_bool( "rc-extend", 0, NULL, EXTEND_TEXT, EXTEND_LONGTEXT, VLC_FALSE );
166
167     set_capability( "interface", 20 );
168     set_callbacks( Activate, Deactivate );
169 vlc_module_end();
170
171 /*****************************************************************************
172  * Activate: initialize and create stuff
173  *****************************************************************************/
174 static int Activate( vlc_object_t *p_this )
175 {
176     intf_thread_t *p_intf = (intf_thread_t*)p_this;
177     playlist_t *p_playlist;
178     char *psz_host, *psz_unix_path;
179     int i_socket = -1;
180
181 #if defined(HAVE_ISATTY) && !defined(WIN32)
182     /* Check that stdin is a TTY */
183     if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
184     {
185         msg_Warn( p_intf, "fd 0 is not a TTY" );
186         return VLC_EGENERIC;
187     }
188 #endif
189
190     psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
191     if( psz_unix_path )
192     {
193 #ifndef PF_LOCAL
194         msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
195         free( psz_unix_path );
196         return VLC_EGENERIC;
197 #else
198         struct sockaddr_un addr;
199         int i_ret;
200
201         memset( &addr, 0, sizeof(struct sockaddr_un) );
202
203         msg_Dbg( p_intf, "trying UNIX socket" );
204
205         if( (i_socket = socket( PF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
206         {
207             msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
208             free( psz_unix_path );
209             return VLC_EGENERIC;
210         }
211
212         addr.sun_family = AF_LOCAL;
213         strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
214         addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
215
216         if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
217                            sizeof(struct sockaddr_un) ) ) < 0 )
218         {
219             msg_Warn( p_intf, "couldn't bind socket to address: %s",
220                       strerror(errno) );
221             free( psz_unix_path );
222             net_Close( i_socket );
223             return VLC_EGENERIC;
224         }
225
226         if( ( i_ret = listen( i_socket, 1 ) ) < 0 )
227         {
228             msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
229             free( psz_unix_path );
230             net_Close( i_socket );
231             return VLC_EGENERIC;
232         }
233 #endif
234     }
235
236     if( ( i_socket == -1) &&
237         ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
238     {
239         vlc_url_t url;
240
241         vlc_UrlParse( &url, psz_host, 0 );
242
243         msg_Dbg( p_intf, "base %s port %d", url.psz_host, url.i_port );
244
245         if( (i_socket = net_ListenTCP(p_this, url.psz_host, url.i_port)) == -1)
246         {
247             msg_Warn( p_intf, "can't listen to %s port %i",
248                       url.psz_host, url.i_port );
249             vlc_UrlClean( &url );
250             free( psz_host );
251             return VLC_EGENERIC;
252         }
253
254         vlc_UrlClean( &url );
255         free( psz_host );
256     }
257
258     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
259     if( !p_intf->p_sys )
260     {
261         msg_Err( p_intf, "no memory" );
262         return VLC_ENOMEM;
263     }
264
265     p_intf->p_sys->i_socket_listen = i_socket;
266     p_intf->p_sys->i_socket = -1;
267     p_intf->p_sys->psz_unix_path = psz_unix_path;
268
269     /* Non-buffered stdout */
270     setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
271
272     p_intf->pf_run = Run;
273
274 #ifdef WIN32
275     p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
276     if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
277 #else
278     CONSOLE_INTRO_MSG;
279 #endif
280
281     /* Force "no-view" mode */
282     p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
283                                                  FIND_ANYWHERE );
284     if( p_playlist )
285     {
286         vlc_mutex_lock( &p_playlist->object_lock );
287         p_playlist->status.i_view = -1;
288         vlc_mutex_unlock( &p_playlist->object_lock );
289         vlc_object_release( p_playlist );
290     }
291
292     msg_rc( _("Remote control interface initialized, `h' for help\n") );
293     return VLC_SUCCESS;
294 }
295
296 /*****************************************************************************
297  * Deactivate: uninitialize and cleanup
298  *****************************************************************************/
299 static void Deactivate( vlc_object_t *p_this )
300 {
301     intf_thread_t *p_intf = (intf_thread_t*)p_this;
302
303     if( p_intf->p_sys->i_socket_listen != -1 )
304         net_Close( p_intf->p_sys->i_socket_listen );
305     if( p_intf->p_sys->i_socket != -1 )
306         net_Close( p_intf->p_sys->i_socket );
307     if( p_intf->p_sys->psz_unix_path != NULL )
308     {
309 #ifdef PF_LOCAL
310         unlink( p_intf->p_sys->psz_unix_path );
311 #endif
312         free( p_intf->p_sys->psz_unix_path );
313     }
314     free( p_intf->p_sys );
315 }
316
317 /*****************************************************************************
318  * Run: rc thread
319  *****************************************************************************
320  * This part of the interface is in a separate thread so that we can call
321  * exec() from within it without annoying the rest of the program.
322  *****************************************************************************/
323 static void Run( intf_thread_t *p_intf )
324 {
325     input_thread_t * p_input;
326     playlist_t *     p_playlist;
327
328     char       p_buffer[ MAX_LINE_LENGTH + 1 ];
329     vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
330
331     int        i_size = 0;
332     int        i_oldpos = 0;
333     int        i_newpos;
334
335     p_buffer[0] = 0;
336     p_input = NULL;
337     p_playlist = NULL;
338  
339     p_intf->p_sys->b_extend = config_GetInt( p_intf, "rc-extend" );
340     /* Register commands that will be cleaned up upon object destruction */
341     var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
342     var_AddCallback( p_intf, "quit", Quit, NULL );
343     var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
344     var_AddCallback( p_intf, "intf", Intf, NULL );
345
346     var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
347     var_AddCallback( p_intf, "add", Playlist, NULL );
348     var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
349     var_AddCallback( p_intf, "playlist", Playlist, NULL );
350     var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
351     var_AddCallback( p_intf, "play", Playlist, NULL );
352     var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
353     var_AddCallback( p_intf, "stop", Playlist, NULL );
354     var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
355     var_AddCallback( p_intf, "prev", Playlist, NULL );
356     var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
357     var_AddCallback( p_intf, "next", Playlist, NULL );
358   
359     var_Create( p_intf, "marq-marquee", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
360     var_AddCallback( p_intf, "marq-marquee", Other, NULL );
361     var_Create( p_intf, "marq-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
362     var_AddCallback( p_intf, "marq-x", Other, NULL );
363     var_Create( p_intf, "marq-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
364     var_AddCallback( p_intf, "marq-y", Other, NULL );
365     var_Create( p_intf, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
366     var_AddCallback( p_intf, "marq-timeout", Other, NULL );
367
368     var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
369     var_AddCallback( p_intf, "pause", Input, NULL );
370     var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
371     var_AddCallback( p_intf, "seek", Input, NULL );
372     var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
373     var_AddCallback( p_intf, "title", Input, NULL );
374     var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
375     var_AddCallback( p_intf, "title_n", Input, NULL );
376     var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
377     var_AddCallback( p_intf, "title_p", Input, NULL );
378     var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
379     var_AddCallback( p_intf, "chapter", Input, NULL );
380     var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
381     var_AddCallback( p_intf, "chapter_n", Input, NULL );
382     var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
383     var_AddCallback( p_intf, "chapter_p", Input, NULL );
384
385     var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
386     var_AddCallback( p_intf, "volume", Volume, NULL );
387     var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
388     var_AddCallback( p_intf, "volup", VolumeMove, NULL );
389     var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
390     var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
391     var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
392     var_AddCallback( p_intf, "adev", AudioConfig, NULL );
393     var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
394     var_AddCallback( p_intf, "achan", AudioConfig, NULL );
395
396 #ifdef WIN32
397     /* Get the file descriptor of the console input */
398     p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
399     if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
400     {
401         msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
402         p_intf->b_die = VLC_TRUE;
403     }
404 #endif
405
406     while( !p_intf->b_die )
407     {
408         char *psz_cmd, *psz_arg;
409         vlc_bool_t b_complete;
410
411         if( p_intf->p_sys->i_socket_listen != - 1 &&
412             p_intf->p_sys->i_socket == -1 )
413         {
414             p_intf->p_sys->i_socket =
415                 net_Accept( p_intf, p_intf->p_sys->i_socket_listen, 0 );
416         }
417
418         b_complete = ReadCommand( p_intf, p_buffer, &i_size );
419
420         /* Manage the input part */
421         if( p_input == NULL )
422         {
423             if( p_playlist )
424             {
425                 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
426                                                        FIND_CHILD );
427             }
428             else
429             {
430                 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
431                                                    FIND_ANYWHERE );
432                 if( p_input )
433                 {
434                     p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
435                                                            FIND_PARENT );
436                 }
437             }
438         }
439         else if( p_input->b_dead )
440         {
441             vlc_object_release( p_input );
442             p_input = NULL;
443         }
444
445         if( p_input && b_showpos )
446         {
447             i_newpos = 100 * var_GetFloat( p_input, "position" );
448             if( i_oldpos != i_newpos )
449             {
450                 i_oldpos = i_newpos;
451                 msg_rc( "pos: %d%%\n", i_newpos );
452             }
453         }
454
455         /* Is there something to do? */
456         if( !b_complete ) continue;
457
458
459         /* Skip heading spaces */
460         psz_cmd = p_buffer;
461         while( *psz_cmd == ' ' )
462         {
463             psz_cmd++;
464         }
465
466         /* Split psz_cmd at the first space and make sure that
467          * psz_arg is valid */
468         psz_arg = strchr( psz_cmd, ' ' );
469         if( psz_arg )
470         {
471             *psz_arg++ = 0;
472             while( *psz_arg == ' ' )
473             {
474                 psz_arg++;
475             }
476         }
477         else
478         {
479             psz_arg = "";
480         }
481
482         /* If the user typed a registered local command, try it */
483         if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
484         {
485             vlc_value_t val;
486             int i_ret;
487
488             val.psz_string = psz_arg;
489             i_ret = var_Set( p_intf, psz_cmd, val );
490             msg_rc( "%s: returned %i (%s)\n",
491                     psz_cmd, i_ret, vlc_error( i_ret ) );
492         }
493         /* Or maybe it's a global command */
494         else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
495         {
496             vlc_value_t val;
497             int i_ret;
498
499             val.psz_string = psz_arg;
500             /* FIXME: it's a global command, but we should pass the
501              * local object as an argument, not p_intf->p_libvlc. */
502             i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
503             if( i_ret != 0 )
504             {
505                 msg_rc( "%s: returned %i (%s)\n",
506                          psz_cmd, i_ret, vlc_error( i_ret ) );
507             }
508         }
509         else if( !strcmp( psz_cmd, "logout" ) )
510         {
511             /* Close connection */
512             if( p_intf->p_sys->i_socket != -1 )
513             {
514                 net_Close( p_intf->p_sys->i_socket );
515             }
516             p_intf->p_sys->i_socket = -1;
517         }
518         else if( !strcmp( psz_cmd, "info" ) )
519         {
520             if( p_input )
521             {
522                 int i, j;
523                 vlc_mutex_lock( &p_input->input.p_item->lock );
524                 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
525                 {
526                     info_category_t *p_category =
527                         p_input->input.p_item->pp_categories[i];
528
529                     msg_rc( "+----[ %s ]\n", p_category->psz_name );
530                     msg_rc( "| \n" );
531                     for ( j = 0; j < p_category->i_infos; j++ )
532                     {
533                         info_t *p_info = p_category->pp_infos[j];
534                         msg_rc( "| %s: %s\n", p_info->psz_name,
535                                 p_info->psz_value );
536                     }
537                     msg_rc( "| \n" );
538                 }
539                 msg_rc( "+----[ end of stream info ]\n" );
540                 vlc_mutex_unlock( &p_input->input.p_item->lock );
541             }
542             else
543             {
544                 msg_rc( "no input\n" );
545             }
546         }
547         else if( !strcmp( psz_cmd, "is_playing" ) )
548         {
549             if( ! p_input )
550             {
551                 msg_rc( "0\n" );
552             }
553             else
554             {
555                 msg_rc( "1\n" );
556             }
557         }
558         else if( !strcmp( psz_cmd, "get_time" ) )
559         {
560             if( ! p_input )
561             {
562                 msg_rc("0\n");
563             }
564             else
565             {
566                 vlc_value_t time;
567                 var_Get( p_input, "time", &time );
568                 msg_rc( "%i\n", time.i_time / 1000000);
569             }
570         }
571         else if( !strcmp( psz_cmd, "get_length" ) )
572         {
573             if( ! p_input )
574             {
575                 msg_rc("0\n");
576             }
577             else
578             {
579                 vlc_value_t time;
580                 var_Get( p_input, "length", &time );
581                 msg_rc( "%i\n", time.i_time / 1000000);
582             }
583         }
584         else if( !strcmp( psz_cmd, "get_title" ) )
585         {
586             if( ! p_input )
587             {
588                 msg_rc("\n");
589             }
590             else
591             {
592                 msg_rc( "%s\n", p_input->input.p_item->psz_name );
593             }
594         }
595         else switch( psz_cmd[0] )
596         {
597         case 'f':
598         case 'F':
599             if( p_input )
600             {
601                 vout_thread_t *p_vout;
602                 p_vout = vlc_object_find( p_input,
603                                           VLC_OBJECT_VOUT, FIND_CHILD );
604
605                 if( p_vout )
606                 {
607                     p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
608                     vlc_object_release( p_vout );
609                 }
610             }
611             break;
612
613         case 's':
614         case 'S':
615             ;
616             break;
617
618         case '?':
619         case 'h':
620         case 'H':
621             msg_rc(_("+----[ Remote control commands ]\n"));
622             msg_rc("| \n");
623             msg_rc(_("| add XYZ  . . . . . . . . . . add XYZ to playlist\n"));
624             msg_rc(_("| playlist . . .  show items currently in playlist\n"));
625             msg_rc(_("| play . . . . . . . . . . . . . . . . play stream\n"));
626             msg_rc(_("| stop . . . . . . . . . . . . . . . . stop stream\n"));
627             msg_rc(_("| next . . . . . . . . . . . .  next playlist item\n"));
628             msg_rc(_("| prev . . . . . . . . . .  previous playlist item\n"));
629             msg_rc(_("| title [X]  . . . . set/get title in current item\n"));
630             msg_rc(_("| title_n  . . . . . .  next title in current item\n"));
631             msg_rc(_("| title_p  . . . .  previous title in current item\n"));
632             msg_rc(_("| chapter [X]  . . set/get chapter in current item\n"));
633             msg_rc(_("| chapter_n  . . . .  next chapter in current item\n"));
634             msg_rc(_("| chapter_p  . .  previous chapter in current item\n"));
635             msg_rc("| \n");
636             msg_rc(_("| seek X . seek in seconds, for instance `seek 12'\n"));
637             msg_rc(_("| pause  . . . . . . . . . . . . . .  toggle pause\n"));
638             msg_rc(_("| f  . . . . . . . . . . . . . . toggle fullscreen\n"));
639             msg_rc(_("| info . . .  information about the current stream\n"));
640             msg_rc("| \n");
641             msg_rc(_("| volume [X] . . . . . . . .  set/get audio volume\n"));
642             msg_rc(_("| volup [X]  . . . . .  raise audio volume X steps\n"));
643             msg_rc(_("| voldown [X]  . . . .  lower audio volume X steps\n"));
644             msg_rc(_("| adev [X] . . . . . . . . .  set/get audio device\n"));
645             msg_rc(_("| achan [X]. . . . . . . .  set/get audio channels\n"));
646             msg_rc("| \n");
647             if (p_intf->p_sys->b_extend)
648             {
649                    msg_rc(_("| marq-marquee STRING  . . overlay STRING in video\n"));
650                msg_rc(_("| marq-x X . . . . . .offset of marquee, from left\n"));
651                msg_rc(_("| marq-y Y . . . . . . offset of marquee, from top\n"));
652                msg_rc(_("| marq-timeout T. . . . .timeout of marquee, in ms\n"));
653                msg_rc("| \n");
654             }    
655             msg_rc(_("| help . . . . . . . . . . . . . this help message\n"));
656             msg_rc(_("| logout . . . . . .exit (if in socket connection)\n"));
657             msg_rc(_("| quit . . . . . . . . . . . . . . . . .  quit vlc\n"));
658             msg_rc("| \n");
659             msg_rc(_("+----[ end of help ]\n"));
660             break;
661
662         case '\0':
663             /* Ignore empty lines */
664             break;
665
666         default:
667             msg_rc(_("unknown command `%s', type `help' for help\n"), psz_cmd);
668             break;
669         }
670
671         /* Command processed */
672         i_size = 0; p_buffer[0] = 0;
673     }
674
675     if( p_input )
676     {
677         vlc_object_release( p_input );
678         p_input = NULL;
679     }
680
681     if( p_playlist )
682     {
683         vlc_object_release( p_playlist );
684         p_playlist = NULL;
685     }
686 }
687
688 static int Input( vlc_object_t *p_this, char const *psz_cmd,
689                   vlc_value_t oldval, vlc_value_t newval, void *p_data )
690 {
691     intf_thread_t *p_intf = (intf_thread_t*)p_this;
692     input_thread_t *p_input;
693     vlc_value_t     val;
694
695     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
696     if( !p_input ) return VLC_ENOOBJ;
697
698     /* Parse commands that only require an input */
699     if( !strcmp( psz_cmd, "pause" ) )
700     {
701         val.i_int = PAUSE_S;
702
703         var_Set( p_input, "state", val );
704         vlc_object_release( p_input );
705         return VLC_SUCCESS;
706     }
707     else if( !strcmp( psz_cmd, "seek" ) )
708     {
709         if( strlen( newval.psz_string ) > 0 &&
710             newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
711         {
712             val.f_float = (float)atoi( newval.psz_string ) / 100.0;
713             var_Set( p_input, "position", val );
714         }
715         else
716         {
717             val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
718             var_Set( p_input, "time", val );
719         }
720         vlc_object_release( p_input );
721         return VLC_SUCCESS;
722     }
723    
724     else if( !strcmp( psz_cmd, "chapter" ) ||
725              !strcmp( psz_cmd, "chapter_n" ) ||
726              !strcmp( psz_cmd, "chapter_p" ) )
727     {
728         if( !strcmp( psz_cmd, "chapter" ) )
729         {
730             if ( *newval.psz_string )
731             {
732                 /* Set. */
733                 val.i_int = atoi( newval.psz_string );
734                 var_Set( p_input, "chapter", val );
735             }
736             else
737             {
738                 vlc_value_t val_list;
739
740                 /* Get. */
741                 var_Get( p_input, "chapter", &val );
742                 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
743                             &val_list, NULL );
744                 msg_rc( "Currently playing chapter %d/%d\n",
745                         val.i_int, val_list.p_list->i_count );
746                 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
747                             &val_list, NULL );
748             }
749         }
750         else if( !strcmp( psz_cmd, "chapter_n" ) )
751         {
752             val.b_bool = VLC_TRUE;
753             var_Set( p_input, "next-chapter", val );
754         }
755         else if( !strcmp( psz_cmd, "chapter_p" ) )
756         {
757             val.b_bool = VLC_TRUE;
758             var_Set( p_input, "prev-chapter", val );
759         }
760
761         vlc_object_release( p_input );
762         return VLC_SUCCESS;
763     }
764     else if( !strcmp( psz_cmd, "title" ) ||
765              !strcmp( psz_cmd, "title_n" ) ||
766              !strcmp( psz_cmd, "title_p" ) )
767     {
768         if( !strcmp( psz_cmd, "title" ) )
769         {
770             if ( *newval.psz_string )
771             {
772                 /* Set. */
773                 val.i_int = atoi( newval.psz_string );
774                 var_Set( p_input, "title", val );
775             }
776             else
777             {
778                 vlc_value_t val_list;
779
780                 /* Get. */
781                 var_Get( p_input, "title", &val );
782                 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
783                             &val_list, NULL );
784                 msg_rc( "Currently playing title %d/%d\n",
785                         val.i_int, val_list.p_list->i_count );
786                 var_Change( p_this, "title", VLC_VAR_FREELIST,
787                             &val_list, NULL );
788             }
789         }
790         else if( !strcmp( psz_cmd, "title_n" ) )
791         {
792             val.b_bool = VLC_TRUE;
793             var_Set( p_input, "next-title", val );
794         }
795         else if( !strcmp( psz_cmd, "title_p" ) )
796         {
797             val.b_bool = VLC_TRUE;
798             var_Set( p_input, "prev-title", val );
799         }
800
801         vlc_object_release( p_input );
802         return VLC_SUCCESS;
803     }
804
805     /* Never reached. */
806     return VLC_EGENERIC;
807 }
808
809 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
810                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
811 {
812     intf_thread_t *p_intf = (intf_thread_t*)p_this;
813     playlist_t *p_playlist;
814
815     p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
816                                            FIND_ANYWHERE );
817     if( !p_playlist )
818     {
819         return VLC_ENOOBJ;
820     }
821
822     /* Parse commands that require a playlist */
823     if( !strcmp( psz_cmd, "prev" ) )
824     {
825         playlist_Prev( p_playlist );
826     }
827     else if( !strcmp( psz_cmd, "next" ) )
828     {
829         playlist_Next( p_playlist );
830     }
831     else if( !strcmp( psz_cmd, "play" ) )
832     {
833         playlist_Play( p_playlist );
834     }
835     else if( !strcmp( psz_cmd, "stop" ) )
836     {
837         playlist_Stop( p_playlist );
838     }
839     else if( !strcmp( psz_cmd, "add" ) &&
840              newval.psz_string && *newval.psz_string )
841     {
842         playlist_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
843
844         if( p_item )
845         {
846             msg_rc( "trying to add %s to playlist\n", newval.psz_string );
847             playlist_AddItem( p_playlist, p_item,
848                               PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
849         }
850     }
851     else if( !strcmp( psz_cmd, "playlist" ) )
852     {
853         int i;
854         for ( i = 0; i < p_playlist->i_size; i++ )
855         {
856             msg_rc( "|%s%s   %s|\n", i == p_playlist->i_index?"*":" ",
857                     p_playlist->pp_items[i]->input.psz_name,
858                     p_playlist->pp_items[i]->input.psz_uri );
859         }
860         if ( i == 0 )
861         {
862             msg_rc( "| no entries\n" );
863         }
864     }
865  
866     /*
867      * sanity check
868      */
869     else
870     {
871         msg_rc( "unknown command!\n" );
872     }
873
874     vlc_object_release( p_playlist );
875     return VLC_SUCCESS;
876 }
877
878 static int Other( vlc_object_t *p_this, char const *psz_cmd,
879                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
880 {
881     intf_thread_t *p_intf = (intf_thread_t*)p_this;
882     vlc_object_t *p_pl;
883     vlc_value_t     val;
884     vlc_object_t *p_inp;
885
886     p_pl = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
887                                            FIND_ANYWHERE );
888     if( !p_pl )
889     {
890         return VLC_ENOOBJ;
891     }
892     
893     p_inp = vlc_object_find( p_this, VLC_OBJECT_INPUT,
894                                            FIND_ANYWHERE );
895     if( !p_inp )
896     {
897         return VLC_ENOOBJ;
898     }
899
900     /* Parse miscellaneous commands */
901     if( !strcmp( psz_cmd, "marq-marquee" ) )
902     {
903         if( strlen( newval.psz_string ) > 0 )
904         {
905             val.psz_string = newval.psz_string;
906             var_Set( p_inp->p_libvlc, "marq-marquee", val );
907         }
908         else 
909         {
910                 val.psz_string = "";
911                 var_Set( p_inp->p_libvlc, "marq-marquee", val);
912         }
913     }
914     else if( !strcmp( psz_cmd, "marq-x" ) )
915     {
916         if( strlen( newval.psz_string ) > 0) 
917         {
918             val.i_int = atoi( newval.psz_string );
919             var_Set( p_inp->p_libvlc, "marq-x", val );
920         }
921     }
922     else if( !strcmp( psz_cmd, "marq-y" ) )
923     {
924         if( strlen( newval.psz_string ) > 0) 
925         {
926             val.i_int = atoi( newval.psz_string );
927             var_Set( p_inp->p_libvlc, "marq-y", val );
928         }
929     }
930     else if( !strcmp( psz_cmd, "marq-timeout" ) )
931     {
932         if( strlen( newval.psz_string ) > 0) 
933         {
934             val.i_int = atoi( newval.psz_string );
935             var_Set( p_inp, "marq-timeout", val );
936         }
937     }
938  
939     /*
940      * sanity check
941      */
942     else
943     {
944         msg_rc( "unknown command!\n" );
945     }
946
947     vlc_object_release( p_pl );
948     vlc_object_release( p_inp );
949     return VLC_SUCCESS;
950 }
951
952 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
953                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
954 {
955     p_this->p_vlc->b_die = VLC_TRUE;
956     return VLC_SUCCESS;
957 }
958
959 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
960                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
961 {
962     intf_thread_t *p_newintf;
963
964     p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
965
966     if( p_newintf )
967     {
968         p_newintf->b_block = VLC_FALSE;
969         if( intf_RunThread( p_newintf ) )
970         {
971             vlc_object_detach( p_newintf );
972             intf_Destroy( p_newintf );
973         }
974     }
975
976     return VLC_SUCCESS;
977 }
978
979 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
980                    vlc_value_t oldval, vlc_value_t newval, void *p_data )
981 {
982     intf_thread_t *p_intf = (intf_thread_t*)p_this;
983     int i_error;
984
985     if ( *newval.psz_string )
986     {
987         /* Set. */
988         audio_volume_t i_volume = atoi( newval.psz_string );
989         if ( i_volume > AOUT_VOLUME_MAX )
990         {
991             msg_rc( "Volume must be in the range %d-%d\n", AOUT_VOLUME_MIN,
992                     AOUT_VOLUME_MAX );
993             i_error = VLC_EBADVAR;
994         }
995         else i_error = aout_VolumeSet( p_this, i_volume );
996     }
997     else
998     {
999         /* Get. */
1000         audio_volume_t i_volume;
1001         if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1002         {
1003             i_error = VLC_EGENERIC;
1004         }
1005         else
1006         {
1007             msg_rc( "Volume is %d\n", i_volume );
1008             i_error = VLC_SUCCESS;
1009         }
1010     }
1011
1012     return i_error;
1013 }
1014
1015 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1016                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1017 {
1018     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1019     audio_volume_t i_volume;
1020     int i_nb_steps = atoi(newval.psz_string);
1021     int i_error = VLC_SUCCESS;
1022
1023     if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
1024     {
1025         i_nb_steps = 1;
1026     }
1027
1028     if ( !strcmp(psz_cmd, "volup") )
1029     {
1030         if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1031             i_error = VLC_EGENERIC;
1032     }
1033     else
1034     {
1035         if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1036             i_error = VLC_EGENERIC;
1037     }
1038
1039     if ( !i_error ) msg_rc( "Volume is %d\n", i_volume );
1040     return i_error;
1041 }
1042
1043 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1044                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
1045 {
1046     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1047     aout_instance_t * p_aout;
1048     const char * psz_variable;
1049     vlc_value_t val_name;
1050     int i_error;
1051
1052     p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1053     if ( p_aout == NULL ) return VLC_ENOOBJ;
1054
1055     if ( !strcmp( psz_cmd, "adev" ) )
1056     {
1057         psz_variable = "audio-device";
1058     }
1059     else
1060     {
1061         psz_variable = "audio-channels";
1062     }
1063
1064     /* Get the descriptive name of the variable */
1065     var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1066                  &val_name, NULL );
1067     if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1068
1069     if ( !*newval.psz_string )
1070     {
1071         /* Retrieve all registered ***. */
1072         vlc_value_t val, text;
1073         int i, i_value;
1074
1075         if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1076         {
1077             vlc_object_release( (vlc_object_t *)p_aout );
1078             return VLC_EGENERIC;
1079         }
1080         i_value = val.i_int;
1081
1082         if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1083                          VLC_VAR_GETLIST, &val, &text ) < 0 )
1084         {
1085             vlc_object_release( (vlc_object_t *)p_aout );
1086             return VLC_EGENERIC;
1087         }
1088
1089         msg_rc( "+----[ %s ]\n", val_name.psz_string );
1090         for ( i = 0; i < val.p_list->i_count; i++ )
1091         {
1092             if ( i_value == val.p_list->p_values[i].i_int )
1093                 msg_rc( "| %i - %s *\n", val.p_list->p_values[i].i_int,
1094                         text.p_list->p_values[i].psz_string );
1095             else
1096                 msg_rc( "| %i - %s\n", val.p_list->p_values[i].i_int,
1097                         text.p_list->p_values[i].psz_string );
1098         }
1099         var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1100                     &val, &text );
1101         msg_rc( "+----[ end of %s ]\n", val_name.psz_string );
1102
1103         if( val_name.psz_string ) free( val_name.psz_string );
1104         i_error = VLC_SUCCESS;
1105     }
1106     else
1107     {
1108         vlc_value_t val;
1109         val.i_int = atoi( newval.psz_string );
1110
1111         i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1112     }
1113     vlc_object_release( (vlc_object_t *)p_aout );
1114
1115     return i_error;
1116 }
1117
1118 #ifdef WIN32
1119 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1120 {
1121     INPUT_RECORD input_record;
1122     DWORD i_dw;
1123
1124     /* On Win32, select() only works on socket descriptors */
1125     while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1126                                 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1127     {
1128         while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1129                ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1130                                  1, &i_dw ) )
1131         {
1132             if( input_record.EventType != KEY_EVENT ||
1133                 !input_record.Event.KeyEvent.bKeyDown ||
1134                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1135                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1136                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1137                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1138             {
1139                 /* nothing interesting */
1140                 continue;
1141             }
1142
1143             p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1144
1145             /* Echo out the command */
1146             putc( p_buffer[ *pi_size ], stdout );
1147
1148             /* Handle special keys */
1149             if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1150             {
1151                 putc( '\n', stdout );
1152                 break;
1153             }
1154             switch( p_buffer[ *pi_size ] )
1155             {
1156             case '\b':
1157                 if( *pi_size )
1158                 {
1159                     *pi_size -= 2;
1160                     putc( ' ', stdout );
1161                     putc( '\b', stdout );
1162                 }
1163                 break;
1164             case '\r':
1165                 (*pi_size) --;
1166                 break;
1167             }
1168
1169             (*pi_size)++;
1170         }
1171
1172         if( *pi_size == MAX_LINE_LENGTH ||
1173             p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1174         {
1175             p_buffer[ *pi_size ] = 0;
1176             return VLC_TRUE;
1177         }
1178     }
1179
1180     return VLC_FALSE;
1181 }
1182 #endif
1183
1184 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1185 {
1186     int i_read = 0;
1187
1188 #ifdef WIN32
1189     if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
1190         return ReadWin32( p_intf, p_buffer, pi_size );
1191     else if( p_intf->p_sys->i_socket == -1 )
1192     {
1193         msleep( INTF_IDLE_SLEEP );
1194         return VLC_FALSE;
1195     }
1196 #endif
1197
1198     while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1199            (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
1200                        0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
1201                        p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
1202     {
1203         if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1204             break;
1205
1206         (*pi_size)++;
1207     }
1208
1209     /* Connection closed */
1210     if( i_read == -1 )
1211     {
1212         p_intf->p_sys->i_socket = -1;
1213         p_buffer[ *pi_size ] = 0;
1214         return VLC_TRUE;
1215     }
1216
1217     if( *pi_size == MAX_LINE_LENGTH ||
1218         p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1219     {
1220         p_buffer[ *pi_size ] = 0;
1221         return VLC_TRUE;
1222     }
1223
1224     return VLC_FALSE;
1225 }
1226
1227 /*****************************************************************************
1228  * parse_MRL: build a playlist item from a full mrl
1229  *****************************************************************************
1230  * MRL format: "simplified-mrl [:option-name[=option-value]]"
1231  * We don't check for '"' or '\'', we just assume that a ':' that follows a
1232  * space is a new option. Should be good enough for our purpose.
1233  *****************************************************************************/
1234 static playlist_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
1235 {
1236 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
1237 #define SKIPTRAILINGSPACE( p, d ) \
1238     { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
1239
1240     playlist_item_t *p_item = NULL;
1241     char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
1242     char **ppsz_options = NULL;
1243     int i, i_options = 0;
1244
1245     if( !psz_mrl ) return 0;
1246
1247     psz_mrl = psz_orig = strdup( psz_mrl );
1248     while( *psz_mrl )
1249     {
1250         SKIPSPACE( psz_mrl );
1251         psz_item = psz_mrl;
1252
1253         for( ; *psz_mrl; psz_mrl++ )
1254         {
1255             if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
1256             {
1257                 /* We have a complete item */
1258                 break;
1259             }
1260             if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
1261                 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
1262             {
1263                 /* We have a complete item */
1264                 break;
1265             }
1266         }
1267
1268         if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
1269         SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
1270
1271         /* Remove '"' and '\'' if necessary */
1272         if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
1273         { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
1274         if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
1275         { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
1276
1277         if( !psz_item_mrl ) psz_item_mrl = psz_item;
1278         else if( *psz_item )
1279         {
1280             i_options++;
1281             ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
1282             ppsz_options[i_options - 1] = &psz_item[1];
1283         }
1284
1285         if( *psz_mrl ) SKIPSPACE( psz_mrl );
1286     }
1287
1288     /* Now create a playlist item */
1289     if( psz_item_mrl )
1290     {
1291         p_item = playlist_ItemNew( p_intf, psz_item_mrl, psz_item_mrl );
1292         for( i = 0; i < i_options; i++ )
1293         {
1294             playlist_ItemAddOption( p_item, ppsz_options[i] );
1295         }
1296     }
1297
1298     if( i_options ) free( ppsz_options );
1299     free( psz_orig );
1300
1301     return p_item;
1302 }