[vlc-commits] input: allocate stats in separate structure
Rémi Denis-Courmont
git at videolan.org
Tue Dec 12 19:36:52 CET 2017
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Dec 12 18:26:42 2017 +0200| [a021209d08c5d4cebe6af1d22ae83ab67b9a68b4] | committer: Rémi Denis-Courmont
input: allocate stats in separate structure
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a021209d08c5d4cebe6af1d22ae83ab67b9a68b4
---
src/input/access.c | 34 ++++++++++++-------
src/input/decoder.c | 30 +++++++++++------
src/input/es_out.c | 16 ++++-----
src/input/input.c | 82 +++++++++++++++++++---------------------------
src/input/input_internal.h | 54 ++++++++++++++++--------------
src/input/stats.c | 37 +++++++++------------
6 files changed, 129 insertions(+), 124 deletions(-)
diff --git a/src/input/access.c b/src/input/access.c
index d591b22380..f72dbcc7de 100644
--- a/src/input/access.c
+++ b/src/input/access.c
@@ -199,13 +199,18 @@ static block_t *AStreamReadBlock(stream_t *s, bool *restrict eof)
if (block != NULL && input != NULL)
{
- uint64_t total;
+ struct input_stats *stats = input_priv(input)->stats;
- vlc_mutex_lock(&input_priv(input)->counters.counters_lock);
- total = (input_priv(input)->counters.read_bytes += block->i_buffer);
- 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);
+ if (stats != NULL)
+ {
+ uint64_t total;
+
+ vlc_mutex_lock(&stats->lock);
+ total = (stats->read_bytes += block->i_buffer);
+ input_rate_Update(&stats->input_bitrate, total);
+ stats->read_packets++;
+ vlc_mutex_unlock(&stats->lock);
+ }
}
return block;
@@ -226,13 +231,18 @@ static ssize_t AStreamReadStream(stream_t *s, void *buf, size_t len)
if (val > 0 && input != NULL)
{
- uint64_t total;
+ struct input_stats *stats = input_priv(input)->stats;
- vlc_mutex_lock(&input_priv(input)->counters.counters_lock);
- total = (input_priv(input)->counters.read_bytes += val);
- 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);
+ if (stats != NULL)
+ {
+ uint64_t total;
+
+ vlc_mutex_lock(&stats->lock);
+ total = (stats->read_bytes += val);
+ input_rate_Update(&stats->input_bitrate, total);
+ stats->read_packets++;
+ vlc_mutex_unlock(&stats->lock);
+ }
}
return val;
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 859a190796..a8070b2325 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -1093,11 +1093,16 @@ static void DecoderUpdateStatVideo( decoder_owner_sys_t *p_owner,
lost += vout_lost;
}
- vlc_mutex_lock( &input_priv(p_input)->counters.counters_lock );
- input_priv(p_input)->counters.decoded_video += decoded;
- input_priv(p_input)->counters.lost_pictures += lost;
- input_priv(p_input)->counters.displayed_pictures += displayed;
- vlc_mutex_unlock( &input_priv(p_input)->counters.counters_lock );
+ struct input_stats *stats = input_priv(p_input)->stats;
+
+ if( stats != NULL )
+ {
+ vlc_mutex_lock( &stats->lock );
+ stats->decoded_video += decoded;
+ stats->lost_pictures += lost;
+ stats->displayed_pictures += displayed;
+ vlc_mutex_unlock( &stats->lock );
+ }
}
static int DecoderQueueVideo( decoder_t *p_dec, picture_t *p_pic )
@@ -1213,11 +1218,16 @@ static void DecoderUpdateStatAudio( decoder_owner_sys_t *p_owner,
lost += aout_lost;
}
- vlc_mutex_lock( &input_priv(p_input)->counters.counters_lock);
- input_priv(p_input)->counters.lost_abuffers += lost;
- input_priv(p_input)->counters.played_abuffers += played;
- input_priv(p_input)->counters.decoded_audio += decoded;
- vlc_mutex_unlock( &input_priv(p_input)->counters.counters_lock);
+ struct input_stats *stats = input_priv(p_input)->stats;
+
+ if( stats != NULL )
+ {
+ vlc_mutex_lock( &stats->lock );
+ stats->lost_abuffers += lost;
+ stats->played_abuffers += played;
+ stats->decoded_audio += decoded;
+ vlc_mutex_unlock( &stats->lock );
+ }
}
static int DecoderQueueAudio( decoder_t *p_dec, block_t *p_aout_buf )
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 5a3330aa5c..46fa26324f 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -2041,24 +2041,24 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
assert( p_block->p_next == NULL );
- if( libvlc_stats( p_input ) )
+ struct input_stats *stats = input_priv(p_input)->stats;
+ if( stats != NULL )
{
uint64_t i_total;
- vlc_mutex_lock( &input_priv(p_input)->counters.counters_lock );
+ vlc_mutex_lock( &stats->lock );
i_total =
- (input_priv(p_input)->counters.demux_read += p_block->i_buffer);
- input_rate_Update( &input_priv(p_input)->counters.demux_bitrate,
- i_total );
+ (stats->demux_read += p_block->i_buffer);
+ input_rate_Update( &stats->demux_bitrate, i_total );
/* Update number of corrupted data packats */
if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
- input_priv(p_input)->counters.demux_corrupted++;
+ stats->demux_corrupted++;
/* Update number of discontinuities */
if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
- input_priv(p_input)->counters.demux_discontinuity++;
- vlc_mutex_unlock( &input_priv(p_input)->counters.counters_lock );
+ stats->demux_discontinuity++;
+ vlc_mutex_unlock( &stats->lock );
}
vlc_mutex_lock( &p_sys->lock );
diff --git a/src/input/input.c b/src/input/input.c
index 91ac080461..91346d2455 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -252,7 +252,11 @@ static void input_Destructor( vlc_object_t *obj )
input_item_Release( priv->p_item );
- vlc_mutex_destroy( &priv->counters.counters_lock );
+ if( priv->stats != NULL )
+ {
+ vlc_mutex_destroy( &priv->stats->lock );
+ free( priv->stats );
+ }
for( int i = 0; i < priv->i_control; i++ )
{
@@ -468,8 +472,19 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
input_SendEventMeta( p_input );
/* */
- memset( &priv->counters, 0, sizeof( priv->counters ) );
- vlc_mutex_init( &priv->counters.counters_lock );
+ struct input_stats *stats = NULL;
+ if( !priv->b_preparsing && libvlc_stats(p_input) )
+ {
+ stats = malloc( sizeof (*stats) );
+ if( likely(stats != NULL) )
+ {
+ memset( stats, 0, sizeof (*stats) );
+ input_rate_Init( &stats->input_bitrate );
+ input_rate_Init( &stats->demux_bitrate );
+ vlc_mutex_init( &stats->lock );
+ }
+ }
+ priv->stats = stats;
priv->p_es_out_display = input_EsOutNew( p_input, priv->i_rate );
priv->p_es_out = NULL;
@@ -646,32 +661,32 @@ static int MainLoopTryRepeat( input_thread_t *p_input )
*/
static void MainLoopStatistics( input_thread_t *p_input )
{
+ input_thread_private_t *priv = input_priv(p_input);
double f_position = 0.0;
mtime_t i_time = 0;
mtime_t i_length = 0;
/* update input status variables */
- if( demux_Control( input_priv(p_input)->master->p_demux,
+ if( demux_Control( priv->master->p_demux,
DEMUX_GET_POSITION, &f_position ) )
f_position = 0.0;
- if( demux_Control( input_priv(p_input)->master->p_demux,
- DEMUX_GET_TIME, &i_time ) )
+ if( demux_Control( priv->master->p_demux, DEMUX_GET_TIME, &i_time ) )
i_time = 0;
input_priv(p_input)->i_time = i_time;
- if( demux_Control( input_priv(p_input)->master->p_demux,
- DEMUX_GET_LENGTH, &i_length ) )
+ if( demux_Control( priv->master->p_demux, DEMUX_GET_LENGTH, &i_length ) )
i_length = 0;
- es_out_SetTimes( input_priv(p_input)->p_es_out, f_position, i_time, i_length );
+ es_out_SetTimes( priv->p_es_out, f_position, i_time, i_length );
/* update current bookmark */
- vlc_mutex_lock( &input_priv(p_input)->p_item->lock );
- input_priv(p_input)->bookmark.i_time_offset = i_time;
+ vlc_mutex_lock( &priv->p_item->lock );
+ priv->bookmark.i_time_offset = i_time;
- input_stats_Compute( p_input, input_priv(p_input)->p_item->p_stats );
- vlc_mutex_unlock( &input_priv(p_input)->p_item->lock );
+ if( priv->stats != NULL )
+ input_stats_Compute( priv->stats, priv->p_item->p_stats );
+ vlc_mutex_unlock( &priv->p_item->lock );
input_SendEventStatistics( p_input );
}
@@ -804,31 +819,6 @@ static void MainLoop( input_thread_t *p_input, bool b_interactive )
}
}
-static void InitStatistics( input_thread_t *p_input )
-{
- input_thread_private_t *priv = input_priv(p_input);
-
- if( priv->b_preparsing ) return;
-
- /* Prepare statistics */
- if( libvlc_stats( p_input ) )
- {
- priv->counters.read_bytes = 0;
- priv->counters.read_packets = 0;
- priv->counters.demux_read = 0;
- priv->counters.demux_corrupted = 0;
- priv->counters.demux_discontinuity = 0;
- priv->counters.played_abuffers = 0;
- priv->counters.lost_abuffers = 0;
- priv->counters.displayed_pictures = 0;
- priv->counters.lost_pictures = 0;
- priv->counters.decoded_audio = 0;
- priv->counters.decoded_video = 0;
- input_rate_Init( &priv->counters.input_bitrate );
- input_rate_Init( &priv->counters.demux_bitrate );
- }
-}
-
#ifdef ENABLE_SOUT
static int InitSout( input_thread_t * p_input )
{
@@ -1306,7 +1296,6 @@ static int Init( input_thread_t * p_input )
var_SetBool( p_input, "sub-autodetect-file", false );
}
- InitStatistics( p_input );
#ifdef ENABLE_SOUT
if( InitSout( p_input ) )
goto error;
@@ -1445,16 +1434,13 @@ static void End( input_thread_t * p_input )
es_out_Delete( priv->p_es_out );
es_out_SetMode( priv->p_es_out_display, ES_OUT_MODE_END );
- if( !priv->b_preparsing )
+ if( priv->stats != NULL )
{
- if( libvlc_stats( p_input ) )
- {
- input_item_t *item = priv->p_item;
- /* make sure we are up to date */
- vlc_mutex_lock( &item->lock );
- input_stats_Compute( p_input, item->p_stats );
- vlc_mutex_unlock( &item->lock );
- }
+ input_item_t *item = priv->p_item;
+ /* make sure we are up to date */
+ vlc_mutex_lock( &item->lock );
+ input_stats_Compute( priv->stats, item->p_stats );
+ vlc_mutex_unlock( &item->lock );
}
vlc_mutex_lock( &priv->p_item->lock );
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index c92b8e7af0..24340c6df4 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -34,14 +34,7 @@
#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;
+struct input_stats;
/*****************************************************************************
* Private input fields
@@ -156,22 +149,7 @@ typedef struct input_thread_private_t
input_resource_t *p_resource_private;
/* Stats counters */
- struct {
- uintmax_t read_packets;
- uintmax_t read_bytes;
- input_rate_t input_bitrate;
- uintmax_t demux_read;
- input_rate_t demux_bitrate;
- uintmax_t demux_corrupted;
- uintmax_t demux_discontinuity;
- uintmax_t decoded_audio;
- uintmax_t decoded_video;
- uintmax_t played_abuffers;
- uintmax_t lost_abuffers;
- uintmax_t displayed_pictures;
- uintmax_t lost_pictures;
- vlc_mutex_t counters_lock;
- } counters;
+ struct input_stats *stats;
/* Buffer of pending actions */
vlc_mutex_t lock_control;
@@ -287,8 +265,34 @@ 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 input_rate_t
+{
+ struct
+ {
+ uintmax_t value;
+ mtime_t date;
+ } samples[2];
+} input_rate_t;
+
+struct input_stats {
+ uintmax_t read_packets;
+ uintmax_t read_bytes;
+ input_rate_t input_bitrate;
+ uintmax_t demux_read;
+ input_rate_t demux_bitrate;
+ uintmax_t demux_corrupted;
+ uintmax_t demux_discontinuity;
+ uintmax_t decoded_audio;
+ uintmax_t decoded_video;
+ uintmax_t played_abuffers;
+ uintmax_t lost_abuffers;
+ uintmax_t displayed_pictures;
+ uintmax_t lost_pictures;
+ vlc_mutex_t lock;
+};
+
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*);
+void input_stats_Compute(struct input_stats *, input_stats_t*);
#endif
diff --git a/src/input/stats.c b/src/input/stats.c
index e0535346d4..fb803394e1 100644
--- a/src/input/stats.c
+++ b/src/input/stats.c
@@ -49,37 +49,32 @@ static float stats_GetRate(const input_rate_t *rate)
/ (float)(rate->samples[0].date - rate->samples[1].date);
}
-void input_stats_Compute(input_thread_t *input, input_stats_t *st)
+void input_stats_Compute(struct input_stats *stats, input_stats_t *st)
{
- input_thread_private_t *priv = input_priv(input);
-
- if (!libvlc_stats(input))
- return;
-
- vlc_mutex_lock(&priv->counters.counters_lock);
+ vlc_mutex_lock(&stats->lock);
/* 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.input_bitrate);
- st->i_demux_read_bytes = priv->counters.demux_read;
- 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;
+ st->i_read_packets = stats->read_packets;
+ st->i_read_bytes = stats->read_bytes;
+ st->f_input_bitrate = stats_GetRate(&stats->input_bitrate);
+ st->i_demux_read_bytes = stats->demux_read;
+ st->f_demux_bitrate = stats_GetRate(&stats->demux_bitrate);
+ st->i_demux_corrupted = stats->demux_corrupted;
+ st->i_demux_discontinuity = stats->demux_discontinuity;
/* Decoders */
- st->i_decoded_video = priv->counters.decoded_video;
- st->i_decoded_audio = priv->counters.decoded_audio;
+ st->i_decoded_video = stats->decoded_video;
+ st->i_decoded_audio = stats->decoded_audio;
/* Aout */
- st->i_played_abuffers = priv->counters.played_abuffers;
- st->i_lost_abuffers = priv->counters.lost_abuffers;
+ st->i_played_abuffers = stats->played_abuffers;
+ st->i_lost_abuffers = stats->lost_abuffers;
/* Vouts */
- st->i_displayed_pictures = priv->counters.displayed_pictures;
- st->i_lost_pictures = priv->counters.lost_pictures;
+ st->i_displayed_pictures = stats->displayed_pictures;
+ st->i_lost_pictures = stats->lost_pictures;
- vlc_mutex_unlock(&priv->counters.counters_lock);
+ vlc_mutex_unlock(&stats->lock);
}
/** Update a counter element with new values
More information about the vlc-commits
mailing list