1 /*****************************************************************************
2 * libvlc.c: main libvlc source
3 *****************************************************************************
4 * Copyright (C) 1998-2004 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>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
28 * Pretend we are a builtin module
29 *****************************************************************************/
30 #define MODULE_NAME main
31 #define MODULE_PATH main
34 /*****************************************************************************
36 *****************************************************************************/
38 #include <vlc/input.h>
40 #include <errno.h> /* ENOMEM */
41 #include <stdio.h> /* sprintf() */
42 #include <string.h> /* strerror() */
43 #include <stdlib.h> /* free() */
46 # include <netinet/in.h> /* BSD: struct in_addr */
51 #elif defined( WIN32 ) && !defined( UNDER_CE )
55 #ifdef WIN32 /* optind, getopt(), included in unistd.h */
56 # include "extras/getopt.h"
64 # include <hal/libhal.h>
67 #include "vlc_cpu.h" /* CPU detection */
68 #include "os_specific.h"
70 #include "vlc_error.h"
72 #include "vlc_playlist.h"
73 #include "vlc_interface.h"
75 #include "audio_output.h"
77 #include "vlc_video.h"
78 #include "video_output.h"
80 #include "stream_output.h"
85 /*****************************************************************************
86 * The evil global variable. We handle it with care, don't worry.
87 *****************************************************************************/
88 static libvlc_t libvlc;
89 static libvlc_t * p_libvlc;
90 static vlc_t * p_static_vlc;
92 /*****************************************************************************
94 *****************************************************************************/
95 static int AddIntfInternal( int i_object, char const *psz_module,
96 vlc_bool_t b_block, vlc_bool_t b_play,
97 int i_options, char **ppsz_options );
99 static void LocaleInit( void );
100 static void LocaleDeinit( void );
101 static void SetLanguage ( char const * );
102 static int GetFilenames ( vlc_t *, int, char *[] );
103 static void Help ( vlc_t *, char const *psz_help_name );
104 static void Usage ( vlc_t *, char const *psz_module_name );
105 static void ListModules ( vlc_t * );
106 static void Version ( void );
109 static void ShowConsole ( void );
110 static void PauseConsole ( void );
112 static int ConsoleWidth ( void );
114 static int VerboseCallback( vlc_object_t *, char const *,
115 vlc_value_t, vlc_value_t, void * );
117 static void InitDeviceValues( vlc_t * );
119 /*****************************************************************************
120 * vlc_current_object: return the current object.
121 *****************************************************************************
122 * If i_object is non-zero, return the corresponding object. Otherwise,
123 * return the statically allocated p_vlc object.
124 *****************************************************************************/
125 vlc_t * vlc_current_object( int i_object )
129 return vlc_object_get( p_libvlc, i_object );
135 /*****************************************************************************
136 * VLC_Version: return the libvlc version.
137 *****************************************************************************
138 * This function returns full version string (numeric version and codename).
139 *****************************************************************************/
140 char const * VLC_Version( void )
142 return VERSION_MESSAGE;
145 /*****************************************************************************
146 * VLC_CompileBy, VLC_CompileHost, VLC_CompileDomain,
147 * VLC_Compiler, VLC_Changeset
148 *****************************************************************************/
149 #define DECLARE_VLC_VERSION( func, var ) \
150 char const * VLC_##func ( void ) \
155 DECLARE_VLC_VERSION( CompileBy, COMPILE_BY );
156 DECLARE_VLC_VERSION( CompileHost, COMPILE_HOST );
157 DECLARE_VLC_VERSION( CompileDomain, COMPILE_DOMAIN );
158 DECLARE_VLC_VERSION( Compiler, COMPILER );
160 extern const char psz_vlc_changeset[];
161 char const * VLC_Changeset( void )
163 return psz_vlc_changeset;
166 /*****************************************************************************
167 * VLC_Error: strerror() equivalent
168 *****************************************************************************
169 * This function returns full version string (numeric version and codename).
170 *****************************************************************************/
171 char const * VLC_Error( int i_err )
173 return vlc_error( i_err );
176 /*****************************************************************************
177 * VLC_Create: allocate a vlc_t structure, and initialize libvlc if needed.
178 *****************************************************************************
179 * This function allocates a vlc_t structure and returns a negative value
180 * in case of failure. Also, the thread system is initialized.
181 *****************************************************************************/
182 int VLC_Create( void )
185 vlc_t * p_vlc = NULL;
188 /* &libvlc never changes, so we can safely call this multiple times. */
191 /* vlc_threads_init *must* be the first internal call! No other call is
192 * allowed before the thread system has been initialized. */
193 i_ret = vlc_threads_init( p_libvlc );
199 /* Now that the thread system is initialized, we don't have much, but
200 * at least we have var_Create */
201 var_Create( p_libvlc, "libvlc", VLC_VAR_MUTEX );
202 var_Get( p_libvlc, "libvlc", &lockval );
203 vlc_mutex_lock( lockval.p_address );
204 if( !libvlc.b_ready )
208 /* Guess what CPU we have */
209 libvlc.i_cpu = CPUCapabilities();
211 /* Find verbosity from VLC_VERBOSE environment variable */
212 psz_env = getenv( "VLC_VERBOSE" );
213 libvlc.i_verbose = psz_env ? atoi( psz_env ) : -1;
215 #if defined( HAVE_ISATTY ) && !defined( WIN32 )
216 libvlc.b_color = isatty( 2 ); /* 2 is for stderr */
218 libvlc.b_color = VLC_FALSE;
221 /* Initialize message queue */
222 msg_Create( p_libvlc );
224 /* Announce who we are */
225 msg_Dbg( p_libvlc, COPYRIGHT_MESSAGE );
226 msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
228 /* The module bank will be initialized later */
229 libvlc.p_module_bank = NULL;
231 libvlc.b_ready = VLC_TRUE;
233 /* UTF-8 convertor are initialized after the locale */
234 libvlc.from_locale = libvlc.to_locale = (vlc_iconv_t)(-1);
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.
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 ) )
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 );
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 );
491 * Load the builtins and plugins into the module_bank.
492 * We have to do it before config_Load*() because this also gets the
493 * list of configuration options exported by each module and loads their
496 module_LoadBuiltins( p_vlc );
497 module_LoadPlugins( p_vlc );
503 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
504 libvlc.p_module_bank->i_children );
506 /* Hack: insert the help module here */
507 vlc_object_attach( p_help_module, libvlc.p_module_bank );
510 /* Check for help on modules */
511 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
513 Help( p_vlc, p_tmp );
516 i_ret = VLC_EEXITSUCCESS;
518 /* Check for long help option */
519 else if( config_GetInt( p_vlc, "longhelp" ) )
521 Help( p_vlc, "longhelp" );
523 i_ret = VLC_EEXITSUCCESS;
525 /* Check for module list option */
526 else if( config_GetInt( p_vlc, "list" ) )
528 ListModules( p_vlc );
530 i_ret = VLC_EEXITSUCCESS;
533 /* Check for config file options */
534 if( config_GetInt( p_vlc, "reset-config" ) )
536 vlc_object_detach( p_help_module );
537 config_ResetAll( p_vlc );
538 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
539 config_SaveConfigFile( p_vlc, NULL );
540 vlc_object_attach( p_help_module, libvlc.p_module_bank );
542 if( config_GetInt( p_vlc, "save-config" ) )
544 vlc_object_detach( p_help_module );
545 config_LoadConfigFile( p_vlc, NULL );
546 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
547 config_SaveConfigFile( p_vlc, NULL );
548 vlc_object_attach( p_help_module, libvlc.p_module_bank );
551 /* Hack: remove the help module here */
552 vlc_object_detach( p_help_module );
557 config_Free( p_help_module );
558 vlc_object_destroy( p_help_module );
559 module_EndBank( p_vlc );
560 if( i_object ) vlc_object_release( p_vlc );
567 InitDeviceValues( p_vlc );
570 * Override default configuration with config file settings
572 config_LoadConfigFile( p_vlc, NULL );
574 /* Hack: insert the help module here */
575 vlc_object_attach( p_help_module, libvlc.p_module_bank );
579 * Override configuration with command line settings
581 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
585 /* Pause the console because it's destroyed when we exit */
586 fprintf( stderr, "The command line options couldn't be loaded, check "
587 "that they are valid.\n" );
590 vlc_object_detach( p_help_module );
591 config_Free( p_help_module );
592 vlc_object_destroy( p_help_module );
593 module_EndBank( p_vlc );
594 if( i_object ) vlc_object_release( p_vlc );
598 /* Hack: remove the help module here */
599 vlc_object_detach( p_help_module );
600 config_Free( p_help_module );
601 vlc_object_destroy( p_help_module );
605 * System specific configuration
607 system_Configure( p_vlc, &i_argc, ppsz_argv );
610 * Message queue options
613 var_Create( p_vlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
614 if( config_GetInt( p_vlc, "quiet" ) )
617 var_Set( p_vlc, "verbose", val );
619 var_AddCallback( p_vlc, "verbose", VerboseCallback, NULL );
620 var_Change( p_vlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
622 libvlc.b_color = libvlc.b_color && config_GetInt( p_vlc, "color" );
625 * Output messages that may still be in the queue
629 /* p_vlc initialization. FIXME ? */
631 if( !config_GetInt( p_vlc, "fpu" ) )
632 libvlc.i_cpu &= ~CPU_CAPABILITY_FPU;
634 #if defined( __i386__ ) || defined( __x86_64__ )
635 if( !config_GetInt( p_vlc, "mmx" ) )
636 libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
637 if( !config_GetInt( p_vlc, "3dn" ) )
638 libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
639 if( !config_GetInt( p_vlc, "mmxext" ) )
640 libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
641 if( !config_GetInt( p_vlc, "sse" ) )
642 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
643 if( !config_GetInt( p_vlc, "sse2" ) )
644 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE2;
646 #if defined( __powerpc__ ) || defined( SYS_DARWIN )
647 if( !config_GetInt( p_vlc, "altivec" ) )
648 libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
651 #define PRINT_CAPABILITY( capability, string ) \
652 if( libvlc.i_cpu & capability ) \
654 strncat( p_capabilities, string " ", \
655 sizeof(p_capabilities) - strlen(p_capabilities) ); \
656 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
659 p_capabilities[0] = '\0';
660 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
661 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
662 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
663 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
664 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
665 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
666 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
667 PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" );
668 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
669 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
670 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
673 * Choose the best memcpy module
675 p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy", 0 );
677 if( p_vlc->pf_memcpy == NULL )
679 p_vlc->pf_memcpy = memcpy;
682 if( p_vlc->pf_memset == NULL )
684 p_vlc->pf_memset = memset;
687 libvlc.b_stats = config_GetInt( p_vlc, "stats" );
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", VLC_FALSE, VLC_FALSE );
779 if( config_GetInt( p_vlc, "file-logging" ) == 1 )
781 VLC_AddIntf( 0, "logger", VLC_FALSE, VLC_FALSE );
783 if( config_GetInt( p_vlc, "syslog" ) == 1 )
785 char *psz_logmode = "logmode=syslog";
786 AddIntfInternal( 0, "logger", VLC_FALSE, VLC_FALSE, 1, &psz_logmode );
789 if( config_GetInt( p_vlc, "show-intf" ) == 1 )
791 VLC_AddIntf( 0, "showintf", VLC_FALSE, VLC_FALSE );
794 if( config_GetInt( p_vlc, "network-synchronisation") == 1 )
796 VLC_AddIntf( 0, "netsync", VLC_FALSE, VLC_FALSE );
800 * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
802 var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
803 var_Create( p_vlc, "drawableredraw", VLC_VAR_INTEGER );
804 var_Create( p_vlc, "drawablet", VLC_VAR_INTEGER );
805 var_Create( p_vlc, "drawablel", VLC_VAR_INTEGER );
806 var_Create( p_vlc, "drawableb", VLC_VAR_INTEGER );
807 var_Create( p_vlc, "drawabler", VLC_VAR_INTEGER );
808 var_Create( p_vlc, "drawablex", VLC_VAR_INTEGER );
809 var_Create( p_vlc, "drawabley", VLC_VAR_INTEGER );
810 var_Create( p_vlc, "drawablew", VLC_VAR_INTEGER );
811 var_Create( p_vlc, "drawableh", VLC_VAR_INTEGER );
812 var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER );
813 var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER );
815 /* Create volume callback system. */
816 var_Create( p_vlc, "volume-change", VLC_VAR_BOOL );
819 * Get input filenames given as commandline arguments
821 GetFilenames( p_vlc, i_argc, ppsz_argv );
824 * Get --open argument
826 var_Create( p_vlc, "open", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
827 var_Get( p_vlc, "open", &val );
828 if ( val.psz_string != NULL && *val.psz_string )
830 VLC_AddTarget( p_vlc->i_object_id, val.psz_string, NULL, 0,
831 PLAYLIST_INSERT, 0 );
833 if ( val.psz_string != NULL ) free( val.psz_string );
835 if( i_object ) vlc_object_release( p_vlc );
839 /*****************************************************************************
840 * VLC_AddIntf: add an interface
841 *****************************************************************************
842 * This function opens an interface plugin and runs it. If b_block is set
843 * to 0, VLC_AddIntf will return immediately and let the interface run in a
844 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
845 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
846 * the playlist when it is completely initialised.
847 *****************************************************************************/
848 int VLC_AddIntf( int i_object, char const *psz_module,
849 vlc_bool_t b_block, vlc_bool_t b_play )
851 return AddIntfInternal( i_object, psz_module, b_block, b_play, 0, NULL );
855 /*****************************************************************************
856 * VLC_Die: ask vlc to die.
857 *****************************************************************************
858 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
859 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
860 *****************************************************************************/
861 int VLC_Die( int i_object )
863 vlc_t *p_vlc = vlc_current_object( i_object );
870 p_vlc->b_die = VLC_TRUE;
872 if( i_object ) vlc_object_release( p_vlc );
876 /*****************************************************************************
877 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
878 *****************************************************************************/
879 int VLC_CleanUp( int i_object )
881 intf_thread_t * p_intf;
882 playlist_t * p_playlist;
883 vout_thread_t * p_vout;
884 aout_instance_t * p_aout;
885 announce_handler_t * p_announce;
886 stats_handler_t * p_stats;
887 vlc_t *p_vlc = vlc_current_object( i_object );
889 /* Check that the handle is valid */
896 * Ask the interfaces to stop and destroy them
898 msg_Dbg( p_vlc, "removing all interfaces" );
899 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
901 intf_StopThread( p_intf );
902 vlc_object_detach( p_intf );
903 vlc_object_release( p_intf );
904 intf_Destroy( p_intf );
910 msg_Dbg( p_vlc, "removing playlist handler" );
911 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
914 vlc_object_detach( p_playlist );
915 vlc_object_release( p_playlist );
916 playlist_Destroy( p_playlist );
922 msg_Dbg( p_vlc, "removing all video outputs" );
923 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
925 vlc_object_detach( p_vout );
926 vlc_object_release( p_vout );
927 vout_Destroy( p_vout );
933 msg_Dbg( p_vlc, "removing all audio outputs" );
934 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
936 vlc_object_detach( (vlc_object_t *)p_aout );
937 vlc_object_release( (vlc_object_t *)p_aout );
938 aout_Delete( p_aout );
941 while( ( p_stats = vlc_object_find( p_vlc, VLC_OBJECT_STATS, FIND_CHILD) ))
943 stats_HandlerDestroy( p_stats );
944 vlc_object_detach( (vlc_object_t*) p_stats );
945 vlc_object_release( (vlc_object_t *)p_stats );
950 * Free announce handler(s?)
952 while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE,
955 msg_Dbg( p_vlc, "removing announce handler" );
956 vlc_object_detach( p_announce );
957 vlc_object_release( p_announce );
958 announce_HandlerDestroy( p_announce );
961 if( i_object ) vlc_object_release( p_vlc );
965 /*****************************************************************************
966 * VLC_Destroy: Destroy everything.
967 *****************************************************************************
968 * This function requests the running threads to finish, waits for their
969 * termination, and destroys their structure.
970 *****************************************************************************/
971 int VLC_Destroy( int i_object )
973 vlc_t *p_vlc = vlc_current_object( i_object );
981 * Free allocated memory
983 if( p_vlc->p_memcpy_module )
985 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
986 p_vlc->p_memcpy_module = NULL;
992 module_EndBank( p_vlc );
994 if( p_vlc->psz_homedir )
996 free( p_vlc->psz_homedir );
997 p_vlc->psz_homedir = NULL;
1000 if( p_vlc->psz_userdir )
1002 free( p_vlc->psz_userdir );
1003 p_vlc->psz_userdir = NULL;
1006 if( p_vlc->psz_configfile )
1008 free( p_vlc->psz_configfile );
1009 p_vlc->psz_configfile = NULL;
1012 if( p_vlc->p_hotkeys )
1014 free( p_vlc->p_hotkeys );
1015 p_vlc->p_hotkeys = NULL;
1019 * System specific cleaning code
1021 system_End( p_vlc );
1024 * Free message queue.
1025 * Nobody shall use msg_* afterward.
1028 msg_Destroy( p_libvlc );
1030 /* Destroy global iconv */
1033 /* Destroy mutexes */
1034 vlc_mutex_destroy( &p_vlc->config_lock );
1036 vlc_object_detach( p_vlc );
1038 /* Release object before destroying it */
1039 if( i_object ) vlc_object_release( p_vlc );
1041 vlc_object_destroy( p_vlc );
1043 /* Stop thread system: last one out please shut the door! */
1044 vlc_threads_end( p_libvlc );
1049 /*****************************************************************************
1050 * VLC_VariableSet: set a vlc variable
1051 *****************************************************************************/
1052 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
1054 vlc_t *p_vlc = vlc_current_object( i_object );
1062 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
1063 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
1064 if( !strncmp( psz_var, "conf::", 6 ) )
1066 module_config_t *p_item;
1067 char const *psz_newvar = psz_var + 6;
1069 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
1073 switch( p_item->i_type )
1075 case CONFIG_ITEM_BOOL:
1076 config_PutInt( p_vlc, psz_newvar, value.b_bool );
1078 case CONFIG_ITEM_INTEGER:
1079 config_PutInt( p_vlc, psz_newvar, value.i_int );
1081 case CONFIG_ITEM_FLOAT:
1082 config_PutFloat( p_vlc, psz_newvar, value.f_float );
1085 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
1088 if( i_object ) vlc_object_release( p_vlc );
1093 i_ret = var_Set( p_vlc, psz_var, value );
1095 if( i_object ) vlc_object_release( p_vlc );
1099 /*****************************************************************************
1100 * VLC_VariableGet: get a vlc variable
1101 *****************************************************************************/
1102 int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
1104 vlc_t *p_vlc = vlc_current_object( i_object );
1112 i_ret = var_Get( p_vlc , psz_var, p_value );
1114 if( i_object ) vlc_object_release( p_vlc );
1118 /*****************************************************************************
1119 * VLC_VariableType: get a vlc variable type
1120 *****************************************************************************/
1121 int VLC_VariableType( int i_object, char const *psz_var, int *pi_type )
1124 vlc_t *p_vlc = vlc_current_object( i_object );
1131 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
1132 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
1133 if( !strncmp( psz_var, "conf::", 6 ) )
1135 module_config_t *p_item;
1136 char const *psz_newvar = psz_var + 6;
1138 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
1142 switch( p_item->i_type )
1144 case CONFIG_ITEM_BOOL:
1145 i_type = VLC_VAR_BOOL;
1147 case CONFIG_ITEM_INTEGER:
1148 i_type = VLC_VAR_INTEGER;
1150 case CONFIG_ITEM_FLOAT:
1151 i_type = VLC_VAR_FLOAT;
1154 i_type = VLC_VAR_STRING;
1162 i_type = VLC_VAR_TYPE & var_Type( p_vlc , psz_var );
1164 if( i_object ) vlc_object_release( p_vlc );
1174 /*****************************************************************************
1175 * VLC_AddTarget: adds a target for playing.
1176 *****************************************************************************
1177 * This function adds psz_target to the current playlist. If a playlist does
1178 * not exist, it will create one.
1179 *****************************************************************************/
1180 int VLC_AddTarget( int i_object, char const *psz_target,
1181 char const **ppsz_options, int i_options,
1182 int i_mode, int i_pos )
1185 playlist_t *p_playlist;
1186 vlc_t *p_vlc = vlc_current_object( i_object );
1193 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1195 if( p_playlist == NULL )
1197 msg_Dbg( p_vlc, "no playlist present, creating one" );
1198 p_playlist = playlist_Create( p_vlc );
1200 if( p_playlist == NULL )
1202 if( i_object ) vlc_object_release( p_vlc );
1203 return VLC_EGENERIC;
1206 vlc_object_yield( p_playlist );
1209 i_err = playlist_AddExt( p_playlist, psz_target, psz_target,
1210 i_mode, i_pos, -1, ppsz_options, i_options);
1212 vlc_object_release( p_playlist );
1214 if( i_object ) vlc_object_release( p_vlc );
1218 /*****************************************************************************
1219 * VLC_Play: play the playlist
1220 *****************************************************************************/
1221 int VLC_Play( int i_object )
1223 playlist_t * p_playlist;
1224 vlc_t *p_vlc = vlc_current_object( i_object );
1226 /* Check that the handle is valid */
1232 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1236 if( i_object ) vlc_object_release( p_vlc );
1240 playlist_Play( p_playlist );
1241 vlc_object_release( p_playlist );
1243 if( i_object ) vlc_object_release( p_vlc );
1247 /*****************************************************************************
1248 * VLC_Pause: toggle pause
1249 *****************************************************************************/
1250 int VLC_Pause( int i_object )
1252 playlist_t * p_playlist;
1253 vlc_t *p_vlc = vlc_current_object( i_object );
1255 /* Check that the handle is valid */
1261 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1265 if( i_object ) vlc_object_release( p_vlc );
1269 playlist_Pause( p_playlist );
1270 vlc_object_release( p_playlist );
1272 if( i_object ) vlc_object_release( p_vlc );
1276 /*****************************************************************************
1277 * VLC_Pause: toggle pause
1278 *****************************************************************************/
1279 int VLC_Stop( int i_object )
1281 playlist_t * p_playlist;
1282 vlc_t *p_vlc = vlc_current_object( i_object );
1284 /* Check that the handle is valid */
1290 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1294 if( i_object ) vlc_object_release( p_vlc );
1298 playlist_Stop( p_playlist );
1299 vlc_object_release( p_playlist );
1301 if( i_object ) vlc_object_release( p_vlc );
1305 /*****************************************************************************
1306 * VLC_IsPlaying: Query for Playlist Status
1307 *****************************************************************************/
1308 vlc_bool_t VLC_IsPlaying( int i_object )
1310 playlist_t * p_playlist;
1311 vlc_bool_t b_playing;
1313 vlc_t *p_vlc = vlc_current_object( i_object );
1315 /* Check that the handle is valid */
1321 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1325 if( i_object ) vlc_object_release( p_vlc );
1329 if( p_playlist->p_input )
1332 var_Get( p_playlist->p_input, "state", &val );
1333 b_playing = ( val.i_int == PLAYING_S );
1337 msg_Dbg(p_vlc, "polling playlist_IsPlaying");
1338 b_playing = playlist_IsPlaying( p_playlist );
1340 vlc_object_release( p_playlist );
1342 if( i_object ) vlc_object_release( p_vlc );
1347 * Get the current position in a input
1349 * Return the current position as a float
1350 * \note For some inputs, this will be unknown.
1352 * \param i_object a vlc object id
1353 * \return a float in the range of 0.0 - 1.0
1355 float VLC_PositionGet( int i_object )
1357 input_thread_t *p_input;
1359 vlc_t *p_vlc = vlc_current_object( i_object );
1361 /* Check that the handle is valid */
1367 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1371 if( i_object ) vlc_object_release( p_vlc );
1375 var_Get( p_input, "position", &val );
1376 vlc_object_release( p_input );
1378 if( i_object ) vlc_object_release( p_vlc );
1383 * Set the current position in a input
1385 * Set the current position in a input and then return
1386 * the current position as a float.
1387 * \note For some inputs, this will be unknown.
1389 * \param i_object a vlc object id
1390 * \param i_position a float in the range of 0.0 - 1.0
1391 * \return a float in the range of 0.0 - 1.0
1393 float VLC_PositionSet( int i_object, float i_position )
1395 input_thread_t *p_input;
1397 vlc_t *p_vlc = vlc_current_object( i_object );
1399 /* Check that the handle is valid */
1405 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1409 if( i_object ) vlc_object_release( p_vlc );
1413 val.f_float = i_position;
1414 var_Set( p_input, "position", val );
1415 var_Get( p_input, "position", &val );
1416 vlc_object_release( p_input );
1418 if( i_object ) vlc_object_release( p_vlc );
1423 * Get the current position in a input
1425 * Return the current position in seconds from the start.
1426 * \note For some inputs, this will be unknown.
1428 * \param i_object a vlc object id
1429 * \return the offset from 0:00 in seconds
1431 int VLC_TimeGet( int i_object )
1433 input_thread_t *p_input;
1435 vlc_t *p_vlc = vlc_current_object( i_object );
1437 /* Check that the handle is valid */
1443 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1447 if( i_object ) vlc_object_release( p_vlc );
1451 var_Get( p_input, "time", &val );
1452 vlc_object_release( p_input );
1454 if( i_object ) vlc_object_release( p_vlc );
1455 return val.i_time / 1000000;
1459 * Seek to a position in the current input
1461 * Seek i_seconds in the current input. If b_relative is set,
1462 * then the seek will be relative to the current position, otherwise
1463 * it will seek to i_seconds from the beginning of the input.
1464 * \note For some inputs, this will be unknown.
1466 * \param i_object a vlc object id
1467 * \param i_seconds seconds from current position or from beginning of input
1468 * \param b_relative seek relative from current position
1469 * \return VLC_SUCCESS on success
1471 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
1473 input_thread_t *p_input;
1475 vlc_t *p_vlc = vlc_current_object( i_object );
1477 /* Check that the handle is valid */
1483 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1487 if( i_object ) vlc_object_release( p_vlc );
1493 val.i_time = i_seconds;
1494 val.i_time = val.i_time * 1000000L;
1495 var_Set( p_input, "time-offset", val );
1499 val.i_time = i_seconds;
1500 val.i_time = val.i_time * 1000000L;
1501 var_Set( p_input, "time", val );
1503 vlc_object_release( p_input );
1505 if( i_object ) vlc_object_release( p_vlc );
1510 * Get the total length of a input
1512 * Return the total length in seconds from the current input.
1513 * \note For some inputs, this will be unknown.
1515 * \param i_object a vlc object id
1516 * \return the length in seconds
1518 int VLC_LengthGet( int i_object )
1520 input_thread_t *p_input;
1522 vlc_t *p_vlc = vlc_current_object( i_object );
1524 /* Check that the handle is valid */
1530 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1534 if( i_object ) vlc_object_release( p_vlc );
1538 var_Get( p_input, "length", &val );
1539 vlc_object_release( p_input );
1541 if( i_object ) vlc_object_release( p_vlc );
1542 return val.i_time / 1000000L;
1546 * Play the input faster than realtime
1548 * 2x, 4x, 8x faster than realtime
1549 * \note For some inputs, this will be impossible.
1551 * \param i_object a vlc object id
1552 * \return the current speedrate
1554 float VLC_SpeedFaster( int i_object )
1556 input_thread_t *p_input;
1558 vlc_t *p_vlc = vlc_current_object( i_object );
1560 /* Check that the handle is valid */
1566 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1570 if( i_object ) vlc_object_release( p_vlc );
1574 val.b_bool = VLC_TRUE;
1575 var_Set( p_input, "rate-faster", val );
1576 var_Get( p_input, "rate", &val );
1577 vlc_object_release( p_input );
1579 if( i_object ) vlc_object_release( p_vlc );
1580 return val.f_float / INPUT_RATE_DEFAULT;
1584 * Play the input slower than realtime
1586 * 1/2x, 1/4x, 1/8x slower than realtime
1587 * \note For some inputs, this will be impossible.
1589 * \param i_object a vlc object id
1590 * \return the current speedrate
1592 float VLC_SpeedSlower( int i_object )
1594 input_thread_t *p_input;
1596 vlc_t *p_vlc = vlc_current_object( i_object );
1598 /* Check that the handle is valid */
1604 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1608 if( i_object ) vlc_object_release( p_vlc );
1612 val.b_bool = VLC_TRUE;
1613 var_Set( p_input, "rate-slower", val );
1614 var_Get( p_input, "rate", &val );
1615 vlc_object_release( p_input );
1617 if( i_object ) vlc_object_release( p_vlc );
1618 return val.f_float / INPUT_RATE_DEFAULT;
1622 * Return the current playlist item
1624 * Returns the index of the playlistitem that is currently selected for play.
1625 * This is valid even if nothing is currently playing.
1627 * \param i_object a vlc object id
1628 * \return the current index
1630 int VLC_PlaylistIndex( int i_object )
1633 playlist_t * p_playlist;
1634 vlc_t *p_vlc = vlc_current_object( i_object );
1636 /* Check that the handle is valid */
1642 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1646 if( i_object ) vlc_object_release( p_vlc );
1650 i_index = p_playlist->i_index;
1651 vlc_object_release( p_playlist );
1653 if( i_object ) vlc_object_release( p_vlc );
1658 * Total amount of items in the playlist
1660 * \param i_object a vlc object id
1661 * \return amount of playlist items
1663 int VLC_PlaylistNumberOfItems( int i_object )
1666 playlist_t * p_playlist;
1667 vlc_t *p_vlc = vlc_current_object( i_object );
1669 /* Check that the handle is valid */
1675 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1679 if( i_object ) vlc_object_release( p_vlc );
1683 i_size = p_playlist->i_size;
1684 vlc_object_release( p_playlist );
1686 if( i_object ) vlc_object_release( p_vlc );
1691 * Next playlist item
1693 * Skip to the next playlistitem and play it.
1695 * \param i_object a vlc object id
1696 * \return VLC_SUCCESS on success
1698 int VLC_PlaylistNext( int i_object )
1700 playlist_t * p_playlist;
1701 vlc_t *p_vlc = vlc_current_object( i_object );
1703 /* Check that the handle is valid */
1709 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1713 if( i_object ) vlc_object_release( p_vlc );
1717 playlist_Next( p_playlist );
1718 vlc_object_release( p_playlist );
1720 if( i_object ) vlc_object_release( p_vlc );
1725 * Previous playlist item
1727 * Skip to the previous playlistitem and play it.
1729 * \param i_object a vlc object id
1730 * \return VLC_SUCCESS on success
1732 int VLC_PlaylistPrev( int i_object )
1734 playlist_t * p_playlist;
1735 vlc_t *p_vlc = vlc_current_object( i_object );
1737 /* Check that the handle is valid */
1743 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1747 if( i_object ) vlc_object_release( p_vlc );
1751 playlist_Prev( p_playlist );
1752 vlc_object_release( p_playlist );
1754 if( i_object ) vlc_object_release( p_vlc );
1759 /*****************************************************************************
1760 * VLC_PlaylistClear: Empty the playlist
1761 *****************************************************************************/
1762 int VLC_PlaylistClear( int i_object )
1765 playlist_t * p_playlist;
1766 vlc_t *p_vlc = vlc_current_object( i_object );
1768 /* Check that the handle is valid */
1774 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1778 if( i_object ) vlc_object_release( p_vlc );
1782 i_err = playlist_Clear( p_playlist );
1784 vlc_object_release( p_playlist );
1786 if( i_object ) vlc_object_release( p_vlc );
1793 * \param i_object a vlc object id
1794 * \param i_volume something in a range from 0-200
1795 * \return the new volume (range 0-200 %)
1797 int VLC_VolumeSet( int i_object, int i_volume )
1799 audio_volume_t i_vol = 0;
1800 vlc_t *p_vlc = vlc_current_object( i_object );
1802 /* Check that the handle is valid */
1808 if( i_volume >= 0 && i_volume <= 200 )
1810 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
1811 aout_VolumeSet( p_vlc, i_vol );
1814 if( i_object ) vlc_object_release( p_vlc );
1815 return i_vol * 200 / AOUT_VOLUME_MAX;
1819 * Get the current volume
1821 * Retrieve the current volume.
1823 * \param i_object a vlc object id
1824 * \return the current volume (range 0-200 %)
1826 int VLC_VolumeGet( int i_object )
1828 audio_volume_t i_volume;
1829 vlc_t *p_vlc = vlc_current_object( i_object );
1831 /* Check that the handle is valid */
1837 aout_VolumeGet( p_vlc, &i_volume );
1839 if( i_object ) vlc_object_release( p_vlc );
1840 return i_volume*200/AOUT_VOLUME_MAX;
1844 * Mute/Unmute the volume
1846 * \param i_object a vlc object id
1847 * \return VLC_SUCCESS on success
1849 int VLC_VolumeMute( int i_object )
1851 vlc_t *p_vlc = vlc_current_object( i_object );
1853 /* Check that the handle is valid */
1859 aout_VolumeMute( p_vlc, NULL );
1861 if( i_object ) vlc_object_release( p_vlc );
1865 /*****************************************************************************
1866 * VLC_FullScreen: toggle fullscreen mode
1867 *****************************************************************************/
1868 int VLC_FullScreen( int i_object )
1870 vout_thread_t *p_vout;
1871 vlc_t *p_vlc = vlc_current_object( i_object );
1878 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
1882 if( i_object ) vlc_object_release( p_vlc );
1886 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1887 vlc_object_release( p_vout );
1889 if( i_object ) vlc_object_release( p_vlc );
1893 /* following functions are local */
1896 static int AddIntfInternal( int i_object, char const *psz_module,
1897 vlc_bool_t b_block, vlc_bool_t b_play,
1898 int i_options, char **ppsz_options )
1901 intf_thread_t *p_intf;
1902 vlc_t *p_vlc = vlc_current_object( i_object );
1910 if( p_vlc->p_libvlc->b_daemon && b_block && !psz_module )
1912 /* Daemon mode hack.
1913 * We prefer the dummy interface if none is specified. */
1914 char *psz_interface = config_GetPsz( p_vlc, "intf" );
1915 if( !psz_interface || !*psz_interface ) psz_module = "dummy";
1916 if( psz_interface ) free( psz_interface );
1920 /* Try to create the interface */
1921 p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf",
1922 i_options, ppsz_options );
1924 if( p_intf == NULL )
1926 msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
1927 if( i_object ) vlc_object_release( p_vlc );
1928 return VLC_EGENERIC;
1931 /* Interface doesn't handle play on start so do it ourselves */
1932 if( !p_intf->b_play && b_play ) VLC_Play( i_object );
1934 /* Try to run the interface */
1935 p_intf->b_play = b_play;
1936 p_intf->b_block = b_block;
1937 i_err = intf_RunThread( p_intf );
1940 vlc_object_detach( p_intf );
1941 intf_Destroy( p_intf );
1942 if( i_object ) vlc_object_release( p_vlc );
1946 for( i = 0 ; i< i_options ; i++ )
1951 if( i_object ) vlc_object_release( p_vlc );
1955 static void LocaleInit( void )
1959 if( !vlc_current_charset( &psz_charset ) )
1961 char *psz_conv = psz_charset;
1964 * Still allow non-ASCII characters when the locale is not set.
1965 * Western Europeans are being favored for historical reasons.
1967 psz_conv = strcmp( psz_charset, "ASCII" )
1971 vlc_mutex_init( p_libvlc, &libvlc.from_locale_lock );
1972 vlc_mutex_init( p_libvlc, &libvlc.to_locale_lock );
1973 libvlc.from_locale = vlc_iconv_open( "UTF-8", psz_charset );
1974 libvlc.to_locale = vlc_iconv_open( psz_charset, "UTF-8" );
1975 if( !libvlc.to_locale )
1977 /* Not sure it is the right thing to do, but at least it
1978 doesn't make vlc crash with msvc ! */
1979 libvlc.to_locale = (vlc_iconv_t)(-1);
1983 libvlc.from_locale = libvlc.to_locale = (vlc_iconv_t)(-1);
1984 free( psz_charset );
1987 static void LocaleDeinit( void )
1989 if( libvlc.to_locale != (vlc_iconv_t)(-1) )
1991 vlc_mutex_destroy( &libvlc.from_locale_lock );
1992 vlc_mutex_destroy( &libvlc.to_locale_lock );
1993 vlc_iconv_close( libvlc.from_locale );
1994 vlc_iconv_close( libvlc.to_locale );
1998 /*****************************************************************************
1999 * SetLanguage: set the interface language.
2000 *****************************************************************************
2001 * We set the LC_MESSAGES locale category for interface messages and buttons,
2002 * as well as the LC_CTYPE category for string sorting and possible wide
2003 * character support.
2004 *****************************************************************************/
2005 static void SetLanguage ( char const *psz_lang )
2007 #if defined( ENABLE_NLS ) \
2008 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
2011 #if defined( SYS_DARWIN ) || defined ( WIN32 ) || defined( SYS_BEOS )
2015 if( psz_lang && !*psz_lang )
2017 # if defined( HAVE_LC_MESSAGES )
2018 setlocale( LC_MESSAGES, psz_lang );
2020 setlocale( LC_CTYPE, psz_lang );
2025 /* I need that under Darwin, please check it doesn't disturb
2026 * other platforms. --Meuuh */
2027 setenv( "LANG", psz_lang, 1 );
2029 #elif defined( SYS_BEOS ) || defined( WIN32 )
2030 /* We set LC_ALL manually because it is the only way to set
2031 * the language at runtime under eg. Windows. Beware that this
2032 * makes the environment unconsistent when libvlc is unloaded and
2033 * should probably be moved to a safer place like vlc.c. */
2034 static char psz_lcall[20];
2035 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
2036 psz_lcall[19] = '\0';
2037 putenv( psz_lcall );
2040 setlocale( LC_ALL, psz_lang );
2041 /* many code paths assume that float numbers are formatted according
2042 * to the US standard (ie. with dot as decimal point), so we keep
2043 * C for LC_NUMERIC. */
2044 setlocale(LC_NUMERIC, "C" );
2047 /* Specify where to find the locales for current domain */
2048 #if !defined( SYS_DARWIN ) && !defined( WIN32 ) && !defined( SYS_BEOS )
2049 psz_path = LOCALEDIR;
2051 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
2055 if( !bindtextdomain( PACKAGE_NAME, psz_path ) )
2057 fprintf( stderr, "warning: couldn't bind domain %s in directory %s\n",
2058 PACKAGE_NAME, psz_path );
2061 /* Set the default domain */
2062 textdomain( PACKAGE_NAME );
2063 bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
2067 /*****************************************************************************
2068 * GetFilenames: parse command line options which are not flags
2069 *****************************************************************************
2070 * Parse command line for input files as well as their associated options.
2071 * An option always follows its associated input and begins with a ":".
2072 *****************************************************************************/
2073 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
2075 int i_opt, i_options;
2077 /* We assume that the remaining parameters are filenames
2078 * and their input options */
2079 for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
2081 const char *psz_target;
2084 /* Count the input options */
2085 while( *ppsz_argv[ i_opt ] == ':' && i_opt > optind )
2091 /* TODO: write an internal function of this one, to avoid
2092 * unnecessary lookups. */
2093 /* FIXME: should we convert options to UTF-8 as well ?? */
2094 psz_target = FromLocale( ppsz_argv[ i_opt ] );
2095 VLC_AddTarget( p_vlc->i_object_id, psz_target,
2096 (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
2098 PLAYLIST_INSERT, 0 );
2099 LocaleFree( psz_target );
2105 /*****************************************************************************
2106 * Help: print program help
2107 *****************************************************************************
2108 * Print a short inline help. Message interface is initialized at this stage.
2109 *****************************************************************************/
2110 static void Help( vlc_t *p_this, char const *psz_help_name )
2116 if( psz_help_name && !strcmp( psz_help_name, "help" ) )
2118 fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
2119 Usage( p_this, "help" );
2120 Usage( p_this, "main" );
2122 else if( psz_help_name && !strcmp( psz_help_name, "longhelp" ) )
2124 fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
2125 Usage( p_this, NULL );
2127 else if( psz_help_name )
2129 Usage( p_this, psz_help_name );
2132 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2137 /*****************************************************************************
2138 * Usage: print module usage
2139 *****************************************************************************
2140 * Print a short inline help. Message interface is initialized at this stage.
2141 *****************************************************************************/
2142 static void Usage( vlc_t *p_this, char const *psz_module_name )
2144 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
2145 /* short option ------' | | | | | | |
2146 * option name ------------' | | | | | |
2147 * <bra -------------------------' | | | | |
2148 * option type or "" --------------' | | | |
2149 * ket> -----------------------------' | | |
2150 * padding spaces ---------------------' | |
2151 * comment -------------------------------' |
2152 * comment suffix --------------------------'
2154 * The purpose of having bra and ket is that we might i18n them as well.
2156 #define LINE_START 8
2157 #define PADDING_SPACES 25
2160 module_config_t *p_item;
2161 char psz_spaces_text[PADDING_SPACES+LINE_START+1];
2162 char psz_spaces_longtext[LINE_START+3];
2163 char psz_format[sizeof(FORMAT_STRING)];
2164 char psz_buffer[10000];
2167 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
2168 vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" );
2169 vlc_bool_t b_description;
2171 memset( psz_spaces_text, ' ', PADDING_SPACES+LINE_START );
2172 psz_spaces_text[PADDING_SPACES+LINE_START] = '\0';
2173 memset( psz_spaces_longtext, ' ', LINE_START+2 );
2174 psz_spaces_longtext[LINE_START+2] = '\0';
2176 strcpy( psz_format, FORMAT_STRING );
2178 /* List all modules */
2179 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2181 /* Enumerate the config for each module */
2182 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2184 vlc_bool_t b_help_module;
2186 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2188 if( psz_module_name && strcmp( psz_module_name,
2189 p_parser->psz_object_name ) )
2194 /* Ignore modules without config options */
2195 if( !p_parser->i_config_items )
2200 /* Ignore modules with only advanced config options if requested */
2203 for( p_item = p_parser->p_config;
2204 p_item->i_type != CONFIG_HINT_END;
2207 if( (p_item->i_type & CONFIG_ITEM) &&
2208 !p_item->b_advanced ) break;
2210 if( p_item->i_type == CONFIG_HINT_END ) continue;
2213 /* Print name of module */
2214 if( strcmp( "main", p_parser->psz_object_name ) )
2215 fprintf( stdout, "\n %s\n", p_parser->psz_longname );
2217 b_help_module = !strcmp( "help", p_parser->psz_object_name );
2219 /* Print module options */
2220 for( p_item = p_parser->p_config;
2221 p_item->i_type != CONFIG_HINT_END;
2224 char *psz_text, *psz_spaces = psz_spaces_text;
2225 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
2226 char *psz_suf = "", *psz_prefix = NULL;
2229 /* Skip deprecated options */
2230 if( p_item->psz_current )
2234 /* Skip advanced options if requested */
2235 if( p_item->b_advanced && !b_advanced )
2240 switch( p_item->i_type )
2242 case CONFIG_HINT_CATEGORY:
2243 case CONFIG_HINT_USAGE:
2244 if( !strcmp( "main", p_parser->psz_object_name ) )
2245 fprintf( stdout, "\n %s\n", p_item->psz_text );
2248 case CONFIG_ITEM_STRING:
2249 case CONFIG_ITEM_FILE:
2250 case CONFIG_ITEM_DIRECTORY:
2251 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
2252 case CONFIG_ITEM_MODULE_CAT:
2253 case CONFIG_ITEM_MODULE_LIST:
2254 case CONFIG_ITEM_MODULE_LIST_CAT:
2255 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
2257 if( p_item->ppsz_list )
2260 psz_type = psz_buffer;
2262 for( i = 0; p_item->ppsz_list[i]; i++ )
2264 if( i ) strcat( psz_type, "," );
2265 strcat( psz_type, p_item->ppsz_list[i] );
2270 case CONFIG_ITEM_INTEGER:
2271 case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
2272 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
2274 if( p_item->i_list )
2277 psz_type = psz_buffer;
2279 for( i = 0; p_item->ppsz_list_text[i]; i++ )
2281 if( i ) strcat( psz_type, ", " );
2282 sprintf( psz_type + strlen(psz_type), "%i (%s)",
2284 p_item->ppsz_list_text[i] );
2289 case CONFIG_ITEM_FLOAT:
2290 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
2292 case CONFIG_ITEM_BOOL:
2293 psz_bra = ""; psz_type = ""; psz_ket = "";
2294 if( !b_help_module )
2296 psz_suf = p_item->i_value ? _(" (default enabled)") :
2297 _(" (default disabled)");
2307 /* Add short option if any */
2308 if( p_item->i_short )
2310 sprintf( psz_short, "-%c,", p_item->i_short );
2314 strcpy( psz_short, " " );
2317 i = PADDING_SPACES - strlen( p_item->psz_name )
2318 - strlen( psz_bra ) - strlen( psz_type )
2319 - strlen( psz_ket ) - 1;
2321 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
2323 psz_prefix = ", --no-";
2324 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
2329 psz_spaces[0] = '\n';
2334 psz_spaces[i] = '\0';
2337 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
2339 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2340 psz_prefix, p_item->psz_name, psz_bra, psz_type,
2341 psz_ket, psz_spaces );
2345 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2346 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
2349 psz_spaces[i] = ' ';
2351 /* We wrap the rest of the output */
2352 sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
2353 b_description = config_GetInt( p_this, "help-verbose" );
2356 psz_text = psz_buffer;
2359 char *psz_parser, *psz_word;
2360 size_t i_end = strlen( psz_text );
2362 /* If the remaining text fits in a line, print it. */
2363 if( i_end <= (size_t)i_width )
2365 fprintf( stdout, "%s\n", psz_text );
2369 /* Otherwise, eat as many words as possible */
2370 psz_parser = psz_text;
2373 psz_word = psz_parser;
2374 psz_parser = strchr( psz_word, ' ' );
2375 /* If no space was found, we reached the end of the text
2376 * block; otherwise, we skip the space we just found. */
2377 psz_parser = psz_parser ? psz_parser + 1
2380 } while( psz_parser - psz_text <= i_width );
2382 /* We cut a word in one of these cases:
2383 * - it's the only word in the line and it's too long.
2384 * - we used less than 80% of the width and the word we are
2385 * going to wrap is longer than 40% of the width, and even
2386 * if the word would have fit in the next line. */
2387 if( psz_word == psz_text
2388 || ( psz_word - psz_text < 80 * i_width / 100
2389 && psz_parser - psz_word > 40 * i_width / 100 ) )
2391 char c = psz_text[i_width];
2392 psz_text[i_width] = '\0';
2393 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2394 psz_text += i_width;
2399 psz_word[-1] = '\0';
2400 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2401 psz_text = psz_word;
2405 if( b_description && p_item->psz_longtext )
2407 sprintf( psz_buffer, "%s%s", p_item->psz_longtext, psz_suf );
2408 b_description = VLC_FALSE;
2409 psz_spaces = psz_spaces_longtext;
2410 fprintf( stdout, "%s", psz_spaces );
2416 /* Release the module list */
2417 vlc_list_release( p_list );
2420 /*****************************************************************************
2421 * ListModules: list the available modules with their description
2422 *****************************************************************************
2423 * Print a list of all available modules (builtins and plugins) and a short
2424 * description for each one.
2425 *****************************************************************************/
2426 static void ListModules( vlc_t *p_this )
2430 char psz_spaces[22];
2433 memset( psz_spaces, ' ', 22 );
2439 /* List all modules */
2440 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2442 /* Enumerate each module */
2443 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2447 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2449 /* Nasty hack, but right now I'm too tired to think about a nice
2451 i = 22 - strlen( p_parser->psz_object_name ) - 1;
2455 fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
2456 psz_spaces, p_parser->psz_longname );
2458 psz_spaces[i] = ' ';
2461 vlc_list_release( p_list );
2463 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2468 /*****************************************************************************
2469 * Version: print complete program version
2470 *****************************************************************************
2471 * Print complete program version and build number.
2472 *****************************************************************************/
2473 static void Version( void )
2479 fprintf( stdout, _("VLC version %s\n"), VLC_Version() );
2480 fprintf( stdout, _("Compiled by %s@%s.%s\n"),
2481 VLC_CompileBy(), VLC_CompileHost(), VLC_CompileDomain() );
2482 fprintf( stdout, _("Compiler: %s\n"), VLC_Compiler() );
2483 if( strcmp( VLC_Changeset(), "exported" ) )
2484 fprintf( stdout, _("Based upon svn changeset [%s]\n"),
2486 fprintf( stdout, LICENSE_MSG );
2488 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2493 /*****************************************************************************
2494 * ShowConsole: On Win32, create an output console for debug messages
2495 *****************************************************************************
2496 * This function is useful only on Win32.
2497 *****************************************************************************/
2499 static void ShowConsole( void )
2504 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2508 freopen( "CONOUT$", "w", stderr );
2509 freopen( "CONIN$", "r", stdin );
2511 if( (f_help = fopen( "vlc-help.txt", "wt" )) )
2514 freopen( "vlc-help.txt", "wt", stdout );
2515 fprintf( stderr, _("\nDumped content to vlc-help.txt file.\n") );
2518 else freopen( "CONOUT$", "w", stdout );
2524 /*****************************************************************************
2525 * PauseConsole: On Win32, wait for a key press before closing the console
2526 *****************************************************************************
2527 * This function is useful only on Win32.
2528 *****************************************************************************/
2530 static void PauseConsole( void )
2534 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2536 fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
2544 /*****************************************************************************
2545 * ConsoleWidth: Return the console width in characters
2546 *****************************************************************************
2547 * We use the stty shell command to get the console width; if this fails or
2548 * if the width is less than 80, we default to 80.
2549 *****************************************************************************/
2550 static int ConsoleWidth( void )
2555 char buf[20], *psz_parser;
2559 file = popen( "stty size 2>/dev/null", "r" );
2562 i_ret = fread( buf, 1, 20, file );
2566 psz_parser = strchr( buf, ' ' );
2569 i_ret = atoi( psz_parser + 1 );
2584 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
2585 vlc_value_t old_val, vlc_value_t new_val, void *param)
2587 vlc_t *p_vlc = (vlc_t *)p_this;
2589 if( new_val.i_int >= -1 )
2591 p_vlc->p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );
2596 /*****************************************************************************
2597 * InitDeviceValues: initialize device values
2598 *****************************************************************************
2599 * This function inits the dvd, vcd and cd-audio values
2600 *****************************************************************************/
2601 static void InitDeviceValues( vlc_t *p_vlc )
2604 LibHalContext * ctx;
2609 DBusConnection *p_connection;
2613 ctx = libhal_ctx_new();
2615 dbus_error_init( &error );
2616 p_connection = dbus_bus_get ( DBUS_BUS_SYSTEM, &error );
2617 if( dbus_error_is_set( &error ) )
2619 dbus_error_free( &error );
2622 libhal_ctx_set_dbus_connection( ctx, p_connection );
2623 if( libhal_ctx_init( ctx, &error ) )
2625 if( ( ctx = hal_initialize( NULL, FALSE ) ) )
2629 if( ( devices = libhal_get_all_devices( ctx, &i_devices, NULL ) ) )
2631 if( ( devices = hal_get_all_devices( ctx, &i_devices ) ) )
2634 for( i = 0; i < i_devices; i++ )
2637 if( !libhal_device_property_exists( ctx, devices[i],
2638 "storage.cdrom.dvd", NULL ) )
2640 if( !hal_device_property_exists( ctx, devices[ i ],
2641 "storage.cdrom.dvd" ) )
2647 b_dvd = libhal_device_get_property_bool( ctx, devices[ i ],
2648 "storage.cdrom.dvd", NULL );
2649 block_dev = libhal_device_get_property_string( ctx,
2650 devices[ i ], "block.device" , NULL );
2652 b_dvd = hal_device_get_property_bool( ctx, devices[ i ],
2653 "storage.cdrom.dvd" );
2654 block_dev = hal_device_get_property_string( ctx, devices[ i ],
2659 config_PutPsz( p_vlc, "dvd", block_dev );
2662 config_PutPsz( p_vlc, "vcd", block_dev );
2663 config_PutPsz( p_vlc, "cd-audio", block_dev );
2665 libhal_free_string( block_dev );
2667 hal_free_string( block_dev );
2671 libhal_free_string_array( devices );
2673 hal_free_string_array( devices );
2678 libhal_ctx_shutdown( ctx, NULL );
2680 hal_shutdown( ctx );
2685 msg_Warn( p_vlc, "Unable to get HAL device properties" );
2690 /*****************************************************************************
2691 * FromLocale: converts a locale string to UTF-8
2692 *****************************************************************************/
2693 char *FromLocale( const char *locale )
2695 if( locale == NULL )
2698 if( libvlc.from_locale != (vlc_iconv_t)(-1) )
2700 char *iptr = (char *)locale, *output, *optr;
2704 * We are not allowed to modify the locale pointer, even if we cast it
2707 inb = strlen( locale );
2710 /* FIXME: I'm not sure about the value for the multiplication
2711 * (for western people, multiplication by 3 (Latin9) is sufficient) */
2712 optr = output = calloc( outb , 1);
2714 vlc_mutex_lock( &libvlc.from_locale_lock );
2715 vlc_iconv( libvlc.from_locale, NULL, NULL, NULL, NULL );
2717 while( vlc_iconv( libvlc.from_locale, &iptr, &inb, &optr, &outb )
2723 vlc_iconv( libvlc.from_locale, NULL, NULL, NULL, NULL );
2725 vlc_mutex_unlock( &libvlc.from_locale_lock );
2727 return realloc( output, strlen( output ) + 1 );
2729 return (char *)locale;
2732 /*****************************************************************************
2733 * ToLocale: converts an UTF-8 string to locale
2734 *****************************************************************************/
2735 char *ToLocale( const char *utf8 )
2740 if( libvlc.to_locale != (vlc_iconv_t)(-1) )
2742 char *iptr = (char *)utf8, *output, *optr;
2746 * We are not allowed to modify the locale pointer, even if we cast it
2749 inb = strlen( utf8 );
2750 /* FIXME: I'm not sure about the value for the multiplication
2751 * (for western people, multiplication is not needed) */
2754 optr = output = calloc( outb, 1 );
2755 vlc_mutex_lock( &libvlc.to_locale_lock );
2756 vlc_iconv( libvlc.to_locale, NULL, NULL, NULL, NULL );
2758 while( vlc_iconv( libvlc.to_locale, &iptr, &inb, &optr, &outb )
2761 *optr = '?'; /* should not happen, and yes, it sucks */
2764 vlc_iconv( libvlc.to_locale, NULL, NULL, NULL, NULL );
2766 vlc_mutex_unlock( &libvlc.to_locale_lock );
2768 return realloc( output, strlen( output ) + 1 );
2770 return (char *)utf8;
2773 void LocaleFree( const char *str )
2775 if( ( str != NULL ) && ( libvlc.to_locale != (vlc_iconv_t)(-1) ) )
2776 free( (char *)str );