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 [] );
164 static void Help ( libvlc_int_t *, char const *psz_help_name );
165 static void Usage ( libvlc_int_t *, char const *psz_search );
166 static void ListModules ( libvlc_int_t *, bool );
167 static void Version ( void );
170 static void ShowConsole ( bool );
171 static void PauseConsole ( void );
173 static int ConsoleWidth ( void );
175 extern const char psz_vlc_changeset[];
178 * Allocate a libvlc instance, initialize global data if needed
179 * It also initializes the threading system
181 libvlc_int_t * libvlc_InternalCreate( void )
183 libvlc_int_t *p_libvlc;
185 char *psz_env = NULL;
187 /* Now that the thread system is initialized, we don't have much, but
188 * at least we have variables */
189 /* Allocate a libvlc instance object */
190 p_libvlc = vlc_custom_create( (vlc_object_t *)NULL, sizeof (*priv),
192 if( p_libvlc == NULL )
195 priv = libvlc_priv (p_libvlc);
196 priv->p_playlist = NULL;
198 priv->p_dialog_provider = NULL;
201 /* Find verbosity from VLC_VERBOSE environment variable */
202 psz_env = getenv( "VLC_VERBOSE" );
203 if( psz_env != NULL )
204 priv->i_verbose = atoi( psz_env );
207 #if defined( HAVE_ISATTY ) && !defined( WIN32 )
208 priv->b_color = isatty( 2 ); /* 2 is for stderr */
210 priv->b_color = false;
213 /* Initialize mutexes */
214 vlc_mutex_init( &priv->ml_lock );
215 vlc_mutex_init( &priv->timer_lock );
216 vlc_ExitInit( &priv->exit );
222 * Initialize a libvlc instance
223 * This function initializes a previously allocated libvlc instance:
225 * - gettext initialization
226 * - message queue, module bank and playlist initialization
227 * - configuration and commandline parsing
229 int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
230 const char *ppsz_argv[] )
232 libvlc_priv_t *priv = libvlc_priv (p_libvlc);
234 char * psz_modules = NULL;
235 char * psz_parser = NULL;
236 char * psz_control = NULL;
238 int i_ret = VLC_EEXIT;
239 playlist_t *p_playlist = NULL;
242 /* System specific initialization code */
245 /* Initialize the module bank and load the configuration of the
246 * main module. We need to do this at this stage to be able to display
247 * a short help if required by the user. (short help == main module
251 /* Get command line options that affect module loading. */
252 if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, NULL ) )
254 module_EndBank (false);
257 priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" );
259 /* Announce who we are (TODO: only first instance?) */
260 msg_Dbg( p_libvlc, "VLC media player - %s", VERSION_MESSAGE );
261 msg_Dbg( p_libvlc, "%s", COPYRIGHT_MESSAGE );
262 msg_Dbg( p_libvlc, "revision %s", psz_vlc_changeset );
263 msg_Dbg( p_libvlc, "configured with %s", CONFIGURE_LINE );
265 /* Load the builtins and plugins into the module_bank.
266 * We have to do it before config_Load*() because this also gets the
267 * list of configuration options exported by each module and loads their
269 size_t module_count = module_LoadPlugins (p_libvlc);
272 * Override default configuration with config file settings
274 if( !var_InheritBool( p_libvlc, "ignore-config" ) )
276 if( var_InheritBool( p_libvlc, "reset-config" ) )
277 config_SaveConfigFile( p_libvlc ); /* Save default config */
279 config_LoadConfigFile( p_libvlc );
283 * Override configuration with command line settings
286 if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, &vlc_optind ) )
289 ShowConsole( false );
290 /* Pause the console because it's destroyed when we exit */
291 fprintf( stderr, "The command line options couldn't be loaded, check "
292 "that they are valid.\n" );
295 module_EndBank (true);
298 priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" );
301 * Support for gettext
303 #if defined( ENABLE_NLS ) \
304 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
305 # if defined (WIN32) || defined (__APPLE__)
306 /* Check if the user specified a custom language */
307 char *lang = var_InheritString (p_libvlc, "language");
308 if (lang != NULL && strcmp (lang, "auto"))
312 vlc_bindtextdomain (PACKAGE_NAME);
314 /*xgettext: Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
315 msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") );
317 /* Check for short help option */
318 if( var_InheritBool( p_libvlc, "help" ) )
320 Help( p_libvlc, "help" );
322 i_ret = VLC_EEXITSUCCESS;
324 /* Check for version option */
325 else if( var_InheritBool( p_libvlc, "version" ) )
329 i_ret = VLC_EEXITSUCCESS;
332 /* Check for daemon mode */
333 #if !defined( WIN32 ) && !defined( __SYMBIAN32__ )
334 if( var_InheritBool( p_libvlc, "daemon" ) )
337 char *psz_pidfile = NULL;
339 if( daemon( 1, 0) != 0 )
341 msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
346 /* lets check if we need to write the pidfile */
347 psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
348 if( psz_pidfile != NULL )
351 pid_t i_pid = getpid ();
352 msg_Dbg( p_libvlc, "PID is %d, writing it to %s",
353 i_pid, psz_pidfile );
354 pidfile = vlc_fopen( psz_pidfile,"w" );
355 if( pidfile != NULL )
357 utf8_fprintf( pidfile, "%d", (int)i_pid );
362 msg_Err( p_libvlc, "cannot open pid file for writing: %s (%m)",
371 if( ( i_pid = fork() ) < 0 )
373 msg_Err( p_libvlc, "unable to fork vlc to daemon mode" );
378 /* This is the parent, exit right now */
379 msg_Dbg( p_libvlc, "closing parent process" );
381 i_ret = VLC_EEXITSUCCESS;
385 /* We are the child */
386 msg_Dbg( p_libvlc, "daemon spawned" );
387 close( STDIN_FILENO );
388 close( STDOUT_FILENO );
389 close( STDERR_FILENO );
399 module_EndBank (true);
403 /* Check for help on modules */
404 if( (p_tmp = var_InheritString( p_libvlc, "module" )) )
406 Help( p_libvlc, p_tmp );
409 i_ret = VLC_EEXITSUCCESS;
411 /* Check for full help option */
412 else if( var_InheritBool( p_libvlc, "full-help" ) )
414 var_Create( p_libvlc, "advanced", VLC_VAR_BOOL );
415 var_SetBool( p_libvlc, "advanced", true );
416 var_Create( p_libvlc, "help-verbose", VLC_VAR_BOOL );
417 var_SetBool( p_libvlc, "help-verbose", true );
418 Help( p_libvlc, "full-help" );
420 i_ret = VLC_EEXITSUCCESS;
422 /* Check for long help option */
423 else if( var_InheritBool( p_libvlc, "longhelp" ) )
425 Help( p_libvlc, "longhelp" );
427 i_ret = VLC_EEXITSUCCESS;
429 /* Check for module list option */
430 else if( var_InheritBool( p_libvlc, "list" ) )
432 ListModules( p_libvlc, false );
434 i_ret = VLC_EEXITSUCCESS;
436 else if( var_InheritBool( p_libvlc, "list-verbose" ) )
438 ListModules( p_libvlc, true );
440 i_ret = VLC_EEXITSUCCESS;
443 if( module_count <= 1 )
445 msg_Err( p_libvlc, "No plugins found! Check your VLC installation.");
452 module_EndBank (true);
456 /* FIXME: could be replaced by using Unix sockets */
458 dbus_threads_init_default();
460 if( var_InheritBool( p_libvlc, "one-instance" )
461 || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" )
462 && var_InheritBool( p_libvlc, "started-from-file" ) ) )
464 /* Initialise D-Bus interface, check for other instances */
465 DBusConnection *p_conn = NULL;
466 DBusError dbus_error;
468 dbus_error_init( &dbus_error );
470 /* connect to the session bus */
471 p_conn = dbus_bus_get( DBUS_BUS_SESSION, &dbus_error );
474 msg_Err( p_libvlc, "Failed to connect to D-Bus session daemon: %s",
475 dbus_error.message );
476 dbus_error_free( &dbus_error );
480 /* check if VLC is available on the bus
481 * if not: D-Bus control is not enabled on the other
482 * instance and we can't pass MRLs to it */
483 DBusMessage *p_test_msg = NULL;
484 DBusMessage *p_test_reply = NULL;
486 p_test_msg = dbus_message_new_method_call(
487 "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2",
488 "org.freedesktop.DBus.Introspectable", "Introspect" );
490 /* block until a reply arrives */
491 p_test_reply = dbus_connection_send_with_reply_and_block(
492 p_conn, p_test_msg, -1, &dbus_error );
493 dbus_message_unref( p_test_msg );
494 if( p_test_reply == NULL )
496 dbus_error_free( &dbus_error );
497 msg_Dbg( p_libvlc, "No Media Player is running. "
498 "Continuing normally." );
503 DBusMessage* p_dbus_msg = NULL;
504 DBusMessageIter dbus_args;
505 DBusPendingCall* p_dbus_pending = NULL;
508 dbus_message_unref( p_test_reply );
509 msg_Warn( p_libvlc, "Another Media Player is running. Exiting");
511 for( i_input = vlc_optind; i_input < i_argc;i_input++ )
513 /* Skip input options, we can't pass them through D-Bus */
514 if( ppsz_argv[i_input][0] == ':' )
516 msg_Warn( p_libvlc, "Ignoring option %s",
517 ppsz_argv[i_input] );
521 /* We need to resolve relative paths in this instance */
522 char *psz_mrl = make_URI( ppsz_argv[i_input], NULL );
523 const char *psz_after_track = "/";
525 if( psz_mrl == NULL )
527 msg_Dbg( p_libvlc, "Adds %s to the running Media Player",
530 p_dbus_msg = dbus_message_new_method_call(
531 "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2",
532 "org.mpris.MediaPlayer2.TrackList", "AddTrack" );
534 if ( NULL == p_dbus_msg )
536 msg_Err( p_libvlc, "D-Bus problem" );
543 dbus_message_iter_init_append( p_dbus_msg, &dbus_args );
544 if ( !dbus_message_iter_append_basic( &dbus_args,
545 DBUS_TYPE_STRING, &psz_mrl ) )
547 dbus_message_unref( p_dbus_msg );
554 if( !dbus_message_iter_append_basic( &dbus_args,
555 DBUS_TYPE_OBJECT_PATH, &psz_after_track ) )
557 dbus_message_unref( p_dbus_msg );
563 if( var_InheritBool( p_libvlc, "playlist-enqueue" ) )
566 if ( !dbus_message_iter_append_basic( &dbus_args,
567 DBUS_TYPE_BOOLEAN, &b_play ) )
569 dbus_message_unref( p_dbus_msg );
574 /* send message and get a handle for a reply */
575 if ( !dbus_connection_send_with_reply ( p_conn,
576 p_dbus_msg, &p_dbus_pending, -1 ) )
578 msg_Err( p_libvlc, "D-Bus problem" );
579 dbus_message_unref( p_dbus_msg );
584 if ( NULL == p_dbus_pending )
586 msg_Err( p_libvlc, "D-Bus problem" );
587 dbus_message_unref( p_dbus_msg );
591 dbus_connection_flush( p_conn );
592 dbus_message_unref( p_dbus_msg );
593 /* block until we receive a reply */
594 dbus_pending_call_block( p_dbus_pending );
595 dbus_pending_call_unref( p_dbus_pending );
596 } /* processes all command line MRLs */
603 /* we unreference the connection when we've finished with it */
604 if( p_conn ) dbus_connection_unref( p_conn );
609 * Message queue options
611 /* Last chance to set the verbosity. Once we start interfaces and other
612 * threads, verbosity becomes read-only. */
613 var_Create( p_libvlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
614 if( var_InheritBool( p_libvlc, "quiet" ) )
616 var_SetInteger( p_libvlc, "verbose", -1 );
617 priv->i_verbose = -1;
619 vlc_threads_setup( p_libvlc );
622 priv->b_color = var_InheritBool( p_libvlc, "color" );
624 vlc_CPU_dump( VLC_OBJECT(p_libvlc) );
626 * Choose the best memcpy module
628 priv->p_memcpy_module = module_need( p_libvlc, "memcpy", "$memcpy", false );
629 /* Avoid being called "memcpy":*/
630 vlc_object_set_name( p_libvlc, "main" );
632 priv->b_stats = var_InheritBool( p_libvlc, "stats" );
634 priv->pp_timers = NULL;
637 * Initialize hotkey handling
639 priv->actions = vlc_InitActions( p_libvlc );
641 /* Create a variable for showing the fullscreen interface */
642 var_Create( p_libvlc, "intf-show", VLC_VAR_BOOL );
643 var_SetBool( p_libvlc, "intf-show", true );
645 /* Create a variable for showing the right click menu */
646 var_Create( p_libvlc, "intf-popupmenu", VLC_VAR_BOOL );
648 /* variables for signalling creation of new files */
649 var_Create( p_libvlc, "snapshot-file", VLC_VAR_STRING );
650 var_Create( p_libvlc, "record-file", VLC_VAR_STRING );
652 /* some default internal settings */
653 var_Create( p_libvlc, "window", VLC_VAR_STRING );
654 var_Create( p_libvlc, "user-agent", VLC_VAR_STRING );
655 var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" );
657 /* Initialize playlist and get commandline files */
658 p_playlist = playlist_Create( VLC_OBJECT(p_libvlc) );
661 msg_Err( p_libvlc, "playlist initialization failed" );
662 if( priv->p_memcpy_module != NULL )
664 module_unneed( p_libvlc, priv->p_memcpy_module );
666 module_EndBank (true);
670 /* System specific configuration */
671 system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );
673 #if defined(MEDIA_LIBRARY)
675 if( var_GetBool( p_libvlc, "load-media-library-on-startup" ) )
677 priv->p_ml = ml_Create( VLC_OBJECT( p_libvlc ), NULL );
680 msg_Err( p_libvlc, "ML initialization failed" );
690 /* Add service discovery modules */
691 psz_modules = var_InheritString( p_libvlc, "services-discovery" );
694 char *p = psz_modules, *m;
695 while( ( m = strsep( &p, " :," ) ) != NULL )
696 playlist_ServicesDiscoveryAdd( p_playlist, m );
701 /* Initialize VLM if vlm-conf is specified */
702 psz_parser = var_CreateGetNonEmptyString( p_libvlc, "vlm-conf" );
705 priv->p_vlm = vlm_New( p_libvlc );
707 msg_Err( p_libvlc, "VLM initialization failed" );
713 * Load background interfaces
715 psz_modules = var_CreateGetNonEmptyString( p_libvlc, "extraintf" );
716 psz_control = var_CreateGetNonEmptyString( p_libvlc, "control" );
718 if( psz_modules && psz_control )
721 if( asprintf( &psz_tmp, "%s:%s", psz_modules, psz_control ) != -1 )
724 psz_modules = psz_tmp;
727 else if( psz_control )
730 psz_modules = strdup( psz_control );
733 psz_parser = psz_modules;
734 while ( psz_parser && *psz_parser )
736 char *psz_module, *psz_temp;
737 psz_module = psz_parser;
738 psz_parser = strchr( psz_module, ':' );
744 if( asprintf( &psz_temp, "%s,none", psz_module ) != -1)
746 intf_Create( p_libvlc, psz_temp );
754 * Always load the hotkeys interface if it exists
756 intf_Create( p_libvlc, "hotkeys,none" );
759 /* loads dbus control interface if in one-instance mode
760 * we do it only when playlist exists, because dbus module needs it */
761 if( var_InheritBool( p_libvlc, "one-instance" )
762 || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" )
763 && var_InheritBool( p_libvlc, "started-from-file" ) ) )
764 intf_Create( p_libvlc, "dbus,none" );
766 # if !defined (HAVE_MAEMO)
767 /* Prevents the power management daemon from suspending the system
768 * when VLC is active */
769 if( var_InheritBool( p_libvlc, "inhibit" ) > 0 )
770 intf_Create( p_libvlc, "inhibit,none" );
774 if( var_InheritBool( p_libvlc, "file-logging" ) &&
775 !var_InheritBool( p_libvlc, "syslog" ) )
777 intf_Create( p_libvlc, "logger,none" );
780 if( var_InheritBool( p_libvlc, "syslog" ) )
782 char *logmode = var_CreateGetNonEmptyString( p_libvlc, "logmode" );
783 var_SetString( p_libvlc, "logmode", "syslog" );
784 intf_Create( p_libvlc, "logger,none" );
788 var_SetString( p_libvlc, "logmode", logmode );
791 var_Destroy( p_libvlc, "logmode" );
795 if( var_InheritBool( p_libvlc, "network-synchronisation") )
797 intf_Create( p_libvlc, "netsync,none" );
801 var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER );
802 var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER );
803 var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER );
804 var_Create( p_libvlc, "drawable-view-right", VLC_VAR_INTEGER );
805 var_Create( p_libvlc, "drawable-clip-top", VLC_VAR_INTEGER );
806 var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER );
807 var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER );
808 var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER );
809 var_Create( p_libvlc, "drawable-nsobject", VLC_VAR_ADDRESS );
812 var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_INTEGER );
816 * Get input filenames given as commandline arguments.
817 * We assume that the remaining parameters are filenames
818 * and their input options.
820 GetFilenames( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );
823 * Get --open argument
825 psz_val = var_InheritString( p_libvlc, "open" );
826 if ( psz_val != NULL )
828 playlist_AddExt( p_playlist, psz_val, NULL, PLAYLIST_INSERT, 0,
829 -1, 0, NULL, 0, true, pl_Unlocked );
837 * Cleanup a libvlc instance. The instance is not completely deallocated
838 * \param p_libvlc the instance to clean
840 void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
842 libvlc_priv_t *priv = libvlc_priv (p_libvlc);
843 playlist_t *p_playlist = libvlc_priv (p_libvlc)->p_playlist;
845 /* Deactivate the playlist */
846 msg_Dbg( p_libvlc, "deactivating the playlist" );
847 pl_Deactivate( p_libvlc );
849 /* Remove all services discovery */
850 msg_Dbg( p_libvlc, "removing all services discovery tasks" );
851 playlist_ServicesDiscoveryKillAll( p_playlist );
853 /* Ask the interfaces to stop and destroy them */
854 msg_Dbg( p_libvlc, "removing all interfaces" );
855 libvlc_Quit( p_libvlc );
856 intf_DestroyAll( p_libvlc );
859 /* Destroy VLM if created in libvlc_InternalInit */
862 vlm_Delete( priv->p_vlm );
866 #if defined(MEDIA_LIBRARY)
867 media_library_t* p_ml = priv->p_ml;
870 ml_Destroy( VLC_OBJECT( p_ml ) );
871 vlc_object_release( p_ml );
872 libvlc_priv(p_playlist->p_libvlc)->p_ml = NULL;
876 /* Free playlist now, all threads are gone */
877 playlist_Destroy( p_playlist );
878 stats_TimersDumpAll( p_libvlc );
879 stats_TimersCleanAll( p_libvlc );
881 msg_Dbg( p_libvlc, "removing stats" );
884 char* psz_pidfile = NULL;
888 psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
889 if( psz_pidfile != NULL )
891 msg_Dbg( p_libvlc, "removing pid file %s", psz_pidfile );
892 if( unlink( psz_pidfile ) == -1 )
894 msg_Dbg( p_libvlc, "removing pid file %s: %m",
902 if( priv->p_memcpy_module )
904 module_unneed( p_libvlc, priv->p_memcpy_module );
905 priv->p_memcpy_module = NULL;
908 /* Save the configuration */
909 if( !var_InheritBool( p_libvlc, "ignore-config" ) )
910 config_AutoSaveConfigFile( VLC_OBJECT(p_libvlc) );
912 /* Free module bank. It is refcounted, so we call this each time */
913 module_EndBank (true);
915 vlc_DeinitActions( p_libvlc, priv->actions );
919 * Destroy everything.
920 * This function requests the running threads to finish, waits for their
921 * termination, and destroys their structure.
922 * It stops the thread systems: no instance can run after this has run
923 * \param p_libvlc the instance to destroy
925 void libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
927 libvlc_priv_t *priv = libvlc_priv( p_libvlc );
931 /* Destroy mutexes */
932 vlc_ExitDestroy( &priv->exit );
933 vlc_mutex_destroy( &priv->timer_lock );
934 vlc_mutex_destroy( &priv->ml_lock );
936 #ifndef NDEBUG /* Hack to dump leaked objects tree */
937 if( vlc_internals( p_libvlc )->i_refcount > 1 )
938 while( vlc_internals( p_libvlc )->i_refcount > 0 )
939 vlc_object_release( p_libvlc );
942 assert( vlc_internals( p_libvlc )->i_refcount == 1 );
943 vlc_object_release( p_libvlc );
947 * Add an interface plugin and run it
949 int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module )
954 if( !psz_module ) /* requesting the default interface */
956 char *psz_interface = var_CreateGetNonEmptyString( p_libvlc, "intf" );
957 if( !psz_interface ) /* "intf" has not been set */
962 * We prefer the dummy interface if none is specified. */
963 psz_module = "dummy";
966 msg_Info( p_libvlc, "%s",
967 _("Running vlc with the default interface. "
968 "Use 'cvlc' to use vlc without interface.") );
970 free( psz_interface );
971 var_Destroy( p_libvlc, "intf" );
974 /* Try to create the interface */
975 int ret = intf_Create( p_libvlc, psz_module ? psz_module : "$intf" );
977 msg_Err( p_libvlc, "interface \"%s\" initialization failed",
978 psz_module ? psz_module : "default" );
982 #if defined( ENABLE_NLS ) && (defined (__APPLE__) || defined (WIN32)) && \
983 ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
984 /*****************************************************************************
985 * SetLanguage: set the interface language.
986 *****************************************************************************
987 * We set the LC_MESSAGES locale category for interface messages and buttons,
988 * as well as the LC_CTYPE category for string sorting and possible wide
990 *****************************************************************************/
991 static void SetLanguage ( const char *psz_lang )
994 /* I need that under Darwin, please check it doesn't disturb
995 * other platforms. --Meuuh */
996 setenv( "LANG", psz_lang, 1 );
999 /* We set LC_ALL manually because it is the only way to set
1000 * the language at runtime under eg. Windows. Beware that this
1001 * makes the environment unconsistent when libvlc is unloaded and
1002 * should probably be moved to a safer place like vlc.c. */
1003 setenv( "LC_ALL", psz_lang, 1 );
1007 setlocale( LC_ALL, psz_lang );
1011 /*****************************************************************************
1012 * GetFilenames: parse command line options which are not flags
1013 *****************************************************************************
1014 * Parse command line for input files as well as their associated options.
1015 * An option always follows its associated input and begins with a ":".
1016 *****************************************************************************/
1017 static void GetFilenames( libvlc_int_t *p_vlc, unsigned n,
1018 const char *const args[] )
1022 /* Count the input options */
1023 unsigned i_options = 0;
1025 while( args[--n][0] == ':' )
1030 msg_Warn( p_vlc, "options %s without item", args[n] );
1031 return; /* syntax!? */
1035 char *mrl = make_URI( args[n], NULL );
1039 playlist_AddExt( pl_Get( p_vlc ), mrl, NULL, PLAYLIST_INSERT,
1040 0, -1, i_options, ( i_options ? &args[n + 1] : NULL ),
1041 VLC_INPUT_OPTION_TRUSTED, true, pl_Unlocked );
1046 /*****************************************************************************
1047 * Help: print program help
1048 *****************************************************************************
1049 * Print a short inline help. Message interface is initialized at this stage.
1050 *****************************************************************************/
1051 static inline void print_help_on_full_help( void )
1053 utf8_fprintf( stdout, "\n" );
1054 utf8_fprintf( stdout, "%s\n", _("To get exhaustive help, use '-H'.") );
1057 static const char vlc_usage[] = N_(
1058 "Usage: %s [options] [stream] ..."
1059 "\nYou can specify multiple streams on the commandline. They will be enqueued in the playlist."
1060 "\nThe first item specified will be played first."
1063 "\n --option A global option that is set for the duration of the program."
1064 "\n -option A single letter version of a global --option."
1065 "\n :option An option that only applies to the stream directly before it"
1066 "\n and that overrides previous settings."
1068 "\nStream MRL syntax:"
1069 "\n [[access][/demux]://]URL[@[title][:chapter][-[title][:chapter]]] [:option=value ...]"
1071 "\n Many of the global --options can also be used as MRL specific :options."
1072 "\n Multiple :option=value pairs can be specified."
1075 "\n [file://]filename Plain media file"
1076 "\n http://ip:port/file HTTP URL"
1077 "\n ftp://ip:port/file FTP URL"
1078 "\n mms://ip:port/file MMS URL"
1079 "\n screen:// Screen capture"
1080 "\n [dvd://][device][@raw_device] DVD device"
1081 "\n [vcd://][device] VCD device"
1082 "\n [cdda://][device] Audio CD device"
1083 "\n udp://[[<source address>]@[<bind address>][:<bind port>]]"
1084 "\n UDP stream sent by a streaming server"
1085 "\n vlc://pause:<seconds> Special item to pause the playlist for a certain time"
1086 "\n vlc://quit Special item to quit VLC"
1089 static void Help( libvlc_int_t *p_this, char const *psz_help_name )
1092 ShowConsole( true );
1095 if( psz_help_name && !strcmp( psz_help_name, "help" ) )
1097 utf8_fprintf( stdout, vlc_usage, "vlc" );
1098 Usage( p_this, "=help" );
1099 Usage( p_this, "=main" );
1100 print_help_on_full_help();
1102 else if( psz_help_name && !strcmp( psz_help_name, "longhelp" ) )
1104 utf8_fprintf( stdout, vlc_usage, "vlc" );
1105 Usage( p_this, NULL );
1106 print_help_on_full_help();
1108 else if( psz_help_name && !strcmp( psz_help_name, "full-help" ) )
1110 utf8_fprintf( stdout, vlc_usage, "vlc" );
1111 Usage( p_this, NULL );
1113 else if( psz_help_name )
1115 Usage( p_this, psz_help_name );
1118 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1124 /*****************************************************************************
1125 * Usage: print module usage
1126 *****************************************************************************
1127 * Print a short inline help. Message interface is initialized at this stage.
1128 *****************************************************************************/
1129 # define COL(x) "\033[" #x ";1m"
1130 # define RED COL(31)
1131 # define GREEN COL(32)
1132 # define YELLOW COL(33)
1133 # define BLUE COL(34)
1134 # define MAGENTA COL(35)
1135 # define CYAN COL(36)
1136 # define WHITE COL(0)
1137 # define GRAY "\033[0m"
1139 print_help_section( const module_t *m, const module_config_t *p_item,
1140 bool b_color, bool b_description )
1142 if( !p_item ) return;
1145 utf8_fprintf( stdout, RED" %s:\n"GRAY,
1146 module_gettext( m, p_item->psz_text ) );
1147 if( b_description && p_item->psz_longtext )
1148 utf8_fprintf( stdout, MAGENTA" %s\n"GRAY,
1149 module_gettext( m, p_item->psz_longtext ) );
1153 utf8_fprintf( stdout, " %s:\n",
1154 module_gettext( m, p_item->psz_text ) );
1155 if( b_description && p_item->psz_longtext )
1156 utf8_fprintf( stdout, " %s\n",
1157 module_gettext(m, p_item->psz_longtext ) );
1161 static void Usage( libvlc_int_t *p_this, char const *psz_search )
1163 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
1164 /* short option ------' | | | | | | |
1165 * option name ------------' | | | | | |
1166 * <bra ---------------------' | | | | |
1167 * option type or "" ----------' | | | |
1168 * ket> -------------------------' | | |
1169 * padding spaces -----------------' | |
1170 * comment --------------------------' |
1171 * comment suffix ---------------------'
1173 * The purpose of having bra and ket is that we might i18n them as well.
1176 #define COLOR_FORMAT_STRING (WHITE" %s --%s"YELLOW"%s%s%s%s%s%s "GRAY)
1177 #define COLOR_FORMAT_STRING_BOOL (WHITE" %s --%s%s%s%s%s%s%s "GRAY)
1179 #define LINE_START 8
1180 #define PADDING_SPACES 25
1182 # define OPTION_VALUE_SEP "="
1184 # define OPTION_VALUE_SEP " "
1186 char psz_spaces_text[PADDING_SPACES+LINE_START+1];
1187 char psz_spaces_longtext[LINE_START+3];
1188 char psz_format[sizeof(COLOR_FORMAT_STRING)];
1189 char psz_format_bool[sizeof(COLOR_FORMAT_STRING_BOOL)];
1190 char psz_buffer[10000];
1192 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
1193 int i_width_description = i_width + PADDING_SPACES - 1;
1194 bool b_advanced = var_InheritBool( p_this, "advanced" );
1195 bool b_description = var_InheritBool( p_this, "help-verbose" );
1196 bool b_description_hack;
1197 bool b_color = var_InheritBool( p_this, "color" );
1198 bool b_has_advanced = false;
1199 bool b_found = false;
1200 int i_only_advanced = 0; /* Number of modules ignored because they
1201 * only have advanced options */
1202 bool b_strict = psz_search && *psz_search == '=';
1203 if( b_strict ) psz_search++;
1205 memset( psz_spaces_text, ' ', PADDING_SPACES+LINE_START );
1206 psz_spaces_text[PADDING_SPACES+LINE_START] = '\0';
1207 memset( psz_spaces_longtext, ' ', LINE_START+2 );
1208 psz_spaces_longtext[LINE_START+2] = '\0';
1212 b_color = false; // don't put color control codes in a .txt file
1216 strcpy( psz_format, COLOR_FORMAT_STRING );
1217 strcpy( psz_format_bool, COLOR_FORMAT_STRING_BOOL );
1221 strcpy( psz_format, FORMAT_STRING );
1222 strcpy( psz_format_bool, FORMAT_STRING );
1225 /* List all modules */
1226 module_t **list = module_list_get (NULL);
1230 /* Ugly hack to make sure that the help options always come first
1233 Usage( p_this, "help" );
1235 /* Enumerate the config for each module */
1236 for (size_t i = 0; list[i]; i++)
1239 module_t *p_parser = list[i];
1240 module_config_t *p_item = NULL;
1241 module_config_t *p_section = NULL;
1242 module_config_t *p_end = p_parser->p_config + p_parser->confsize;
1243 const char *objname = module_get_object (p_parser);
1246 ( b_strict ? strcmp( objname, psz_search )
1247 : !strstr( objname, psz_search ) ) )
1249 char *const *pp_shortcuts = p_parser->pp_shortcuts;
1251 for( i = 0; i < p_parser->i_shortcuts; i++ )
1253 if( b_strict ? !strcmp( psz_search, pp_shortcuts[i] )
1254 : !!strstr( pp_shortcuts[i], psz_search ) )
1257 if( i == p_parser->i_shortcuts )
1261 /* Ignore modules without config options */
1262 if( !p_parser->i_config_items )
1267 b_help_module = !strcmp( "help", objname );
1268 /* Ugly hack to make sure that the help options always come first
1270 if( !psz_search && b_help_module )
1273 /* Ignore modules with only advanced config options if requested */
1276 for( p_item = p_parser->p_config;
1280 if( CONFIG_ITEM(p_item->i_type) &&
1281 !p_item->b_advanced && !p_item->b_removed ) break;
1284 if( p_item == p_end )
1293 /* Print name of module */
1294 if( strcmp( "main", objname ) )
1297 utf8_fprintf( stdout, "\n " GREEN "%s" GRAY " (%s)\n",
1298 module_gettext( p_parser, p_parser->psz_longname ),
1301 utf8_fprintf( stdout, "\n %s\n",
1302 module_gettext(p_parser, p_parser->psz_longname ) );
1304 if( p_parser->psz_help )
1307 utf8_fprintf( stdout, CYAN" %s\n"GRAY,
1308 module_gettext( p_parser, p_parser->psz_help ) );
1310 utf8_fprintf( stdout, " %s\n",
1311 module_gettext( p_parser, p_parser->psz_help ) );
1314 /* Print module options */
1315 for( p_item = p_parser->p_config;
1319 char *psz_text, *psz_spaces = psz_spaces_text;
1320 const char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1321 const char *psz_suf = "", *psz_prefix = NULL;
1325 /* Skip removed options */
1326 if( p_item->b_removed )
1330 /* Skip advanced options if requested */
1331 if( p_item->b_advanced && !b_advanced )
1333 b_has_advanced = true;
1337 switch( CONFIG_CLASS(p_item->i_type) )
1339 case 0: // hint class
1340 switch( p_item->i_type )
1342 case CONFIG_HINT_CATEGORY:
1343 case CONFIG_HINT_USAGE:
1344 if( !strcmp( "main", objname ) )
1347 utf8_fprintf( stdout, GREEN "\n %s\n" GRAY,
1348 module_gettext( p_parser, p_item->psz_text ) );
1350 utf8_fprintf( stdout, "\n %s\n",
1351 module_gettext( p_parser, p_item->psz_text ) );
1353 if( b_description && p_item->psz_longtext )
1356 utf8_fprintf( stdout, CYAN " %s\n" GRAY,
1357 module_gettext( p_parser, p_item->psz_longtext ) );
1359 utf8_fprintf( stdout, " %s\n",
1360 module_gettext( p_parser, p_item->psz_longtext ) );
1364 case CONFIG_HINT_SUBCATEGORY:
1365 if( strcmp( "main", objname ) )
1367 case CONFIG_SECTION:
1373 case CONFIG_ITEM_STRING:
1374 print_help_section( p_parser, p_section, b_color,
1377 psz_bra = OPTION_VALUE_SEP "<";
1378 psz_type = _("string");
1381 if( p_item->ppsz_list )
1383 psz_bra = OPTION_VALUE_SEP "{";
1384 psz_type = psz_buffer;
1385 psz_buffer[0] = '\0';
1386 for( i = 0; p_item->ppsz_list[i]; i++ )
1388 if( i ) strcat( psz_buffer, "," );
1389 strcat( psz_buffer, p_item->ppsz_list[i] );
1394 case CONFIG_ITEM_INTEGER:
1395 print_help_section( p_parser, p_section, b_color,
1398 psz_bra = OPTION_VALUE_SEP "<";
1399 psz_type = _("integer");
1402 if( p_item->min.i || p_item->max.i )
1404 sprintf( psz_buffer, "%s [%"PRId64" .. %"PRId64"]",
1405 psz_type, p_item->min.i, p_item->max.i );
1406 psz_type = psz_buffer;
1409 if( p_item->i_list )
1411 psz_bra = OPTION_VALUE_SEP "{";
1412 psz_type = psz_buffer;
1413 psz_buffer[0] = '\0';
1414 for( i = 0; p_item->ppsz_list_text[i]; i++ )
1416 if( i ) strcat( psz_buffer, ", " );
1417 sprintf( psz_buffer + strlen(psz_buffer), "%i (%s)",
1419 module_gettext( p_parser, p_item->ppsz_list_text[i] ) );
1424 case CONFIG_ITEM_FLOAT:
1425 print_help_section( p_parser, p_section, b_color,
1428 psz_bra = OPTION_VALUE_SEP "<";
1429 psz_type = _("float");
1431 if( p_item->min.f || p_item->max.f )
1433 sprintf( psz_buffer, "%s [%f .. %f]", psz_type,
1434 p_item->min.f, p_item->max.f );
1435 psz_type = psz_buffer;
1438 case CONFIG_ITEM_BOOL:
1439 print_help_section( p_parser, p_section, b_color,
1442 psz_bra = ""; psz_type = ""; psz_ket = "";
1443 if( !b_help_module )
1445 psz_suf = p_item->value.i ? _(" (default enabled)") :
1446 _(" (default disabled)");
1456 /* Add short option if any */
1457 if( p_item->i_short )
1459 sprintf( psz_short, "-%c,", p_item->i_short );
1463 strcpy( psz_short, " " );
1466 i = PADDING_SPACES - strlen( p_item->psz_name )
1467 - strlen( psz_bra ) - strlen( psz_type )
1468 - strlen( psz_ket ) - 1;
1470 if( CONFIG_CLASS(p_item->i_type) == CONFIG_ITEM_BOOL
1473 psz_prefix = ", --no-";
1474 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
1479 psz_spaces[0] = '\n';
1484 psz_spaces[i] = '\0';
1487 if( CONFIG_CLASS(p_item->i_type) == CONFIG_ITEM_BOOL
1490 utf8_fprintf( stdout, psz_format_bool, psz_short,
1491 p_item->psz_name, psz_prefix, p_item->psz_name,
1492 psz_bra, psz_type, psz_ket, psz_spaces );
1496 utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1497 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
1500 psz_spaces[i] = ' ';
1502 /* We wrap the rest of the output */
1503 sprintf( psz_buffer, "%s%s", module_gettext( p_parser, p_item->psz_text ),
1505 b_description_hack = b_description;
1508 psz_text = psz_buffer;
1509 i_cur_width = b_description && !b_description_hack
1510 ? i_width_description
1512 if( !*psz_text ) strcpy(psz_text, " ");
1515 char *psz_parser, *psz_word;
1516 size_t i_end = strlen( psz_text );
1518 /* If the remaining text fits in a line, print it. */
1519 if( i_end <= i_cur_width )
1523 if( !b_description || b_description_hack )
1524 utf8_fprintf( stdout, BLUE"%s\n"GRAY, psz_text );
1526 utf8_fprintf( stdout, "%s\n", psz_text );
1530 utf8_fprintf( stdout, "%s\n", psz_text );
1535 /* Otherwise, eat as many words as possible */
1536 psz_parser = psz_text;
1539 psz_word = psz_parser;
1540 psz_parser = strchr( psz_word, ' ' );
1541 /* If no space was found, we reached the end of the text
1542 * block; otherwise, we skip the space we just found. */
1543 psz_parser = psz_parser ? psz_parser + 1
1546 } while( (size_t)(psz_parser - psz_text) <= i_cur_width );
1548 /* We cut a word in one of these cases:
1549 * - it's the only word in the line and it's too long.
1550 * - we used less than 80% of the width and the word we are
1551 * going to wrap is longer than 40% of the width, and even
1552 * if the word would have fit in the next line. */
1553 if( psz_word == psz_text
1554 || ( (size_t)(psz_word - psz_text) < 80 * i_cur_width / 100
1555 && (size_t)(psz_parser - psz_word) > 40 * i_cur_width / 100 ) )
1557 char c = psz_text[i_cur_width];
1558 psz_text[i_cur_width] = '\0';
1561 if( !b_description || b_description_hack )
1562 utf8_fprintf( stdout, BLUE"%s\n%s"GRAY,
1563 psz_text, psz_spaces );
1565 utf8_fprintf( stdout, "%s\n%s",
1566 psz_text, psz_spaces );
1570 utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
1572 psz_text += i_cur_width;
1577 psz_word[-1] = '\0';
1580 if( !b_description || b_description_hack )
1581 utf8_fprintf( stdout, BLUE"%s\n%s"GRAY,
1582 psz_text, psz_spaces );
1584 utf8_fprintf( stdout, "%s\n%s",
1585 psz_text, psz_spaces );
1589 utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
1591 psz_text = psz_word;
1595 if( b_description_hack && p_item->psz_longtext )
1597 sprintf( psz_buffer, "%s%s",
1598 module_gettext( p_parser, p_item->psz_longtext ),
1600 b_description_hack = false;
1601 psz_spaces = psz_spaces_longtext;
1602 utf8_fprintf( stdout, "%s", psz_spaces );
1608 if( b_has_advanced )
1611 utf8_fprintf( stdout, "\n" WHITE "%s" GRAY " %s\n", _( "Note:" ),
1612 _( "add --advanced to your command line to see advanced options."));
1614 utf8_fprintf( stdout, "\n%s %s\n", _( "Note:" ),
1615 _( "add --advanced to your command line to see advanced options."));
1618 if( i_only_advanced > 0 )
1622 utf8_fprintf( stdout, "\n" WHITE "%s" GRAY " ", _( "Note:" ) );
1623 utf8_fprintf( stdout, _( "%d module(s) were not displayed because they only have advanced options.\n" ), i_only_advanced );
1627 utf8_fprintf( stdout, "\n%s ", _( "Note:" ) );
1628 utf8_fprintf( stdout, _( "%d module(s) were not displayed because they only have advanced options.\n" ), i_only_advanced );
1634 utf8_fprintf( stdout, "\n" WHITE "%s" GRAY "\n",
1635 _( "No matching module found. Use --list or " \
1636 "--list-verbose to list available modules." ) );
1638 utf8_fprintf( stdout, "\n%s\n",
1639 _( "No matching module found. Use --list or " \
1640 "--list-verbose to list available modules." ) );
1643 /* Release the module list */
1644 module_list_free (list);
1647 /*****************************************************************************
1648 * ListModules: list the available modules with their description
1649 *****************************************************************************
1650 * Print a list of all available modules (builtins and plugins) and a short
1651 * description for each one.
1652 *****************************************************************************/
1653 static void ListModules( libvlc_int_t *p_this, bool b_verbose )
1657 bool b_color = var_InheritBool( p_this, "color" );
1660 ShowConsole( true );
1661 b_color = false; // don't put color control codes in a .txt file
1667 /* List all modules */
1668 module_t **list = module_list_get (NULL);
1670 /* Enumerate each module */
1671 for (size_t j = 0; (p_parser = list[j]) != NULL; j++)
1673 const char *objname = module_get_object (p_parser);
1675 utf8_fprintf( stdout, GREEN" %-22s "WHITE"%s\n"GRAY, objname,
1676 module_gettext( p_parser, p_parser->psz_longname ) );
1678 utf8_fprintf( stdout, " %-22s %s\n", objname,
1679 module_gettext( p_parser, p_parser->psz_longname ) );
1683 char *const *pp_shortcuts = p_parser->pp_shortcuts;
1684 for( unsigned i = 0; i < p_parser->i_shortcuts; i++ )
1686 if( strcmp( pp_shortcuts[i], objname ) )
1689 utf8_fprintf( stdout, CYAN" s %s\n"GRAY,
1692 utf8_fprintf( stdout, " s %s\n",
1696 if( p_parser->psz_capability )
1699 utf8_fprintf( stdout, MAGENTA" c %s (%d)\n"GRAY,
1700 p_parser->psz_capability,
1701 p_parser->i_score );
1703 utf8_fprintf( stdout, " c %s (%d)\n",
1704 p_parser->psz_capability,
1705 p_parser->i_score );
1709 module_list_free (list);
1711 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1716 /*****************************************************************************
1717 * Version: print complete program version
1718 *****************************************************************************
1719 * Print complete program version and build number.
1720 *****************************************************************************/
1721 static void Version( void )
1724 ShowConsole( true );
1727 utf8_fprintf( stdout, _("VLC version %s (%s)\n"), VERSION_MESSAGE,
1728 psz_vlc_changeset );
1729 utf8_fprintf( stdout, _("Compiled by %s on %s (%s)\n"),
1730 VLC_CompileBy(), VLC_CompileHost(), __DATE__" "__TIME__ );
1731 utf8_fprintf( stdout, _("Compiler: %s\n"), VLC_Compiler() );
1732 utf8_fprintf( stdout, "%s", LICENSE_MSG );
1734 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1739 /*****************************************************************************
1740 * ShowConsole: On Win32, create an output console for debug messages
1741 *****************************************************************************
1742 * This function is useful only on Win32.
1743 *****************************************************************************/
1745 static void ShowConsole( bool b_dofile )
1748 FILE *f_help = NULL;
1750 if( getenv( "PWD" ) ) return; /* Cygwin shell or Wine */
1753 /* Use the ANSI code page (e.g. Windows-1252) as expected by the LibVLC
1754 * Unicode/locale subsystem. By default, we have the obsolecent OEM code
1755 * page (e.g. CP437 or CP850). */
1756 SetConsoleOutputCP (GetACP ());
1757 SetConsoleTitle ("VLC media player version "PACKAGE_VERSION);
1759 freopen( "CONOUT$", "w", stderr );
1760 freopen( "CONIN$", "r", stdin );
1762 if( b_dofile && (f_help = fopen( "vlc-help.txt", "wt" )) )
1765 freopen( "vlc-help.txt", "wt", stdout );
1766 utf8_fprintf( stderr, _("\nDumped content to vlc-help.txt file.\n") );
1768 else freopen( "CONOUT$", "w", stdout );
1774 /*****************************************************************************
1775 * PauseConsole: On Win32, wait for a key press before closing the console
1776 *****************************************************************************
1777 * This function is useful only on Win32.
1778 *****************************************************************************/
1780 static void PauseConsole( void )
1784 if( getenv( "PWD" ) ) return; /* Cygwin shell or Wine */
1786 utf8_fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
1794 /*****************************************************************************
1795 * ConsoleWidth: Return the console width in characters
1796 *****************************************************************************
1797 * We use the stty shell command to get the console width; if this fails or
1798 * if the width is less than 80, we default to 80.
1799 *****************************************************************************/
1800 static int ConsoleWidth( void )
1802 unsigned i_width = 80;
1805 FILE *file = popen( "stty size 2>/dev/null", "r" );
1808 if (fscanf (file, "%*u %u", &i_width) <= 0)
1812 #elif !defined (UNDER_CE)
1813 CONSOLE_SCREEN_BUFFER_INFO buf;
1815 if (GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &buf))
1816 i_width = buf.dwSize.X;