]> git.sesse.net Git - vlc/blobdiff - src/libvlc.c
- bootstrap: removed vlcintf.h
[vlc] / src / libvlc.c
index 2e22fa43395665479407e319e714733234c28788..a006aae9c3ac0587c96236faf1b1c39d15654de5 100644 (file)
@@ -1,13 +1,14 @@
 /*****************************************************************************
  * libvlc.c: main libvlc source
  *****************************************************************************
- * Copyright (C) 1998-2004 the VideoLAN team
+ * Copyright (C) 1998-2006 the VideoLAN team
  * $Id$
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
  *          Gildas Bazin <gbazin@videolan.org>
  *          Derk-Jan Hartman <hartman at videolan dot org>
+ *          RĂ©mi Denis-Courmont <rem # videolan : org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,7 +22,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -92,8 +93,12 @@ static vlc_t *    p_static_vlc;
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static void LocaleInit( void );
-static void LocaleDeinit( void );
+static int AddIntfInternal( int i_object, char const *psz_module,
+                             vlc_bool_t b_block, vlc_bool_t b_play,
+                             int i_options, char **ppsz_options );
+
+void LocaleInit( vlc_object_t * );
+void LocaleDeinit( void );
 static void SetLanguage   ( char const * );
 static int  GetFilenames  ( vlc_t *, int, char *[] );
 static void Help          ( vlc_t *, char const *psz_help_name );
@@ -102,7 +107,7 @@ static void ListModules   ( vlc_t * );
 static void Version       ( void );
 
 #ifdef WIN32
-static void ShowConsole   ( void );
+static void ShowConsole   ( vlc_bool_t );
 static void PauseConsole  ( void );
 #endif
 static int  ConsoleWidth  ( void );
@@ -153,11 +158,13 @@ DECLARE_VLC_VERSION( CompileHost, COMPILE_HOST );
 DECLARE_VLC_VERSION( CompileDomain, COMPILE_DOMAIN );
 DECLARE_VLC_VERSION( Compiler, COMPILER );
 
+#ifndef HAVE_SHARED_LIBVLC
 extern const char psz_vlc_changeset[];
 char const * VLC_Changeset( void )
 {
     return psz_vlc_changeset;
 }
+#endif
 
 /*****************************************************************************
  * VLC_Error: strerror() equivalent
@@ -225,9 +232,6 @@ int VLC_Create( void )
         libvlc.p_module_bank = NULL;
 
         libvlc.b_ready = VLC_TRUE;
-
-        /* UTF-8 convertor are initialized after the locale */
-        libvlc.from_locale = libvlc.to_locale = (vlc_iconv_t)(-1);
     }
     vlc_mutex_unlock( lockval.p_address );
     var_Destroy( p_libvlc, "libvlc" );
@@ -244,7 +248,7 @@ int VLC_Create( void )
 
     /* Initialize mutexes */
     vlc_mutex_init( p_vlc, &p_vlc->config_lock );
-#ifdef SYS_DARWIN
+#ifdef __APPLE__
     vlc_mutex_init( p_vlc, &p_vlc->quicktime_lock );
     vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW );
 #endif
@@ -275,13 +279,16 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
     char *       psz_parser;
     char *       psz_control;
     vlc_bool_t   b_exit = VLC_FALSE;
+    int          i_ret = VLC_EEXIT;
     vlc_t *      p_vlc = vlc_current_object( i_object );
     module_t    *p_help_module;
     playlist_t  *p_playlist;
     vlc_value_t  val;
 #if defined( ENABLE_NLS ) \
      && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
+# if defined (WIN32) || defined (__APPLE__)
     char *       psz_language;
+#endif
 #endif
 
     if( !p_vlc )
@@ -318,7 +325,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
      * Global iconv, must be done after setlocale()
      * so that vlc_current_charset() works.
      */
-    LocaleInit();
+    LocaleInit( (vlc_object_t *)p_vlc );
 
     /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
     msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
@@ -358,12 +365,14 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
     {
         Help( p_vlc, "help" );
         b_exit = VLC_TRUE;
+        i_ret = VLC_EEXITSUCCESS;
     }
     /* Check for version option */
     else if( config_GetInt( p_vlc, "version" ) )
     {
         Version();
         b_exit = VLC_TRUE;
+        i_ret = VLC_EEXITSUCCESS;
     }
 
     /* Set the config file stuff */
@@ -410,6 +419,33 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
 
         p_vlc->p_libvlc->b_daemon = VLC_TRUE;
 
