1 /*****************************************************************************
2 * libvlc.c: main libvlc source
3 *****************************************************************************
4 * Copyright (C) 1998-2006 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 *****************************************************************************/
28 /*****************************************************************************
29 * Pretend we are a builtin module
30 *****************************************************************************/
31 #define MODULE_NAME main
32 #define MODULE_PATH main
35 /*****************************************************************************
37 *****************************************************************************/
39 #include <vlc/input.h>
41 #include <errno.h> /* ENOMEM */
42 #include <stdio.h> /* sprintf() */
43 #include <string.h> /* strerror() */
44 #include <stdlib.h> /* free() */
47 # include <netinet/in.h> /* BSD: struct in_addr */
52 #elif defined( WIN32 ) && !defined( UNDER_CE )
56 #ifdef WIN32 /* optind, getopt(), included in unistd.h */
57 # include "extras/getopt.h"
65 # include <hal/libhal.h>
68 #include "vlc_cpu.h" /* CPU detection */
69 #include "os_specific.h"
71 #include "vlc_error.h"
73 #include "vlc_playlist.h"
74 #include "vlc_interface.h"
76 #include "audio_output.h"
78 #include "vlc_video.h"
79 #include "video_output.h"
81 #include "stream_output.h"
86 /*****************************************************************************
87 * The evil global variable. We handle it with care, don't worry.
88 *****************************************************************************/
89 static libvlc_global_data_t libvlc_global;
90 static libvlc_global_data_t * p_libvlc_global;
91 static libvlc_int_t * p_static_vlc;
93 /*****************************************************************************
95 *****************************************************************************/
96 static int AddIntfInternal( int i_object, char const *psz_module,
97 vlc_bool_t b_block, vlc_bool_t b_play,
98 int i_options, char **ppsz_options );
100 void LocaleInit( vlc_object_t * );
101 void LocaleDeinit( void );
102 static void SetLanguage ( char const * );
103 static int GetFilenames ( libvlc_int_t *, int, char *[] );
104 static void Help ( libvlc_int_t *, char const *psz_help_name );
105 static void Usage ( libvlc_int_t *, char const *psz_module_name );
106 static void ListModules ( libvlc_int_t * );
107 static void Version ( void );
110 static void ShowConsole ( vlc_bool_t );
111 static void PauseConsole ( void );
113 static int ConsoleWidth ( void );
115 static int VerboseCallback( vlc_object_t *, char const *,
116 vlc_value_t, vlc_value_t, void * );
118 static void InitDeviceValues( libvlc_int_t * );
120 /*****************************************************************************
121 * vlc_current_object: return the current object.
122 *****************************************************************************
123 * If i_object is non-zero, return the corresponding object. Otherwise,
124 * return the statically allocated p_vlc object.
125 *****************************************************************************/
126 libvlc_int_t * vlc_current_object( int i_object )
130 return vlc_object_get( p_libvlc_global, i_object );
136 /*****************************************************************************
137 * VLC_Version: return the libvlc version.
138 *****************************************************************************
139 * This function returns full version string (numeric version and codename).
140 *****************************************************************************/
141 char const * VLC_Version( void )
143 return VERSION_MESSAGE;
146 /*****************************************************************************
147 * VLC_CompileBy, VLC_CompileHost, VLC_CompileDomain,
148 * VLC_Compiler, VLC_Changeset
149 *****************************************************************************/
150 #define DECLARE_VLC_VERSION( func, var ) \
151 char const * VLC_##func ( void ) \
156 DECLARE_VLC_VERSION( CompileBy, COMPILE_BY );
157 DECLARE_VLC_VERSION( CompileHost, COMPILE_HOST );
158 DECLARE_VLC_VERSION( CompileDomain, COMPILE_DOMAIN );
159 DECLARE_VLC_VERSION( Compiler, COMPILER );
161 #ifndef HAVE_SHARED_LIBVLC
162 extern const char psz_vlc_changeset[];
163 char const * VLC_Changeset( void )
165 return psz_vlc_changeset;
169 /*****************************************************************************
170 * VLC_Error: strerror() equivalent
171 *****************************************************************************
172 * This function returns full version string (numeric version and codename).
173 *****************************************************************************/
174 char const * VLC_Error( int i_err )
176 return vlc_error( i_err );
179 /*****************************************************************************
180 * VLC_Create: allocate a vlc_t structure, and initialize libvlc if needed.
181 *****************************************************************************
182 * This function allocates a vlc_t structure and returns a negative value
183 * in case of failure. Also, the thread system is initialized.
184 *****************************************************************************/
185 int VLC_Create( void )
188 libvlc_int_t * p_libvlc = NULL;
191 /* &libvlc never changes, so we can safely call this multiple times. */
192 p_libvlc_global = &libvlc_global;
194 /* vlc_threads_init *must* be the first internal call! No other call is
195 * allowed before the thread system has been initialized. */
196 i_ret = vlc_threads_init( p_libvlc_global );
202 /* Now that the thread system is initialized, we don't have much, but
203 * at least we have var_Create */
204 var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
205 var_Get( p_libvlc_global, "libvlc", &lockval );
206 vlc_mutex_lock( lockval.p_address );
207 if( !libvlc_global.b_ready )
211 /* Guess what CPU we have */
212 libvlc_global.i_cpu = CPUCapabilities();
214 /* Find verbosity from VLC_VERBOSE environment variable */
215 psz_env = getenv( "VLC_VERBOSE" );
216 libvlc_global.i_verbose = psz_env ? atoi( psz_env ) : -1;
218 #if defined( HAVE_ISATTY ) && !defined( WIN32 )
219 libvlc_global.b_color = isatty( 2 ); /* 2 is for stderr */
221 libvlc_global.b_color = VLC_FALSE;
224 /* Initialize message queue */
225 msg_Create( p_libvlc_global );
227 /* Announce who we are */
228 msg_Dbg( p_libvlc_global, COPYRIGHT_MESSAGE );
229 msg_Dbg( p_libvlc_global, "libvlc was configured with %s",
232 /* The module bank will be initialized later */
233 libvlc_global.p_module_bank = NULL;
235 libvlc_global.b_ready = VLC_TRUE;
237 vlc_mutex_unlock( lockval.p_address );
238 var_Destroy( p_libvlc_global, "libvlc" );
240 /* Allocate a vlc object */
241 p_libvlc = vlc_object_create( p_libvlc_global, VLC_OBJECT_LIBVLC );
242 if( p_libvlc == NULL )
246 p_libvlc->thread_id = 0;
247 p_libvlc->p_playlist = NULL;
248 p_libvlc->psz_object_name = "libvlc";
250 /* Initialize mutexes */
251 vlc_mutex_init( p_libvlc, &p_libvlc->config_lock );
253 vlc_mutex_init( p_libvlc, &p_libvlc->quicktime_lock );
254 vlc_thread_set_priority( p_libvlc, VLC_THREAD_PRIORITY_LOW );
257 /* Store our newly allocated structure in the global list */
258 vlc_object_attach( p_libvlc, p_libvlc_global );
260 /* Store data for the non-reentrant API */
261 p_static_vlc = p_libvlc;
263 return p_libvlc->i_object_id;
266 #define LIBVLC_FUNC \
267 libvlc_int_t * p_libvlc = vlc_current_object( i_object ); \
268 if( !p_libvlc ) return VLC_ENOOBJ;
269 #define LIBVLC_FUNC_END \
270 if( i_object ) vlc_object_release( p_libvlc );
273 /*****************************************************************************
274 * VLC_Init: initialize a vlc_t structure.
275 *****************************************************************************
276 * This function initializes a previously allocated vlc_t structure:
278 * - gettext initialization
279 * - message queue, module bank and playlist initialization
280 * - configuration and commandline parsing
281 *****************************************************************************/
282 int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
284 char p_capabilities[200];
289 vlc_bool_t b_exit = VLC_FALSE;
290 int i_ret = VLC_EEXIT;
291 module_t *p_help_module;
292 playlist_t *p_playlist;
294 #if defined( ENABLE_NLS ) \
295 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
296 # if defined (WIN32) || defined (__APPLE__)
302 /* System specific initialization code */
303 system_Init( p_libvlc, &i_argc, ppsz_argv );
305 /* Get the executable name (similar to the basename command) */
308 p_libvlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
311 if( *p_tmp == '/' ) p_libvlc->psz_object_name = ++p_tmp;
317 p_libvlc->psz_object_name = "vlc";
321 * Support for gettext
326 * Global iconv, must be done after setlocale()
327 * so that vlc_current_charset() works.
329 LocaleInit( (vlc_object_t *)p_libvlc );
331 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
332 msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") );
334 /* Initialize the module bank and load the configuration of the
335 * main module. We need to do this at this stage to be able to display
336 * a short help if required by the user. (short help == main module
338 module_InitBank( p_libvlc );
340 /* Hack: insert the help module here */
341 p_help_module = vlc_object_create( p_libvlc, VLC_OBJECT_MODULE );
342 if( p_help_module == NULL )
344 module_EndBank( p_libvlc );
345 if( i_object ) vlc_object_release( p_libvlc );
348 p_help_module->psz_object_name = "help";
349 p_help_module->psz_longname = N_("Help options");
350 config_Duplicate( p_help_module, p_help_config );
351 vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
354 if( config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE ) )
356 vlc_object_detach( p_help_module );
357 config_Free( p_help_module );
358 vlc_object_destroy( p_help_module );
359 module_EndBank( p_libvlc );
360 if( i_object ) vlc_object_release( p_libvlc );
364 /* Check for short help option */
365 if( config_GetInt( p_libvlc, "help" ) )
367 Help( p_libvlc, "help" );
369 i_ret = VLC_EEXITSUCCESS;
371 /* Check for version option */
372 else if( config_GetInt( p_libvlc, "version" ) )
376 i_ret = VLC_EEXITSUCCESS;
379 /* Set the config file stuff */
380 p_libvlc->psz_homedir = config_GetHomeDir();
381 p_libvlc->psz_userdir = config_GetUserDir();
382 if( p_libvlc->psz_userdir == NULL )
383 p_libvlc->psz_userdir = strdup(p_libvlc->psz_homedir);
384 p_libvlc->psz_configfile = config_GetPsz( p_libvlc, "config" );
385 if( p_libvlc->psz_configfile != NULL && p_libvlc->psz_configfile[0] == '~'
386 && p_libvlc->psz_configfile[1] == '/' )
388 char *psz = malloc( strlen(p_libvlc->psz_userdir)
389 + strlen(p_libvlc->psz_configfile) );
390 /* This is incomplete : we should also support the ~cmassiot/ syntax. */
391 sprintf( psz, "%s/%s", p_libvlc->psz_userdir,
392 p_libvlc->psz_configfile + 2 );
393 free( p_libvlc->psz_configfile );
394 p_libvlc->psz_configfile = psz;
397 /* Check for plugins cache options */
398 if( config_GetInt( p_libvlc, "reset-plugins-cache" ) )
400 libvlc_global.p_module_bank->b_cache_delete = VLC_TRUE;
403 /* Hack: remove the help module here */
404 vlc_object_detach( p_help_module );
407 /* Will be re-done properly later on */
408 p_libvlc->p_libvlc_global->i_verbose = config_GetInt( p_libvlc, "verbose" );
410 /* Check for daemon mode */
412 if( config_GetInt( p_libvlc, "daemon" ) )
415 if( daemon( 1, 0) != 0 )
417 msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
421 p_libvlc->p_libvlc_global->b_daemon = VLC_TRUE;
423 /* lets check if we need to write the pidfile */
424 char * psz_pidfile = config_GetPsz( p_libvlc, "pidfile" );
426 msg_Dbg( p_libvlc, "psz_pidfile is %s", psz_pidfile );
428 if( psz_pidfile != NULL )
431 pid_t i_pid = getpid ();
433 msg_Dbg( p_libvlc, "our PID is %d, writing it to %s", i_pid, psz_pidfile );
435 pidfile = utf8_fopen( psz_pidfile,"w" );
436 if( pidfile != NULL )
438 utf8_fprintf( pidfile, "%d", (int)i_pid );
443 msg_Err( p_libvlc, "Cannot open pid file for writing: %s, error: %s",
444 psz_pidfile, strerror(errno) );
453 if( ( i_pid = fork() ) < 0 )
455 msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
460 /* This is the parent, exit right now */
461 msg_Dbg( p_libvlc, "closing parent process" );
463 i_ret = VLC_EEXITSUCCESS;
467 /* We are the child */
468 msg_Dbg( p_libvlc, "daemon spawned" );
469 close( STDIN_FILENO );
470 close( STDOUT_FILENO );
471 close( STDERR_FILENO );
473 p_libvlc->p_libvlc_global->b_daemon = VLC_TRUE;
481 config_Free( p_help_module );
482 vlc_object_destroy( p_help_module );
483 module_EndBank( p_libvlc );
484 if( i_object ) vlc_object_release( p_libvlc );
488 /* Check for translation config option */
489 #if defined( ENABLE_NLS ) \
490 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
491 # if defined (WIN32) || defined (__APPLE__)
492 /* This ain't really nice to have to reload the config here but it seems
493 * the only way to do it. */
494 config_LoadConfigFile( p_libvlc, "main" );
495 config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE );
497 /* Check if the user specified a custom language */
498 psz_language = config_GetPsz( p_libvlc, "language" );
499 if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
501 vlc_bool_t b_cache_delete = libvlc_global.p_module_bank->b_cache_delete;
503 /* Reset the default domain */
504 SetLanguage( psz_language );
506 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
507 msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") );
509 module_EndBank( p_libvlc );
510 module_InitBank( p_libvlc );
511 config_LoadConfigFile( p_libvlc, "main" );
512 config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE );
513 libvlc_global.p_module_bank->b_cache_delete = b_cache_delete;
515 if( psz_language ) free( psz_language );
520 * Load the builtins and plugins into the module_bank.
521 * We have to do it before config_Load*() because this also gets the
522 * list of configuration options exported by each module and loads their
525 module_LoadBuiltins( p_libvlc );
526 module_LoadPlugins( p_libvlc );
527 if( p_libvlc->b_die )
532 msg_Dbg( p_libvlc, "module bank initialized, found %i modules",
533 libvlc_global.p_module_bank->i_children );
535 /* Hack: insert the help module here */
536 vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
539 /* Check for help on modules */
540 if( (p_tmp = config_GetPsz( p_libvlc, "module" )) )
542 Help( p_libvlc, p_tmp );
545 i_ret = VLC_EEXITSUCCESS;
547 /* Check for long help option */
548 else if( config_GetInt( p_libvlc, "longhelp" ) )
550 Help( p_libvlc, "longhelp" );
552 i_ret = VLC_EEXITSUCCESS;
554 /* Check for module list option */
555 else if( config_GetInt( p_libvlc, "list" ) )
557 ListModules( p_libvlc );
559 i_ret = VLC_EEXITSUCCESS;
562 /* Check for config file options */
563 if( config_GetInt( p_libvlc, "reset-config" ) )
565 vlc_object_detach( p_help_module );
566 config_ResetAll( p_libvlc );
567 config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE );
568 config_SaveConfigFile( p_libvlc, NULL );
569 vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
571 if( config_GetInt( p_libvlc, "save-config" ) )
573 vlc_object_detach( p_help_module );
574 config_LoadConfigFile( p_libvlc, NULL );
575 config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE );
576 config_SaveConfigFile( p_libvlc, NULL );
577 vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
580 /* Hack: remove the help module here */
581 vlc_object_detach( p_help_module );
586 config_Free( p_help_module );
587 vlc_object_destroy( p_help_module );
588 module_EndBank( p_libvlc );
589 if( i_object ) vlc_object_release( p_libvlc );
596 InitDeviceValues( p_libvlc );
599 * Override default configuration with config file settings
601 config_LoadConfigFile( p_libvlc, NULL );
603 /* Hack: insert the help module here */
604 vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
608 * Override configuration with command line settings
610 if( config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_FALSE ) )
613 ShowConsole( VLC_FALSE );
614 /* Pause the console because it's destroyed when we exit */
615 fprintf( stderr, "The command line options couldn't be loaded, check "
616 "that they are valid.\n" );
619 vlc_object_detach( p_help_module );
620 config_Free( p_help_module );
621 vlc_object_destroy( p_help_module );
622 module_EndBank( p_libvlc );
623 if( i_object ) vlc_object_release( p_libvlc );
627 /* Hack: remove the help module here */
628 vlc_object_detach( p_help_module );
629 config_Free( p_help_module );
630 vlc_object_destroy( p_help_module );
634 * System specific configuration
636 system_Configure( p_libvlc, &i_argc, ppsz_argv );
639 * Message queue options
642 var_Create( p_libvlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
643 if( config_GetInt( p_libvlc, "quiet" ) )
646 var_Set( p_libvlc, "verbose", val );
648 var_AddCallback( p_libvlc, "verbose", VerboseCallback, NULL );
649 var_Change( p_libvlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
651 libvlc_global.b_color = libvlc_global.b_color &&
652 config_GetInt( p_libvlc, "color" );
655 * Output messages that may still be in the queue
657 msg_Flush( p_libvlc );
659 /* p_libvlc initialization. FIXME ? */
661 if( !config_GetInt( p_libvlc, "fpu" ) )
662 libvlc_global.i_cpu &= ~CPU_CAPABILITY_FPU;
664 #if defined( __i386__ ) || defined( __x86_64__ )
665 if( !config_GetInt( p_libvlc, "mmx" ) )
666 libvlc_global.i_cpu &= ~CPU_CAPABILITY_MMX;
667 if( !config_GetInt( p_libvlc, "3dn" ) )
668 libvlc_global.i_cpu &= ~CPU_CAPABILITY_3DNOW;
669 if( !config_GetInt( p_libvlc, "mmxext" ) )
670 libvlc_global.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
671 if( !config_GetInt( p_libvlc, "sse" ) )
672 libvlc_global.i_cpu &= ~CPU_CAPABILITY_SSE;
673 if( !config_GetInt( p_libvlc, "sse2" ) )
674 libvlc_global.i_cpu &= ~CPU_CAPABILITY_SSE2;
676 #if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
677 if( !config_GetInt( p_libvlc, "altivec" ) )
678 libvlc_global.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
681 #define PRINT_CAPABILITY( capability, string ) \
682 if( libvlc_global.i_cpu & capability ) \
684 strncat( p_capabilities, string " ", \
685 sizeof(p_capabilities) - strlen(p_capabilities) ); \
686 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
689 p_capabilities[0] = '\0';
690 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
691 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
692 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
693 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
694 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
695 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
696 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
697 PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" );
698 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
699 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
700 msg_Dbg( p_libvlc, "CPU has capabilities %s", p_capabilities );
703 * Choose the best memcpy module
705 p_libvlc->p_memcpy_module = module_Need( p_libvlc, "memcpy", "$memcpy", 0 );
707 if( p_libvlc->pf_memcpy == NULL )
709 p_libvlc->pf_memcpy = memcpy;
712 if( p_libvlc->pf_memset == NULL )
714 p_libvlc->pf_memset = memset;
717 p_libvlc->b_stats = config_GetInt( p_libvlc, "stats" );
718 p_libvlc->i_timers = 0;
719 p_libvlc->pp_timers = NULL;
720 vlc_mutex_init( p_libvlc, &p_libvlc->timer_lock );
723 * Initialize hotkey handling
725 var_Create( p_libvlc, "key-pressed", VLC_VAR_INTEGER );
726 p_libvlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
727 /* Do a copy (we don't need to modify the strings) */
728 memcpy( p_libvlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
730 /* Initialize playlist and get commandline files */
731 playlist_ThreadCreate( p_libvlc );
732 if( !p_libvlc->p_playlist )
734 msg_Err( p_libvlc, "playlist initialization failed" );
735 if( p_libvlc->p_memcpy_module != NULL )
737 module_Unneed( p_libvlc, p_libvlc->p_memcpy_module );
739 module_EndBank( p_libvlc );
740 if( i_object ) vlc_object_release( p_libvlc );
743 p_playlist = p_libvlc->p_playlist;
745 psz_modules = config_GetPsz( p_playlist, "services-discovery" );
746 if( psz_modules && *psz_modules )
748 /* Add service discovery modules */
749 playlist_AddSDModules( p_playlist, psz_modules );
751 if( psz_modules ) free( psz_modules );
754 * Load background interfaces
756 psz_modules = config_GetPsz( p_libvlc, "extraintf" );
757 psz_control = config_GetPsz( p_libvlc, "control" );
759 if( psz_modules && *psz_modules && psz_control && *psz_control )
761 psz_modules = (char *)realloc( psz_modules, strlen( psz_modules ) +
762 strlen( psz_control ) + 1 );
763 sprintf( psz_modules, "%s:%s", psz_modules, psz_control );
765 else if( psz_control && *psz_control )
767 if( psz_modules ) free( psz_modules );
768 psz_modules = strdup( psz_control );
771 psz_parser = psz_modules;
772 while ( psz_parser && *psz_parser )
774 char *psz_module, *psz_temp;
775 psz_module = psz_parser;
776 psz_parser = strchr( psz_module, ':' );
782 psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
785 sprintf( psz_temp, "%s,none", psz_module );
786 VLC_AddIntf( 0, psz_temp, VLC_FALSE, VLC_FALSE );
796 * Always load the hotkeys interface if it exists
798 VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
801 * If needed, load the Xscreensaver interface
802 * Currently, only for X
804 #ifdef HAVE_X11_XLIB_H
805 if( config_GetInt( p_libvlc, "disable-screensaver" ) == 1 )
807 VLC_AddIntf( 0, "screensaver,none", VLC_FALSE, VLC_FALSE );
811 if( config_GetInt( p_libvlc, "file-logging" ) == 1 )
813 VLC_AddIntf( 0, "logger,none", VLC_FALSE, VLC_FALSE );
816 if( config_GetInt( p_libvlc, "syslog" ) == 1 )
818 char *psz_logmode = "logmode=syslog";
819 AddIntfInternal( 0, "logger,none", VLC_FALSE, VLC_FALSE, 1, &psz_logmode );
823 if( config_GetInt( p_libvlc, "show-intf" ) == 1 )
825 VLC_AddIntf( 0, "showintf,none", VLC_FALSE, VLC_FALSE );
828 if( config_GetInt( p_libvlc, "network-synchronisation") == 1 )
830 VLC_AddIntf( 0, "netsync,none", VLC_FALSE, VLC_FALSE );
834 * FIXME: kludge to use a p_libvlc-local variable for the Mozilla plugin
836 var_Create( p_libvlc, "drawable", VLC_VAR_INTEGER );
837 var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER );
838 var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER );
839 var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER );
840 var_Create( p_libvlc, "drawable-view-right", VLC_VAR_INTEGER );
841 var_Create( p_libvlc, "drawable-clip-top", VLC_VAR_INTEGER );
842 var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER );
843 var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER );
844 var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER );
846 /* Create volume callback system. */
847 var_Create( p_libvlc, "volume-change", VLC_VAR_BOOL );
850 * Get input filenames given as commandline arguments
852 GetFilenames( p_libvlc, i_argc, ppsz_argv );
855 * Get --open argument
857 var_Create( p_libvlc, "open", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
858 var_Get( p_libvlc, "open", &val );
859 if ( val.psz_string != NULL && *val.psz_string )
861 VLC_AddTarget( p_libvlc->i_object_id, val.psz_string, NULL, 0,
862 PLAYLIST_INSERT, 0 );
864 if ( val.psz_string != NULL ) free( val.psz_string );
870 /*****************************************************************************
871 * VLC_AddIntf: add an interface
872 *****************************************************************************
873 * This function opens an interface plugin and runs it. If b_block is set
874 * to 0, VLC_AddIntf will return immediately and let the interface run in a
875 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
876 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
877 * the playlist when it is completely initialised.
878 *****************************************************************************/
879 int VLC_AddIntf( int i_object, char const *psz_module,
880 vlc_bool_t b_block, vlc_bool_t b_play )
882 return AddIntfInternal( i_object, psz_module, b_block, b_play, 0, NULL );
886 /*****************************************************************************
887 * VLC_Die: ask vlc to die.
888 *****************************************************************************
889 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
890 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
891 *****************************************************************************/
892 int VLC_Die( int i_object )
895 p_libvlc->b_die = VLC_TRUE;
900 /*****************************************************************************
901 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
902 *****************************************************************************/
903 int VLC_CleanUp( int i_object )
905 intf_thread_t * p_intf;
906 playlist_t * p_playlist;
907 vout_thread_t * p_vout;
908 aout_instance_t * p_aout;
909 announce_handler_t * p_announce;
913 /* Ask the interfaces to stop and destroy them */
914 msg_Dbg( p_libvlc, "removing all interfaces" );
915 while( (p_intf = vlc_object_find( p_libvlc, VLC_OBJECT_INTF, FIND_CHILD )) )
917 intf_StopThread( p_intf );
918 vlc_object_detach( p_intf );
919 vlc_object_release( p_intf );
920 intf_Destroy( p_intf );
924 msg_Dbg( p_libvlc, "removing playlist" );
925 playlist_ThreadDestroy( p_libvlc->p_playlist );
927 /* Free video outputs */
928 msg_Dbg( p_libvlc, "removing all video outputs" );
929 while( (p_vout = vlc_object_find( p_libvlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
931 vlc_object_detach( p_vout );
932 vlc_object_release( p_vout );
933 vout_Destroy( p_vout );
936 /* Free audio outputs */
937 msg_Dbg( p_libvlc, "removing all audio outputs" );
938 while( (p_aout = vlc_object_find( p_libvlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
940 vlc_object_detach( (vlc_object_t *)p_aout );
941 vlc_object_release( (vlc_object_t *)p_aout );
942 aout_Delete( p_aout );
945 stats_TimersDumpAll( p_libvlc );
946 stats_TimersClean( p_libvlc );
948 /* Free announce handler(s?) */
949 while( (p_announce = vlc_object_find( p_libvlc, VLC_OBJECT_ANNOUNCE,
952 msg_Dbg( p_libvlc, "removing announce handler" );
953 vlc_object_detach( p_announce );
954 vlc_object_release( p_announce );
955 announce_HandlerDestroy( p_announce );
961 /*****************************************************************************
962 * VLC_Destroy: Destroy everything.
963 *****************************************************************************
964 * This function requests the running threads to finish, waits for their
965 * termination, and destroys their structure.
966 *****************************************************************************/
967 int VLC_Destroy( int i_object )
971 /* Free allocated memory */
972 if( p_libvlc->p_memcpy_module )
974 module_Unneed( p_libvlc, p_libvlc->p_memcpy_module );
975 p_libvlc->p_memcpy_module = NULL;
978 /* Free module bank ! */
979 module_EndBank( p_libvlc );
981 FREENULL( p_libvlc->psz_homedir );
982 FREENULL( p_libvlc->psz_userdir );
983 FREENULL( p_libvlc->psz_configfile );
984 FREENULL( p_libvlc->p_hotkeys );
986 /* System specific cleaning code */
987 system_End( p_libvlc );
990 * Free message queue.
991 * Nobody shall use msg_* afterward.
993 msg_Flush( p_libvlc );
994 msg_Destroy( p_libvlc_global );
996 /* Destroy global iconv */
999 /* Destroy mutexes */
1000 vlc_mutex_destroy( &p_libvlc->config_lock );
1002 vlc_object_detach( p_libvlc );
1004 /* Release object before destroying it */
1005 if( i_object ) vlc_object_release( p_libvlc );
1007 vlc_object_destroy( p_libvlc );
1009 /* Stop thread system: last one out please shut the door! */
1010 vlc_threads_end( p_libvlc_global );
1015 /*****************************************************************************
1016 * VLC_VariableSet: set a vlc variable
1017 *****************************************************************************/
1018 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
1023 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
1024 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
1025 if( !strncmp( psz_var, "conf::", 6 ) )
1027 module_config_t *p_item;
1028 char const *psz_newvar = psz_var + 6;
1030 p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_newvar );
1034 switch( p_item->i_type )
1036 case CONFIG_ITEM_BOOL:
1037 config_PutInt( p_libvlc, psz_newvar, value.b_bool );
1039 case CONFIG_ITEM_INTEGER:
1040 config_PutInt( p_libvlc, psz_newvar, value.i_int );
1042 case CONFIG_ITEM_FLOAT:
1043 config_PutFloat( p_libvlc, psz_newvar, value.f_float );
1046 config_PutPsz( p_libvlc, psz_newvar, value.psz_string );
1049 if( i_object ) vlc_object_release( p_libvlc );
1054 i_ret = var_Set( p_libvlc, psz_var, value );
1060 /*****************************************************************************
1061 * VLC_VariableGet: get a vlc variable
1062 *****************************************************************************/
1063 int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
1067 i_ret = var_Get( p_libvlc , psz_var, p_value );
1072 /*****************************************************************************
1073 * VLC_VariableType: get a vlc variable type
1074 *****************************************************************************/
1075 int VLC_VariableType( int i_object, char const *psz_var, int *pi_type )
1079 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
1080 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
1081 if( !strncmp( psz_var, "conf::", 6 ) )
1083 module_config_t *p_item;
1084 char const *psz_newvar = psz_var + 6;
1086 p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_newvar );
1090 switch( p_item->i_type )
1092 case CONFIG_ITEM_BOOL:
1093 i_type = VLC_VAR_BOOL;
1095 case CONFIG_ITEM_INTEGER:
1096 i_type = VLC_VAR_INTEGER;
1098 case CONFIG_ITEM_FLOAT:
1099 i_type = VLC_VAR_FLOAT;
1102 i_type = VLC_VAR_STRING;
1110 i_type = VLC_VAR_TYPE & var_Type( p_libvlc , psz_var );
1122 #define LIBVLC_PLAYLIST_FUNC \
1123 libvlc_int_t *p_libvlc = vlc_current_object( i_object );\
1124 if( !p_libvlc || !p_libvlc->p_playlist ) return VLC_ENOOBJ; \
1125 vlc_object_yield( p_libvlc->p_playlist );
1127 #define LIBVLC_PLAYLIST_FUNC_END \
1128 vlc_object_release( p_libvlc->p_playlist ); \
1129 if( i_object ) vlc_object_release( p_libvlc );
1131 /*****************************************************************************
1132 * VLC_AddTarget: adds a target for playing.
1133 *****************************************************************************
1134 * This function adds psz_target to the playlist
1135 *****************************************************************************/
1137 int VLC_AddTarget( int i_object, char const *psz_target,
1138 char const **ppsz_options, int i_options,
1139 int i_mode, int i_pos )
1142 LIBVLC_PLAYLIST_FUNC;
1143 i_err = playlist_PlaylistAddExt( p_libvlc->p_playlist, psz_target,
1144 psz_target, i_mode, i_pos, -1,
1145 ppsz_options, i_options );
1146 LIBVLC_PLAYLIST_FUNC_END;
1150 /*****************************************************************************
1151 * VLC_Play: play the playlist
1152 *****************************************************************************/
1153 int VLC_Play( int i_object )
1155 LIBVLC_PLAYLIST_FUNC;
1156 playlist_Play( p_libvlc->p_playlist );
1157 LIBVLC_PLAYLIST_FUNC_END;
1161 /*****************************************************************************
1162 * VLC_Pause: toggle pause
1163 *****************************************************************************/
1164 int VLC_Pause( int i_object )
1166 LIBVLC_PLAYLIST_FUNC;
1167 playlist_Pause( p_libvlc->p_playlist );
1168 LIBVLC_PLAYLIST_FUNC_END;
1172 /*****************************************************************************
1173 * VLC_Stop: stop playback
1174 *****************************************************************************/
1175 int VLC_Stop( int i_object )
1177 LIBVLC_PLAYLIST_FUNC;
1178 playlist_Stop( p_libvlc->p_playlist );
1179 LIBVLC_PLAYLIST_FUNC_END;
1183 /*****************************************************************************
1184 * VLC_IsPlaying: Query for Playlist Status
1185 *****************************************************************************/
1186 vlc_bool_t VLC_IsPlaying( int i_object )
1188 vlc_bool_t b_playing;
1190 LIBVLC_PLAYLIST_FUNC;
1191 if( p_libvlc->p_playlist->p_input )
1194 var_Get( p_libvlc->p_playlist->p_input, "state", &val );
1195 b_playing = ( val.i_int == PLAYING_S );
1199 b_playing = playlist_IsPlaying( p_libvlc->p_playlist );
1201 LIBVLC_PLAYLIST_FUNC_END;
1206 * Get the current position in a input
1208 * Return the current position as a float
1209 * \note For some inputs, this will be unknown.
1211 * \param i_object a vlc object id
1212 * \return a float in the range of 0.0 - 1.0
1214 float VLC_PositionGet( int i_object )
1216 input_thread_t *p_input;
1218 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1220 /* Check that the handle is valid */
1226 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
1230 if( i_object ) vlc_object_release( p_libvlc );
1234 var_Get( p_input, "position", &val );
1235 vlc_object_release( p_input );
1237 if( i_object ) vlc_object_release( p_libvlc );
1242 * Set the current position in a input
1244 * Set the current position in a input and then return
1245 * the current position as a float.
1246 * \note For some inputs, this will be unknown.
1248 * \param i_object a vlc object id
1249 * \param i_position a float in the range of 0.0 - 1.0
1250 * \return a float in the range of 0.0 - 1.0
1252 float VLC_PositionSet( int i_object, float i_position )
1254 input_thread_t *p_input;
1256 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1258 /* Check that the handle is valid */
1264 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
1268 if( i_object ) vlc_object_release( p_libvlc );
1272 val.f_float = i_position;
1273 var_Set( p_input, "position", val );
1274 var_Get( p_input, "position", &val );
1275 vlc_object_release( p_input );
1277 if( i_object ) vlc_object_release( p_libvlc );
1282 * Get the current position in a input
1284 * Return the current position in seconds from the start.
1285 * \note For some inputs, this will be unknown.
1287 * \param i_object a vlc object id
1288 * \return the offset from 0:00 in seconds
1290 int VLC_TimeGet( int i_object )
1292 input_thread_t *p_input;
1294 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1296 /* Check that the handle is valid */
1302 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
1306 if( i_object ) vlc_object_release( p_libvlc );
1310 var_Get( p_input, "time", &val );
1311 vlc_object_release( p_input );
1313 if( i_object ) vlc_object_release( p_libvlc );
1314 return val.i_time / 1000000;
1318 * Seek to a position in the current input
1320 * Seek i_seconds in the current input. If b_relative is set,
1321 * then the seek will be relative to the current position, otherwise
1322 * it will seek to i_seconds from the beginning of the input.
1323 * \note For some inputs, this will be unknown.
1325 * \param i_object a vlc object id
1326 * \param i_seconds seconds from current position or from beginning of input
1327 * \param b_relative seek relative from current position
1328 * \return VLC_SUCCESS on success
1330 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
1332 input_thread_t *p_input;
1334 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1336 /* Check that the handle is valid */
1342 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
1346 if( i_object ) vlc_object_release( p_libvlc );
1352 val.i_time = i_seconds;
1353 val.i_time = val.i_time * 1000000L;
1354 var_Set( p_input, "time-offset", val );
1358 val.i_time = i_seconds;
1359 val.i_time = val.i_time * 1000000L;
1360 var_Set( p_input, "time", val );
1362 vlc_object_release( p_input );
1364 if( i_object ) vlc_object_release( p_libvlc );
1369 * Get the total length of a input
1371 * Return the total length in seconds from the current input.
1372 * \note For some inputs, this will be unknown.
1374 * \param i_object a vlc object id
1375 * \return the length in seconds
1377 int VLC_LengthGet( int i_object )
1379 input_thread_t *p_input;
1381 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1383 /* Check that the handle is valid */
1389 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
1393 if( i_object ) vlc_object_release( p_libvlc );
1397 var_Get( p_input, "length", &val );
1398 vlc_object_release( p_input );
1400 if( i_object ) vlc_object_release( p_libvlc );
1401 return val.i_time / 1000000L;
1405 * Play the input faster than realtime
1407 * 2x, 4x, 8x faster than realtime
1408 * \note For some inputs, this will be impossible.
1410 * \param i_object a vlc object id
1411 * \return the current speedrate
1413 float VLC_SpeedFaster( int i_object )
1415 input_thread_t *p_input;
1417 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1419 /* Check that the handle is valid */
1425 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
1429 if( i_object ) vlc_object_release( p_libvlc );
1433 val.b_bool = VLC_TRUE;
1434 var_Set( p_input, "rate-faster", val );
1435 var_Get( p_input, "rate", &val );
1436 vlc_object_release( p_input );
1438 if( i_object ) vlc_object_release( p_libvlc );
1439 return val.f_float / INPUT_RATE_DEFAULT;
1443 * Play the input slower than realtime
1445 * 1/2x, 1/4x, 1/8x slower than realtime
1446 * \note For some inputs, this will be impossible.
1448 * \param i_object a vlc object id
1449 * \return the current speedrate
1451 float VLC_SpeedSlower( int i_object )
1453 input_thread_t *p_input;
1455 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1457 /* Check that the handle is valid */
1463 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
1467 if( i_object ) vlc_object_release( p_libvlc );
1471 val.b_bool = VLC_TRUE;
1472 var_Set( p_input, "rate-slower", val );
1473 var_Get( p_input, "rate", &val );
1474 vlc_object_release( p_input );
1476 if( i_object ) vlc_object_release( p_libvlc );
1477 return val.f_float / INPUT_RATE_DEFAULT;
1481 * Return the current playlist item
1483 * Returns the index of the playlistitem that is currently selected for play.
1484 * This is valid even if nothing is currently playing.
1486 * \param i_object a vlc object id
1487 * \return the current index
1489 int VLC_PlaylistIndex( int i_object )
1491 printf( "This function is deprecated and should not be used anymore" );
1496 * Total amount of items in the playlist
1498 * \param i_object a vlc object id
1499 * \return amount of playlist items
1501 int VLC_PlaylistNumberOfItems( int i_object )
1504 playlist_t * p_playlist;
1505 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1507 /* Check that the handle is valid */
1513 p_playlist = vlc_object_find( p_libvlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1517 if( i_object ) vlc_object_release( p_libvlc );
1521 i_size = p_playlist->i_size;
1522 vlc_object_release( p_playlist );
1524 if( i_object ) vlc_object_release( p_libvlc );
1529 * Next playlist item
1531 * Skip to the next playlistitem and play it.
1533 * \param i_object a vlc object id
1534 * \return VLC_SUCCESS on success
1536 int VLC_PlaylistNext( int i_object )
1538 playlist_t * p_playlist;
1539 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1541 /* Check that the handle is valid */
1547 p_playlist = vlc_object_find( p_libvlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1551 if( i_object ) vlc_object_release( p_libvlc );
1555 playlist_Next( p_playlist );
1556 vlc_object_release( p_playlist );
1558 if( i_object ) vlc_object_release( p_libvlc );
1563 * Previous playlist item
1565 * Skip to the previous playlistitem and play it.
1567 * \param i_object a vlc object id
1568 * \return VLC_SUCCESS on success
1570 int VLC_PlaylistPrev( int i_object )
1572 playlist_t * p_playlist;
1573 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1575 /* Check that the handle is valid */
1581 p_playlist = vlc_object_find( p_libvlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1585 if( i_object ) vlc_object_release( p_libvlc );
1589 playlist_Prev( p_playlist );
1590 vlc_object_release( p_playlist );
1592 if( i_object ) vlc_object_release( p_libvlc );
1597 /*****************************************************************************
1598 * VLC_PlaylistClear: Empty the playlist
1599 *****************************************************************************/
1600 int VLC_PlaylistClear( int i_object )
1602 playlist_t * p_playlist;
1603 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1605 /* Check that the handle is valid */
1611 p_playlist = vlc_object_find( p_libvlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1615 if( i_object ) vlc_object_release( p_libvlc );
1619 playlist_Clear( p_playlist );
1621 vlc_object_release( p_playlist );
1623 if( i_object ) vlc_object_release( p_libvlc );
1630 * \param i_object a vlc object id
1631 * \param i_volume something in a range from 0-200
1632 * \return the new volume (range 0-200 %)
1634 int VLC_VolumeSet( int i_object, int i_volume )
1636 audio_volume_t i_vol = 0;
1637 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1639 /* Check that the handle is valid */
1645 if( i_volume >= 0 && i_volume <= 200 )
1647 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
1648 aout_VolumeSet( p_libvlc, i_vol );
1651 if( i_object ) vlc_object_release( p_libvlc );
1652 return i_vol * 200 / AOUT_VOLUME_MAX;
1656 * Get the current volume
1658 * Retrieve the current volume.
1660 * \param i_object a vlc object id
1661 * \return the current volume (range 0-200 %)
1663 int VLC_VolumeGet( int i_object )
1665 audio_volume_t i_volume;
1666 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1668 /* Check that the handle is valid */
1674 aout_VolumeGet( p_libvlc, &i_volume );
1676 if( i_object ) vlc_object_release( p_libvlc );
1677 return i_volume*200/AOUT_VOLUME_MAX;
1681 * Mute/Unmute the volume
1683 * \param i_object a vlc object id
1684 * \return VLC_SUCCESS on success
1686 int VLC_VolumeMute( int i_object )
1688 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1690 /* Check that the handle is valid */
1696 aout_VolumeMute( p_libvlc, NULL );
1698 if( i_object ) vlc_object_release( p_libvlc );
1702 /*****************************************************************************
1703 * VLC_FullScreen: toggle fullscreen mode
1704 *****************************************************************************/
1705 int VLC_FullScreen( int i_object )
1707 vout_thread_t *p_vout;
1708 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1715 p_vout = vlc_object_find( p_libvlc, VLC_OBJECT_VOUT, FIND_CHILD );
1719 if( i_object ) vlc_object_release( p_libvlc );
1723 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1724 vlc_object_release( p_vout );
1726 if( i_object ) vlc_object_release( p_libvlc );
1730 /* following functions are local */
1733 static int AddIntfInternal( int i_object, char const *psz_module,
1734 vlc_bool_t b_block, vlc_bool_t b_play,
1735 int i_options, char **ppsz_options )
1738 intf_thread_t *p_intf;
1739 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
1747 if( p_libvlc->p_libvlc_global->b_daemon && b_block && !psz_module )
1749 /* Daemon mode hack.
1750 * We prefer the dummy interface if none is specified. */
1751 char *psz_interface = config_GetPsz( p_libvlc, "intf" );
1752 if( !psz_interface || !*psz_interface ) psz_module = "dummy";
1753 if( psz_interface ) free( psz_interface );
1757 /* Try to create the interface */
1758 p_intf = intf_Create( p_libvlc, psz_module ? psz_module : "$intf",
1759 i_options, ppsz_options );
1761 if( p_intf == NULL )
1763 msg_Err( p_libvlc, "interface \"%s\" initialization failed", psz_module );
1764 if( i_object ) vlc_object_release( p_libvlc );
1765 return VLC_EGENERIC;
1768 /* Interface doesn't handle play on start so do it ourselves */
1769 if( !p_intf->b_play && b_play ) VLC_Play( i_object );
1771 /* Try to run the interface */
1772 p_intf->b_play = b_play;
1773 p_intf->b_block = b_block;
1774 i_err = intf_RunThread( p_intf );
1777 vlc_object_detach( p_intf );
1778 intf_Destroy( p_intf );
1779 if( i_object ) vlc_object_release( p_libvlc );
1783 if( i_object ) vlc_object_release( p_libvlc );
1788 /*****************************************************************************
1789 * SetLanguage: set the interface language.
1790 *****************************************************************************
1791 * We set the LC_MESSAGES locale category for interface messages and buttons,
1792 * as well as the LC_CTYPE category for string sorting and possible wide
1793 * character support.
1794 *****************************************************************************/
1795 static void SetLanguage ( char const *psz_lang )
1797 #if defined( ENABLE_NLS ) \
1798 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
1801 #if defined( __APPLE__ ) || defined ( WIN32 ) || defined( SYS_BEOS )
1805 if( psz_lang && !*psz_lang )
1807 # if defined( HAVE_LC_MESSAGES )
1808 setlocale( LC_MESSAGES, psz_lang );
1810 setlocale( LC_CTYPE, psz_lang );
1815 /* I need that under Darwin, please check it doesn't disturb
1816 * other platforms. --Meuuh */
1817 setenv( "LANG", psz_lang, 1 );
1819 #elif defined( SYS_BEOS ) || defined( WIN32 )
1820 /* We set LC_ALL manually because it is the only way to set
1821 * the language at runtime under eg. Windows. Beware that this
1822 * makes the environment unconsistent when libvlc is unloaded and
1823 * should probably be moved to a safer place like vlc.c. */
1824 static char psz_lcall[20];
1825 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
1826 psz_lcall[19] = '\0';
1827 putenv( psz_lcall );
1830 setlocale( LC_ALL, psz_lang );
1833 /* Specify where to find the locales for current domain */
1834 #if !defined( __APPLE__ ) && !defined( WIN32 ) && !defined( SYS_BEOS )
1835 psz_path = LOCALEDIR;
1837 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc_global.psz_vlcpath,
1841 if( !bindtextdomain( PACKAGE_NAME, psz_path ) )
1843 fprintf( stderr, "warning: couldn't bind domain %s in directory %s\n",
1844 PACKAGE_NAME, psz_path );
1847 /* Set the default domain */
1848 bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
1852 /*****************************************************************************
1853 * GetFilenames: parse command line options which are not flags
1854 *****************************************************************************
1855 * Parse command line for input files as well as their associated options.
1856 * An option always follows its associated input and begins with a ":".
1857 *****************************************************************************/
1858 static int GetFilenames( libvlc_int_t *p_vlc, int i_argc, char *ppsz_argv[] )
1860 int i_opt, i_options;
1862 /* We assume that the remaining parameters are filenames
1863 * and their input options */
1864 for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
1866 const char *psz_target;
1869 /* Count the input options */
1870 while( *ppsz_argv[ i_opt ] == ':' && i_opt > optind )
1876 /* TODO: write an internal function of this one, to avoid
1877 * unnecessary lookups. */
1878 /* FIXME: should we convert options to UTF-8 as well ?? */
1879 psz_target = FromLocale( ppsz_argv[ i_opt ] );
1880 VLC_AddTarget( p_vlc->i_object_id, psz_target,
1881 (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
1883 PLAYLIST_INSERT, 0 );
1884 LocaleFree( psz_target );
1890 /*****************************************************************************
1891 * Help: print program help
1892 *****************************************************************************
1893 * Print a short inline help. Message interface is initialized at this stage.
1894 *****************************************************************************/
1895 static void Help( libvlc_int_t *p_this, char const *psz_help_name )
1898 ShowConsole( VLC_TRUE );
1901 if( psz_help_name && !strcmp( psz_help_name, "help" ) )
1903 utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
1904 Usage( p_this, "help" );
1905 Usage( p_this, "main" );
1907 else if( psz_help_name && !strcmp( psz_help_name, "longhelp" ) )
1909 utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
1910 Usage( p_this, NULL );
1912 else if( psz_help_name )
1914 Usage( p_this, psz_help_name );
1917 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1922 /*****************************************************************************
1923 * Usage: print module usage
1924 *****************************************************************************
1925 * Print a short inline help. Message interface is initialized at this stage.
1926 *****************************************************************************/
1927 static void Usage( libvlc_int_t *p_this, char const *psz_module_name )
1929 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
1930 /* short option ------' | | | | | | |
1931 * option name ------------' | | | | | |
1932 * <bra -------------------------' | | | | |
1933 * option type or "" --------------' | | | |
1934 * ket> -----------------------------' | | |
1935 * padding spaces ---------------------' | |
1936 * comment -------------------------------' |
1937 * comment suffix --------------------------'
1939 * The purpose of having bra and ket is that we might i18n them as well.
1941 #define LINE_START 8
1942 #define PADDING_SPACES 25
1945 module_config_t *p_item;
1946 char psz_spaces_text[PADDING_SPACES+LINE_START+1];
1947 char psz_spaces_longtext[LINE_START+3];
1948 char psz_format[sizeof(FORMAT_STRING)];
1949 char psz_buffer[10000];
1952 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
1953 vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" );
1954 vlc_bool_t b_description;
1956 memset( psz_spaces_text, ' ', PADDING_SPACES+LINE_START );
1957 psz_spaces_text[PADDING_SPACES+LINE_START] = '\0';
1958 memset( psz_spaces_longtext, ' ', LINE_START+2 );
1959 psz_spaces_longtext[LINE_START+2] = '\0';
1961 strcpy( psz_format, FORMAT_STRING );
1963 /* List all modules */
1964 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1966 /* Enumerate the config for each module */
1967 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1969 vlc_bool_t b_help_module;
1971 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1973 if( psz_module_name && strcmp( psz_module_name,
1974 p_parser->psz_object_name ) )
1979 /* Ignore modules without config options */
1980 if( !p_parser->i_config_items )
1985 /* Ignore modules with only advanced config options if requested */
1988 for( p_item = p_parser->p_config;
1989 p_item->i_type != CONFIG_HINT_END;
1992 if( (p_item->i_type & CONFIG_ITEM) &&
1993 !p_item->b_advanced ) break;
1995 if( p_item->i_type == CONFIG_HINT_END ) continue;
1998 /* Print name of module */
1999 if( strcmp( "main", p_parser->psz_object_name ) )
2000 utf8_fprintf( stdout, "\n %s\n", p_parser->psz_longname );
2002 b_help_module = !strcmp( "help", p_parser->psz_object_name );
2004 /* Print module options */
2005 for( p_item = p_parser->p_config;
2006 p_item->i_type != CONFIG_HINT_END;
2009 char *psz_text, *psz_spaces = psz_spaces_text;
2010 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
2011 char *psz_suf = "", *psz_prefix = NULL;
2014 /* Skip deprecated options */
2015 if( p_item->psz_current )
2019 /* Skip advanced options if requested */
2020 if( p_item->b_advanced && !b_advanced )
2025 switch( p_item->i_type )
2027 case CONFIG_HINT_CATEGORY:
2028 case CONFIG_HINT_USAGE:
2029 if( !strcmp( "main", p_parser->psz_object_name ) )
2030 utf8_fprintf( stdout, "\n %s\n", p_item->psz_text );
2033 case CONFIG_ITEM_STRING:
2034 case CONFIG_ITEM_FILE:
2035 case CONFIG_ITEM_DIRECTORY:
2036 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
2037 case CONFIG_ITEM_MODULE_CAT:
2038 case CONFIG_ITEM_MODULE_LIST:
2039 case CONFIG_ITEM_MODULE_LIST_CAT:
2040 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
2042 if( p_item->ppsz_list )
2045 psz_type = psz_buffer;
2047 for( i = 0; p_item->ppsz_list[i]; i++ )
2049 if( i ) strcat( psz_type, "," );
2050 strcat( psz_type, p_item->ppsz_list[i] );
2055 case CONFIG_ITEM_INTEGER:
2056 case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
2057 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
2059 if( p_item->i_list )
2062 psz_type = psz_buffer;
2064 for( i = 0; p_item->ppsz_list_text[i]; i++ )
2066 if( i ) strcat( psz_type, ", " );
2067 sprintf( psz_type + strlen(psz_type), "%i (%s)",
2069 p_item->ppsz_list_text[i] );
2074 case CONFIG_ITEM_FLOAT:
2075 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
2077 case CONFIG_ITEM_BOOL:
2078 psz_bra = ""; psz_type = ""; psz_ket = "";
2079 if( !b_help_module )
2081 psz_suf = p_item->i_value ? _(" (default enabled)") :
2082 _(" (default disabled)");
2092 /* Add short option if any */
2093 if( p_item->i_short )
2095 sprintf( psz_short, "-%c,", p_item->i_short );
2099 strcpy( psz_short, " " );
2102 i = PADDING_SPACES - strlen( p_item->psz_name )
2103 - strlen( psz_bra ) - strlen( psz_type )
2104 - strlen( psz_ket ) - 1;
2106 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
2108 psz_prefix = ", --no-";
2109 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
2114 psz_spaces[0] = '\n';
2119 psz_spaces[i] = '\0';
2122 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
2124 utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2125 psz_prefix, p_item->psz_name, psz_bra, psz_type,
2126 psz_ket, psz_spaces );
2130 utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2131 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
2134 psz_spaces[i] = ' ';
2136 /* We wrap the rest of the output */
2137 sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
2138 b_description = config_GetInt( p_this, "help-verbose" );
2141 psz_text = psz_buffer;
2144 char *psz_parser, *psz_word;
2145 size_t i_end = strlen( psz_text );
2147 /* If the remaining text fits in a line, print it. */
2148 if( i_end <= (size_t)i_width )
2150 utf8_fprintf( stdout, "%s\n", psz_text );
2154 /* Otherwise, eat as many words as possible */
2155 psz_parser = psz_text;
2158 psz_word = psz_parser;
2159 psz_parser = strchr( psz_word, ' ' );
2160 /* If no space was found, we reached the end of the text
2161 * block; otherwise, we skip the space we just found. */
2162 psz_parser = psz_parser ? psz_parser + 1
2165 } while( psz_parser - psz_text <= i_width );
2167 /* We cut a word in one of these cases:
2168 * - it's the only word in the line and it's too long.
2169 * - we used less than 80% of the width and the word we are
2170 * going to wrap is longer than 40% of the width, and even
2171 * if the word would have fit in the next line. */
2172 if( psz_word == psz_text
2173 || ( psz_word - psz_text < 80 * i_width / 100
2174 && psz_parser - psz_word > 40 * i_width / 100 ) )
2176 char c = psz_text[i_width];
2177 psz_text[i_width] = '\0';
2178 utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2179 psz_text += i_width;
2184 psz_word[-1] = '\0';
2185 utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2186 psz_text = psz_word;
2190 if( b_description && p_item->psz_longtext )
2192 sprintf( psz_buffer, "%s%s", p_item->psz_longtext, psz_suf );
2193 b_description = VLC_FALSE;
2194 psz_spaces = psz_spaces_longtext;
2195 utf8_fprintf( stdout, "%s", psz_spaces );
2201 /* Release the module list */
2202 vlc_list_release( p_list );
2205 /*****************************************************************************
2206 * ListModules: list the available modules with their description
2207 *****************************************************************************
2208 * Print a list of all available modules (builtins and plugins) and a short
2209 * description for each one.
2210 *****************************************************************************/
2211 static void ListModules( libvlc_int_t *p_this )
2215 char psz_spaces[22];
2218 memset( psz_spaces, ' ', 22 );
2221 ShowConsole( VLC_TRUE );
2224 /* List all modules */
2225 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2227 /* Enumerate each module */
2228 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2232 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2234 /* Nasty hack, but right now I'm too tired to think about a nice
2236 i = 22 - strlen( p_parser->psz_object_name ) - 1;
2240 utf8_fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
2241 psz_spaces, p_parser->psz_longname );
2243 psz_spaces[i] = ' ';
2246 vlc_list_release( p_list );
2248 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2253 /*****************************************************************************
2254 * Version: print complete program version
2255 *****************************************************************************
2256 * Print complete program version and build number.
2257 *****************************************************************************/
2258 static void Version( void )
2261 ShowConsole( VLC_TRUE );
2264 utf8_fprintf( stdout, _("VLC version %s\n"), VLC_Version() );
2265 utf8_fprintf( stdout, _("Compiled by %s@%s.%s\n"),
2266 VLC_CompileBy(), VLC_CompileHost(), VLC_CompileDomain() );
2267 utf8_fprintf( stdout, _("Compiler: %s\n"), VLC_Compiler() );
2268 #ifndef HAVE_SHARED_LIBVLC
2269 if( strcmp( VLC_Changeset(), "exported" ) )
2270 utf8_fprintf( stdout, _("Based upon svn changeset [%s]\n"),
2273 utf8_fprintf( stdout, LICENSE_MSG );
2275 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2280 /*****************************************************************************
2281 * ShowConsole: On Win32, create an output console for debug messages
2282 *****************************************************************************
2283 * This function is useful only on Win32.
2284 *****************************************************************************/
2286 static void ShowConsole( vlc_bool_t b_dofile )
2291 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2295 freopen( "CONOUT$", "w", stderr );
2296 freopen( "CONIN$", "r", stdin );
2298 if( b_dofile && (f_help = fopen( "vlc-help.txt", "wt" )) )
2301 freopen( "vlc-help.txt", "wt", stdout );
2302 utf8_fprintf( stderr, _("\nDumped content to vlc-help.txt file.\n") );
2305 else freopen( "CONOUT$", "w", stdout );
2311 /*****************************************************************************
2312 * PauseConsole: On Win32, wait for a key press before closing the console
2313 *****************************************************************************
2314 * This function is useful only on Win32.
2315 *****************************************************************************/
2317 static void PauseConsole( void )
2321 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2323 utf8_fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
2331 /*****************************************************************************
2332 * ConsoleWidth: Return the console width in characters
2333 *****************************************************************************
2334 * We use the stty shell command to get the console width; if this fails or
2335 * if the width is less than 80, we default to 80.
2336 *****************************************************************************/
2337 static int ConsoleWidth( void )
2342 char buf[20], *psz_parser;
2346 file = popen( "stty size 2>/dev/null", "r" );
2349 i_ret = fread( buf, 1, 20, file );
2353 psz_parser = strchr( buf, ' ' );
2356 i_ret = atoi( psz_parser + 1 );
2371 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
2372 vlc_value_t old_val, vlc_value_t new_val, void *param)
2374 libvlc_int_t *p_vlc = (libvlc_int_t *)p_this;
2376 if( new_val.i_int >= -1 )
2378 p_vlc->p_libvlc_global->i_verbose = __MIN( new_val.i_int, 2 );
2383 /*****************************************************************************
2384 * InitDeviceValues: initialize device values
2385 *****************************************************************************
2386 * This function inits the dvd, vcd and cd-audio values
2387 *****************************************************************************/
2388 static void InitDeviceValues( libvlc_int_t *p_vlc )
2391 LibHalContext * ctx;
2396 DBusConnection *p_connection;
2400 ctx = libhal_ctx_new();
2402 dbus_error_init( &error );
2403 p_connection = dbus_bus_get ( DBUS_BUS_SYSTEM, &error );
2404 if( dbus_error_is_set( &error ) )
2406 dbus_error_free( &error );
2409 libhal_ctx_set_dbus_connection( ctx, p_connection );
2410 if( libhal_ctx_init( ctx, &error ) )
2412 if( ( ctx = hal_initialize( NULL, FALSE ) ) )
2416 if( ( devices = libhal_get_all_devices( ctx, &i_devices, NULL ) ) )
2418 if( ( devices = hal_get_all_devices( ctx, &i_devices ) ) )
2421 for( i = 0; i < i_devices; i++ )
2424 if( !libhal_device_property_exists( ctx, devices[i],
2425 "storage.cdrom.dvd", NULL ) )
2427 if( !hal_device_property_exists( ctx, devices[ i ],
2428 "storage.cdrom.dvd" ) )
2434 b_dvd = libhal_device_get_property_bool( ctx, devices[ i ],
2435 "storage.cdrom.dvd", NULL );
2436 block_dev = libhal_device_get_property_string( ctx,
2437 devices[ i ], "block.device" , NULL );
2439 b_dvd = hal_device_get_property_bool( ctx, devices[ i ],
2440 "storage.cdrom.dvd" );
2441 block_dev = hal_device_get_property_string( ctx, devices[ i ],
2446 config_PutPsz( p_vlc, "dvd", block_dev );
2449 config_PutPsz( p_vlc, "vcd", block_dev );
2450 config_PutPsz( p_vlc, "cd-audio", block_dev );
2452 libhal_free_string( block_dev );
2454 hal_free_string( block_dev );
2458 libhal_free_string_array( devices );
2460 hal_free_string_array( devices );
2465 libhal_ctx_shutdown( ctx, NULL );
2467 hal_shutdown( ctx );
2472 msg_Warn( p_vlc, "Unable to get HAL device properties" );