[vlc-commits] stats: factor sum and rate code

Rémi Denis-Courmont git at videolan.org
Tue Dec 12 19:36:57 CET 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Dec 12 19:56:06 2017 +0200| [69faa87b8a5d78248827a6478307376f354d0e21] | committer: Rémi Denis-Courmont

stats: factor sum and rate code

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=69faa87b8a5d78248827a6478307376f354d0e21
---

 src/input/access.c         | 10 ++--------
 src/input/es_out.c         |  6 +-----
 src/input/input_internal.h |  5 ++---
 src/input/stats.c          | 12 ++++++------
 4 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/src/input/access.c b/src/input/access.c
index f72dbcc7de..730a91454a 100644
--- a/src/input/access.c
+++ b/src/input/access.c
@@ -203,12 +203,9 @@ static block_t *AStreamReadBlock(stream_t *s, bool *restrict eof)
 
         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++;
+            input_rate_Add(&stats->input_bitrate, block->i_buffer);
             vlc_mutex_unlock(&stats->lock);
         }
     }
@@ -235,12 +232,9 @@ static ssize_t AStreamReadStream(stream_t *s, void *buf, size_t len)
 
         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++;
+            input_rate_Add(&stats->input_bitrate, val);
             vlc_mutex_unlock(&stats->lock);
         }
     }
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 46fa26324f..896a2bbb24 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -2044,12 +2044,8 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
     struct input_stats *stats = input_priv(p_input)->stats;
     if( stats != NULL )
     {
-        uint64_t i_total;
-
         vlc_mutex_lock( &stats->lock );
-        i_total =
-            (stats->demux_read += p_block->i_buffer);
-        input_rate_Update( &stats->demux_bitrate, i_total );
+        input_rate_Add( &stats->demux_bitrate, p_block->i_buffer );
 
         /* Update number of corrupted data packats */
         if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 79cadb7af3..d82e82623d 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -268,6 +268,7 @@ void input_item_node_PostAndDelete( input_item_node_t *p_node );
 /* stats.c */
 typedef struct input_rate_t
 {
+    uintmax_t value;
     struct
     {
         uintmax_t value;
@@ -278,9 +279,7 @@ typedef struct input_rate_t
 struct input_stats {
     vlc_mutex_t lock;
     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;
@@ -294,7 +293,7 @@ struct input_stats {
 
 struct input_stats *input_stats_Create(void);
 void input_stats_Destroy(struct input_stats *);
-void input_rate_Update(input_rate_t *, uintmax_t);
+void input_rate_Add(input_rate_t *, uintmax_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 4e02888ebd..059434a287 100644
--- a/src/input/stats.c
+++ b/src/input/stats.c
@@ -36,6 +36,7 @@
  */
 static void input_rate_Init(input_rate_t *rate)
 {
+    rate->value = 0;
     rate->samples[0].date = VLC_TS_INVALID;
     rate->samples[1].date = VLC_TS_INVALID;
 }
@@ -80,9 +81,9 @@ void input_stats_Compute(struct input_stats *stats, input_stats_t *st)
 
     /* Input */
     st->i_read_packets = stats->read_packets;
-    st->i_read_bytes = stats->read_bytes;
+    st->i_read_bytes = stats->input_bitrate.value;
     st->f_input_bitrate = stats_GetRate(&stats->input_bitrate);
-    st->i_demux_read_bytes = stats->demux_read;
+    st->i_demux_read_bytes = stats->demux_bitrate.value;
     st->f_demux_bitrate = stats_GetRate(&stats->demux_bitrate);
     st->i_demux_corrupted = stats->demux_corrupted;
     st->i_demux_discontinuity = stats->demux_discontinuity;
@@ -111,10 +112,9 @@ void input_stats_Compute(struct input_stats *stats, input_stats_t *st)
  * \param val the vlc_value union containing the new value to aggregate. For
  * more information on how data is aggregated, \see stats_Create
  */
-void input_rate_Update(input_rate_t *counter, uintmax_t val)
+void input_rate_Add(input_rate_t *counter, uintmax_t val)
 {
-    if (counter == NULL)
-        return;
+    counter->value += val;
 
     /* Ignore samples within a second of another */
     mtime_t now = mdate();
@@ -125,6 +125,6 @@ void input_rate_Update(input_rate_t *counter, uintmax_t val)
     memcpy(counter->samples + 1, counter->samples,
            sizeof (counter->samples[0]));
 
-    counter->samples[0].value = val;
+    counter->samples[0].value = counter->value;
     counter->samples[0].date = now;
 }



More information about the vlc-commits mailing list