]> git.sesse.net Git - vlc/blobdiff - src/input/stream.c
stream: remove shadow variable
[vlc] / src / input / stream.c
index 4e29dea10596dd5c776c2542034166ed9f058894..42cd823bf5e1a918605278872610b24ebc7b8b7c 100644 (file)
@@ -116,7 +116,8 @@ typedef struct
 typedef enum
 {
     STREAM_METHOD_BLOCK,
-    STREAM_METHOD_STREAM
+    STREAM_METHOD_STREAM,
+    STREAM_METHOD_READDIR
 } stream_read_method_t;
 
 struct stream_sys_t
@@ -197,7 +198,11 @@ static int  AStreamSeekStream( stream_t *s, uint64_t i_pos );
 static void AStreamPrebufferStream( stream_t *s );
 static int  AReadStream( stream_t *s, void *p_read, unsigned int i_read );
 
+/* ReadDir */
+static int  AStreamReadDir( stream_t *s, input_item_node_t *p_node );
+
 /* Common */
+static int  AStreamGenericError( ) { return VLC_EGENERIC; }
 static int AStreamControl( stream_t *s, int i_query, va_list );
 static void AStreamDestroy( stream_t *s );
 static int  ASeek( stream_t *s, uint64_t i_pos );
@@ -285,17 +290,21 @@ stream_t *stream_AccessNew( access_t *p_access, char **ppsz_list )
         return NULL;
     }
 
-    s->pf_read   = NULL;    /* Set up later */
-    s->pf_peek   = NULL;
+    s->pf_read    = AStreamGenericError;    /* Replaced later */
+    s->pf_peek    = AStreamGenericError;
+    s->pf_readdir = AStreamGenericError;
     s->pf_control = AStreamControl;
     s->pf_destroy = AStreamDestroy;
 
     /* Common field */
     p_sys->p_access = p_access;
+    assert( p_access->pf_block || p_access->pf_read || p_access->pf_readdir );
     if( p_access->pf_block )
         p_sys->method = STREAM_METHOD_BLOCK;
-    else
+    else if( p_access->pf_read )
         p_sys->method = STREAM_METHOD_STREAM;
+    else
+        p_sys->method = STREAM_METHOD_READDIR;
 
     p_sys->i_pos = p_access->info.i_pos;
 
@@ -340,7 +349,10 @@ stream_t *stream_AccessNew( access_t *p_access, char **ppsz_list )
             access_t *p_tmp = access_New( p_access, p_access->p_input,
                                           p_access->psz_access, "", psz_name );
             if( !p_tmp )
+            {
+                free( psz_name );
                 continue;
+            }
 
             p_entry = malloc( sizeof(*p_entry) );
             if( p_entry )
@@ -382,12 +394,10 @@ stream_t *stream_AccessNew( access_t *p_access, char **ppsz_list )
             goto error;
         }
     }
-    else
+    else if ( p_sys->method == STREAM_METHOD_STREAM )
     {
         int i;
 
-        assert( p_sys->method == STREAM_METHOD_STREAM );
-
         msg_Dbg( s, "Using stream method for AStream*" );
 
         s->pf_read = AStreamReadStream;
@@ -423,6 +433,13 @@ stream_t *stream_AccessNew( access_t *p_access, char **ppsz_list )
             goto error;
         }
     }
+    else
+    {
+        msg_Dbg( s, "Using readdir method for AStream*" );
+
+        assert( p_sys->method == STREAM_METHOD_READDIR );
+        s->pf_readdir = AStreamReadDir;
+    }
 
     return s;
 
@@ -431,7 +448,7 @@ error:
     {
         /* Nothing yet */
     }
-    else
+    else if( p_sys->method == STREAM_METHOD_STREAM )
     {
         free( p_sys->stream.p_buffer );
     }
@@ -453,7 +470,7 @@ static void AStreamDestroy( stream_t *s )
 
     if( p_sys->method == STREAM_METHOD_BLOCK )
         block_ChainRelease( p_sys->block.p_first );
-    else
+    else if( p_sys->method == STREAM_METHOD_STREAM )
         free( p_sys->stream.p_buffer );
 
     free( p_sys->p_peek );
@@ -554,6 +571,7 @@ static int AStreamControl( stream_t *s, int i_query, va_list args )
     static_control_match(CAN_FASTSEEK);
     static_control_match(CAN_PAUSE);
     static_control_match(CAN_CONTROL_PACE);
+    static_control_match(GET_PTS_DELAY);
     static_control_match(GET_TITLE_INFO);
     static_control_match(GET_TITLE);
     static_control_match(GET_SEEKPOINT);
@@ -573,6 +591,7 @@ static int AStreamControl( stream_t *s, int i_query, va_list args )
         case STREAM_CAN_FASTSEEK:
         case STREAM_CAN_PAUSE:
         case STREAM_CAN_CONTROL_PACE:
