Commit 8baa527e authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Convert rate stats to integer and remove useless float support

This saves a whole lot of float conversion and simplifies the code.
parent ef69c0b3
......@@ -1327,14 +1327,9 @@ static void DecoderDecodeAudio( decoder_t *p_dec, block_t *p_block )
if( p_input != NULL && (i_decoded > 0 || i_lost > 0 || i_played > 0) )
{
vlc_mutex_lock( &p_input->p->counters.counters_lock);
stats_UpdateInteger( p_input->p->counters.p_lost_abuffers,
i_lost, NULL );
stats_UpdateInteger( p_input->p->counters.p_played_abuffers,
i_played, NULL );
stats_UpdateInteger( p_input->p->counters.p_decoded_audio,
i_decoded, NULL );
stats_Update( p_input->p->counters.p_lost_abuffers, i_lost, NULL );
stats_Update( p_input->p->counters.p_played_abuffers, i_played, NULL );
stats_Update( p_input->p->counters.p_decoded_audio, i_decoded, NULL );
vlc_mutex_unlock( &p_input->p->counters.counters_lock);
}
}
......@@ -1556,15 +1551,10 @@ static void DecoderDecodeVideo( decoder_t *p_dec, block_t *p_block )
if( p_input != NULL && (i_decoded > 0 || i_lost > 0 || i_displayed > 0) )
{
vlc_mutex_lock( &p_input->p->counters.counters_lock );
stats_UpdateInteger( p_input->p->counters.p_decoded_video,
i_decoded, NULL );
stats_UpdateInteger( p_input->p->counters.p_lost_pictures,
i_lost , NULL);
stats_UpdateInteger( p_input->p->counters.p_displayed_pictures,
stats_Update( p_input->p->counters.p_decoded_video, i_decoded, NULL );
stats_Update( p_input->p->counters.p_lost_pictures, i_lost , NULL);
stats_Update( p_input->p->counters.p_displayed_pictures,
i_displayed, NULL);
vlc_mutex_unlock( &p_input->p->counters.counters_lock );
}
}
......@@ -1956,7 +1946,7 @@ static void DecoderProcessSpu( decoder_t *p_dec, block_t *p_block, bool b_flush
if( p_input != NULL )
{
vlc_mutex_lock( &p_input->p->counters.counters_lock );
stats_UpdateInteger( p_input->p->counters.p_decoded_sub, 1, NULL );
stats_Update( p_input->p->counters.p_decoded_sub, 1, NULL );
vlc_mutex_unlock( &p_input->p->counters.counters_lock );
}
......
......@@ -1920,27 +1920,25 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
{
es_out_sys_t *p_sys = out->p_sys;
input_thread_t *p_input = p_sys->p_input;
int i_total = 0;
if( libvlc_stats( p_input ) )
{
uint64_t i_total;
vlc_mutex_lock( &p_input->p->counters.counters_lock );
stats_UpdateInteger( p_input->p->counters.p_demux_read,
stats_Update( p_input->p->counters.p_demux_read,
p_block->i_buffer, &i_total );
stats_UpdateFloat( p_input->p->counters.p_demux_bitrate,
(float)i_total, NULL );
stats_Update( p_input->p->counters.p_demux_bitrate, i_total, NULL );
/* Update number of corrupted data packats */
if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
{
stats_UpdateInteger( p_input->p->counters.p_demux_corrupted,
1, NULL );
stats_Update( p_input->p->counters.p_demux_corrupted, 1, NULL );
}
/* Update number of discontinuities */
if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
{
stats_UpdateInteger( p_input->p->counters.p_demux_discontinuity,
1, NULL );
stats_Update( p_input->p->counters.p_demux_discontinuity, 1, NULL );
}
vlc_mutex_unlock( &p_input->p->counters.counters_lock );
}
......
......@@ -851,24 +851,24 @@ static void InitStatistics( input_thread_t * p_input )
if( p_input->b_preparsing ) return;
/* Prepare statistics */
#define INIT_COUNTER( c, type, compute ) p_input->p->counters.p_##c = \
stats_CounterCreate( VLC_VAR_##type, STATS_##compute);
#define INIT_COUNTER( c, compute ) p_input->p->counters.p_##c = \
stats_CounterCreate( STATS_##compute);
if( libvlc_stats( p_input ) )
{
INIT_COUNTER( read_bytes, INTEGER, COUNTER );
INIT_COUNTER( read_packets, INTEGER, COUNTER );
INIT_COUNTER( demux_read, INTEGER, COUNTER );
INIT_COUNTER( input_bitrate, FLOAT, DERIVATIVE );
INIT_COUNTER( demux_bitrate, FLOAT, DERIVATIVE );
INIT_COUNTER( demux_corrupted, INTEGER, COUNTER );
INIT_COUNTER( demux_discontinuity, INTEGER, COUNTER );
INIT_COUNTER( played_abuffers, INTEGER, COUNTER );
INIT_COUNTER( lost_abuffers, INTEGER, COUNTER );
INIT_COUNTER( displayed_pictures, INTEGER, COUNTER );
INIT_COUNTER( lost_pictures, INTEGER, COUNTER );
INIT_COUNTER( decoded_audio, INTEGER, COUNTER );
INIT_COUNTER( decoded_video, INTEGER, COUNTER );
INIT_COUNTER( decoded_sub, INTEGER, COUNTER );
INIT_COUNTER( read_bytes, COUNTER );
INIT_COUNTER( read_packets, COUNTER );
INIT_COUNTER( demux_read, COUNTER );
INIT_COUNTER( input_bitrate, DERIVATIVE );
INIT_COUNTER( demux_bitrate, DERIVATIVE );
INIT_COUNTER( demux_corrupted, COUNTER );
INIT_COUNTER( demux_discontinuity, COUNTER );
INIT_COUNTER( played_abuffers, COUNTER );
INIT_COUNTER( lost_abuffers, COUNTER );
INIT_COUNTER( displayed_pictures, COUNTER );
INIT_COUNTER( lost_pictures, COUNTER );
INIT_COUNTER( decoded_audio, COUNTER );
INIT_COUNTER( decoded_video, COUNTER );
INIT_COUNTER( decoded_sub, COUNTER );
p_input->p->counters.p_sout_send_bitrate = NULL;
p_input->p->counters.p_sout_sent_packets = NULL;
p_input->p->counters.p_sout_sent_bytes = NULL;
......@@ -896,9 +896,9 @@ static int InitSout( input_thread_t * p_input )
}
if( libvlc_stats( p_input ) )
{
INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER );
INIT_COUNTER( sout_sent_bytes, INTEGER, COUNTER );
INIT_COUNTER( sout_send_bitrate, FLOAT, DERIVATIVE );
INIT_COUNTER( sout_sent_packets, COUNTER );
INIT_COUNTER( sout_sent_bytes, COUNTER );
INIT_COUNTER( sout_send_bitrate, DERIVATIVE );
}
}
else
......@@ -3195,7 +3195,7 @@ void input_UpdateStatistic( input_thread_t *p_input,
vlc_mutex_lock( &p_input->p->counters.counters_lock);
switch( i_type )
{
#define I(c) stats_UpdateInteger( p_input->p->counters.c, i_delta, NULL )
#define I(c) stats_Update( p_input->p->counters.c, i_delta, NULL )
case INPUT_STATISTIC_DECODED_VIDEO:
I(p_decoded_video);
break;
......@@ -3211,10 +3211,10 @@ void input_UpdateStatistic( input_thread_t *p_input,
#undef I
case INPUT_STATISTIC_SENT_BYTE:
{
int i_bytes; /* That's pretty stupid to define it as an integer, it will overflow
really fast ... */
if( !stats_UpdateInteger( p_input->p->counters.p_sout_sent_bytes, i_delta, &i_bytes ) )
stats_UpdateFloat( p_input->p->counters.p_sout_send_bitrate, i_bytes, NULL );
uint64_t bytes;
stats_Update( p_input->p->counters.p_sout_sent_bytes, i_delta, &bytes );
stats_Update( p_input->p->counters.p_sout_send_bitrate, bytes, NULL );
break;
}
default:
......
......@@ -1680,7 +1680,6 @@ static int AReadStream( stream_t *s, void *p_read, unsigned int i_read )
access_t *p_access = p_sys->p_access;
input_thread_t *p_input = s->p_input;
int i_read_orig = i_read;
int i_total = 0;
if( !p_sys->i_list )
{
......@@ -1689,12 +1688,12 @@ static int AReadStream( stream_t *s, void *p_read, unsigned int i_read )
vlc_object_kill( s );
if( p_input )
{
uint64_t total;
vlc_mutex_lock( &p_input->p->counters.counters_lock );
stats_UpdateInteger( p_input->p->counters.p_read_bytes, i_read,
&i_total );
stats_UpdateFloat( p_input->p->counters.p_input_bitrate,
(float)i_total, NULL );
stats_UpdateInteger( p_input->p->counters.p_read_packets, 1, NULL );
stats_Update( p_input->p->counters.p_read_bytes, i_read, &total );
stats_Update( p_input->p->counters.p_input_bitrate, total, NULL );
stats_Update( p_input->p->counters.p_read_packets, 1, NULL );
vlc_mutex_unlock( &p_input->p->counters.counters_lock );
}
return i_read;
......@@ -1729,11 +1728,12 @@ static int AReadStream( stream_t *s, void *p_read, unsigned int i_read )
/* Update read bytes in input */
if( p_input )
{
uint64_t total;
vlc_mutex_lock( &p_input->p->counters.counters_lock );
stats_UpdateInteger( p_input->p->counters.p_read_bytes, i_read, &i_total );
stats_UpdateFloat( p_input->p->counters.p_input_bitrate,
(float)i_total, NULL );
stats_UpdateInteger( p_input->p->counters.p_read_packets, 1, NULL );
stats_Update( p_input->p->counters.p_read_bytes, i_read, &total );
stats_Update( p_input->p->counters.p_input_bitrate, total, NULL );
stats_Update( p_input->p->counters.p_read_packets, 1, NULL );
vlc_mutex_unlock( &p_input->p->counters.counters_lock );
}
return i_read;
......@@ -1746,7 +1746,6 @@ static block_t *AReadBlock( stream_t *s, bool *pb_eof )
input_thread_t *p_input = s->p_input;
block_t *p_block;
bool b_eof;
int i_total = 0;
if( !p_sys->i_list )
{
......@@ -1756,12 +1755,14 @@ static block_t *AReadBlock( stream_t *s, bool *pb_eof )
if( pb_eof ) *pb_eof = p_access->info.b_eof;
if( p_input && p_block && libvlc_stats (p_access) )
{
uint64_t total;
vlc_mutex_lock( &p_input->p->counters.counters_lock );
stats_UpdateInteger( p_input->p->counters.p_read_bytes,
p_block->i_buffer, &i_total );
stats_UpdateFloat( p_input->p->counters.p_input_bitrate,
(float)i_total, NULL );
stats_UpdateInteger( p_input->p->counters.p_read_packets, 1, NULL );
stats_Update( p_input->p->counters.p_read_bytes,
p_block->i_buffer, &total );
stats_Update( p_input->p->counters.p_input_bitrate,
total, NULL );
stats_Update( p_input->p->counters.p_read_packets, 1, NULL );
vlc_mutex_unlock( &p_input->p->counters.counters_lock );
}
return p_block;
......@@ -1797,13 +1798,13 @@ static block_t *AReadBlock( stream_t *s, bool *pb_eof )
{
if( p_input )
{
uint64_t total;
vlc_mutex_lock( &p_input->p->counters.counters_lock );
stats_UpdateInteger( p_input->p->counters.p_read_bytes,
p_block->i_buffer, &i_total );
stats_UpdateFloat( p_input->p->counters.p_input_bitrate,
(float)i_total, NULL );
stats_UpdateInteger( p_input->p->counters.p_read_packets,
1 , NULL);
stats_Update( p_input->p->counters.p_read_bytes,
p_block->i_buffer, &total );
stats_Update( p_input->p->counters.p_input_bitrate, total, NULL );
stats_Update( p_input->p->counters.p_read_packets, 1 , NULL);
vlc_mutex_unlock( &p_input->p->counters.counters_lock );
}
}
......
......@@ -230,13 +230,12 @@ enum
typedef struct counter_sample_t
{
vlc_value_t value;
uint64_t value;
mtime_t date;
} counter_sample_t;
typedef struct counter_t
{
int i_type;
int i_compute_type;
int i_samples;
counter_sample_t ** pp_samples;
......@@ -267,58 +266,10 @@ enum
STATS_LOST_PICTURES,
};
int stats_Update (counter_t *, vlc_value_t, vlc_value_t *);
counter_t * stats_CounterCreate (int, int);
int stats_Get (counter_t *, vlc_value_t*);
counter_t * stats_CounterCreate (int);
void stats_Update (counter_t *, uint64_t, uint64_t *);
void stats_CounterClean (counter_t * );
static inline int stats_GetInteger( counter_t *p_counter, int64_t *value )
{
int i_ret;
vlc_value_t val; val.i_int = 0;
if( !p_counter ) return VLC_EGENERIC;
i_ret = stats_Get( p_counter, &val );
*value = val.i_int;
return i_ret;
}
static inline int stats_GetFloat( counter_t *p_counter, float *value )
{
int i_ret;
vlc_value_t val; val.f_float = 0.0;
if( !p_counter ) return VLC_EGENERIC;
i_ret = stats_Get( p_counter, &val );
*value = val.f_float;
return i_ret;
}
static inline int stats_UpdateInteger( counter_t *p_co, int i, int *pi_new )
{
int i_ret;
vlc_value_t val;
vlc_value_t new_val; new_val.i_int = 0;
if( !p_co ) return VLC_EGENERIC;
val.i_int = i;
i_ret = stats_Update( p_co, val, &new_val );
if( pi_new )
*pi_new = new_val.i_int;
return i_ret;
}
static inline int stats_UpdateFloat( counter_t *p_co, float f, float *pf_new )
{
vlc_value_t val;
int i_ret;
vlc_value_t new_val;new_val.f_float = 0.0;
if( !p_co ) return VLC_EGENERIC;
val.f_float = f;
i_ret = stats_Update( p_co, val, &new_val );
if( pf_new )
*pf_new = new_val.f_float;
return i_ret;
}
void stats_ComputeInputStats(input_thread_t*, input_stats_t*);
void stats_ReinitInputStats(input_stats_t *);
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment