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 ) )
298 * System specific initialization code
300 system_Init( p_vlc, &i_argc, ppsz_argv );
302 /* Get the executable name (similar to the basename command) */
305 p_vlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
308 if( *p_tmp == '/' ) p_vlc->psz_object_name = ++p_tmp;
314 p_vlc->psz_object_name = "vlc";
318 * Support for gettext
323 * Global iconv, must be done after setlocale()
324 * so that vlc_current_charset() works.
326 LocaleInit( (vlc_object_t *)p_vlc );
328 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
329 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
331 /* Initialize the module bank and load the configuration of the
332 * main module. We need to do this at this stage to be able to display
333 * a short help if required by the user. (short help == main module
335 module_InitBank( p_vlc );
337 /* Hack: insert the help module here */
338 p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
339 if( p_help_module == NULL )
341 module_EndBank( p_vlc );
342 if( i_object ) vlc_object_release( p_vlc );
345 p_help_module->psz_object_name = "help";
346 p_help_module->psz_longname = N_("Help options");
347 config_Duplicate( p_help_module, p_help_config );
348 vlc_object_attach( p_help_module, libvlc.p_module_bank );
351 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE ) )
353 vlc_object_detach( p_help_module );
354 config_Free( p_help_module );
355 vlc_object_destroy( p_help_module );
356 module_EndBank( p_vlc );
357 if( i_object ) vlc_object_release( p_vlc );
361 /* Check for short help option */
362 if( config_GetInt( p_vlc, "help" ) )
364 Help( p_vlc, "help" );
366 i_ret = VLC_EEXITSUCCESS;
368 /* Check for version option */
369 else if( config_GetInt( p_vlc, "version" ) )
373 i_ret = VLC_EEXITSUCCESS;
376 /* Set the config file stuff */
377 p_vlc->psz_homedir = config_GetHomeDir();
378 p_vlc->psz_userdir = config_GetUserDir();
379 if( p_vlc->psz_userdir == NULL )
380 p_vlc->psz_userdir = strdup(p_vlc->psz_homedir);
381 p_vlc->psz_configfile = config_GetPsz( p_vlc, "config" );
382 if( p_vlc->psz_configfile != NULL && p_vlc->psz_configfile[0] == '~'
383 && p_vlc->psz_configfile[1] == '/' )
385 char *psz = malloc( strlen(p_vlc->psz_userdir)
386 + strlen(p_vlc->psz_configfile) );
387 /* This is incomplete : we should also support the ~cmassiot/ syntax. */
388 sprintf( psz, "%s/%s", p_vlc->psz_userdir,
389 p_vlc->psz_configfile + 2 );
390 free( p_vlc->psz_configfile );
391 p_vlc->psz_configfile = psz;
394 /* Check for plugins cache options */
395 if( config_GetInt( p_vlc, "reset-plugins-cache" ) )
397 libvlc.p_module_bank->b_cache_delete = VLC_TRUE;
400 /* Hack: remove the help module here */
401 vlc_object_detach( p_help_module );
404 /* Will be re-done properly later on */
405 p_vlc->p_libvlc->i_verbose = config_GetInt( p_vlc, "verbose" );
407 /* Check for daemon mode */
409 if( config_GetInt( p_vlc, "daemon" ) )
412 if( daemon( 1, 0) != 0 )
414 msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
418 p_vlc->p_libvlc->b_daemon = VLC_TRUE;
423 if( ( i_pid = fork() ) < 0 )
425 msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
430 /* This is the parent, exit right now */
431 msg_Dbg( p_vlc, "closing parent process" );
433 i_ret = VLC_EEXITSUCCESS;
437 /* We are the child */
438 msg_Dbg( p_vlc, "daemon spawned" );
439 close( STDIN_FILENO );
440 close( STDOUT_FILENO );
441 close( STDERR_FILENO );
443 p_vlc->p_libvlc->b_daemon = VLC_TRUE;
451 config_Free( p_help_module );
452 vlc_object_destroy( p_help_module );
453 module_EndBank( p_vlc );
454 if( i_object ) vlc_object_release( p_vlc );
458 /* Check for translation config option */
459 #if defined( ENABLE_NLS ) \
460 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
461 # if defined (WIN32) || defined (__APPLE__)
462 /* This ain't really nice to have to reload the config here but it seems
463 * the only way to do it. */
464 config_LoadConfigFile( p_vlc, "main" );
465 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
467 /* Check if the user specified a custom language */
468 psz_language = config_GetPsz( p_vlc, "language" );
469 if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
471 vlc_bool_t b_cache_delete = libvlc.p_module_bank->b_cache_delete;
473 /* Reset the default domain */
474 SetLanguage( psz_language );
476 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
477 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
479 module_EndBank( p_vlc );
480 module_InitBank( p_vlc );
481 config_LoadConfigFile( p_vlc, "main" );
482 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
483 libvlc.p_module_bank->b_cache_delete = b_cache_delete;
485 if( psz_language ) free( psz_language );
490 * Load the builtins and plugins into the module_bank.
491 * We have to do it before config_Load*() because this also gets the
492 * list of configuration options exported by each module and loads their
495 module_LoadBuiltins( p_vlc );
496 module_LoadPlugins( p_vlc );
502 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
503 libvlc.p_module_bank->i_children );
505 /* Hack: insert the help module here */
506 vlc_object_attach( p_help_module, libvlc.p_module_bank );
509 /* Check for help on modules */
510 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
512 Help( p_vlc, p_tmp );
515 i_ret = VLC_EEXITSUCCESS;
517 /* Check for long help option */
518 else if( config_GetInt( p_vlc, "longhelp" ) )
520 Help( p_vlc, "longhelp" );
522 i_ret = VLC_EEXITSUCCESS;
524 /* Check for module list option */
525 else if( config_GetInt( p_vlc, "list" ) )
527 ListModules( p_vlc );
529 i_ret = VLC_EEXITSUCCESS;
532 /* Check for config file options */
533 if( config_GetInt( p_vlc, "reset-config" ) )
535 vlc_object_detach( p_help_module );
536 config_ResetAll( p_vlc );
537 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
538 config_SaveConfigFile( p_vlc, NULL );
539 vlc_object_attach( p_help_module, libvlc.p_module_bank );
541 if( config_GetInt( p_vlc, "save-config" ) )
543 vlc_object_detach( p_help_module );
544 config_LoadConfigFile( p_vlc, NULL );
545 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
546 config_SaveConfigFile( p_vlc, NULL );
547 vlc_object_attach( p_help_module, libvlc.p_module_bank );
550 /* Hack: remove the help module here */
551 vlc_object_detach( p_help_module );
556 config_Free( p_help_module );
557 vlc_object_destroy( p_help_module );
558 module_EndBank( p_vlc );
559 if( i_object ) vlc_object_release( p_vlc );
566 InitDeviceValues( p_vlc );
569 * Override default configuration with config file settings
571 config_LoadConfigFile( p_vlc, NULL );
573 /* Hack: insert the help module here */
574 vlc_object_attach( p_help_module, libvlc.p_module_bank );
578 * Override configuration with command line settings
580 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
583 ShowConsole( VLC_FALSE );
584 /* Pause the console because it's destroyed when we exit */
585 fprintf( stderr, "The command line options couldn't be loaded, check "
586 "that they are valid.\n" );
589 vlc_object_detach( p_help_module );
590 config_Free( p_help_module );
591 vlc_object_destroy( p_help_module );
592 module_EndBank( p_vlc );
593 if( i_object ) vlc_object_release( p_vlc );
597 /* Hack: remove the help module here */
598 vlc_object_detach( p_help_module );
599 config_Free( p_help_module );
600 vlc_object_destroy( p_help_module );
604 * System specific configuration
606 system_Configure( p_vlc, &i_argc, ppsz_argv );
609 * Message queue options
612 var_Create( p_vlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
613 if( config_GetInt( p_vlc, "quiet" ) )
616 var_Set( p_vlc, "verbose", val );
618 var_AddCallback( p_vlc, "verbose", VerboseCallback, NULL );
619 var_Change( p_vlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
621 libvlc.b_color = libvlc.b_color && config_GetInt( p_vlc, "color" );
624 * Output messages that may still be in the queue
628 /* p_vlc initialization. FIXME ? */
630 if( !config_GetInt( p_vlc, "fpu" ) )
631 libvlc.i_cpu &= ~CPU_CAPABILITY_FPU;
633 #if defined( __i386__ ) || defined( __x86_64__ )
634 if( !config_GetInt( p_vlc, "mmx" ) )
635 libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
636 if( !config_GetInt( p_vlc, "3dn" ) )
637 libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
638 if( !config_GetInt( p_vlc, "mmxext" ) )
639 libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
640 if( !config_GetInt( p_vlc, "sse" ) )
641 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
642 if( !config_GetInt( p_vlc, "sse2" ) )
643 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE2;
645 #if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
646 if( !config_GetInt( p_vlc, "altivec" ) )
647 libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
650 #define PRINT_CAPABILITY( capability, string ) \
651 if( libvlc.i_cpu & capability ) \
653 strncat( p_capabilities, string " ", \
654 sizeof(p_capabilities) - strlen(p_capabilities) ); \
655 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
658 p_capabilities[0] = '\0';
659 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
660 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
661 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
662 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
663 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
664 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
665 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
666 PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" );
667 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
668 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
669 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
672 * Choose the best memcpy module
674 p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy", 0 );
676 if( p_vlc->pf_memcpy == NULL )
678 p_vlc->pf_memcpy = memcpy;
681 if( p_vlc->pf_memset == NULL )
683 p_vlc->pf_memset = memset;
686 libvlc.b_stats = config_GetInt( p_vlc, "stats" );
687 libvlc.p_stats = NULL;
690 * Initialize hotkey handling
692 var_Create( p_vlc, "key-pressed", VLC_VAR_INTEGER );
693 p_vlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
694 /* Do a copy (we don't need to modify the strings) */
695 memcpy( p_vlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
698 * Initialize playlist and get commandline files
700 p_playlist = playlist_Create( p_vlc );
703 msg_Err( p_vlc, "playlist initialization failed" );
704 if( p_vlc->p_memcpy_module != NULL )
706 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
708 module_EndBank( p_vlc );
709 if( i_object ) vlc_object_release( p_vlc );
713 psz_modules = config_GetPsz( p_playlist, "services-discovery" );
714 if( psz_modules && *psz_modules )
716 /* Add service discovery modules */
717 playlist_AddSDModules( p_playlist, psz_modules );
719 if( psz_modules ) free( psz_modules );
722 * Load background interfaces
724 psz_modules = config_GetPsz( p_vlc, "extraintf" );
725 psz_control = config_GetPsz( p_vlc, "control" );
727 if( psz_modules && *psz_modules && psz_control && *psz_control )
729 psz_modules = (char *)realloc( psz_modules, strlen( psz_modules ) +
730 strlen( psz_control ) + 1 );
731 sprintf( psz_modules, "%s:%s", psz_modules, psz_control );
733 else if( psz_control && *psz_control )
735 if( psz_modules ) free( psz_modules );
736 psz_modules = strdup( psz_control );
739 psz_parser = psz_modules;
740 while ( psz_parser && *psz_parser )
742 char *psz_module, *psz_temp;
743 psz_module = psz_parser;
744 psz_parser = strchr( psz_module, ':' );
750 psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
753 sprintf( psz_temp, "%s,none", psz_module );
754 VLC_AddIntf( 0, psz_temp, VLC_FALSE, VLC_FALSE );
764 * Always load the hotkeys interface if it exists
766 VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
769 * If needed, load the Xscreensaver interface
770 * Currently, only for X
772 #ifdef HAVE_X11_XLIB_H
773 if( config_GetInt( p_vlc, "disable-screensaver" ) == 1 )
775 VLC_AddIntf( 0, "screensaver,none", VLC_FALSE, VLC_FALSE );
779 if( config_GetInt( p_vlc, "file-logging" ) == 1 )
781 VLC_AddIntf( 0, "logger,none", VLC_FALSE, VLC_FALSE );
784 if( config_GetInt( p_vlc, "syslog" ) == 1 )
786 char *psz_logmode = "logmode=syslog";
787 AddIntfInternal( 0, "logger,none", VLC_FALSE, VLC_FALSE, 1, &psz_logmode );
791 if( config_GetInt( p_vlc, "show-intf" ) == 1 )
793 VLC_AddIntf( 0, "showintf,none", VLC_FALSE, VLC_FALSE );
796 if( config_GetInt( p_vlc, "network-synchronisation") == 1 )
798 VLC_AddIntf( 0, "netsync,none", VLC_FALSE, VLC_FALSE );
802 * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
804 var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
805 var_Create( p_vlc, "drawableredraw", VLC_VAR_INTEGER );
806 var_Create( p_vlc, "drawablet", VLC_VAR_INTEGER );
807 var_Create( p_vlc, "drawablel", VLC_VAR_INTEGER );
808 var_Create( p_vlc, "drawableb", VLC_VAR_INTEGER );
809 var_Create( p_vlc, "drawabler", VLC_VAR_INTEGER );
810 var_Create( p_vlc, "drawablex", VLC_VAR_INTEGER );
811 var_Create( p_vlc, "drawabley", VLC_VAR_INTEGER );
812 var_Create( p_vlc, "drawablew", VLC_VAR_INTEGER );
813 var_Create( p_vlc, "drawableh", VLC_VAR_INTEGER );
814 var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER );
815 var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER );
817 /* Create volume callback system. */
818 var_Create( p_vlc, "volume-change", VLC_VAR_BOOL );
821 * Get input filenames given as commandline arguments
823 GetFilenames( p_vlc, i_argc, ppsz_argv );
826 * Get --open argument
828 var_Create( p_vlc, "open", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
829 var_Get( p_vlc, "open", &val );
830 if ( val.psz_string != NULL && *val.psz_string )
832 VLC_AddTarget( p_vlc->i_object_id, val.psz_string, NULL, 0,
833 PLAYLIST_INSERT, 0 );
835 if ( val.psz_string != NULL ) free( val.psz_string );
837 if( i_object ) vlc_object_release( p_vlc );
841 /*****************************************************************************
842 * VLC_AddIntf: add an interface
843 *****************************************************************************
844 * This function opens an interface plugin and runs it. If b_block is set
845 * to 0, VLC_AddIntf will return immediately and let the interface run in a
846 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
847 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
848 * the playlist when it is completely initialised.
849 *****************************************************************************/
850 int VLC_AddIntf( int i_object, char const *psz_module,
851 vlc_bool_t b_block, vlc_bool_t b_play )
853 return AddIntfInternal( i_object, psz_module, b_block, b_play, 0, NULL );
857 /*****************************************************************************
858 * VLC_Die: ask vlc to die.
859 *****************************************************************************
860 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
861 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
862 *****************************************************************************/
863 int VLC_Die( int i_object )
865 vlc_t *p_vlc = vlc_current_object( i_object );
872 p_vlc->b_die = VLC_TRUE;
874 if( i_object ) vlc_object_release( p_vlc );
878 /*****************************************************************************
879 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
880 *****************************************************************************/
881 int VLC_CleanUp( int i_object )
883 intf_thread_t * p_intf;
884 playlist_t * p_playlist;
885 vout_thread_t * p_vout;
886 aout_instance_t * p_aout;
887 announce_handler_t * p_announce;
888 stats_handler_t * p_stats;
889 vlc_t *p_vlc = vlc_current_object( i_object );
891 /* Check that the handle is valid */
898 * Ask the interfaces to stop and destroy them
900 msg_Dbg( p_vlc, "removing all interfaces" );
901 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
903 intf_StopThread( p_intf );
904 vlc_object_detach( p_intf );
905 vlc_object_release( p_intf );
906 intf_Destroy( p_intf );
912 msg_Dbg( p_vlc, "removing playlist handler" );
913 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
916 vlc_object_detach( p_playlist );
917 vlc_object_release( p_playlist );
918 playlist_Destroy( p_playlist );
924 msg_Dbg( p_vlc, "removing all video outputs" );
925 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
927 vlc_object_detach( p_vout );
928 vlc_object_release( p_vout );
929 vout_Destroy( p_vout );
935 msg_Dbg( p_vlc, "removing all audio outputs" );
936 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
938 vlc_object_detach( (vlc_object_t *)p_aout );
939 vlc_object_release( (vlc_object_t *)p_aout );
940 aout_Delete( p_aout );
943 while( ( p_stats = vlc_object_find( p_vlc, VLC_OBJECT_STATS, FIND_CHILD) ))
945 stats_TimersDumpAll( p_vlc );
946 stats_HandlerDestroy( p_stats );
947 vlc_object_detach( (vlc_object_t*) p_stats );
948 vlc_object_release( (vlc_object_t *)p_stats );
953 * Free announce handler(s?)
955 while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE,
958 msg_Dbg( p_vlc, "removing announce handler" );
959 vlc_object_detach( p_announce );
960 vlc_object_release( p_announce );
961 announce_HandlerDestroy( p_announce );
964 if( i_object ) vlc_object_release( p_vlc );
968 /*****************************************************************************
969 * VLC_Destroy: Destroy everything.
970 *****************************************************************************
971 * This function requests the running threads to finish, waits for their
972 * termination, and destroys their structure.
973 *****************************************************************************/
974 int VLC_Destroy( int i_object )
976 vlc_t *p_vlc = vlc_current_object( i_object );
984 * Free allocated memory
986 if( p_vlc->p_memcpy_module )
988 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
989 p_vlc->p_memcpy_module = NULL;
995 module_EndBank( p_vlc );
997 if( p_vlc->psz_homedir )
999 free( p_vlc->psz_homedir );
1000 p_vlc->psz_homedir = NULL;
1003 if( p_vlc->psz_userdir )
1005 free( p_vlc->psz_userdir );
1006 p_vlc->psz_userdir = NULL;
1009 if( p_vlc->psz_configfile )
1011 free( p_vlc->psz_configfile );
1012 p_vlc->psz_configfile = NULL;
1015 if( p_vlc->p_hotkeys )
1017 free( p_vlc->p_hotkeys );
1018 p_vlc->p_hotkeys = NULL;
1022 * System specific cleaning code
1024 system_End( p_vlc );
1027 * Free message queue.
1028 * Nobody shall use msg_* afterward.
1031 msg_Destroy( p_libvlc );
1033 /* Destroy global iconv */
1036 /* Destroy mutexes */
1037 vlc_mutex_destroy( &p_vlc->config_lock );
1039 vlc_object_detach( p_vlc );
1041 /* Release object before destroying it */
1042 if( i_object ) vlc_object_release( p_vlc );
1044 vlc_object_destroy( p_vlc );
1046 /* Stop thread system: last one out please shut the door! */
1047 vlc_threads_end( p_libvlc );
1052 /*****************************************************************************
1053 * VLC_VariableSet: set a vlc variable
1054 *****************************************************************************/
1055 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
1057 vlc_t *p_vlc = vlc_current_object( i_object );
1065 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
1066 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
1067 if( !strncmp( psz_var, "conf::", 6 ) )
1069 module_config_t *p_item;
1070 char const *psz_newvar = psz_var + 6;
1072 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
1076 switch( p_item->i_type )
1078 case CONFIG_ITEM_BOOL:
1079 config_PutInt( p_vlc, psz_newvar, value.b_bool );
1081 case CONFIG_ITEM_INTEGER:
1082 config_PutInt( p_vlc, psz_newvar, value.i_int );
1084 case CONFIG_ITEM_FLOAT:
1085 config_PutFloat( p_vlc, psz_newvar, value.f_float );
1088 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
1091 if( i_object ) vlc_object_release( p_vlc );
1096 i_ret = var_Set( p_vlc, psz_var, value );
1098 if( i_object ) vlc_object_release( p_vlc );
1102 /*****************************************************************************
1103 * VLC_VariableGet: get a vlc variable
1104 *****************************************************************************/
1105 int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
1107 vlc_t *p_vlc = vlc_current_object( i_object );
1115 i_ret = var_Get( p_vlc , psz_var, p_value );
1117 if( i_object ) vlc_object_release( p_vlc );
1121 /*****************************************************************************
1122 * VLC_VariableType: get a vlc variable type
1123 *****************************************************************************/
1124 int VLC_VariableType( int i_object, char const *psz_var, int *pi_type )
1127 vlc_t *p_vlc = vlc_current_object( i_object );
1134 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
1135 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
1136 if( !strncmp( psz_var, "conf::", 6 ) )
1138 module_config_t *p_item;
1139 char const *psz_newvar = psz_var + 6;
1141 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
1145 switch( p_item->i_type )
1147 case CONFIG_ITEM_BOOL:
1148 i_type = VLC_VAR_BOOL;
1150 case CONFIG_ITEM_INTEGER:
1151 i_type = VLC_VAR_INTEGER;
1153 case CONFIG_ITEM_FLOAT:
1154 i_type = VLC_VAR_FLOAT;
1157 i_type = VLC_VAR_STRING;
1165 i_type = VLC_VAR_TYPE & var_Type( p_vlc , psz_var );
1167 if( i_object ) vlc_object_release( p_vlc );
1177 /*****************************************************************************
1178 * VLC_AddTarget: adds a target for playing.
1179 *****************************************************************************
1180 * This function adds psz_target to the current playlist. If a playlist does
1181 * not exist, it will create one.
1182 *****************************************************************************/
1183 int VLC_AddTarget( int i_object, char const *psz_target,
1184 char const **ppsz_options, int i_options,
1185 int i_mode, int i_pos )
1188 playlist_t *p_playlist;
1189 vlc_t *p_vlc = vlc_current_object( i_object );
1196 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1198 if( p_playlist == NULL )
1200 msg_Dbg( p_vlc, "no playlist present, creating one" );
1201 p_playlist = playlist_Create( p_vlc );
1203 if( p_playlist == NULL )
1205 if( i_object ) vlc_object_release( p_vlc );
1206 return VLC_EGENERIC;
1209 vlc_object_yield( p_playlist );
1212 i_err = playlist_AddExt( p_playlist, psz_target, psz_target,
1213 i_mode, i_pos, -1, ppsz_options, i_options);
1215 vlc_object_release( p_playlist );
1217 if( i_object ) vlc_object_release( p_vlc );
1221 /*****************************************************************************
1222 * VLC_Play: play the playlist
1223 *****************************************************************************/
1224 int VLC_Play( int i_object )
1226 playlist_t * p_playlist;
1227 vlc_t *p_vlc = vlc_current_object( i_object );
1229 /* Check that the handle is valid */
1235 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1239 if( i_object ) vlc_object_release( p_vlc );
1243 playlist_Play( p_playlist );
1244 vlc_object_release( p_playlist );
1246 if( i_object ) vlc_object_release( p_vlc );
1250 /*****************************************************************************
1251 * VLC_Pause: toggle pause
1252 *****************************************************************************/
1253 int VLC_Pause( int i_object )
1255 playlist_t * p_playlist;
1256 vlc_t *p_vlc = vlc_current_object( i_object );
1258 /* Check that the handle is valid */
1264 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1268 if( i_object ) vlc_object_release( p_vlc );
1272 playlist_Pause( p_playlist );
1273 vlc_object_release( p_playlist );
1275 if( i_object ) vlc_object_release( p_vlc );
1279 /*****************************************************************************
1280 * VLC_Pause: toggle pause
1281 *****************************************************************************/
1282 int VLC_Stop( int i_object )
1284 playlist_t * p_playlist;
1285 vlc_t *p_vlc = vlc_current_object( i_object );
1287 /* Check that the handle is valid */
1293 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1297 if( i_object ) vlc_object_release( p_vlc );
1301 playlist_Stop( p_playlist );
1302 vlc_object_release( p_playlist );
1304 if( i_object ) vlc_object_release( p_vlc );
1308 /*****************************************************************************
1309 * VLC_IsPlaying: Query for Playlist Status
1310 *****************************************************************************/
1311 vlc_bool_t VLC_IsPlaying( int i_object )
1313 playlist_t * p_playlist;
1314 vlc_bool_t b_playing;
1316 vlc_t *p_vlc = vlc_current_object( i_object );
1318 /* Check that the handle is valid */
1324 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1328 if( i_object ) vlc_object_release( p_vlc );
1332 if( p_playlist->p_input )
1335 var_Get( p_playlist->p_input, "state", &val );
1336 b_playing = ( val.i_int == PLAYING_S );
1340 msg_Dbg(p_vlc, "polling playlist_IsPlaying");
1341 b_playing = playlist_IsPlaying( p_playlist );
1343 vlc_object_release( p_playlist );
1345 if( i_object ) vlc_object_release( p_vlc );
1350 * Get the current position in a input
1352 * Return the current position as a float
1353 * \note For some inputs, this will be unknown.
1355 * \param i_object a vlc object id
1356 * \return a float in the range of 0.0 - 1.0
1358 float VLC_PositionGet( int i_object )
1360 input_thread_t *p_input;
1362 vlc_t *p_vlc = vlc_current_object( i_object );
1364 /* Check that the handle is valid */
1370 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1374 if( i_object ) vlc_object_release( p_vlc );
1378 var_Get( p_input, "position", &val );
1379 vlc_object_release( p_input );
1381 if( i_object ) vlc_object_release( p_vlc );
1386 * Set the current position in a input
1388 * Set the current position in a input and then return
1389 * the current position as a float.
1390 * \note For some inputs, this will be unknown.
1392 * \param i_object a vlc object id
1393 * \param i_position a float in the range of 0.0 - 1.0
1394 * \return a float in the range of 0.0 - 1.0
1396 float VLC_PositionSet( int i_object, float i_position )
1398 input_thread_t *p_input;
1400 vlc_t *p_vlc = vlc_current_object( i_object );
1402 /* Check that the handle is valid */
1408 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1412 if( i_object ) vlc_object_release( p_vlc );
1416 val.f_float = i_position;
1417 var_Set( p_input, "position", val );
1418 var_Get( p_input, "position", &val );
1419 vlc_object_release( p_input );
1421 if( i_object ) vlc_object_release( p_vlc );
1426 * Get the current position in a input
1428 * Return the current position in seconds from the start.
1429 * \note For some inputs, this will be unknown.
1431 * \param i_object a vlc object id
1432 * \return the offset from 0:00 in seconds
1434 int VLC_TimeGet( int i_object )
1436 input_thread_t *p_input;
1438 vlc_t *p_vlc = vlc_current_object( i_object );
1440 /* Check that the handle is valid */
1446 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1450 if( i_object ) vlc_object_release( p_vlc );
1454 var_Get( p_input, "time", &val );
1455 vlc_object_release( p_input );
1457 if( i_object ) vlc_object_release( p_vlc );
1458 return val.i_time / 1000000;
1462 * Seek to a position in the current input
1464 * Seek i_seconds in the current input. If b_relative is set,
1465 * then the seek will be relative to the current position, otherwise
1466 * it will seek to i_seconds from the beginning of the input.
1467 * \note For some inputs, this will be unknown.
1469 * \param i_object a vlc object id
1470 * \param i_seconds seconds from current position or from beginning of input
1471 * \param b_relative seek relative from current position
1472 * \return VLC_SUCCESS on success
1474 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
1476 input_thread_t *p_input;
1478 vlc_t *p_vlc = vlc_current_object( i_object );
1480 /* Check that the handle is valid */
1486 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1490 if( i_object ) vlc_object_release( p_vlc );
1496 val.i_time = i_seconds;
1497 val.i_time = val.i_time * 1000000L;
1498 var_Set( p_input, "time-offset", val );
1502 val.i_time = i_seconds;
1503 val.i_time = val.i_time * 1000000L;
1504 var_Set( p_input, "time", val );
1506 vlc_object_release( p_input );
1508 if( i_object ) vlc_object_release( p_vlc );
1513 * Get the total length of a input
1515 * Return the total length in seconds from the current input.
1516 * \note For some inputs, this will be unknown.
1518 * \param i_object a vlc object id
1519 * \return the length in seconds
1521 int VLC_LengthGet( int i_object )
1523 input_thread_t *p_input;
1525 vlc_t *p_vlc = vlc_current_object( i_object );
1527 /* Check that the handle is valid */
1533 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1537 if( i_object ) vlc_object_release( p_vlc );
1541 var_Get( p_input, "length", &val );
1542 vlc_object_release( p_input );
1544 if( i_object ) vlc_object_release( p_vlc );
1545 return val.i_time / 1000000L;
1549 * Play the input faster than realtime
1551 * 2x, 4x, 8x faster than realtime
1552 * \note For some inputs, this will be impossible.
1554 * \param i_object a vlc object id
1555 * \return the current speedrate
1557 float VLC_SpeedFaster( int i_object )
1559 input_thread_t *p_input;
1561 vlc_t *p_vlc = vlc_current_object( i_object );
1563 /* Check that the handle is valid */
1569 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1573 if( i_object ) vlc_object_release( p_vlc );
1577 val.b_bool = VLC_TRUE;
1578 var_Set( p_input, "rate-faster", val );
1579 var_Get( p_input, "rate", &val );
1580 vlc_object_release( p_input );
1582 if( i_object ) vlc_object_release( p_vlc );
1583 return val.f_float / INPUT_RATE_DEFAULT;
1587 * Play the input slower than realtime
1589 * 1/2x, 1/4x, 1/8x slower than realtime
1590 * \note For some inputs, this will be impossible.
1592 * \param i_object a vlc object id
1593 * \return the current speedrate
1595 float VLC_SpeedSlower( int i_object )
1597 input_thread_t *p_input;
1599 vlc_t *p_vlc = vlc_current_object( i_object );
1601 /* Check that the handle is valid */
1607 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1611 if( i_object ) vlc_object_release( p_vlc );
1615 val.b_bool = VLC_TRUE;
1616 var_Set( p_input, "rate-slower", val );
1617 var_Get( p_input, "rate", &val );
1618 vlc_object_release( p_input );
1620 if( i_object ) vlc_object_release( p_vlc );
1621 return val.f_float / INPUT_RATE_DEFAULT;
1625 * Return the current playlist item
1627 * Returns the index of the playlistitem that is currently selected for play.
1628 * This is valid even if nothing is currently playing.
1630 * \param i_object a vlc object id
1631 * \return the current index
1633 int VLC_PlaylistIndex( int i_object )
1636 playlist_t * p_playlist;
1637 vlc_t *p_vlc = vlc_current_object( i_object );
1639 /* Check that the handle is valid */
1645 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1649 if( i_object ) vlc_object_release( p_vlc );
1653 i_index = p_playlist->i_index;
1654 vlc_object_release( p_playlist );
1656 if( i_object ) vlc_object_release( p_vlc );
1661 * Total amount of items in the playlist
1663 * \param i_object a vlc object id
1664 * \return amount of playlist items
1666 int VLC_PlaylistNumberOfItems( int i_object )
1669 playlist_t * p_playlist;
1670 vlc_t *p_vlc = vlc_current_object( i_object );
1672 /* Check that the handle is valid */
1678 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1682 if( i_object ) vlc_object_release( p_vlc );
1686 i_size = p_playlist->i_size;
1687 vlc_object_release( p_playlist );
1689 if( i_object ) vlc_object_release( p_vlc );
1694 * Next playlist item
1696 * Skip to the next playlistitem and play it.
1698 * \param i_object a vlc object id
1699 * \return VLC_SUCCESS on success
1701 int VLC_PlaylistNext( int i_object )
1703 playlist_t * p_playlist;
1704 vlc_t *p_vlc = vlc_current_object( i_object );
1706 /* Check that the handle is valid */
1712 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1716 if( i_object ) vlc_object_release( p_vlc );
1720 playlist_Next( p_playlist );
1721 vlc_object_release( p_playlist );
1723 if( i_object ) vlc_object_release( p_vlc );
1728 * Previous playlist item
1730 * Skip to the previous playlistitem and play it.
1732 * \param i_object a vlc object id
1733 * \return VLC_SUCCESS on success
1735 int VLC_PlaylistPrev( int i_object )
1737 playlist_t * p_playlist;
1738 vlc_t *p_vlc = vlc_current_object( i_object );
1740 /* Check that the handle is valid */
1746 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1750 if( i_object ) vlc_object_release( p_vlc );
1754 playlist_Prev( p_playlist );
1755 vlc_object_release( p_playlist );
1757 if( i_object ) vlc_object_release( p_vlc );
1762 /*****************************************************************************
1763 * VLC_PlaylistClear: Empty the playlist
1764 *****************************************************************************/
1765 int VLC_PlaylistClear( int i_object )
1768 playlist_t * p_playlist;
1769 vlc_t *p_vlc = vlc_current_object( i_object );
1771 /* Check that the handle is valid */
1777 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1781 if( i_object ) vlc_object_release( p_vlc );
1785 i_err = playlist_Clear( p_playlist );
1787 vlc_object_release( p_playlist );
1789 if( i_object ) vlc_object_release( p_vlc );
1796 * \param i_object a vlc object id
1797 * \param i_volume something in a range from 0-200
1798 * \return the new volume (range 0-200 %)
1800 int VLC_VolumeSet( int i_object, int i_volume )
1802 audio_volume_t i_vol = 0;
1803 vlc_t *p_vlc = vlc_current_object( i_object );
1805 /* Check that the handle is valid */
1811 if( i_volume >= 0 && i_volume <= 200 )
1813 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
1814 aout_VolumeSet( p_vlc, i_vol );
1817 if( i_object ) vlc_object_release( p_vlc );
1818 return i_vol * 200 / AOUT_VOLUME_MAX;
1822 * Get the current volume
1824 * Retrieve the current volume.
1826 * \param i_object a vlc object id
1827 * \return the current volume (range 0-200 %)
1829 int VLC_VolumeGet( int i_object )
1831 audio_volume_t i_volume;
1832 vlc_t *p_vlc = vlc_current_object( i_object );
1834 /* Check that the handle is valid */
1840 aout_VolumeGet( p_vlc, &i_volume );
1842 if( i_object ) vlc_object_release( p_vlc );
1843 return i_volume*200/AOUT_VOLUME_MAX;
1847 * Mute/Unmute the volume
1849 * \param i_object a vlc object id
1850 * \return VLC_SUCCESS on success
1852 int VLC_VolumeMute( int i_object )
1854 vlc_t *p_vlc = vlc_current_object( i_object );
1856 /* Check that the handle is valid */
1862 aout_VolumeMute( p_vlc, NULL );
1864 if( i_object ) vlc_object_release( p_vlc );
1868 /*****************************************************************************
1869 * VLC_FullScreen: toggle fullscreen mode
1870 *****************************************************************************/
1871 int VLC_FullScreen( int i_object )
1873 vout_thread_t *p_vout;
1874 vlc_t *p_vlc = vlc_current_object( i_object );
1881 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
1885 if( i_object ) vlc_object_release( p_vlc );
1889 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1890 vlc_object_release( p_vout );
1892 if( i_object ) vlc_object_release( p_vlc );
1896 /* following functions are local */
1899 static int AddIntfInternal( int i_object, char const *psz_module,
1900 vlc_bool_t b_block, vlc_bool_t b_play,
1901 int i_options, char **ppsz_options )
1904 intf_thread_t *p_intf;
1905 vlc_t *p_vlc = vlc_current_object( i_object );
1913 if( p_vlc->p_libvlc->b_daemon && b_block && !psz_module )
1915 /* Daemon mode hack.
1916 * We prefer the dummy interface if none is specified. */
1917 char *psz_interface = config_GetPsz( p_vlc, "intf" );
1918 if( !psz_interface || !*psz_interface ) psz_module = "dummy";
1919 if( psz_interface ) free( psz_interface );
1923 /* Try to create the interface */
1924 p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf",
1925 i_options, ppsz_options );
1927 if( p_intf == NULL )
1929 msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
1930 if( i_object ) vlc_object_release( p_vlc );
1931 return VLC_EGENERIC;
1934 /* Interface doesn't handle play on start so do it ourselves */
1935 if( !p_intf->b_play && b_play ) VLC_Play( i_object );
1937 /* Try to run the interface */
1938 p_intf->b_play = b_play;
1939 p_intf->b_block = b_block;
1940 i_err = intf_RunThread( p_intf );
1943 vlc_object_detach( p_intf );
1944 intf_Destroy( p_intf );
1945 if( i_object ) vlc_object_release( p_vlc );
1949 if( i_object ) vlc_object_release( p_vlc );
1954 /*****************************************************************************
1955 * SetLanguage: set the interface language.
1956 *****************************************************************************
1957 * We set the LC_MESSAGES locale category for interface messages and buttons,
1958 * as well as the LC_CTYPE category for string sorting and possible wide
1959 * character support.
1960 *****************************************************************************/
1961 static void SetLanguage ( char const *psz_lang )
1963 #if defined( ENABLE_NLS ) \
1964 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
1967 #if defined( __APPLE__ ) || defined ( WIN32 ) || defined( SYS_BEOS )
1971 if( psz_lang && !*psz_lang )
1973 # if defined( HAVE_LC_MESSAGES )
1974 setlocale( LC_MESSAGES, psz_lang );
1976 setlocale( LC_CTYPE, psz_lang );
1981 /* I need that under Darwin, please check it doesn't disturb
1982 * other platforms. --Meuuh */
1983 setenv( "LANG", psz_lang, 1 );
1985 #elif defined( SYS_BEOS ) || defined( WIN32 )
1986 /* We set LC_ALL manually because it is the only way to set
1987 * the language at runtime under eg. Windows. Beware that this
1988 * makes the environment unconsistent when libvlc is unloaded and
1989 * should probably be moved to a safer place like vlc.c. */
1990 static char psz_lcall[20];
1991 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
1992 psz_lcall[19] = '\0';
1993 putenv( psz_lcall );
1996 setlocale( LC_ALL, psz_lang );
1999 /* Specify where to find the locales for current domain */
2000 #if !defined( __APPLE__ ) && !defined( WIN32 ) && !defined( SYS_BEOS )
2001 psz_path = LOCALEDIR;
2003 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
2007 if( !bindtextdomain( PACKAGE_NAME, psz_path ) )
2009 fprintf( stderr, "warning: couldn't bind domain %s in directory %s\n",
2010 PACKAGE_NAME, psz_path );
2013 /* Set the default domain */
2014 bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
2018 /*****************************************************************************
2019 * GetFilenames: parse command line options which are not flags
2020 *****************************************************************************
2021 * Parse command line for input files as well as their associated options.
2022 * An option always follows its associated input and begins with a ":".
2023 *****************************************************************************/
2024 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
2026 int i_opt, i_options;
2028 /* We assume that the remaining parameters are filenames
2029 * and their input options */
2030 for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
2032 const char *psz_target;
2035 /* Count the input options */
2036 while( *ppsz_argv[ i_opt ] == ':' && i_opt > optind )
2042 /* TODO: write an internal function of this one, to avoid
2043 * unnecessary lookups. */
2044 /* FIXME: should we convert options to UTF-8 as well ?? */
2045 psz_target = FromLocale( ppsz_argv[ i_opt ] );
2046 VLC_AddTarget( p_vlc->i_object_id, psz_target,
2047 (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
2049 PLAYLIST_INSERT, 0 );
2050 LocaleFree( psz_target );
2056 /*****************************************************************************
2057 * Help: print program help
2058 *****************************************************************************
2059 * Print a short inline help. Message interface is initialized at this stage.
2060 *****************************************************************************/
2061 static void Help( vlc_t *p_this, char const *psz_help_name )
2064 ShowConsole( VLC_TRUE );
2067 if( psz_help_name && !strcmp( psz_help_name, "help" ) )
2069 utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
2070 Usage( p_this, "help" );
2071 Usage( p_this, "main" );
2073 else if( psz_help_name && !strcmp( psz_help_name, "longhelp" ) )
2075 utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
2076 Usage( p_this, NULL );
2078 else if( psz_help_name )
2080 Usage( p_this, psz_help_name );
2083 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2088 /*****************************************************************************
2089 * Usage: print module usage
2090 *****************************************************************************
2091 * Print a short inline help. Message interface is initialized at this stage.
2092 *****************************************************************************/
2093 static void Usage( vlc_t *p_this, char const *psz_module_name )
2095 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
2096 /* short option ------' | | | | | | |
2097 * option name ------------' | | | | | |
2098 * <bra -------------------------' | | | | |
2099 * option type or "" --------------' | | | |
2100 * ket> -----------------------------' | | |
2101 * padding spaces ---------------------' | |
2102 * comment -------------------------------' |
2103 * comment suffix --------------------------'
2105 * The purpose of having bra and ket is that we might i18n them as well.
2107 #define LINE_START 8
2108 #define PADDING_SPACES 25
2111 module_config_t *p_item;
2112 char psz_spaces_text[PADDING_SPACES+LINE_START+1];
2113 char psz_spaces_longtext[LINE_START+3];
2114 char psz_format[sizeof(FORMAT_STRING)];
2115 char psz_buffer[10000];
2118 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
2119 vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" );
2120 vlc_bool_t b_description;
2122 memset( psz_spaces_text, ' ', PADDING_SPACES+LINE_START );
2123 psz_spaces_text[PADDING_SPACES+LINE_START] = '\0';
2124 memset( psz_spaces_longtext, ' ', LINE_START+2 );
2125 psz_spaces_longtext[LINE_START+2] = '\0';
2127 strcpy( psz_format, FORMAT_STRING );
2129 /* List all modules */
2130 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2132 /* Enumerate the config for each module */
2133 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2135 vlc_bool_t b_help_module;
2137 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2139 if( psz_module_name && strcmp( psz_module_name,
2140 p_parser->psz_object_name ) )
2145 /* Ignore modules without config options */
2146 if( !p_parser->i_config_items )
2151 /* Ignore modules with only advanced config options if requested */
2154 for( p_item = p_parser->p_config;
2155 p_item->i_type != CONFIG_HINT_END;
2158 if( (p_item->i_type & CONFIG_ITEM) &&
2159 !p_item->b_advanced ) break;
2161 if( p_item->i_type == CONFIG_HINT_END ) continue;
2164 /* Print name of module */
2165 if( strcmp( "main", p_parser->psz_object_name ) )
2166 utf8_fprintf( stdout, "\n %s\n", p_parser->psz_longname );
2168 b_help_module = !strcmp( "help", p_parser->psz_object_name );
2170 /* Print module options */
2171 for( p_item = p_parser->p_config;
2172 p_item->i_type != CONFIG_HINT_END;
2175 char *psz_text, *psz_spaces = psz_spaces_text;
2176 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
2177 char *psz_suf = "", *psz_prefix = NULL;
2180 /* Skip deprecated options */
2181 if( p_item->psz_current )
2185 /* Skip advanced options if requested */
2186 if( p_item->b_advanced && !b_advanced )
2191 switch( p_item->i_type )
2193 case CONFIG_HINT_CATEGORY:
2194 case CONFIG_HINT_USAGE:
2195 if( !strcmp( "main", p_parser->psz_object_name ) )
2196 utf8_fprintf( stdout, "\n %s\n", p_item->psz_text );
2199 case CONFIG_ITEM_STRING:
2200 case CONFIG_ITEM_FILE:
2201 case CONFIG_ITEM_DIRECTORY:
2202 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
2203 case CONFIG_ITEM_MODULE_CAT:
2204 case CONFIG_ITEM_MODULE_LIST:
2205 case CONFIG_ITEM_MODULE_LIST_CAT:
2206 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
2208 if( p_item->ppsz_list )
2211 psz_type = psz_buffer;
2213 for( i = 0; p_item->ppsz_list[i]; i++ )
2215 if( i ) strcat( psz_type, "," );
2216 strcat( psz_type, p_item->ppsz_list[i] );
2221 case CONFIG_ITEM_INTEGER:
2222 case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
2223 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
2225 if( p_item->i_list )
2228 psz_type = psz_buffer;
2230 for( i = 0; p_item->ppsz_list_text[i]; i++ )
2232 if( i ) strcat( psz_type, ", " );
2233 sprintf( psz_type + strlen(psz_type), "%i (%s)",
2235 p_item->ppsz_list_text[i] );
2240 case CONFIG_ITEM_FLOAT:
2241 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
2243 case CONFIG_ITEM_BOOL:
2244 psz_bra = ""; psz_type = ""; psz_ket = "";
2245 if( !b_help_module )
2247 psz_suf = p_item->i_value ? _(" (default enabled)") :
2248 _(" (default disabled)");
2258 /* Add short option if any */
2259 if( p_item->i_short )
2261 sprintf( psz_short, "-%c,", p_item->i_short );
2265 strcpy( psz_short, " " );
2268 i = PADDING_SPACES - strlen( p_item->psz_name )
2269 - strlen( psz_bra ) - strlen( psz_type )
2270 - strlen( psz_ket ) - 1;
2272 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
2274 psz_prefix = ", --no-";
2275 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
2280 psz_spaces[0] = '\n';
2285 psz_spaces[i] = '\0';
2288 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
2290 utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2291 psz_prefix, p_item->psz_name, psz_bra, psz_type,
2292 psz_ket, psz_spaces );
2296 utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2297 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
2300 psz_spaces[i] = ' ';
2302 /* We wrap the rest of the output */
2303 sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
2304 b_description = config_GetInt( p_this, "help-verbose" );
2307 psz_text = psz_buffer;
2310 char *psz_parser, *psz_word;
2311 size_t i_end = strlen( psz_text );
2313 /* If the remaining text fits in a line, print it. */
2314 if( i_end <= (size_t)i_width )
2316 utf8_fprintf( stdout, "%s\n", psz_text );
2320 /* Otherwise, eat as many words as possible */
2321 psz_parser = psz_text;
2324 psz_word = psz_parser;
2325 psz_parser = strchr( psz_word, ' ' );
2326 /* If no space was found, we reached the end of the text
2327 * block; otherwise, we skip the space we just found. */
2328 psz_parser = psz_parser ? psz_parser + 1
2331 } while( psz_parser - psz_text <= i_width );
2333 /* We cut a word in one of these cases:
2334 * - it's the only word in the line and it's too long.
2335 * - we used less than 80% of the width and the word we are
2336 * going to wrap is longer than 40% of the width, and even
2337 * if the word would have fit in the next line. */
2338 if( psz_word == psz_text
2339 || ( psz_word - psz_text < 80 * i_width / 100
2340 && psz_parser - psz_word > 40 * i_width / 100 ) )
2342 char c = psz_text[i_width];
2343 psz_text[i_width] = '\0';
2344 utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2345 psz_text += i_width;
2350 psz_word[-1] = '\0';
2351 utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2352 psz_text = psz_word;
2356 if( b_description && p_item->psz_longtext )
2358 sprintf( psz_buffer, "%s%s", p_item->psz_longtext, psz_suf );
2359 b_description = VLC_FALSE;
2360 psz_spaces = psz_spaces_longtext;
2361 utf8_fprintf( stdout, "%s", psz_spaces );
2367 /* Release the module list */
2368 vlc_list_release( p_list );
2371 /*****************************************************************************
2372 * ListModules: list the available modules with their description
2373 *****************************************************************************
2374 * Print a list of all available modules (builtins and plugins) and a short
2375 * description for each one.
2376 *****************************************************************************/
2377 static void ListModules( vlc_t *p_this )
2381 char psz_spaces[22];
2384 memset( psz_spaces, ' ', 22 );
2387 ShowConsole( VLC_TRUE );
2390 /* List all modules */
2391 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2393 /* Enumerate each module */
2394 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2398 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2400 /* Nasty hack, but right now I'm too tired to think about a nice
2402 i = 22 - strlen( p_parser->psz_object_name ) - 1;
2406 utf8_fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
2407 psz_spaces, p_parser->psz_longname );
2409 psz_spaces[i] = ' ';
2412 vlc_list_release( p_list );
2414 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2419 /*****************************************************************************
2420 * Version: print complete program version
2421 *****************************************************************************
2422 * Print complete program version and build number.
2423 *****************************************************************************/
2424 static void Version( void )
2427 ShowConsole( VLC_TRUE );
2430 utf8_fprintf( stdout, _("VLC version %s\n"), VLC_Version() );
2431 utf8_fprintf( stdout, _("Compiled by %s@%s.%s\n"),
2432 VLC_CompileBy(), VLC_CompileHost(), VLC_CompileDomain() );
2433 utf8_fprintf( stdout, _("Compiler: %s\n"), VLC_Compiler() );
2434 #ifndef HAVE_SHARED_LIBVLC
2435 if( strcmp( VLC_Changeset(), "exported" ) )
2436 utf8_fprintf( stdout, _("Based upon svn changeset [%s]\n"),
2439 utf8_fprintf( stdout, LICENSE_MSG );
2441 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2446 /*****************************************************************************
2447 * ShowConsole: On Win32, create an output console for debug messages
2448 *****************************************************************************
2449 * This function is useful only on Win32.
2450 *****************************************************************************/
2452 static void ShowConsole( vlc_bool_t b_dofile )
2457 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2461 freopen( "CONOUT$", "w", stderr );
2462 freopen( "CONIN$", "r", stdin );
2464 if( b_dofile && (f_help = fopen( "vlc-help.txt", "wt" )) )
2467 freopen( "vlc-help.txt", "wt", stdout );
2468 utf8_fprintf( stderr, _("\nDumped content to vlc-help.txt file.\n") );
2471 else freopen( "CONOUT$", "w", stdout );
2477 /*****************************************************************************
2478 * PauseConsole: On Win32, wait for a key press before closing the console
2479 *****************************************************************************
2480 * This function is useful only on Win32.
2481 *****************************************************************************/
2483 static void PauseConsole( void )
2487 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2489 utf8_fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
2497 /*****************************************************************************
2498 * ConsoleWidth: Return the console width in characters
2499 *****************************************************************************
2500 * We use the stty shell command to get the console width; if this fails or
2501 * if the width is less than 80, we default to 80.
2502 *****************************************************************************/
2503 static int ConsoleWidth( void )
2508 char buf[20], *psz_parser;
2512 file = popen( "stty size 2>/dev/null", "r" );
2515 i_ret = fread( buf, 1, 20, file );
2519 psz_parser = strchr( buf, ' ' );
2522 i_ret = atoi( psz_parser + 1 );
2537 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
2538 vlc_value_t old_val, vlc_value_t new_val, void *param)
2540 vlc_t *p_vlc = (vlc_t *)p_this;
2542 if( new_val.i_int >= -1 )
2544 p_vlc->p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );
2549 /*****************************************************************************
2550 * InitDeviceValues: initialize device values
2551 *****************************************************************************
2552 * This function inits the dvd, vcd and cd-audio values
2553 *****************************************************************************/
2554 static void InitDeviceValues( vlc_t *p_vlc )
2557 LibHalContext * ctx;
2562 DBusConnection *p_connection;
2566 ctx = libhal_ctx_new();
2568 dbus_error_init( &error );
2569 p_connection = dbus_bus_get ( DBUS_BUS_SYSTEM, &error );
2570 if( dbus_error_is_set( &error ) )
2572 dbus_error_free( &error );
2575 libhal_ctx_set_dbus_connection( ctx, p_connection );
2576 if( libhal_ctx_init( ctx, &error ) )
2578 if( ( ctx = hal_initialize( NULL, FALSE ) ) )
2582 if( ( devices = libhal_get_all_devices( ctx, &i_devices, NULL ) ) )
2584 if( ( devices = hal_get_all_devices( ctx, &i_devices ) ) )
2587 for( i = 0; i < i_devices; i++ )
2590 if( !libhal_device_property_exists( ctx, devices[i],
2591 "storage.cdrom.dvd", NULL ) )
2593 if( !hal_device_property_exists( ctx, devices[ i ],
2594 "storage.cdrom.dvd" ) )
2600 b_dvd = libhal_device_get_property_bool( ctx, devices[ i ],
2601 "storage.cdrom.dvd", NULL );
2602 block_dev = libhal_device_get_property_string( ctx,
2603 devices[ i ], "block.device" , NULL );
2605 b_dvd = hal_device_get_property_bool( ctx, devices[ i ],
2606 "storage.cdrom.dvd" );
2607 block_dev = hal_device_get_property_string( ctx, devices[ i ],
2612 config_PutPsz( p_vlc, "dvd", block_dev );
2615 config_PutPsz( p_vlc, "vcd", block_dev );
2616 config_PutPsz( p_vlc, "cd-audio", block_dev );
2618 libhal_free_string( block_dev );
2620 hal_free_string( block_dev );
2624 libhal_free_string_array( devices );
2626 hal_free_string_array( devices );
2631 libhal_ctx_shutdown( ctx, NULL );
2633 hal_shutdown( ctx );
2638 msg_Warn( p_vlc, "Unable to get HAL device properties" );