[vlc-devel] [RFC PATCH 1/3] options: add stream-cache

Thomas Guillem thomas at gllm.fr
Wed Oct 21 15:40:14 CEST 2015


---
 src/input/access.c  | 36 ++++++++++++++++++++++++++++++++++--
 src/input/var.c     |  1 +
 src/libvlc-module.c |  6 ++++++
 3 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/src/input/access.c b/src/input/access.c
index 18b8357..aeae35b 100644
--- a/src/input/access.c
+++ b/src/input/access.c
@@ -341,6 +341,36 @@ static void AStreamDestroy(stream_t *s)
     free(sys);
 }
 
+static const char *get_cachename(const char *cache_option,
+                                 const char *default_cache)
+{
+    if (!cache_option || strcmp(cache_option, "all") == 0)
+        return default_cache;
+    else if (strcmp(cache_option, "none") == 0)
+        return NULL;
+    else
+    {
+        char *saveptr;
+        char *cache_option_dup = strdup(cache_option);
+
+        /* check if modules in cache_option are compatible with the one in
+         * default_cache */
+        if (!cache_option_dup)
+            return NULL;
+        for (const char *name = strtok_r(cache_option_dup, ",", &saveptr);
+             name != NULL; name = strtok_r(NULL, ",", &saveptr))
+        {
+            if (!strstr(default_cache, name))
+            {
+                free(cache_option_dup);
+                return default_cache;
+            }
+        }
+        free(cache_option_dup);
+        return cache_option;
+    }
+}
+
 stream_t *stream_AccessNew(vlc_object_t *parent, input_thread_t *input,
                            const char *url)
 {
@@ -362,17 +392,18 @@ stream_t *stream_AccessNew(vlc_object_t *parent, input_thread_t *input,
     sys->block = NULL;
 
     const char *cachename;
+    char *cache_option = var_GetNonEmptyString(parent, "stream-cache");
 
     if (sys->access->pf_block != NULL)
     {
         s->pf_read = AStreamReadBlock;
-        cachename = "cache_block";
+        cachename = get_cachename(cache_option, "cache_block");
     }
     else
     if (sys->access->pf_read != NULL)
     {
         s->pf_read = AStreamReadStream;
-        cachename = "prefetch,cache_read";
+        cachename = get_cachename(cache_option, "prefetch,cache_read");
     }
     else
     {
@@ -391,6 +422,7 @@ stream_t *stream_AccessNew(vlc_object_t *parent, input_thread_t *input,
 
     if (cachename != NULL)
         s = stream_FilterChainNew(s, cachename);
+    free(cache_option);
     return s;
 error:
     free(sys);
diff --git a/src/input/var.c b/src/input/var.c
index 47f4b88..a82b16c 100644
--- a/src/input/var.c
+++ b/src/input/var.c
@@ -497,6 +497,7 @@ void input_ConfigVarInit ( input_thread_t *p_input )
     var_Create( p_input, "access", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
     var_Create( p_input, "demux", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
     var_Create( p_input, "stream-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+    var_Create( p_input, "stream-cache", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
 
     /* Meta */
     var_Create( p_input, "meta-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index a13093d..0e95ae5 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -988,6 +988,10 @@ static const char *const ppsz_prefres[] = {
 #define STREAM_FILTER_LONGTEXT N_( \
     "Stream filters are used to modify the stream that is being read. " )
 
+#define STREAM_CACHE_TEXT N_("Stream cache filter module")
+#define STREAM_CACHE_LONGTEXT N_( \
+    "Stream cache filters are used to cache the stream that is being read. " )
+
 #define DEMUX_TEXT N_("Demux module")
 #define DEMUX_LONGTEXT N_( \
     "Demultiplexers are used to separate the \"elementary\" streams " \
@@ -1871,6 +1875,8 @@ vlc_module_begin ()
     set_subcategory( SUBCAT_INPUT_STREAM_FILTER )
     add_module_list( "stream-filter", "stream_filter", NULL,
                      STREAM_FILTER_TEXT, STREAM_FILTER_LONGTEXT, false )
+    add_module_list( "stream-cache", "stream_cache", NULL,
+                     STREAM_CACHE_TEXT, STREAM_CACHE_LONGTEXT, false )
 
 
 /* Stream output options */
-- 
2.1.4



More information about the vlc-devel mailing list