1 /*****************************************************************************
2 * rc.c : remote control stdin/stdout module for vlc
3 *****************************************************************************
4 * Copyright (C) 2004 - 2005 the VideoLAN team
7 * Author: Peter Surda <shurdeek@panorama.sth.ac.at>
8 * Jean-Paul Saman <jpsaman #_at_# m2x _replaceWith#dot_ nl>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
31 #include <errno.h> /* ENOMEM */
40 #include <vlc_video.h>
47 #ifdef HAVE_SYS_TIME_H
48 # include <sys/time.h>
50 #include <sys/types.h>
52 #include "vlc_error.h"
55 #if defined(AF_UNIX) && !defined(AF_LOCAL)
56 # define AF_LOCAL AF_UNIX
59 #if defined(AF_LOCAL) && ! defined(WIN32)
63 #define MAX_LINE_LENGTH 256
64 #define STATUS_CHANGE "status change: "
66 /*****************************************************************************
68 *****************************************************************************/
69 static int Activate ( vlc_object_t * );
70 static void Deactivate ( vlc_object_t * );
71 static void Run ( intf_thread_t * );
73 static void Help ( intf_thread_t *, vlc_bool_t );
74 static void RegisterCallbacks( intf_thread_t * );
76 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
78 static playlist_item_t *parse_MRL( intf_thread_t *, char * );
80 static int Input ( vlc_object_t *, char const *,
81 vlc_value_t, vlc_value_t, void * );
82 static int Playlist ( vlc_object_t *, char const *,
83 vlc_value_t, vlc_value_t, void * );
84 static int Other ( vlc_object_t *, char const *,
85 vlc_value_t, vlc_value_t, void * );
86 static int Quit ( vlc_object_t *, char const *,
87 vlc_value_t, vlc_value_t, void * );
88 static int Intf ( vlc_object_t *, char const *,
89 vlc_value_t, vlc_value_t, void * );
90 static int Volume ( vlc_object_t *, char const *,
91 vlc_value_t, vlc_value_t, void * );
92 static int VolumeMove ( vlc_object_t *, char const *,
93 vlc_value_t, vlc_value_t, void * );
94 static int AudioConfig ( vlc_object_t *, char const *,
95 vlc_value_t, vlc_value_t, void * );
96 static int Menu ( vlc_object_t *, char const *,
97 vlc_value_t, vlc_value_t, void * );
99 /* Status Callbacks */
100 static int TimeOffsetChanged( vlc_object_t *, char const *,
101 vlc_value_t, vlc_value_t , void * );
102 static int VolumeChanged ( vlc_object_t *, char const *,
103 vlc_value_t, vlc_value_t, void * );
104 static int StateChanged ( vlc_object_t *, char const *,
105 vlc_value_t, vlc_value_t, void * );
106 static int RateChanged ( vlc_object_t *, char const *,
107 vlc_value_t, vlc_value_t, void * );
111 int *pi_socket_listen;
116 vlc_mutex_t status_lock;
117 playlist_status_t i_last_state;
125 #ifdef HAVE_VARIADIC_MACROS
126 # define msg_rc( psz_format, args... ) \
127 __msg_rc( p_intf, psz_format, ## args )
130 void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
133 va_start( args, psz_fmt );
135 if( p_intf->p_sys->i_socket == -1 )
137 vprintf( psz_fmt, args );
142 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
143 net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );
148 /*****************************************************************************
150 *****************************************************************************/
151 #define POS_TEXT N_("Show stream position")
152 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
153 "stream from time to time." )
155 #define TTY_TEXT N_("Fake TTY")
156 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
158 #define UNIX_TEXT N_("UNIX socket command input")
159 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
162 #define HOST_TEXT N_("TCP command input")
163 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
164 "You can set the address and port the interface will bind to." )
167 #define QUIET_TEXT N_("Do not open a DOS command box interface")
168 #define QUIET_LONGTEXT N_( \
169 "By default the rc interface plugin will start a DOS command box. " \
170 "Enabling the quiet mode will not bring this command box but can also " \
171 "be pretty annoying when you want to stop VLC and no video window is " \
176 set_shortname( _("RC"));
177 set_category( CAT_INTERFACE );
178 set_subcategory( SUBCAT_INTERFACE_GENERAL );
179 set_description( _("Remote control interface") );
180 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
182 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
184 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
185 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
188 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
191 set_capability( "interface", 20 );
192 set_callbacks( Activate, Deactivate );
195 /*****************************************************************************
196 * Activate: initialize and create stuff
197 *****************************************************************************/
198 static int Activate( vlc_object_t *p_this )
200 intf_thread_t *p_intf = (intf_thread_t*)p_this;
201 playlist_t *p_playlist;
202 char *psz_host, *psz_unix_path;
203 int *pi_socket = NULL;
205 #if defined(HAVE_ISATTY) && !defined(WIN32)
206 /* Check that stdin is a TTY */
207 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
209 msg_Warn( p_intf, "fd 0 is not a TTY" );
214 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
219 #if !defined(AF_LOCAL) || defined(WIN32)
220 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
221 free( psz_unix_path );
224 struct sockaddr_un addr;
227 memset( &addr, 0, sizeof(struct sockaddr_un) );
229 msg_Dbg( p_intf, "trying UNIX socket" );
231 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
233 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
234 free( psz_unix_path );
238 addr.sun_family = AF_LOCAL;
239 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
240 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
242 if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
243 sizeof(struct sockaddr_un) ) ) < 0 )
245 msg_Warn( p_intf, "couldn't bind socket to address: %s",
247 free( psz_unix_path );
248 net_Close( i_socket );
252 if( ( i_ret = listen( i_socket, 1 ) ) < 0 )
254 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
255 free( psz_unix_path );
256 net_Close( i_socket );
260 /* FIXME: we need a core function to merge listening sockets sets */
261 pi_socket = calloc( 2, sizeof( int ) );
262 if( pi_socket == NULL )
264 free( psz_unix_path );
265 net_Close( i_socket );
268 pi_socket[0] = i_socket;
273 if( ( pi_socket == NULL ) &&
274 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
278 vlc_UrlParse( &url, psz_host, 0 );
280 msg_Dbg( p_intf, "base %s port %d", url.psz_host, url.i_port );
282 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
283 if( pi_socket == NULL )
285 msg_Warn( p_intf, "can't listen to %s port %i",
286 url.psz_host, url.i_port );
287 vlc_UrlClean( &url );
292 vlc_UrlClean( &url );
296 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
299 msg_Err( p_intf, "no memory" );
303 p_intf->p_sys->pi_socket_listen = pi_socket;
304 p_intf->p_sys->i_socket = -1;
305 p_intf->p_sys->psz_unix_path = psz_unix_path;
306 vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
307 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
309 /* Non-buffered stdout */
310 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
312 p_intf->pf_run = Run;
315 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
316 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
321 /* Force "no-view" mode */
322 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
326 vlc_mutex_lock( &p_playlist->object_lock );
327 p_playlist->status.i_view = -1;
328 vlc_mutex_unlock( &p_playlist->object_lock );
329 vlc_object_release( p_playlist );
332 msg_rc( _("Remote control interface initialized, `h' for help") );
336 /*****************************************************************************
337 * Deactivate: uninitialize and cleanup
338 *****************************************************************************/
339 static void Deactivate( vlc_object_t *p_this )
341 intf_thread_t *p_intf = (intf_thread_t*)p_this;
343 net_ListenClose( p_intf->p_sys->pi_socket_listen );
344 if( p_intf->p_sys->i_socket != -1 )
345 net_Close( p_intf->p_sys->i_socket );
346 if( p_intf->p_sys->psz_unix_path != NULL )
348 #if defined(AF_LOCAL) && !defined(WIN32)
349 unlink( p_intf->p_sys->psz_unix_path );
351 free( p_intf->p_sys->psz_unix_path );
353 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
354 free( p_intf->p_sys );
357 /*****************************************************************************
358 * RegisterCallbacks: Register callbacks to dynamic variables
359 *****************************************************************************/
360 static void RegisterCallbacks( intf_thread_t *p_intf )
362 /* Register commands that will be cleaned up upon object destruction */
363 var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
364 var_AddCallback( p_intf, "quit", Quit, NULL );
365 var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
366 var_AddCallback( p_intf, "intf", Intf, NULL );
368 var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
369 var_AddCallback( p_intf, "add", Playlist, NULL );
370 var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
371 var_AddCallback( p_intf, "playlist", Playlist, NULL );
372 var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
373 var_AddCallback( p_intf, "play", Playlist, NULL );
374 var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
375 var_AddCallback( p_intf, "stop", Playlist, NULL );
376 var_Create( p_intf, "clear", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
377 var_AddCallback( p_intf, "clear", Playlist, NULL );
378 var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
379 var_AddCallback( p_intf, "prev", Playlist, NULL );
380 var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
381 var_AddCallback( p_intf, "next", Playlist, NULL );
382 var_Create( p_intf, "goto", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
383 var_AddCallback( p_intf, "goto", Playlist, NULL );
384 var_Create( p_intf, "status", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
385 var_AddCallback( p_intf, "status", Playlist, NULL );
387 /* marquee on the fly items */
388 var_Create( p_intf, "marq-marquee", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
389 var_AddCallback( p_intf, "marq-marquee", Other, NULL );
390 var_Create( p_intf, "marq-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
391 var_AddCallback( p_intf, "marq-x", Other, NULL );
392 var_Create( p_intf, "marq-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
393 var_AddCallback( p_intf, "marq-y", Other, NULL );
394 var_Create( p_intf, "marq-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
395 var_AddCallback( p_intf, "marq-position", Other, NULL );
396 var_Create( p_intf, "marq-color", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
397 var_AddCallback( p_intf, "marq-color", Other, NULL );
398 var_Create( p_intf, "marq-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
399 var_AddCallback( p_intf, "marq-opacity", Other, NULL );
400 var_Create( p_intf, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
401 var_AddCallback( p_intf, "marq-timeout", Other, NULL );
402 var_Create( p_intf, "marq-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
403 var_AddCallback( p_intf, "marq-size", Other, NULL );
405 var_Create( p_intf, "mosaic-alpha", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
406 var_AddCallback( p_intf, "mosaic-alpha", Other, NULL );
407 var_Create( p_intf, "mosaic-height", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
408 var_AddCallback( p_intf, "mosaic-height", Other, NULL );
409 var_Create( p_intf, "mosaic-width", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
410 var_AddCallback( p_intf, "mosaic-width", Other, NULL );
411 var_Create( p_intf, "mosaic-xoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
412 var_AddCallback( p_intf, "mosaic-xoffset", Other, NULL );
413 var_Create( p_intf, "mosaic-yoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
414 var_AddCallback( p_intf, "mosaic-yoffset", Other, NULL );
415 var_Create( p_intf, "mosaic-align", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
416 var_AddCallback( p_intf, "mosaic-align", Other, NULL );
417 var_Create( p_intf, "mosaic-vborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
418 var_AddCallback( p_intf, "mosaic-vborder", Other, NULL );
419 var_Create( p_intf, "mosaic-hborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
420 var_AddCallback( p_intf, "mosaic-hborder", Other, NULL );
421 var_Create( p_intf, "mosaic-position",
422 VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
423 var_AddCallback( p_intf, "mosaic-position", Other, NULL );
424 var_Create( p_intf, "mosaic-rows", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
425 var_AddCallback( p_intf, "mosaic-rows", Other, NULL );
426 var_Create( p_intf, "mosaic-cols", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
427 var_AddCallback( p_intf, "mosaic-cols", Other, NULL );
428 var_Create( p_intf, "mosaic-keep-aspect-ratio",
429 VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
430 var_AddCallback( p_intf, "mosaic-keep-aspect-ratio", Other, NULL );
432 /* time on the fly items */
433 var_Create( p_intf, "time-format", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
434 var_AddCallback( p_intf, "time-format", Other, NULL );
435 var_Create( p_intf, "time-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
436 var_AddCallback( p_intf, "time-x", Other, NULL );
437 var_Create( p_intf, "time-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
438 var_AddCallback( p_intf, "time-y", Other, NULL );
439 var_Create( p_intf, "time-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
440 var_AddCallback( p_intf, "time-position", Other, NULL );
441 var_Create( p_intf, "time-color", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
442 var_AddCallback( p_intf, "time-color", Other, NULL );
443 var_Create( p_intf, "time-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
444 var_AddCallback( p_intf, "time-opacity", Other, NULL );
445 var_Create( p_intf, "time-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
446 var_AddCallback( p_intf, "time-size", Other, NULL );
448 /* logo on the fly items */
449 var_Create( p_intf, "logo-file", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
450 var_AddCallback( p_intf, "logo-file", Other, NULL );
451 var_Create( p_intf, "logo-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
452 var_AddCallback( p_intf, "logo-x", Other, NULL );
453 var_Create( p_intf, "logo-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
454 var_AddCallback( p_intf, "logo-y", Other, NULL );
455 var_Create( p_intf, "logo-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
456 var_AddCallback( p_intf, "logo-position", Other, NULL );
457 var_Create( p_intf, "logo-transparency", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
458 var_AddCallback( p_intf, "logo-transparency", Other, NULL );
460 /* OSD menu commands */
461 var_Create( p_intf, "menu", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
462 var_AddCallback( p_intf, "menu", Menu, NULL );
465 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
466 var_AddCallback( p_intf, "pause", Input, NULL );
467 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
468 var_AddCallback( p_intf, "seek", Input, NULL );
469 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
470 var_AddCallback( p_intf, "title", Input, NULL );
471 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
472 var_AddCallback( p_intf, "title_n", Input, NULL );
473 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
474 var_AddCallback( p_intf, "title_p", Input, NULL );
475 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
476 var_AddCallback( p_intf, "chapter", Input, NULL );
477 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
478 var_AddCallback( p_intf, "chapter_n", Input, NULL );
479 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
480 var_AddCallback( p_intf, "chapter_p", Input, NULL );
482 var_Create( p_intf, "fastforward", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
483 var_AddCallback( p_intf, "fastforward", Input, NULL );
484 var_Create( p_intf, "rewind", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
485 var_AddCallback( p_intf, "rewind", Input, NULL );
486 var_Create( p_intf, "faster", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
487 var_AddCallback( p_intf, "faster", Input, NULL );
488 var_Create( p_intf, "slower", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
489 var_AddCallback( p_intf, "slower", Input, NULL );
490 var_Create( p_intf, "normal", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
491 var_AddCallback( p_intf, "normal", Input, NULL );
494 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
495 var_AddCallback( p_intf, "volume", Volume, NULL );
496 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
497 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
498 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
499 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
500 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
501 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
502 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
503 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
506 /*****************************************************************************
508 *****************************************************************************
509 * This part of the interface is in a separate thread so that we can call
510 * exec() from within it without annoying the rest of the program.
511 *****************************************************************************/
512 static void Run( intf_thread_t *p_intf )
514 input_thread_t * p_input;
515 playlist_t * p_playlist;
517 char p_buffer[ MAX_LINE_LENGTH + 1 ];
518 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
519 vlc_bool_t b_longhelp = VLC_FALSE;
529 /* Register commands that will be cleaned up upon object destruction */
530 RegisterCallbacks( p_intf );
532 /* status callbacks */
533 /* Listen to audio volume updates */
534 var_AddCallback( p_intf->p_vlc, "volume-change", VolumeChanged, p_intf );
537 /* Get the file descriptor of the console input */
538 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
539 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
541 msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
542 p_intf->b_die = VLC_TRUE;
546 while( !p_intf->b_die )
548 char *psz_cmd, *psz_arg;
549 vlc_bool_t b_complete;
551 if( p_intf->p_sys->pi_socket_listen != NULL &&
552 p_intf->p_sys->i_socket == -1 )
554 p_intf->p_sys->i_socket =
555 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen, 0 );
558 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
560 /* Manage the input part */
561 if( p_input == NULL )
565 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
570 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
574 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
578 /* New input has been registered */
581 if( !p_input->b_dead || !p_input->b_die )
583 msg_rc( STATUS_CHANGE "( New input: %s )", p_input->input.p_item->psz_uri );
584 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
586 var_AddCallback( p_input, "state", StateChanged, p_intf );
587 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
588 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
589 var_AddCallback( p_input, "rate", RateChanged, p_intf );
590 var_AddCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
593 else if( p_input->b_dead )
595 var_DelCallback( p_input, "state", StateChanged, p_intf );
596 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
597 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
598 var_DelCallback( p_input, "rate", RateChanged, p_intf );
599 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
600 vlc_object_release( p_input );
605 vlc_mutex_lock( &p_playlist->object_lock );
606 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
607 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
608 vlc_mutex_unlock( &p_playlist->object_lock );
612 if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
613 (p_playlist != NULL) )
615 vlc_mutex_lock( &p_playlist->object_lock );
616 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
617 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
619 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
620 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
622 else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
623 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
625 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
626 msg_rc( STATUS_CHANGE "( play state: 1 )" );
628 else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
629 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
631 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
632 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
634 vlc_mutex_unlock( &p_playlist->object_lock );
637 if( p_input && b_showpos )
639 i_newpos = 100 * var_GetFloat( p_input, "position" );
640 if( i_oldpos != i_newpos )
643 msg_rc( "pos: %d%%", i_newpos );
647 /* Is there something to do? */
648 if( !b_complete ) continue;
651 /* Skip heading spaces */
653 while( *psz_cmd == ' ' )
658 /* Split psz_cmd at the first space and make sure that
659 * psz_arg is valid */
660 psz_arg = strchr( psz_cmd, ' ' );
664 while( *psz_arg == ' ' )
674 /* If the user typed a registered local command, try it */
675 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
680 val.psz_string = psz_arg;
681 i_ret = var_Set( p_intf, psz_cmd, val );
682 msg_rc( "%s: returned %i (%s)",
683 psz_cmd, i_ret, vlc_error( i_ret ) );
685 /* Or maybe it's a global command */
686 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
691 val.psz_string = psz_arg;
692 /* FIXME: it's a global command, but we should pass the
693 * local object as an argument, not p_intf->p_libvlc. */
694 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
697 msg_rc( "%s: returned %i (%s)",
698 psz_cmd, i_ret, vlc_error( i_ret ) );
701 else if( !strcmp( psz_cmd, "logout" ) )
703 /* Close connection */
704 if( p_intf->p_sys->i_socket != -1 )
706 net_Close( p_intf->p_sys->i_socket );
708 p_intf->p_sys->i_socket = -1;
710 else if( !strcmp( psz_cmd, "info" ) )
715 vlc_mutex_lock( &p_input->input.p_item->lock );
716 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
718 info_category_t *p_category =
719 p_input->input.p_item->pp_categories[i];
721 msg_rc( "+----[ %s ]", p_category->psz_name );
723 for ( j = 0; j < p_category->i_infos; j++ )
725 info_t *p_info = p_category->pp_infos[j];
726 msg_rc( "| %s: %s", p_info->psz_name,
731 msg_rc( "+----[ end of stream info ]" );
732 vlc_mutex_unlock( &p_input->input.p_item->lock );
736 msg_rc( "no input" );
739 else if( !strcmp( psz_cmd, "is_playing" ) )
750 else if( !strcmp( psz_cmd, "get_time" ) )
759 var_Get( p_input, "time", &time );
760 msg_rc( "%i", time.i_time / 1000000);
763 else if( !strcmp( psz_cmd, "get_length" ) )
772 var_Get( p_input, "length", &time );
773 msg_rc( "%i", time.i_time / 1000000);
776 else if( !strcmp( psz_cmd, "get_title" ) )
784 msg_rc( "%s", p_input->input.p_item->psz_name );
787 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
788 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
790 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
791 b_longhelp = VLC_TRUE;
792 else b_longhelp = VLC_FALSE;
794 Help( p_intf, b_longhelp );
796 else switch( psz_cmd[0] )
802 vout_thread_t *p_vout;
803 p_vout = vlc_object_find( p_input,
804 VLC_OBJECT_VOUT, FIND_CHILD );
809 vlc_bool_t b_update = VLC_FALSE;
810 var_Get( p_vout, "fullscreen", &val );
811 val.b_bool = !val.b_bool;
812 if( !strncmp(psz_arg, "on", 2) && (val.b_bool == VLC_TRUE) )
815 val.b_bool = VLC_TRUE;
817 else if( !strncmp(psz_arg, "off", 3) && (val.b_bool == VLC_FALSE) )
820 val.b_bool = VLC_FALSE;
822 else if( strncmp(psz_arg, "off", 3) && strncmp(psz_arg, "on", 2) )
824 if( b_update ) var_Set( p_vout, "fullscreen", val );
825 vlc_object_release( p_vout );
836 /* Ignore empty lines */
840 msg_rc(_("unknown command `%s', type `help' for help"), psz_cmd);
844 /* Command processed */
845 i_size = 0; p_buffer[0] = 0;
848 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
849 msg_rc( STATUS_CHANGE "( quit )" );
853 var_DelCallback( p_input, "state", StateChanged, p_intf );
854 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
855 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
856 var_DelCallback( p_input, "rate", RateChanged, p_intf );
857 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
858 vlc_object_release( p_input );
864 vlc_object_release( p_playlist );
868 var_DelCallback( p_intf->p_vlc, "volume-change", VolumeChanged, p_intf );
871 static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
873 msg_rc(_("+----[ Remote control commands ]"));
875 msg_rc(_("| add XYZ . . . . . . . . . . add XYZ to playlist"));
876 msg_rc(_("| playlist . . . show items currently in playlist"));
877 msg_rc(_("| play . . . . . . . . . . . . . . . . play stream"));
878 msg_rc(_("| stop . . . . . . . . . . . . . . . . stop stream"));
879 msg_rc(_("| next . . . . . . . . . . . . next playlist item"));
880 msg_rc(_("| prev . . . . . . . . . . previous playlist item"));
881 msg_rc(_("| goto . . . . . . . . . . . . goto item at index"));
882 msg_rc(_("| clear . . . . . . . . . . . clear the playlist"));
883 msg_rc(_("| status . . . . . . . . . current playlist status"));
884 msg_rc(_("| title [X] . . . . set/get title in current item"));
885 msg_rc(_("| title_n . . . . . . next title in current item"));
886 msg_rc(_("| title_p . . . . previous title in current item"));
887 msg_rc(_("| chapter [X] . . set/get chapter in current item"));
888 msg_rc(_("| chapter_n . . . . next chapter in current item"));
889 msg_rc(_("| chapter_p . . previous chapter in current item"));
891 msg_rc(_("| seek X . seek in seconds, for instance `seek 12'"));
892 msg_rc(_("| pause . . . . . . . . . . . . . . toggle pause"));
893 msg_rc(_("| fastforward . . . . . . . set to maximum rate"));
894 msg_rc(_("| rewind . . . . . . . . . . set to minimum rate"));
895 msg_rc(_("| faster . . . . . . . . faster playing of stream"));
896 msg_rc(_("| slower . . . . . . . . slower playing of stream"));
897 msg_rc(_("| normal . . . . . . . . normal playing of stream"));
898 msg_rc(_("| f [on|off] . . . . . . . . . . toggle fullscreen"));
899 msg_rc(_("| info . . . information about the current stream"));
901 msg_rc(_("| volume [X] . . . . . . . . set/get audio volume"));
902 msg_rc(_("| volup [X] . . . . . raise audio volume X steps"));
903 msg_rc(_("| voldown [X] . . . . lower audio volume X steps"));
904 msg_rc(_("| adev [X] . . . . . . . . . set/get audio device"));
905 msg_rc(_("| achan [X]. . . . . . . . set/get audio channels"));
906 msg_rc(_("| menu [on|off|up|down|left|right|select] use menu"));
911 msg_rc(_("| marq-marquee STRING . . overlay STRING in video"));
912 msg_rc(_("| marq-x X . . . . . . . . . . . .offset from left"));
913 msg_rc(_("| marq-y Y . . . . . . . . . . . . offset from top"));
914 msg_rc(_("| marq-position #. . . .relative position control"));
915 msg_rc(_("| marq-color # . . . . . . . . . . font color, RGB"));
916 msg_rc(_("| marq-opacity # . . . . . . . . . . . . . opacity"));
917 msg_rc(_("| marq-timeout T. . . . . . . . . . timeout, in ms"));
918 msg_rc(_("| marq-size # . . . . . . . . font size, in pixels"));
920 msg_rc(_("| time-format STRING . . . overlay STRING in video"));
921 msg_rc(_("| time-x X . . . . . . . . . . . .offset from left"));
922 msg_rc(_("| time-y Y . . . . . . . . . . . . offset from top"));
923 msg_rc(_("| time-position #. . . . . . . . relative position"));
924 msg_rc(_("| time-color # . . . . . . . . . . font color, RGB"));
925 msg_rc(_("| time-opacity # . . . . . . . . . . . . . opacity"));
926 msg_rc(_("| time-size # . . . . . . . . font size, in pixels"));
928 msg_rc(_("| logo-file STRING . . . the overlay file path/name"));
929 msg_rc(_("| logo-x X . . . . . . . . . . . .offset from left"));
930 msg_rc(_("| logo-y Y . . . . . . . . . . . . offset from top"));
931 msg_rc(_("| logo-position #. . . . . . . . relative position"));
932 msg_rc(_("| logo-transparency #. . . . . . . . .transparency"));
934 msg_rc(_("| mosaic-alpha # . . . . . . . . . . . . . . alpha"));
935 msg_rc(_("| mosaic-height #. . . . . . . . . . . . . .height"));
936 msg_rc(_("| mosaic-width # . . . . . . . . . . . . . . width"));
937 msg_rc(_("| mosaic-xoffset # . . . .top left corner position"));
938 msg_rc(_("| mosaic-yoffset # . . . .top left corner position"));
939 msg_rc(_("| mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
940 msg_rc(_("| mosaic-vborder # . . . . . . . . vertical border"));
941 msg_rc(_("| mosaic-hborder # . . . . . . . horizontal border"));
942 msg_rc(_("| mosaic-position {0=auto,1=fixed} . . . .position"));
943 msg_rc(_("| mosaic-rows #. . . . . . . . . . .number of rows"));
944 msg_rc(_("| mosaic-cols #. . . . . . . . . . .number of cols"));
945 msg_rc(_("| mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
948 msg_rc(_("| help . . . . . . . . . . . . . this help message"));
949 msg_rc(_("| longhelp . . . . . . . . . a longer help message"));
950 msg_rc(_("| logout . . . . . exit (if in socket connection)"));
951 msg_rc(_("| quit . . . . . . . . . . . . . . . . . quit vlc"));
953 msg_rc(_("+----[ end of help ]"));
956 /********************************************************************
957 * Status callback routines
958 ********************************************************************/
959 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
960 vlc_value_t oldval, vlc_value_t newval, void *p_data )
962 intf_thread_t *p_intf = (intf_thread_t*)p_data;
963 input_thread_t *p_input = NULL;
965 vlc_mutex_lock( &p_intf->p_sys->status_lock );
966 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
969 msg_rc( STATUS_CHANGE "( time-offset: %d )", var_GetInteger( p_input, "time-offset" ) );
970 vlc_object_release( p_input );
972 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
976 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
977 vlc_value_t oldval, vlc_value_t newval, void *p_data )
979 intf_thread_t *p_intf = (intf_thread_t*)p_data;
981 vlc_mutex_lock( &p_intf->p_sys->status_lock );
982 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_this, "volume") );
983 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
987 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
988 vlc_value_t oldval, vlc_value_t newval, void *p_data )
990 intf_thread_t *p_intf = (intf_thread_t*)p_data;
991 playlist_t *p_playlist = NULL;
992 input_thread_t *p_input = NULL;
994 vlc_mutex_lock( &p_intf->p_sys->status_lock );
995 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
998 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
1002 switch( p_playlist->status.i_status )
1004 case PLAYLIST_STOPPED:
1005 strncpy( &cmd[0], "stop", 4);
1008 case PLAYLIST_RUNNING:
1009 strncpy( &cmd[0], "play", 4);
1012 case PLAYLIST_PAUSED:
1013 strncpy( &cmd[0], "pause", 5);
1016 } /* var_GetInteger( p_input, "state" ) */
1017 msg_rc( STATUS_CHANGE "( %s state: %d )", &cmd[0], newval.i_int );
1018 vlc_object_release( p_playlist );
1020 vlc_object_release( p_input );
1022 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1026 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1027 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1029 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1030 input_thread_t *p_input = NULL;
1032 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1033 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1036 msg_rc( STATUS_CHANGE "( new rate: %d )", var_GetInteger( p_input, "rate" ) );
1037 vlc_object_release( p_input );
1039 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1043 /********************************************************************
1045 ********************************************************************/
1046 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1047 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1049 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1050 input_thread_t *p_input;
1053 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1054 if( !p_input ) return VLC_ENOOBJ;
1056 var_Get( p_input, "state", &val );
1057 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1058 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1060 msg_rc( _("press menu select or pause to continue") );
1061 vlc_object_release( p_input );
1062 return VLC_EGENERIC;
1065 /* Parse commands that only require an input */
1066 if( !strcmp( psz_cmd, "pause" ) )
1068 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1069 var_Set( p_intf->p_vlc, "key-pressed", val );
1070 vlc_object_release( p_input );
1073 else if( !strcmp( psz_cmd, "seek" ) )
1075 if( strlen( newval.psz_string ) > 0 &&
1076 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1078 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
1079 var_Set( p_input, "position", val );
1083 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1084 var_Set( p_input, "time", val );
1086 vlc_object_release( p_input );
1089 else if ( !strcmp( psz_cmd, "fastforward" ) )
1091 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1092 var_Set( p_intf->p_vlc, "key-pressed", val );
1093 vlc_object_release( p_input );
1096 else if ( !strcmp( psz_cmd, "rewind" ) )
1098 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1099 var_Set( p_intf->p_vlc, "key-pressed", val );
1100 vlc_object_release( p_input );
1103 else if ( !strcmp( psz_cmd, "faster" ) )
1105 val.b_bool = VLC_TRUE;
1106 var_Set( p_input, "rate-faster", val );
1107 vlc_object_release( p_input );
1110 else if ( !strcmp( psz_cmd, "slower" ) )
1112 val.b_bool = VLC_TRUE;
1113 var_Set( p_input, "rate-slower", val );
1114 vlc_object_release( p_input );
1117 else if ( !strcmp( psz_cmd, "normal" ) )
1119 val.i_int = INPUT_RATE_DEFAULT;
1120 var_Set( p_input, "rate", val );
1121 vlc_object_release( p_input );
1124 else if( !strcmp( psz_cmd, "chapter" ) ||
1125 !strcmp( psz_cmd, "chapter_n" ) ||
1126 !strcmp( psz_cmd, "chapter_p" ) )
1128 if( !strcmp( psz_cmd, "chapter" ) )
1130 if ( *newval.psz_string )
1133 val.i_int = atoi( newval.psz_string );
1134 var_Set( p_input, "chapter", val );
1138 vlc_value_t val_list;
1141 var_Get( p_input, "chapter", &val );
1142 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1144 msg_rc( "Currently playing chapter %d/%d",
1145 val.i_int, val_list.p_list->i_count );
1146 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1150 else if( !strcmp( psz_cmd, "chapter_n" ) )
1152 val.b_bool = VLC_TRUE;
1153 var_Set( p_input, "next-chapter", val );
1155 else if( !strcmp( psz_cmd, "chapter_p" ) )
1157 val.b_bool = VLC_TRUE;
1158 var_Set( p_input, "prev-chapter", val );
1160 vlc_object_release( p_input );
1163 else if( !strcmp( psz_cmd, "title" ) ||
1164 !strcmp( psz_cmd, "title_n" ) ||
1165 !strcmp( psz_cmd, "title_p" ) )
1167 if( !strcmp( psz_cmd, "title" ) )
1169 if ( *newval.psz_string )
1172 val.i_int = atoi( newval.psz_string );
1173 var_Set( p_input, "title", val );
1177 vlc_value_t val_list;
1180 var_Get( p_input, "title", &val );
1181 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1183 msg_rc( "Currently playing title %d/%d",
1184 val.i_int, val_list.p_list->i_count );
1185 var_Change( p_this, "title", VLC_VAR_FREELIST,
1189 else if( !strcmp( psz_cmd, "title_n" ) )
1191 val.b_bool = VLC_TRUE;
1192 var_Set( p_input, "next-title", val );
1194 else if( !strcmp( psz_cmd, "title_p" ) )
1196 val.b_bool = VLC_TRUE;
1197 var_Set( p_input, "prev-title", val );
1200 vlc_object_release( p_input );
1204 /* Never reached. */
1205 vlc_object_release( p_input );
1206 return VLC_EGENERIC;
1209 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1210 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1213 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1214 playlist_t *p_playlist;
1216 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
1223 if( p_playlist->p_input )
1226 var_Get( p_playlist->p_input, "state", &val );
1227 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1228 msg_rc( _("press menu select or pause to continue") );
1229 vlc_object_release( p_playlist );
1230 return VLC_EGENERIC;
1234 /* Parse commands that require a playlist */
1235 if( !strcmp( psz_cmd, "prev" ) )
1237 playlist_Prev( p_playlist );
1239 else if( !strcmp( psz_cmd, "next" ) )
1241 playlist_Next( p_playlist );
1243 else if( !strcmp( psz_cmd, "play" ) )
1245 if( p_playlist->p_input )
1249 var_Get( p_playlist->p_input, "rate", &val );
1250 if( val.i_int != INPUT_RATE_DEFAULT )
1252 val.i_int = INPUT_RATE_DEFAULT;
1253 var_Set( p_playlist->p_input, "rate", val );
1257 playlist_Play( p_playlist );
1261 else if (!strcmp( psz_cmd, "goto" ) )
1263 if( strlen( newval.psz_string ) > 0)
1265 val.i_int = atoi( newval.psz_string );
1266 playlist_Goto( p_playlist, val.i_int);
1269 else if( !strcmp( psz_cmd, "stop" ) )
1271 playlist_Stop( p_playlist );
1273 else if( !strcmp( psz_cmd, "clear" ) )
1275 playlist_Stop( p_playlist );
1276 vlc_mutex_lock( &p_playlist->object_lock );
1277 playlist_Clear( p_playlist );
1278 vlc_mutex_unlock( &p_playlist->object_lock );
1280 else if( !strcmp( psz_cmd, "add" ) &&
1281 newval.psz_string && *newval.psz_string )
1283 playlist_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1287 msg_rc( "trying to add %s to playlist", newval.psz_string );
1288 playlist_AddItem( p_playlist, p_item,
1289 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
1292 else if( !strcmp( psz_cmd, "playlist" ) )
1296 for ( i = 0; i < p_playlist->i_size; i++ )
1298 msg_rc( "|%s%s %s|%s|", i == p_playlist->i_index ? "*" : " ",
1299 p_playlist->pp_items[i]->input.psz_name,
1300 p_playlist->pp_items[i]->input.psz_uri,
1301 p_playlist->pp_items[i]->i_parents > 0 ?
1302 p_playlist->pp_items[i]->pp_parents[0]->p_parent->input.psz_name : "" );
1306 msg_rc( "| no entries" );
1309 else if( !strcmp( psz_cmd, "status" ) )
1311 if( p_playlist->p_input )
1313 /* Replay the current state of the system. */
1314 msg_rc( STATUS_CHANGE "( New input: %s )", p_playlist->p_input->input.p_item->psz_uri );
1315 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
1317 vlc_mutex_lock( &p_playlist->object_lock );
1318 switch( p_playlist->status.i_status )
1320 case PLAYLIST_STOPPED:
1321 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
1323 case PLAYLIST_RUNNING:
1324 msg_rc( STATUS_CHANGE "( play state: 1 )" );
1326 case PLAYLIST_PAUSED:
1327 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
1330 msg_rc( STATUS_CHANGE "( state unknown )" );
1333 vlc_mutex_unlock( &p_playlist->object_lock );
1342 msg_rc( "unknown command!" );
1345 vlc_object_release( p_playlist );
1349 static int Other( vlc_object_t *p_this, char const *psz_cmd,
1350 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1352 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1353 vlc_object_t *p_playlist;
1355 vlc_object_t *p_input;
1357 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1363 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1366 vlc_object_release( p_playlist );
1372 var_Get( p_input, "state", &val );
1373 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1375 msg_rc( _("press pause to continue") );
1376 vlc_object_release( p_playlist );
1377 vlc_object_release( p_input );
1378 return VLC_EGENERIC;
1382 /* Parse miscellaneous commands */
1383 if( !strcmp( psz_cmd, "marq-marquee" ) )
1385 if( strlen( newval.psz_string ) > 0 )
1387 val.psz_string = newval.psz_string;
1388 var_Set( p_input->p_libvlc, "marq-marquee", val );
1392 val.psz_string = "";
1393 var_Set( p_input->p_libvlc, "marq-marquee", val);
1396 else if( !strcmp( psz_cmd, "marq-x" ) )
1398 if( strlen( newval.psz_string ) > 0)
1400 val.i_int = atoi( newval.psz_string );
1401 var_Set( p_input->p_libvlc, "marq-x", val );
1404 else if( !strcmp( psz_cmd, "marq-y" ) )
1406 if( strlen( newval.psz_string ) > 0)
1408 val.i_int = atoi( newval.psz_string );
1409 var_Set( p_input->p_libvlc, "marq-y", val );
1412 else if( !strcmp( psz_cmd, "marq-position" ) )
1414 if( strlen( newval.psz_string ) > 0)
1416 val.i_int = atoi( newval.psz_string );
1417 var_Set( p_input->p_libvlc, "marq-position", val );
1420 else if( !strcmp( psz_cmd, "marq-color" ) )
1422 if( strlen( newval.psz_string ) > 0)
1424 val.i_int = strtol( newval.psz_string, NULL, 0 );
1425 var_Set( p_input->p_libvlc, "marq-color", val );
1428 else if( !strcmp( psz_cmd, "marq-opacity" ) )
1430 if( strlen( newval.psz_string ) > 0)
1432 val.i_int = strtol( newval.psz_string, NULL, 0 );
1433 var_Set( p_input->p_libvlc, "marq-opacity", val );
1436 else if( !strcmp( psz_cmd, "marq-size" ) )
1438 if( strlen( newval.psz_string ) > 0)
1440 val.i_int = atoi( newval.psz_string );
1441 var_Set( p_input->p_libvlc, "marq-size", val );
1444 else if( !strcmp( psz_cmd, "marq-timeout" ) )
1446 if( strlen( newval.psz_string ) > 0)
1448 val.i_int = atoi( newval.psz_string );
1449 var_Set( p_input, "marq-timeout", val );
1452 else if( !strcmp( psz_cmd, "mosaic-alpha" ) )
1454 if( strlen( newval.psz_string ) > 0)
1456 val.i_int = atoi( newval.psz_string );
1457 var_Set( p_input->p_libvlc, "mosaic-alpha", val );
1460 else if( !strcmp( psz_cmd, "mosaic-height" ) )
1462 if( strlen( newval.psz_string ) > 0)
1464 val.i_int = atoi( newval.psz_string );
1465 var_Set( p_input->p_libvlc, "mosaic-height", val );
1468 else if( !strcmp( psz_cmd, "mosaic-width" ) )
1470 if( strlen( newval.psz_string ) > 0)
1472 val.i_int = atoi( newval.psz_string );
1473 var_Set( p_input->p_libvlc, "mosaic-width", val );
1476 else if( !strcmp( psz_cmd, "mosaic-xoffset" ) )
1478 if( strlen( newval.psz_string ) > 0)
1480 val.i_int = atoi( newval.psz_string );
1481 var_Set( p_input->p_libvlc, "mosaic-xoffset", val );
1484 else if( !strcmp( psz_cmd, "mosaic-yoffset" ) )
1486 if( strlen( newval.psz_string ) > 0)
1488 val.i_int = atoi( newval.psz_string );
1489 var_Set( p_input->p_libvlc, "mosaic-yoffset", val );
1492 else if( !strcmp( psz_cmd, "mosaic-align" ) )
1494 if( strlen( newval.psz_string ) > 0 )
1496 val.i_int = atoi( newval.psz_string );
1497 var_Set( p_input->p_libvlc, "mosaic-align", val );
1500 else if( !strcmp( psz_cmd, "mosaic-vborder" ) )
1502 if( strlen( newval.psz_string ) > 0)
1504 val.i_int = atoi( newval.psz_string );
1505 var_Set( p_input->p_libvlc, "mosaic-vborder", val );
1508 else if( !strcmp( psz_cmd, "mosaic-hborder" ) )
1510 if( strlen( newval.psz_string ) > 0)
1512 val.i_int = atoi( newval.psz_string );
1513 var_Set( p_input->p_libvlc, "mosaic-hborder", val );
1516 else if( !strcmp( psz_cmd, "mosaic-position" ) )
1518 if( strlen( newval.psz_string ) > 0)
1520 val.i_int = atoi( newval.psz_string );
1521 var_Set( p_input->p_libvlc, "mosaic-position", val );
1524 else if( !strcmp( psz_cmd, "mosaic-rows" ) )
1526 if( strlen( newval.psz_string ) > 0)
1528 val.i_int = atoi( newval.psz_string );
1529 var_Set( p_input->p_libvlc, "mosaic-rows", val );
1532 else if( !strcmp( psz_cmd, "mosaic-cols" ) )
1534 if( strlen( newval.psz_string ) > 0)
1536 val.i_int = atoi( newval.psz_string );
1537 var_Set( p_input->p_libvlc, "mosaic-cols", val );
1540 else if( !strcmp( psz_cmd, "mosaic-keep-aspect-ratio" ) )
1542 if( strlen( newval.psz_string ) > 0)
1544 val.i_int = atoi( newval.psz_string );
1545 var_Set( p_input->p_libvlc, "mosaic-keep-aspect-ratio", val );
1548 else if( !strcmp( psz_cmd, "time-format" ) )
1550 if( strlen( newval.psz_string ) > 0 )
1552 val.psz_string = newval.psz_string;
1553 var_Set( p_input->p_libvlc, "time-format", val );
1557 val.psz_string = "";
1558 var_Set( p_input->p_libvlc, "time-format", val);
1561 else if( !strcmp( psz_cmd, "time-x" ) )
1563 if( strlen( newval.psz_string ) > 0)
1565 val.i_int = atoi( newval.psz_string );
1566 var_Set( p_input->p_libvlc, "time-x", val );
1569 else if( !strcmp( psz_cmd, "time-y" ) )
1571 if( strlen( newval.psz_string ) > 0)
1573 val.i_int = atoi( newval.psz_string );
1574 var_Set( p_input->p_libvlc, "time-y", val );
1577 else if( !strcmp( psz_cmd, "time-position" ) )
1579 if( strlen( newval.psz_string ) > 0)
1581 val.i_int = atoi( newval.psz_string );
1582 var_Set( p_input->p_libvlc, "time-position", val );
1585 else if( !strcmp( psz_cmd, "time-color" ) )
1587 if( strlen( newval.psz_string ) > 0)
1589 val.i_int = strtol( newval.psz_string, NULL, 0 );
1590 var_Set( p_input->p_libvlc, "time-color", val );
1593 else if( !strcmp( psz_cmd, "time-opacity" ) )
1595 if( strlen( newval.psz_string ) > 0)
1597 val.i_int = strtol( newval.psz_string, NULL, 0 );
1598 var_Set( p_input->p_libvlc, "time-opacity", val );
1601 else if( !strcmp( psz_cmd, "time-size" ) )
1603 if( strlen( newval.psz_string ) > 0)
1605 val.i_int = atoi( newval.psz_string );
1606 var_Set( p_input->p_libvlc, "time-size", val );
1609 else if( !strcmp( psz_cmd, "logo-file" ) )
1611 if( strlen( newval.psz_string ) > 0 )
1613 val.psz_string = newval.psz_string;
1614 var_Set( p_input->p_libvlc, "logo-file", val );
1617 else if( !strcmp( psz_cmd, "logo-x" ) )
1619 if( strlen( newval.psz_string ) > 0)
1621 val.i_int = atoi( newval.psz_string );
1622 var_Set( p_input->p_libvlc, "logo-x", val );
1625 else if( !strcmp( psz_cmd, "logo-y" ) )
1627 if( strlen( newval.psz_string ) > 0)
1629 val.i_int = atoi( newval.psz_string );
1630 var_Set( p_input->p_libvlc, "logo-y", val );
1633 else if( !strcmp( psz_cmd, "logo-position" ) )
1635 if( strlen( newval.psz_string ) > 0)
1637 val.i_int = atoi( newval.psz_string );
1638 var_Set( p_input->p_libvlc, "logo-position", val );
1641 else if( !strcmp( psz_cmd, "logo-transparency" ) )
1643 if( strlen( newval.psz_string ) > 0)
1645 val.i_int = strtol( newval.psz_string, NULL, 0 );
1646 var_Set( p_input->p_libvlc, "logo-transparency", val );
1655 msg_rc( "unknown command!" );
1658 vlc_object_release( p_playlist );
1659 vlc_object_release( p_input );
1663 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1664 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1666 playlist_t *p_playlist;
1668 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1671 playlist_Stop( p_playlist );
1672 vlc_object_release( p_playlist );
1674 p_this->p_vlc->b_die = VLC_TRUE;
1678 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1679 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1681 intf_thread_t *p_newintf = NULL;
1683 p_newintf = intf_Create( p_this->p_vlc, newval.psz_string, 0, NULL );
1686 p_newintf->b_block = VLC_FALSE;
1687 if( intf_RunThread( p_newintf ) )
1689 vlc_object_detach( p_newintf );
1690 intf_Destroy( p_newintf );
1697 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1698 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1700 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1701 input_thread_t *p_input = NULL;
1702 int i_error = VLC_EGENERIC;
1704 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1712 var_Get( p_input, "state", &val );
1713 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1715 msg_rc( _("press menu select or pause to continue") );
1716 vlc_object_release( p_input );
1717 return VLC_EGENERIC;
1719 vlc_object_release( p_input );
1722 if ( *newval.psz_string )
1725 audio_volume_t i_volume = atoi( newval.psz_string );
1726 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1728 msg_rc( "Volume must be in the range %d-%d", AOUT_VOLUME_MIN,
1730 i_error = VLC_EBADVAR;
1734 if( i_volume == AOUT_VOLUME_MIN )
1738 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1739 var_Set( p_intf->p_vlc, "key-pressed", keyval );
1741 i_error = aout_VolumeSet( p_this, i_volume );
1742 osd_Volume( p_this );
1743 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1749 audio_volume_t i_volume;
1750 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1752 i_error = VLC_EGENERIC;
1756 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1757 i_error = VLC_SUCCESS;
1764 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1765 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1767 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1768 audio_volume_t i_volume;
1769 input_thread_t *p_input = NULL;
1770 int i_nb_steps = atoi(newval.psz_string);
1771 int i_error = VLC_SUCCESS;
1772 int i_volume_step = 0;
1774 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1782 var_Get( p_input, "state", &val );
1783 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1785 msg_rc( _("press menu select or pause to continue") );
1786 vlc_object_release( p_input );
1787 return VLC_EGENERIC;
1789 vlc_object_release( p_input );
1792 i_volume_step = config_GetInt( p_intf->p_vlc, "volume-step" );
1793 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1798 if ( !strcmp(psz_cmd, "volup") )
1800 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1801 i_error = VLC_EGENERIC;
1805 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1806 i_error = VLC_EGENERIC;
1808 osd_Volume( p_this );
1810 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1814 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1815 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1817 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1818 input_thread_t *p_input = NULL;
1819 aout_instance_t * p_aout;
1820 const char * psz_variable;
1821 vlc_value_t val_name;
1824 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1832 var_Get( p_input, "state", &val );
1833 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1834 msg_rc( _("press menu select or pause to continue") );
1835 vlc_object_release( p_input );
1836 return VLC_EGENERIC;
1838 vlc_object_release( p_input );
1841 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1842 if ( p_aout == NULL ) return VLC_ENOOBJ;
1844 if ( !strcmp( psz_cmd, "adev" ) )
1846 psz_variable = "audio-device";
1850 psz_variable = "audio-channels";
1853 /* Get the descriptive name of the variable */
1854 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1856 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1858 if ( !*newval.psz_string )
1860 /* Retrieve all registered ***. */
1861 vlc_value_t val, text;
1864 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1866 vlc_object_release( (vlc_object_t *)p_aout );
1867 return VLC_EGENERIC;
1869 i_value = val.i_int;
1871 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1872 VLC_VAR_GETLIST, &val, &text ) < 0 )
1874 vlc_object_release( (vlc_object_t *)p_aout );
1875 return VLC_EGENERIC;
1878 msg_rc( "+----[ %s ]", val_name.psz_string );
1879 for ( i = 0; i < val.p_list->i_count; i++ )
1881 if ( i_value == val.p_list->p_values[i].i_int )
1882 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1883 text.p_list->p_values[i].psz_string );
1885 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1886 text.p_list->p_values[i].psz_string );
1888 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1890 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1892 if( val_name.psz_string ) free( val_name.psz_string );
1893 i_error = VLC_SUCCESS;
1898 val.i_int = atoi( newval.psz_string );
1900 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1902 vlc_object_release( (vlc_object_t *)p_aout );
1907 /* OSD menu commands */
1908 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1909 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1911 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1912 playlist_t *p_playlist = NULL;
1914 int i_error = VLC_EGENERIC;
1916 if ( !*newval.psz_string )
1918 msg_rc( _("please provide one of the following paramaters") );
1919 msg_rc( "[on|off|up|down|left|right|select]" );
1923 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1927 if( p_playlist->p_input )
1929 var_Get( p_playlist->p_input, "state", &val );
1930 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1931 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1933 msg_rc( _("press menu select or pause to continue") );
1934 vlc_object_release( p_playlist );
1935 return VLC_EGENERIC;
1938 vlc_object_release( p_playlist );
1940 val.psz_string = strdup( newval.psz_string );
1941 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1942 osd_MenuShow( p_this );
1943 else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
1944 osd_MenuHide( p_this );
1945 else if( !strcmp( val.psz_string, "up" ) )
1946 osd_MenuUp( p_this );
1947 else if( !strcmp( val.psz_string, "down" ) )
1948 osd_MenuDown( p_this );
1949 else if( !strcmp( val.psz_string, "left" ) )
1950 osd_MenuPrev( p_this );
1951 else if( !strcmp( val.psz_string, "right" ) )
1952 osd_MenuNext( p_this );
1953 else if( !strcmp( val.psz_string, "select" ) )
1954 osd_MenuActivate( p_this );
1957 msg_rc( _("please provide one of the following paramaters") );
1958 msg_rc( "[on|off|up|down|left|right|select]" );
1959 if( val.psz_string ) free( val.psz_string );
1963 i_error = VLC_SUCCESS;
1964 if( val.psz_string ) free( val.psz_string );
1969 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1971 INPUT_RECORD input_record;
1974 /* On Win32, select() only works on socket descriptors */
1975 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1976 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1978 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1979 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1982 if( input_record.EventType != KEY_EVENT ||
1983 !input_record.Event.KeyEvent.bKeyDown ||
1984 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1985 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1986 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1987 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1989 /* nothing interesting */
1993 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1995 /* Echo out the command */
1996 putc( p_buffer[ *pi_size ], stdout );
1998 /* Handle special keys */
1999 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2001 putc( '\n', stdout );
2004 switch( p_buffer[ *pi_size ] )
2010 putc( ' ', stdout );
2011 putc( '\b', stdout );
2022 if( *pi_size == MAX_LINE_LENGTH ||
2023 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2025 p_buffer[ *pi_size ] = 0;
2034 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2039 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2040 return ReadWin32( p_intf, p_buffer, pi_size );
2041 else if( p_intf->p_sys->i_socket == -1 )
2043 msleep( INTF_IDLE_SLEEP );
2048 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
2049 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
2050 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2051 (uint8_t *)p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
2053 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2059 /* Connection closed */
2062 p_intf->p_sys->i_socket = -1;
2063 p_buffer[ *pi_size ] = 0;
2067 if( *pi_size == MAX_LINE_LENGTH ||
2068 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2070 p_buffer[ *pi_size ] = 0;
2077 /*****************************************************************************
2078 * parse_MRL: build a playlist item from a full mrl
2079 *****************************************************************************
2080 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2081 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2082 * space is a new option. Should be good enough for our purpose.
2083 *****************************************************************************/
2084 static playlist_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2086 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
2087 #define SKIPTRAILINGSPACE( p, d ) \
2088 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2090 playlist_item_t *p_item = NULL;
2091 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2092 char **ppsz_options = NULL;
2093 int i, i_options = 0;
2095 if( !psz_mrl ) return 0;
2097 psz_mrl = psz_orig = strdup( psz_mrl );
2100 SKIPSPACE( psz_mrl );
2103 for( ; *psz_mrl; psz_mrl++ )
2105 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2107 /* We have a complete item */
2110 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2111 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2113 /* We have a complete item */
2118 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2119 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2121 /* Remove '"' and '\'' if necessary */
2122 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2123 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2124 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2125 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2127 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2128 else if( *psz_item )
2131 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2132 ppsz_options[i_options - 1] = &psz_item[1];
2135 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2138 /* Now create a playlist item */
2141 p_item = playlist_ItemNew( p_intf, psz_item_mrl, psz_item_mrl );
2142 for( i = 0; i < i_options; i++ )
2144 playlist_ItemAddOption( p_item, ppsz_options[i] );
2148 if( i_options ) free( ppsz_options );