+        /* lets check if we need to write the pidfile */
+        char * psz_pidfile = config_GetPsz( p_vlc, "pidfile" );
+        
+        msg_Dbg( p_vlc, "psz_pidfile is %s", psz_pidfile );
+        
+        if( psz_pidfile != NULL )
+        {
+            FILE *pidfile;
+            pid_t i_pid = getpid ();
+            
+            msg_Dbg( p_vlc, "our PID is %d, writing it to %s", i_pid, psz_pidfile );
+            
+            pidfile = utf8_fopen( psz_pidfile,"w" );
+            if( pidfile != NULL )
+            {
+                utf8_fprintf( pidfile, "%d", (int)i_pid );
+                fclose( pidfile );
+            }
+            else
+            {
+                msg_Err( p_vlc, "Cannot open pid file for writing: %s, error: %s", 
+                        psz_pidfile, strerror(errno) );
+            }
+        }
+
+        free( psz_pidfile );
+
 #else
         pid_t i_pid;
 
@@ -423,6 +459,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
             /* This is the parent, exit right now */
             msg_Dbg( p_vlc, "closing parent process" );
             b_exit = VLC_TRUE;
+            i_ret = VLC_EEXITSUCCESS;
         }
         else
         {
@@ -444,13 +481,13 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
         vlc_object_destroy( p_help_module );
         module_EndBank( p_vlc );
         if( i_object ) vlc_object_release( p_vlc );
-        return VLC_EEXIT;
+        return i_ret;
     }
 
     /* Check for translation config option */
 #if defined( ENABLE_NLS ) \
      && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
-
+# if defined (WIN32) || defined (__APPLE__)
     /* This ain't really nice to have to reload the config here but it seems
      * the only way to do it. */
     config_LoadConfigFile( p_vlc, "main" );
@@ -464,8 +501,6 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
 
         /* Reset the default domain */
         SetLanguage( psz_language );
-        LocaleDeinit();
-        LocaleInit();
 
         /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
         msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
@@ -477,6 +512,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
         libvlc.p_module_bank->b_cache_delete = b_cache_delete;
     }
     if( psz_language ) free( psz_language );
+# endif
 #endif
 
     /*
@@ -505,18 +541,21 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
         Help( p_vlc, p_tmp );
         free( p_tmp );
         b_exit = VLC_TRUE;
+        i_ret = VLC_EEXITSUCCESS;
     }
     /* Check for long help option */
     else if( config_GetInt( p_vlc, "longhelp" ) )
     {
         Help( p_vlc, "longhelp" );
         b_exit = VLC_TRUE;
+        i_ret = VLC_EEXITSUCCESS;
     }
     /* Check for module list option */
     else if( config_GetInt( p_vlc, "list" ) )
     {
         ListModules( p_vlc );
         b_exit = VLC_TRUE;
+        i_ret = VLC_EEXITSUCCESS;
     }
 
     /* Check for config file options */
@@ -547,7 +586,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
         vlc_object_destroy( p_help_module );
         module_EndBank( p_vlc );
         if( i_object ) vlc_object_release( p_vlc );
-        return VLC_EEXIT;
+        return i_ret;
     }
 
     /*
@@ -570,7 +609,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
     if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
     {
 #ifdef WIN32
-        ShowConsole();
+        ShowConsole( VLC_FALSE );
         /* Pause the console because it's destroyed when we exit */
         fprintf( stderr, "The command line options couldn't be loaded, check "
                  "that they are valid.\n" );
@@ -632,7 +671,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
     if( !config_GetInt( p_vlc, "sse2" ) )
         libvlc.i_cpu &= ~CPU_CAPABILITY_SSE2;
 #endif
-#if defined( __powerpc__ ) || defined( SYS_DARWIN )
+#if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
     if( !config_GetInt( p_vlc, "altivec" ) )
         libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
 #endif
@@ -673,6 +712,11 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
         p_vlc->pf_memset = memset;
     }
 
+    libvlc.b_stats = config_GetInt( p_vlc, "stats" );
+    libvlc.i_timers = 0;
+    libvlc.pp_timers = NULL;
+    vlc_mutex_init( p_vlc, &libvlc.timer_lock );
+
     /*
      * Initialize hotkey handling
      */
@@ -684,7 +728,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
     /*
      * Initialize playlist and get commandline files
      */
