]> git.sesse.net Git - vlc/blob - src/libvlc.c
libvlc: simplify logging callback
[vlc] / src / libvlc.c
1 /*****************************************************************************
2  * libvlc.c: libvlc instances creation and deletion, interfaces handling
3  *****************************************************************************
4  * Copyright (C) 1998-2008 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Vincent Seguin <seguin@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Gildas Bazin <gbazin@videolan.org>
10  *          Derk-Jan Hartman <hartman at videolan dot org>
11  *          RĂ©mi Denis-Courmont <rem # videolan : org>
12  *
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation; either version 2.1 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26  *****************************************************************************/
27
28 /** \file
29  * This file contains functions to create and destroy libvlc instances
30  */
31
32 /*****************************************************************************
33  * Preamble
34  *****************************************************************************/
35 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
38
39 #include <vlc_common.h>
40 #include "../lib/libvlc_internal.h"
41 #include <vlc_input.h>
42
43 #include "modules/modules.h"
44 #include "config/configuration.h"
45
46 #include <stdio.h>                                              /* sprintf() */
47 #include <string.h>
48 #include <stdlib.h>                                                /* free() */
49
50 #include "config/vlc_getopt.h"
51
52 #ifdef HAVE_UNISTD_H
53 #   include <unistd.h> /* isatty() */
54 #endif
55
56 #ifdef HAVE_DBUS
57 /* used for one-instance mode */
58 #   include <dbus/dbus.h>
59 #endif
60
61
62 #include <vlc_media_library.h>
63 #include <vlc_playlist.h>
64 #include <vlc_interface.h>
65
66 #include <vlc_charset.h>
67 #include <vlc_fs.h>
68 #include <vlc_cpu.h>
69 #include <vlc_url.h>
70 #include <vlc_modules.h>
71
72 #include "libvlc.h"
73 #include "playlist/playlist_internal.h"
74 #include "misc/variables.h"
75
76 #include <vlc_vlm.h>
77
78 #ifdef __APPLE__
79 # include <libkern/OSAtomic.h>
80 #endif
81
82 #include <assert.h>
83
84 /*****************************************************************************
85  * The evil global variables. We handle them with care, don't worry.
86  *****************************************************************************/
87
88 #if !defined(WIN32) && !defined(__OS2__)
89 static bool b_daemon = false;
90 #endif
91
92 /*****************************************************************************
93  * Local prototypes
94  *****************************************************************************/
95 static void GetFilenames  ( libvlc_int_t *, unsigned, const char *const [] );
96
97 /**
98  * Allocate a libvlc instance, initialize global data if needed
99  * It also initializes the threading system
100  */
101 libvlc_int_t * libvlc_InternalCreate( void )
102 {
103     libvlc_int_t *p_libvlc;
104     libvlc_priv_t *priv;
105
106     /* Now that the thread system is initialized, we don't have much, but
107      * at least we have variables */
108     /* Allocate a libvlc instance object */
109     p_libvlc = vlc_custom_create( (vlc_object_t *)NULL, sizeof (*priv),
110                                   "libvlc" );
111     if( p_libvlc == NULL )
112         return NULL;
113
114     priv = libvlc_priv (p_libvlc);
115     priv->p_playlist = NULL;
116     priv->p_ml = NULL;
117     priv->p_dialog_provider = NULL;
118     priv->p_vlm = NULL;
119
120     /* Initialize mutexes */
121     vlc_mutex_init( &priv->ml_lock );
122     vlc_ExitInit( &priv->exit );
123
124     return p_libvlc;
125 }
126
127 /**
128  * Initialize a libvlc instance
129  * This function initializes a previously allocated libvlc instance:
130  *  - CPU detection
131  *  - gettext initialization
132  *  - message queue, module bank and playlist initialization
133  *  - configuration and commandline parsing
134  */
135 int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
136                          const char *ppsz_argv[] )
137 {
138     libvlc_priv_t *priv = libvlc_priv (p_libvlc);
139     char *       psz_modules = NULL;
140     char *       psz_parser = NULL;
141     char *       psz_control = NULL;
142     char        *psz_val;
143
144     /* System specific initialization code */
145     system_Init();
146
147     /* Initialize the module bank and load the configuration of the
148      * main module. We need to do this at this stage to be able to display
149      * a short help if required by the user. (short help == main module
150      * options) */
151     module_InitBank ();
152
153     /* Get command line options that affect module loading. */
154     if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, NULL ) )
155     {
156         module_EndBank (false);
157         return VLC_EGENERIC;
158     }
159
160     /*
161      * Message queue options (read-only afterwards)
162      */
163 #if defined (HAVE_ISATTY) && !defined (WIN32)
164     if (isatty (STDERR_FILENO))
165         priv->b_color = var_InheritBool (p_libvlc, "color");
166     else
167 #endif
168         priv->b_color = false;
169
170     priv->i_verbose = var_InheritInteger (p_libvlc, "verbose");
171     psz_val = getenv ("VLC_VERBOSE");
172     if (psz_val != NULL)
173         priv->i_verbose = atoi (psz_val);
174
175     if (var_InheritBool (p_libvlc, "quiet"))
176     {
177         var_Create (p_libvlc, "verbose", VLC_VAR_INTEGER);
178         var_SetInteger (p_libvlc, "verbose", -1);
179         priv->i_verbose = -1;
180     }
181
182     vlc_LogInit (p_libvlc);
183
184     /* Announce who we are (TODO: only first instance?) */
185     msg_Dbg( p_libvlc, "VLC media player - %s", VERSION_MESSAGE );
186     msg_Dbg( p_libvlc, "%s", COPYRIGHT_MESSAGE );
187     msg_Dbg( p_libvlc, "revision %s", psz_vlc_changeset );
188     msg_Dbg( p_libvlc, "configured with %s", CONFIGURE_LINE );
189     vlc_threads_setup (p_libvlc);
190
191     /* Load the builtins and plugins into the module_bank.
192      * We have to do it before config_Load*() because this also gets the
193      * list of configuration options exported by each module and loads their
194      * default values. */
195     size_t module_count = module_LoadPlugins (p_libvlc);
196
197     /*
198      * Override default configuration with config file settings
199      */
200     if( !var_InheritBool( p_libvlc, "ignore-config" ) )
201     {
202         if( var_InheritBool( p_libvlc, "reset-config" ) )
203             config_SaveConfigFile( p_libvlc ); /* Save default config */
204         else
205             config_LoadConfigFile( p_libvlc );
206     }
207
208     /*
209      * Override configuration with command line settings
210      */
211     int vlc_optind;
212     if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, &vlc_optind ) )
213     {
214         module_EndBank (true);
215         vlc_LogDeinit (p_libvlc);
216         return VLC_EGENERIC;
217     }
218
219     /*
220      * Support for gettext
221      */
222 #if defined( ENABLE_NLS ) \
223      && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
224     vlc_bindtextdomain (PACKAGE_NAME);
225 #endif
226     /*xgettext: Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
227     msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") );
228
229     if (config_PrintHelp (VLC_OBJECT(p_libvlc)))
230     {
231         module_EndBank (true);
232         exit(0);
233     }
234
235     if( module_count <= 1 )
236     {
237         msg_Err( p_libvlc, "No plugins found! Check your VLC installation.");
238         module_EndBank (true);
239         vlc_LogDeinit (p_libvlc);
240         return VLC_ENOMOD;
241     }
242
243 #ifdef HAVE_DAEMON
244     /* Check for daemon mode */
245     if( var_InheritBool( p_libvlc, "daemon" ) )
246     {
247         char *psz_pidfile = NULL;
248
249         if( daemon( 1, 0) != 0 )
250         {
251             msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
252             module_EndBank (true);
253             vlc_LogDeinit (p_libvlc);
254             return VLC_ENOMEM;
255         }
256         b_daemon = true;
257
258         /* lets check if we need to write the pidfile */
259         psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
260         if( psz_pidfile != NULL )
261         {
262             FILE *pidfile;
263             pid_t i_pid = getpid ();
264             msg_Dbg( p_libvlc, "PID is %d, writing it to %s",
265                                i_pid, psz_pidfile );
266             pidfile = vlc_fopen( psz_pidfile,"w" );
267             if( pidfile != NULL )
268             {
269                 utf8_fprintf( pidfile, "%d", (int)i_pid );
270                 fclose( pidfile );
271             }
272             else
273             {
274                 msg_Err( p_libvlc, "cannot open pid file for writing: %s (%m)",
275                          psz_pidfile );
276             }
277         }
278         free( psz_pidfile );
279     }
280 #endif
281
282 /* FIXME: could be replaced by using Unix sockets */
283 #ifdef HAVE_DBUS
284
285 #define MPRIS_APPEND "/org/mpris/MediaPlayer2/TrackList/Append"
286 #define MPRIS_BUS_NAME "org.mpris.MediaPlayer2.vlc"
287 #define MPRIS_OBJECT_PATH "/org/mpris/MediaPlayer2"
288 #define MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList"
289
290     if( var_InheritBool( p_libvlc, "one-instance" )
291     || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" )
292       && var_InheritBool( p_libvlc, "started-from-file" ) ) )
293     {
294         for( int i = vlc_optind; i < i_argc; i++ )
295             if( ppsz_argv[i][0] == ':' )
296             {
297                 msg_Err( p_libvlc, "item option %s incompatible with single instance",
298                          ppsz_argv[i] );
299                 goto dbus_out;
300             }
301
302         /* Initialise D-Bus interface, check for other instances */
303         dbus_threads_init_default();
304
305         DBusError err;
306         dbus_error_init( &err );
307
308         /* connect to the session bus */
309         DBusConnection  *conn = dbus_bus_get( DBUS_BUS_SESSION, &err );
310         if( conn == NULL )
311         {
312             msg_Err( p_libvlc, "Failed to connect to D-Bus session daemon: %s",
313                     err.message );
314             dbus_error_free( &err );
315             goto dbus_out;
316         }
317
318         /* check if VLC is available on the bus
319          * if not: D-Bus control is not enabled on the other
320          * instance and we can't pass MRLs to it */
321         /* FIXME: This check is totally brain-dead and buggy. */
322         if( !dbus_bus_name_has_owner( conn, MPRIS_BUS_NAME, &err ) )
323         {
324             dbus_connection_unref( conn );
325             if( dbus_error_is_set( &err ) )
326             {
327                 msg_Err( p_libvlc, "D-Bus error: %s", err.message );
328             }
329             else
330                 msg_Dbg( p_libvlc, "No media player running. Continuing normally." );
331             dbus_error_free( &err );
332             goto dbus_out;
333         }
334
335         const dbus_bool_t play = !var_InheritBool( p_libvlc, "playlist-enqueue" );
336
337         msg_Warn( p_libvlc, "media player running. Exiting...");
338         for( int i = vlc_optind; i < i_argc; i++ )
339         {
340             DBusMessage *msg = dbus_message_new_method_call(
341                MPRIS_BUS_NAME, MPRIS_OBJECT_PATH, MPRIS_TRACKLIST_INTERFACE, "AddTrack" );
342             if( unlikely(msg == NULL) )
343                 continue;
344
345             /* We need to resolve relative paths in this instance */
346             char *mrl;
347             if( strstr( ppsz_argv[i], "://" ) )
348                 mrl = strdup( ppsz_argv[i] );
349             else
350                 mrl = vlc_path2uri( ppsz_argv[i], NULL );
351             if( mrl == NULL )
352             {
353                 dbus_message_unref( msg );
354                 continue;
355             }
356
357             const char *after_track = MPRIS_APPEND;
358
359             /* append MRLs */
360             if( !dbus_message_append_args( msg, DBUS_TYPE_STRING, &mrl,
361                                                 DBUS_TYPE_OBJECT_PATH, &after_track,
362                                                 DBUS_TYPE_BOOLEAN, &play,
363                                                 DBUS_TYPE_INVALID ) )
364             {
365                  dbus_message_unref( msg );
366                  msg = NULL;
367             }
368             free( mrl );
369             if( unlikely(msg == NULL) )
370                 continue;
371
372             msg_Dbg( p_libvlc, "Adds %s to the running media player", mrl );
373
374             /* send message and get a handle for a reply */
375             DBusMessage *reply = dbus_connection_send_with_reply_and_block( conn, msg, -1,
376                                                                             &err );
377             dbus_message_unref( msg );
378             if( reply == NULL )
379             {
380                 msg_Err( p_libvlc, "D-Bus error: %s", err.message );
381                 continue;
382             }
383             dbus_message_unref( reply );
384         }
385         /* we unreference the connection when we've finished with it */
386         dbus_connection_unref( conn );
387         exit( 1 );
388     }
389 #undef MPRIS_APPEND
390 #undef MPRIS_BUS_NAME
391 #undef MPRIS_OBJECT_PATH
392 #undef MPRIS_TRACKLIST_INTERFACE
393 dbus_out:
394 #endif // HAVE_DBUS
395
396     vlc_CPU_dump( VLC_OBJECT(p_libvlc) );
397
398     priv->b_stats = var_InheritBool( p_libvlc, "stats" );
399
400     /*
401      * Initialize hotkey handling
402      */
403     priv->actions = vlc_InitActions( p_libvlc );
404
405     /* Create a variable for showing the fullscreen interface */
406     var_Create( p_libvlc, "intf-toggle-fscontrol", VLC_VAR_BOOL );
407     var_SetBool( p_libvlc, "intf-toggle-fscontrol", true );
408
409     /* Create a variable for the Boss Key */
410     var_Create( p_libvlc, "intf-boss", VLC_VAR_VOID );
411
412     /* Create a variable for showing the main interface */
413     var_Create( p_libvlc, "intf-show", VLC_VAR_BOOL );
414
415     /* Create a variable for showing the right click menu */
416     var_Create( p_libvlc, "intf-popupmenu", VLC_VAR_BOOL );
417
418     /* variables for signalling creation of new files */
419     var_Create( p_libvlc, "snapshot-file", VLC_VAR_STRING );
420     var_Create( p_libvlc, "record-file", VLC_VAR_STRING );
421
422     /* some default internal settings */
423     var_Create( p_libvlc, "window", VLC_VAR_STRING );
424     var_Create( p_libvlc, "user-agent", VLC_VAR_STRING );
425     var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" );
426
427     /* System specific configuration */
428     system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );
429
430 #if defined(MEDIA_LIBRARY)
431     /* Get the ML */
432     if( var_GetBool( p_libvlc, "load-media-library-on-startup" ) )
433     {
434         priv->p_ml = ml_Create( VLC_OBJECT( p_libvlc ), NULL );
435         if( !priv->p_ml )
436         {
437             msg_Err( p_libvlc, "ML initialization failed" );
438             return VLC_EGENERIC;
439         }
440     }
441     else
442     {
443         priv->p_ml = NULL;
444     }
445 #endif
446
447 #ifdef ENABLE_VLM
448     /* Initialize VLM if vlm-conf is specified */
449     psz_parser = var_CreateGetNonEmptyString( p_libvlc, "vlm-conf" );
450     if( psz_parser )
451     {
452         priv->p_vlm = vlm_New( p_libvlc );
453         if( !priv->p_vlm )
454             msg_Err( p_libvlc, "VLM initialization failed" );
455     }
456     free( psz_parser );
457 #endif
458
459     /*
460      * Load background interfaces
461      */
462     psz_modules = var_CreateGetNonEmptyString( p_libvlc, "extraintf" );
463     psz_control = var_CreateGetNonEmptyString( p_libvlc, "control" );
464
465     if( psz_modules && psz_control )
466     {
467         char* psz_tmp;
468         if( asprintf( &psz_tmp, "%s:%s", psz_modules, psz_control ) != -1 )
469         {
470             free( psz_modules );
471             psz_modules = psz_tmp;
472         }
473     }
474     else if( psz_control )
475     {
476         free( psz_modules );
477         psz_modules = strdup( psz_control );
478     }
479
480     psz_parser = psz_modules;
481     while ( psz_parser && *psz_parser )
482     {
483         char *psz_module, *psz_temp;
484         psz_module = psz_parser;
485         psz_parser = strchr( psz_module, ':' );
486         if ( psz_parser )
487         {
488             *psz_parser = '\0';
489             psz_parser++;
490         }
491         if( asprintf( &psz_temp, "%s,none", psz_module ) != -1)
492         {
493             intf_Create( p_libvlc, psz_temp );
494             free( psz_temp );
495         }
496     }
497     free( psz_modules );
498     free( psz_control );
499
500     if( var_InheritBool( p_libvlc, "file-logging" )
501 #ifdef HAVE_SYSLOG_H
502         && !var_InheritBool( p_libvlc, "syslog" )
503 #endif
504         )
505     {
506         intf_Create( p_libvlc, "logger,none" );
507     }
508 #ifdef HAVE_SYSLOG_H
509     if( var_InheritBool( p_libvlc, "syslog" ) )
510     {
511         char *logmode = var_CreateGetNonEmptyString( p_libvlc, "logmode" );
512         var_SetString( p_libvlc, "logmode", "syslog" );
513         intf_Create( p_libvlc, "logger,none" );
514
515         if( logmode )
516         {
517             var_SetString( p_libvlc, "logmode", logmode );
518             free( logmode );
519         }
520         var_Destroy( p_libvlc, "logmode" );
521     }
522 #endif
523
524     if( var_InheritBool( p_libvlc, "network-synchronisation") )
525     {
526         intf_Create( p_libvlc, "netsync,none" );
527     }
528
529 #ifdef __APPLE__
530     var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER );
531     var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER );
532     var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER );
533     var_Create( p_libvlc, "drawable-view-right", VLC_VAR_INTEGER );
534     var_Create( p_libvlc, "drawable-clip-top", VLC_VAR_INTEGER );
535     var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER );
536     var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER );
537     var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER );
538     var_Create( p_libvlc, "drawable-nsobject", VLC_VAR_ADDRESS );
539 #endif
540 #if defined (WIN32) || defined (__OS2__)
541     var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_INTEGER );
542 #endif
543
544     /*
545      * Get input filenames given as commandline arguments.
546      * We assume that the remaining parameters are filenames
547      * and their input options.
548      */
549     GetFilenames( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );
550
551     /*
552      * Get --open argument
553      */
554     psz_val = var_InheritString( p_libvlc, "open" );
555     if ( psz_val != NULL )
556     {
557         playlist_AddExt( pl_Get(p_libvlc), psz_val, NULL, PLAYLIST_INSERT, 0,
558                          -1, 0, NULL, 0, true, pl_Unlocked );
559         free( psz_val );
560     }
561
562     return VLC_SUCCESS;
563 }
564
565 /**
566  * Cleanup a libvlc instance. The instance is not completely deallocated
567  * \param p_libvlc the instance to clean
568  */
569 void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
570 {
571     libvlc_priv_t *priv = libvlc_priv (p_libvlc);
572
573     /* Ask the interfaces to stop and destroy them */
574     msg_Dbg( p_libvlc, "removing all interfaces" );
575     libvlc_Quit( p_libvlc );
576     intf_DestroyAll( p_libvlc );
577
578 #ifdef ENABLE_VLM
579     /* Destroy VLM if created in libvlc_InternalInit */
580     if( priv->p_vlm )
581     {
582         vlm_Delete( priv->p_vlm );
583     }
584 #endif
585
586 #if defined(MEDIA_LIBRARY)
587     media_library_t* p_ml = priv->p_ml;
588     if( p_ml )
589     {
590         ml_Destroy( VLC_OBJECT( p_ml ) );
591         vlc_object_release( p_ml );
592         libvlc_priv(p_playlist->p_libvlc)->p_ml = NULL;
593     }
594 #endif
595
596     /* Free playlist now, all threads are gone */
597     playlist_t *p_playlist = libvlc_priv (p_libvlc)->p_playlist;
598     if( p_playlist != NULL )
599         playlist_Destroy( p_playlist );
600
601     msg_Dbg( p_libvlc, "removing stats" );
602
603 #if !defined( WIN32 ) && !defined( __OS2__ )
604     char* psz_pidfile = NULL;
605
606     if( b_daemon )
607     {
608         psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
609         if( psz_pidfile != NULL )
610         {
611             msg_Dbg( p_libvlc, "removing pid file %s", psz_pidfile );
612             if( unlink( psz_pidfile ) == -1 )
613             {
614                 msg_Dbg( p_libvlc, "removing pid file %s: %m",
615                         psz_pidfile );
616             }
617         }
618         free( psz_pidfile );
619     }
620 #endif
621
622     vlc_DeinitActions( p_libvlc, priv->actions );
623
624     /* Save the configuration */
625     if( !var_InheritBool( p_libvlc, "ignore-config" ) )
626         config_AutoSaveConfigFile( VLC_OBJECT(p_libvlc) );
627
628     /* Free module bank. It is refcounted, so we call this each time  */
629     module_EndBank (true);
630     vlc_LogDeinit (p_libvlc);
631 #if defined(WIN32) || defined(__OS2__)
632     system_End( );
633 #endif
634 }
635
636 /**
637  * Destroy everything.
638  * This function requests the running threads to finish, waits for their
639  * termination, and destroys their structure.
640  * It stops the thread systems: no instance can run after this has run
641  * \param p_libvlc the instance to destroy
642  */
643 void libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
644 {
645     libvlc_priv_t *priv = libvlc_priv( p_libvlc );
646
647     /* Destroy mutexes */
648     vlc_ExitDestroy( &priv->exit );
649     vlc_mutex_destroy( &priv->ml_lock );
650
651     assert( atomic_load(&(vlc_internals(p_libvlc)->refs)) == 1 );
652     vlc_object_release( p_libvlc );
653 }
654
655 /**
656  * Add an interface plugin and run it
657  */
658 int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module )
659 {
660     if( !p_libvlc )
661         return VLC_EGENERIC;
662
663     if( !psz_module ) /* requesting the default interface */
664     {
665         char *psz_interface = var_CreateGetNonEmptyString( p_libvlc, "intf" );
666         if( !psz_interface ) /* "intf" has not been set */
667         {
668 #if !defined( WIN32 ) && !defined( __OS2__ )
669             if( b_daemon )
670                  /* Daemon mode hack.
671                   * We prefer the dummy interface if none is specified. */
672                 psz_module = "dummy";
673             else
674 #endif
675                 msg_Info( p_libvlc, "%s",
676                           _("Running vlc with the default interface. "
677                             "Use 'cvlc' to use vlc without interface.") );
678         }
679         free( psz_interface );
680         var_Destroy( p_libvlc, "intf" );
681     }
682
683     /* Try to create the interface */
684     int ret = intf_Create( p_libvlc, psz_module ? psz_module : "$intf" );
685     if( ret )
686         msg_Err( p_libvlc, "interface \"%s\" initialization failed",
687                  psz_module ? psz_module : "default" );
688     return ret;
689 }
690
691 /*****************************************************************************
692  * GetFilenames: parse command line options which are not flags
693  *****************************************************************************
694  * Parse command line for input files as well as their associated options.
695  * An option always follows its associated input and begins with a ":".
696  *****************************************************************************/
697 static void GetFilenames( libvlc_int_t *p_vlc, unsigned n,
698                           const char *const args[] )
699 {
700     while( n > 0 )
701     {
702         /* Count the input options */
703         unsigned i_options = 0;
704
705         while( args[--n][0] == ':' )
706         {
707             i_options++;
708             if( n == 0 )
709             {
710                 msg_Warn( p_vlc, "options %s without item", args[n] );
711                 return; /* syntax!? */
712             }
713         }
714
715         char *mrl = NULL;
716         if( strstr( args[n], "://" ) == NULL )
717         {
718             mrl = vlc_path2uri( args[n], NULL );
719             if( !mrl )
720                 continue;
721         }
722
723         playlist_AddExt( pl_Get( p_vlc ), (mrl != NULL) ? mrl : args[n], NULL,
724                          PLAYLIST_INSERT, 0, -1, i_options,
725                          ( i_options ? &args[n + 1] : NULL ),
726                          VLC_INPUT_OPTION_TRUSTED, true, pl_Unlocked );
727         free( mrl );
728     }
729 }