]> git.sesse.net Git - vlc/blob - src/libvlc.c
Win32: move MessageBox error from libVLC to vlc.exe
[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     priv->i_verbose = 3; /* initial value until config is loaded */
120 #if defined( HAVE_ISATTY ) && !defined( WIN32 )
121     priv->b_color = isatty( STDERR_FILENO ); /* 2 is for stderr */
122 #else
123     priv->b_color = false;
124 #endif
125
126     /* Initialize mutexes */
127     vlc_mutex_init( &priv->ml_lock );
128     vlc_ExitInit( &priv->exit );
129
130     return p_libvlc;
131 }
132
133 /**
134  * Initialize a libvlc instance
135  * This function initializes a previously allocated libvlc instance:
136  *  - CPU detection
137  *  - gettext initialization
138  *  - message queue, module bank and playlist initialization
139  *  - configuration and commandline parsing
140  */
141 int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
142                          const char *ppsz_argv[] )
143 {
144     libvlc_priv_t *priv = libvlc_priv (p_libvlc);
145     char *       psz_modules = NULL;
146     char *       psz_parser = NULL;
147     char *       psz_control = NULL;
148     char        *psz_val;
149
150     /* System specific initialization code */
151     system_Init();
152
153     /* Initialize the module bank and load the configuration of the
154      * main module. We need to do this at this stage to be able to display
155      * a short help if required by the user. (short help == main module
156      * options) */
157     module_InitBank ();
158
159     /* Get command line options that affect module loading. */
160     if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, NULL ) )
161     {
162         module_EndBank (false);
163         return VLC_EGENERIC;
164     }
165     priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" );
166
167     /* Find verbosity from VLC_VERBOSE environment variable */
168     {
169         char *env = getenv( "VLC_VERBOSE" );
170         if( env != NULL )
171             priv->i_verbose = atoi( env );
172     }
173
174     /* Announce who we are (TODO: only first instance?) */
175     msg_Dbg( p_libvlc, "VLC media player - %s", VERSION_MESSAGE );
176     msg_Dbg( p_libvlc, "%s", COPYRIGHT_MESSAGE );
177     msg_Dbg( p_libvlc, "revision %s", psz_vlc_changeset );
178     msg_Dbg( p_libvlc, "configured with %s", CONFIGURE_LINE );
179     vlc_threads_setup (p_libvlc);
180
181     /* Load the builtins and plugins into the module_bank.
182      * We have to do it before config_Load*() because this also gets the
183      * list of configuration options exported by each module and loads their
184      * default values. */
185     size_t module_count = module_LoadPlugins (p_libvlc);
186
187     /*
188      * Override default configuration with config file settings
189      */
190     if( !var_InheritBool( p_libvlc, "ignore-config" ) )
191     {
192         if( var_InheritBool( p_libvlc, "reset-config" ) )
193             config_SaveConfigFile( p_libvlc ); /* Save default config */
194         else
195             config_LoadConfigFile( p_libvlc );
196     }
197
198     /*
199      * Override configuration with command line settings
200      */
201     int vlc_optind;
202     if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, &vlc_optind ) )
203     {
204         module_EndBank (true);
205         return VLC_EGENERIC;
206     }
207     priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" );
208
209     /*
210      * Support for gettext
211      */
212 #if defined( ENABLE_NLS ) \
213      && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
214     vlc_bindtextdomain (PACKAGE_NAME);
215 #endif
216     /*xgettext: Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
217     msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") );
218
219     if (config_PrintHelp (VLC_OBJECT(p_libvlc)))
220     {
221         module_EndBank (true);
222         exit(0);
223     }
224
225     if( module_count <= 1 )
226     {
227         msg_Err( p_libvlc, "No plugins found! Check your VLC installation.");
228         module_EndBank (true);
229         return VLC_ENOMOD;
230     }
231
232 #ifdef HAVE_DAEMON
233     /* Check for daemon mode */
234     if( var_InheritBool( p_libvlc, "daemon" ) )
235     {
236         char *psz_pidfile = NULL;
237
238         if( daemon( 1, 0) != 0 )
239         {
240             msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
241             module_EndBank (true);
242             return VLC_ENOMEM;
243         }
244         b_daemon = true;
245
246         /* lets check if we need to write the pidfile */
247         psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
248         if( psz_pidfile != NULL )
249         {
250             FILE *pidfile;
251             pid_t i_pid = getpid ();
252             msg_Dbg( p_libvlc, "PID is %d, writing it to %s",
253                                i_pid, psz_pidfile );
254             pidfile = vlc_fopen( psz_pidfile,"w" );
255             if( pidfile != NULL )
256             {
257                 utf8_fprintf( pidfile, "%d", (int)i_pid );
258                 fclose( pidfile );
259             }
260             else
261             {
262                 msg_Err( p_libvlc, "cannot open pid file for writing: %s (%m)",
263                          psz_pidfile );
264             }
265         }
266         free( psz_pidfile );
267     }
268 #endif
269
270 /* FIXME: could be replaced by using Unix sockets */
271 #ifdef HAVE_DBUS
272
273 #define MPRIS_APPEND "/org/mpris/MediaPlayer2/TrackList/Append"
274 #define MPRIS_BUS_NAME "org.mpris.MediaPlayer2.vlc"
275 #define MPRIS_OBJECT_PATH "/org/mpris/MediaPlayer2"
276 #define MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList"
277
278     if( var_InheritBool( p_libvlc, "one-instance" )
279     || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" )
280       && var_InheritBool( p_libvlc, "started-from-file" ) ) )
281     {
282         for( int i = vlc_optind; i < i_argc; i++ )
283             if( ppsz_argv[i][0] == ':' )
284             {
285                 msg_Err( p_libvlc, "item option %s incompatible with single instance",
286                          ppsz_argv[i] );
287                 goto dbus_out;
288             }
289
290         /* Initialise D-Bus interface, check for other instances */
291         dbus_threads_init_default();
292
293         DBusError err;
294         dbus_error_init( &err );
295
296         /* connect to the session bus */
297         DBusConnection  *conn = dbus_bus_get( DBUS_BUS_SESSION, &err );
298         if( conn == NULL )
299         {
300             msg_Err( p_libvlc, "Failed to connect to D-Bus session daemon: %s",
301                     err.message );
302             dbus_error_free( &err );
303             goto dbus_out;
304         }
305
306         /* check if VLC is available on the bus
307          * if not: D-Bus control is not enabled on the other
308          * instance and we can't pass MRLs to it */
309         /* FIXME: This check is totally brain-dead and buggy. */
310         if( !dbus_bus_name_has_owner( conn, MPRIS_BUS_NAME, &err ) )
311         {
312             dbus_connection_unref( conn );
313             if( dbus_error_is_set( &err ) )
314             {
315                 msg_Err( p_libvlc, "D-Bus error: %s", err.message );
316             }
317             else
318                 msg_Dbg( p_libvlc, "No media player running. Continuing normally." );
319             dbus_error_free( &err );
320             goto dbus_out;
321         }
322
323         const dbus_bool_t play = !var_InheritBool( p_libvlc, "playlist-enqueue" );
324
325         msg_Warn( p_libvlc, "media player running. Exiting...");
326         for( int i = vlc_optind; i < i_argc; i++ )
327         {
328             DBusMessage *msg = dbus_message_new_method_call(
329                MPRIS_BUS_NAME, MPRIS_OBJECT_PATH, MPRIS_TRACKLIST_INTERFACE, "AddTrack" );
330             if( unlikely(msg == NULL) )
331                 continue;
332
333             /* We need to resolve relative paths in this instance */
334             char *mrl;
335             if( strstr( ppsz_argv[i], "://" ) )
336                 mrl = strdup( ppsz_argv[i] );
337             else
338                 mrl = vlc_path2uri( ppsz_argv[i], NULL );
339             if( mrl == NULL )
340             {
341                 dbus_message_unref( msg );
342                 continue;
343             }
344
345             const char *after_track = MPRIS_APPEND;
346
347             /* append MRLs */
348             if( !dbus_message_append_args( msg, DBUS_TYPE_STRING, &mrl,
349                                                 DBUS_TYPE_OBJECT_PATH, &after_track,
350                                                 DBUS_TYPE_BOOLEAN, &play,
351                                                 DBUS_TYPE_INVALID ) )
352             {
353                  dbus_message_unref( msg );
354                  msg = NULL;
355             }
356             free( mrl );
357             if( unlikely(msg == NULL) )
358                 continue;
359
360             msg_Dbg( p_libvlc, "Adds %s to the running media player", mrl );
361
362             /* send message and get a handle for a reply */
363             DBusMessage *reply = dbus_connection_send_with_reply_and_block( conn, msg, -1,
364                                                                             &err );
365             dbus_message_unref( msg );
366             if( reply == NULL )
367             {
368                 msg_Err( p_libvlc, "D-Bus error: %s", err.message );
369                 continue;
370             }
371             dbus_message_unref( reply );
372         }
373         /* we unreference the connection when we've finished with it */
374         dbus_connection_unref( conn );
375         exit( 1 );
376     }
377 #undef MPRIS_APPEND
378 #undef MPRIS_BUS_NAME
379 #undef MPRIS_OBJECT_PATH
380 #undef MPRIS_TRACKLIST_INTERFACE
381 dbus_out:
382 #endif // HAVE_DBUS
383
384     /*
385      * Message queue options
386      */
387     /* Last chance to set the verbosity. Once we start interfaces and other
388      * threads, verbosity becomes read-only. */
389     var_Create( p_libvlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
390     if( var_InheritBool( p_libvlc, "quiet" ) )
391     {
392         var_SetInteger( p_libvlc, "verbose", -1 );
393         priv->i_verbose = -1;
394     }
395     if( priv->b_color )
396         priv->b_color = var_InheritBool( p_libvlc, "color" );
397
398     vlc_CPU_dump( VLC_OBJECT(p_libvlc) );
399     vlc_object_set_name( p_libvlc, "main" );
400
401     priv->b_stats = var_InheritBool( p_libvlc, "stats" );
402
403     /*
404      * Initialize hotkey handling
405      */
406     priv->actions = vlc_InitActions( p_libvlc );
407
408     /* Create a variable for showing the fullscreen interface */
409     var_Create( p_libvlc, "intf-toggle-fscontrol", VLC_VAR_BOOL );
410     var_SetBool( p_libvlc, "intf-toggle-fscontrol", true );
411
412     /* Create a variable for the Boss Key */
413     var_Create( p_libvlc, "intf-boss", VLC_VAR_VOID );
414
415     /* Create a variable for showing the main interface */
416     var_Create( p_libvlc, "intf-show", VLC_VAR_BOOL );
417
418     /* Create a variable for showing the right click menu */
419     var_Create( p_libvlc, "intf-popupmenu", VLC_VAR_BOOL );
420
421     /* variables for signalling creation of new files */
422     var_Create( p_libvlc, "snapshot-file", VLC_VAR_STRING );
423     var_Create( p_libvlc, "record-file", VLC_VAR_STRING );
424
425     /* some default internal settings */
426     var_Create( p_libvlc, "window", VLC_VAR_STRING );
427     var_Create( p_libvlc, "user-agent", VLC_VAR_STRING );
428     var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" );
429
430     /* System specific configuration */
431     system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );
432
433 #if defined(MEDIA_LIBRARY)
434     /* Get the ML */
435     if( var_GetBool( p_libvlc, "load-media-library-on-startup" ) )
436     {
437         priv->p_ml = ml_Create( VLC_OBJECT( p_libvlc ), NULL );
438         if( !priv->p_ml )
439         {
440             msg_Err( p_libvlc, "ML initialization failed" );
441             return VLC_EGENERIC;
442         }
443     }
444     else
445     {
446         priv->p_ml = NULL;
447     }
448 #endif
449
450 #ifdef ENABLE_VLM
451     /* Initialize VLM if vlm-conf is specified */
452     psz_parser = var_CreateGetNonEmptyString( p_libvlc, "vlm-conf" );
453     if( psz_parser )
454     {
455         priv->p_vlm = vlm_New( p_libvlc );
456         if( !priv->p_vlm )
457             msg_Err( p_libvlc, "VLM initialization failed" );
458     }
459     free( psz_parser );
460 #endif
461
462     /*
463      * Load background interfaces
464      */
465     psz_modules = var_CreateGetNonEmptyString( p_libvlc, "extraintf" );
466     psz_control = var_CreateGetNonEmptyString( p_libvlc, "control" );
467
468     if( psz_modules && psz_control )
469     {
470         char* psz_tmp;
471         if( asprintf( &psz_tmp, "%s:%s", psz_modules, psz_control ) != -1 )
472         {
473             free( psz_modules );
474             psz_modules = psz_tmp;
475         }
476     }
477     else if( psz_control )
478     {
479         free( psz_modules );
480         psz_modules = strdup( psz_control );
481     }
482
483     psz_parser = psz_modules;
484     while ( psz_parser && *psz_parser )
485     {
486         char *psz_module, *psz_temp;
487         psz_module = psz_parser;
488         psz_parser = strchr( psz_module, ':' );
489         if ( psz_parser )
490         {
491             *psz_parser = '\0';
492             psz_parser++;
493         }
494         if( asprintf( &psz_temp, "%s,none", psz_module ) != -1)
495         {
496             intf_Create( p_libvlc, psz_temp );
497             free( psz_temp );
498         }
499     }
500     free( psz_modules );
501     free( psz_control );
502
503     if( var_InheritBool( p_libvlc, "file-logging" )
504 #ifdef HAVE_SYSLOG_H
505         && !var_InheritBool( p_libvlc, "syslog" )
506 #endif
507         )
508     {
509         intf_Create( p_libvlc, "logger,none" );
510     }
511 #ifdef HAVE_SYSLOG_H
512     if( var_InheritBool( p_libvlc, "syslog" ) )
513     {
514         char *logmode = var_CreateGetNonEmptyString( p_libvlc, "logmode" );
515         var_SetString( p_libvlc, "logmode", "syslog" );
516         intf_Create( p_libvlc, "logger,none" );
517
518         if( logmode )
519         {
520             var_SetString( p_libvlc, "logmode", logmode );
521             free( logmode );
522         }
523         var_Destroy( p_libvlc, "logmode" );
524     }
525 #endif
526
527     if( var_InheritBool( p_libvlc, "network-synchronisation") )
528     {
529         intf_Create( p_libvlc, "netsync,none" );
530     }
531
532 #ifdef __APPLE__
533     var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER );
534     var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER );
535     var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER );
536     var_Create( p_libvlc, "drawable-view-right", VLC_VAR_INTEGER );
537     var_Create( p_libvlc, "drawable-clip-top", VLC_VAR_INTEGER );
538     var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER );
539     var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER );
540     var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER );
541     var_Create( p_libvlc, "drawable-nsobject", VLC_VAR_ADDRESS );
542 #endif
543 #if defined (WIN32) || defined (__OS2__)
544     var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_INTEGER );
545 #endif
546
547     /*
548      * Get input filenames given as commandline arguments.
549      * We assume that the remaining parameters are filenames
550      * and their input options.
551      */
552     GetFilenames( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );
553
554     /*
555      * Get --open argument
556      */
557     psz_val = var_InheritString( p_libvlc, "open" );
558     if ( psz_val != NULL )
559     {
560         playlist_AddExt( pl_Get(p_libvlc), psz_val, NULL, PLAYLIST_INSERT, 0,
561                          -1, 0, NULL, 0, true, pl_Unlocked );
562         free( psz_val );
563     }
564
565     return VLC_SUCCESS;
566 }
567
568 /**
569  * Cleanup a libvlc instance. The instance is not completely deallocated
570  * \param p_libvlc the instance to clean
571  */
572 void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
573 {
574     libvlc_priv_t *priv = libvlc_priv (p_libvlc);
575
576     /* Ask the interfaces to stop and destroy them */
577     msg_Dbg( p_libvlc, "removing all interfaces" );
578     libvlc_Quit( p_libvlc );
579     intf_DestroyAll( p_libvlc );
580
581 #ifdef ENABLE_VLM
582     /* Destroy VLM if created in libvlc_InternalInit */
583     if( priv->p_vlm )
584     {
585         vlm_Delete( priv->p_vlm );
586     }
587 #endif
588
589 #if defined(MEDIA_LIBRARY)
590     media_library_t* p_ml = priv->p_ml;
591     if( p_ml )
592     {
593         ml_Destroy( VLC_OBJECT( p_ml ) );
594         vlc_object_release( p_ml );
595         libvlc_priv(p_playlist->p_libvlc)->p_ml = NULL;
596     }
597 #endif
598
599     /* Free playlist now, all threads are gone */
600     playlist_t *p_playlist = libvlc_priv (p_libvlc)->p_playlist;
601     if( p_playlist != NULL )
602         playlist_Destroy( p_playlist );
603
604     msg_Dbg( p_libvlc, "removing stats" );
605
606 #if !defined( WIN32 ) && !defined( __OS2__ )
607     char* psz_pidfile = NULL;
608
609     if( b_daemon )
610     {
611         psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
612         if( psz_pidfile != NULL )
613         {
614             msg_Dbg( p_libvlc, "removing pid file %s", psz_pidfile );
615             if( unlink( psz_pidfile ) == -1 )
616             {
617                 msg_Dbg( p_libvlc, "removing pid file %s: %m",
618                         psz_pidfile );
619             }
620         }
621         free( psz_pidfile );
622     }
623 #endif
624
625     /* Save the configuration */
626     if( !var_InheritBool( p_libvlc, "ignore-config" ) )
627         config_AutoSaveConfigFile( VLC_OBJECT(p_libvlc) );
628
629     /* Free module bank. It is refcounted, so we call this each time  */
630     module_EndBank (true);
631
632     vlc_DeinitActions( p_libvlc, priv->actions );
633 #if defined(WIN32) || defined(__OS2__)
634     system_End( );
635 #endif
636 }
637
638 /**
639  * Destroy everything.
640  * This function requests the running threads to finish, waits for their
641  * termination, and destroys their structure.
642  * It stops the thread systems: no instance can run after this has run
643  * \param p_libvlc the instance to destroy
644  */
645 void libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
646 {
647     libvlc_priv_t *priv = libvlc_priv( p_libvlc );
648
649     /* Destroy mutexes */
650     vlc_ExitDestroy( &priv->exit );
651     vlc_mutex_destroy( &priv->ml_lock );
652
653     assert( atomic_load(&(vlc_internals(p_libvlc)->refs)) == 1 );
654     vlc_object_release( p_libvlc );
655 }
656
657 /**
658  * Add an interface plugin and run it
659  */
660 int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module )
661 {
662     if( !p_libvlc )
663         return VLC_EGENERIC;
664
665     if( !psz_module ) /* requesting the default interface */
666     {
667         char *psz_interface = var_CreateGetNonEmptyString( p_libvlc, "intf" );
668         if( !psz_interface ) /* "intf" has not been set */
669         {
670 #if !defined( WIN32 ) && !defined( __OS2__ )
671             if( b_daemon )
672                  /* Daemon mode hack.
673                   * We prefer the dummy interface if none is specified. */
674                 psz_module = "dummy";
675             else
676 #endif
677                 msg_Info( p_libvlc, "%s",
678                           _("Running vlc with the default interface. "
679                             "Use 'cvlc' to use vlc without interface.") );
680         }
681         free( psz_interface );
682         var_Destroy( p_libvlc, "intf" );
683     }
684
685     /* Try to create the interface */
686     int ret = intf_Create( p_libvlc, psz_module ? psz_module : "$intf" );
687     if( ret )
688         msg_Err( p_libvlc, "interface \"%s\" initialization failed",
689                  psz_module ? psz_module : "default" );
690     return ret;
691 }
692
693 /*****************************************************************************
694  * GetFilenames: parse command line options which are not flags
695  *****************************************************************************
696  * Parse command line for input files as well as their associated options.
697  * An option always follows its associated input and begins with a ":".
698  *****************************************************************************/
699 static void GetFilenames( libvlc_int_t *p_vlc, unsigned n,
700                           const char *const args[] )
701 {
702     while( n > 0 )
703     {
704         /* Count the input options */
705         unsigned i_options = 0;
706
707         while( args[--n][0] == ':' )
708         {
709             i_options++;
710             if( n == 0 )
711             {
712                 msg_Warn( p_vlc, "options %s without item", args[n] );
713                 return; /* syntax!? */
714             }
715         }
716
717         char *mrl = NULL;
718         if( strstr( args[n], "://" ) == NULL )
719         {
720             mrl = vlc_path2uri( args[n], NULL );
721             if( !mrl )
722                 continue;
723         }
724
725         playlist_AddExt( pl_Get( p_vlc ), (mrl != NULL) ? mrl : args[n], NULL,
726                          PLAYLIST_INSERT, 0, -1, i_options,
727                          ( i_options ? &args[n + 1] : NULL ),
728                          VLC_INPUT_OPTION_TRUSTED, true, pl_Unlocked );
729         free( mrl );
730     }
731 }