[vlc-devel] [PATCH 1/2] cache_block: follow block->i_size for memory usage

Ilkka Ollakka ileoo at videolan.org
Sat Jan 30 12:54:50 CET 2016


Should be more accurate on actual memory usage, block->i_buffer just
mentions how much usefull payload there is.

Fixes #16315
---
 modules/stream_filter/cache_block.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/modules/stream_filter/cache_block.c b/modules/stream_filter/cache_block.c
index dc31506..e0db302 100644
--- a/modules/stream_filter/cache_block.c
+++ b/modules/stream_filter/cache_block.c
@@ -72,7 +72,8 @@ struct stream_sys_t
     uint64_t     i_offset;       /* Offset for data in p_current */
     block_t     *p_current;     /* Current block */
 
-    uint64_t     i_size;         /* Total amount of data in the list */
+    uint64_t     i_size;         /* Total amount of memory user in the list */
+    uint64_t     i_buffer;       /* Total amount of data in the list */
     block_t     *p_first;
     block_t    **pp_last;
 
@@ -108,7 +109,8 @@ static int AStreamRefillBlock(stream_t *s)
         block_t *b = sys->p_first;
 
         sys->i_start += b->i_buffer;
-        sys->i_size  -= b->i_buffer;
+        sys->i_size  -= b->i_size;
+        sys->i_buffer -= b->i_buffer;
         sys->p_first  = b->p_next;
 
         block_Release(b);
@@ -143,7 +145,8 @@ static int AStreamRefillBlock(stream_t *s)
     while (b)
     {
         /* Append the block */
-        sys->i_size += b->i_buffer;
+        sys->i_size += b->i_size;
+        sys->i_buffer += b->i_buffer;
         *sys->pp_last = b;
         sys->pp_last = &b->p_next;
 
@@ -171,12 +174,12 @@ static void AStreamPrebufferBlock(stream_t *s)
     {
         const int64_t now = mdate();
 
-        if (vlc_killed() || sys->i_size > STREAM_CACHE_PREBUFFER_SIZE)
+        if (vlc_killed() || sys->i_buffer > STREAM_CACHE_PREBUFFER_SIZE)
         {
             int64_t i_byterate;
 
             /* Update stat */
-            sys->stat.i_bytes = sys->i_size;
+            sys->stat.i_bytes = sys->i_buffer;
             sys->stat.i_read_time = now - start;
             i_byterate = (CLOCK_FREQ * sys->stat.i_bytes) /
                          (sys->stat.i_read_time + 1);
@@ -202,7 +205,8 @@ static void AStreamPrebufferBlock(stream_t *s)
         while (b)
         {
             /* Append the block */
-            sys->i_size += b->i_buffer;
+            sys->i_size += b->i_size;
+            sys->i_buffer += b->i_buffer;
             *sys->pp_last = b;
             sys->pp_last = &b->p_next;
 
@@ -237,6 +241,7 @@ static void AStreamControlReset(stream_t *s)
     sys->i_offset = 0;
     sys->p_current = NULL;
     sys->i_size = 0;
+    sys->i_buffer = 0;
     sys->p_first = NULL;
     sys->pp_last = &sys->p_first;
 
@@ -251,7 +256,7 @@ static int AStreamSeekBlock(stream_t *s, uint64_t i_pos)
     bool b_seek;
 
     /* We already have thoses data, just update p_current/i_offset */
-    if (i_offset >= 0 && (uint64_t)i_offset < sys->i_size)
+    if (i_offset >= 0 && (uint64_t)i_offset < sys->i_buffer)
     {
         block_t *b = sys->p_first;
         int i_current = 0;
@@ -295,11 +300,11 @@ static int AStreamSeekBlock(stream_t *s, uint64_t i_pos)
         {
             b_seek = false;
             msg_Warn(s, "%"PRId64" bytes need to be skipped "
-                      "(access non seekable)", i_offset - sys->i_size);
+                      "(access non seekable)", i_offset - sys->i_buffer);
         }
         else
         {
-            int64_t i_skip = i_offset - sys->i_size;
+            int64_t i_skip = i_offset - sys->i_buffer;
 
             /* Avg bytes per packets */
             int i_avg = sys->stat.i_bytes / sys->stat.i_read_count;
@@ -330,6 +335,7 @@ static int AStreamSeekBlock(stream_t *s, uint64_t i_pos)
         sys->i_offset = 0;
         sys->p_current = NULL;
         sys->i_size = 0;
+        sys->i_buffer = 0;
         sys->p_first = NULL;
         sys->pp_last = &sys->p_first;
 
@@ -356,7 +362,7 @@ static int AStreamSeekBlock(stream_t *s, uint64_t i_pos)
                     return VLC_EGENERIC;
             }
         }
-        while (sys->i_start + sys->i_size < i_pos);
+        while (sys->i_start + sys->i_buffer < i_pos);
 
         sys->i_offset += i_pos - sys->i_pos;
         sys->i_pos = i_pos;
@@ -472,6 +478,7 @@ static int Open(vlc_object_t *obj)
     sys->i_offset = 0;
     sys->p_current = NULL;
     sys->i_size = 0;
+    sys->i_buffer = 0;
     sys->p_first = NULL;
     sys->pp_last = &sys->p_first;
 
-- 
2.6.2



More information about the vlc-devel mailing list