[vlc-commits] Add support for pf_readdir access modules in Streams

Julien 'Lta' BALLET git at videolan.org
Tue Jun 24 11:02:09 CEST 2014


vlc | branch: master | Julien 'Lta' BALLET <contact at lta.io> | Sat Jun 21 15:55:10 2014 +0200| [4371ecfc961c75f4fb1817b63172458cccee384e] | committer: Jean-Baptiste Kempf

Add support for pf_readdir access modules in Streams

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 include/vlc_stream.h |    9 +++++---
 src/input/stream.c   |   57 ++++++++++++++++++++++++++++++++++++++++++--------
 src/libvlccore.sym   |    1 +
 3 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/include/vlc_stream.h b/include/vlc_stream.h
index 10a98ef..db247bc 100644
--- a/include/vlc_stream.h
+++ b/include/vlc_stream.h
@@ -65,9 +65,10 @@ struct stream_t
     stream_t *p_source;
 
     /* */
-    int      (*pf_read)   ( stream_t *, void *p_read, unsigned int i_read );
-    int      (*pf_peek)   ( stream_t *, const uint8_t **pp_peek, unsigned int i_peek );
-    int      (*pf_control)( stream_t *, int i_query, va_list );
+    int         (*pf_read)   ( stream_t *, void *p_read, unsigned int i_read );
+    int         (*pf_peek)   ( stream_t *, const uint8_t **pp_peek, unsigned int i_peek );
+    int         (*pf_readdir)( stream_t *, input_item_node_t * );
+    int         (*pf_control)( stream_t *, int i_query, va_list );
 
     /* */
     void     (*pf_destroy)( stream_t *);
@@ -92,6 +93,7 @@ enum stream_query_e
     STREAM_CAN_FASTSEEK,        /**< arg1= bool *   res=cannot fail*/
     STREAM_CAN_PAUSE,           /**< arg1= bool *   res=cannot fail*/
     STREAM_CAN_CONTROL_PACE,    /**< arg1= bool *   res=cannot fail*/
+    STREAM_IS_DIRECTORY,        /**< arg1= bool *   res=cannot fail*/
 
     /* */
     STREAM_SET_POSITION,        /**< arg1= uint64_t       res=can fail  */
@@ -132,6 +134,7 @@ VLC_API int stream_Control( stream_t *s, int i_query, ... );
 VLC_API block_t * stream_Block( stream_t *s, int i_size );
 VLC_API block_t * stream_BlockRemaining( stream_t *s, int i_max_size );
 VLC_API char * stream_ReadLine( stream_t * );
+VLC_API int stream_ReadDir( stream_t *, input_item_node_t * );
 
 /**
  * Get the current position in a stream
diff --git a/src/input/stream.c b/src/input/stream.c
index 18e77e2..44138b1 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -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,8 +290,9 @@ 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    = (void *)AStreamGenericError;    /* Replaced later */
+    s->pf_peek    = (void *)AStreamGenericError;
+    s->pf_readdir = (void *)AStreamGenericError;
     s->pf_control = AStreamControl;
     s->pf_destroy = AStreamDestroy;
 
@@ -294,8 +300,10 @@ stream_t *stream_AccessNew( access_t *p_access, char **ppsz_list )
     p_sys->p_access = p_access;
     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;
 
@@ -385,12 +393,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;
@@ -426,6 +432,11 @@ stream_t *stream_AccessNew( access_t *p_access, char **ppsz_list )
             goto error;
         }
     }
+    else
+    {
+        assert( p_sys->method == STREAM_METHOD_READDIR );
+        s->pf_readdir = AStreamReadDir;
+    }
 
     return s;
 
@@ -434,7 +445,7 @@ error:
     {
         /* Nothing yet */
     }
-    else
+    else if( p_sys->method == STREAM_METHOD_STREAM )
     {
         free( p_sys->stream.p_buffer );
     }
@@ -456,7 +467,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 );
@@ -637,6 +648,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 );
@@ -1473,6 +1491,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;
@@ -1830,6 +1852,15 @@ 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;
+
+    if( p_access->pf_readdir != NULL )
+        return p_access->pf_readdir( p_access, p_node );
+    else
+        return VLC_ENOITEM;
+}
 
 /**
  * Try to read "i_read" bytes into a buffer pointed by "p_read".  If
@@ -1962,3 +1993,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 );
+}
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index e583c21..7b40435 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -402,6 +402,7 @@ stream_Read
 stream_ReadLine
 stream_UrlNew
 stream_vaControl
+stream_ReadDir
 str_format_meta
 str_format_time
 str_duration



More information about the vlc-commits mailing list