-    p_playlist = playlist_Create( p_vlc );
+    p_playlist = playlist_ThreadCreate( p_vlc );
     if( !p_playlist )
     {
         msg_Err( p_vlc, "playlist initialization failed" );
@@ -759,25 +803,44 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
 #ifdef HAVE_X11_XLIB_H
     if( config_GetInt( p_vlc, "disable-screensaver" ) == 1 )
     {
-        VLC_AddIntf( 0, "screensaver", VLC_FALSE, VLC_FALSE );
+        VLC_AddIntf( 0, "screensaver,none", VLC_FALSE, VLC_FALSE );
+    }
+#endif
+
+    if( config_GetInt( p_vlc, "file-logging" ) == 1 )
+    {
+        VLC_AddIntf( 0, "logger,none", VLC_FALSE, VLC_FALSE );
+    }
+#ifdef HAVE_SYSLOG_H
+    if( config_GetInt( p_vlc, "syslog" ) == 1 )
+    {
+        char *psz_logmode = "logmode=syslog";
+        AddIntfInternal( 0, "logger,none", VLC_FALSE, VLC_FALSE, 1, &psz_logmode );
     }
 #endif
 
+    if( config_GetInt( p_vlc, "show-intf" ) == 1 )
+    {
+        VLC_AddIntf( 0, "showintf,none", VLC_FALSE, VLC_FALSE );
+    }
+
+    if( config_GetInt( p_vlc, "network-synchronisation") == 1 )
+    {
+        VLC_AddIntf( 0, "netsync,none", VLC_FALSE, VLC_FALSE );
+    }
+
     /*
      * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
      */
     var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
-    var_Create( p_vlc, "drawableredraw", VLC_VAR_INTEGER );
-    var_Create( p_vlc, "drawablet", VLC_VAR_INTEGER );
-    var_Create( p_vlc, "drawablel", VLC_VAR_INTEGER );
-    var_Create( p_vlc, "drawableb", VLC_VAR_INTEGER );
-    var_Create( p_vlc, "drawabler", VLC_VAR_INTEGER );
-    var_Create( p_vlc, "drawablex", VLC_VAR_INTEGER );
-    var_Create( p_vlc, "drawabley", VLC_VAR_INTEGER );
-    var_Create( p_vlc, "drawablew", VLC_VAR_INTEGER );
-    var_Create( p_vlc, "drawableh", VLC_VAR_INTEGER );
-    var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER );
-    var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER );
+    var_Create( p_vlc, "drawable-view-top", VLC_VAR_INTEGER );
+    var_Create( p_vlc, "drawable-view-left", VLC_VAR_INTEGER );
+    var_Create( p_vlc, "drawable-view-bottom", VLC_VAR_INTEGER );
+    var_Create( p_vlc, "drawable-view-right", VLC_VAR_INTEGER );
+    var_Create( p_vlc, "drawable-clip-top", VLC_VAR_INTEGER );
+    var_Create( p_vlc, "drawable-clip-left", VLC_VAR_INTEGER );
+    var_Create( p_vlc, "drawable-clip-bottom", VLC_VAR_INTEGER );
+    var_Create( p_vlc, "drawable-clip-right", VLC_VAR_INTEGER );
 
     /* Create volume callback system. */
     var_Create( p_vlc, "volume-change", VLC_VAR_BOOL );
@@ -815,55 +878,10 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
 int VLC_AddIntf( int i_object, char const *psz_module,
                  vlc_bool_t b_block, vlc_bool_t b_play )
 {
-    int i_err;
-    intf_thread_t *p_intf;
-    vlc_t *p_vlc = vlc_current_object( i_object );
-
-    if( !p_vlc )
-    {
-        return VLC_ENOOBJ;
-    }
-
-#ifndef WIN32
-    if( p_vlc->p_libvlc->b_daemon && b_block && !psz_module )
-    {
-        /* Daemon mode hack.
-         * We prefer the dummy interface if none is specified. */
-        char *psz_interface = config_GetPsz( p_vlc, "intf" );
-        if( !psz_interface || !*psz_interface ) psz_module = "dummy";
-        if( psz_interface ) free( psz_interface );
-    }
-#endif
-
-    /* Try to create the interface */
-    p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf" );
-
-    if( p_intf == NULL )
-    {
-        msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
-        if( i_object ) vlc_object_release( p_vlc );
-        return VLC_EGENERIC;
-    }
-
-    /* Interface doesn't handle play on start so do it ourselves */
-    if( !p_intf->b_play && b_play ) VLC_Play( i_object );
-
-    /* Try to run the interface */
-    p_intf->b_play = b_play;
-    p_intf->b_block = b_block;
-    i_err = intf_RunThread( p_intf );
-    if( i_err )
-    {
-        vlc_object_detach( p_intf );
-        intf_Destroy( p_intf );
-        if( i_object ) vlc_object_release( p_vlc );
-        return i_err;
-    }
-
-    if( i_object ) vlc_object_release( p_vlc );
-    return VLC_SUCCESS;
+    return AddIntfInternal( i_object, psz_module, b_block, b_play, 0, NULL );
 }
 
