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