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