+
 /*****************************************************************************
  * VLC_Die: ask vlc to die.
  *****************************************************************************
@@ -916,15 +934,15 @@ int VLC_CleanUp( int i_object )
     }
 
     /*
-     * Free playlists
+     * Free playlist
      */
-    msg_Dbg( p_vlc, "removing all playlists" );
+    msg_Dbg( p_vlc, "removing playlist handler" );
     while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
                                           FIND_CHILD )) )
     {
         vlc_object_detach( p_playlist );
         vlc_object_release( p_playlist );
-        playlist_Destroy( p_playlist );
+        playlist_ThreadDestroy( p_playlist );
     }
 
     /*
@@ -949,17 +967,20 @@ int VLC_CleanUp( int i_object )
         aout_Delete( p_aout );
     }
 
+    stats_TimersDumpAll( p_vlc );
+    stats_TimersClean( p_vlc );
+
     /*
      * Free announce handler(s?)
      */
-    msg_Dbg( p_vlc, "removing announce handler" );
     while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE,
                                                  FIND_CHILD ) ) )
-   {
+    {
+        msg_Dbg( p_vlc, "removing announce handler" );
         vlc_object_detach( p_announce );
         vlc_object_release( p_announce );
         announce_HandlerDestroy( p_announce );
-   }
+    }
 
     if( i_object ) vlc_object_release( p_vlc );
     return VLC_SUCCESS;