+        case STREAM_GET_PTS_DELAY:
         case STREAM_GET_TITLE_INFO:
         case STREAM_GET_TITLE:
         case STREAM_GET_SEEKPOINT:
@@ -632,6 +651,13 @@ static int AStreamControl( stream_t *s, int i_query, va_list args )
             return ret;
         }
 
+        case STREAM_IS_DIRECTORY:
+        {
+            bool *pb_canreaddir = va_arg( args, bool * );
+            *pb_canreaddir = p_sys->method == STREAM_METHOD_READDIR;
+            return VLC_SUCCESS;
+        }
+
         case STREAM_SET_RECORD_STATE:
         default:
             msg_Err( s, "invalid stream_vaControl query=0x%x", i_query );
@@ -665,13 +691,13 @@ static void AStreamPrebufferBlock( stream_t *s )
             /* Update stat */
             p_sys->stat.i_bytes = p_sys->block.i_size;
             p_sys->stat.i_read_time = i_date - i_start;
-            i_byterate = ( INT64_C(1000000) * p_sys->stat.i_bytes ) /
+            i_byterate = ( CLOCK_FREQ * p_sys->stat.i_bytes ) /
                          (p_sys->stat.i_read_time + 1);
 
             msg_Dbg( s, "prebuffering done %"PRId64" bytes in %"PRId64"s - "
                      "%"PRId64" KiB/s",
                      p_sys->stat.i_bytes,
-                     p_sys->stat.i_read_time / INT64_C(1000000),
+                     p_sys->stat.i_read_time / CLOCK_FREQ,
                      i_byterate / 1024 );
             break;
         }
@@ -722,9 +748,9 @@ static int AStreamReadBlock( stream_t *s, void *p_read, unsigned int i_read )
     if( p_data == NULL )
     {
         /* seek within this stream if possible, else use plain old read and discard */
-        stream_sys_t *p_sys = s->p_sys;
-        access_t     *p_access = p_sys->p_access;
-        bool   b_aseek;
+        access_t *p_access = p_sys->p_access;
+        bool b_aseek;
+
         access_Control( p_access, ACCESS_CAN_SEEK, &b_aseek );
         if( b_aseek )
             return AStreamSeekBlock( s, p_sys->i_pos + i_read ) ? 0 : i_read;
@@ -968,7 +994,6 @@ static int AStreamSeekBlock( stream_t *s, uint64_t i_pos )
 static int AStreamRefillBlock( stream_t *s )
 {
     stream_sys_t *p_sys = s->p_sys;
-    block_t      *b;
 
     /* Release data */
     while( p_sys->block.i_size >= STREAM_CACHE_SIZE &&
@@ -992,6 +1017,8 @@ static int AStreamRefillBlock( stream_t *s )
 
     /* Now read a new block */
     const int64_t i_start = mdate();
+    block_t *b;
+
     for( ;; )
     {
         bool b_eof;
@@ -1420,13 +1447,13 @@ static void AStreamPrebufferStream( stream_t *s )
             /* Update stat */
             p_sys->stat.i_bytes = i_buffered;
             p_sys->stat.i_read_time = i_date - i_start;
-            i_byterate = ( INT64_C(1000000) * p_sys->stat.i_bytes ) /
+            i_byterate = ( CLOCK_FREQ * p_sys->stat.i_bytes ) /
                          (p_sys->stat.i_read_time+1);
 
             msg_Dbg( s, "pre-buffering done %"PRId64" bytes in %"PRId64"s - "
                      "%"PRId64" KiB/s",
                      p_sys->stat.i_bytes,
-                     p_sys->stat.i_read_time / INT64_C(1000000),
+                     p_sys->stat.i_read_time / CLOCK_FREQ,
                      i_byterate / 1024 );
             break;
         }
@@ -1468,6 +1495,10 @@ char *stream_ReadLine( stream_t *s )
     char *p_line = NULL;
     int i_line = 0, i_read = 0;
 
+    /* Let's fail quickly if this is a readdir access */
+    if( s->pf_read == NULL )
+        return NULL;
+
     for( ;; )
     {
         char *psz_eol;
@@ -1825,6 +1856,12 @@ static int ASeek( stream_t *s, uint64_t i_pos )
     return p_access->pf_seek( p_access, i_pos );
 }
 
+static int AStreamReadDir( stream_t *s, input_item_node_t *p_node )
+{
+    access_t *p_access = s->p_sys->p_access;
+
+    return p_access->pf_readdir( p_access, p_node );
+}
 
 /**
  * Try to read "i_read" bytes into a buffer pointed by "p_read".  If
@@ -1957,3 +1994,11 @@ block_t *stream_BlockRemaining( stream_t *s, int i_max_size )
     return p_block;
 }
 
+/**
+ * Returns a node containing all the input_item of the directory pointer by
+ * this stream. returns VLC_SUCCESS on success.
+ */
+int stream_ReadDir( stream_t *s, input_item_node_t *p_node )
+{
+    return s->pf_readdir( s, p_node );
+}