]> git.sesse.net Git - vlc/blobdiff - src/input/stream.c
Remove uninitialized and unsynchronized global stats
[vlc] / src / input / stream.c
index 6f239473acb3c45b0d2c7a79b8c175fc48293661..ec2570502cf97b9b9c422f3a77f5e3e979d8cbb9 100644 (file)
@@ -40,7 +40,7 @@
 
 #include "input_internal.h"
 
-#undef STREAM_DEBUG
+// #define STREAM_DEBUG 1
 
 /* TODO:
  *  - tune the 2 methods (block/stream)
@@ -237,6 +237,7 @@ void stream_CommonDelete( stream_t *s )
             vlc_iconv_close( s->p_text->conv );
         free( s->p_text );
     }
+    free( s->psz_path );
     vlc_object_release( s );
 }
 
@@ -284,8 +285,9 @@ stream_t *stream_AccessNew( access_t *p_access, char **ppsz_list )
     if( !s )
         return NULL;
 
+    s->psz_path = strdup( p_access->psz_path );
     s->p_sys = p_sys = malloc( sizeof( *p_sys ) );
-    if( !p_sys )
+    if( !s->psz_path || !s->p_sys )
     {
         stream_CommonDelete( s );
         return NULL;
@@ -410,12 +412,10 @@ stream_t *stream_AccessNew( access_t *p_access, char **ppsz_list )
         if( p_sys->stream.p_buffer == NULL )
             goto error;
         p_sys->stream.i_used   = 0;
-        access_Control( p_access, ACCESS_GET_MTU,
-                         &p_sys->stream.i_read_size );
-        if( p_sys->stream.i_read_size <= 0 )
-            p_sys->stream.i_read_size = STREAM_READ_ATONCE;
-        else if( p_sys->stream.i_read_size <= 256 )
-            p_sys->stream.i_read_size = 256;
+        p_sys->stream.i_read_size = STREAM_READ_ATONCE;
+#if STREAM_READ_ATONCE < 256
+#   error "Invalid STREAM_READ_ATONCE value"
+#endif
 
         for( i = 0; i < STREAM_CACHE_TRACK; i++ )
         {
@@ -615,9 +615,6 @@ static int AStreamControl( stream_t *s, int i_query, va_list args )
                 return VLC_EGENERIC;
             }
 
-        case STREAM_GET_MTU:
-            return VLC_EGENERIC;
-
         case STREAM_CONTROL_ACCESS:
         {
             i_int = (int) va_arg( args, int );
@@ -658,7 +655,6 @@ static int AStreamControl( stream_t *s, int i_query, va_list args )
 static void AStreamPrebufferBlock( stream_t *s )
 {
     stream_sys_t *p_sys = s->p_sys;
-    access_t     *p_access = p_sys->p_access;
 
     int64_t i_first = 0;
     int64_t i_start;
@@ -968,7 +964,7 @@ static int AStreamSeekBlock( stream_t *s, int64_t i_pos )
         }
         while( p_sys->block.i_start + p_sys->block.i_size < i_pos );
 
-        p_sys->block.i_offset = i_pos - p_sys->i_pos;
+        p_sys->block.i_offset += i_pos - p_sys->i_pos;
         p_sys->i_pos = i_pos;
 
         return VLC_SUCCESS;
@@ -980,7 +976,6 @@ static int AStreamSeekBlock( stream_t *s, int64_t i_pos )
 static int AStreamRefillBlock( stream_t *s )
 {
     stream_sys_t *p_sys = s->p_sys;
-    int64_t      i_start, i_stop;
     block_t      *b;
 
     /* Release data */
@@ -1004,7 +999,7 @@ static int AStreamRefillBlock( stream_t *s )
     }
 
     /* Now read a new block */
-    i_start = mdate();
+    const int64_t i_start = mdate();
     for( ;; )
     {
         bool b_eof;
@@ -1019,10 +1014,9 @@ static int AStreamRefillBlock( stream_t *s )
             return VLC_EGENERIC;
     }
 
+    p_sys->stat.i_read_time += mdate() - i_start;
     while( b )
     {
-        i_stop = mdate();
-
         /* Append the block */
         p_sys->block.i_size += b->i_buffer;
         *p_sys->block.pp_last = b;
@@ -1034,11 +1028,9 @@ static int AStreamRefillBlock( stream_t *s )
 
         /* Update stat */
         p_sys->stat.i_bytes += b->i_buffer;
-        p_sys->stat.i_read_time += i_stop - i_start;
         p_sys->stat.i_read_count++;
 
         b = b->p_next;
-        i_start = mdate();
     }
     return VLC_SUCCESS;
 }
@@ -1399,7 +1391,6 @@ static int AStreamRefillStream( stream_t *s )
 static void AStreamPrebufferStream( stream_t *s )
 {
     stream_sys_t *p_sys = s->p_sys;
-    access_t     *p_access = p_sys->p_access;
 
     int64_t i_first = 0;
     int64_t i_start;
@@ -1676,7 +1667,7 @@ static int AReadStream( stream_t *s, void *p_read, unsigned int i_read )
     int i_total = 0;
 
     if( s->p_parent && s->p_parent->p_parent &&
-        s->p_parent->p_parent->i_object_type == VLC_OBJECT_INPUT )
+        vlc_internals( s->p_parent->p_parent )->i_object_type == VLC_OBJECT_INPUT )
         p_input = (input_thread_t *)s->p_parent->p_parent;
 
     if( !p_sys->i_list )
@@ -1746,7 +1737,7 @@ static block_t *AReadBlock( stream_t *s, bool *pb_eof )
     int i_total = 0;
 
     if( s->p_parent && s->p_parent->p_parent &&
-        s->p_parent->p_parent->i_object_type == VLC_OBJECT_INPUT )
+        vlc_internals( s->p_parent->p_parent )->i_object_type == VLC_OBJECT_INPUT )
         p_input = (input_thread_t *)s->p_parent->p_parent;
 
     if( !p_sys->i_list )