1 /*****************************************************************************
2 * libvlc-common.c: libvlc instances creation and deletion, interfaces handling
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 *****************************************************************************/
29 * This file contains functions to create and destroy libvlc instances
32 /*****************************************************************************
33 * Pretend we are a builtin module
34 *****************************************************************************/
35 #define MODULE_NAME main
36 #define MODULE_PATH main
39 /*****************************************************************************
41 *****************************************************************************/
43 #include <libvlc_internal.h>
44 #include <vlc/input.h>
46 #include <errno.h> /* ENOMEM */
47 #include <stdio.h> /* sprintf() */
48 #include <string.h> /* strerror() */
49 #include <stdlib.h> /* free() */
52 # include <netinet/in.h> /* BSD: struct in_addr */
57 #elif defined( WIN32 ) && !defined( UNDER_CE )
61 #ifdef WIN32 /* optind, getopt(), included in unistd.h */
62 # include "extras/getopt.h"
70 # include <hal/libhal.h>
73 #include "vlc_cpu.h" /* CPU detection */
74 #include "os_specific.h"
76 #include "vlc_error.h"
78 #include "vlc_playlist.h"
79 #include "vlc_interface.h"
81 #include "audio_output.h"
83 #include "vlc_video.h"
84 #include "video_output.h"
86 #include "stream_output.h"
91 /*****************************************************************************
92 * The evil global variable. We handle it with care, don't worry.
93 *****************************************************************************/
94 static libvlc_global_data_t libvlc_global;
95 static libvlc_global_data_t * p_libvlc_global;
96 static libvlc_int_t * p_static_vlc;
97 static volatile unsigned int i_instances = 0;
99 /*****************************************************************************
101 *****************************************************************************/
102 void LocaleInit( vlc_object_t * );
103 void LocaleDeinit( void );
104 static void SetLanguage ( char const * );
105 static int GetFilenames ( libvlc_int_t *, int, char *[] );
106 static void Help ( libvlc_int_t *, char const *psz_help_name );
107 static void Usage ( libvlc_int_t *, char const *psz_module_name );
108 static void ListModules ( libvlc_int_t * );
109 static void Version ( void );
112 static void ShowConsole ( vlc_bool_t );
113 static void PauseConsole ( void );
115 static int ConsoleWidth ( void );
117 static int VerboseCallback( vlc_object_t *, char const *,
118 vlc_value_t, vlc_value_t, void * );
120 static void InitDeviceValues( libvlc_int_t * );
122 /*****************************************************************************
123 * vlc_current_object: return the current object.
124 *****************************************************************************
125 * If i_object is non-zero, return the corresponding object. Otherwise,
126 * return the statically allocated p_vlc object.
127 *****************************************************************************/
128 libvlc_int_t * vlc_current_object( int i_object )
132 return vlc_object_get( p_libvlc_global, i_object );
140 * Allocate a libvlc instance, initialize global data if needed
141 * It also initializes the threading system
143 libvlc_int_t * libvlc_InternalCreate( void )
146 libvlc_int_t * p_libvlc = NULL;
150 /* &libvlc_global never changes,
151 * so we can safely call this multiple times. */
152 p_libvlc_global = &libvlc_global;
154 /* vlc_threads_init *must* be the first internal call! No other call is
155 * allowed before the thread system has been initialized. */
156 i_ret = vlc_threads_init( p_libvlc_global );
157 if( i_ret < 0 ) return NULL;
159 /* Now that the thread system is initialized, we don't have much, but
160 * at least we have var_Create */
161 var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
162 var_Get( p_libvlc_global, "libvlc", &lockval );
163 vlc_mutex_lock( lockval.p_address );
167 if( !libvlc_global.b_ready )
169 /* Guess what CPU we have */
170 libvlc_global.i_cpu = CPUCapabilities();
171 /* The module bank will be initialized later */
172 libvlc_global.p_module_bank = NULL;
174 libvlc_global.b_ready = VLC_TRUE;
176 vlc_mutex_unlock( lockval.p_address );
177 var_Destroy( p_libvlc_global, "libvlc" );
179 /* Allocate a libvlc instance object */
180 p_libvlc = vlc_object_create( p_libvlc_global, VLC_OBJECT_LIBVLC );
181 if( p_libvlc == NULL ) { i_instances--; return NULL; }
182 p_libvlc->thread_id = 0;
183 p_libvlc->p_playlist = NULL;
184 p_libvlc->psz_object_name = "libvlc";
186 /* Initialize message queue */
187 msg_Create( p_libvlc );
188 /* Announce who we are - Do it only for first instance ? */
189 msg_Dbg( p_libvlc, COPYRIGHT_MESSAGE );
190 msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
192 /* Find verbosity from VLC_VERBOSE environment variable */
193 psz_env = getenv( "VLC_VERBOSE" );
194 p_libvlc->i_verbose = psz_env ? atoi( psz_env ) : -1;
196 #if defined( HAVE_ISATTY ) && !defined( WIN32 )
197 p_libvlc->b_color = isatty( 2 ); /* 2 is for stderr */
199 p_libvlc->b_color = VLC_FALSE;
202 /* Initialize mutexes */
203 vlc_mutex_init( p_libvlc, &p_libvlc->config_lock );
205 vlc_mutex_init( p_libvlc, &p_libvlc->quicktime_lock );
206 vlc_thread_set_priority( p_libvlc, VLC_THREAD_PRIORITY_LOW );
209 /* Store our newly allocated structure in the global list */
210 vlc_object_attach( p_libvlc, p_libvlc_global );
212 /* Store data for the non-reentrant API */
213 p_static_vlc = p_libvlc;
219 * Initialize a libvlc instance
220 * This function initializes a previously allocated libvlc instance:
222 * - gettext initialization
223 * - message queue, module bank and playlist initialization
224 * - configuration and commandline parsing
226 int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
228 char p_capabilities[200];
233 vlc_bool_t b_exit = VLC_FALSE;
234 int i_ret = VLC_EEXIT;
235 module_t *p_help_module;
236 playlist_t *p_playlist;
238 #if defined( ENABLE_NLS ) \
239 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
240 # if defined (WIN32) || defined (__APPLE__)
245 /* System specific initialization code */
246 system_Init( p_libvlc, &i_argc, ppsz_argv );
248 /* Get the executable name (similar to the basename command) */
251 p_libvlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
254 if( *p_tmp == '/' ) p_libvlc->psz_object_name = ++p_tmp;
260 p_libvlc->psz_object_name = "vlc";
264 * Support for gettext
269 * Global iconv, must be done after setlocale()
270 * so that vlc_current_charset() works.
272 LocaleInit( (vlc_object_t *)p_libvlc );
274 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
275 msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") );
277 /* Initialize the module bank and load the configuration of the
278 * main module. We need to do this at this stage to be able to display
279 * a short help if required by the user. (short help == main module
281 module_InitBank( p_libvlc );
283 /* Hack: insert the help module here */
284 p_help_module = vlc_object_create( p_libvlc, VLC_OBJECT_MODULE );
285 if( p_help_module == NULL )
287 module_EndBank( p_libvlc );
290 p_help_module->psz_object_name = "help";
291 p_help_module->psz_longname = N_("Help options");
292 config_Duplicate( p_help_module, p_help_config );
293 vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
296 if( config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE ) )
298 vlc_object_detach( p_help_module );
299 config_Free( p_help_module );
300 vlc_object_destroy( p_help_module );
301 module_EndBank( p_libvlc );
305 /* Check for short help option */
306 if( config_GetInt( p_libvlc, "help" ) )
308 Help( p_libvlc, "help" );
310 i_ret = VLC_EEXITSUCCESS;
312 /* Check for version option */
313 else if( config_GetInt( p_libvlc, "version" ) )
317 i_ret = VLC_EEXITSUCCESS;
320 /* Set the config file stuff */
321 p_libvlc->psz_homedir = config_GetHomeDir();
322 p_libvlc->psz_userdir = config_GetUserDir();
323 if( p_libvlc->psz_userdir == NULL )
324 p_libvlc->psz_userdir = strdup(p_libvlc->psz_homedir);
325 p_libvlc->psz_configfile = config_GetPsz( p_libvlc, "config" );
326 if( p_libvlc->psz_configfile != NULL && p_libvlc->psz_configfile[0] == '~'
327 && p_libvlc->psz_configfile[1] == '/' )
329 char *psz = malloc( strlen(p_libvlc->psz_userdir)
330 + strlen(p_libvlc->psz_configfile) );
331 /* This is incomplete : we should also support the ~cmassiot/ syntax. */
332 sprintf( psz, "%s/%s", p_libvlc->psz_userdir,
333 p_libvlc->psz_configfile + 2 );
334 free( p_libvlc->psz_configfile );
335 p_libvlc->psz_configfile = psz;
338 /* Check for plugins cache options */
339 if( config_GetInt( p_libvlc, "reset-plugins-cache" ) )
341 libvlc_global.p_module_bank->b_cache_delete = VLC_TRUE;
344 /* Hack: remove the help module here */
345 vlc_object_detach( p_help_module );
348 /* Will be re-done properly later on */
349 p_libvlc->i_verbose = config_GetInt( p_libvlc, "verbose" );
351 /* Check for daemon mode */
353 if( config_GetInt( p_libvlc, "daemon" ) )
356 if( daemon( 1, 0) != 0 )
358 msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
362 p_libvlc->p_libvlc_global->b_daemon = VLC_TRUE;
364 /* lets check if we need to write the pidfile */
365 char * psz_pidfile = config_GetPsz( p_libvlc, "pidfile" );
367 if( psz_pidfile != NULL )
370 pid_t i_pid = getpid ();
371 msg_Dbg( p_libvlc, "PID is %d, writing it to %s",
372 i_pid, psz_pidfile );
373 pidfile = utf8_fopen( psz_pidfile,"w" );
374 if( pidfile != NULL )
376 utf8_fprintf( pidfile, "%d", (int)i_pid );
381 msg_Err( p_libvlc, "cannot open pid file for writing: %s (%s)",
382 psz_pidfile, strerror(errno) );
390 if( ( i_pid = fork() ) < 0 )
392 msg_Err( p_libvlc, "unable to fork vlc to daemon mode" );
397 /* This is the parent, exit right now */
398 msg_Dbg( p_libvlc, "closing parent process" );
400 i_ret = VLC_EEXITSUCCESS;
404 /* We are the child */
405 msg_Dbg( p_libvlc, "daemon spawned" );
406 close( STDIN_FILENO );
407 close( STDOUT_FILENO );
408 close( STDERR_FILENO );
410 p_libvlc->p_libvlc_global->b_daemon = VLC_TRUE;
418 config_Free( p_help_module );
419 vlc_object_destroy( p_help_module );
420 module_EndBank( p_libvlc );
424 /* Check for translation config option */
425 #if defined( ENABLE_NLS ) \
426 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
427 # if defined (WIN32) || defined (__APPLE__)
428 /* This ain't really nice to have to reload the config here but it seems
429 * the only way to do it. */
430 config_LoadConfigFile( p_libvlc, "main" );
431 config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE );
433 /* Check if the user specified a custom language */
434 psz_language = config_GetPsz( p_libvlc, "language" );
435 if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
437 vlc_bool_t b_cache_delete = libvlc_global.p_module_bank->b_cache_delete;
439 /* Reset the default domain */
440 SetLanguage( psz_language );
442 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
443 msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") );
445 module_EndBank( p_libvlc );
446 module_InitBank( p_libvlc );
447 config_LoadConfigFile( p_libvlc, "main" );
448 config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE );
449 libvlc_global.p_module_bank->b_cache_delete = b_cache_delete;
451 if( psz_language ) free( psz_language );
456 * Load the builtins and plugins into the module_bank.
457 * We have to do it before config_Load*() because this also gets the
458 * list of configuration options exported by each module and loads their
461 module_LoadBuiltins( p_libvlc );
462 module_LoadPlugins( p_libvlc );
463 if( p_libvlc->b_die )
468 msg_Dbg( p_libvlc, "module bank initialized, found %i modules",
469 libvlc_global.p_module_bank->i_children );
471 /* Hack: insert the help module here */
472 vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
475 /* Check for help on modules */
476 if( (p_tmp = config_GetPsz( p_libvlc, "module" )) )
478 Help( p_libvlc, p_tmp );
481 i_ret = VLC_EEXITSUCCESS;
483 /* Check for long help option */
484 else if( config_GetInt( p_libvlc, "longhelp" ) )
486 Help( p_libvlc, "longhelp" );
488 i_ret = VLC_EEXITSUCCESS;
490 /* Check for module list option */
491 else if( config_GetInt( p_libvlc, "list" ) )
493 ListModules( p_libvlc );
495 i_ret = VLC_EEXITSUCCESS;
498 /* Check for config file options */
499 if( config_GetInt( p_libvlc, "reset-config" ) )
501 vlc_object_detach( p_help_module );
502 config_ResetAll( p_libvlc );
503 config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE );
504 config_SaveConfigFile( p_libvlc, NULL );
505 vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
507 if( config_GetInt( p_libvlc, "save-config" ) )
509 vlc_object_detach( p_help_module );
510 config_LoadConfigFile( p_libvlc, NULL );
511 config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE );
512 config_SaveConfigFile( p_libvlc, NULL );
513 vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
516 /* Hack: remove the help module here */
517 vlc_object_detach( p_help_module );
522 config_Free( p_help_module );
523 vlc_object_destroy( p_help_module );
524 module_EndBank( p_libvlc );
531 InitDeviceValues( p_libvlc );
534 * Override default configuration with config file settings
536 config_LoadConfigFile( p_libvlc, NULL );
538 /* Hack: insert the help module here */
539 vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
543 * Override configuration with command line settings
545 if( config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_FALSE ) )
548 ShowConsole( VLC_FALSE );
549 /* Pause the console because it's destroyed when we exit */
550 fprintf( stderr, "The command line options couldn't be loaded, check "
551 "that they are valid.\n" );
554 vlc_object_detach( p_help_module );
555 config_Free( p_help_module );
556 vlc_object_destroy( p_help_module );
557 module_EndBank( p_libvlc );
561 /* Hack: remove the help module here */
562 vlc_object_detach( p_help_module );
563 config_Free( p_help_module );
564 vlc_object_destroy( p_help_module );
568 * System specific configuration
570 system_Configure( p_libvlc, &i_argc, ppsz_argv );
573 * Message queue options
576 var_Create( p_libvlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
577 if( config_GetInt( p_libvlc, "quiet" ) )
580 var_Set( p_libvlc, "verbose", val );
582 var_AddCallback( p_libvlc, "verbose", VerboseCallback, NULL );
583 var_Change( p_libvlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
585 p_libvlc->b_color = p_libvlc->b_color && config_GetInt( p_libvlc, "color" );
588 * Output messages that may still be in the queue
590 msg_Flush( p_libvlc );
592 /* p_libvlc initialization. FIXME ? */
594 if( !config_GetInt( p_libvlc, "fpu" ) )
595 libvlc_global.i_cpu &= ~CPU_CAPABILITY_FPU;
597 #if defined( __i386__ ) || defined( __x86_64__ )
598 if( !config_GetInt( p_libvlc, "mmx" ) )
599 libvlc_global.i_cpu &= ~CPU_CAPABILITY_MMX;
600 if( !config_GetInt( p_libvlc, "3dn" ) )
601 libvlc_global.i_cpu &= ~CPU_CAPABILITY_3DNOW;
602 if( !config_GetInt( p_libvlc, "mmxext" ) )
603 libvlc_global.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
604 if( !config_GetInt( p_libvlc, "sse" ) )
605 libvlc_global.i_cpu &= ~CPU_CAPABILITY_SSE;
606 if( !config_GetInt( p_libvlc, "sse2" ) )
607 libvlc_global.i_cpu &= ~CPU_CAPABILITY_SSE2;
609 #if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
610 if( !config_GetInt( p_libvlc, "altivec" ) )
611 libvlc_global.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
614 #define PRINT_CAPABILITY( capability, string ) \
615 if( libvlc_global.i_cpu & capability ) \
617 strncat( p_capabilities, string " ", \
618 sizeof(p_capabilities) - strlen(p_capabilities) ); \
619 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
622 p_capabilities[0] = '\0';
623 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
624 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
625 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
626 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
627 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
628 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
629 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
630 PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" );
631 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
632 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
633 msg_Dbg( p_libvlc, "CPU has capabilities %s", p_capabilities );
636 * Choose the best memcpy module
638 p_libvlc->p_memcpy_module = module_Need( p_libvlc, "memcpy", "$memcpy", 0 );
640 if( p_libvlc->pf_memcpy == NULL )
642 p_libvlc->pf_memcpy = memcpy;
645 if( p_libvlc->pf_memset == NULL )
647 p_libvlc->pf_memset = memset;
650 p_libvlc->b_stats = config_GetInt( p_libvlc, "stats" );
651 p_libvlc->i_timers = 0;
652 p_libvlc->pp_timers = NULL;
653 vlc_mutex_init( p_libvlc, &p_libvlc->timer_lock );
656 * Initialize hotkey handling
658 var_Create( p_libvlc, "key-pressed", VLC_VAR_INTEGER );
659 p_libvlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
660 /* Do a copy (we don't need to modify the strings) */
661 memcpy( p_libvlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
663 /* Initialize playlist and get commandline files */
664 playlist_ThreadCreate( p_libvlc );
665 if( !p_libvlc->p_playlist )
667 msg_Err( p_libvlc, "playlist initialization failed" );
668 if( p_libvlc->p_memcpy_module != NULL )
670 module_Unneed( p_libvlc, p_libvlc->p_memcpy_module );
672 module_EndBank( p_libvlc );
675 p_playlist = p_libvlc->p_playlist;
677 psz_modules = config_GetPsz( p_playlist, "services-discovery" );
678 if( psz_modules && *psz_modules )
680 /* Add service discovery modules */
681 playlist_AddSDModules( p_playlist, psz_modules );
683 if( psz_modules ) free( psz_modules );
686 * Load background interfaces
688 psz_modules = config_GetPsz( p_libvlc, "extraintf" );
689 psz_control = config_GetPsz( p_libvlc, "control" );
691 if( psz_modules && *psz_modules && psz_control && *psz_control )
693 psz_modules = (char *)realloc( psz_modules, strlen( psz_modules ) +
694 strlen( psz_control ) + 1 );
695 sprintf( psz_modules, "%s:%s", psz_modules, psz_control );
697 else if( psz_control && *psz_control )
699 if( psz_modules ) free( psz_modules );
700 psz_modules = strdup( psz_control );
703 psz_parser = psz_modules;
704 while ( psz_parser && *psz_parser )
706 char *psz_module, *psz_temp;
707 psz_module = psz_parser;
708 psz_parser = strchr( psz_module, ':' );
714 psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
717 sprintf( psz_temp, "%s,none", psz_module );
718 VLC_AddIntf( 0, psz_temp, VLC_FALSE, VLC_FALSE );
728 * Always load the hotkeys interface if it exists
730 VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
733 * If needed, load the Xscreensaver interface
734 * Currently, only for X
736 #ifdef HAVE_X11_XLIB_H
737 if( config_GetInt( p_libvlc, "disable-screensaver" ) == 1 )
739 VLC_AddIntf( 0, "screensaver,none", VLC_FALSE, VLC_FALSE );
743 if( config_GetInt( p_libvlc, "file-logging" ) == 1 )
745 VLC_AddIntf( 0, "logger,none", VLC_FALSE, VLC_FALSE );
748 if( config_GetInt( p_libvlc, "syslog" ) == 1 )
750 char *psz_logmode = "logmode=syslog";
751 libvlc_InternalAddIntf( 0, "logger,none", VLC_FALSE, VLC_FALSE,
756 if( config_GetInt( p_libvlc, "show-intf" ) == 1 )
758 VLC_AddIntf( 0, "showintf,none", VLC_FALSE, VLC_FALSE );
761 if( config_GetInt( p_libvlc, "network-synchronisation") == 1 )
763 VLC_AddIntf( 0, "netsync,none", VLC_FALSE, VLC_FALSE );
767 * FIXME: kludge to use a p_libvlc-local variable for the Mozilla plugin
769 var_Create( p_libvlc, "drawable", VLC_VAR_INTEGER );
770 var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER );
771 var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER );
772 var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER );
773 var_Create( p_libvlc, "drawable-view-right", VLC_VAR_INTEGER );
774 var_Create( p_libvlc, "drawable-clip-top", VLC_VAR_INTEGER );
775 var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER );
776 var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER );
777 var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER );
779 /* Create volume callback system. */
780 var_Create( p_libvlc, "volume-change", VLC_VAR_BOOL );
783 * Get input filenames given as commandline arguments
785 GetFilenames( p_libvlc, i_argc, ppsz_argv );
788 * Get --open argument
790 var_Create( p_libvlc, "open", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
791 var_Get( p_libvlc, "open", &val );
792 if ( val.psz_string != NULL && *val.psz_string )
794 VLC_AddTarget( p_libvlc->i_object_id, val.psz_string, NULL, 0,
795 PLAYLIST_INSERT, 0 );
797 if ( val.psz_string != NULL ) free( val.psz_string );
803 * Cleanup a libvlc instance. The instance is not completely deallocated
804 * \param p_libvlc the instance to clean
806 int libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
808 intf_thread_t * p_intf;
809 vout_thread_t * p_vout;
810 aout_instance_t * p_aout;
811 announce_handler_t * p_announce;
813 /* Ask the interfaces to stop and destroy them */
814 msg_Dbg( p_libvlc, "removing all interfaces" );
815 while( (p_intf = vlc_object_find( p_libvlc, VLC_OBJECT_INTF, FIND_CHILD )) )
817 intf_StopThread( p_intf );
818 vlc_object_detach( p_intf );
819 vlc_object_release( p_intf );
820 intf_Destroy( p_intf );
824 msg_Dbg( p_libvlc, "removing playlist" );
825 playlist_ThreadDestroy( p_libvlc->p_playlist );
827 /* Free video outputs */
828 msg_Dbg( p_libvlc, "removing all video outputs" );
829 while( (p_vout = vlc_object_find( p_libvlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
831 vlc_object_detach( p_vout );
832 vlc_object_release( p_vout );
833 vout_Destroy( p_vout );
836 /* Free audio outputs */
837 msg_Dbg( p_libvlc, "removing all audio outputs" );
838 while( (p_aout = vlc_object_find( p_libvlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
840 vlc_object_detach( (vlc_object_t *)p_aout );
841 vlc_object_release( (vlc_object_t *)p_aout );
842 aout_Delete( p_aout );
845 stats_TimersDumpAll( p_libvlc );
846 stats_TimersClean( p_libvlc );
848 /* Free announce handler(s?) */
849 while( (p_announce = vlc_object_find( p_libvlc, VLC_OBJECT_ANNOUNCE,
852 msg_Dbg( p_libvlc, "removing announce handler" );
853 vlc_object_detach( p_announce );
854 vlc_object_release( p_announce );
855 announce_HandlerDestroy( p_announce );
861 * Destroy everything.
862 * This function requests the running threads to finish, waits for their
863 * termination, and destroys their structure.
864 * It stops the thread systems: no instance can run after this has run
865 * \param p_libvlc the instance to destroy
866 * \param b_release whether we should do a release on the instance
868 int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release )
872 if( p_libvlc->p_memcpy_module )
874 module_Unneed( p_libvlc, p_libvlc->p_memcpy_module );
875 p_libvlc->p_memcpy_module = NULL;
878 /* Free module bank. It is refcounted, so we call this each time */
879 module_EndBank( p_libvlc );
881 FREENULL( p_libvlc->psz_homedir );
882 FREENULL( p_libvlc->psz_userdir );
883 FREENULL( p_libvlc->psz_configfile );
884 FREENULL( p_libvlc->p_hotkeys );
886 var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
887 var_Get( p_libvlc_global, "libvlc", &lockval );
888 vlc_mutex_lock( lockval.p_address );
891 if( i_instances == 0 )
893 /* System specific cleaning code */
894 system_End( p_libvlc );
896 /* Destroy global iconv */
899 vlc_mutex_unlock( lockval.p_address );
900 var_Destroy( p_libvlc_global, "libvlc" );
902 msg_Flush( p_libvlc );
903 msg_Destroy( p_libvlc );
905 /* Destroy mutexes */
906 vlc_mutex_destroy( &p_libvlc->config_lock );
908 vlc_object_detach( p_libvlc );
909 if( b_release ) vlc_object_release( p_libvlc );
910 vlc_object_destroy( p_libvlc );
912 /* Stop thread system: last one out please shut the door!
913 * The number of initializations of the thread system is counted, we
914 * can call this each time */
915 vlc_threads_end( p_libvlc_global );
921 * Add an interface plugin and run it
923 int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc,
924 char const *psz_module,
925 vlc_bool_t b_block, vlc_bool_t b_play,
926 int i_options, char **ppsz_options )
929 intf_thread_t *p_intf;
932 if( p_libvlc->p_libvlc_global->b_daemon && b_block && !psz_module )
935 * We prefer the dummy interface if none is specified. */
936 char *psz_interface = config_GetPsz( p_libvlc, "intf" );
937 if( !psz_interface || !*psz_interface ) psz_module = "dummy";
938 if( psz_interface ) free( psz_interface );
942 /* Try to create the interface */
943 p_intf = intf_Create( p_libvlc, psz_module ? psz_module : "$intf",
944 i_options, ppsz_options );
948 msg_Err( p_libvlc, "interface \"%s\" initialization failed",
953 /* Interface doesn't handle play on start so do it ourselves */
954 if( !p_intf->b_play && b_play )
955 playlist_Play( p_libvlc->p_playlist );
957 /* Try to run the interface */
958 p_intf->b_play = b_play;
959 p_intf->b_block = b_block;
960 i_err = intf_RunThread( p_intf );
963 vlc_object_detach( p_intf );
964 intf_Destroy( p_intf );
971 /*****************************************************************************
972 * SetLanguage: set the interface language.
973 *****************************************************************************
974 * We set the LC_MESSAGES locale category for interface messages and buttons,
975 * as well as the LC_CTYPE category for string sorting and possible wide
977 *****************************************************************************/
978 static void SetLanguage ( char const *psz_lang )
980 #if defined( ENABLE_NLS ) \
981 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
984 #if defined( __APPLE__ ) || defined ( WIN32 ) || defined( SYS_BEOS )
988 if( psz_lang && !*psz_lang )
990 # if defined( HAVE_LC_MESSAGES )
991 setlocale( LC_MESSAGES, psz_lang );
993 setlocale( LC_CTYPE, psz_lang );
998 /* I need that under Darwin, please check it doesn't disturb
999 * other platforms. --Meuuh */
1000 setenv( "LANG", psz_lang, 1 );
1002 #elif defined( SYS_BEOS ) || defined( WIN32 )
1003 /* We set LC_ALL manually because it is the only way to set
1004 * the language at runtime under eg. Windows. Beware that this
1005 * makes the environment unconsistent when libvlc is unloaded and
1006 * should probably be moved to a safer place like vlc.c. */
1007 static char psz_lcall[20];
1008 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
1009 psz_lcall[19] = '\0';
1010 putenv( psz_lcall );
1013 setlocale( LC_ALL, psz_lang );
1016 /* Specify where to find the locales for current domain */
1017 #if !defined( __APPLE__ ) && !defined( WIN32 ) && !defined( SYS_BEOS )
1018 psz_path = LOCALEDIR;
1020 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc_global.psz_vlcpath,
1024 if( !bindtextdomain( PACKAGE_NAME, psz_path ) )
1026 fprintf( stderr, "warning: couldn't bind domain %s in directory %s\n",
1027 PACKAGE_NAME, psz_path );
1030 /* Set the default domain */
1031 bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
1035 /*****************************************************************************
1036 * GetFilenames: parse command line options which are not flags
1037 *****************************************************************************
1038 * Parse command line for input files as well as their associated options.
1039 * An option always follows its associated input and begins with a ":".
1040 *****************************************************************************/
1041 static int GetFilenames( libvlc_int_t *p_vlc, int i_argc, char *ppsz_argv[] )
1043 int i_opt, i_options;
1045 /* We assume that the remaining parameters are filenames
1046 * and their input options */
1047 for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
1049 const char *psz_target;
1052 /* Count the input options */
1053 while( *ppsz_argv[ i_opt ] == ':' && i_opt > optind )
1059 /* TODO: write an internal function of this one, to avoid
1060 * unnecessary lookups. */
1061 /* FIXME: should we convert options to UTF-8 as well ?? */
1062 psz_target = FromLocale( ppsz_argv[ i_opt ] );
1063 VLC_AddTarget( p_vlc->i_object_id, psz_target,
1064 (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
1066 PLAYLIST_INSERT, 0 );
1067 LocaleFree( psz_target );
1073 /*****************************************************************************
1074 * Help: print program help
1075 *****************************************************************************
1076 * Print a short inline help. Message interface is initialized at this stage.
1077 *****************************************************************************/
1078 static void Help( libvlc_int_t *p_this, char const *psz_help_name )
1081 ShowConsole( VLC_TRUE );
1084 if( psz_help_name && !strcmp( psz_help_name, "help" ) )
1086 utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
1087 Usage( p_this, "help" );
1088 Usage( p_this, "main" );
1090 else if( psz_help_name && !strcmp( psz_help_name, "longhelp" ) )
1092 utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
1093 Usage( p_this, NULL );
1095 else if( psz_help_name )
1097 Usage( p_this, psz_help_name );
1100 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1105 /*****************************************************************************
1106 * Usage: print module usage
1107 *****************************************************************************
1108 * Print a short inline help. Message interface is initialized at this stage.
1109 *****************************************************************************/
1110 static void Usage( libvlc_int_t *p_this, char const *psz_module_name )
1112 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
1113 /* short option ------' | | | | | | |
1114 * option name ------------' | | | | | |
1115 * <bra ---------------------' | | | | |
1116 * option type or "" ----------' | | | |
1117 * ket> -------------------------' | | |
1118 * padding spaces -----------------' | |
1119 * comment --------------------------' |
1120 * comment suffix ---------------------'
1122 * The purpose of having bra and ket is that we might i18n them as well.
1124 #define LINE_START 8
1125 #define PADDING_SPACES 25
1128 module_config_t *p_item;
1129 char psz_spaces_text[PADDING_SPACES+LINE_START+1];
1130 char psz_spaces_longtext[LINE_START+3];
1131 char psz_format[sizeof(FORMAT_STRING)];
1132 char psz_buffer[10000];
1135 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
1136 vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" );
1137 vlc_bool_t b_description;
1139 memset( psz_spaces_text, ' ', PADDING_SPACES+LINE_START );
1140 psz_spaces_text[PADDING_SPACES+LINE_START] = '\0';
1141 memset( psz_spaces_longtext, ' ', LINE_START+2 );
1142 psz_spaces_longtext[LINE_START+2] = '\0';
1144 strcpy( psz_format, FORMAT_STRING );
1146 /* List all modules */
1147 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1149 /* Enumerate the config for each module */
1150 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1152 vlc_bool_t b_help_module;
1154 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1156 if( psz_module_name && strcmp( psz_module_name,
1157 p_parser->psz_object_name ) )
1162 /* Ignore modules without config options */
1163 if( !p_parser->i_config_items )
1168 /* Ignore modules with only advanced config options if requested */
1171 for( p_item = p_parser->p_config;
1172 p_item->i_type != CONFIG_HINT_END;
1175 if( (p_item->i_type & CONFIG_ITEM) &&
1176 !p_item->b_advanced ) break;
1178 if( p_item->i_type == CONFIG_HINT_END ) continue;
1181 /* Print name of module */
1182 if( strcmp( "main", p_parser->psz_object_name ) )
1183 utf8_fprintf( stdout, "\n %s\n", p_parser->psz_longname );
1185 b_help_module = !strcmp( "help", p_parser->psz_object_name );
1187 /* Print module options */
1188 for( p_item = p_parser->p_config;
1189 p_item->i_type != CONFIG_HINT_END;
1192 char *psz_text, *psz_spaces = psz_spaces_text;
1193 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1194 char *psz_suf = "", *psz_prefix = NULL;
1197 /* Skip deprecated options */
1198 if( p_item->psz_current )
1202 /* Skip advanced options if requested */
1203 if( p_item->b_advanced && !b_advanced )
1208 switch( p_item->i_type )
1210 case CONFIG_HINT_CATEGORY:
1211 case CONFIG_HINT_USAGE:
1212 if( !strcmp( "main", p_parser->psz_object_name ) )
1213 utf8_fprintf( stdout, "\n %s\n", p_item->psz_text );
1216 case CONFIG_ITEM_STRING:
1217 case CONFIG_ITEM_FILE:
1218 case CONFIG_ITEM_DIRECTORY:
1219 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
1220 case CONFIG_ITEM_MODULE_CAT:
1221 case CONFIG_ITEM_MODULE_LIST:
1222 case CONFIG_ITEM_MODULE_LIST_CAT:
1223 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
1225 if( p_item->ppsz_list )
1228 psz_type = psz_buffer;
1230 for( i = 0; p_item->ppsz_list[i]; i++ )
1232 if( i ) strcat( psz_type, "," );
1233 strcat( psz_type, p_item->ppsz_list[i] );
1238 case CONFIG_ITEM_INTEGER:
1239 case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
1240 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
1242 if( p_item->i_list )
1245 psz_type = psz_buffer;
1247 for( i = 0; p_item->ppsz_list_text[i]; i++ )
1249 if( i ) strcat( psz_type, ", " );
1250 sprintf( psz_type + strlen(psz_type), "%i (%s)",
1252 p_item->ppsz_list_text[i] );
1257 case CONFIG_ITEM_FLOAT:
1258 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
1260 case CONFIG_ITEM_BOOL:
1261 psz_bra = ""; psz_type = ""; psz_ket = "";
1262 if( !b_help_module )
1264 psz_suf = p_item->i_value ? _(" (default enabled)") :
1265 _(" (default disabled)");
1275 /* Add short option if any */
1276 if( p_item->i_short )
1278 sprintf( psz_short, "-%c,", p_item->i_short );
1282 strcpy( psz_short, " " );
1285 i = PADDING_SPACES - strlen( p_item->psz_name )
1286 - strlen( psz_bra ) - strlen( psz_type )
1287 - strlen( psz_ket ) - 1;
1289 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1291 psz_prefix = ", --no-";
1292 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
1297 psz_spaces[0] = '\n';
1302 psz_spaces[i] = '\0';
1305 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1307 utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1308 psz_prefix, p_item->psz_name, psz_bra, psz_type,
1309 psz_ket, psz_spaces );
1313 utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1314 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
1317 psz_spaces[i] = ' ';
1319 /* We wrap the rest of the output */
1320 sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
1321 b_description = config_GetInt( p_this, "help-verbose" );
1324 psz_text = psz_buffer;
1327 char *psz_parser, *psz_word;
1328 size_t i_end = strlen( psz_text );
1330 /* If the remaining text fits in a line, print it. */
1331 if( i_end <= (size_t)i_width )
1333 utf8_fprintf( stdout, "%s\n", psz_text );
1337 /* Otherwise, eat as many words as possible */
1338 psz_parser = psz_text;
1341 psz_word = psz_parser;
1342 psz_parser = strchr( psz_word, ' ' );
1343 /* If no space was found, we reached the end of the text
1344 * block; otherwise, we skip the space we just found. */
1345 psz_parser = psz_parser ? psz_parser + 1
1348 } while( psz_parser - psz_text <= i_width );
1350 /* We cut a word in one of these cases:
1351 * - it's the only word in the line and it's too long.
1352 * - we used less than 80% of the width and the word we are
1353 * going to wrap is longer than 40% of the width, and even
1354 * if the word would have fit in the next line. */
1355 if( psz_word == psz_text
1356 || ( psz_word - psz_text < 80 * i_width / 100
1357 && psz_parser - psz_word > 40 * i_width / 100 ) )
1359 char c = psz_text[i_width];
1360 psz_text[i_width] = '\0';
1361 utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
1362 psz_text += i_width;
1367 psz_word[-1] = '\0';
1368 utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
1369 psz_text = psz_word;
1373 if( b_description && p_item->psz_longtext )
1375 sprintf( psz_buffer, "%s%s", p_item->psz_longtext, psz_suf );
1376 b_description = VLC_FALSE;
1377 psz_spaces = psz_spaces_longtext;
1378 utf8_fprintf( stdout, "%s", psz_spaces );
1384 /* Release the module list */
1385 vlc_list_release( p_list );
1388 /*****************************************************************************
1389 * ListModules: list the available modules with their description
1390 *****************************************************************************
1391 * Print a list of all available modules (builtins and plugins) and a short
1392 * description for each one.
1393 *****************************************************************************/
1394 static void ListModules( libvlc_int_t *p_this )
1398 char psz_spaces[22];
1401 memset( psz_spaces, ' ', 22 );
1404 ShowConsole( VLC_TRUE );
1407 /* List all modules */
1408 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1410 /* Enumerate each module */
1411 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1415 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1417 /* Nasty hack, but right now I'm too tired to think about a nice
1419 i = 22 - strlen( p_parser->psz_object_name ) - 1;
1423 utf8_fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
1424 psz_spaces, p_parser->psz_longname );
1426 psz_spaces[i] = ' ';
1429 vlc_list_release( p_list );
1431 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1436 /*****************************************************************************
1437 * Version: print complete program version
1438 *****************************************************************************
1439 * Print complete program version and build number.
1440 *****************************************************************************/
1441 static void Version( void )
1444 ShowConsole( VLC_TRUE );
1447 utf8_fprintf( stdout, _("VLC version %s\n"), VLC_Version() );
1448 utf8_fprintf( stdout, _("Compiled by %s@%s.%s\n"),
1449 VLC_CompileBy(), VLC_CompileHost(), VLC_CompileDomain() );
1450 utf8_fprintf( stdout, _("Compiler: %s\n"), VLC_Compiler() );
1451 #ifndef HAVE_SHARED_LIBVLC
1452 if( strcmp( VLC_Changeset(), "exported" ) )
1453 utf8_fprintf( stdout, _("Based upon svn changeset [%s]\n"),
1456 utf8_fprintf( stdout, LICENSE_MSG );
1458 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1463 /*****************************************************************************
1464 * ShowConsole: On Win32, create an output console for debug messages
1465 *****************************************************************************
1466 * This function is useful only on Win32.
1467 *****************************************************************************/
1469 static void ShowConsole( vlc_bool_t b_dofile )
1474 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
1478 freopen( "CONOUT$", "w", stderr );
1479 freopen( "CONIN$", "r", stdin );
1481 if( b_dofile && (f_help = fopen( "vlc-help.txt", "wt" )) )
1484 freopen( "vlc-help.txt", "wt", stdout );
1485 utf8_fprintf( stderr, _("\nDumped content to vlc-help.txt file.\n") );
1488 else freopen( "CONOUT$", "w", stdout );
1494 /*****************************************************************************
1495 * PauseConsole: On Win32, wait for a key press before closing the console
1496 *****************************************************************************
1497 * This function is useful only on Win32.
1498 *****************************************************************************/
1500 static void PauseConsole( void )
1504 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
1506 utf8_fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
1514 /*****************************************************************************
1515 * ConsoleWidth: Return the console width in characters
1516 *****************************************************************************
1517 * We use the stty shell command to get the console width; if this fails or
1518 * if the width is less than 80, we default to 80.
1519 *****************************************************************************/
1520 static int ConsoleWidth( void )
1525 char buf[20], *psz_parser;
1529 file = popen( "stty size 2>/dev/null", "r" );
1532 i_ret = fread( buf, 1, 20, file );
1536 psz_parser = strchr( buf, ' ' );
1539 i_ret = atoi( psz_parser + 1 );
1554 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
1555 vlc_value_t old_val, vlc_value_t new_val, void *param)
1557 libvlc_int_t *p_libvlc = (libvlc_int_t *)p_this;
1559 if( new_val.i_int >= -1 )
1561 p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );
1566 /*****************************************************************************
1567 * InitDeviceValues: initialize device values
1568 *****************************************************************************
1569 * This function inits the dvd, vcd and cd-audio values
1570 *****************************************************************************/
1571 static void InitDeviceValues( libvlc_int_t *p_vlc )
1574 LibHalContext * ctx;
1579 DBusConnection *p_connection;
1583 ctx = libhal_ctx_new();
1585 dbus_error_init( &error );
1586 p_connection = dbus_bus_get ( DBUS_BUS_SYSTEM, &error );
1587 if( dbus_error_is_set( &error ) )
1589 dbus_error_free( &error );
1592 libhal_ctx_set_dbus_connection( ctx, p_connection );
1593 if( libhal_ctx_init( ctx, &error ) )
1595 if( ( ctx = hal_initialize( NULL, FALSE ) ) )
1599 if( ( devices = libhal_get_all_devices( ctx, &i_devices, NULL ) ) )
1601 if( ( devices = hal_get_all_devices( ctx, &i_devices ) ) )
1604 for( i = 0; i < i_devices; i++ )
1607 if( !libhal_device_property_exists( ctx, devices[i],
1608 "storage.cdrom.dvd", NULL ) )
1610 if( !hal_device_property_exists( ctx, devices[ i ],
1611 "storage.cdrom.dvd" ) )
1617 b_dvd = libhal_device_get_property_bool( ctx, devices[ i ],
1618 "storage.cdrom.dvd", NULL );
1619 block_dev = libhal_device_get_property_string( ctx,
1620 devices[ i ], "block.device" , NULL );
1622 b_dvd = hal_device_get_property_bool( ctx, devices[ i ],
1623 "storage.cdrom.dvd" );
1624 block_dev = hal_device_get_property_string( ctx, devices[ i ],
1629 config_PutPsz( p_vlc, "dvd", block_dev );
1632 config_PutPsz( p_vlc, "vcd", block_dev );
1633 config_PutPsz( p_vlc, "cd-audio", block_dev );
1635 libhal_free_string( block_dev );
1637 hal_free_string( block_dev );
1641 libhal_free_string_array( devices );
1643 hal_free_string_array( devices );
1648 libhal_ctx_shutdown( ctx, NULL );
1650 hal_shutdown( ctx );
1655 msg_Warn( p_vlc, "Unable to get HAL device properties" );