@@ -1198,7 +1219,7 @@ int VLC_AddTarget( int i_object, char const *psz_target,
     if( p_playlist == NULL )
     {
         msg_Dbg( p_vlc, "no playlist present, creating one" );
-        p_playlist = playlist_Create( p_vlc );
+        p_playlist = playlist_ThreadCreate( p_vlc );
 
         if( p_playlist == NULL )
         {
@@ -1209,7 +1230,7 @@ int VLC_AddTarget( int i_object, char const *psz_target,
         vlc_object_yield( p_playlist );
     }
 
-    i_err = playlist_AddExt( p_playlist, psz_target, psz_target,
+    i_err = playlist_PlaylistAddExt( p_playlist, psz_target, psz_target,
                              i_mode, i_pos, -1, ppsz_options, i_options);
 
     vlc_object_release( p_playlist );
@@ -1277,7 +1298,7 @@ int VLC_Pause( int i_object )
 }
 
 /*****************************************************************************
- * VLC_Pause: toggle pause
+ * VLC_Stop: stop playback
  *****************************************************************************/
 int VLC_Stop( int i_object )
 {
@@ -1312,7 +1333,6 @@ vlc_bool_t VLC_IsPlaying( int i_object )
 {
     playlist_t * p_playlist;
     vlc_bool_t   b_playing;
-    vlc_value_t  val;
 
     vlc_t *p_vlc = vlc_current_object( i_object );
 
@@ -1329,13 +1349,17 @@ vlc_bool_t VLC_IsPlaying( int i_object )
         if( i_object ) vlc_object_release( p_vlc );
         return VLC_ENOOBJ;
     }
-    if( !p_playlist->p_input )
+
+    if( p_playlist->p_input )
     {
-        if( i_object ) vlc_object_release( p_vlc );
-        return VLC_ENOOBJ;
+        vlc_value_t  val;
+        var_Get( p_playlist->p_input, "state", &val );
+        b_playing = ( val.i_int == PLAYING_S );
+    }
+    else
+    {
+        b_playing = playlist_IsPlaying( p_playlist );
     }
-    var_Get( p_playlist->p_input, "state", &val );
-    b_playing = ( val.i_int == PLAYING_S );
     vlc_object_release( p_playlist );
 
     if( i_object ) vlc_object_release( p_vlc );
@@ -1628,29 +1652,8 @@ float VLC_SpeedSlower( int i_object )
  */
 int VLC_PlaylistIndex( int i_object )
 {
-    int i_index;
-    playlist_t * p_playlist;
-    vlc_t *p_vlc = vlc_current_object( i_object );
-
-    /* Check that the handle is valid */
-    if( !p_vlc )
-    {
-        return VLC_ENOOBJ;
-    }
-
-    p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
-
-    if( !p_playlist )
-    {
-        if( i_object ) vlc_object_release( p_vlc );
-        return VLC_ENOOBJ;
-    }
-
-    i_index = p_playlist->i_index;
-    vlc_object_release( p_playlist );
-
-    if( i_object ) vlc_object_release( p_vlc );
-    return i_index;
+    printf( "This function is deprecated and should not be used anymore" );
+    return -1;
 }
 
 /**
@@ -1760,7 +1763,6 @@ int VLC_PlaylistPrev( int i_object )
  *****************************************************************************/
 int VLC_PlaylistClear( int i_object )
 {
-    int i_err;
     playlist_t * p_playlist;
     vlc_t *p_vlc = vlc_current_object( i_object );
 
@@ -1778,12 +1780,12 @@ int VLC_PlaylistClear( int i_object )
         return VLC_ENOOBJ;
     }
 
-    i_err = playlist_Clear( p_playlist );
+    playlist_Clear( p_playlist );
 
     vlc_object_release( p_playlist );
 
     if( i_object ) vlc_object_release( p_vlc );
-    return i_err;
+    return VLC_SUCCESS;
 }
 
 /**
@@ -1891,48 +1893,61 @@ int VLC_FullScreen( int i_object )
 
 /* following functions are local */
 
-static void LocaleInit( void )
+
+static int  AddIntfInternal( int i_object, char const *psz_module,
+                             vlc_bool_t b_block, vlc_bool_t b_play,
+                             int i_options, char **ppsz_options )
 {
-    char *psz_charset;
+    int i_err;
+    intf_thread_t *p_intf;
+    vlc_t *p_vlc = vlc_current_object( i_object );
 
-    if( !vlc_current_charset( &psz_charset ) )
+    if( !p_vlc )
+    {
+        return VLC_ENOOBJ;
+    }
+
+#ifndef WIN32
+    if( p_vlc->p_libvlc->b_daemon && b_block && !psz_module )
     {
-        char *psz_conv = psz_charset;
+        /* Daemon mode hack.
+         * We prefer the dummy interface if none is specified. */
+        char *psz_interface = config_GetPsz( p_vlc, "intf" );
+        if( !psz_interface || !*psz_interface ) psz_module = "dummy";
+        if( psz_interface ) free( psz_interface );
+    }
+#endif
 
-        /*
-         * Still allow non-ASCII characters when the locale is not set.
-         * Western Europeans are being favored for historical reasons.
-         */
-        psz_conv = strcmp( psz_charset, "ASCII" )
-            ? psz_charset
-            : "ISO-8859-15";
+    /* Try to create the interface */
+    p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf",
+                          i_options, ppsz_options );
 
-        vlc_mutex_init( p_libvlc, &libvlc.from_locale_lock );
-        vlc_mutex_init( p_libvlc, &libvlc.to_locale_lock );
-        libvlc.from_locale = vlc_iconv_open( "UTF-8", psz_charset );
-        libvlc.to_locale = vlc_iconv_open( psz_charset, "UTF-8" );
-        if( !libvlc.to_locale )
-        {
-            /* Not sure it is the right thing to do, but at least it
-             doesn't make vlc crash with msvc ! */
-            libvlc.to_locale = (vlc_iconv_t)(-1);
-        }
+    if( p_intf == NULL )
+    {
+        msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
+        if( i_object ) vlc_object_release( p_vlc );
+        return VLC_EGENERIC;
     }
-    else
-        libvlc.from_locale = libvlc.to_locale = (vlc_iconv_t)(-1);
-    free( psz_charset );
-}
 
-static void LocaleDeinit( void )
-{
-    if( libvlc.to_locale != (vlc_iconv_t)(-1) )
+    /* Interface doesn't handle play on start so do it ourselves */
+    if( !p_intf->b_play && b_play ) VLC_Play( i_object );
+
+    /* Try to run the interface */
+    p_intf->b_play = b_play;
+    p_intf->b_block = b_block;
+    i_err = intf_RunThread( p_intf );
+    if( i_err )
     {
-        vlc_mutex_destroy( &libvlc.from_locale_lock );
-        vlc_mutex_destroy( &libvlc.to_locale_lock );
-        vlc_iconv_close( libvlc.from_locale );
-        vlc_iconv_close( libvlc.to_locale );
+        vlc_object_detach( p_intf );
+        intf_Destroy( p_intf );
+        if( i_object ) vlc_object_release( p_vlc );
+        return i_err;
     }
-}
+
+    if( i_object ) vlc_object_release( p_vlc );
+    return VLC_SUCCESS;
+};
+
 
 /*****************************************************************************
  * SetLanguage: set the interface language.
@@ -1947,7 +1962,7 @@ static void SetLanguage ( char const *psz_lang )
      && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
 
     char *          psz_path;
-#if defined( SYS_DARWIN ) || defined ( WIN32 ) || defined( SYS_BEOS )
+#if defined( __APPLE__ ) || defined ( WIN32 ) || defined( SYS_BEOS )
     char            psz_tmp[1024];
 #endif
 
@@ -1960,7 +1975,7 @@ static void SetLanguage ( char const *psz_lang )
     }
     else if( psz_lang )
     {
-#ifdef SYS_DARWIN
+#ifdef __APPLE__
         /* I need that under Darwin, please check it doesn't disturb
          * other platforms. --Meuuh */
         setenv( "LANG", psz_lang, 1 );
@@ -1977,14 +1992,10 @@ static void SetLanguage ( char const *psz_lang )
 #endif
 
         setlocale( LC_ALL, psz_lang );
-        /* many code paths assume that float numbers are formatted according
-         * to the US standard (ie. with dot as decimal point), so we keep
-         * C for LC_NUMERIC. */
-        setlocale(LC_NUMERIC, "C" );
     }
 
     /* Specify where to find the locales for current domain */
