]> git.sesse.net Git - vlc/blobdiff - src/input/stream.c
Remove uninitialized and unsynchronized global stats
[vlc] / src / input / stream.c
index b50a1a3bb3796455b60749e2c8df8d4d7670b4ab..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)
@@ -182,9 +182,6 @@ struct stream_sys_t
     access_entry_t **list;
     int            i_list_index;
     access_t       *p_list_access;
-
-    /* Preparse mode ? */
-    bool      b_quick;
 };
 
 /* Method 1: */
@@ -240,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 );
 }
 
@@ -269,7 +267,7 @@ stream_t *__stream_UrlNew( vlc_object_t *p_parent, const char *psz_url )
         return NULL;
     }
 
-    if( !( p_res = stream_AccessNew( p_access, true ) ) )
+    if( !( p_res = stream_AccessNew( p_access, NULL ) ) )
     {
         access_Delete( p_access );
         return NULL;
@@ -279,17 +277,17 @@ stream_t *__stream_UrlNew( vlc_object_t *p_parent, const char *psz_url )
     return p_res;
 }
 
-stream_t *stream_AccessNew( access_t *p_access, bool b_quick )
+stream_t *stream_AccessNew( access_t *p_access, char **ppsz_list )
 {
     stream_t *s = stream_CommonNew( VLC_OBJECT(p_access) );
     stream_sys_t *p_sys;
-    char *psz_list = NULL;
 
     if( !s )
         return NULL;
 
-    s->p_sys = p_sys = malloc( sizeof( stream_sys_t ) );
-    if( !p_sys )
+    s->psz_path = strdup( p_access->psz_path );
+    s->p_sys = p_sys = malloc( sizeof( *p_sys ) );
+    if( !s->psz_path || !s->p_sys )
     {
         stream_CommonDelete( s );
         return NULL;
@@ -320,69 +318,54 @@ stream_t *stream_AccessNew( access_t *p_access, bool b_quick )
     p_sys->stat.i_seek_count = 0;
     p_sys->stat.i_seek_time = 0;
 
-    p_sys->i_list = 0;
-    p_sys->list = 0;
+    TAB_INIT( p_sys->i_list, p_sys->list );
     p_sys->i_list_index = 0;
-    p_sys->p_list_access = 0;
-
-    p_sys->b_quick = b_quick;
+    p_sys->p_list_access = NULL;
 
     /* Get the additional list of inputs if any (for concatenation) */
-    if( (psz_list = var_CreateGetString( s, "input-list" )) && *psz_list )
+    if( ppsz_list && ppsz_list[0] )
     {
-        access_entry_t *p_entry = malloc( sizeof(access_entry_t) );
-        if( p_entry == NULL )
+        access_entry_t *p_entry = malloc( sizeof(*p_entry) );
+        if( !p_entry )
             goto error;
-        char *psz_name, *psz_parser = psz_name = psz_list;
 
-        p_sys->p_list_access = p_access;
         p_entry->i_size = p_access->info.i_size;
         p_entry->psz_path = strdup( p_access->psz_path );
-        if( p_entry->psz_path == NULL )
+        if( !p_entry->psz_path )
         {
             free( p_entry );
             goto error;
         }
+        p_sys->p_list_access = p_access;
         TAB_APPEND( p_sys->i_list, p_sys->list, p_entry );
         msg_Dbg( p_access, "adding file `%s', (%"PRId64" bytes)",
                  p_entry->psz_path, p_access->info.i_size );
 
-        while( psz_name && *psz_name )
+        for( int i = 0; ppsz_list[i] != NULL; i++ )
         {
-            psz_parser = strchr( psz_name, ',' );
-            if( psz_parser ) *psz_parser = 0;
+            char *psz_name = strdup( ppsz_list[i] );
 
-            psz_name = strdup( psz_name );
-            if( psz_name )
-            {
-                access_t *p_tmp = access_New( p_access, p_access->psz_access,
-                                               "", psz_name );
+            if( !psz_name )
+                break;
 
-                if( !p_tmp )
-                {
-                    psz_name = psz_parser;
-                    if( psz_name ) psz_name++;
-                    continue;
-                }
+            access_t *p_tmp = access_New( p_access,
+                                          p_access->psz_access, "", psz_name );
+            if( !p_tmp )
+                continue;
 
-                msg_Dbg( p_access, "adding file `%s', (%"PRId64" bytes)",
-                         psz_name, p_tmp->info.i_size );
+            msg_Dbg( p_access, "adding file `%s', (%"PRId64" bytes)",
+                     psz_name, p_tmp->info.i_size );
 
-                p_entry = malloc( sizeof(access_entry_t) );
-                if( p_entry == NULL )
-                    goto error;
+            p_entry = malloc( sizeof(*p_entry) );
+            if( p_entry )
+            {
                 p_entry->i_size = p_tmp->info.i_size;
                 p_entry->psz_path = psz_name;
                 TAB_APPEND( p_sys->i_list, p_sys->list, p_entry );
-
-                access_Delete( p_tmp );
             }
-
-            psz_name = psz_parser;
-            if( psz_name ) psz_name++;
+            access_Delete( p_tmp );
         }
     }
-    FREENULL( psz_list );
 
     /* Peek */
     p_sys->i_peek = 0;
@@ -429,12 +412,10 @@ stream_t *stream_AccessNew( access_t *p_access, bool b_quick )
         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++ )
         {
@@ -469,7 +450,6 @@ error:
     while( p_sys->i_list > 0 )
         free( p_sys->list[--(p_sys->i_list)] );
     free( p_sys->list );
-    free( psz_list );
     free( s->p_sys );
     vlc_object_detach( s );
     stream_CommonDelete( s );
@@ -635,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 );
@@ -678,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;
@@ -988,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;
@@ -1000,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 */
@@ -1024,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;
@@ -1039,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;
@@ -1054,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;
 }
@@ -1419,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;
@@ -1696,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 )
@@ -1766,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 )