[vlc-devel] [RFC PATCH 3/3] libvlc_stream: add test

Thomas Guillem thomas at gllm.fr
Tue May 24 16:01:36 CEST 2016


TODO: test_src_input_stream_net (not run with make check) fails because of a
problem in cache_block that is now highlighted when comparing stream_t vs
libvlc_stream_t returns.
---
 test/src/input/stream.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 104 insertions(+), 2 deletions(-)

diff --git a/test/src/input/stream.c b/test/src/input/stream.c
index 4f2c407..080667b 100644
--- a/test/src/input/stream.c
+++ b/test/src/input/stream.c
@@ -23,6 +23,7 @@
 
 #include <vlc_md5.h>
 #include <vlc_stream.h>
+#include <vlc/vlc.h>
 
 #include <inttypes.h>
 #include <limits.h>
@@ -45,6 +46,7 @@ struct reader
     union {
         FILE *f;
         stream_t *s;
+        libvlc_stream_t *ls;
     } u;
     void *p_data;
 
@@ -220,6 +222,104 @@ stream_open( const char *psz_url )
     return p_reader;
 }
 
+static uint64_t
+lstream_getsize( struct reader *p_reader )
+{
+    uint64_t i_size;
+
+    assert( libvlc_stream_size( p_reader->u.ls, &i_size ) == 0 );
+    return i_size;
+}
+
+static ssize_t
+lstream_read( struct reader *p_reader, void *p_buf, size_t i_len )
+{
+    return libvlc_stream_read( p_reader->u.ls, p_buf, i_len );
+}
+
+static ssize_t
+lstream_peek( struct reader *p_reader, const uint8_t **pp_buf, size_t i_len )
+{
+    ssize_t i_ret;
+    uint64_t i_last_pos;
+
+    free( p_reader->p_data );
+    p_reader->p_data = malloc( i_len );
+    assert( p_reader->p_data );
+
+    assert( libvlc_stream_tell( p_reader->u.ls, &i_last_pos ) == 0 );
+
+    i_ret = libvlc_stream_read( p_reader->u.ls, p_reader->p_data, i_len );
+    *pp_buf = p_reader->p_data;
+
+    assert( libvlc_stream_seekto( p_reader->u.ls, i_last_pos ) == 0 );
+    return i_ret;
+}
+
+static uint64_t
+lstream_tell( struct reader *p_reader )
+{
+    uint64_t i_offset;
+    assert( libvlc_stream_tell( p_reader->u.ls, &i_offset ) == 0 );
+    return i_offset;
+}
+
+static int
+lstream_seek( struct reader *p_reader, uint64_t i_offset )
+{
+    return libvlc_stream_seekto( p_reader->u.ls, i_offset );
+}
+
+static void
+lstream_close( struct reader *p_reader )
+{
+    libvlc_stream_release( p_reader->u.ls );
+    libvlc_release( p_reader->p_libvlc );
+    free( p_reader->p_data );
+    free( p_reader );
+}
+
+static struct reader *
+lstream_open( const char *psz_url )
+{
+    libvlc_instance_t *p_vlc;
+    struct reader *p_reader;
+    const char * argv[] = {
+        "-v",
+        "--ignore-config",
+        "-I",
+        "dummy",
+        "--no-media-library",
+        "--vout=dummy",
+        "--aout=dummy",
+    };
+
+    p_reader = calloc( 1, sizeof(struct reader) );
+    assert( p_reader );
+
+    p_vlc = libvlc_new( sizeof(argv) / sizeof(argv[0]), argv );
+    assert( p_vlc != NULL );
+
+    p_reader->u.ls = libvlc_stream_new( p_vlc );
+    if( !p_reader->u.ls || libvlc_stream_open_input( p_reader->u.ls, psz_url ) != 0 )
+    {
+        if( p_reader->u.ls )
+            libvlc_stream_release( p_reader->u.ls );
+        libvlc_release( p_vlc );
+        free( p_reader );
+        return NULL;
+    }
+    p_reader->pf_close = lstream_close;
+    p_reader->pf_getsize = lstream_getsize;
+    p_reader->pf_read = lstream_read;
+    p_reader->pf_peek = lstream_peek;
+    p_reader->pf_tell = lstream_tell;
+    p_reader->pf_seek = lstream_seek;
+    p_reader->p_libvlc = p_vlc;
+    p_reader->psz_name = "libvlc_stream";
+    return p_reader;
+}
+
 static ssize_t
 read_at( struct reader **pp_readers, unsigned int i_readers,
          void *p_buf, uint64_t i_offset,
@@ -351,7 +451,7 @@ main( void )
     test_init();
 
 #ifndef TEST_NET
-#define NB_READER 2
+#define NB_READER 3
     char psz_file[PATH_MAX];
 
     log( "Test local file with libc, and stream\n" );
@@ -360,15 +460,17 @@ main( void )
 
     assert( ( pp_readers[0] = libc_open( psz_file ) ) );
     assert( ( pp_readers[1] = stream_open( psz_url ) ) );
+    assert( ( pp_readers[2] = lstream_open( psz_url ) ) );
 
     test( pp_readers, NB_READER, FILE_MD5 );
 
 #else
-#define NB_READER 1
+#define NB_READER 2
 
     log( "Test http url with stream\n" );
     alarm( 0 );
     assert( ( pp_readers[0] = stream_open( HTTP_URL ) ) );
+    assert( ( pp_readers[1] = lstream_open( HTTP_URL ) ) );
 
     test( pp_readers, NB_READER, HTTP_MD5 );
 #endif
-- 
2.8.1



More information about the vlc-devel mailing list