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