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 *****************************************************************************/
101 static unsigned i_instances = 0;
104 static bool b_daemon = false;
112 * Atomically set the reference count to 1.
113 * @param p_gc reference counted object
114 * @param pf_destruct destruction calback
117 void *vlc_gc_init (gc_object_t *p_gc, void (*pf_destruct) (gc_object_t *))
119 /* There is no point in using the GC if there is no destructor... */
120 assert (pf_destruct);
121 p_gc->pf_destructor = pf_destruct;
123 vlc_atomic_set (&p_gc->refs, 1);
128 * Atomically increment the reference count.
129 * @param p_gc reference counted object
132 void *vlc_hold (gc_object_t * p_gc)
137 refs = vlc_atomic_inc (&p_gc->refs);
138 assert (refs != 1); /* there had to be a reference already */
143 * Atomically decrement the reference count and, if it reaches zero, destroy.
144 * @param p_gc reference counted object.
146 void vlc_release (gc_object_t *p_gc)
151 refs = vlc_atomic_dec (&p_gc->refs);
152 assert (refs != (uintptr_t)(-1)); /* reference underflow?! */
154 p_gc->pf_destructor (p_gc);
157 /*****************************************************************************
159 *****************************************************************************/
160 #if defined( ENABLE_NLS ) && (defined (__APPLE__) || defined (WIN32)) && \
161 ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
162 static void SetLanguage ( char const * );
164 static void GetFilenames ( libvlc_int_t *, unsigned, const char *const [] );
165 static void Help ( libvlc_int_t *, char const *psz_help_name );
166 static void Usage ( libvlc_int_t *, char const *psz_search );
167 static void ListModules ( libvlc_int_t *, bool );
168 static void Version ( void );
171 static void ShowConsole ( bool );
172 static void PauseConsole ( void );
174 static int ConsoleWidth ( void );
176 static vlc_mutex_t global_lock = VLC_STATIC_MUTEX;
177 extern const char psz_vlc_changeset[];
180 * Allocate a libvlc instance, initialize global data if needed
181 * It also initializes the threading system
183 libvlc_int_t * libvlc_InternalCreate( void )
185 libvlc_int_t *p_libvlc;
187 char *psz_env = NULL;
189 /* Now that the thread system is initialized, we don't have much, but
190 * at least we have variables */
191 vlc_mutex_lock( &global_lock );
192 if( i_instances == 0 )
194 /* Guess what CPU we have */
195 cpu_flags = CPUCapabilities();
196 /* The module bank will be initialized later */
199 /* Allocate a libvlc instance object */
200 p_libvlc = vlc_custom_create( (vlc_object_t *)NULL, sizeof (*priv),
202 if( p_libvlc != NULL )
204 vlc_mutex_unlock( &global_lock );
206 if( p_libvlc == NULL )
209 priv = libvlc_priv (p_libvlc);
210 priv->p_playlist = NULL;
212 priv->p_dialog_provider = NULL;
215 /* Find verbosity from VLC_VERBOSE environment variable */
216 psz_env = getenv( "VLC_VERBOSE" );
217 if( psz_env != NULL )
218 priv->i_verbose = atoi( psz_env );
221 #if defined( HAVE_ISATTY ) && !defined( WIN32 )
222 priv->b_color = isatty( 2 ); /* 2 is for stderr */
224 priv->b_color = false;
227 /* Initialize mutexes */
228 vlc_mutex_init( &priv->ml_lock );
229 vlc_mutex_init( &priv->timer_lock );
230 vlc_ExitInit( &priv->exit );
236 * Initialize a libvlc instance
237 * This function initializes a previously allocated libvlc instance:
239 * - gettext initialization
240 * - message queue, module bank and playlist initialization
241 * - configuration and commandline parsing
243 int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
244 const char *ppsz_argv[] )
246 libvlc_priv_t *priv = libvlc_priv (p_libvlc);
248 char * psz_modules = NULL;
249 char * psz_parser = NULL;
250 char * psz_control = NULL;
252 int i_ret = VLC_EEXIT;
253 playlist_t *p_playlist = NULL;
255 #if defined( ENABLE_NLS ) \
256 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
257 # if defined (WIN32) || defined (__APPLE__)
262 /* System specific initialization code */
266 * Support for gettext
268 vlc_bindtextdomain (PACKAGE_NAME);
270 /* Initialize the module bank and load the configuration of the
271 * main module. We need to do this at this stage to be able to display
272 * a short help if required by the user. (short help == main module
276 if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, NULL ) )
278 module_EndBank (false);
282 priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" );
283 /* Announce who we are - Do it only for first instance ? */
284 msg_Dbg( p_libvlc, "VLC media player - %s", VERSION_MESSAGE );
285 msg_Dbg( p_libvlc, "%s", COPYRIGHT_MESSAGE );
286 msg_Dbg( p_libvlc, "revision %s", psz_vlc_changeset );
287 msg_Dbg( p_libvlc, "configured with %s", CONFIGURE_LINE );
288 /*xgettext: Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
289 msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") );
291 /* Check for short help option */
292 if( var_InheritBool( p_libvlc, "help" ) )
294 Help( p_libvlc, "help" );
296 i_ret = VLC_EEXITSUCCESS;
298 /* Check for version option */
299 else if( var_InheritBool( p_libvlc, "version" ) )
303 i_ret = VLC_EEXITSUCCESS;
306 /* Check for daemon mode */
307 #if !defined( WIN32 ) && !defined( __SYMBIAN32__ )
308 if( var_InheritBool( p_libvlc, "daemon" ) )
311 char *psz_pidfile = NULL;
313 if( daemon( 1, 0) != 0 )
315 msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
320 /* lets check if we need to write the pidfile */
321 psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
322 if( psz_pidfile != NULL )
325 pid_t i_pid = getpid ();
326 msg_Dbg( p_libvlc, "PID is %d, writing it to %s",
327 i_pid, psz_pidfile );
328 pidfile = vlc_fopen( psz_pidfile,"w" );
329 if( pidfile != NULL )
331 utf8_fprintf( pidfile, "%d", (int)i_pid );
336 msg_Err( p_libvlc, "cannot open pid file for writing: %s (%m)",
345 if( ( i_pid = fork() ) < 0 )
347 msg_Err( p_libvlc, "unable to fork vlc to daemon mode" );
352 /* This is the parent, exit right now */
353 msg_Dbg( p_libvlc, "closing parent process" );
355 i_ret = VLC_EEXITSUCCESS;
359 /* We are the child */
360 msg_Dbg( p_libvlc, "daemon spawned" );
361 close( STDIN_FILENO );
362 close( STDOUT_FILENO );
363 close( STDERR_FILENO );
373 module_EndBank (false);
377 /* Check for translation config option */
378 #if defined( ENABLE_NLS ) \
379 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
380 # if defined (WIN32) || defined (__APPLE__)
381 if( !var_InheritBool( p_libvlc, "ignore-config" ) )
382 config_LoadConfigFile( p_libvlc );
383 priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" );
385 /* Check if the user specified a custom language */
386 psz_language = var_CreateGetNonEmptyString( p_libvlc, "language" );
387 if( psz_language && strcmp( psz_language, "auto" ) )
389 /* Reset the default domain */
390 SetLanguage( psz_language );
392 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
393 msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") );
395 free( psz_language );
400 * Load the builtins and plugins into the module_bank.
401 * We have to do it before config_Load*() because this also gets the
402 * list of configuration options exported by each module and loads their
405 module_LoadPlugins( p_libvlc );
406 if( p_libvlc->b_die )
412 module_t **list = module_list_get( &module_count );
413 module_list_free( list );
414 msg_Dbg( p_libvlc, "module bank initialized (%zu modules)", module_count );
416 /* Check for help on modules */
417 if( (p_tmp = var_InheritString( p_libvlc, "module" )) )
419 Help( p_libvlc, p_tmp );
422 i_ret = VLC_EEXITSUCCESS;
424 /* Check for full help option */
425 else if( var_InheritBool( p_libvlc, "full-help" ) )
427 var_Create( p_libvlc, "advanced", VLC_VAR_BOOL );
428 var_SetBool( p_libvlc, "advanced", true );
429 var_Create( p_libvlc, "help-verbose", VLC_VAR_BOOL );
430 var_SetBool( p_libvlc, "help-verbose", true );
431 Help( p_libvlc, "full-help" );
433 i_ret = VLC_EEXITSUCCESS;
435 /* Check for long help option */
436 else if( var_InheritBool( p_libvlc, "longhelp" ) )
438 Help( p_libvlc, "longhelp" );
440 i_ret = VLC_EEXITSUCCESS;
442 /* Check for module list option */
443 else if( var_InheritBool( p_libvlc, "list" ) )
445 ListModules( p_libvlc, false );
447 i_ret = VLC_EEXITSUCCESS;
449 else if( var_InheritBool( p_libvlc, "list-verbose" ) )
451 ListModules( p_libvlc, true );
453 i_ret = VLC_EEXITSUCCESS;
456 if( module_count <= 1 )
458 msg_Err( p_libvlc, "No plugins found! Check your VLC installation.");
465 module_EndBank (true);
470 * Override default configuration with config file settings
472 if( !var_InheritBool( p_libvlc, "ignore-config" ) )
474 if( var_InheritBool( p_libvlc, "reset-config" ) )
476 config_ResetAll( p_libvlc );
477 config_SaveConfigFile( p_libvlc );
480 config_LoadConfigFile( p_libvlc );
484 * Override configuration with command line settings
487 if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, &vlc_optind ) )
490 ShowConsole( false );
491 /* Pause the console because it's destroyed when we exit */
492 fprintf( stderr, "The command line options couldn't be loaded, check "
493 "that they are valid.\n" );
496 module_EndBank (true);
499 priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" );
501 /* FIXME: could be replaced by using Unix sockets */
503 dbus_threads_init_default();
505 if( var_InheritBool( p_libvlc, "one-instance" )
506 || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" )
507 && var_InheritBool( p_libvlc, "started-from-file" ) ) )
509 /* Initialise D-Bus interface, check for other instances */
510 DBusConnection *p_conn = NULL;
511 DBusError dbus_error;
513 dbus_error_init( &dbus_error );
515 /* connect to the session bus */
516 p_conn = dbus_bus_get( DBUS_BUS_SESSION, &dbus_error );
519 msg_Err( p_libvlc, "Failed to connect to D-Bus session daemon: %s",
520 dbus_error.message );
521 dbus_error_free( &dbus_error );
525 /* check if VLC is available on the bus
526 * if not: D-Bus control is not enabled on the other
527 * instance and we can't pass MRLs to it */
528 DBusMessage *p_test_msg = NULL;
529 DBusMessage *p_test_reply = NULL;
531 p_test_msg = dbus_message_new_method_call(
532 "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2",
533 "org.freedesktop.DBus.Introspectable", "Introspect" );
535 /* block until a reply arrives */
536 p_test_reply = dbus_connection_send_with_reply_and_block(
537 p_conn, p_test_msg, -1, &dbus_error );
538 dbus_message_unref( p_test_msg );
539 if( p_test_reply == NULL )
541 dbus_error_free( &dbus_error );
542 msg_Dbg( p_libvlc, "No Media Player is running. "
543 "Continuing normally." );
548 DBusMessage* p_dbus_msg = NULL;
549 DBusMessageIter dbus_args;
550 DBusPendingCall* p_dbus_pending = NULL;
553 dbus_message_unref( p_test_reply );
554 msg_Warn( p_libvlc, "Another Media Player is running. Exiting");
556 for( i_input = vlc_optind; i_input < i_argc;i_input++ )
558 /* Skip input options, we can't pass them through D-Bus */
559 if( ppsz_argv[i_input][0] == ':' )
561 msg_Warn( p_libvlc, "Ignoring option %s",
562 ppsz_argv[i_input] );
566 /* We need to resolve relative paths in this instance */
567 char *psz_mrl = make_URI( ppsz_argv[i_input], NULL );
568 const char *psz_after_track = "/";
570 if( psz_mrl == NULL )
572 msg_Dbg( p_libvlc, "Adds %s to the running Media Player",
575 p_dbus_msg = dbus_message_new_method_call(
576 "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2",
577 "org.mpris.MediaPlayer2.TrackList", "AddTrack" );
579 if ( NULL == p_dbus_msg )
581 msg_Err( p_libvlc, "D-Bus problem" );
588 dbus_message_iter_init_append( p_dbus_msg, &dbus_args );
589 if ( !dbus_message_iter_append_basic( &dbus_args,
590 DBUS_TYPE_STRING, &psz_mrl ) )
592 dbus_message_unref( p_dbus_msg );
599 if( !dbus_message_iter_append_basic( &dbus_args,
600 DBUS_TYPE_OBJECT_PATH, &psz_after_track ) )
602 dbus_message_unref( p_dbus_msg );
608 if( var_InheritBool( p_libvlc, "playlist-enqueue" ) )
611 if ( !dbus_message_iter_append_basic( &dbus_args,
612 DBUS_TYPE_BOOLEAN, &b_play ) )
614 dbus_message_unref( p_dbus_msg );
619 /* send message and get a handle for a reply */
620 if ( !dbus_connection_send_with_reply ( p_conn,
621 p_dbus_msg, &p_dbus_pending, -1 ) )
623 msg_Err( p_libvlc, "D-Bus problem" );
624 dbus_message_unref( p_dbus_msg );
629 if ( NULL == p_dbus_pending )
631 msg_Err( p_libvlc, "D-Bus problem" );
632 dbus_message_unref( p_dbus_msg );
636 dbus_connection_flush( p_conn );
637 dbus_message_unref( p_dbus_msg );
638 /* block until we receive a reply */
639 dbus_pending_call_block( p_dbus_pending );
640 dbus_pending_call_unref( p_dbus_pending );
641 } /* processes all command line MRLs */
648 /* we unreference the connection when we've finished with it */
649 if( p_conn ) dbus_connection_unref( p_conn );
654 * Message queue options
656 /* Last chance to set the verbosity. Once we start interfaces and other
657 * threads, verbosity becomes read-only. */
658 var_Create( p_libvlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
659 if( var_InheritBool( p_libvlc, "quiet" ) )
661 var_SetInteger( p_libvlc, "verbose", -1 );
662 priv->i_verbose = -1;
664 vlc_threads_setup( p_libvlc );
667 priv->b_color = var_InheritBool( p_libvlc, "color" );
669 char p_capabilities[200];
670 #define PRINT_CAPABILITY( capability, string ) \
671 if( vlc_CPU() & capability ) \
673 strncat( p_capabilities, string " ", \
674 sizeof(p_capabilities) - strlen(p_capabilities) ); \
675 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
677 p_capabilities[0] = '\0';
679 #if defined( __i386__ ) || defined( __x86_64__ )
680 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
681 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
682 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
683 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
684 PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" );
685 PRINT_CAPABILITY( CPU_CAPABILITY_SSE3, "SSE3" );
686 PRINT_CAPABILITY( CPU_CAPABILITY_SSSE3, "SSSE3" );
687 PRINT_CAPABILITY( CPU_CAPABILITY_SSE4_1, "SSE4.1" );
688 PRINT_CAPABILITY( CPU_CAPABILITY_SSE4_2, "SSE4.2" );
689 PRINT_CAPABILITY( CPU_CAPABILITY_SSE4A, "SSE4A" );
691 #elif defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
692 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
694 #elif defined( __arm__ )
695 PRINT_CAPABILITY( CPU_CAPABILITY_NEON, "NEONv1" );
700 strncat( p_capabilities, "FPU ",
701 sizeof(p_capabilities) - strlen( p_capabilities) );
702 p_capabilities[sizeof(p_capabilities) - 1] = '\0';
705 if (p_capabilities[0])
706 msg_Dbg( p_libvlc, "CPU has capabilities %s", p_capabilities );
709 * Choose the best memcpy module
711 priv->p_memcpy_module = module_need( p_libvlc, "memcpy", "$memcpy", false );
712 /* Avoid being called "memcpy":*/
713 vlc_object_set_name( p_libvlc, "main" );
715 priv->b_stats = var_InheritBool( p_libvlc, "stats" );
717 priv->pp_timers = NULL;
720 * Initialize hotkey handling
722 priv->actions = vlc_InitActions( p_libvlc );
724 /* Create a variable for showing the fullscreen interface */
725 var_Create( p_libvlc, "intf-show", VLC_VAR_BOOL );
726 var_SetBool( p_libvlc, "intf-show", true );
728 /* Create a variable for showing the right click menu */
729 var_Create( p_libvlc, "intf-popupmenu", VLC_VAR_BOOL );
731 /* variables for signalling creation of new files */
732 var_Create( p_libvlc, "snapshot-file", VLC_VAR_STRING );
733 var_Create( p_libvlc, "record-file", VLC_VAR_STRING );
735 /* some default internal settings */
736 var_Create( p_libvlc, "window", VLC_VAR_STRING );
737 var_Create( p_libvlc, "user-agent", VLC_VAR_STRING );
738 var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" );
740 /* Initialize playlist and get commandline files */
741 p_playlist = playlist_Create( VLC_OBJECT(p_libvlc) );
744 msg_Err( p_libvlc, "playlist initialization failed" );
745 if( priv->p_memcpy_module != NULL )
747 module_unneed( p_libvlc, priv->p_memcpy_module );
749 module_EndBank (true);
753 /* System specific configuration */
754 system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );
756 #if defined(MEDIA_LIBRARY)
758 if( var_GetBool( p_libvlc, "load-media-library-on-startup" ) )
760 priv->p_ml = ml_Create( VLC_OBJECT( p_libvlc ), NULL );
763 msg_Err( p_libvlc, "ML initialization failed" );
773 /* Add service discovery modules */
774 psz_modules = var_InheritString( p_libvlc, "services-discovery" );
777 char *p = psz_modules, *m;
778 while( ( m = strsep( &p, " :," ) ) != NULL )
779 playlist_ServicesDiscoveryAdd( p_playlist, m );
784 /* Initialize VLM if vlm-conf is specified */
785 psz_parser = var_CreateGetNonEmptyString( p_libvlc, "vlm-conf" );
788 priv->p_vlm = vlm_New( p_libvlc );
790 msg_Err( p_libvlc, "VLM initialization failed" );
796 * Load background interfaces
798 psz_modules = var_CreateGetNonEmptyString( p_libvlc, "extraintf" );
799 psz_control = var_CreateGetNonEmptyString( p_libvlc, "control" );
801 if( psz_modules && psz_control )
804 if( asprintf( &psz_tmp, "%s:%s", psz_modules, psz_control ) != -1 )
807 psz_modules = psz_tmp;
810 else if( psz_control )
813 psz_modules = strdup( psz_control );
816 psz_parser = psz_modules;
817 while ( psz_parser && *psz_parser )
819 char *psz_module, *psz_temp;
820 psz_module = psz_parser;
821 psz_parser = strchr( psz_module, ':' );
827 if( asprintf( &psz_temp, "%s,none", psz_module ) != -1)
829 intf_Create( p_libvlc, psz_temp );
837 * Always load the hotkeys interface if it exists
839 intf_Create( p_libvlc, "hotkeys,none" );
842 /* loads dbus control interface if in one-instance mode
843 * we do it only when playlist exists, because dbus module needs it */
844 if( var_InheritBool( p_libvlc, "one-instance" )
845 || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" )
846 && var_InheritBool( p_libvlc, "started-from-file" ) ) )
847 intf_Create( p_libvlc, "dbus,none" );
849 # if !defined (HAVE_MAEMO)
850 /* Prevents the power management daemon from suspending the system
851 * when VLC is active */
852 if( var_InheritBool( p_libvlc, "inhibit" ) > 0 )
853 intf_Create( p_libvlc, "inhibit,none" );
857 if( var_InheritBool( p_libvlc, "file-logging" ) &&
858 !var_InheritBool( p_libvlc, "syslog" ) )
860 intf_Create( p_libvlc, "logger,none" );
863 if( var_InheritBool( p_libvlc, "syslog" ) )
865 char *logmode = var_CreateGetNonEmptyString( p_libvlc, "logmode" );
866 var_SetString( p_libvlc, "logmode", "syslog" );
867 intf_Create( p_libvlc, "logger,none" );
871 var_SetString( p_libvlc, "logmode", logmode );
874 var_Destroy( p_libvlc, "logmode" );
878 if( var_InheritBool( p_libvlc, "network-synchronisation") )
880 intf_Create( p_libvlc, "netsync,none" );
884 var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER );
885 var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER );
886 var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER );
887 var_Create( p_libvlc, "drawable-view-right", VLC_VAR_INTEGER );
888 var_Create( p_libvlc, "drawable-clip-top", VLC_VAR_INTEGER );
889 var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER );
890 var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER );
891 var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER );
892 var_Create( p_libvlc, "drawable-nsobject", VLC_VAR_ADDRESS );
895 var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_INTEGER );
899 * Get input filenames given as commandline arguments.
900 * We assume that the remaining parameters are filenames
901 * and their input options.
903 GetFilenames( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );
906 * Get --open argument
908 psz_val = var_InheritString( p_libvlc, "open" );
909 if ( psz_val != NULL )
911 playlist_AddExt( p_playlist, psz_val, NULL, PLAYLIST_INSERT, 0,
912 -1, 0, NULL, 0, true, pl_Unlocked );
920 * Cleanup a libvlc instance. The instance is not completely deallocated
921 * \param p_libvlc the instance to clean
923 void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
925 libvlc_priv_t *priv = libvlc_priv (p_libvlc);
926 playlist_t *p_playlist = libvlc_priv (p_libvlc)->p_playlist;
928 /* Deactivate the playlist */
929 msg_Dbg( p_libvlc, "deactivating the playlist" );
930 pl_Deactivate( p_libvlc );
932 /* Remove all services discovery */
933 msg_Dbg( p_libvlc, "removing all services discovery tasks" );
934 playlist_ServicesDiscoveryKillAll( p_playlist );
936 /* Ask the interfaces to stop and destroy them */
937 msg_Dbg( p_libvlc, "removing all interfaces" );
938 libvlc_Quit( p_libvlc );
939 intf_DestroyAll( p_libvlc );
942 /* Destroy VLM if created in libvlc_InternalInit */
945 vlm_Delete( priv->p_vlm );
949 #if defined(MEDIA_LIBRARY)
950 media_library_t* p_ml = priv->p_ml;
953 ml_Destroy( VLC_OBJECT( p_ml ) );
954 vlc_object_release( p_ml );
955 libvlc_priv(p_playlist->p_libvlc)->p_ml = NULL;
959 /* Free playlist now, all threads are gone */
960 playlist_Destroy( p_playlist );
961 stats_TimersDumpAll( p_libvlc );
962 stats_TimersCleanAll( p_libvlc );
964 msg_Dbg( p_libvlc, "removing stats" );
967 char* psz_pidfile = NULL;
971 psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
972 if( psz_pidfile != NULL )
974 msg_Dbg( p_libvlc, "removing pid file %s", psz_pidfile );
975 if( unlink( psz_pidfile ) == -1 )
977 msg_Dbg( p_libvlc, "removing pid file %s: %m",
985 if( priv->p_memcpy_module )
987 module_unneed( p_libvlc, priv->p_memcpy_module );
988 priv->p_memcpy_module = NULL;
991 /* Save the configuration */
992 if( !var_InheritBool( p_libvlc, "ignore-config" ) )
993 config_AutoSaveConfigFile( VLC_OBJECT(p_libvlc) );
995 /* Free module bank. It is refcounted, so we call this each time */
996 module_EndBank (true);
998 vlc_DeinitActions( p_libvlc, priv->actions );
1002 * Destroy everything.
1003 * This function requests the running threads to finish, waits for their
1004 * termination, and destroys their structure.
1005 * It stops the thread systems: no instance can run after this has run
1006 * \param p_libvlc the instance to destroy
1008 void libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
1010 libvlc_priv_t *priv = libvlc_priv( p_libvlc );
1012 vlc_mutex_lock( &global_lock );
1015 if( i_instances == 0 )
1017 /* System specific cleaning code */
1020 vlc_mutex_unlock( &global_lock );
1022 /* Destroy mutexes */
1023 vlc_ExitDestroy( &priv->exit );
1024 vlc_mutex_destroy( &priv->timer_lock );
1025 vlc_mutex_destroy( &priv->ml_lock );
1027 #ifndef NDEBUG /* Hack to dump leaked objects tree */
1028 if( vlc_internals( p_libvlc )->i_refcount > 1 )
1029 while( vlc_internals( p_libvlc )->i_refcount > 0 )
1030 vlc_object_release( p_libvlc );
1033 assert( vlc_internals( p_libvlc )->i_refcount == 1 );
1034 vlc_object_release( p_libvlc );
1038 * Add an interface plugin and run it
1040 int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module )
1043 return VLC_EGENERIC;
1045 if( !psz_module ) /* requesting the default interface */
1047 char *psz_interface = var_CreateGetNonEmptyString( p_libvlc, "intf" );
1048 if( !psz_interface ) /* "intf" has not been set */
1052 /* Daemon mode hack.
1053 * We prefer the dummy interface if none is specified. */
1054 psz_module = "dummy";
1057 msg_Info( p_libvlc, "%s",
1058 _("Running vlc with the default interface. "
1059 "Use 'cvlc' to use vlc without interface.") );
1061 free( psz_interface );
1062 var_Destroy( p_libvlc, "intf" );
1065 /* Try to create the interface */
1066 int ret = intf_Create( p_libvlc, psz_module ? psz_module : "$intf" );
1068 msg_Err( p_libvlc, "interface \"%s\" initialization failed",
1069 psz_module ? psz_module : "default" );
1073 #if defined( ENABLE_NLS ) && (defined (__APPLE__) || defined (WIN32)) && \
1074 ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
1075 /*****************************************************************************
1076 * SetLanguage: set the interface language.
1077 *****************************************************************************
1078 * We set the LC_MESSAGES locale category for interface messages and buttons,
1079 * as well as the LC_CTYPE category for string sorting and possible wide
1080 * character support.
1081 *****************************************************************************/
1082 static void SetLanguage ( const char *psz_lang )
1085 /* I need that under Darwin, please check it doesn't disturb
1086 * other platforms. --Meuuh */
1087 setenv( "LANG", psz_lang, 1 );
1090 /* We set LC_ALL manually because it is the only way to set
1091 * the language at runtime under eg. Windows. Beware that this
1092 * makes the environment unconsistent when libvlc is unloaded and
1093 * should probably be moved to a safer place like vlc.c. */
1094 setenv( "LC_ALL", psz_lang, 1 );
1098 setlocale( LC_ALL, psz_lang );
1102 /*****************************************************************************
1103 * GetFilenames: parse command line options which are not flags
1104 *****************************************************************************
1105 * Parse command line for input files as well as their associated options.
1106 * An option always follows its associated input and begins with a ":".
1107 *****************************************************************************/
1108 static void GetFilenames( libvlc_int_t *p_vlc, unsigned n,
1109 const char *const args[] )
1113 /* Count the input options */
1114 unsigned i_options = 0;
1116 while( args[--n][0] == ':' )
1121 msg_Warn( p_vlc, "options %s without item", args[n] );
1122 return; /* syntax!? */
1126 char *mrl = make_URI( args[n], NULL );
1130 playlist_AddExt( pl_Get( p_vlc ), mrl, NULL, PLAYLIST_INSERT,
1131 0, -1, i_options, ( i_options ? &args[n + 1] : NULL ),
1132 VLC_INPUT_OPTION_TRUSTED, true, pl_Unlocked );
1137 /*****************************************************************************
1138 * Help: print program help
1139 *****************************************************************************
1140 * Print a short inline help. Message interface is initialized at this stage.
1141 *****************************************************************************/
1142 static inline void print_help_on_full_help( void )
1144 utf8_fprintf( stdout, "\n" );
1145 utf8_fprintf( stdout, "%s\n", _("To get exhaustive help, use '-H'.") );
1148 static const char vlc_usage[] = N_(
1149 "Usage: %s [options] [stream] ..."
1150 "\nYou can specify multiple streams on the commandline. They will be enqueued in the playlist."
1151 "\nThe first item specified will be played first."
1154 "\n --option A global option that is set for the duration of the program."
1155 "\n -option A single letter version of a global --option."
1156 "\n :option An option that only applies to the stream directly before it"
1157 "\n and that overrides previous settings."
1159 "\nStream MRL syntax:"
1160 "\n [[access][/demux]://]URL[@[title][:chapter][-[title][:chapter]]] [:option=value ...]"
1162 "\n Many of the global --options can also be used as MRL specific :options."
1163 "\n Multiple :option=value pairs can be specified."
1166 "\n [file://]filename Plain media file"
1167 "\n http://ip:port/file HTTP URL"
1168 "\n ftp://ip:port/file FTP URL"
1169 "\n mms://ip:port/file MMS URL"
1170 "\n screen:// Screen capture"
1171 "\n [dvd://][device][@raw_device] DVD device"
1172 "\n [vcd://][device] VCD device"
1173 "\n [cdda://][device] Audio CD device"
1174 "\n udp://[[<source address>]@[<bind address>][:<bind port>]]"
1175 "\n UDP stream sent by a streaming server"
1176 "\n vlc://pause:<seconds> Special item to pause the playlist for a certain time"
1177 "\n vlc://quit Special item to quit VLC"
1180 static void Help( libvlc_int_t *p_this, char const *psz_help_name )
1183 ShowConsole( true );
1186 if( psz_help_name && !strcmp( psz_help_name, "help" ) )
1188 utf8_fprintf( stdout, vlc_usage, "vlc" );
1189 Usage( p_this, "=help" );
1190 Usage( p_this, "=main" );
1191 print_help_on_full_help();
1193 else if( psz_help_name && !strcmp( psz_help_name, "longhelp" ) )
1195 utf8_fprintf( stdout, vlc_usage, "vlc" );
1196 Usage( p_this, NULL );
1197 print_help_on_full_help();
1199 else if( psz_help_name && !strcmp( psz_help_name, "full-help" ) )
1201 utf8_fprintf( stdout, vlc_usage, "vlc" );
1202 Usage( p_this, NULL );
1204 else if( psz_help_name )
1206 Usage( p_this, psz_help_name );
1209 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1215 /*****************************************************************************
1216 * Usage: print module usage
1217 *****************************************************************************
1218 * Print a short inline help. Message interface is initialized at this stage.
1219 *****************************************************************************/
1220 # define COL(x) "\033[" #x ";1m"
1221 # define RED COL(31)
1222 # define GREEN COL(32)
1223 # define YELLOW COL(33)
1224 # define BLUE COL(34)
1225 # define MAGENTA COL(35)
1226 # define CYAN COL(36)
1227 # define WHITE COL(0)
1228 # define GRAY "\033[0m"
1230 print_help_section( const module_t *m, const module_config_t *p_item,
1231 bool b_color, bool b_description )
1233 if( !p_item ) return;
1236 utf8_fprintf( stdout, RED" %s:\n"GRAY,
1237 module_gettext( m, p_item->psz_text ) );
1238 if( b_description && p_item->psz_longtext )
1239 utf8_fprintf( stdout, MAGENTA" %s\n"GRAY,
1240 module_gettext( m, p_item->psz_longtext ) );
1244 utf8_fprintf( stdout, " %s:\n",
1245 module_gettext( m, p_item->psz_text ) );
1246 if( b_description && p_item->psz_longtext )
1247 utf8_fprintf( stdout, " %s\n",
1248 module_gettext(m, p_item->psz_longtext ) );
1252 static void Usage( libvlc_int_t *p_this, char const *psz_search )
1254 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
1255 /* short option ------' | | | | | | |
1256 * option name ------------' | | | | | |
1257 * <bra ---------------------' | | | | |
1258 * option type or "" ----------' | | | |
1259 * ket> -------------------------' | | |
1260 * padding spaces -----------------' | |
1261 * comment --------------------------' |
1262 * comment suffix ---------------------'
1264 * The purpose of having bra and ket is that we might i18n them as well.
1267 #define COLOR_FORMAT_STRING (WHITE" %s --%s"YELLOW"%s%s%s%s%s%s "GRAY)
1268 #define COLOR_FORMAT_STRING_BOOL (WHITE" %s --%s%s%s%s%s%s%s "GRAY)
1270 #define LINE_START 8
1271 #define PADDING_SPACES 25
1273 # define OPTION_VALUE_SEP "="
1275 # define OPTION_VALUE_SEP " "
1277 char psz_spaces_text[PADDING_SPACES+LINE_START+1];
1278 char psz_spaces_longtext[LINE_START+3];
1279 char psz_format[sizeof(COLOR_FORMAT_STRING)];
1280 char psz_format_bool[sizeof(COLOR_FORMAT_STRING_BOOL)];
1281 char psz_buffer[10000];
1283 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
1284 int i_width_description = i_width + PADDING_SPACES - 1;
1285 bool b_advanced = var_InheritBool( p_this, "advanced" );
1286 bool b_description = var_InheritBool( p_this, "help-verbose" );
1287 bool b_description_hack;
1288 bool b_color = var_InheritBool( p_this, "color" );
1289 bool b_has_advanced = false;
1290 bool b_found = false;
1291 int i_only_advanced = 0; /* Number of modules ignored because they
1292 * only have advanced options */
1293 bool b_strict = psz_search && *psz_search == '=';
1294 if( b_strict ) psz_search++;
1296 memset( psz_spaces_text, ' ', PADDING_SPACES+LINE_START );
1297 psz_spaces_text[PADDING_SPACES+LINE_START] = '\0';
1298 memset( psz_spaces_longtext, ' ', LINE_START+2 );
1299 psz_spaces_longtext[LINE_START+2] = '\0';
1303 b_color = false; // don't put color control codes in a .txt file
1307 strcpy( psz_format, COLOR_FORMAT_STRING );
1308 strcpy( psz_format_bool, COLOR_FORMAT_STRING_BOOL );
1312 strcpy( psz_format, FORMAT_STRING );
1313 strcpy( psz_format_bool, FORMAT_STRING );
1316 /* List all modules */
1317 module_t **list = module_list_get (NULL);
1321 /* Ugly hack to make sure that the help options always come first
1324 Usage( p_this, "help" );
1326 /* Enumerate the config for each module */
1327 for (size_t i = 0; list[i]; i++)
1330 module_t *p_parser = list[i];
1331 module_config_t *p_item = NULL;
1332 module_config_t *p_section = NULL;
1333 module_config_t *p_end = p_parser->p_config + p_parser->confsize;
1334 const char *objname = module_get_object (p_parser);
1337 ( b_strict ? strcmp( objname, psz_search )
1338 : !strstr( objname, psz_search ) ) )
1340 char *const *pp_shortcuts = p_parser->pp_shortcuts;
1342 for( i = 0; i < p_parser->i_shortcuts; i++ )
1344 if( b_strict ? !strcmp( psz_search, pp_shortcuts[i] )
1345 : !!strstr( pp_shortcuts[i], psz_search ) )
1348 if( i == p_parser->i_shortcuts )
1352 /* Ignore modules without config options */
1353 if( !p_parser->i_config_items )
1358 b_help_module = !strcmp( "help", objname );
1359 /* Ugly hack to make sure that the help options always come first
1361 if( !psz_search && b_help_module )
1364 /* Ignore modules with only advanced config options if requested */
1367 for( p_item = p_parser->p_config;
1371 if( CONFIG_ITEM(p_item->i_type) &&
1372 !p_item->b_advanced && !p_item->b_removed ) break;
1375 if( p_item == p_end )
1384 /* Print name of module */
1385 if( strcmp( "main", objname ) )
1388 utf8_fprintf( stdout, "\n " GREEN "%s" GRAY " (%s)\n",
1389 module_gettext( p_parser, p_parser->psz_longname ),
1392 utf8_fprintf( stdout, "\n %s\n",
1393 module_gettext(p_parser, p_parser->psz_longname ) );
1395 if( p_parser->psz_help )
1398 utf8_fprintf( stdout, CYAN" %s\n"GRAY,
1399 module_gettext( p_parser, p_parser->psz_help ) );
1401 utf8_fprintf( stdout, " %s\n",
1402 module_gettext( p_parser, p_parser->psz_help ) );
1405 /* Print module options */
1406 for( p_item = p_parser->p_config;
1410 char *psz_text, *psz_spaces = psz_spaces_text;
1411 const char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1412 const char *psz_suf = "", *psz_prefix = NULL;
1416 /* Skip removed options */
1417 if( p_item->b_removed )
1421 /* Skip advanced options if requested */
1422 if( p_item->b_advanced && !b_advanced )
1424 b_has_advanced = true;
1428 switch( CONFIG_CLASS(p_item->i_type) )
1430 case 0: // hint class
1431 switch( p_item->i_type )
1433 case CONFIG_HINT_CATEGORY:
1434 case CONFIG_HINT_USAGE:
1435 if( !strcmp( "main", objname ) )
1438 utf8_fprintf( stdout, GREEN "\n %s\n" GRAY,
1439 module_gettext( p_parser, p_item->psz_text ) );
1441 utf8_fprintf( stdout, "\n %s\n",
1442 module_gettext( p_parser, p_item->psz_text ) );
1444 if( b_description && p_item->psz_longtext )
1447 utf8_fprintf( stdout, CYAN " %s\n" GRAY,
1448 module_gettext( p_parser, p_item->psz_longtext ) );
1450 utf8_fprintf( stdout, " %s\n",
1451 module_gettext( p_parser, p_item->psz_longtext ) );
1455 case CONFIG_HINT_SUBCATEGORY:
1456 if( strcmp( "main", objname ) )
1458 case CONFIG_SECTION:
1464 case CONFIG_ITEM_STRING:
1465 print_help_section( p_parser, p_section, b_color,
1468 psz_bra = OPTION_VALUE_SEP "<";
1469 psz_type = _("string");
1472 if( p_item->ppsz_list )
1474 psz_bra = OPTION_VALUE_SEP "{";
1475 psz_type = psz_buffer;
1476 psz_buffer[0] = '\0';
1477 for( i = 0; p_item->ppsz_list[i]; i++ )
1479 if( i ) strcat( psz_buffer, "," );
1480 strcat( psz_buffer, p_item->ppsz_list[i] );
1485 case CONFIG_ITEM_INTEGER:
1486 print_help_section( p_parser, p_section, b_color,
1489 psz_bra = OPTION_VALUE_SEP "<";
1490 psz_type = _("integer");
1493 if( p_item->min.i || p_item->max.i )
1495 sprintf( psz_buffer, "%s [%"PRId64" .. %"PRId64"]",
1496 psz_type, p_item->min.i, p_item->max.i );
1497 psz_type = psz_buffer;
1500 if( p_item->i_list )
1502 psz_bra = OPTION_VALUE_SEP "{";
1503 psz_type = psz_buffer;
1504 psz_buffer[0] = '\0';
1505 for( i = 0; p_item->ppsz_list_text[i]; i++ )
1507 if( i ) strcat( psz_buffer, ", " );
1508 sprintf( psz_buffer + strlen(psz_buffer), "%i (%s)",
1510 module_gettext( p_parser, p_item->ppsz_list_text[i] ) );
1515 case CONFIG_ITEM_FLOAT:
1516 print_help_section( p_parser, p_section, b_color,
1519 psz_bra = OPTION_VALUE_SEP "<";
1520 psz_type = _("float");
1522 if( p_item->min.f || p_item->max.f )
1524 sprintf( psz_buffer, "%s [%f .. %f]", psz_type,
1525 p_item->min.f, p_item->max.f );
1526 psz_type = psz_buffer;
1529 case CONFIG_ITEM_BOOL:
1530 print_help_section( p_parser, p_section, b_color,
1533 psz_bra = ""; psz_type = ""; psz_ket = "";
1534 if( !b_help_module )
1536 psz_suf = p_item->value.i ? _(" (default enabled)") :
1537 _(" (default disabled)");
1547 /* Add short option if any */
1548 if( p_item->i_short )
1550 sprintf( psz_short, "-%c,", p_item->i_short );
1554 strcpy( psz_short, " " );
1557 i = PADDING_SPACES - strlen( p_item->psz_name )
1558 - strlen( psz_bra ) - strlen( psz_type )
1559 - strlen( psz_ket ) - 1;
1561 if( CONFIG_CLASS(p_item->i_type) == CONFIG_ITEM_BOOL
1564 psz_prefix = ", --no-";
1565 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
1570 psz_spaces[0] = '\n';
1575 psz_spaces[i] = '\0';
1578 if( CONFIG_CLASS(p_item->i_type) == CONFIG_ITEM_BOOL
1581 utf8_fprintf( stdout, psz_format_bool, psz_short,
1582 p_item->psz_name, psz_prefix, p_item->psz_name,
1583 psz_bra, psz_type, psz_ket, psz_spaces );
1587 utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1588 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
1591 psz_spaces[i] = ' ';
1593 /* We wrap the rest of the output */
1594 sprintf( psz_buffer, "%s%s", module_gettext( p_parser, p_item->psz_text ),
1596 b_description_hack = b_description;
1599 psz_text = psz_buffer;
1600 i_cur_width = b_description && !b_description_hack
1601 ? i_width_description
1603 if( !*psz_text ) strcpy(psz_text, " ");
1606 char *psz_parser, *psz_word;
1607 size_t i_end = strlen( psz_text );
1609 /* If the remaining text fits in a line, print it. */
1610 if( i_end <= i_cur_width )
1614 if( !b_description || b_description_hack )
1615 utf8_fprintf( stdout, BLUE"%s\n"GRAY, psz_text );
1617 utf8_fprintf( stdout, "%s\n", psz_text );
1621 utf8_fprintf( stdout, "%s\n", psz_text );
1626 /* Otherwise, eat as many words as possible */
1627 psz_parser = psz_text;
1630 psz_word = psz_parser;
1631 psz_parser = strchr( psz_word, ' ' );
1632 /* If no space was found, we reached the end of the text
1633 * block; otherwise, we skip the space we just found. */
1634 psz_parser = psz_parser ? psz_parser + 1
1637 } while( (size_t)(psz_parser - psz_text) <= i_cur_width );
1639 /* We cut a word in one of these cases:
1640 * - it's the only word in the line and it's too long.
1641 * - we used less than 80% of the width and the word we are
1642 * going to wrap is longer than 40% of the width, and even
1643 * if the word would have fit in the next line. */
1644 if( psz_word == psz_text
1645 || ( (size_t)(psz_word - psz_text) < 80 * i_cur_width / 100
1646 && (size_t)(psz_parser - psz_word) > 40 * i_cur_width / 100 ) )
1648 char c = psz_text[i_cur_width];
1649 psz_text[i_cur_width] = '\0';
1652 if( !b_description || b_description_hack )
1653 utf8_fprintf( stdout, BLUE"%s\n%s"GRAY,
1654 psz_text, psz_spaces );
1656 utf8_fprintf( stdout, "%s\n%s",
1657 psz_text, psz_spaces );
1661 utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
1663 psz_text += i_cur_width;
1668 psz_word[-1] = '\0';
1671 if( !b_description || b_description_hack )
1672 utf8_fprintf( stdout, BLUE"%s\n%s"GRAY,
1673 psz_text, psz_spaces );
1675 utf8_fprintf( stdout, "%s\n%s",
1676 psz_text, psz_spaces );
1680 utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
1682 psz_text = psz_word;
1686 if( b_description_hack && p_item->psz_longtext )
1688 sprintf( psz_buffer, "%s%s",
1689 module_gettext( p_parser, p_item->psz_longtext ),
1691 b_description_hack = false;
1692 psz_spaces = psz_spaces_longtext;
1693 utf8_fprintf( stdout, "%s", psz_spaces );
1699 if( b_has_advanced )
1702 utf8_fprintf( stdout, "\n" WHITE "%s" GRAY " %s\n", _( "Note:" ),
1703 _( "add --advanced to your command line to see advanced options."));
1705 utf8_fprintf( stdout, "\n%s %s\n", _( "Note:" ),
1706 _( "add --advanced to your command line to see advanced options."));
1709 if( i_only_advanced > 0 )
1713 utf8_fprintf( stdout, "\n" WHITE "%s" GRAY " ", _( "Note:" ) );
1714 utf8_fprintf( stdout, _( "%d module(s) were not displayed because they only have advanced options.\n" ), i_only_advanced );
1718 utf8_fprintf( stdout, "\n%s ", _( "Note:" ) );
1719 utf8_fprintf( stdout, _( "%d module(s) were not displayed because they only have advanced options.\n" ), i_only_advanced );
1725 utf8_fprintf( stdout, "\n" WHITE "%s" GRAY "\n",
1726 _( "No matching module found. Use --list or " \
1727 "--list-verbose to list available modules." ) );
1729 utf8_fprintf( stdout, "\n%s\n",
1730 _( "No matching module found. Use --list or " \
1731 "--list-verbose to list available modules." ) );
1734 /* Release the module list */
1735 module_list_free (list);
1738 /*****************************************************************************
1739 * ListModules: list the available modules with their description
1740 *****************************************************************************
1741 * Print a list of all available modules (builtins and plugins) and a short
1742 * description for each one.
1743 *****************************************************************************/
1744 static void ListModules( libvlc_int_t *p_this, bool b_verbose )
1748 bool b_color = var_InheritBool( p_this, "color" );
1751 ShowConsole( true );
1752 b_color = false; // don't put color control codes in a .txt file
1758 /* List all modules */
1759 module_t **list = module_list_get (NULL);
1761 /* Enumerate each module */
1762 for (size_t j = 0; (p_parser = list[j]) != NULL; j++)
1764 const char *objname = module_get_object (p_parser);
1766 utf8_fprintf( stdout, GREEN" %-22s "WHITE"%s\n"GRAY, objname,
1767 module_gettext( p_parser, p_parser->psz_longname ) );
1769 utf8_fprintf( stdout, " %-22s %s\n", objname,
1770 module_gettext( p_parser, p_parser->psz_longname ) );
1774 char *const *pp_shortcuts = p_parser->pp_shortcuts;
1775 for( unsigned i = 0; i < p_parser->i_shortcuts; i++ )
1777 if( strcmp( pp_shortcuts[i], objname ) )
1780 utf8_fprintf( stdout, CYAN" s %s\n"GRAY,
1783 utf8_fprintf( stdout, " s %s\n",
1787 if( p_parser->psz_capability )
1790 utf8_fprintf( stdout, MAGENTA" c %s (%d)\n"GRAY,
1791 p_parser->psz_capability,
1792 p_parser->i_score );
1794 utf8_fprintf( stdout, " c %s (%d)\n",
1795 p_parser->psz_capability,
1796 p_parser->i_score );
1800 module_list_free (list);
1802 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1807 /*****************************************************************************
1808 * Version: print complete program version
1809 *****************************************************************************
1810 * Print complete program version and build number.
1811 *****************************************************************************/
1812 static void Version( void )
1815 ShowConsole( true );
1818 utf8_fprintf( stdout, _("VLC version %s (%s)\n"), VERSION_MESSAGE,
1819 psz_vlc_changeset );
1820 utf8_fprintf( stdout, _("Compiled by %s on %s (%s)\n"),
1821 VLC_CompileBy(), VLC_CompileHost(), __DATE__" "__TIME__ );
1822 utf8_fprintf( stdout, _("Compiler: %s\n"), VLC_Compiler() );
1823 utf8_fprintf( stdout, "%s", LICENSE_MSG );
1825 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1830 /*****************************************************************************
1831 * ShowConsole: On Win32, create an output console for debug messages
1832 *****************************************************************************
1833 * This function is useful only on Win32.
1834 *****************************************************************************/
1836 static void ShowConsole( bool b_dofile )
1839 FILE *f_help = NULL;
1841 if( getenv( "PWD" ) ) return; /* Cygwin shell or Wine */
1844 /* Use the ANSI code page (e.g. Windows-1252) as expected by the LibVLC
1845 * Unicode/locale subsystem. By default, we have the obsolecent OEM code
1846 * page (e.g. CP437 or CP850). */
1847 SetConsoleOutputCP (GetACP ());
1848 SetConsoleTitle ("VLC media player version "PACKAGE_VERSION);
1850 freopen( "CONOUT$", "w", stderr );
1851 freopen( "CONIN$", "r", stdin );
1853 if( b_dofile && (f_help = fopen( "vlc-help.txt", "wt" )) )
1856 freopen( "vlc-help.txt", "wt", stdout );
1857 utf8_fprintf( stderr, _("\nDumped content to vlc-help.txt file.\n") );
1859 else freopen( "CONOUT$", "w", stdout );
1865 /*****************************************************************************
1866 * PauseConsole: On Win32, wait for a key press before closing the console
1867 *****************************************************************************
1868 * This function is useful only on Win32.
1869 *****************************************************************************/
1871 static void PauseConsole( void )
1875 if( getenv( "PWD" ) ) return; /* Cygwin shell or Wine */
1877 utf8_fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
1885 /*****************************************************************************
1886 * ConsoleWidth: Return the console width in characters
1887 *****************************************************************************
1888 * We use the stty shell command to get the console width; if this fails or
1889 * if the width is less than 80, we default to 80.
1890 *****************************************************************************/
1891 static int ConsoleWidth( void )
1893 unsigned i_width = 80;
1896 FILE *file = popen( "stty size 2>/dev/null", "r" );
1899 if (fscanf (file, "%*u %u", &i_width) <= 0)
1903 #elif !defined (UNDER_CE)
1904 CONSOLE_SCREEN_BUFFER_INFO buf;
1906 if (GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &buf))
1907 i_width = buf.dwSize.X;