/*****************************************************************************
* 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
*
* 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.
*****************************************************************************/
/*****************************************************************************
#include <stdio.h> /* sprintf() */
#include <string.h> /* strerror() */
#include <stdlib.h> /* free() */
+#ifdef HAVE_ASSERT
+# include <assert.h>
+#else
+# define assert( c ) ((void)0)
+#endif
#ifndef WIN32
# include <netinet/in.h> /* BSD: struct in_addr */
/*****************************************************************************
* Local prototypes
*****************************************************************************/
+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 );
+
static void LocaleInit( void );
static void LocaleDeinit( void );
static void SetLanguage ( char const * );
/* 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
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
p_vlc->pf_memset = memset;
}
+ libvlc.b_stats = config_GetInt( p_vlc, "stats" );
+ libvlc.p_stats = NULL;
+
/*
* Initialize hotkey handling
*/
}
#endif
+ if( config_GetInt( p_vlc, "file-logging" ) == 1 )
+ {
+ VLC_AddIntf( 0, "logger", VLC_FALSE, VLC_FALSE );
+ }
+#ifdef HAVE_SYSLOG_H
+ if( config_GetInt( p_vlc, "syslog" ) == 1 )
+ {
+ char *psz_logmode = "logmode=syslog";
+ AddIntfInternal( 0, "logger", VLC_FALSE, VLC_FALSE, 1, &psz_logmode );
+ }
+#endif
+
+ if( config_GetInt( p_vlc, "show-intf" ) == 1 )
+ {
+ VLC_AddIntf( 0, "showintf", VLC_FALSE, VLC_FALSE );
+ }
+
+ if( config_GetInt( p_vlc, "network-synchronisation") == 1 )
+ {
+ VLC_AddIntf( 0, "netsync", VLC_FALSE, VLC_FALSE );
+ }
+
/*
* FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
*/
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.
*****************************************************************************
vout_thread_t * p_vout;
aout_instance_t * p_aout;
announce_handler_t * p_announce;
+ stats_handler_t * p_stats;
vlc_t *p_vlc = vlc_current_object( i_object );
/* Check that the handle is valid */
}
/*
- * 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 )) )
{
aout_Delete( p_aout );
}
+ while( ( p_stats = vlc_object_find( p_vlc, VLC_OBJECT_STATS, FIND_CHILD) ))
+ {
+ stats_TimersDumpAll( p_vlc );
+ stats_HandlerDestroy( p_stats );
+ vlc_object_detach( (vlc_object_t*) p_stats );
+ vlc_object_release( (vlc_object_t *)p_stats );
+ // TODO: Delete it
+ }
+
/*
* 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;
/* following functions are local */
+
+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 )
+{
+ int i_err,i;
+ 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",
+ i_options, ppsz_options );
+
+ 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;
+ }
+
+ for( i = 0 ; i< i_options ; i++ )
+ {
+
+ }
+
+ if( i_object ) vlc_object_release( p_vlc );
+ return VLC_SUCCESS;
+};
+
static void LocaleInit( void )
{
char *psz_charset;
&& ( 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
}
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 );
}
/* 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,
return;
}
libhal_ctx_set_dbus_connection( ctx, p_connection );
- if( !libhal_ctx_init( ctx, &error ) )
+ if( libhal_ctx_init( ctx, &error ) )
#else
if( ( ctx = hal_initialize( NULL, FALSE ) ) )
#endif
}
else
{
- msg_Dbg( p_vlc, "Unable to get HAL device properties" );
+ msg_Warn( p_vlc, "Unable to get HAL device properties" );
}
#endif
}
* 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) */
+ outb = inb * 6 + 1;
+
optr = output = calloc( outb , 1);
vlc_mutex_lock( &libvlc.from_locale_lock );
while( vlc_iconv( libvlc.from_locale, &iptr, &inb, &optr, &outb )
== (size_t)-1 )
{
- *optr = '?';
- optr++;
+ *optr++ = '?';
+ outb--;
iptr++;
+ inb--;
vlc_iconv( libvlc.from_locale, NULL, NULL, NULL, NULL );
}
- vlc_mutex_unlock( &libvlc.from_locale_lock );
+ vlc_mutex_unlock( &libvlc.from_locale_lock );
- return realloc( output, strlen( output ) + 1 );
+ assert (inb == 0);
+ assert (*iptr == '\0');
+ assert (*optr == '\0');
+ assert (strlen( output ) == (size_t)(optr - output));
+ return realloc( output, optr - output + 1 );
}
return (char *)locale;
}
while( vlc_iconv( libvlc.to_locale, &iptr, &inb, &optr, &outb )
== (size_t)-1 )
{
- *optr = '?'; /* should not happen, and yes, it sucks */
- optr++;
+ *optr++ = '?'; /* should not happen, and yes, it sucks */
+ outb--;
iptr++;
+ inb--;
vlc_iconv( libvlc.to_locale, NULL, NULL, NULL, NULL );
}
vlc_mutex_unlock( &libvlc.to_locale_lock );
- return realloc( output, strlen( output ) + 1 );
+ assert (inb == 0);
+ assert (*iptr == '\0');
+ assert (*optr == '\0');
+ assert (strlen( output ) == (size_t)(optr - output));
+ return realloc( output, optr - output + 1 );
}
return (char *)utf8;
}