vlc_bool_t b_ready; ///< Initialization boolean
uint32_t i_cpu; ///< CPU extensions
-
+
/* Object structure data */
int i_counter; ///< object counter
int i_objects; ///< Attached objects count
p_i->i_type = ITEM_TYPE_UNKNOWN;
p_i->b_fixed_name = VLC_TRUE;
- p_i->p_stats = (input_stats_t*) malloc( sizeof( input_stats_t ) );
+ p_i->p_stats = NULL;
p_i->p_meta = NULL;
- vlc_mutex_init( p_o, &p_i->p_stats->lock );
vlc_mutex_init( p_o, &p_i->lock );
}
static inline void input_ItemClean( input_item_t *p_i )
{
- if( p_i->psz_name ) free( p_i->psz_name );
- if( p_i->psz_uri ) free( p_i->psz_uri );
- if( p_i->p_stats ) free( p_i->p_stats );
- p_i->psz_name = 0;
- p_i->psz_uri = 0;
+ free( p_i->psz_name );
+ free( p_i->psz_uri );
+ if( p_i->p_stats )
+ {
+ vlc_mutex_destroy( &p_i->p_stats->lock );
+ free( p_i->p_stats );
+ }
if( p_i->p_meta ) vlc_meta_Delete( p_i->p_meta );
// Playlist-unrelated fields
interaction_t *p_interaction; /**< Interaction manager */
+ /** The input thread computing stats */
+ input_thread_t *p_stats_computer;
global_stats_t *p_stats; /**< Global statistics */
/*@}*/
};
msg_Err( p_parent, "out of memory" );
return NULL;
}
+
+ /* One "randomly" selected input thread is responsible for computing
+ * the global stats. Check if there is already someone doing this */
+ if( p_input->p_libvlc->p_playlist->p_stats && !b_quick )
+ {
+ vlc_mutex_lock( &p_input->p_libvlc->p_playlist->p_stats->lock );
+ if( p_input->p_libvlc->p_playlist->p_stats_computer == NULL )
+ {
+ p_input->p_libvlc->p_playlist->p_stats_computer = p_input;
+ }
+ vlc_mutex_unlock( &p_input->p_libvlc->p_playlist->p_stats->lock );
+ }
+
p_input->b_preparsing = b_quick;
p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
if( !p_input->input.p_item->p_meta )
p_input->input.p_item->p_meta = vlc_meta_New();
- stats_ReinitInputStats( p_item->p_stats );
+
+ if( !p_item->p_stats )
+ {
+ p_item->p_stats = (input_stats_t*)malloc( sizeof( input_stats_t ) );
+ vlc_mutex_init( p_input, &p_item->p_stats->lock );
+ stats_ReinitInputStats( p_item->p_stats );
+ }
/* No slave */
p_input->i_slave = 0;
static void MainLoop( input_thread_t *p_input )
{
int64_t i_intf_update = 0;
+ int i_updates = 0;
while( !p_input->b_die && !p_input->b_error && !p_input->input.b_eof )
{
vlc_bool_t b_force_update = VLC_FALSE;
var_SetBool( p_input, "intf-change", VLC_TRUE );
i_intf_update = mdate() + I64C(150000);
}
+ /* 150ms * 8 = ~ 1 second */
+ if( ++i_updates % 8 == 0 )
+ {
+ stats_ComputeInputStats( p_input, p_input->input.p_item->p_stats );
+ /* Are we the thread responsible for computing global stats ? */
+ if( p_input->p_libvlc->p_playlist->p_stats_computer == p_input )
+ {
+ stats_ComputeGlobalStats( p_input->p_libvlc->p_playlist,
+ p_input->p_libvlc->p_playlist->p_stats );
+ }
+ }
}
}
#define CL_CO( c ) stats_CounterClean( p_input->counters.p_##c ); p_input->counters.p_##c = NULL;
if( p_input->p_libvlc->b_stats )
{
+ /* make sure we are up to date */
+ stats_ComputeInputStats( p_input, p_input->input.p_item->p_stats );
+ if( p_input->p_libvlc->p_playlist->p_stats_computer == p_input )
+ {
+ stats_ComputeGlobalStats( p_input->p_libvlc->p_playlist,
+ p_input->p_libvlc->p_playlist->p_stats );
+ p_input->p_libvlc->p_playlist->p_stats_computer = NULL;
+ }
vlc_mutex_lock( &p_input->counters.counters_lock );
CL_CO( read_bytes );
CL_CO( read_packets );
static void EndPlaylist( playlist_t * );
static void DestroyPlaylist( playlist_t * );
-static void HandleStats( playlist_t *, int );
-
static void HandleInteraction( playlist_t * );
static void DestroyInteraction( playlist_t * );
// Stats
p_playlist->p_stats = (global_stats_t *)malloc( sizeof( global_stats_t ) );
vlc_mutex_init( p_playlist, &p_playlist->p_stats->lock );
+ p_playlist->p_stats_computer = NULL;
// Interaction
p_playlist->p_interaction = NULL;
i_loops++;
HandleInteraction( p_playlist );
- HandleStats( p_playlist, i_loops );
HandlePlaylist( p_playlist );
/* 100 ms is an acceptable delay for playlist operations */
stats_TimerStop( p_playlist, STATS_TIMER_INTERACTION );
}
}
-
-
-/*****************************************************************************
- * Stats functions
- *****************************************************************************/
-static void HandleStats( playlist_t *p_playlist, int i_loops )
-{
- if( i_loops % 5 == 0 && p_playlist->p_stats )
- {
- stats_ComputeGlobalStats( p_playlist, p_playlist->p_stats );
- if( p_playlist->p_input )
- {
- stats_ComputeInputStats( p_playlist->p_input,
- p_playlist->p_input->input.p_item->p_stats );
- }
- }
-}