-#if !defined( SYS_DARWIN ) && !defined( WIN32 ) && !defined( SYS_BEOS )
+#if !defined( __APPLE__ ) && !defined( WIN32 ) && !defined( SYS_BEOS )
     psz_path = LOCALEDIR;
 #else
     snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
@@ -1993,12 +2004,11 @@ static void SetLanguage ( char const *psz_lang )
 #endif
     if( !bindtextdomain( PACKAGE_NAME, psz_path ) )
     {
-        fprintf( stderr, "warning: no domain %s in directory %s\n",
+        fprintf( stderr, "warning: couldn't bind domain %s in directory %s\n",
                  PACKAGE_NAME, psz_path );
     }
 
     /* Set the default domain */
-    textdomain( PACKAGE_NAME );
     bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
 #endif
 }
@@ -2049,18 +2059,18 @@ static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
 static void Help( vlc_t *p_this, char const *psz_help_name )
 {
 #ifdef WIN32
-    ShowConsole();
+    ShowConsole( VLC_TRUE );
 #endif
 
     if( psz_help_name && !strcmp( psz_help_name, "help" ) )
     {
-        fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
+        utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
         Usage( p_this, "help" );
         Usage( p_this, "main" );
     }
     else if( psz_help_name && !strcmp( psz_help_name, "longhelp" ) )
     {
-        fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
+        utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
         Usage( p_this, NULL );
     }
     else if( psz_help_name )
@@ -2151,7 +2161,7 @@ static void Usage( vlc_t *p_this, char const *psz_module_name )
 
         /* Print name of module */
         if( strcmp( "main", p_parser->psz_object_name ) )
-        fprintf( stdout, "\n %s\n", p_parser->psz_longname );
+        utf8_fprintf( stdout, "\n %s\n", p_parser->psz_longname );
 
         b_help_module = !strcmp( "help", p_parser->psz_object_name );
 
@@ -2181,7 +2191,7 @@ static void Usage( vlc_t *p_this, char const *psz_module_name )
             case CONFIG_HINT_CATEGORY:
             case CONFIG_HINT_USAGE:
                 if( !strcmp( "main", p_parser->psz_object_name ) )
-                fprintf( stdout, "\n %s\n", p_item->psz_text );
+                utf8_fprintf( stdout, "\n %s\n", p_item->psz_text );
                 break;
 
             case CONFIG_ITEM_STRING:
@@ -2275,13 +2285,13 @@ static void Usage( vlc_t *p_this, char const *psz_module_name )
 
             if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
             {
-                fprintf( stdout, psz_format, psz_short, p_item->psz_name,
+                utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
                          psz_prefix, p_item->psz_name, psz_bra, psz_type,
                          psz_ket, psz_spaces );
             }
             else
             {
-                fprintf( stdout, psz_format, psz_short, p_item->psz_name,
+                utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
                          "", "", psz_bra, psz_type, psz_ket, psz_spaces );
             }
 
@@ -2301,7 +2311,7 @@ static void Usage( vlc_t *p_this, char const *psz_module_name )
                 /* If the remaining text fits in a line, print it. */
                 if( i_end <= (size_t)i_width )
                 {
-                    fprintf( stdout, "%s\n", psz_text );
+                    utf8_fprintf( stdout, "%s\n", psz_text );
                     break;
                 }
 
@@ -2329,14 +2339,14 @@ static void Usage( vlc_t *p_this, char const *psz_module_name )
                 {
                     char c = psz_text[i_width];
                     psz_text[i_width] = '\0';
-                    fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
+                    utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
                     psz_text += i_width;
                     psz_text[0] = c;
                 }
                 else
                 {
                     psz_word[-1] = '\0';
-                    fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
+                    utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
                     psz_text = psz_word;
                 }
             }
