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;
425 if( ( i_pid = fork() ) < 0 )
427 msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
432 /* This is the parent, exit right now */
433 msg_Dbg( p_vlc, "closing parent process" );
435 i_ret = VLC_EEXITSUCCESS;
439 /* We are the child */
440 msg_Dbg( p_vlc, "daemon spawned" );
441 close( STDIN_FILENO );
442 close( STDOUT_FILENO );
443 close( STDERR_FILENO );
445 p_vlc->p_libvlc->b_daemon = VLC_TRUE;
453 config_Free( p_help_module );
454 vlc_object_destroy( p_help_module );
455 module_EndBank( p_vlc );
456 if( i_object ) vlc_object_release( p_vlc );
460 /* Check for translation config option */
461 #if defined( ENABLE_NLS ) \
462 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
463 # if defined (WIN32) || defined (__APPLE__)
464 /* This ain't really nice to have to reload the config here but it seems
465 * the only way to do it. */
466 config_LoadConfigFile( p_vlc, "main" );
467 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
469 /* Check if the user specified a custom language */
470 psz_language = config_GetPsz( p_vlc, "language" );
471 if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
473 vlc_bool_t b_cache_delete = libvlc.p_module_bank->b_cache_delete;
475 /* Reset the default domain */
476 SetLanguage( psz_language );
478 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
479 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
481 module_EndBank( p_vlc );
482 module_InitBank( p_vlc );
483 config_LoadConfigFile( p_vlc, "main" );
484 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
485 libvlc.p_module_bank->b_cache_delete = b_cache_delete;
487 if( psz_language ) free( psz_language );
492 * Load the builtins and plugins into the module_bank.
493 * We have to do it before config_Load*() because this also gets the
494 * list of configuration options exported by each module and loads their
497 module_LoadBuiltins( p_vlc );
498 module_LoadPlugins( p_vlc );
504 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
505 libvlc.p_module_bank->i_children );
507 /* Hack: insert the help module here */
508 vlc_object_attach( p_help_module, libvlc.p_module_bank );
511 /* Check for help on modules */
512 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
514 Help( p_vlc, p_tmp );
517 i_ret = VLC_EEXITSUCCESS;
519 /* Check for long help option */
520 else if( config_GetInt( p_vlc, "longhelp" ) )
522 Help( p_vlc, "longhelp" );
524 i_ret = VLC_EEXITSUCCESS;
526 /* Check for module list option */
527 else if( config_GetInt( p_vlc, "list" ) )
529 ListModules( p_vlc );
531 i_ret = VLC_EEXITSUCCESS;
534 /* Check for config file options */
535 if( config_GetInt( p_vlc, "reset-config" ) )
537 vlc_object_detach( p_help_module );
538 config_ResetAll( p_vlc );
539 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
540 config_SaveConfigFile( p_vlc, NULL );
541 vlc_object_attach( p_help_module, libvlc.p_module_bank );
543 if( config_GetInt( p_vlc, "save-config" ) )
545 vlc_object_detach( p_help_module );
546 config_LoadConfigFile( p_vlc, NULL );
547 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
548 config_SaveConfigFile( p_vlc, NULL );
549 vlc_object_attach( p_help_module, libvlc.p_module_bank );
552 /* Hack: remove the help module here */
553 vlc_object_detach( p_help_module );
558 config_Free( p_help_module );
559 vlc_object_destroy( p_help_module );
560 module_EndBank( p_vlc );
561 if( i_object ) vlc_object_release( p_vlc );
568 InitDeviceValues( p_vlc );
571 * Override default configuration with config file settings
573 config_LoadConfigFile( p_vlc, NULL );
575 /* Hack: insert the help module here */
576 vlc_object_attach( p_help_module, libvlc.p_module_bank );
580 * Override configuration with command line settings
582 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
585 ShowConsole( VLC_FALSE );
586 /* Pause the console because it's destroyed when we exit */
587 fprintf( stderr, "The command line options couldn't be loaded, check "
588 "that they are valid.\n" );
591 vlc_object_detach( p_help_module );
592 config_Free( p_help_module );
593 vlc_object_destroy( p_help_module );
594 module_EndBank( p_vlc );
595 if( i_object ) vlc_object_release( p_vlc );
599 /* Hack: remove the help module here */
600 vlc_object_detach( p_help_module );
601 config_Free( p_help_module );
602 vlc_object_destroy( p_help_module );
606 * System specific configuration
608 system_Configure( p_vlc, &i_argc, ppsz_argv );
611 * Message queue options
614 var_Create( p_vlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
615 if( config_GetInt( p_vlc, "quiet" ) )
618 var_Set( p_vlc, "verbose", val );
620 var_AddCallback( p_vlc, "verbose", VerboseCallback, NULL );
621 var_Change( p_vlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
623 libvlc.b_color = libvlc.b_color && config_GetInt( p_vlc, "color" );
626 * Output messages that may still be in the queue
630 /* p_vlc initialization. FIXME ? */
632 if( !config_GetInt( p_vlc, "fpu" ) )
633 libvlc.i_cpu &= ~CPU_CAPABILITY_FPU;
635 #if defined( __i386__ ) || defined( __x86_64__ )
636 if( !config_GetInt( p_vlc, "mmx" ) )
637 libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
638 if( !config_GetInt( p_vlc, "3dn" ) )
639 libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
640 if( !config_GetInt( p_vlc, "mmxext" ) )
641 libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
642 if( !config_GetInt( p_vlc, "sse" ) )
643 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
644 if( !config_GetInt( p_vlc, "sse2" ) )
645 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE2;
647 #if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
648 if( !config_GetInt( p_vlc, "altivec" ) )
649 libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
652 #define PRINT_CAPABILITY( capability, string ) \
653 if( libvlc.i_cpu & capability ) \
655 strncat( p_capabilities, string " ", \
656 sizeof(p_capabilities) - strlen(p_capabilities) ); \
657 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
660 p_capabilities[0] = '\0';
661 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
662 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
663 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
664 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
665 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
666 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
667 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
668 PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" );
669 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
670 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
671 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
674 * Choose the best memcpy module
676 p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy", 0 );
678 if( p_vlc->pf_memcpy == NULL )
680 p_vlc->pf_memcpy = memcpy;
683 if( p_vlc->pf_memset == NULL )
685 p_vlc->pf_memset = memset;
688 libvlc.b_stats = config_GetInt( p_vlc, "stats" );
689 libvlc.p_stats = NULL;
692 * Initialize hotkey handling
694 var_Create( p_vlc, "key-pressed", VLC_VAR_INTEGER );
695 p_vlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
696 /* Do a copy (we don't need to modify the strings) */
697 memcpy( p_vlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
700 * Initialize playlist and get commandline files
702 p_playlist = playlist_ThreadCreate( p_vlc );
705 msg_Err( p_vlc, "playlist initialization failed" );
706 if( p_vlc->p_memcpy_module != NULL )
708 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
710 module_EndBank( p_vlc );
711 if( i_object ) vlc_object_release( p_vlc );
715 psz_modules = config_GetPsz( p_playlist, "services-discovery" );
716 if( psz_modules && *psz_modules )
718 /* Add service discovery modules */
719 playlist_AddSDModules( p_playlist, psz_modules );
721 if( psz_modules ) free( psz_modules );
724 * Load background interfaces
726 psz_modules = config_GetPsz( p_vlc, "extraintf" );
727 psz_control = config_GetPsz( p_vlc, "control" );
729 if( psz_modules && *psz_modules && psz_control && *psz_control )
731 psz_modules = (char *)realloc( psz_modules, strlen( psz_modules ) +
732 strlen( psz_control ) + 1 );
733 sprintf( psz_modules, "%s:%s", psz_modules, psz_control );
735 else if( psz_control && *psz_control )
737 if( psz_modules ) free( psz_modules );
738 psz_modules = strdup( psz_control );
741 psz_parser = psz_modules;
742 while ( psz_parser && *psz_parser )
744 char *psz_module, *psz_temp;
745 psz_module = psz_parser;
746 psz_parser = strchr( psz_module, ':' );
752 psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
755 sprintf( psz_temp, "%s,none", psz_module );
756 VLC_AddIntf( 0, psz_temp, VLC_FALSE, VLC_FALSE );
766 * Always load the hotkeys interface if it exists
768 VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
771 * If needed, load the Xscreensaver interface
772 * Currently, only for X
774 #ifdef HAVE_X11_XLIB_H
775 if( config_GetInt( p_vlc, "disable-screensaver" ) == 1 )
777 VLC_AddIntf( 0, "screensaver,none", VLC_FALSE, VLC_FALSE );
781 if( config_GetInt( p_vlc, "file-logging" ) == 1 )
783 VLC_AddIntf( 0, "logger,none", VLC_FALSE, VLC_FALSE );
786 if( config_GetInt( p_vlc, "syslog" ) == 1 )
788 char *psz_logmode = "logmode=syslog";
789 AddIntfInternal( 0, "logger,none", VLC_FALSE, VLC_FALSE, 1, &psz_logmode );
793 if( config_GetInt( p_vlc, "show-intf" ) == 1 )
795 VLC_AddIntf( 0, "showintf,none", VLC_FALSE, VLC_FALSE );
798 if( config_GetInt( p_vlc, "network-synchronisation") == 1 )
800 VLC_AddIntf( 0, "netsync,none", VLC_FALSE, VLC_FALSE );
804 * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
806 var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
807 var_Create( p_vlc, "drawableredraw", VLC_VAR_INTEGER );
808 var_Create( p_vlc, "drawablet", VLC_VAR_INTEGER );
809 var_Create( p_vlc, "drawablel", VLC_VAR_INTEGER );
810 var_Create( p_vlc, "drawableb", VLC_VAR_INTEGER );
811 var_Create( p_vlc, "drawabler", VLC_VAR_INTEGER );
812 var_Create( p_vlc, "drawablex", VLC_VAR_INTEGER );
813 var_Create( p_vlc, "drawabley", VLC_VAR_INTEGER );
814 var_Create( p_vlc, "drawablew", VLC_VAR_INTEGER );
815 var_Create( p_vlc, "drawableh", VLC_VAR_INTEGER );
816 var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER );
817 var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER );
819 /* Create volume callback system. */
820 var_Create( p_vlc, "volume-change", VLC_VAR_BOOL );
823 * Get input filenames given as commandline arguments
825 GetFilenames( p_vlc, i_argc, ppsz_argv );
828 * Get --open argument
830 var_Create( p_vlc, "open", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
831 var_Get( p_vlc, "open", &val );
832 if ( val.psz_string != NULL && *val.psz_string )
834 VLC_AddTarget( p_vlc->i_object_id, val.psz_string, NULL, 0,
835 PLAYLIST_INSERT, 0 );
837 if ( val.psz_string != NULL ) free( val.psz_string );
839 if( i_object ) vlc_object_release( p_vlc );
843 /*****************************************************************************
844 * VLC_AddIntf: add an interface
845 *****************************************************************************
846 * This function opens an interface plugin and runs it. If b_block is set
847 * to 0, VLC_AddIntf will return immediately and let the interface run in a
848 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
849 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
850 * the playlist when it is completely initialised.
851 *****************************************************************************/
852 int VLC_AddIntf( int i_object, char const *psz_module,
853 vlc_bool_t b_block, vlc_bool_t b_play )
855 return AddIntfInternal( i_object, psz_module, b_block, b_play, 0, NULL );
859 /*****************************************************************************
860 * VLC_Die: ask vlc to die.
861 *****************************************************************************
862 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
863 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
864 *****************************************************************************/
865 int VLC_Die( int i_object )
867 vlc_t *p_vlc = vlc_current_object( i_object );
874 p_vlc->b_die = VLC_TRUE;
876 if( i_object ) vlc_object_release( p_vlc );
880 /*****************************************************************************
881 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
882 *****************************************************************************/
883 int VLC_CleanUp( int i_object )
885 intf_thread_t * p_intf;
886 playlist_t * p_playlist;
887 vout_thread_t * p_vout;
888 aout_instance_t * p_aout;
889 announce_handler_t * p_announce;
890 stats_handler_t * p_stats;
891 vlc_t *p_vlc = vlc_current_object( i_object );
893 /* Check that the handle is valid */
900 * Ask the interfaces to stop and destroy them
902 msg_Dbg( p_vlc, "removing all interfaces" );
903 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
905 intf_StopThread( p_intf );
906 vlc_object_detach( p_intf );
907 vlc_object_release( p_intf );
908 intf_Destroy( p_intf );
914 msg_Dbg( p_vlc, "removing playlist handler" );
915 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
918 vlc_object_detach( p_playlist );
919 vlc_object_release( p_playlist );
920 playlist_ThreadDestroy( p_playlist );
926 msg_Dbg( p_vlc, "removing all video outputs" );
927 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
929 vlc_object_detach( p_vout );
930 vlc_object_release( p_vout );
931 vout_Destroy( p_vout );
937 msg_Dbg( p_vlc, "removing all audio outputs" );
938 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
940 vlc_object_detach( (vlc_object_t *)p_aout );
941 vlc_object_release( (vlc_object_t *)p_aout );
942 aout_Delete( p_aout );
945 while( ( p_stats = vlc_object_find( p_vlc, VLC_OBJECT_STATS, FIND_CHILD) ))
947 stats_TimersDumpAll( p_vlc );
948 stats_HandlerDestroy( p_stats );
949 vlc_object_detach( (vlc_object_t*) p_stats );
950 vlc_object_release( (vlc_object_t *)p_stats );
955 * Free announce handler(s?)
957 while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE,
960 msg_Dbg( p_vlc, "removing announce handler" );
961 vlc_object_detach( p_announce );
962 vlc_object_release( p_announce );
963 announce_HandlerDestroy( p_announce );
966 if( i_object ) vlc_object_release( p_vlc );
970 /*****************************************************************************
971 * VLC_Destroy: Destroy everything.
972 *****************************************************************************
973 * This function requests the running threads to finish, waits for their
974 * termination, and destroys their structure.
975 *****************************************************************************/
976 int VLC_Destroy( int i_object )
978 vlc_t *p_vlc = vlc_current_object( i_object );
986 * Free allocated memory
988 if( p_vlc->p_memcpy_module )
990 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
991 p_vlc->p_memcpy_module = NULL;
997 module_EndBank( p_vlc );
999 if( p_vlc->psz_homedir )
1001 free( p_vlc->psz_homedir );
1002 p_vlc->psz_homedir = NULL;
1005 if( p_vlc->psz_userdir )
1007 free( p_vlc->psz_userdir );
1008 p_vlc->psz_userdir = NULL;
1011 if( p_vlc->psz_configfile )
1013 free( p_vlc->psz_configfile );
1014 p_vlc->psz_configfile = NULL;
1017 if( p_vlc->p_hotkeys )
1019 free( p_vlc->p_hotkeys );
1020 p_vlc->p_hotkeys = NULL;
1024 * System specific cleaning code
1026 system_End( p_vlc );
1029 * Free message queue.
1030 * Nobody shall use msg_* afterward.
1033 msg_Destroy( p_libvlc );
1035 /* Destroy global iconv */
1038 /* Destroy mutexes */
1039 vlc_mutex_destroy( &p_vlc->config_lock );
1041 vlc_object_detach( p_vlc );
1043 /* Release object before destroying it */
1044 if( i_object ) vlc_object_release( p_vlc );
1046 vlc_object_destroy( p_vlc );
1048 /* Stop thread system: last one out please shut the door! */
1049 vlc_threads_end( p_libvlc );
1054 /*****************************************************************************
1055 * VLC_VariableSet: set a vlc variable
1056 *****************************************************************************/
1057 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
1059 vlc_t *p_vlc = vlc_current_object( i_object );
1067 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
1068 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
1069 if( !strncmp( psz_var, "conf::", 6 ) )
1071 module_config_t *p_item;
1072 char const *psz_newvar = psz_var + 6;
1074 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
1078 switch( p_item->i_type )
1080 case CONFIG_ITEM_BOOL:
1081 config_PutInt( p_vlc, psz_newvar, value.b_bool );
1083 case CONFIG_ITEM_INTEGER:
1084 config_PutInt( p_vlc, psz_newvar, value.i_int );
1086 case CONFIG_ITEM_FLOAT:
1087 config_PutFloat( p_vlc, psz_newvar, value.f_float );
1090 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
1093 if( i_object ) vlc_object_release( p_vlc );
1098 i_ret = var_Set( p_vlc, psz_var, value );
1100 if( i_object ) vlc_object_release( p_vlc );
1104 /*****************************************************************************
1105 * VLC_VariableGet: get a vlc variable
1106 *****************************************************************************/
1107 int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
1109 vlc_t *p_vlc = vlc_current_object( i_object );
1117 i_ret = var_Get( p_vlc , psz_var, p_value );
1119 if( i_object ) vlc_object_release( p_vlc );
1123 /*****************************************************************************
1124 * VLC_VariableType: get a vlc variable type
1125 *****************************************************************************/
1126 int VLC_VariableType( int i_object, char const *psz_var, int *pi_type )
1129 vlc_t *p_vlc = vlc_current_object( i_object );
1136 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
1137 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
1138 if( !strncmp( psz_var, "conf::", 6 ) )
1140 module_config_t *p_item;
1141 char const *psz_newvar = psz_var + 6;
1143 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
1147 switch( p_item->i_type )
1149 case CONFIG_ITEM_BOOL:
1150 i_type = VLC_VAR_BOOL;
1152 case CONFIG_ITEM_INTEGER:
1153 i_type = VLC_VAR_INTEGER;
1155 case CONFIG_ITEM_FLOAT:
1156 i_type = VLC_VAR_FLOAT;
1159 i_type = VLC_VAR_STRING;
1167 i_type = VLC_VAR_TYPE & var_Type( p_vlc , psz_var );
1169 if( i_object ) vlc_object_release( p_vlc );
1179 /*****************************************************************************
1180 * VLC_AddTarget: adds a target for playing.
1181 *****************************************************************************
1182 * This function adds psz_target to the current playlist. If a playlist does
1183 * not exist, it will create one.
1184 *****************************************************************************/
1185 int VLC_AddTarget( int i_object, char const *psz_target,
1186 char const **ppsz_options, int i_options,
1187 int i_mode, int i_pos )
1190 playlist_t *p_playlist;
1191 vlc_t *p_vlc = vlc_current_object( i_object );
1198 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1200 if( p_playlist == NULL )
1202 msg_Dbg( p_vlc, "no playlist present, creating one" );
1203 p_playlist = playlist_ThreadCreate( p_vlc );
1205 if( p_playlist == NULL )
1207 if( i_object ) vlc_object_release( p_vlc );
1208 return VLC_EGENERIC;
1211 vlc_object_yield( p_playlist );
1214 i_err = playlist_PlaylistAddExt( p_playlist, psz_target, psz_target,
1215 i_mode, i_pos, -1, ppsz_options, i_options);
1217 vlc_object_release( p_playlist );
1219 if( i_object ) vlc_object_release( p_vlc );
1223 /*****************************************************************************
1224 * VLC_Play: play the playlist
1225 *****************************************************************************/
1226 int VLC_Play( int i_object )
1228 playlist_t * p_playlist;
1229 vlc_t *p_vlc = vlc_current_object( i_object );
1231 /* Check that the handle is valid */
1237 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1241 if( i_object ) vlc_object_release( p_vlc );
1245 playlist_Play( p_playlist );
1246 vlc_object_release( p_playlist );
1248 if( i_object ) vlc_object_release( p_vlc );
1252 /*****************************************************************************
1253 * VLC_Pause: toggle pause
1254 *****************************************************************************/
1255 int VLC_Pause( int i_object )
1257 playlist_t * p_playlist;
1258 vlc_t *p_vlc = vlc_current_object( i_object );
1260 /* Check that the handle is valid */
1266 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1270 if( i_object ) vlc_object_release( p_vlc );
1274 playlist_Pause( p_playlist );
1275 vlc_object_release( p_playlist );
1277 if( i_object ) vlc_object_release( p_vlc );
1281 /*****************************************************************************
1282 * VLC_Pause: toggle pause
1283 *****************************************************************************/
1284 int VLC_Stop( int i_object )
1286 playlist_t * p_playlist;
1287 vlc_t *p_vlc = vlc_current_object( i_object );
1289 /* Check that the handle is valid */
1295 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1299 if( i_object ) vlc_object_release( p_vlc );
1303 playlist_Stop( p_playlist );
1304 vlc_object_release( p_playlist );
1306 if( i_object ) vlc_object_release( p_vlc );
1310 /*****************************************************************************
1311 * VLC_IsPlaying: Query for Playlist Status
1312 *****************************************************************************/
1313 vlc_bool_t VLC_IsPlaying( int i_object )
1315 playlist_t * p_playlist;
1316 vlc_bool_t b_playing;
1318 vlc_t *p_vlc = vlc_current_object( i_object );
1320 /* Check that the handle is valid */
1326 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1330 if( i_object ) vlc_object_release( p_vlc );
1334 if( p_playlist->p_input )
1337 var_Get( p_playlist->p_input, "state", &val );
1338 b_playing = ( val.i_int == PLAYING_S );
1342 b_playing = playlist_IsPlaying( p_playlist );
1344 vlc_object_release( p_playlist );
1346 if( i_object ) vlc_object_release( p_vlc );
1351 * Get the current position in a input
1353 * Return the current position as a float
1354 * \note For some inputs, this will be unknown.
1356 * \param i_object a vlc object id
1357 * \return a float in the range of 0.0 - 1.0
1359 float VLC_PositionGet( int i_object )
1361 input_thread_t *p_input;
1363 vlc_t *p_vlc = vlc_current_object( i_object );
1365 /* Check that the handle is valid */
1371 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1375 if( i_object ) vlc_object_release( p_vlc );
1379 var_Get( p_input, "position", &val );
1380 vlc_object_release( p_input );
1382 if( i_object ) vlc_object_release( p_vlc );
1387 * Set the current position in a input
1389 * Set the current position in a input and then return
1390 * the current position as a float.
1391 * \note For some inputs, this will be unknown.
1393 * \param i_object a vlc object id
1394 * \param i_position a float in the range of 0.0 - 1.0
1395 * \return a float in the range of 0.0 - 1.0
1397 float VLC_PositionSet( int i_object, float i_position )
1399 input_thread_t *p_input;
1401 vlc_t *p_vlc = vlc_current_object( i_object );
1403 /* Check that the handle is valid */
1409 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1413 if( i_object ) vlc_object_release( p_vlc );
1417 val.f_float = i_position;
1418 var_Set( p_input, "position", val );
1419 var_Get( p_input, "position", &val );
1420 vlc_object_release( p_input );
1422 if( i_object ) vlc_object_release( p_vlc );
1427 * Get the current position in a input
1429 * Return the current position in seconds from the start.
1430 * \note For some inputs, this will be unknown.
1432 * \param i_object a vlc object id
1433 * \return the offset from 0:00 in seconds
1435 int VLC_TimeGet( int i_object )
1437 input_thread_t *p_input;
1439 vlc_t *p_vlc = vlc_current_object( i_object );
1441 /* Check that the handle is valid */
1447 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1451 if( i_object ) vlc_object_release( p_vlc );
1455 var_Get( p_input, "time", &val );
1456 vlc_object_release( p_input );
1458 if( i_object ) vlc_object_release( p_vlc );
1459 return val.i_time / 1000000;
1463 * Seek to a position in the current input
1465 * Seek i_seconds in the current input. If b_relative is set,
1466 * then the seek will be relative to the current position, otherwise
1467 * it will seek to i_seconds from the beginning of the input.
1468 * \note For some inputs, this will be unknown.
1470 * \param i_object a vlc object id
1471 * \param i_seconds seconds from current position or from beginning of input
1472 * \param b_relative seek relative from current position
1473 * \return VLC_SUCCESS on success
1475 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
1477 input_thread_t *p_input;
1479 vlc_t *p_vlc = vlc_current_object( i_object );
1481 /* Check that the handle is valid */
1487 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1491 if( i_object ) vlc_object_release( p_vlc );
1497 val.i_time = i_seconds;
1498 val.i_time = val.i_time * 1000000L;
1499 var_Set( p_input, "time-offset", val );
1503 val.i_time = i_seconds;
1504 val.i_time = val.i_time * 1000000L;
1505 var_Set( p_input, "time", val );
1507 vlc_object_release( p_input );
1509 if( i_object ) vlc_object_release( p_vlc );
1514 * Get the total length of a input
1516 * Return the total length in seconds from the current input.
1517 * \note For some inputs, this will be unknown.
1519 * \param i_object a vlc object id
1520 * \return the length in seconds
1522 int VLC_LengthGet( int i_object )
1524 input_thread_t *p_input;
1526 vlc_t *p_vlc = vlc_current_object( i_object );
1528 /* Check that the handle is valid */
1534 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1538 if( i_object ) vlc_object_release( p_vlc );
1542 var_Get( p_input, "length", &val );
1543 vlc_object_release( p_input );
1545 if( i_object ) vlc_object_release( p_vlc );
1546 return val.i_time / 1000000L;
1550 * Play the input faster than realtime
1552 * 2x, 4x, 8x faster than realtime
1553 * \note For some inputs, this will be impossible.
1555 * \param i_object a vlc object id
1556 * \return the current speedrate
1558 float VLC_SpeedFaster( int i_object )
1560 input_thread_t *p_input;
1562 vlc_t *p_vlc = vlc_current_object( i_object );
1564 /* Check that the handle is valid */
1570 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1574 if( i_object ) vlc_object_release( p_vlc );
1578 val.b_bool = VLC_TRUE;
1579 var_Set( p_input, "rate-faster", val );
1580 var_Get( p_input, "rate", &val );
1581 vlc_object_release( p_input );
1583 if( i_object ) vlc_object_release( p_vlc );
1584 return val.f_float / INPUT_RATE_DEFAULT;
1588 * Play the input slower than realtime
1590 * 1/2x, 1/4x, 1/8x slower than realtime
1591 * \note For some inputs, this will be impossible.
1593 * \param i_object a vlc object id
1594 * \return the current speedrate
1596 float VLC_SpeedSlower( int i_object )
1598 input_thread_t *p_input;
1600 vlc_t *p_vlc = vlc_current_object( i_object );
1602 /* Check that the handle is valid */
1608 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1612 if( i_object ) vlc_object_release( p_vlc );
1616 val.b_bool = VLC_TRUE;
1617 var_Set( p_input, "rate-slower", val );
1618 var_Get( p_input, "rate", &val );
1619 vlc_object_release( p_input );
1621 if( i_object ) vlc_object_release( p_vlc );
1622 return val.f_float / INPUT_RATE_DEFAULT;
1626 * Return the current playlist item
1628 * Returns the index of the playlistitem that is currently selected for play.
1629 * This is valid even if nothing is currently playing.
1631 * \param i_object a vlc object id
1632 * \return the current index
1634 int VLC_PlaylistIndex( int i_object )
1636 printf( "This function is deprecated and should not be used anymore" );
1641 * Total amount of items in the playlist
1643 * \param i_object a vlc object id
1644 * \return amount of playlist items
1646 int VLC_PlaylistNumberOfItems( int i_object )
1649 playlist_t * p_playlist;
1650 vlc_t *p_vlc = vlc_current_object( i_object );
1652 /* Check that the handle is valid */
1658 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1662 if( i_object ) vlc_object_release( p_vlc );
1666 i_size = p_playlist->i_size;
1667 vlc_object_release( p_playlist );
1669 if( i_object ) vlc_object_release( p_vlc );
1674 * Next playlist item
1676 * Skip to the next playlistitem and play it.
1678 * \param i_object a vlc object id
1679 * \return VLC_SUCCESS on success
1681 int VLC_PlaylistNext( int i_object )
1683 playlist_t * p_playlist;
1684 vlc_t *p_vlc = vlc_current_object( i_object );
1686 /* Check that the handle is valid */
1692 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1696 if( i_object ) vlc_object_release( p_vlc );
1700 playlist_Next( p_playlist );
1701 vlc_object_release( p_playlist );
1703 if( i_object ) vlc_object_release( p_vlc );
1708 * Previous playlist item
1710 * Skip to the previous playlistitem and play it.
1712 * \param i_object a vlc object id
1713 * \return VLC_SUCCESS on success
1715 int VLC_PlaylistPrev( int i_object )
1717 playlist_t * p_playlist;
1718 vlc_t *p_vlc = vlc_current_object( i_object );
1720 /* Check that the handle is valid */
1726 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1730 if( i_object ) vlc_object_release( p_vlc );
1734 playlist_Prev( p_playlist );
1735 vlc_object_release( p_playlist );
1737 if( i_object ) vlc_object_release( p_vlc );
1742 /*****************************************************************************
1743 * VLC_PlaylistClear: Empty the playlist
1744 *****************************************************************************/
1745 int VLC_PlaylistClear( int i_object )
1747 playlist_t * p_playlist;
1748 vlc_t *p_vlc = vlc_current_object( i_object );
1750 /* Check that the handle is valid */
1756 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1760 if( i_object ) vlc_object_release( p_vlc );
1764 playlist_Clear( p_playlist );
1766 vlc_object_release( p_playlist );
1768 if( i_object ) vlc_object_release( p_vlc );
1775 * \param i_object a vlc object id
1776 * \param i_volume something in a range from 0-200
1777 * \return the new volume (range 0-200 %)
1779 int VLC_VolumeSet( int i_object, int i_volume )
1781 audio_volume_t i_vol = 0;
1782 vlc_t *p_vlc = vlc_current_object( i_object );
1784 /* Check that the handle is valid */
1790 if( i_volume >= 0 && i_volume <= 200 )
1792 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
1793 aout_VolumeSet( p_vlc, i_vol );
1796 if( i_object ) vlc_object_release( p_vlc );
1797 return i_vol * 200 / AOUT_VOLUME_MAX;
1801 * Get the current volume
1803 * Retrieve the current volume.
1805 * \param i_object a vlc object id
1806 * \return the current volume (range 0-200 %)
1808 int VLC_VolumeGet( int i_object )
1810 audio_volume_t i_volume;
1811 vlc_t *p_vlc = vlc_current_object( i_object );
1813 /* Check that the handle is valid */
1819 aout_VolumeGet( p_vlc, &i_volume );
1821 if( i_object ) vlc_object_release( p_vlc );
1822 return i_volume*200/AOUT_VOLUME_MAX;
1826 * Mute/Unmute the volume
1828 * \param i_object a vlc object id
1829 * \return VLC_SUCCESS on success
1831 int VLC_VolumeMute( int i_object )
1833 vlc_t *p_vlc = vlc_current_object( i_object );
1835 /* Check that the handle is valid */
1841 aout_VolumeMute( p_vlc, NULL );
1843 if( i_object ) vlc_object_release( p_vlc );
1847 /*****************************************************************************
1848 * VLC_FullScreen: toggle fullscreen mode
1849 *****************************************************************************/
1850 int VLC_FullScreen( int i_object )
1852 vout_thread_t *p_vout;
1853 vlc_t *p_vlc = vlc_current_object( i_object );
1860 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
1864 if( i_object ) vlc_object_release( p_vlc );
1868 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1869 vlc_object_release( p_vout );
1871 if( i_object ) vlc_object_release( p_vlc );
1875 /* following functions are local */
1878 static int AddIntfInternal( int i_object, char const *psz_module,
1879 vlc_bool_t b_block, vlc_bool_t b_play,
1880 int i_options, char **ppsz_options )
1883 intf_thread_t *p_intf;
1884 vlc_t *p_vlc = vlc_current_object( i_object );
1892 if( p_vlc->p_libvlc->b_daemon && b_block && !psz_module )
1894 /* Daemon mode hack.
1895 * We prefer the dummy interface if none is specified. */
1896 char *psz_interface = config_GetPsz( p_vlc, "intf" );
1897 if( !psz_interface || !*psz_interface ) psz_module = "dummy";
1898 if( psz_interface ) free( psz_interface );
1902 /* Try to create the interface */
1903 p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf",
1904 i_options, ppsz_options );
1906 if( p_intf == NULL )
1908 msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
1909 if( i_object ) vlc_object_release( p_vlc );
1910 return VLC_EGENERIC;
1913 /* Interface doesn't handle play on start so do it ourselves */
1914 if( !p_intf->b_play && b_play ) VLC_Play( i_object );
1916 /* Try to run the interface */
1917 p_intf->b_play = b_play;
1918 p_intf->b_block = b_block;
1919 i_err = intf_RunThread( p_intf );
1922 vlc_object_detach( p_intf );
1923 intf_Destroy( p_intf );
1924 if( i_object ) vlc_object_release( p_vlc );
1928 if( i_object ) vlc_object_release( p_vlc );
1933 /*****************************************************************************
1934 * SetLanguage: set the interface language.
1935 *****************************************************************************
1936 * We set the LC_MESSAGES locale category for interface messages and buttons,
1937 * as well as the LC_CTYPE category for string sorting and possible wide
1938 * character support.
1939 *****************************************************************************/
1940 static void SetLanguage ( char const *psz_lang )
1942 #if defined( ENABLE_NLS ) \
1943 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
1946 #if defined( __APPLE__ ) || defined ( WIN32 ) || defined( SYS_BEOS )
1950 if( psz_lang && !*psz_lang )
1952 # if defined( HAVE_LC_MESSAGES )
1953 setlocale( LC_MESSAGES, psz_lang );
1955 setlocale( LC_CTYPE, psz_lang );
1960 /* I need that under Darwin, please check it doesn't disturb
1961 * other platforms. --Meuuh */
1962 setenv( "LANG", psz_lang, 1 );
1964 #elif defined( SYS_BEOS ) || defined( WIN32 )
1965 /* We set LC_ALL manually because it is the only way to set
1966 * the language at runtime under eg. Windows. Beware that this
1967 * makes the environment unconsistent when libvlc is unloaded and
1968 * should probably be moved to a safer place like vlc.c. */
1969 static char psz_lcall[20];
1970 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
1971 psz_lcall[19] = '\0';
1972 putenv( psz_lcall );
1975 setlocale( LC_ALL, psz_lang );
1978 /* Specify where to find the locales for current domain */
1979 #if !defined( __APPLE__ ) && !defined( WIN32 ) && !defined( SYS_BEOS )
1980 psz_path = LOCALEDIR;
1982 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
1986 if( !bindtextdomain( PACKAGE_NAME, psz_path ) )
1988 fprintf( stderr, "warning: couldn't bind domain %s in directory %s\n",
1989 PACKAGE_NAME, psz_path );
1992 /* Set the default domain */
1993 bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
1997 /*****************************************************************************
1998 * GetFilenames: parse command line options which are not flags
1999 *****************************************************************************
2000 * Parse command line for input files as well as their associated options.
2001 * An option always follows its associated input and begins with a ":".
2002 *****************************************************************************/
2003 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
2005 int i_opt, i_options;
2007 /* We assume that the remaining parameters are filenames
2008 * and their input options */
2009 for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
2011 const char *psz_target;
2014 /* Count the input options */
2015 while( *ppsz_argv[ i_opt ] == ':' && i_opt > optind )
2021 /* TODO: write an internal function of this one, to avoid
2022 * unnecessary lookups. */
2023 /* FIXME: should we convert options to UTF-8 as well ?? */
2024 psz_target = FromLocale( ppsz_argv[ i_opt ] );
2025 VLC_AddTarget( p_vlc->i_object_id, psz_target,
2026 (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
2028 PLAYLIST_INSERT, 0 );
2029 LocaleFree( psz_target );
2035 /*****************************************************************************
2036 * Help: print program help
2037 *****************************************************************************
2038 * Print a short inline help. Message interface is initialized at this stage.
2039 *****************************************************************************/
2040 static void Help( vlc_t *p_this, char const *psz_help_name )
2043 ShowConsole( VLC_TRUE );
2046 if( psz_help_name && !strcmp( psz_help_name, "help" ) )
2048 utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
2049 Usage( p_this, "help" );
2050 Usage( p_this, "main" );
2052 else if( psz_help_name && !strcmp( psz_help_name, "longhelp" ) )
2054 utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
2055 Usage( p_this, NULL );
2057 else if( psz_help_name )
2059 Usage( p_this, psz_help_name );
2062 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2067 /*****************************************************************************
2068 * Usage: print module usage
2069 *****************************************************************************
2070 * Print a short inline help. Message interface is initialized at this stage.
2071 *****************************************************************************/
2072 static void Usage( vlc_t *p_this, char const *psz_module_name )
2074 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
2075 /* short option ------' | | | | | | |
2076 * option name ------------' | | | | | |
2077 * <bra -------------------------' | | | | |
2078 * option type or "" --------------' | | | |
2079 * ket> -----------------------------' | | |
2080 * padding spaces ---------------------' | |
2081 * comment -------------------------------' |
2082 * comment suffix --------------------------'
2084 * The purpose of having bra and ket is that we might i18n them as well.
2086 #define LINE_START 8
2087 #define PADDING_SPACES 25
2090 module_config_t *p_item;
2091 char psz_spaces_text[PADDING_SPACES+LINE_START+1];
2092 char psz_spaces_longtext[LINE_START+3];
2093 char psz_format[sizeof(FORMAT_STRING)];
2094 char psz_buffer[10000];
2097 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
2098 vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" );
2099 vlc_bool_t b_description;
2101 memset( psz_spaces_text, ' ', PADDING_SPACES+LINE_START );
2102 psz_spaces_text[PADDING_SPACES+LINE_START] = '\0';
2103 memset( psz_spaces_longtext, ' ', LINE_START+2 );
2104 psz_spaces_longtext[LINE_START+2] = '\0';
2106 strcpy( psz_format, FORMAT_STRING );
2108 /* List all modules */
2109 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2111 /* Enumerate the config for each module */
2112 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2114 vlc_bool_t b_help_module;
2116 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2118 if( psz_module_name && strcmp( psz_module_name,
2119 p_parser->psz_object_name ) )
2124 /* Ignore modules without config options */
2125 if( !p_parser->i_config_items )
2130 /* Ignore modules with only advanced config options if requested */
2133 for( p_item = p_parser->p_config;
2134 p_item->i_type != CONFIG_HINT_END;
2137 if( (p_item->i_type & CONFIG_ITEM) &&
2138 !p_item->b_advanced ) break;
2140 if( p_item->i_type == CONFIG_HINT_END ) continue;
2143 /* Print name of module */
2144 if( strcmp( "main", p_parser->psz_object_name ) )
2145 utf8_fprintf( stdout, "\n %s\n", p_parser->psz_longname );
2147 b_help_module = !strcmp( "help", p_parser->psz_object_name );
2149 /* Print module options */
2150 for( p_item = p_parser->p_config;
2151 p_item->i_type != CONFIG_HINT_END;
2154 char *psz_text, *psz_spaces = psz_spaces_text;
2155 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
2156 char *psz_suf = "", *psz_prefix = NULL;
2159 /* Skip deprecated options */
2160 if( p_item->psz_current )
2164 /* Skip advanced options if requested */
2165 if( p_item->b_advanced && !b_advanced )
2170 switch( p_item->i_type )
2172 case CONFIG_HINT_CATEGORY:
2173 case CONFIG_HINT_USAGE:
2174 if( !strcmp( "main", p_parser->psz_object_name ) )
2175 utf8_fprintf( stdout, "\n %s\n", p_item->psz_text );
2178 case CONFIG_ITEM_STRING:
2179 case CONFIG_ITEM_FILE:
2180 case CONFIG_ITEM_DIRECTORY:
2181 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
2182 case CONFIG_ITEM_MODULE_CAT:
2183 case CONFIG_ITEM_MODULE_LIST:
2184 case CONFIG_ITEM_MODULE_LIST_CAT:
2185 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
2187 if( p_item->ppsz_list )
2190 psz_type = psz_buffer;
2192 for( i = 0; p_item->ppsz_list[i]; i++ )
2194 if( i ) strcat( psz_type, "," );
2195 strcat( psz_type, p_item->ppsz_list[i] );
2200 case CONFIG_ITEM_INTEGER:
2201 case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
2202 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
2204 if( p_item->i_list )
2207 psz_type = psz_buffer;
2209 for( i = 0; p_item->ppsz_list_text[i]; i++ )
2211 if( i ) strcat( psz_type, ", " );
2212 sprintf( psz_type + strlen(psz_type), "%i (%s)",
2214 p_item->ppsz_list_text[i] );
2219 case CONFIG_ITEM_FLOAT:
2220 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
2222 case CONFIG_ITEM_BOOL:
2223 psz_bra = ""; psz_type = ""; psz_ket = "";
2224 if( !b_help_module )
2226 psz_suf = p_item->i_value ? _(" (default enabled)") :
2227 _(" (default disabled)");
2237 /* Add short option if any */
2238 if( p_item->i_short )
2240 sprintf( psz_short, "-%c,", p_item->i_short );
2244 strcpy( psz_short, " " );
2247 i = PADDING_SPACES - strlen( p_item->psz_name )
2248 - strlen( psz_bra ) - strlen( psz_type )
2249 - strlen( psz_ket ) - 1;
2251 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
2253 psz_prefix = ", --no-";
2254 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
2259 psz_spaces[0] = '\n';
2264 psz_spaces[i] = '\0';
2267 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
2269 utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2270 psz_prefix, p_item->psz_name, psz_bra, psz_type,
2271 psz_ket, psz_spaces );
2275 utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2276 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
2279 psz_spaces[i] = ' ';
2281 /* We wrap the rest of the output */
2282 sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
2283 b_description = config_GetInt( p_this, "help-verbose" );
2286 psz_text = psz_buffer;
2289 char *psz_parser, *psz_word;
2290 size_t i_end = strlen( psz_text );
2292 /* If the remaining text fits in a line, print it. */
2293 if( i_end <= (size_t)i_width )
2295 utf8_fprintf( stdout, "%s\n", psz_text );
2299 /* Otherwise, eat as many words as possible */
2300 psz_parser = psz_text;
2303 psz_word = psz_parser;
2304 psz_parser = strchr( psz_word, ' ' );
2305 /* If no space was found, we reached the end of the text
2306 * block; otherwise, we skip the space we just found. */
2307 psz_parser = psz_parser ? psz_parser + 1
2310 } while( psz_parser - psz_text <= i_width );
2312 /* We cut a word in one of these cases:
2313 * - it's the only word in the line and it's too long.
2314 * - we used less than 80% of the width and the word we are
2315 * going to wrap is longer than 40% of the width, and even
2316 * if the word would have fit in the next line. */
2317 if( psz_word == psz_text
2318 || ( psz_word - psz_text < 80 * i_width / 100
2319 && psz_parser - psz_word > 40 * i_width / 100 ) )
2321 char c = psz_text[i_width];
2322 psz_text[i_width] = '\0';
2323 utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2324 psz_text += i_width;
2329 psz_word[-1] = '\0';
2330 utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2331 psz_text = psz_word;
2335 if( b_description && p_item->psz_longtext )
2337 sprintf( psz_buffer, "%s%s", p_item->psz_longtext, psz_suf );
2338 b_description = VLC_FALSE;
2339 psz_spaces = psz_spaces_longtext;
2340 utf8_fprintf( stdout, "%s", psz_spaces );
2346 /* Release the module list */
2347 vlc_list_release( p_list );
2350 /*****************************************************************************
2351 * ListModules: list the available modules with their description
2352 *****************************************************************************
2353 * Print a list of all available modules (builtins and plugins) and a short
2354 * description for each one.
2355 *****************************************************************************/
2356 static void ListModules( vlc_t *p_this )
2360 char psz_spaces[22];
2363 memset( psz_spaces, ' ', 22 );
2366 ShowConsole( VLC_TRUE );
2369 /* List all modules */
2370 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2372 /* Enumerate each module */
2373 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2377 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2379 /* Nasty hack, but right now I'm too tired to think about a nice
2381 i = 22 - strlen( p_parser->psz_object_name ) - 1;
2385 utf8_fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
2386 psz_spaces, p_parser->psz_longname );
2388 psz_spaces[i] = ' ';
2391 vlc_list_release( p_list );
2393 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2398 /*****************************************************************************
2399 * Version: print complete program version
2400 *****************************************************************************
2401 * Print complete program version and build number.
2402 *****************************************************************************/
2403 static void Version( void )
2406 ShowConsole( VLC_TRUE );
2409 utf8_fprintf( stdout, _("VLC version %s\n"), VLC_Version() );
2410 utf8_fprintf( stdout, _("Compiled by %s@%s.%s\n"),
2411 VLC_CompileBy(), VLC_CompileHost(), VLC_CompileDomain() );
2412 utf8_fprintf( stdout, _("Compiler: %s\n"), VLC_Compiler() );
2413 #ifndef HAVE_SHARED_LIBVLC
2414 if( strcmp( VLC_Changeset(), "exported" ) )
2415 utf8_fprintf( stdout, _("Based upon svn changeset [%s]\n"),
2418 utf8_fprintf( stdout, LICENSE_MSG );
2420 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2425 /*****************************************************************************
2426 * ShowConsole: On Win32, create an output console for debug messages
2427 *****************************************************************************
2428 * This function is useful only on Win32.
2429 *****************************************************************************/
2431 static void ShowConsole( vlc_bool_t b_dofile )
2436 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2440 freopen( "CONOUT$", "w", stderr );
2441 freopen( "CONIN$", "r", stdin );
2443 if( b_dofile && (f_help = fopen( "vlc-help.txt", "wt" )) )
2446 freopen( "vlc-help.txt", "wt", stdout );
2447 utf8_fprintf( stderr, _("\nDumped content to vlc-help.txt file.\n") );
2450 else freopen( "CONOUT$", "w", stdout );
2456 /*****************************************************************************
2457 * PauseConsole: On Win32, wait for a key press before closing the console
2458 *****************************************************************************
2459 * This function is useful only on Win32.
2460 *****************************************************************************/
2462 static void PauseConsole( void )
2466 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2468 utf8_fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
2476 /*****************************************************************************
2477 * ConsoleWidth: Return the console width in characters
2478 *****************************************************************************
2479 * We use the stty shell command to get the console width; if this fails or
2480 * if the width is less than 80, we default to 80.
2481 *****************************************************************************/
2482 static int ConsoleWidth( void )
2487 char buf[20], *psz_parser;
2491 file = popen( "stty size 2>/dev/null", "r" );
2494 i_ret = fread( buf, 1, 20, file );
2498 psz_parser = strchr( buf, ' ' );
2501 i_ret = atoi( psz_parser + 1 );
2516 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
2517 vlc_value_t old_val, vlc_value_t new_val, void *param)
2519 vlc_t *p_vlc = (vlc_t *)p_this;
2521 if( new_val.i_int >= -1 )
2523 p_vlc->p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );
2528 /*****************************************************************************
2529 * InitDeviceValues: initialize device values
2530 *****************************************************************************
2531 * This function inits the dvd, vcd and cd-audio values
2532 *****************************************************************************/
2533 static void InitDeviceValues( vlc_t *p_vlc )
2536 LibHalContext * ctx;
2541 DBusConnection *p_connection;
2545 ctx = libhal_ctx_new();
2547 dbus_error_init( &error );
2548 p_connection = dbus_bus_get ( DBUS_BUS_SYSTEM, &error );
2549 if( dbus_error_is_set( &error ) )
2551 dbus_error_free( &error );
2554 libhal_ctx_set_dbus_connection( ctx, p_connection );
2555 if( libhal_ctx_init( ctx, &error ) )
2557 if( ( ctx = hal_initialize( NULL, FALSE ) ) )
2561 if( ( devices = libhal_get_all_devices( ctx, &i_devices, NULL ) ) )
2563 if( ( devices = hal_get_all_devices( ctx, &i_devices ) ) )
2566 for( i = 0; i < i_devices; i++ )
2569 if( !libhal_device_property_exists( ctx, devices[i],
2570 "storage.cdrom.dvd", NULL ) )
2572 if( !hal_device_property_exists( ctx, devices[ i ],
2573 "storage.cdrom.dvd" ) )
2579 b_dvd = libhal_device_get_property_bool( ctx, devices[ i ],
2580 "storage.cdrom.dvd", NULL );
2581 block_dev = libhal_device_get_property_string( ctx,
2582 devices[ i ], "block.device" , NULL );
2584 b_dvd = hal_device_get_property_bool( ctx, devices[ i ],
2585 "storage.cdrom.dvd" );
2586 block_dev = hal_device_get_property_string( ctx, devices[ i ],
2591 config_PutPsz( p_vlc, "dvd", block_dev );
2594 config_PutPsz( p_vlc, "vcd", block_dev );
2595 config_PutPsz( p_vlc, "cd-audio", block_dev );
2597 libhal_free_string( block_dev );
2599 hal_free_string( block_dev );
2603 libhal_free_string_array( devices );
2605 hal_free_string_array( devices );
2610 libhal_ctx_shutdown( ctx, NULL );
2612 hal_shutdown( ctx );
2617 msg_Warn( p_vlc, "Unable to get HAL device properties" );