Commit 9df28485 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

Add long overdue private libvlc object pointer...

...and use it for stats and the config lock
parent aebd6a43
...@@ -68,13 +68,6 @@ struct libvlc_int_t ...@@ -68,13 +68,6 @@ struct libvlc_int_t
module_t * p_memcpy_module; ///< Fast memcpy plugin used module_t * p_memcpy_module; ///< Fast memcpy plugin used
bool b_stats; ///< Should we collect stats ?
vlc_mutex_t timer_lock; ///< Lock to protect timers
int i_timers; ///< Number of timers
counter_t **pp_timers; ///< Array of all timers
vlc_mutex_t config_lock; ///< Lock for the config file
/* Structure storing the action name / key associations */ /* Structure storing the action name / key associations */
struct hotkey struct hotkey
{ {
......
...@@ -557,12 +557,13 @@ void config_UnsetCallbacks( module_config_t *p_new, size_t n ) ...@@ -557,12 +557,13 @@ void config_UnsetCallbacks( module_config_t *p_new, size_t n )
*****************************************************************************/ *****************************************************************************/
void __config_ResetAll( vlc_object_t *p_this ) void __config_ResetAll( vlc_object_t *p_this )
{ {
libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
int i_index; int i_index;
vlc_list_t *p_list; vlc_list_t *p_list;
module_t *p_module; module_t *p_module;
/* Acquire config file lock */ /* Acquire config file lock */
vlc_mutex_lock( &p_this->p_libvlc->config_lock ); vlc_mutex_lock( &priv->config_lock );
p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
...@@ -589,7 +590,7 @@ void __config_ResetAll( vlc_object_t *p_this ) ...@@ -589,7 +590,7 @@ void __config_ResetAll( vlc_object_t *p_this )
} }
vlc_list_release( p_list ); vlc_list_release( p_list );
vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); vlc_mutex_unlock( &priv->config_lock );
} }
/** /**
......
...@@ -139,6 +139,7 @@ static int strtoi (const char *str) ...@@ -139,6 +139,7 @@ static int strtoi (const char *str)
*****************************************************************************/ *****************************************************************************/
int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
{ {
libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
vlc_list_t *p_list; vlc_list_t *p_list;
FILE *file; FILE *file;
...@@ -147,7 +148,7 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) ...@@ -147,7 +148,7 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
return VLC_EGENERIC; return VLC_EGENERIC;
/* Acquire config file lock */ /* Acquire config file lock */
vlc_mutex_lock( &p_this->p_libvlc->config_lock ); vlc_mutex_lock( &priv->config_lock );
/* Look for the selected module, if NULL then save everything */ /* Look for the selected module, if NULL then save everything */
p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
...@@ -296,7 +297,7 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) ...@@ -296,7 +297,7 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
vlc_list_release( p_list ); vlc_list_release( p_list );
vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); vlc_mutex_unlock( &priv->config_lock );
return 0; return 0;
} }
...@@ -386,6 +387,7 @@ config_Write (FILE *file, const char *type, const char *desc, ...@@ -386,6 +387,7 @@ config_Write (FILE *file, const char *type, const char *desc,
static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
bool b_autosave ) bool b_autosave )
{ {
libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
module_t *p_parser; module_t *p_parser;
vlc_list_t *p_list; vlc_list_t *p_list;
FILE *file; FILE *file;
...@@ -396,7 +398,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, ...@@ -396,7 +398,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
int i_index; int i_index;
/* Acquire config file lock */ /* Acquire config file lock */
vlc_mutex_lock( &p_this->p_libvlc->config_lock ); vlc_mutex_lock( &priv->config_lock );
if( p_this->p_libvlc->psz_configfile == NULL ) if( p_this->p_libvlc->psz_configfile == NULL )
{ {
...@@ -404,7 +406,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, ...@@ -404,7 +406,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
if( !psz_configdir ) /* XXX: This should never happen */ if( !psz_configdir ) /* XXX: This should never happen */
{ {
msg_Err( p_this, "no configuration directory defined" ); msg_Err( p_this, "no configuration directory defined" );
vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); vlc_mutex_unlock( &priv->config_lock );
return -1; return -1;
} }
...@@ -424,7 +426,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, ...@@ -424,7 +426,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
if( !p_bigbuffer ) if( !p_bigbuffer )
{ {
if( file ) fclose( file ); if( file ) fclose( file );
vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); vlc_mutex_unlock( &priv->config_lock );
return -1; return -1;
} }
p_bigbuffer[0] = 0; p_bigbuffer[0] = 0;
...@@ -498,7 +500,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, ...@@ -498,7 +500,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
{ {
vlc_list_release( p_list ); vlc_list_release( p_list );
free( p_bigbuffer ); free( p_bigbuffer );
vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); vlc_mutex_unlock( &priv->config_lock );
return -1; return -1;
} }
...@@ -619,20 +621,21 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, ...@@ -619,20 +621,21 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
free( p_bigbuffer ); free( p_bigbuffer );
fclose( file ); fclose( file );
vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); vlc_mutex_unlock( &priv->config_lock );
return 0; return 0;
} }
int config_AutoSaveConfigFile( vlc_object_t *p_this ) int config_AutoSaveConfigFile( vlc_object_t *p_this )
{ {
libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
vlc_list_t *p_list; vlc_list_t *p_list;
int i_index, i_count; int i_index, i_count;
assert( p_this ); assert( p_this );
/* Check if there's anything to save */ /* Check if there's anything to save */
vlc_mutex_lock( &p_this->p_libvlc->config_lock ); vlc_mutex_lock( &priv->config_lock );
p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
i_count = p_list->i_count; i_count = p_list->i_count;
for( i_index = 0; i_index < i_count; i_index++ ) for( i_index = 0; i_index < i_count; i_index++ )
...@@ -651,7 +654,7 @@ int config_AutoSaveConfigFile( vlc_object_t *p_this ) ...@@ -651,7 +654,7 @@ int config_AutoSaveConfigFile( vlc_object_t *p_this )
if( p_item < p_end ) break; if( p_item < p_end ) break;
} }
vlc_list_release( p_list ); vlc_list_release( p_list );
vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); vlc_mutex_unlock( &priv->config_lock );
if( i_index == i_count ) return VLC_SUCCESS; if( i_index == i_count ) return VLC_SUCCESS;
return SaveConfigFile( p_this, 0, true ); return SaveConfigFile( p_this, 0, true );
......
...@@ -1362,7 +1362,7 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block ) ...@@ -1362,7 +1362,7 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
else else
i_delay = 0; i_delay = 0;
if( p_input->p_libvlc->b_stats ) if( libvlc_stats (p_input) )
{ {
vlc_mutex_lock( &p_input->p->counters.counters_lock ); vlc_mutex_lock( &p_input->p->counters.counters_lock );
stats_UpdateInteger( p_input, p_input->p->counters.p_demux_read, stats_UpdateInteger( p_input, p_input->p->counters.p_demux_read,
......
...@@ -795,7 +795,7 @@ static void InitStatistics( input_thread_t * p_input ) ...@@ -795,7 +795,7 @@ static void InitStatistics( input_thread_t * p_input )
/* Prepare statistics */ /* Prepare statistics */
#define INIT_COUNTER( c, type, compute ) p_input->p->counters.p_##c = \ #define INIT_COUNTER( c, type, compute ) p_input->p->counters.p_##c = \
stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute); stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute);
if( p_input->p_libvlc->b_stats ) if( libvlc_stats (p_input) )
{ {
INIT_COUNTER( read_bytes, INTEGER, COUNTER ); INIT_COUNTER( read_bytes, INTEGER, COUNTER );
INIT_COUNTER( read_packets, INTEGER, COUNTER ); INIT_COUNTER( read_packets, INTEGER, COUNTER );
...@@ -863,7 +863,7 @@ static int InitSout( input_thread_t * p_input ) ...@@ -863,7 +863,7 @@ static int InitSout( input_thread_t * p_input )
return VLC_EGENERIC; return VLC_EGENERIC;
} }
} }
if( p_input->p_libvlc->b_stats ) if( libvlc_stats (p_input) )
{ {
INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER ); INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER );
INIT_COUNTER (sout_sent_bytes, INTEGER, COUNTER ); INIT_COUNTER (sout_sent_bytes, INTEGER, COUNTER );
...@@ -1260,7 +1260,7 @@ error: ...@@ -1260,7 +1260,7 @@ error:
} }
#endif #endif
if( !p_input->b_preparsing && p_input->p_libvlc->b_stats ) if( !p_input->b_preparsing && libvlc_stats (p_input) )
{ {
#define EXIT_COUNTER( c ) do { if( p_input->p->counters.p_##c ) \ #define EXIT_COUNTER( c ) do { if( p_input->p->counters.p_##c ) \
stats_CounterClean( p_input->p->counters.p_##c );\ stats_CounterClean( p_input->p->counters.p_##c );\
...@@ -1343,7 +1343,7 @@ static void End( input_thread_t * p_input ) ...@@ -1343,7 +1343,7 @@ static void End( input_thread_t * p_input )
if( !p_input->b_preparsing ) if( !p_input->b_preparsing )
{ {
#define CL_CO( c ) stats_CounterClean( p_input->p->counters.p_##c ); p_input->p->counters.p_##c = NULL; #define CL_CO( c ) stats_CounterClean( p_input->p->counters.p_##c ); p_input->p->counters.p_##c = NULL;
if( p_input->p_libvlc->b_stats ) if( libvlc_stats (p_input) )
{ {
/* make sure we are up to date */ /* make sure we are up to date */
stats_ComputeInputStats( p_input, p_input->p->input.p_item->p_stats ); stats_ComputeInputStats( p_input, p_input->p->input.p_item->p_stats );
......
...@@ -1752,7 +1752,7 @@ static block_t *AReadBlock( stream_t *s, bool *pb_eof ) ...@@ -1752,7 +1752,7 @@ static block_t *AReadBlock( stream_t *s, bool *pb_eof )
{ {
p_block = p_access->pf_block( p_access ); p_block = p_access->pf_block( p_access );
if( pb_eof ) *pb_eof = p_access->info.b_eof; if( pb_eof ) *pb_eof = p_access->info.b_eof;
if( p_input && p_block && p_access->p_libvlc->b_stats ) if( p_input && p_block && libvlc_stats (p_access) )
{ {
vlc_mutex_lock( &p_input->p->counters.counters_lock ); vlc_mutex_lock( &p_input->p->counters.counters_lock );
stats_UpdateInteger( s, p_input->p->counters.p_read_bytes, stats_UpdateInteger( s, p_input->p->counters.p_read_bytes,
......
...@@ -146,7 +146,8 @@ libvlc_int_t * vlc_current_object( int i_object ) ...@@ -146,7 +146,8 @@ libvlc_int_t * vlc_current_object( int i_object )
*/ */
libvlc_int_t * libvlc_InternalCreate( void ) libvlc_int_t * libvlc_InternalCreate( void )
{ {
libvlc_int_t * p_libvlc = NULL; libvlc_int_t *p_libvlc;
libvlc_priv_t *priv;
char *psz_env = NULL; char *psz_env = NULL;
/* vlc_threads_init *must* be the first internal call! No other call is /* vlc_threads_init *must* be the first internal call! No other call is
...@@ -167,7 +168,9 @@ libvlc_int_t * libvlc_InternalCreate( void ) ...@@ -167,7 +168,9 @@ libvlc_int_t * libvlc_InternalCreate( void )
} }
/* Allocate a libvlc instance object */ /* Allocate a libvlc instance object */
p_libvlc = vlc_object_create( p_libvlc_global, VLC_OBJECT_LIBVLC ); p_libvlc = vlc_custom_create( VLC_OBJECT(p_libvlc_global),
sizeof (*p_libvlc) + sizeof (libvlc_priv_t),
VLC_OBJECT_LIBVLC, "libvlc" );
if( p_libvlc != NULL ) if( p_libvlc != NULL )
i_instances++; i_instances++;
vlc_mutex_unlock( lock ); vlc_mutex_unlock( lock );
...@@ -179,6 +182,7 @@ libvlc_int_t * libvlc_InternalCreate( void ) ...@@ -179,6 +182,7 @@ libvlc_int_t * libvlc_InternalCreate( void )
p_libvlc->p_interaction = NULL; p_libvlc->p_interaction = NULL;
p_libvlc->p_vlm = NULL; p_libvlc->p_vlm = NULL;
p_libvlc->psz_object_name = strdup( "libvlc" ); p_libvlc->psz_object_name = strdup( "libvlc" );
priv = libvlc_priv (p_libvlc);
/* Initialize message queue */ /* Initialize message queue */
msg_Create( p_libvlc ); msg_Create( p_libvlc );
...@@ -200,8 +204,8 @@ libvlc_int_t * libvlc_InternalCreate( void ) ...@@ -200,8 +204,8 @@ libvlc_int_t * libvlc_InternalCreate( void )
msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE ); msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
/* Initialize mutexes */ /* Initialize mutexes */
vlc_mutex_init( &p_libvlc->timer_lock ); vlc_mutex_init( &priv->timer_lock );
vlc_mutex_init( &p_libvlc->config_lock ); vlc_mutex_init( &priv->config_lock );
#ifdef __APPLE__ #ifdef __APPLE__
vlc_thread_set_priority( p_libvlc, VLC_THREAD_PRIORITY_LOW ); vlc_thread_set_priority( p_libvlc, VLC_THREAD_PRIORITY_LOW );
#endif #endif
...@@ -223,6 +227,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, ...@@ -223,6 +227,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
const char *ppsz_argv[] ) const char *ppsz_argv[] )
{ {
libvlc_global_data_t *p_libvlc_global = vlc_global(); libvlc_global_data_t *p_libvlc_global = vlc_global();
libvlc_priv_t *priv = libvlc_priv (p_libvlc);
char p_capabilities[200]; char p_capabilities[200];
char * p_tmp = NULL; char * p_tmp = NULL;
char * psz_modules = NULL; char * psz_modules = NULL;
...@@ -705,9 +710,9 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, ...@@ -705,9 +710,9 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
*/ */
p_libvlc->p_memcpy_module = module_Need( p_libvlc, "memcpy", "$memcpy", 0 ); p_libvlc->p_memcpy_module = module_Need( p_libvlc, "memcpy", "$memcpy", 0 );
p_libvlc->b_stats = config_GetInt( p_libvlc, "stats" ) > 0; priv->b_stats = config_GetInt( p_libvlc, "stats" ) > 0;
p_libvlc->i_timers = 0; priv->i_timers = 0;
p_libvlc->pp_timers = NULL; priv->pp_timers = NULL;
/* Init stats */ /* Init stats */
p_libvlc->p_stats = (global_stats_t *)malloc( sizeof( global_stats_t ) ); p_libvlc->p_stats = (global_stats_t *)malloc( sizeof( global_stats_t ) );
...@@ -1030,6 +1035,8 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, bool b_release ) ...@@ -1030,6 +1035,8 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, bool b_release )
if( !p_libvlc ) if( !p_libvlc )
return VLC_EGENERIC; return VLC_EGENERIC;
libvlc_priv_t *priv = libvlc_priv (p_libvlc);
#ifndef WIN32 #ifndef WIN32
char* psz_pidfile = NULL; char* psz_pidfile = NULL;
...@@ -1081,8 +1088,8 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, bool b_release ) ...@@ -1081,8 +1088,8 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, bool b_release )
msg_Destroy( p_libvlc ); msg_Destroy( p_libvlc );
/* Destroy mutexes */ /* Destroy mutexes */
vlc_mutex_destroy( &p_libvlc->config_lock ); vlc_mutex_destroy( &priv->config_lock );
vlc_mutex_destroy( &p_libvlc->timer_lock ); vlc_mutex_destroy( &priv->timer_lock );
if( b_release ) vlc_object_release( p_libvlc ); if( b_release ) vlc_object_release( p_libvlc );
vlc_object_release( p_libvlc ); vlc_object_release( p_libvlc );
......
...@@ -130,7 +130,9 @@ typedef struct libvlc_global_data_t ...@@ -130,7 +130,9 @@ typedef struct libvlc_global_data_t
libvlc_global_data_t *vlc_global (void); libvlc_global_data_t *vlc_global (void);
libvlc_int_t *vlc_current_object (int i_object); libvlc_int_t *vlc_current_object (int i_object);
/* Private LibVLC data for each objects */ /**
* Private LibVLC data for each object.
*/
struct vlc_object_internals_t struct vlc_object_internals_t
{ {
/* Object variables */ /* Object variables */
...@@ -163,6 +165,32 @@ static inline vlc_object_internals_t *vlc_internals( vlc_object_t *obj ) ...@@ -163,6 +165,32 @@ static inline vlc_object_internals_t *vlc_internals( vlc_object_t *obj )
return ((vlc_object_internals_t *)obj) - 1; return ((vlc_object_internals_t *)obj) - 1;
} }
/**
* Private LibVLC instance data.
*/
typedef struct libvlc_priv_t
{
vlc_mutex_t config_lock; ///< config file lock
vlc_mutex_t timer_lock; ///< Lock to protect timers
counter_t **pp_timers; ///< Array of all timers
int i_timers; ///< Number of timers
bool b_stats; ///< Whether to collect stats
} libvlc_priv_t;
static inline libvlc_priv_t *libvlc_priv (libvlc_int_t *libvlc)
{
return (libvlc_priv_t *)(libvlc + 1);
}
static inline bool libvlc_stats (vlc_object_t *obj)
{
return libvlc_priv (obj->p_libvlc)->b_stats;
}
/**
* LibVLC "main module" configuration settings array.
*/
extern module_config_t libvlc_config[]; extern module_config_t libvlc_config[];
extern const size_t libvlc_config_count; extern const size_t libvlc_config_count;
......
...@@ -85,7 +85,7 @@ counter_t * __stats_CounterCreate( vlc_object_t *p_this, ...@@ -85,7 +85,7 @@ counter_t * __stats_CounterCreate( vlc_object_t *p_this,
int __stats_Update( vlc_object_t *p_this, counter_t *p_counter, int __stats_Update( vlc_object_t *p_this, counter_t *p_counter,
vlc_value_t val, vlc_value_t *val_new ) vlc_value_t val, vlc_value_t *val_new )
{ {
if( !p_this->p_libvlc->b_stats || !p_counter ) return VLC_EGENERIC; if( !libvlc_stats (p_this) || !p_counter ) return VLC_EGENERIC;
return CounterUpdate( p_this, p_counter, val, val_new ); return CounterUpdate( p_this, p_counter, val, val_new );
} }
...@@ -98,7 +98,7 @@ int __stats_Update( vlc_object_t *p_this, counter_t *p_counter, ...@@ -98,7 +98,7 @@ int __stats_Update( vlc_object_t *p_this, counter_t *p_counter,
*/ */
int __stats_Get( vlc_object_t *p_this, counter_t *p_counter, vlc_value_t *val ) int __stats_Get( vlc_object_t *p_this, counter_t *p_counter, vlc_value_t *val )
{ {
if( !p_this->p_libvlc->b_stats || !p_counter || p_counter->i_samples == 0 ) if( !libvlc_stats (p_this) || !p_counter || p_counter->i_samples == 0 )
{ {
val->i_int = val->f_float = 0.0; val->i_int = val->f_float = 0.0;
return VLC_EGENERIC; return VLC_EGENERIC;
...@@ -157,7 +157,7 @@ input_stats_t *stats_NewInputStats( input_thread_t *p_input ) ...@@ -157,7 +157,7 @@ input_stats_t *stats_NewInputStats( input_thread_t *p_input )
void stats_ComputeInputStats( input_thread_t *p_input, input_stats_t *p_stats ) void stats_ComputeInputStats( input_thread_t *p_input, input_stats_t *p_stats )
{ {
if( !p_input->p_libvlc->b_stats ) return; if( !libvlc_stats (p_input) ) return;
vlc_mutex_lock( &p_input->p->counters.counters_lock ); vlc_mutex_lock( &p_input->p->counters.counters_lock );
vlc_mutex_lock( &p_stats->lock ); vlc_mutex_lock( &p_stats->lock );
...@@ -245,7 +245,7 @@ void __stats_ComputeGlobalStats( vlc_object_t *p_obj, global_stats_t *p_stats ) ...@@ -245,7 +245,7 @@ void __stats_ComputeGlobalStats( vlc_object_t *p_obj, global_stats_t *p_stats )
vlc_list_t *p_list; vlc_list_t *p_list;
int i_index; int i_index;
if( !p_obj->p_libvlc->b_stats ) return; if( !libvlc_stats (p_obj) ) return;
vlc_mutex_lock( &p_stats->lock ); vlc_mutex_lock( &p_stats->lock );
...@@ -280,17 +280,19 @@ void __stats_ComputeGlobalStats( vlc_object_t *p_obj, global_stats_t *p_stats ) ...@@ -280,17 +280,19 @@ void __stats_ComputeGlobalStats( vlc_object_t *p_obj, global_stats_t *p_stats )
void __stats_TimerStart( vlc_object_t *p_obj, const char *psz_name, void __stats_TimerStart( vlc_object_t *p_obj, const char *psz_name,
unsigned int i_id ) unsigned int i_id )
{ {
int i; libvlc_priv_t *priv = libvlc_priv (p_obj->p_libvlc);
counter_t *p_counter = NULL; counter_t *p_counter = NULL;
if( !p_obj->p_libvlc->b_stats ) return;
vlc_mutex_lock( &p_obj->p_libvlc->timer_lock );
for( i = 0 ; i < p_obj->p_libvlc->i_timers; i++ ) if( !priv->b_stats ) return;
vlc_mutex_lock( &priv->timer_lock );
for( int i = 0 ; i < priv->i_timers; i++ )
{ {
if( p_obj->p_libvlc->pp_timers[i]->i_id == i_id if( priv->pp_timers[i]->i_id == i_id
&& p_obj->p_libvlc->pp_timers[i]->p_obj == p_obj ) && priv->pp_timers[i]->p_obj == p_obj )
{ {
p_counter = p_obj->p_libvlc->pp_timers[i]; p_counter = priv->pp_timers[i];
break; break;
} }
} }
...@@ -300,15 +302,12 @@ void __stats_TimerStart( vlc_object_t *p_obj, const char *psz_name, ...@@ -300,15 +302,12 @@ void __stats_TimerStart( vlc_object_t *p_obj, const char *psz_name,
p_counter = stats_CounterCreate( p_obj->p_libvlc, VLC_VAR_TIME, p_counter = stats_CounterCreate( p_obj->p_libvlc, VLC_VAR_TIME,
STATS_TIMER ); STATS_TIMER );
if( !p_counter ) if( !p_counter )
{ goto out;
vlc_mutex_unlock( &p_obj->p_libvlc->timer_lock );
return;
}
p_counter->psz_name = strdup( psz_name ); p_counter->psz_name = strdup( psz_name );
p_counter->i_id = i_id; p_counter->i_id = i_id;
p_counter->p_obj = p_obj; p_counter->p_obj = p_obj;
INSERT_ELEM( p_obj->p_libvlc->pp_timers, p_obj->p_libvlc->i_timers, INSERT_ELEM( priv->pp_timers, priv->i_timers,
p_obj->p_libvlc->i_timers, p_counter ); priv->i_timers, p_counter );
/* 1st sample : if started: start_date, else last_time, b_started */ /* 1st sample : if started: start_date, else last_time, b_started */
p_sample = (counter_sample_t *)malloc( sizeof( counter_sample_t ) ); p_sample = (counter_sample_t *)malloc( sizeof( counter_sample_t ) );
...@@ -324,107 +323,110 @@ void __stats_TimerStart( vlc_object_t *p_obj, const char *psz_name, ...@@ -324,107 +323,110 @@ void __stats_TimerStart( vlc_object_t *p_obj, const char *psz_name,
if( p_counter->pp_samples[0]->value.b_bool == true ) if( p_counter->pp_samples[0]->value.b_bool == true )
{ {
msg_Warn( p_obj, "timer '%s' was already started !", psz_name ); msg_Warn( p_obj, "timer '%s' was already started !", psz_name );
vlc_mutex_unlock( &p_obj->p_libvlc->timer_lock ); goto out;
return;
} }
p_counter->pp_samples[0]->value.b_bool = true; p_counter->pp_samples[0]->value.b_bool = true;
p_counter->pp_samples[0]->date = mdate(); p_counter->pp_samples[0]->date = mdate();
vlc_mutex_unlock( &p_obj->p_libvlc->timer_lock ); out:
vlc_mutex_unlock( &priv->timer_lock );
} }
void __stats_TimerStop( vlc_object_t *p_obj, unsigned int i_id ) void __stats_TimerStop( vlc_object_t *p_obj, unsigned int i_id )
{ {
counter_t *p_counter = NULL; counter_t *p_counter = NULL;
int i; libvlc_priv_t *priv = libvlc_priv (p_obj->p_libvlc);
if( !p_obj->p_libvlc->b_stats ) return;
vlc_mutex_lock( &p_obj->p_libvlc->timer_lock ); if( !priv->b_stats ) return;
for( i = 0 ; i < p_obj->p_libvlc->i_timers; i++ )