1 /*****************************************************************************
2 * libvlc.c: libvlc instances creation and deletion, interfaces handling
3 *****************************************************************************
4 * Copyright (C) 1998-2008 the VideoLAN team
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>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
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 General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
29 * This file contains functions to create and destroy libvlc instances
32 /*****************************************************************************
34 *****************************************************************************/
39 #include <vlc_common.h>
40 #include "control/libvlc_internal.h"
41 #include <vlc_input.h>
43 #include "modules/modules.h"
44 #include "config/configuration.h"
46 #include <stdio.h> /* sprintf() */
48 #include <stdlib.h> /* free() */
51 # include <netinet/in.h> /* BSD: struct in_addr */
56 #elif defined( WIN32 ) && !defined( UNDER_CE )
60 #include "config/vlc_getopt.h"
67 /* used for one-instance mode */
68 # include <dbus/dbus.h>
72 #include <vlc_media_library.h>
73 #include <vlc_playlist.h>
74 #include <vlc_interface.h>
77 #include "audio_output/aout_internal.h"
79 #include <vlc_charset.h>
83 #include <vlc_atomic.h>
84 #include <vlc_modules.h>
88 #include "playlist/playlist_internal.h"
93 # include <libkern/OSAtomic.h>
98 /*****************************************************************************
99 * The evil global variables. We handle them with care, don't worry.
100 *****************************************************************************/
103 static bool b_daemon = false;
111 * Atomically set the reference count to 1.
112 * @param p_gc reference counted object
113 * @param pf_destruct destruction calback
116 void *vlc_gc_init (gc_object_t *p_gc, void (*pf_destruct) (gc_object_t *))
118 /* There is no point in using the GC if there is no destructor... */
119 assert (pf_destruct);
120 p_gc->pf_destructor = pf_destruct;
122 vlc_atomic_set (&p_gc->refs, 1);
127 * Atomically increment the reference count.
128 * @param p_gc reference counted object
131 void *vlc_hold (gc_object_t * p_gc)
136 refs = vlc_atomic_inc (&p_gc->refs);
137 assert (refs != 1); /* there had to be a reference already */
142 * Atomically decrement the reference count and, if it reaches zero, destroy.
143 * @param p_gc reference counted object.
145 void vlc_release (gc_object_t *p_gc)
150 refs = vlc_atomic_dec (&p_gc->refs);
151 assert (refs != (uintptr_t)(-1)); /* reference underflow?! */
153 p_gc->pf_destructor (p_gc);
156 /*****************************************************************************
158 *****************************************************************************/
159 #if defined( ENABLE_NLS ) && (defined (__APPLE__) || defined (WIN32)) && \
160 ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
161 static void SetLanguage ( char const * );
163 static void GetFilenames ( libvlc_int_t *, unsigned, const char *const [] );
166 * Allocate a libvlc instance, initialize global data if needed
167 * It also initializes the threading system
169 libvlc_int_t * libvlc_InternalCreate( void )
171 libvlc_int_t *p_libvlc;
173 char *psz_env = NULL;
175 /* Now that the thread system is initialized, we don't have much, but
176 * at least we have variables */
177 /* Allocate a libvlc instance object */
178 p_libvlc = vlc_custom_create( (vlc_object_t *)NULL, sizeof (*priv),
180 if( p_libvlc == NULL )
183 priv = libvlc_priv (p_libvlc);
184 priv->p_playlist = NULL;
186 priv->p_dialog_provider = NULL;
189 /* Find verbosity from VLC_VERBOSE environment variable */
190 psz_env = getenv( "VLC_VERBOSE" );
191 if( psz_env != NULL )
192 priv->i_verbose = atoi( psz_env );
195 #if defined( HAVE_ISATTY ) && !defined( WIN32 )
196 priv->b_color = isatty( 2 ); /* 2 is for stderr */
198 priv->b_color = false;
201 /* Initialize mutexes */
202 vlc_mutex_init( &priv->ml_lock );
203 vlc_mutex_init( &priv->timer_lock );
204 vlc_ExitInit( &priv->exit );
210 * Initialize a libvlc instance
211 * This function initializes a previously allocated libvlc instance:
213 * - gettext initialization
214 * - message queue, module bank and playlist initialization
215 * - configuration and commandline parsing
217 int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
218 const char *ppsz_argv[] )
220 libvlc_priv_t *priv = libvlc_priv (p_libvlc);
221 char * psz_modules = NULL;
222 char * psz_parser = NULL;
223 char * psz_control = NULL;
224 playlist_t *p_playlist = NULL;
227 /* System specific initialization code */
230 /* Initialize the module bank and load the configuration of the
231 * main module. We need to do this at this stage to be able to display
232 * a short help if required by the user. (short help == main module
236 /* Get command line options that affect module loading. */
237 if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, NULL ) )
239 module_EndBank (false);
242 priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" );
244 /* Announce who we are (TODO: only first instance?) */
245 msg_Dbg( p_libvlc, "VLC media player - %s", VERSION_MESSAGE );
246 msg_Dbg( p_libvlc, "%s", COPYRIGHT_MESSAGE );
247 msg_Dbg( p_libvlc, "revision %s", psz_vlc_changeset );
248 msg_Dbg( p_libvlc, "configured with %s", CONFIGURE_LINE );
250 /* Load the builtins and plugins into the module_bank.
251 * We have to do it before config_Load*() because this also gets the
252 * list of configuration options exported by each module and loads their
254 size_t module_count = module_LoadPlugins (p_libvlc);
257 * Override default configuration with config file settings
259 if( !var_InheritBool( p_libvlc, "ignore-config" ) )
261 if( var_InheritBool( p_libvlc, "reset-config" ) )
262 config_SaveConfigFile( p_libvlc ); /* Save default config */
264 config_LoadConfigFile( p_libvlc );
268 * Override configuration with command line settings
271 if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, &vlc_optind ) )
274 ShowConsole( false );
275 /* Pause the console because it's destroyed when we exit */
276 fprintf( stderr, "The command line options couldn't be loaded, check "
277 "that they are valid.\n" );
280 module_EndBank (true);
283 priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" );
286 * Support for gettext
288 #if defined( ENABLE_NLS ) \
289 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
290 # if defined (WIN32) || defined (__APPLE__)
291 /* Check if the user specified a custom language */
292 char *lang = var_InheritString (p_libvlc, "language");
293 if (lang != NULL && strcmp (lang, "auto"))
297 vlc_bindtextdomain (PACKAGE_NAME);
299 /*xgettext: Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
300 msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") );
302 if (config_PrintHelp (VLC_OBJECT(p_libvlc)))
304 module_EndBank (true);
305 return VLC_EEXITSUCCESS;
308 if( module_count <= 1 )
310 msg_Err( p_libvlc, "No plugins found! Check your VLC installation.");
311 module_EndBank (true);
316 /* Check for daemon mode */
317 if( var_InheritBool( p_libvlc, "daemon" ) )
319 char *psz_pidfile = NULL;
321 if( daemon( 1, 0) != 0 )
323 msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
324 module_EndBank (true);
329 /* lets check if we need to write the pidfile */
330 psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
331 if( psz_pidfile != NULL )
334 pid_t i_pid = getpid ();
335 msg_Dbg( p_libvlc, "PID is %d, writing it to %s",
336 i_pid, psz_pidfile );
337 pidfile = vlc_fopen( psz_pidfile,"w" );
338 if( pidfile != NULL )
340 utf8_fprintf( pidfile, "%d", (int)i_pid );
345 msg_Err( p_libvlc, "cannot open pid file for writing: %s (%m)",
353 /* FIXME: could be replaced by using Unix sockets */
355 dbus_threads_init_default();
357 if( var_InheritBool( p_libvlc, "one-instance" )
358 || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" )
359 && var_InheritBool( p_libvlc, "started-from-file" ) ) )
361 /* Initialise D-Bus interface, check for other instances */
362 DBusConnection *p_conn = NULL;
363 DBusError dbus_error;
365 dbus_error_init( &dbus_error );
367 /* connect to the session bus */
368 p_conn = dbus_bus_get( DBUS_BUS_SESSION, &dbus_error );
371 msg_Err( p_libvlc, "Failed to connect to D-Bus session daemon: %s",
372 dbus_error.message );
373 dbus_error_free( &dbus_error );
377 /* check if VLC is available on the bus
378 * if not: D-Bus control is not enabled on the other
379 * instance and we can't pass MRLs to it */
380 DBusMessage *p_test_msg = NULL;
381 DBusMessage *p_test_reply = NULL;
383 p_test_msg = dbus_message_new_method_call(
384 "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2",
385 "org.freedesktop.DBus.Introspectable", "Introspect" );
387 /* block until a reply arrives */
388 p_test_reply = dbus_connection_send_with_reply_and_block(
389 p_conn, p_test_msg, -1, &dbus_error );
390 dbus_message_unref( p_test_msg );
391 if( p_test_reply == NULL )
393 dbus_error_free( &dbus_error );
394 msg_Dbg( p_libvlc, "No Media Player is running. "
395 "Continuing normally." );
400 DBusMessage* p_dbus_msg = NULL;
401 DBusMessageIter dbus_args;
402 DBusPendingCall* p_dbus_pending = NULL;
405 dbus_message_unref( p_test_reply );
406 msg_Warn( p_libvlc, "Another Media Player is running. Exiting");
408 for( i_input = vlc_optind; i_input < i_argc;i_input++ )
410 /* Skip input options, we can't pass them through D-Bus */
411 if( ppsz_argv[i_input][0] == ':' )
413 msg_Warn( p_libvlc, "Ignoring option %s",
414 ppsz_argv[i_input] );
418 /* We need to resolve relative paths in this instance */
419 char *psz_mrl = make_URI( ppsz_argv[i_input], NULL );
420 const char *psz_after_track = "/";
422 if( psz_mrl == NULL )
424 msg_Dbg( p_libvlc, "Adds %s to the running Media Player",
427 p_dbus_msg = dbus_message_new_method_call(
428 "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2",
429 "org.mpris.MediaPlayer2.TrackList", "AddTrack" );
431 if ( NULL == p_dbus_msg )
433 msg_Err( p_libvlc, "D-Bus problem" );
440 dbus_message_iter_init_append( p_dbus_msg, &dbus_args );
441 if ( !dbus_message_iter_append_basic( &dbus_args,
442 DBUS_TYPE_STRING, &psz_mrl ) )
444 dbus_message_unref( p_dbus_msg );
451 if( !dbus_message_iter_append_basic( &dbus_args,
452 DBUS_TYPE_OBJECT_PATH, &psz_after_track ) )
454 dbus_message_unref( p_dbus_msg );
460 if( var_InheritBool( p_libvlc, "playlist-enqueue" ) )
463 if ( !dbus_message_iter_append_basic( &dbus_args,
464 DBUS_TYPE_BOOLEAN, &b_play ) )
466 dbus_message_unref( p_dbus_msg );
471 /* send message and get a handle for a reply */
472 if ( !dbus_connection_send_with_reply ( p_conn,
473 p_dbus_msg, &p_dbus_pending, -1 ) )
475 msg_Err( p_libvlc, "D-Bus problem" );
476 dbus_message_unref( p_dbus_msg );
481 if ( NULL == p_dbus_pending )
483 msg_Err( p_libvlc, "D-Bus problem" );
484 dbus_message_unref( p_dbus_msg );
488 dbus_connection_flush( p_conn );
489 dbus_message_unref( p_dbus_msg );
490 /* block until we receive a reply */
491 dbus_pending_call_block( p_dbus_pending );
492 dbus_pending_call_unref( p_dbus_pending );
493 } /* processes all command line MRLs */
500 /* we unreference the connection when we've finished with it */
501 if( p_conn ) dbus_connection_unref( p_conn );
506 * Message queue options
508 /* Last chance to set the verbosity. Once we start interfaces and other
509 * threads, verbosity becomes read-only. */
510 var_Create( p_libvlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
511 if( var_InheritBool( p_libvlc, "quiet" ) )
513 var_SetInteger( p_libvlc, "verbose", -1 );
514 priv->i_verbose = -1;
516 vlc_threads_setup( p_libvlc );
519 priv->b_color = var_InheritBool( p_libvlc, "color" );
521 vlc_CPU_dump( VLC_OBJECT(p_libvlc) );
523 * Choose the best memcpy module
525 priv->p_memcpy_module = module_need( p_libvlc, "memcpy", "$memcpy", false );
526 /* Avoid being called "memcpy":*/
527 vlc_object_set_name( p_libvlc, "main" );
529 priv->b_stats = var_InheritBool( p_libvlc, "stats" );
531 priv->pp_timers = NULL;
534 * Initialize hotkey handling
536 priv->actions = vlc_InitActions( p_libvlc );
538 /* Create a variable for showing the fullscreen interface */
539 var_Create( p_libvlc, "intf-show", VLC_VAR_BOOL );
540 var_SetBool( p_libvlc, "intf-show", true );
542 /* Create a variable for showing the right click menu */
543 var_Create( p_libvlc, "intf-popupmenu", VLC_VAR_BOOL );
545 /* variables for signalling creation of new files */
546 var_Create( p_libvlc, "snapshot-file", VLC_VAR_STRING );
547 var_Create( p_libvlc, "record-file", VLC_VAR_STRING );
549 /* some default internal settings */
550 var_Create( p_libvlc, "window", VLC_VAR_STRING );
551 var_Create( p_libvlc, "user-agent", VLC_VAR_STRING );
552 var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" );
554 /* Initialize playlist and get commandline files */
555 p_playlist = playlist_Create( VLC_OBJECT(p_libvlc) );
558 msg_Err( p_libvlc, "playlist initialization failed" );
559 if( priv->p_memcpy_module != NULL )
561 module_unneed( p_libvlc, priv->p_memcpy_module );
563 module_EndBank (true);
567 /* System specific configuration */
568 system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );
570 #if defined(MEDIA_LIBRARY)
572 if( var_GetBool( p_libvlc, "load-media-library-on-startup" ) )
574 priv->p_ml = ml_Create( VLC_OBJECT( p_libvlc ), NULL );
577 msg_Err( p_libvlc, "ML initialization failed" );
587 /* Add service discovery modules */
588 psz_modules = var_InheritString( p_libvlc, "services-discovery" );
591 char *p = psz_modules, *m;
592 while( ( m = strsep( &p, " :," ) ) != NULL )
593 playlist_ServicesDiscoveryAdd( p_playlist, m );
598 /* Initialize VLM if vlm-conf is specified */
599 psz_parser = var_CreateGetNonEmptyString( p_libvlc, "vlm-conf" );
602 priv->p_vlm = vlm_New( p_libvlc );
604 msg_Err( p_libvlc, "VLM initialization failed" );
610 * Load background interfaces
612 psz_modules = var_CreateGetNonEmptyString( p_libvlc, "extraintf" );
613 psz_control = var_CreateGetNonEmptyString( p_libvlc, "control" );
615 if( psz_modules && psz_control )
618 if( asprintf( &psz_tmp, "%s:%s", psz_modules, psz_control ) != -1 )
621 psz_modules = psz_tmp;
624 else if( psz_control )
627 psz_modules = strdup( psz_control );
630 psz_parser = psz_modules;
631 while ( psz_parser && *psz_parser )
633 char *psz_module, *psz_temp;
634 psz_module = psz_parser;
635 psz_parser = strchr( psz_module, ':' );
641 if( asprintf( &psz_temp, "%s,none", psz_module ) != -1)
643 intf_Create( p_libvlc, psz_temp );
651 * Always load the hotkeys interface if it exists
653 intf_Create( p_libvlc, "hotkeys,none" );
656 /* loads dbus control interface if in one-instance mode
657 * we do it only when playlist exists, because dbus module needs it */
658 if( var_InheritBool( p_libvlc, "one-instance" )
659 || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" )
660 && var_InheritBool( p_libvlc, "started-from-file" ) ) )
661 intf_Create( p_libvlc, "dbus,none" );
663 # if !defined (HAVE_MAEMO)
664 /* Prevents the power management daemon from suspending the system
665 * when VLC is active */
666 if( var_InheritBool( p_libvlc, "inhibit" ) > 0 )
667 intf_Create( p_libvlc, "inhibit,none" );
671 if( var_InheritBool( p_libvlc, "file-logging" ) &&
672 !var_InheritBool( p_libvlc, "syslog" ) )
674 intf_Create( p_libvlc, "logger,none" );
677 if( var_InheritBool( p_libvlc, "syslog" ) )
679 char *logmode = var_CreateGetNonEmptyString( p_libvlc, "logmode" );
680 var_SetString( p_libvlc, "logmode", "syslog" );
681 intf_Create( p_libvlc, "logger,none" );
685 var_SetString( p_libvlc, "logmode", logmode );
688 var_Destroy( p_libvlc, "logmode" );
692 if( var_InheritBool( p_libvlc, "network-synchronisation") )
694 intf_Create( p_libvlc, "netsync,none" );
698 var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER );
699 var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER );
700 var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER );
701 var_Create( p_libvlc, "drawable-view-right", VLC_VAR_INTEGER );
702 var_Create( p_libvlc, "drawable-clip-top", VLC_VAR_INTEGER );
703 var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER );
704 var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER );
705 var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER );
706 var_Create( p_libvlc, "drawable-nsobject", VLC_VAR_ADDRESS );
709 var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_INTEGER );
713 * Get input filenames given as commandline arguments.
714 * We assume that the remaining parameters are filenames
715 * and their input options.
717 GetFilenames( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );
720 * Get --open argument
722 psz_val = var_InheritString( p_libvlc, "open" );
723 if ( psz_val != NULL )
725 playlist_AddExt( p_playlist, psz_val, NULL, PLAYLIST_INSERT, 0,
726 -1, 0, NULL, 0, true, pl_Unlocked );
734 * Cleanup a libvlc instance. The instance is not completely deallocated
735 * \param p_libvlc the instance to clean
737 void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
739 libvlc_priv_t *priv = libvlc_priv (p_libvlc);
740 playlist_t *p_playlist = libvlc_priv (p_libvlc)->p_playlist;
742 /* Deactivate the playlist */
743 msg_Dbg( p_libvlc, "deactivating the playlist" );
744 pl_Deactivate( p_libvlc );
746 /* Remove all services discovery */
747 msg_Dbg( p_libvlc, "removing all services discovery tasks" );
748 playlist_ServicesDiscoveryKillAll( p_playlist );
750 /* Ask the interfaces to stop and destroy them */
751 msg_Dbg( p_libvlc, "removing all interfaces" );
752 libvlc_Quit( p_libvlc );
753 intf_DestroyAll( p_libvlc );
756 /* Destroy VLM if created in libvlc_InternalInit */
759 vlm_Delete( priv->p_vlm );
763 #if defined(MEDIA_LIBRARY)
764 media_library_t* p_ml = priv->p_ml;
767 ml_Destroy( VLC_OBJECT( p_ml ) );
768 vlc_object_release( p_ml );
769 libvlc_priv(p_playlist->p_libvlc)->p_ml = NULL;
773 /* Free playlist now, all threads are gone */
774 playlist_Destroy( p_playlist );
775 stats_TimersDumpAll( p_libvlc );
776 stats_TimersCleanAll( p_libvlc );
778 msg_Dbg( p_libvlc, "removing stats" );
781 char* psz_pidfile = NULL;
785 psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
786 if( psz_pidfile != NULL )
788 msg_Dbg( p_libvlc, "removing pid file %s", psz_pidfile );
789 if( unlink( psz_pidfile ) == -1 )
791 msg_Dbg( p_libvlc, "removing pid file %s: %m",
799 if( priv->p_memcpy_module )
801 module_unneed( p_libvlc, priv->p_memcpy_module );
802 priv->p_memcpy_module = NULL;
805 /* Save the configuration */
806 if( !var_InheritBool( p_libvlc, "ignore-config" ) )
807 config_AutoSaveConfigFile( VLC_OBJECT(p_libvlc) );
809 /* Free module bank. It is refcounted, so we call this each time */
810 module_EndBank (true);
812 vlc_DeinitActions( p_libvlc, priv->actions );
816 * Destroy everything.
817 * This function requests the running threads to finish, waits for their
818 * termination, and destroys their structure.
819 * It stops the thread systems: no instance can run after this has run
820 * \param p_libvlc the instance to destroy
822 void libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
824 libvlc_priv_t *priv = libvlc_priv( p_libvlc );
828 /* Destroy mutexes */
829 vlc_ExitDestroy( &priv->exit );
830 vlc_mutex_destroy( &priv->timer_lock );
831 vlc_mutex_destroy( &priv->ml_lock );
833 #ifndef NDEBUG /* Hack to dump leaked objects tree */
834 if( vlc_internals( p_libvlc )->i_refcount > 1 )
835 while( vlc_internals( p_libvlc )->i_refcount > 0 )
836 vlc_object_release( p_libvlc );
839 assert( vlc_internals( p_libvlc )->i_refcount == 1 );
840 vlc_object_release( p_libvlc );
844 * Add an interface plugin and run it
846 int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module )
851 if( !psz_module ) /* requesting the default interface */
853 char *psz_interface = var_CreateGetNonEmptyString( p_libvlc, "intf" );
854 if( !psz_interface ) /* "intf" has not been set */
859 * We prefer the dummy interface if none is specified. */
860 psz_module = "dummy";
863 msg_Info( p_libvlc, "%s",
864 _("Running vlc with the default interface. "
865 "Use 'cvlc' to use vlc without interface.") );
867 free( psz_interface );
868 var_Destroy( p_libvlc, "intf" );
871 /* Try to create the interface */
872 int ret = intf_Create( p_libvlc, psz_module ? psz_module : "$intf" );
874 msg_Err( p_libvlc, "interface \"%s\" initialization failed",
875 psz_module ? psz_module : "default" );
879 #if defined( ENABLE_NLS ) && (defined (__APPLE__) || defined (WIN32)) && \
880 ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
881 /*****************************************************************************
882 * SetLanguage: set the interface language.
883 *****************************************************************************
884 * We set the LC_MESSAGES locale category for interface messages and buttons,
885 * as well as the LC_CTYPE category for string sorting and possible wide
887 *****************************************************************************/
888 static void SetLanguage ( const char *psz_lang )
891 /* I need that under Darwin, please check it doesn't disturb
892 * other platforms. --Meuuh */
893 setenv( "LANG", psz_lang, 1 );
896 /* We set LC_ALL manually because it is the only way to set
897 * the language at runtime under eg. Windows. Beware that this
898 * makes the environment unconsistent when libvlc is unloaded and
899 * should probably be moved to a safer place like vlc.c. */
900 setenv( "LC_ALL", psz_lang, 1 );
904 setlocale( LC_ALL, psz_lang );
908 /*****************************************************************************
909 * GetFilenames: parse command line options which are not flags
910 *****************************************************************************
911 * Parse command line for input files as well as their associated options.
912 * An option always follows its associated input and begins with a ":".
913 *****************************************************************************/
914 static void GetFilenames( libvlc_int_t *p_vlc, unsigned n,
915 const char *const args[] )
919 /* Count the input options */
920 unsigned i_options = 0;
922 while( args[--n][0] == ':' )
927 msg_Warn( p_vlc, "options %s without item", args[n] );
928 return; /* syntax!? */
932 char *mrl = make_URI( args[n], NULL );
936 playlist_AddExt( pl_Get( p_vlc ), mrl, NULL, PLAYLIST_INSERT,
937 0, -1, i_options, ( i_options ? &args[n + 1] : NULL ),
938 VLC_INPUT_OPTION_TRUSTED, true, pl_Unlocked );
943 /*****************************************************************************
944 * ShowConsole: On Win32, create an output console for debug messages
945 *****************************************************************************
946 * This function is useful only on Win32.
947 *****************************************************************************/
949 static void ShowConsole( bool b_dofile )
954 if( getenv( "PWD" ) ) return; /* Cygwin shell or Wine */
957 /* Use the ANSI code page (e.g. Windows-1252) as expected by the LibVLC
958 * Unicode/locale subsystem. By default, we have the obsolecent OEM code
959 * page (e.g. CP437 or CP850). */
960 SetConsoleOutputCP (GetACP ());
961 SetConsoleTitle ("VLC media player version "PACKAGE_VERSION);
963 freopen( "CONOUT$", "w", stderr );
964 freopen( "CONIN$", "r", stdin );
966 if( b_dofile && (f_help = fopen( "vlc-help.txt", "wt" )) )
969 freopen( "vlc-help.txt", "wt", stdout );
970 utf8_fprintf( stderr, _("\nDumped content to vlc-help.txt file.\n") );
972 else freopen( "CONOUT$", "w", stdout );
978 /*****************************************************************************
979 * PauseConsole: On Win32, wait for a key press before closing the console
980 *****************************************************************************
981 * This function is useful only on Win32.
982 *****************************************************************************/
984 static void PauseConsole( void )
988 if( getenv( "PWD" ) ) return; /* Cygwin shell or Wine */
990 utf8_fprintf( stderr, _("\nPress the RETURN key to continue...\n") );