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_t libvlc;
90 static libvlc_t * p_libvlc;
91 static vlc_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 ( vlc_t *, int, char *[] );
104 static void Help ( vlc_t *, char const *psz_help_name );
105 static void Usage ( vlc_t *, char const *psz_module_name );
106 static void ListModules ( vlc_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( vlc_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 vlc_t * vlc_current_object( int i_object )
130 return vlc_object_get( p_libvlc, 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 vlc_t * p_vlc = NULL;
191 /* &libvlc never changes, so we can safely call this multiple times. */
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 );
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, "libvlc", VLC_VAR_MUTEX );
205 var_Get( p_libvlc, "libvlc", &lockval );
206 vlc_mutex_lock( lockval.p_address );
207 if( !libvlc.b_ready )
211 /* Guess what CPU we have */
212 libvlc.i_cpu = CPUCapabilities();
214 /* Find verbosity from VLC_VERBOSE environment variable */
215 psz_env = getenv( "VLC_VERBOSE" );
216 libvlc.i_verbose = psz_env ? atoi( psz_env ) : -1;
218 #if defined( HAVE_ISATTY ) && !defined( WIN32 )
219 libvlc.b_color = isatty( 2 ); /* 2 is for stderr */
221 libvlc.b_color = VLC_FALSE;
224 /* Initialize message queue */
225 msg_Create( p_libvlc );
227 /* Announce who we are */
228 msg_Dbg( p_libvlc, COPYRIGHT_MESSAGE );
229 msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
231 /* The module bank will be initialized later */
232 libvlc.p_module_bank = NULL;
234 libvlc.b_ready = VLC_TRUE;
236 vlc_mutex_unlock( lockval.p_address );
237 var_Destroy( p_libvlc, "libvlc" );
239 /* Allocate a vlc object */
240 p_vlc = vlc_object_create( p_libvlc, VLC_OBJECT_VLC );
245 p_vlc->thread_id = 0;
247 p_vlc->psz_object_name = "root";
249 /* Initialize mutexes */
250 vlc_mutex_init( p_vlc, &p_vlc->config_lock );
252 vlc_mutex_init( p_vlc, &p_vlc->quicktime_lock );
253 vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW );
256 /* Store our newly allocated structure in the global list */
257 vlc_object_attach( p_vlc, p_libvlc );
259 /* Store data for the non-reentrant API */
260 p_static_vlc = p_vlc;
262 return p_vlc->i_object_id;
265 /*****************************************************************************
266 * VLC_Init: initialize a vlc_t structure.
267 *****************************************************************************
268 * This function initializes a previously allocated vlc_t structure:
270 * - gettext initialization
271 * - message queue, module bank and playlist initialization
272 * - configuration and commandline parsing
273 *****************************************************************************/
274 int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
276 char p_capabilities[200];
281 vlc_bool_t b_exit = VLC_FALSE;
282 int i_ret = VLC_EEXIT;
283 vlc_t * p_vlc = vlc_current_object( i_object );
284 module_t *p_help_module;
285 playlist_t *p_playlist;
287 #if defined( ENABLE_NLS ) \
288 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
289 # if defined (WIN32) || defined (__APPLE__)
300 * System specific initialization code
302 system_Init( p_vlc, &i_argc, ppsz_argv );
304 /* Get the executable name (similar to the basename command) */
307 p_vlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
310 if( *p_tmp == '/' ) p_vlc->psz_object_name = ++p_tmp;
316 p_vlc->psz_object_name = "vlc";
320 * Support for gettext
325 * Global iconv, must be done after setlocale()
326 * so that vlc_current_charset() works.
328 LocaleInit( (vlc_object_t *)p_vlc );
330 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
331 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
333 /* Initialize the module bank and load the configuration of the
334 * main module. We need to do this at this stage to be able to display
335 * a short help if required by the user. (short help == main module
337 module_InitBank( p_vlc );
339 /* Hack: insert the help module here */
340 p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
341 if( p_help_module == NULL )
343 module_EndBank( p_vlc );
344 if( i_object ) vlc_object_release( p_vlc );
347 p_help_module->psz_object_name = "help";
348 p_help_module->psz_longname = N_("Help options");
349 config_Duplicate( p_help_module, p_help_config );
350 vlc_object_attach( p_help_module, libvlc.p_module_bank );
353 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE ) )
355 vlc_object_detach( p_help_module );
356 config_Free( p_help_module );
357 vlc_object_destroy( p_help_module );
358 module_EndBank( p_vlc );
359 if( i_object ) vlc_object_release( p_vlc );
363 /* Check for short help option */
364 if( config_GetInt( p_vlc, "help" ) )
366 Help( p_vlc, "help" );
368 i_ret = VLC_EEXITSUCCESS;
370 /* Check for version option */
371 else if( config_GetInt( p_vlc, "version" ) )
375 i_ret = VLC_EEXITSUCCESS;
378 /* Set the config file stuff */
379 p_vlc->psz_homedir = config_GetHomeDir();
380 p_vlc->psz_userdir = config_GetUserDir();
381 if( p_vlc->psz_userdir == NULL )
382 p_vlc->psz_userdir = strdup(p_vlc->psz_homedir);
383 p_vlc->psz_configfile = config_GetPsz( p_vlc, "config" );
384 if( p_vlc->psz_configfile != NULL && p_vlc->psz_configfile[0] == '~'
385 && p_vlc->psz_configfile[1] == '/' )
387 char *psz = malloc( strlen(p_vlc->psz_userdir)
388 + strlen(p_vlc->psz_configfile) );
389 /* This is incomplete : we should also support the ~cmassiot/ syntax. */
390 sprintf( psz, "%s/%s", p_vlc->psz_userdir,
391 p_vlc->psz_configfile + 2 );
392 free( p_vlc->psz_configfile );
393 p_vlc->psz_configfile = psz;
396 /* Check for plugins cache options */
397 if( config_GetInt( p_vlc, "reset-plugins-cache" ) )
399 libvlc.p_module_bank->b_cache_delete = VLC_TRUE;
402 /* Hack: remove the help module here */
403 vlc_object_detach( p_help_module );
406 /* Will be re-done properly later on */
407 p_vlc->p_libvlc->i_verbose = config_GetInt( p_vlc, "verbose" );
409 /* Check for daemon mode */
411 if( config_GetInt( p_vlc, "daemon" ) )
414 if( daemon( 1, 0) != 0 )
416 msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
420 p_vlc->p_libvlc->b_daemon = VLC_TRUE;
422 /* lets check if we need to write the pidfile */
423 char * psz_pidfile = config_GetPsz( p_vlc, "pidfile" );
425 msg_Dbg( p_vlc, "psz_pidfile is %s", psz_pidfile );
427 if( psz_pidfile != NULL )
430 pid_t i_pid = getpid ();
432 msg_Dbg( p_vlc, "our PID is %d, writing it to %s", i_pid, psz_pidfile );
434 pidfile = utf8_fopen( psz_pidfile,"w" );
435 if( pidfile != NULL )
437 utf8_fprintf( pidfile, "%d", (int)i_pid );
442 msg_Err( p_vlc, "Cannot open pid file for writing: %s, error: %s",
443 psz_pidfile, strerror(errno) );
452 if( ( i_pid = fork() ) < 0 )
454 msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
459 /* This is the parent, exit right now */
460 msg_Dbg( p_vlc, "closing parent process" );
462 i_ret = VLC_EEXITSUCCESS;
466 /* We are the child */
467 msg_Dbg( p_vlc, "daemon spawned" );
468 close( STDIN_FILENO );
469 close( STDOUT_FILENO );
470 close( STDERR_FILENO );
472 p_vlc->p_libvlc->b_daemon = VLC_TRUE;
480 config_Free( p_help_module );
481 vlc_object_destroy( p_help_module );
482 module_EndBank( p_vlc );
483 if( i_object ) vlc_object_release( p_vlc );
487 /* Check for translation config option */
488 #if defined( ENABLE_NLS ) \
489 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
490 # if defined (WIN32) || defined (__APPLE__)
491 /* This ain't really nice to have to reload the config here but it seems
492 * the only way to do it. */
493 config_LoadConfigFile( p_vlc, "main" );
494 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
496 /* Check if the user specified a custom language */
497 psz_language = config_GetPsz( p_vlc, "language" );
498 if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
500 vlc_bool_t b_cache_delete = libvlc.p_module_bank->b_cache_delete;
502 /* Reset the default domain */
503 SetLanguage( psz_language );
505 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
506 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
508 module_EndBank( p_vlc );
509 module_InitBank( p_vlc );
510 config_LoadConfigFile( p_vlc, "main" );
511 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
512 libvlc.p_module_bank->b_cache_delete = b_cache_delete;
514 if( psz_language ) free( psz_language );
519 * Load the builtins and plugins into the module_bank.
520 * We have to do it before config_Load*() because this also gets the
521 * list of configuration options exported by each module and loads their
524 module_LoadBuiltins( p_vlc );
525 module_LoadPlugins( p_vlc );
531 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
532 libvlc.p_module_bank->i_children );
534 /* Hack: insert the help module here */
535 vlc_object_attach( p_help_module, libvlc.p_module_bank );
538 /* Check for help on modules */
539 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
541 Help( p_vlc, p_tmp );
544 i_ret = VLC_EEXITSUCCESS;
546 /* Check for long help option */
547 else if( config_GetInt( p_vlc, "longhelp" ) )
549 Help( p_vlc, "longhelp" );
551 i_ret = VLC_EEXITSUCCESS;
553 /* Check for module list option */
554 else if( config_GetInt( p_vlc, "list" ) )
556 ListModules( p_vlc );
558 i_ret = VLC_EEXITSUCCESS;
561 /* Check for config file options */
562 if( config_GetInt( p_vlc, "reset-config" ) )
564 vlc_object_detach( p_help_module );
565 config_ResetAll( p_vlc );
566 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
567 config_SaveConfigFile( p_vlc, NULL );
568 vlc_object_attach( p_help_module, libvlc.p_module_bank );
570 if( config_GetInt( p_vlc, "save-config" ) )
572 vlc_object_detach( p_help_module );
573 config_LoadConfigFile( p_vlc, NULL );
574 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
575 config_SaveConfigFile( p_vlc, NULL );
576 vlc_object_attach( p_help_module, libvlc.p_module_bank );
579 /* Hack: remove the help module here */
580 vlc_object_detach( p_help_module );
585 config_Free( p_help_module );
586 vlc_object_destroy( p_help_module );
587 module_EndBank( p_vlc );
588 if( i_object ) vlc_object_release( p_vlc );
595 InitDeviceValues( p_vlc );
598 * Override default configuration with config file settings
600 config_LoadConfigFile( p_vlc, NULL );
602 /* Hack: insert the help module here */
603 vlc_object_attach( p_help_module, libvlc.p_module_bank );
607 * Override configuration with command line settings
609 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
612 ShowConsole( VLC_FALSE );
613 /* Pause the console because it's destroyed when we exit */
614 fprintf( stderr, "The command line options couldn't be loaded, check "
615 "that they are valid.\n" );
618 vlc_object_detach( p_help_module );
619 config_Free( p_help_module );
620 vlc_object_destroy( p_help_module );
621 module_EndBank( p_vlc );
622 if( i_object ) vlc_object_release( p_vlc );
626 /* Hack: remove the help module here */
627 vlc_object_detach( p_help_module );
628 config_Free( p_help_module );
629 vlc_object_destroy( p_help_module );
633 * System specific configuration
635 system_Configure( p_vlc, &i_argc, ppsz_argv );
638 * Message queue options
641 var_Create( p_vlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
642 if( config_GetInt( p_vlc, "quiet" ) )
645 var_Set( p_vlc, "verbose", val );
647 var_AddCallback( p_vlc, "verbose", VerboseCallback, NULL );
648 var_Change( p_vlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
650 libvlc.b_color = libvlc.b_color && config_GetInt( p_vlc, "color" );
653 * Output messages that may still be in the queue
657 /* p_vlc initialization. FIXME ? */
659 if( !config_GetInt( p_vlc, "fpu" ) )
660 libvlc.i_cpu &= ~CPU_CAPABILITY_FPU;
662 #if defined( __i386__ ) || defined( __x86_64__ )
663 if( !config_GetInt( p_vlc, "mmx" ) )
664 libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
665 if( !config_GetInt( p_vlc, "3dn" ) )
666 libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
667 if( !config_GetInt( p_vlc, "mmxext" ) )
668 libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
669 if( !config_GetInt( p_vlc, "sse" ) )
670 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
671 if( !config_GetInt( p_vlc, "sse2" ) )
672 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE2;
674 #if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
675 if( !config_GetInt( p_vlc, "altivec" ) )
676 libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
679 #define PRINT_CAPABILITY( capability, string ) \
680 if( libvlc.i_cpu & capability ) \
682 strncat( p_capabilities, string " ", \
683 sizeof(p_capabilities) - strlen(p_capabilities) ); \
684 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
687 p_capabilities[0] = '\0';
688 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
689 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
690 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
691 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
692 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
693 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
694 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
695 PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" );
696 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
697 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
698 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
701 * Choose the best memcpy module
703 p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy", 0 );
705 if( p_vlc->pf_memcpy == NULL )
707 p_vlc->pf_memcpy = memcpy;
710 if( p_vlc->pf_memset == NULL )
712 p_vlc->pf_memset = memset;
715 libvlc.b_stats = config_GetInt( p_vlc, "stats" );
717 libvlc.pp_timers = NULL;
718 vlc_mutex_init( p_vlc, &libvlc.timer_lock );
721 * Initialize hotkey handling
723 var_Create( p_vlc, "key-pressed", VLC_VAR_INTEGER );
724 p_vlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
725 /* Do a copy (we don't need to modify the strings) */
726 memcpy( p_vlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
729 * Initialize playlist and get commandline files
731 p_playlist = playlist_ThreadCreate( p_vlc );
734 msg_Err( p_vlc, "playlist initialization failed" );
735 if( p_vlc->p_memcpy_module != NULL )
737 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
739 module_EndBank( p_vlc );
740 if( i_object ) vlc_object_release( p_vlc );
744 psz_modules = config_GetPsz( p_playlist, "services-discovery" );
745 if( psz_modules && *psz_modules )
747 /* Add service discovery modules */
748 playlist_AddSDModules( p_playlist, psz_modules );
750 if( psz_modules ) free( psz_modules );
753 * Load background interfaces
755 psz_modules = config_GetPsz( p_vlc, "extraintf" );
756 psz_control = config_GetPsz( p_vlc, "control" );
758 if( psz_modules && *psz_modules && psz_control && *psz_control )
760 psz_modules = (char *)realloc( psz_modules, strlen( psz_modules ) +
761 strlen( psz_control ) + 1 );
762 sprintf( psz_modules, "%s:%s", psz_modules, psz_control );
764 else if( psz_control && *psz_control )
766 if( psz_modules ) free( psz_modules );
767 psz_modules = strdup( psz_control );
770 psz_parser = psz_modules;
771 while ( psz_parser && *psz_parser )
773 char *psz_module, *psz_temp;
774 psz_module = psz_parser;
775 psz_parser = strchr( psz_module, ':' );
781 psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
784 sprintf( psz_temp, "%s,none", psz_module );
785 VLC_AddIntf( 0, psz_temp, VLC_FALSE, VLC_FALSE );
795 * Always load the hotkeys interface if it exists
797 VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
800 * If needed, load the Xscreensaver interface
801 * Currently, only for X
803 #ifdef HAVE_X11_XLIB_H
804 if( config_GetInt( p_vlc, "disable-screensaver" ) == 1 )
806 VLC_AddIntf( 0, "screensaver,none", VLC_FALSE, VLC_FALSE );
810 if( config_GetInt( p_vlc, "file-logging" ) == 1 )
812 VLC_AddIntf( 0, "logger,none", VLC_FALSE, VLC_FALSE );
815 if( config_GetInt( p_vlc, "syslog" ) == 1 )
817 char *psz_logmode = "logmode=syslog";
818 AddIntfInternal( 0, "logger,none", VLC_FALSE, VLC_FALSE, 1, &psz_logmode );
822 if( config_GetInt( p_vlc, "show-intf" ) == 1 )
824 VLC_AddIntf( 0, "showintf,none", VLC_FALSE, VLC_FALSE );
827 if( config_GetInt( p_vlc, "network-synchronisation") == 1 )
829 VLC_AddIntf( 0, "netsync,none", VLC_FALSE, VLC_FALSE );
833 * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
835 var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
836 var_Create( p_vlc, "drawableredraw", VLC_VAR_INTEGER );
837 var_Create( p_vlc, "drawablet", VLC_VAR_INTEGER );
838 var_Create( p_vlc, "drawablel", VLC_VAR_INTEGER );
839 var_Create( p_vlc, "drawableb", VLC_VAR_INTEGER );
840 var_Create( p_vlc, "drawabler", VLC_VAR_INTEGER );
841 var_Create( p_vlc, "drawablex", VLC_VAR_INTEGER );
842 var_Create( p_vlc, "drawabley", VLC_VAR_INTEGER );
843 var_Create( p_vlc, "drawablew", VLC_VAR_INTEGER );
844 var_Create( p_vlc, "drawableh", VLC_VAR_INTEGER );
845 var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER );
846 var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER );
848 /* Create volume callback system. */
849 var_Create( p_vlc, "volume-change", VLC_VAR_BOOL );
852 * Get input filenames given as commandline arguments
854 GetFilenames( p_vlc, i_argc, ppsz_argv );
857 * Get --open argument
859 var_Create( p_vlc, "open", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
860 var_Get( p_vlc, "open", &val );
861 if ( val.psz_string != NULL && *val.psz_string )
863 VLC_AddTarget( p_vlc->i_object_id, val.psz_string, NULL, 0,
864 PLAYLIST_INSERT, 0 );
866 if ( val.psz_string != NULL ) free( val.psz_string );
868 if( i_object ) vlc_object_release( p_vlc );
872 /*****************************************************************************
873 * VLC_AddIntf: add an interface
874 *****************************************************************************
875 * This function opens an interface plugin and runs it. If b_block is set
876 * to 0, VLC_AddIntf will return immediately and let the interface run in a
877 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
878 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
879 * the playlist when it is completely initialised.
880 *****************************************************************************/
881 int VLC_AddIntf( int i_object, char const *psz_module,
882 vlc_bool_t b_block, vlc_bool_t b_play )
884 return AddIntfInternal( i_object, psz_module, b_block, b_play, 0, NULL );
888 /*****************************************************************************
889 * VLC_Die: ask vlc to die.
890 *****************************************************************************
891 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
892 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
893 *****************************************************************************/
894 int VLC_Die( int i_object )
896 vlc_t *p_vlc = vlc_current_object( i_object );
903 p_vlc->b_die = VLC_TRUE;
905 if( i_object ) vlc_object_release( p_vlc );
909 /*****************************************************************************
910 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
911 *****************************************************************************/
912 int VLC_CleanUp( int i_object )
914 intf_thread_t * p_intf;
915 playlist_t * p_playlist;
916 vout_thread_t * p_vout;
917 aout_instance_t * p_aout;
918 announce_handler_t * p_announce;
919 vlc_t *p_vlc = vlc_current_object( i_object );
921 /* Check that the handle is valid */
928 * Ask the interfaces to stop and destroy them
930 msg_Dbg( p_vlc, "removing all interfaces" );
931 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
933 intf_StopThread( p_intf );
934 vlc_object_detach( p_intf );
935 vlc_object_release( p_intf );
936 intf_Destroy( p_intf );
942 msg_Dbg( p_vlc, "removing playlist handler" );
943 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
946 vlc_object_detach( p_playlist );
947 vlc_object_release( p_playlist );
948 playlist_ThreadDestroy( p_playlist );
954 msg_Dbg( p_vlc, "removing all video outputs" );
955 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
957 vlc_object_detach( p_vout );
958 vlc_object_release( p_vout );
959 vout_Destroy( p_vout );
965 msg_Dbg( p_vlc, "removing all audio outputs" );
966 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
968 vlc_object_detach( (vlc_object_t *)p_aout );
969 vlc_object_release( (vlc_object_t *)p_aout );
970 aout_Delete( p_aout );
973 stats_TimersDumpAll( p_vlc );
974 stats_TimersClean( p_vlc );
977 * Free announce handler(s?)
979 while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE,
982 msg_Dbg( p_vlc, "removing announce handler" );
983 vlc_object_detach( p_announce );
984 vlc_object_release( p_announce );
985 announce_HandlerDestroy( p_announce );
988 if( i_object ) vlc_object_release( p_vlc );
992 /*****************************************************************************
993 * VLC_Destroy: Destroy everything.
994 *****************************************************************************
995 * This function requests the running threads to finish, waits for their
996 * termination, and destroys their structure.
997 *****************************************************************************/
998 int VLC_Destroy( int i_object )
1000 vlc_t *p_vlc = vlc_current_object( i_object );
1008 * Free allocated memory
1010 if( p_vlc->p_memcpy_module )
1012 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
1013 p_vlc->p_memcpy_module = NULL;
1017 * Free module bank !
1019 module_EndBank( p_vlc );
1021 if( p_vlc->psz_homedir )
1023 free( p_vlc->psz_homedir );
1024 p_vlc->psz_homedir = NULL;
1027 if( p_vlc->psz_userdir )
1029 free( p_vlc->psz_userdir );
1030 p_vlc->psz_userdir = NULL;
1033 if( p_vlc->psz_configfile )
1035 free( p_vlc->psz_configfile );
1036 p_vlc->psz_configfile = NULL;
1039 if( p_vlc->p_hotkeys )
1041 free( p_vlc->p_hotkeys );
1042 p_vlc->p_hotkeys = NULL;
1046 * System specific cleaning code
1048 system_End( p_vlc );
1051 * Free message queue.
1052 * Nobody shall use msg_* afterward.
1055 msg_Destroy( p_libvlc );
1057 /* Destroy global iconv */
1060 /* Destroy mutexes */
1061 vlc_mutex_destroy( &p_vlc->config_lock );
1063 vlc_object_detach( p_vlc );
1065 /* Release object before destroying it */
1066 if( i_object ) vlc_object_release( p_vlc );
1068 vlc_object_destroy( p_vlc );
1070 /* Stop thread system: last one out please shut the door! */
1071 vlc_threads_end( p_libvlc );
1076 /*****************************************************************************
1077 * VLC_VariableSet: set a vlc variable
1078 *****************************************************************************/
1079 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
1081 vlc_t *p_vlc = vlc_current_object( i_object );
1089 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
1090 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
1091 if( !strncmp( psz_var, "conf::", 6 ) )
1093 module_config_t *p_item;
1094 char const *psz_newvar = psz_var + 6;
1096 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
1100 switch( p_item->i_type )
1102 case CONFIG_ITEM_BOOL:
1103 config_PutInt( p_vlc, psz_newvar, value.b_bool );
1105 case CONFIG_ITEM_INTEGER:
1106 config_PutInt( p_vlc, psz_newvar, value.i_int );
1108 case CONFIG_ITEM_FLOAT:
1109 config_PutFloat( p_vlc, psz_newvar, value.f_float );
1112 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
1115 if( i_object ) vlc_object_release( p_vlc );
1120 i_ret = var_Set( p_vlc, psz_var, value );
1122 if( i_object ) vlc_object_release( p_vlc );
1126 /*****************************************************************************
1127 * VLC_VariableGet: get a vlc variable
1128 *****************************************************************************/
1129 int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
1131 vlc_t *p_vlc = vlc_current_object( i_object );
1139 i_ret = var_Get( p_vlc , psz_var, p_value );
1141 if( i_object ) vlc_object_release( p_vlc );
1145 /*****************************************************************************
1146 * VLC_VariableType: get a vlc variable type
1147 *****************************************************************************/
1148 int VLC_VariableType( int i_object, char const *psz_var, int *pi_type )
1151 vlc_t *p_vlc = vlc_current_object( i_object );
1158 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
1159 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
1160 if( !strncmp( psz_var, "conf::", 6 ) )
1162 module_config_t *p_item;
1163 char const *psz_newvar = psz_var + 6;
1165 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
1169 switch( p_item->i_type )
1171 case CONFIG_ITEM_BOOL:
1172 i_type = VLC_VAR_BOOL;
1174 case CONFIG_ITEM_INTEGER:
1175 i_type = VLC_VAR_INTEGER;
1177 case CONFIG_ITEM_FLOAT:
1178 i_type = VLC_VAR_FLOAT;
1181 i_type = VLC_VAR_STRING;
1189 i_type = VLC_VAR_TYPE & var_Type( p_vlc , psz_var );
1191 if( i_object ) vlc_object_release( p_vlc );
1201 /*****************************************************************************
1202 * VLC_AddTarget: adds a target for playing.
1203 *****************************************************************************
1204 * This function adds psz_target to the current playlist. If a playlist does
1205 * not exist, it will create one.
1206 *****************************************************************************/
1207 int VLC_AddTarget( int i_object, char const *psz_target,
1208 char const **ppsz_options, int i_options,
1209 int i_mode, int i_pos )
1212 playlist_t *p_playlist;
1213 vlc_t *p_vlc = vlc_current_object( i_object );
1220 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1222 if( p_playlist == NULL )
1224 msg_Dbg( p_vlc, "no playlist present, creating one" );
1225 p_playlist = playlist_ThreadCreate( p_vlc );
1227 if( p_playlist == NULL )
1229 if( i_object ) vlc_object_release( p_vlc );
1230 return VLC_EGENERIC;
1233 vlc_object_yield( p_playlist );
1236 i_err = playlist_PlaylistAddExt( p_playlist, psz_target, psz_target,
1237 i_mode, i_pos, -1, ppsz_options, i_options);
1239 vlc_object_release( p_playlist );
1241 if( i_object ) vlc_object_release( p_vlc );
1245 /*****************************************************************************
1246 * VLC_Play: play the playlist
1247 *****************************************************************************/
1248 int VLC_Play( int i_object )
1250 playlist_t * p_playlist;
1251 vlc_t *p_vlc = vlc_current_object( i_object );
1253 /* Check that the handle is valid */
1259 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1263 if( i_object ) vlc_object_release( p_vlc );
1267 playlist_Play( p_playlist );
1268 vlc_object_release( p_playlist );
1270 if( i_object ) vlc_object_release( p_vlc );
1274 /*****************************************************************************
1275 * VLC_Pause: toggle pause
1276 *****************************************************************************/
1277 int VLC_Pause( int i_object )
1279 playlist_t * p_playlist;
1280 vlc_t *p_vlc = vlc_current_object( i_object );
1282 /* Check that the handle is valid */
1288 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1292 if( i_object ) vlc_object_release( p_vlc );
1296 playlist_Pause( p_playlist );
1297 vlc_object_release( p_playlist );
1299 if( i_object ) vlc_object_release( p_vlc );
1303 /*****************************************************************************
1304 * VLC_Stop: stop playback
1305 *****************************************************************************/
1306 int VLC_Stop( int i_object )
1308 playlist_t * p_playlist;
1309 vlc_t *p_vlc = vlc_current_object( i_object );
1311 /* Check that the handle is valid */
1317 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1321 if( i_object ) vlc_object_release( p_vlc );
1325 playlist_Stop( p_playlist );
1326 vlc_object_release( p_playlist );
1328 if( i_object ) vlc_object_release( p_vlc );
1332 /*****************************************************************************
1333 * VLC_IsPlaying: Query for Playlist Status
1334 *****************************************************************************/
1335 vlc_bool_t VLC_IsPlaying( int i_object )
1337 playlist_t * p_playlist;
1338 vlc_bool_t b_playing;
1340 vlc_t *p_vlc = vlc_current_object( i_object );
1342 /* Check that the handle is valid */
1348 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1352 if( i_object ) vlc_object_release( p_vlc );
1356 if( p_playlist->p_input )
1359 var_Get( p_playlist->p_input, "state", &val );
1360 b_playing = ( val.i_int == PLAYING_S );
1364 b_playing = playlist_IsPlaying( p_playlist );
1366 vlc_object_release( p_playlist );
1368 if( i_object ) vlc_object_release( p_vlc );
1373 * Get the current position in a input
1375 * Return the current position as a float
1376 * \note For some inputs, this will be unknown.
1378 * \param i_object a vlc object id
1379 * \return a float in the range of 0.0 - 1.0
1381 float VLC_PositionGet( int i_object )
1383 input_thread_t *p_input;
1385 vlc_t *p_vlc = vlc_current_object( i_object );
1387 /* Check that the handle is valid */
1393 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1397 if( i_object ) vlc_object_release( p_vlc );
1401 var_Get( p_input, "position", &val );
1402 vlc_object_release( p_input );
1404 if( i_object ) vlc_object_release( p_vlc );
1409 * Set the current position in a input
1411 * Set the current position in a input and then return
1412 * the current position as a float.
1413 * \note For some inputs, this will be unknown.
1415 * \param i_object a vlc object id
1416 * \param i_position a float in the range of 0.0 - 1.0
1417 * \return a float in the range of 0.0 - 1.0
1419 float VLC_PositionSet( int i_object, float i_position )
1421 input_thread_t *p_input;
1423 vlc_t *p_vlc = vlc_current_object( i_object );
1425 /* Check that the handle is valid */
1431 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1435 if( i_object ) vlc_object_release( p_vlc );
1439 val.f_float = i_position;
1440 var_Set( p_input, "position", val );
1441 var_Get( p_input, "position", &val );
1442 vlc_object_release( p_input );
1444 if( i_object ) vlc_object_release( p_vlc );
1449 * Get the current position in a input
1451 * Return the current position in seconds from the start.
1452 * \note For some inputs, this will be unknown.
1454 * \param i_object a vlc object id
1455 * \return the offset from 0:00 in seconds
1457 int VLC_TimeGet( int i_object )
1459 input_thread_t *p_input;
1461 vlc_t *p_vlc = vlc_current_object( i_object );
1463 /* Check that the handle is valid */
1469 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1473 if( i_object ) vlc_object_release( p_vlc );
1477 var_Get( p_input, "time", &val );
1478 vlc_object_release( p_input );
1480 if( i_object ) vlc_object_release( p_vlc );
1481 return val.i_time / 1000000;
1485 * Seek to a position in the current input
1487 * Seek i_seconds in the current input. If b_relative is set,
1488 * then the seek will be relative to the current position, otherwise
1489 * it will seek to i_seconds from the beginning of the input.
1490 * \note For some inputs, this will be unknown.
1492 * \param i_object a vlc object id
1493 * \param i_seconds seconds from current position or from beginning of input
1494 * \param b_relative seek relative from current position
1495 * \return VLC_SUCCESS on success
1497 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
1499 input_thread_t *p_input;
1501 vlc_t *p_vlc = vlc_current_object( i_object );
1503 /* Check that the handle is valid */
1509 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1513 if( i_object ) vlc_object_release( p_vlc );
1519 val.i_time = i_seconds;
1520 val.i_time = val.i_time * 1000000L;
1521 var_Set( p_input, "time-offset", val );
1525 val.i_time = i_seconds;
1526 val.i_time = val.i_time * 1000000L;
1527 var_Set( p_input, "time", val );
1529 vlc_object_release( p_input );
1531 if( i_object ) vlc_object_release( p_vlc );
1536 * Get the total length of a input
1538 * Return the total length in seconds from the current input.
1539 * \note For some inputs, this will be unknown.
1541 * \param i_object a vlc object id
1542 * \return the length in seconds
1544 int VLC_LengthGet( int i_object )
1546 input_thread_t *p_input;
1548 vlc_t *p_vlc = vlc_current_object( i_object );
1550 /* Check that the handle is valid */
1556 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1560 if( i_object ) vlc_object_release( p_vlc );
1564 var_Get( p_input, "length", &val );
1565 vlc_object_release( p_input );
1567 if( i_object ) vlc_object_release( p_vlc );
1568 return val.i_time / 1000000L;
1572 * Play the input faster than realtime
1574 * 2x, 4x, 8x faster than realtime
1575 * \note For some inputs, this will be impossible.
1577 * \param i_object a vlc object id
1578 * \return the current speedrate
1580 float VLC_SpeedFaster( int i_object )
1582 input_thread_t *p_input;
1584 vlc_t *p_vlc = vlc_current_object( i_object );
1586 /* Check that the handle is valid */
1592 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1596 if( i_object ) vlc_object_release( p_vlc );
1600 val.b_bool = VLC_TRUE;
1601 var_Set( p_input, "rate-faster", val );
1602 var_Get( p_input, "rate", &val );
1603 vlc_object_release( p_input );
1605 if( i_object ) vlc_object_release( p_vlc );
1606 return val.f_float / INPUT_RATE_DEFAULT;
1610 * Play the input slower than realtime
1612 * 1/2x, 1/4x, 1/8x slower than realtime
1613 * \note For some inputs, this will be impossible.
1615 * \param i_object a vlc object id
1616 * \return the current speedrate
1618 float VLC_SpeedSlower( int i_object )
1620 input_thread_t *p_input;
1622 vlc_t *p_vlc = vlc_current_object( i_object );
1624 /* Check that the handle is valid */
1630 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1634 if( i_object ) vlc_object_release( p_vlc );
1638 val.b_bool = VLC_TRUE;
1639 var_Set( p_input, "rate-slower", val );
1640 var_Get( p_input, "rate", &val );
1641 vlc_object_release( p_input );
1643 if( i_object ) vlc_object_release( p_vlc );
1644 return val.f_float / INPUT_RATE_DEFAULT;
1648 * Return the current playlist item
1650 * Returns the index of the playlistitem that is currently selected for play.
1651 * This is valid even if nothing is currently playing.
1653 * \param i_object a vlc object id
1654 * \return the current index
1656 int VLC_PlaylistIndex( int i_object )
1658 printf( "This function is deprecated and should not be used anymore" );
1663 * Total amount of items in the playlist
1665 * \param i_object a vlc object id
1666 * \return amount of playlist items
1668 int VLC_PlaylistNumberOfItems( int i_object )
1671 playlist_t * p_playlist;
1672 vlc_t *p_vlc = vlc_current_object( i_object );
1674 /* Check that the handle is valid */
1680 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1684 if( i_object ) vlc_object_release( p_vlc );
1688 i_size = p_playlist->i_size;
1689 vlc_object_release( p_playlist );
1691 if( i_object ) vlc_object_release( p_vlc );
1696 * Next playlist item
1698 * Skip to the next playlistitem and play it.
1700 * \param i_object a vlc object id
1701 * \return VLC_SUCCESS on success
1703 int VLC_PlaylistNext( int i_object )
1705 playlist_t * p_playlist;
1706 vlc_t *p_vlc = vlc_current_object( i_object );
1708 /* Check that the handle is valid */
1714 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1718 if( i_object ) vlc_object_release( p_vlc );
1722 playlist_Next( p_playlist );
1723 vlc_object_release( p_playlist );
1725 if( i_object ) vlc_object_release( p_vlc );
1730 * Previous playlist item
1732 * Skip to the previous playlistitem and play it.
1734 * \param i_object a vlc object id
1735 * \return VLC_SUCCESS on success
1737 int VLC_PlaylistPrev( int i_object )
1739 playlist_t * p_playlist;
1740 vlc_t *p_vlc = vlc_current_object( i_object );
1742 /* Check that the handle is valid */
1748 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1752 if( i_object ) vlc_object_release( p_vlc );
1756 playlist_Prev( p_playlist );
1757 vlc_object_release( p_playlist );
1759 if( i_object ) vlc_object_release( p_vlc );
1764 /*****************************************************************************
1765 * VLC_PlaylistClear: Empty the playlist
1766 *****************************************************************************/
1767 int VLC_PlaylistClear( int i_object )
1769 playlist_t * p_playlist;
1770 vlc_t *p_vlc = vlc_current_object( i_object );
1772 /* Check that the handle is valid */
1778 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1782 if( i_object ) vlc_object_release( p_vlc );
1786 playlist_Clear( p_playlist );
1788 vlc_object_release( p_playlist );
1790 if( i_object ) vlc_object_release( p_vlc );
1797 * \param i_object a vlc object id
1798 * \param i_volume something in a range from 0-200
1799 * \return the new volume (range 0-200 %)
1801 int VLC_VolumeSet( int i_object, int i_volume )
1803 audio_volume_t i_vol = 0;
1804 vlc_t *p_vlc = vlc_current_object( i_object );
1806 /* Check that the handle is valid */
1812 if( i_volume >= 0 && i_volume <= 200 )
1814 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
1815 aout_VolumeSet( p_vlc, i_vol );
1818 if( i_object ) vlc_object_release( p_vlc );
1819 return i_vol * 200 / AOUT_VOLUME_MAX;
1823 * Get the current volume
1825 * Retrieve the current volume.
1827 * \param i_object a vlc object id
1828 * \return the current volume (range 0-200 %)
1830 int VLC_VolumeGet( int i_object )
1832 audio_volume_t i_volume;
1833 vlc_t *p_vlc = vlc_current_object( i_object );
1835 /* Check that the handle is valid */
1841 aout_VolumeGet( p_vlc, &i_volume );
1843 if( i_object ) vlc_object_release( p_vlc );
1844 return i_volume*200/AOUT_VOLUME_MAX;
1848 * Mute/Unmute the volume
1850 * \param i_object a vlc object id
1851 * \return VLC_SUCCESS on success
1853 int VLC_VolumeMute( int i_object )
1855 vlc_t *p_vlc = vlc_current_object( i_object );
1857 /* Check that the handle is valid */
1863 aout_VolumeMute( p_vlc, NULL );
1865 if( i_object ) vlc_object_release( p_vlc );
1869 /*****************************************************************************
1870 * VLC_FullScreen: toggle fullscreen mode
1871 *****************************************************************************/
1872 int VLC_FullScreen( int i_object )
1874 vout_thread_t *p_vout;
1875 vlc_t *p_vlc = vlc_current_object( i_object );
1882 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
1886 if( i_object ) vlc_object_release( p_vlc );
1890 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1891 vlc_object_release( p_vout );
1893 if( i_object ) vlc_object_release( p_vlc );
1897 /* following functions are local */
1900 static int AddIntfInternal( int i_object, char const *psz_module,
1901 vlc_bool_t b_block, vlc_bool_t b_play,
1902 int i_options, char **ppsz_options )
1905 intf_thread_t *p_intf;
1906 vlc_t *p_vlc = vlc_current_object( i_object );
1914 if( p_vlc->p_libvlc->b_daemon && b_block && !psz_module )
1916 /* Daemon mode hack.
1917 * We prefer the dummy interface if none is specified. */
1918 char *psz_interface = config_GetPsz( p_vlc, "intf" );
1919 if( !psz_interface || !*psz_interface ) psz_module = "dummy";
1920 if( psz_interface ) free( psz_interface );
1924 /* Try to create the interface */
1925 p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf",
1926 i_options, ppsz_options );
1928 if( p_intf == NULL )
1930 msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
1931 if( i_object ) vlc_object_release( p_vlc );
1932 return VLC_EGENERIC;
1935 /* Interface doesn't handle play on start so do it ourselves */
1936 if( !p_intf->b_play && b_play ) VLC_Play( i_object );
1938 /* Try to run the interface */
1939 p_intf->b_play = b_play;
1940 p_intf->b_block = b_block;
1941 i_err = intf_RunThread( p_intf );
1944 vlc_object_detach( p_intf );
1945 intf_Destroy( p_intf );
1946 if( i_object ) vlc_object_release( p_vlc );
1950 if( i_object ) vlc_object_release( p_vlc );
1955 /*****************************************************************************
1956 * SetLanguage: set the interface language.
1957 *****************************************************************************
1958 * We set the LC_MESSAGES locale category for interface messages and buttons,
1959 * as well as the LC_CTYPE category for string sorting and possible wide
1960 * character support.
1961 *****************************************************************************/
1962 static void SetLanguage ( char const *psz_lang )
1964 #if defined( ENABLE_NLS ) \
1965 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
1968 #if defined( __APPLE__ ) || defined ( WIN32 ) || defined( SYS_BEOS )
1972 if( psz_lang && !*psz_lang )
1974 # if defined( HAVE_LC_MESSAGES )
1975 setlocale( LC_MESSAGES, psz_lang );
1977 setlocale( LC_CTYPE, psz_lang );
1982 /* I need that under Darwin, please check it doesn't disturb
1983 * other platforms. --Meuuh */
1984 setenv( "LANG", psz_lang, 1 );
1986 #elif defined( SYS_BEOS ) || defined( WIN32 )
1987 /* We set LC_ALL manually because it is the only way to set
1988 * the language at runtime under eg. Windows. Beware that this
1989 * makes the environment unconsistent when libvlc is unloaded and
1990 * should probably be moved to a safer place like vlc.c. */
1991 static char psz_lcall[20];
1992 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
1993 psz_lcall[19] = '\0';
1994 putenv( psz_lcall );
1997 setlocale( LC_ALL, psz_lang );
2000 /* Specify where to find the locales for current domain */
2001 #if !defined( __APPLE__ ) && !defined( WIN32 ) && !defined( SYS_BEOS )
2002 psz_path = LOCALEDIR;
2004 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
2008 if( !bindtextdomain( PACKAGE_NAME, psz_path ) )
2010 fprintf( stderr, "warning: couldn't bind domain %s in directory %s\n",
2011 PACKAGE_NAME, psz_path );
2014 /* Set the default domain */
2015 bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
2019 /*****************************************************************************
2020 * GetFilenames: parse command line options which are not flags
2021 *****************************************************************************
2022 * Parse command line for input files as well as their associated options.
2023 * An option always follows its associated input and begins with a ":".
2024 *****************************************************************************/
2025 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
2027 int i_opt, i_options;
2029 /* We assume that the remaining parameters are filenames
2030 * and their input options */
2031 for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
2033 const char *psz_target;
2036 /* Count the input options */
2037 while( *ppsz_argv[ i_opt ] == ':' && i_opt > optind )
2043 /* TODO: write an internal function of this one, to avoid
2044 * unnecessary lookups. */
2045 /* FIXME: should we convert options to UTF-8 as well ?? */
2046 psz_target = FromLocale( ppsz_argv[ i_opt ] );
2047 VLC_AddTarget( p_vlc->i_object_id, psz_target,
2048 (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
2050 PLAYLIST_INSERT, 0 );
2051 LocaleFree( psz_target );
2057 /*****************************************************************************
2058 * Help: print program help
2059 *****************************************************************************
2060 * Print a short inline help. Message interface is initialized at this stage.
2061 *****************************************************************************/
2062 static void Help( vlc_t *p_this, char const *psz_help_name )
2065 ShowConsole( VLC_TRUE );
2068 if( psz_help_name && !strcmp( psz_help_name, "help" ) )
2070 utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
2071 Usage( p_this, "help" );
2072 Usage( p_this, "main" );
2074 else if( psz_help_name && !strcmp( psz_help_name, "longhelp" ) )
2076 utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
2077 Usage( p_this, NULL );
2079 else if( psz_help_name )
2081 Usage( p_this, psz_help_name );
2084 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2089 /*****************************************************************************
2090 * Usage: print module usage
2091 *****************************************************************************
2092 * Print a short inline help. Message interface is initialized at this stage.
2093 *****************************************************************************/
2094 static void Usage( vlc_t *p_this, char const *psz_module_name )
2096 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
2097 /* short option ------' | | | | | | |
2098 * option name ------------' | | | | | |
2099 * <bra -------------------------' | | | | |
2100 * option type or "" --------------' | | | |
2101 * ket> -----------------------------' | | |
2102 * padding spaces ---------------------' | |
2103 * comment -------------------------------' |
2104 * comment suffix --------------------------'
2106 * The purpose of having bra and ket is that we might i18n them as well.
2108 #define LINE_START 8
2109 #define PADDING_SPACES 25
2112 module_config_t *p_item;
2113 char psz_spaces_text[PADDING_SPACES+LINE_START+1];
2114 char psz_spaces_longtext[LINE_START+3];
2115 char psz_format[sizeof(FORMAT_STRING)];
2116 char psz_buffer[10000];
2119 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
2120 vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" );
2121 vlc_bool_t b_description;
2123 memset( psz_spaces_text, ' ', PADDING_SPACES+LINE_START );
2124 psz_spaces_text[PADDING_SPACES+LINE_START] = '\0';
2125 memset( psz_spaces_longtext, ' ', LINE_START+2 );
2126 psz_spaces_longtext[LINE_START+2] = '\0';
2128 strcpy( psz_format, FORMAT_STRING );
2130 /* List all modules */
2131 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2133 /* Enumerate the config for each module */
2134 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2136 vlc_bool_t b_help_module;
2138 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2140 if( psz_module_name && strcmp( psz_module_name,
2141 p_parser->psz_object_name ) )
2146 /* Ignore modules without config options */
2147 if( !p_parser->i_config_items )
2152 /* Ignore modules with only advanced config options if requested */
2155 for( p_item = p_parser->p_config;
2156 p_item->i_type != CONFIG_HINT_END;
2159 if( (p_item->i_type & CONFIG_ITEM) &&
2160 !p_item->b_advanced ) break;
2162 if( p_item->i_type == CONFIG_HINT_END ) continue;
2165 /* Print name of module */
2166 if( strcmp( "main", p_parser->psz_object_name ) )
2167 utf8_fprintf( stdout, "\n %s\n", p_parser->psz_longname );
2169 b_help_module = !strcmp( "help", p_parser->psz_object_name );
2171 /* Print module options */
2172 for( p_item = p_parser->p_config;
2173 p_item->i_type != CONFIG_HINT_END;
2176 char *psz_text, *psz_spaces = psz_spaces_text;
2177 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
2178 char *psz_suf = "", *psz_prefix = NULL;
2181 /* Skip deprecated options */
2182 if( p_item->psz_current )
2186 /* Skip advanced options if requested */
2187 if( p_item->b_advanced && !b_advanced )
2192 switch( p_item->i_type )
2194 case CONFIG_HINT_CATEGORY:
2195 case CONFIG_HINT_USAGE:
2196 if( !strcmp( "main", p_parser->psz_object_name ) )
2197 utf8_fprintf( stdout, "\n %s\n", p_item->psz_text );
2200 case CONFIG_ITEM_STRING:
2201 case CONFIG_ITEM_FILE:
2202 case CONFIG_ITEM_DIRECTORY:
2203 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
2204 case CONFIG_ITEM_MODULE_CAT:
2205 case CONFIG_ITEM_MODULE_LIST:
2206 case CONFIG_ITEM_MODULE_LIST_CAT:
2207 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
2209 if( p_item->ppsz_list )
2212 psz_type = psz_buffer;
2214 for( i = 0; p_item->ppsz_list[i]; i++ )
2216 if( i ) strcat( psz_type, "," );
2217 strcat( psz_type, p_item->ppsz_list[i] );
2222 case CONFIG_ITEM_INTEGER:
2223 case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
2224 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
2226 if( p_item->i_list )
2229 psz_type = psz_buffer;
2231 for( i = 0; p_item->ppsz_list_text[i]; i++ )
2233 if( i ) strcat( psz_type, ", " );
2234 sprintf( psz_type + strlen(psz_type), "%i (%s)",
2236 p_item->ppsz_list_text[i] );
2241 case CONFIG_ITEM_FLOAT:
2242 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
2244 case CONFIG_ITEM_BOOL:
2245 psz_bra = ""; psz_type = ""; psz_ket = "";
2246 if( !b_help_module )
2248 psz_suf = p_item->i_value ? _(" (default enabled)") :
2249 _(" (default disabled)");
2259 /* Add short option if any */
2260 if( p_item->i_short )
2262 sprintf( psz_short, "-%c,", p_item->i_short );
2266 strcpy( psz_short, " " );
2269 i = PADDING_SPACES - strlen( p_item->psz_name )
2270 - strlen( psz_bra ) - strlen( psz_type )
2271 - strlen( psz_ket ) - 1;
2273 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
2275 psz_prefix = ", --no-";
2276 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
2281 psz_spaces[0] = '\n';
2286 psz_spaces[i] = '\0';
2289 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
2291 utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2292 psz_prefix, p_item->psz_name, psz_bra, psz_type,
2293 psz_ket, psz_spaces );
2297 utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2298 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
2301 psz_spaces[i] = ' ';
2303 /* We wrap the rest of the output */
2304 sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
2305 b_description = config_GetInt( p_this, "help-verbose" );
2308 psz_text = psz_buffer;
2311 char *psz_parser, *psz_word;
2312 size_t i_end = strlen( psz_text );
2314 /* If the remaining text fits in a line, print it. */
2315 if( i_end <= (size_t)i_width )
2317 utf8_fprintf( stdout, "%s\n", psz_text );
2321 /* Otherwise, eat as many words as possible */
2322 psz_parser = psz_text;
2325 psz_word = psz_parser;
2326 psz_parser = strchr( psz_word, ' ' );
2327 /* If no space was found, we reached the end of the text
2328 * block; otherwise, we skip the space we just found. */
2329 psz_parser = psz_parser ? psz_parser + 1
2332 } while( psz_parser - psz_text <= i_width );
2334 /* We cut a word in one of these cases:
2335 * - it's the only word in the line and it's too long.
2336 * - we used less than 80% of the width and the word we are
2337 * going to wrap is longer than 40% of the width, and even
2338 * if the word would have fit in the next line. */
2339 if( psz_word == psz_text
2340 || ( psz_word - psz_text < 80 * i_width / 100
2341 && psz_parser - psz_word > 40 * i_width / 100 ) )
2343 char c = psz_text[i_width];
2344 psz_text[i_width] = '\0';
2345 utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2346 psz_text += i_width;
2351 psz_word[-1] = '\0';
2352 utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2353 psz_text = psz_word;
2357 if( b_description && p_item->psz_longtext )
2359 sprintf( psz_buffer, "%s%s", p_item->psz_longtext, psz_suf );
2360 b_description = VLC_FALSE;
2361 psz_spaces = psz_spaces_longtext;
2362 utf8_fprintf( stdout, "%s", psz_spaces );
2368 /* Release the module list */
2369 vlc_list_release( p_list );
2372 /*****************************************************************************
2373 * ListModules: list the available modules with their description
2374 *****************************************************************************
2375 * Print a list of all available modules (builtins and plugins) and a short
2376 * description for each one.
2377 *****************************************************************************/
2378 static void ListModules( vlc_t *p_this )
2382 char psz_spaces[22];
2385 memset( psz_spaces, ' ', 22 );
2388 ShowConsole( VLC_TRUE );
2391 /* List all modules */
2392 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2394 /* Enumerate each module */
2395 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2399 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2401 /* Nasty hack, but right now I'm too tired to think about a nice
2403 i = 22 - strlen( p_parser->psz_object_name ) - 1;
2407 utf8_fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
2408 psz_spaces, p_parser->psz_longname );
2410 psz_spaces[i] = ' ';
2413 vlc_list_release( p_list );
2415 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2420 /*****************************************************************************
2421 * Version: print complete program version
2422 *****************************************************************************
2423 * Print complete program version and build number.
2424 *****************************************************************************/
2425 static void Version( void )
2428 ShowConsole( VLC_TRUE );
2431 utf8_fprintf( stdout, _("VLC version %s\n"), VLC_Version() );
2432 utf8_fprintf( stdout, _("Compiled by %s@%s.%s\n"),
2433 VLC_CompileBy(), VLC_CompileHost(), VLC_CompileDomain() );
2434 utf8_fprintf( stdout, _("Compiler: %s\n"), VLC_Compiler() );
2435 #ifndef HAVE_SHARED_LIBVLC
2436 if( strcmp( VLC_Changeset(), "exported" ) )
2437 utf8_fprintf( stdout, _("Based upon svn changeset [%s]\n"),
2440 utf8_fprintf( stdout, LICENSE_MSG );
2442 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2447 /*****************************************************************************
2448 * ShowConsole: On Win32, create an output console for debug messages
2449 *****************************************************************************
2450 * This function is useful only on Win32.
2451 *****************************************************************************/
2453 static void ShowConsole( vlc_bool_t b_dofile )
2458 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2462 freopen( "CONOUT$", "w", stderr );
2463 freopen( "CONIN$", "r", stdin );
2465 if( b_dofile && (f_help = fopen( "vlc-help.txt", "wt" )) )
2468 freopen( "vlc-help.txt", "wt", stdout );
2469 utf8_fprintf( stderr, _("\nDumped content to vlc-help.txt file.\n") );
2472 else freopen( "CONOUT$", "w", stdout );
2478 /*****************************************************************************
2479 * PauseConsole: On Win32, wait for a key press before closing the console
2480 *****************************************************************************
2481 * This function is useful only on Win32.
2482 *****************************************************************************/
2484 static void PauseConsole( void )
2488 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2490 utf8_fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
2498 /*****************************************************************************
2499 * ConsoleWidth: Return the console width in characters
2500 *****************************************************************************
2501 * We use the stty shell command to get the console width; if this fails or
2502 * if the width is less than 80, we default to 80.
2503 *****************************************************************************/
2504 static int ConsoleWidth( void )
2509 char buf[20], *psz_parser;
2513 file = popen( "stty size 2>/dev/null", "r" );
2516 i_ret = fread( buf, 1, 20, file );
2520 psz_parser = strchr( buf, ' ' );
2523 i_ret = atoi( psz_parser + 1 );
2538 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
2539 vlc_value_t old_val, vlc_value_t new_val, void *param)
2541 vlc_t *p_vlc = (vlc_t *)p_this;
2543 if( new_val.i_int >= -1 )
2545 p_vlc->p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );
2550 /*****************************************************************************
2551 * InitDeviceValues: initialize device values
2552 *****************************************************************************
2553 * This function inits the dvd, vcd and cd-audio values
2554 *****************************************************************************/
2555 static void InitDeviceValues( vlc_t *p_vlc )
2558 LibHalContext * ctx;
2563 DBusConnection *p_connection;
2567 ctx = libhal_ctx_new();
2569 dbus_error_init( &error );
2570 p_connection = dbus_bus_get ( DBUS_BUS_SYSTEM, &error );
2571 if( dbus_error_is_set( &error ) )
2573 dbus_error_free( &error );
2576 libhal_ctx_set_dbus_connection( ctx, p_connection );
2577 if( libhal_ctx_init( ctx, &error ) )
2579 if( ( ctx = hal_initialize( NULL, FALSE ) ) )
2583 if( ( devices = libhal_get_all_devices( ctx, &i_devices, NULL ) ) )
2585 if( ( devices = hal_get_all_devices( ctx, &i_devices ) ) )
2588 for( i = 0; i < i_devices; i++ )
2591 if( !libhal_device_property_exists( ctx, devices[i],
2592 "storage.cdrom.dvd", NULL ) )
2594 if( !hal_device_property_exists( ctx, devices[ i ],
2595 "storage.cdrom.dvd" ) )
2601 b_dvd = libhal_device_get_property_bool( ctx, devices[ i ],
2602 "storage.cdrom.dvd", NULL );
2603 block_dev = libhal_device_get_property_string( ctx,
2604 devices[ i ], "block.device" , NULL );
2606 b_dvd = hal_device_get_property_bool( ctx, devices[ i ],
2607 "storage.cdrom.dvd" );
2608 block_dev = hal_device_get_property_string( ctx, devices[ i ],
2613 config_PutPsz( p_vlc, "dvd", block_dev );
2616 config_PutPsz( p_vlc, "vcd", block_dev );
2617 config_PutPsz( p_vlc, "cd-audio", block_dev );
2619 libhal_free_string( block_dev );
2621 hal_free_string( block_dev );
2625 libhal_free_string_array( devices );
2627 hal_free_string_array( devices );
2632 libhal_ctx_shutdown( ctx, NULL );
2634 hal_shutdown( ctx );
2639 msg_Warn( p_vlc, "Unable to get HAL device properties" );