[vlc-commits] stats: allocate rate estimators in place
Rémi Denis-Courmont
git at videolan.org
Mon Dec 11 21:02:30 CET 2017
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Dec 11 22:01:17 2017 +0200| [91882d2da26b277edab5ba10d67fdc0ba76c4bc0] | committer: Rémi Denis-Courmont
stats: allocate rate estimators in place
This simplifies the input code.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=91882d2da26b277edab5ba10d67fdc0ba76c4bc0
---
src/input/access.c | 4 ++--
src/input/es_out.c | 3 ++-
src/input/input.c | 46 +++++------------------------------------
src/input/input_internal.h | 25 ++++++++++++++---------
src/input/stats.c | 51 +++++++++++++---------------------------------
5 files changed, 38 insertions(+), 91 deletions(-)
diff --git a/src/input/access.c b/src/input/access.c
index de2f223c4b..d591b22380 100644
--- a/src/input/access.c
+++ b/src/input/access.c
@@ -203,7 +203,7 @@ static block_t *AStreamReadBlock(stream_t *s, bool *restrict eof)
vlc_mutex_lock(&input_priv(input)->counters.counters_lock);
total = (input_priv(input)->counters.read_bytes += block->i_buffer);
- stats_Update(input_priv(input)->counters.p_input_bitrate, total);
+ input_rate_Update(&input_priv(input)->counters.input_bitrate, total);
input_priv(input)->counters.read_packets++;
vlc_mutex_unlock(&input_priv(input)->counters.counters_lock);
}
@@ -230,7 +230,7 @@ static ssize_t AStreamReadStream(stream_t *s, void *buf, size_t len)
vlc_mutex_lock(&input_priv(input)->counters.counters_lock);
total = (input_priv(input)->counters.read_bytes += val);
- stats_Update(input_priv(input)->counters.p_input_bitrate, total);
+ input_rate_Update(&input_priv(input)->counters.input_bitrate, total);
input_priv(input)->counters.read_packets++;
vlc_mutex_unlock(&input_priv(input)->counters.counters_lock);
}
diff --git a/src/input/es_out.c b/src/input/es_out.c
index c6e87ed8d3..5a3330aa5c 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -2048,7 +2048,8 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
vlc_mutex_lock( &input_priv(p_input)->counters.counters_lock );
i_total =
(input_priv(p_input)->counters.demux_read += p_block->i_buffer);
- stats_Update( input_priv(p_input)->counters.p_demux_bitrate, i_total );
+ input_rate_Update( &input_priv(p_input)->counters.demux_bitrate,
+ i_total );
/* Update number of corrupted data packats */
if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
diff --git a/src/input/input.c b/src/input/input.c
index 4b654f5f65..b395ec9760 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -670,7 +670,7 @@ static void MainLoopStatistics( input_thread_t *p_input )
vlc_mutex_lock( &input_priv(p_input)->p_item->lock );
input_priv(p_input)->bookmark.i_time_offset = i_time;
- stats_ComputeInputStats( p_input, input_priv(p_input)->p_item->p_stats );
+ input_stats_Compute( p_input, input_priv(p_input)->p_item->p_stats );
vlc_mutex_unlock( &input_priv(p_input)->p_item->lock );
input_SendEventStatistics( p_input );
@@ -811,15 +811,11 @@ static void InitStatistics( input_thread_t *p_input )
if( priv->b_preparsing ) return;
/* Prepare statistics */
-#define INIT_COUNTER( c ) free( priv->counters.p_##c ); \
- priv->counters.p_##c = stats_CounterCreate( );
if( libvlc_stats( p_input ) )
{
priv->counters.read_bytes = 0;
priv->counters.read_packets = 0;
priv->counters.demux_read = 0;
- INIT_COUNTER( input_bitrate );
- INIT_COUNTER( demux_bitrate );
priv->counters.demux_corrupted = 0;
priv->counters.demux_discontinuity = 0;
priv->counters.played_abuffers = 0;
@@ -829,9 +825,11 @@ static void InitStatistics( input_thread_t *p_input )
priv->counters.decoded_audio = 0;
priv->counters.decoded_video = 0;
priv->counters.decoded_sub = 0;
- priv->counters.p_sout_send_bitrate = NULL;
priv->counters.sout_sent_packets = 0;
priv->counters.sout_sent_bytes = 0;
+ input_rate_Init( &priv->counters.input_bitrate );
+ input_rate_Init( &priv->counters.demux_bitrate );
+ input_rate_Init( &priv->counters.sout_send_bitrate );
}
}
@@ -864,10 +862,6 @@ static int InitSout( input_thread_t * p_input )
free( psz );
return VLC_EGENERIC;
}
- if( libvlc_stats( p_input ) )
- {
- INIT_COUNTER( sout_send_bitrate );
- }
}
else
{
@@ -1415,21 +1409,6 @@ error:
input_resource_Terminate( input_priv(p_input)->p_resource_private );
}
- if( !priv->b_preparsing && libvlc_stats( p_input ) )
- {
-#define EXIT_COUNTER( c ) do { if( input_priv(p_input)->counters.p_##c ) \
- stats_CounterClean( input_priv(p_input)->counters.p_##c );\
- input_priv(p_input)->counters.p_##c = NULL; } while(0)
- EXIT_COUNTER( input_bitrate );
- EXIT_COUNTER( demux_bitrate );
-
- if( input_priv(p_input)->p_sout )
- {
- EXIT_COUNTER( sout_send_bitrate );
- }
-#undef EXIT_COUNTER
- }
-
/* Mark them deleted */
input_priv(p_input)->p_es_out = NULL;
input_priv(p_input)->p_sout = NULL;
@@ -1472,29 +1451,14 @@ static void End( input_thread_t * p_input )
if( !priv->b_preparsing )
{
-#define CL_CO( c ) \
-do { \
- stats_CounterClean( priv->counters.p_##c ); \
- priv->counters.p_##c = NULL; \
-} while (0)
-
if( libvlc_stats( p_input ) )
{
input_item_t *item = priv->p_item;
/* make sure we are up to date */
vlc_mutex_lock( &item->lock );
- stats_ComputeInputStats( p_input, item->p_stats );
+ input_stats_Compute( p_input, item->p_stats );
vlc_mutex_unlock( &item->lock );
- CL_CO( input_bitrate );
- CL_CO( demux_bitrate );
- }
-
- /* Close optional stream output instance */
- if( priv->p_sout )
- {
- CL_CO( sout_send_bitrate );
}
-#undef CL_CO
}
vlc_mutex_lock( &priv->p_item->lock );
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index aef91be44f..2d67c5c3cc 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -34,6 +34,15 @@
#include "input_interface.h"
#include "misc/interrupt.h"
+typedef struct input_rate_t
+{
+ struct
+ {
+ uintmax_t value;
+ mtime_t date;
+ } samples[2];
+} input_rate_t;
+
/*****************************************************************************
* Private input fields
*****************************************************************************/
@@ -150,9 +159,9 @@ typedef struct input_thread_private_t
struct {
uintmax_t read_packets;
uintmax_t read_bytes;
- counter_t *p_input_bitrate;
+ input_rate_t input_bitrate;
uintmax_t demux_read;
- counter_t *p_demux_bitrate;
+ input_rate_t demux_bitrate;
uintmax_t demux_corrupted;
uintmax_t demux_discontinuity;
uintmax_t decoded_audio;
@@ -160,7 +169,7 @@ typedef struct input_thread_private_t
uintmax_t decoded_sub;
uintmax_t sout_sent_packets;
uintmax_t sout_sent_bytes;
- counter_t *p_sout_send_bitrate;
+ input_rate_t sout_send_bitrate;
uintmax_t played_abuffers;
uintmax_t lost_abuffers;
uintmax_t displayed_pictures;
@@ -282,12 +291,8 @@ void vlc_audio_replay_gain_MergeFromMeta( audio_replay_gain_t *p_dst,
void input_item_node_PostAndDelete( input_item_node_t *p_node );
/* stats.c */
-typedef struct counter_t counter_t;
-
-counter_t * stats_CounterCreate(void);
-void stats_Update(counter_t *, uint64_t);
-void stats_CounterClean (counter_t * );
-
-void stats_ComputeInputStats(input_thread_t*, input_stats_t*);
+void input_rate_Init(input_rate_t *rate);
+void input_rate_Update(input_rate_t *, uintmax_t);
+void input_stats_Compute(input_thread_t *, input_stats_t*);
#endif
diff --git a/src/input/stats.c b/src/input/stats.c
index 4665341cb6..2d4a0133a1 100644
--- a/src/input/stats.c
+++ b/src/input/stats.c
@@ -31,39 +31,25 @@
#include <vlc_common.h>
#include "input/input_internal.h"
-struct counter_t
-{
- struct
- {
- uintmax_t value;
- mtime_t date;
- } samples[2];
-};
-
/**
* Create a statistics counter
*/
-counter_t * stats_CounterCreate( void )
+void input_rate_Init(input_rate_t *rate)
{
- counter_t *counter = malloc(sizeof (*counter)) ;
- if (unlikely(counter == NULL))
- return NULL;
-
- counter->samples[0].date = VLC_TS_INVALID;
- counter->samples[1].date = VLC_TS_INVALID;
- return counter;
+ rate->samples[0].date = VLC_TS_INVALID;
+ rate->samples[1].date = VLC_TS_INVALID;
}
-static float stats_GetRate(const counter_t *counter)
+static float stats_GetRate(const input_rate_t *rate)
{
- if (counter == NULL || counter->samples[1].date == VLC_TS_INVALID)
+ if (rate->samples[1].date == VLC_TS_INVALID)
return 0.;
- return (counter->samples[0].value - counter->samples[1].value)
- / (float)(counter->samples[0].date - counter->samples[1].date);
+ return (rate->samples[0].value - rate->samples[1].value)
+ / (float)(rate->samples[0].date - rate->samples[1].date);
}
-void stats_ComputeInputStats(input_thread_t *input, input_stats_t *st)
+void input_stats_Compute(input_thread_t *input, input_stats_t *st)
{
input_thread_private_t *priv = input_priv(input);
@@ -75,9 +61,9 @@ void stats_ComputeInputStats(input_thread_t *input, input_stats_t *st)
/* Input */
st->i_read_packets = priv->counters.read_packets;
st->i_read_bytes = priv->counters.read_bytes;
- st->f_input_bitrate = stats_GetRate(priv->counters.p_input_bitrate);
+ st->f_input_bitrate = stats_GetRate(&priv->counters.input_bitrate);
st->i_demux_read_bytes = priv->counters.demux_read;
- st->f_demux_bitrate = stats_GetRate(priv->counters.p_demux_bitrate);
+ st->f_demux_bitrate = stats_GetRate(&priv->counters.demux_bitrate);
st->i_demux_corrupted = priv->counters.demux_corrupted;
st->i_demux_discontinuity = priv->counters.demux_discontinuity;
@@ -86,12 +72,9 @@ void stats_ComputeInputStats(input_thread_t *input, input_stats_t *st)
st->i_decoded_audio = priv->counters.decoded_audio;
/* Sout */
- if (priv->counters.p_sout_send_bitrate)
- {
- st->i_sent_packets = priv->counters.sout_sent_packets;
- st->i_sent_bytes = priv->counters.sout_sent_bytes;
- st->f_send_bitrate = stats_GetRate(priv->counters.p_sout_send_bitrate);
- }
+ st->i_sent_packets = priv->counters.sout_sent_packets;
+ st->i_sent_bytes = priv->counters.sout_sent_bytes;
+ st->f_send_bitrate = stats_GetRate(&priv->counters.sout_send_bitrate);
/* Aout */
st->i_played_abuffers = priv->counters.played_abuffers;
@@ -104,18 +87,12 @@ void stats_ComputeInputStats(input_thread_t *input, input_stats_t *st)
vlc_mutex_unlock(&priv->counters.counters_lock);
}
-void stats_CounterClean(counter_t *counter)
-{
- free(counter);
-}
-
-
/** Update a counter element with new values
* \param p_counter the counter to update
* \param val the vlc_value union containing the new value to aggregate. For
* more information on how data is aggregated, \see stats_Create
*/
-void stats_Update(counter_t *counter, uint64_t val)
+void input_rate_Update(input_rate_t *counter, uintmax_t val)
{
if (counter == NULL)
return;
More information about the vlc-commits
mailing list