@@ -2346,7 +2356,7 @@ static void Usage( vlc_t *p_this, char const *psz_module_name )
                 sprintf( psz_buffer, "%s%s", p_item->psz_longtext, psz_suf );
                 b_description = VLC_FALSE;
                 psz_spaces = psz_spaces_longtext;
-                fprintf( stdout, "%s", psz_spaces );
+                utf8_fprintf( stdout, "%s", psz_spaces );
                 goto description;
             }
         }
@@ -2372,7 +2382,7 @@ static void ListModules( vlc_t *p_this )
     memset( psz_spaces, ' ', 22 );
 
 #ifdef WIN32
-    ShowConsole();
+    ShowConsole( VLC_TRUE );
 #endif
 
     /* List all modules */
@@ -2391,7 +2401,7 @@ static void ListModules( vlc_t *p_this )
         if( i < 0 ) i = 0;
         psz_spaces[i] = 0;
 
-        fprintf( stdout, "  %s%s %s\n", p_parser->psz_object_name,
+        utf8_fprintf( stdout, "  %s%s %s\n", p_parser->psz_object_name,
                          psz_spaces, p_parser->psz_longname );
 
         psz_spaces[i] = ' ';
@@ -2412,21 +2422,19 @@ static void ListModules( vlc_t *p_this )
 static void Version( void )
 {
 #ifdef WIN32
-    ShowConsole();
+    ShowConsole( VLC_TRUE );
 #endif
 
-    fprintf( stdout, _("VLC version %s\n"), VLC_Version() );
-    fprintf( stdout, _("Compiled by %s@%s.%s\n"),
+    utf8_fprintf( stdout, _("VLC version %s\n"), VLC_Version() );
+    utf8_fprintf( stdout, _("Compiled by %s@%s.%s\n"),
              VLC_CompileBy(), VLC_CompileHost(), VLC_CompileDomain() );
-    fprintf( stdout, _("Compiler: %s\n"), VLC_Compiler() );
+    utf8_fprintf( stdout, _("Compiler: %s\n"), VLC_Compiler() );
+#ifndef HAVE_SHARED_LIBVLC
     if( strcmp( VLC_Changeset(), "exported" ) )
-        fprintf( stdout, _("Based upon svn changeset [%s]\n"),
+        utf8_fprintf( stdout, _("Based upon svn changeset [%s]\n"),
                  VLC_Changeset() );
-    fprintf( stdout,
-      _("This program comes with NO WARRANTY, to the extent permitted by "
-        "law.\nYou may redistribute it under the terms of the GNU General "
-        "Public License;\nsee the file named COPYING for details.\n"
-        "Written by the VideoLAN team; see the AUTHORS file.\n") );
+#endif
+    utf8_fprintf( stdout, LICENSE_MSG );
 
 #ifdef WIN32        /* Pause the console because it's destroyed when we exit */
     PauseConsole();
@@ -2439,7 +2447,7 @@ static void Version( void )
  * This function is useful only on Win32.
  *****************************************************************************/
 #ifdef WIN32 /*  */
-static void ShowConsole( void )
+static void ShowConsole( vlc_bool_t b_dofile )
 {
 #   ifndef UNDER_CE
     FILE *f_help;
@@ -2451,11 +2459,11 @@ static void ShowConsole( void )
     freopen( "CONOUT$", "w", stderr );
     freopen( "CONIN$", "r", stdin );
 
-    if( (f_help = fopen( "vlc-help.txt", "wt" )) )
+    if( b_dofile && (f_help = fopen( "vlc-help.txt", "wt" )) )
     {
         fclose( f_help );
         freopen( "vlc-help.txt", "wt", stdout );
-        fprintf( stderr, _("\nDumped content to vlc-help.txt file.\n") );
+        utf8_fprintf( stderr, _("\nDumped content to vlc-help.txt file.\n") );
     }
 
     else freopen( "CONOUT$", "w", stdout );
@@ -2476,7 +2484,7 @@ static void PauseConsole( void )
 
     if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
 
-    fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
+    utf8_fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
     getchar();
     fclose( stdout );
 
@@ -2549,9 +2557,21 @@ static void InitDeviceValues( vlc_t *p_vlc )
     char **devices;
     char *block_dev;
     dbus_bool_t b_dvd;
+    DBusConnection *p_connection;
+    DBusError       error;
 
 #ifdef HAVE_HAL_1
-    if( ( ctx = libhal_ctx_init_direct( NULL ) ) )
+    ctx =  libhal_ctx_new();
+    if( !ctx ) return;
+    dbus_error_init( &error );
+    p_connection = dbus_bus_get ( DBUS_BUS_SYSTEM, &error );
+    if( dbus_error_is_set( &error ) )
+    {
+        dbus_error_free( &error );
+        return;
+    }
+    libhal_ctx_set_dbus_connection( ctx, p_connection );
+    if( libhal_ctx_init( ctx, &error ) )
 #else
     if( ( ctx = hal_initialize( NULL, FALSE ) ) )
 #endif
@@ -2611,94 +2631,9 @@ static void InitDeviceValues( vlc_t *p_vlc )
         hal_shutdown( ctx );
 #endif
     }
-#endif
-}
-
-/*****************************************************************************
- * FromLocale: converts a locale string to UTF-8
- *****************************************************************************/
-char *FromLocale( const char *locale )
-{
-    if( locale == NULL )
-        return NULL;
-
-    if( libvlc.from_locale != (vlc_iconv_t)(-1) )
-    {
-        char *iptr = (char *)locale, *output, *optr;
-        size_t inb, outb;
-
-        /*
-         * We are not allowed to modify the locale pointer, even if we cast it
-         * to non-const.
-         */
-        inb = strlen( locale );
-        outb = inb * 6 + 1;
-
-        /* FIXME: I'm not sure about the value for the multiplication
-         * (for western people, multiplication by 3 (Latin9) is sufficient) */
-        optr = output = calloc( outb , 1);
-
-        vlc_mutex_lock( &libvlc.from_locale_lock );
-        vlc_iconv( libvlc.from_locale, NULL, NULL, NULL, NULL );
-
-        while( vlc_iconv( libvlc.from_locale, &iptr, &inb, &optr, &outb )
-                                                               == (size_t)-1 )
-        {
-            *optr = '?';
-            optr++;
-            iptr++;
-            vlc_iconv( libvlc.from_locale, NULL, NULL, NULL, NULL );
-        }
-        vlc_mutex_unlock( &libvlc.from_locale_lock );
-
-        return realloc( output, strlen( output ) + 1 );
-    }
-    return (char *)locale;
-}
-
-/*****************************************************************************
- * ToLocale: converts an UTF-8 string to locale
- *****************************************************************************/
-char *ToLocale( const char *utf8 )
-{
-    if( utf8 == NULL )
-        return NULL;
-
-    if( libvlc.to_locale != (vlc_iconv_t)(-1) )
+    else
     {
-        char *iptr = (char *)utf8, *output, *optr;
-        size_t inb, outb;
-
-        /*
-         * We are not allowed to modify the locale pointer, even if we cast it
-         * to non-const.
-         */
-        inb = strlen( utf8 );
-        /* FIXME: I'm not sure about the value for the multiplication
-         * (for western people, multiplication is not needed) */
-        outb = inb * 2 + 1;
-
-        optr = output = calloc( outb, 1 );
-        vlc_mutex_lock( &libvlc.to_locale_lock );
-        vlc_iconv( libvlc.to_locale, NULL, NULL, NULL, NULL );
-
-        while( vlc_iconv( libvlc.to_locale, &iptr, &inb, &optr, &outb )
-                                                               == (size_t)-1 )
-        {
-            *optr = '?'; /* should not happen, and yes, it sucks */
-            optr++;
-            iptr++;
-            vlc_iconv( libvlc.to_locale, NULL, NULL, NULL, NULL );
-        }
-        vlc_mutex_unlock( &libvlc.to_locale_lock );
-
-        return realloc( output, strlen( output ) + 1 );
+        msg_Warn( p_vlc, "Unable to get HAL device properties" );
     }
-    return (char *)utf8;
-}
-
-void LocaleFree( const char *str )
-{
-    if( ( str != NULL ) && ( libvlc.to_locale != (vlc_iconv_t)(-1) ) )
-        free( (char *)str );
+#endif
 }