[vlc-commits] accesstweaks: automatically probe

Rémi Denis-Courmont git at videolan.org
Tue Nov 28 18:20:12 CET 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Nov 28 19:03:05 2017 +0200| [0ef201d8cc4a136a141516032b5a123027c02568] | committer: Rémi Denis-Courmont

accesstweaks: automatically probe

accesstweaks no longer needs to be explicitly added to stream filters.
It is now enabled implicitly with --no-seek, --no-fastseek and/or
 --no-stream-size.

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

 modules/stream_filter/accesstweaks.c | 50 ++++++++++++++++++++++++------------
 1 file changed, 34 insertions(+), 16 deletions(-)

diff --git a/modules/stream_filter/accesstweaks.c b/modules/stream_filter/accesstweaks.c
index d6c2623817..bea1b8087c 100644
--- a/modules/stream_filter/accesstweaks.c
+++ b/modules/stream_filter/accesstweaks.c
@@ -31,22 +31,21 @@
 #include <assert.h>
 
 static int  Open(vlc_object_t *);
-static void Close(vlc_object_t *);
 
 vlc_module_begin ()
     set_shortname("accesstweaks")
     set_category (CAT_INPUT)
     set_subcategory (SUBCAT_INPUT_STREAM_FILTER)
-    set_capability ("stream_filter", 0)
+    set_capability ("stream_filter", 1)
     /* Developers only module, no translation please */
     set_description ("Access controls tweaking")
-    set_callbacks (Open, Close)
+    set_callbacks(Open, NULL)
 
-    add_bool ("seek", true, "forces result of the CAN_SEEK control", NULL, false)
+    add_bool("seek", true, "Expose seeking capability", NULL, false)
         change_volatile ()
-    add_bool ("fastseek", true, "forces result of the CAN_FASTSEEK control", NULL, false)
+    add_bool("fastseek", true, "Expose fast-seeking capability", NULL, false)
         change_volatile ()
-    add_bool("stream-size", true, "expose stream size if known", NULL, false)
+    add_bool("stream-size", true, "Expose stream size if known", NULL, false)
         change_volatile()
     add_shortcut("tweaks")
 vlc_module_end ()
@@ -108,24 +107,43 @@ static int Seek( stream_t *s, uint64_t offset )
 static int Open( vlc_object_t *p_object )
 {
     stream_t *p_stream = (stream_t *) p_object;
-
-    stream_sys_t *p_sys = p_stream->p_sys = malloc( sizeof(*p_sys) );
+    stream_sys_t *p_sys = vlc_obj_malloc(p_object, sizeof (*p_sys));
     if (unlikely(p_sys == NULL))
         return VLC_ENOMEM;
 
-    p_sys->b_seek = var_InheritBool( p_stream, "seek" );
-    p_sys->b_fastseek = var_InheritBool( p_stream, "fastseek" );
+    uint64_t size;
+    bool b;
+    bool used = false;
+
+    p_sys->b_seek = var_InheritBool(p_stream, "seek");
     p_sys->b_size = var_InheritBool(p_stream, "stream-size");
 
+    if (!p_sys->b_seek)
+    {
+        if (vlc_stream_Control(p_stream->p_source, STREAM_CAN_SEEK, &b) == 0)
+            used = b;
+
+        p_sys->b_fastseek = false;
+    }
+    else
+    {
+        p_sys->b_fastseek = var_InheritBool(p_stream, "fastseek");
+        if (!p_sys->b_fastseek
+         && vlc_stream_Control(p_stream->p_source, STREAM_CAN_FASTSEEK,
+                               &b) == 0)
+            used = b;
+    }
+
+    if (!p_sys->b_size && vlc_stream_GetSize(p_stream->p_source, &size) == 0)
+        used = true;
+
+    if (!used) /* Nothing to do: skip this filter */
+        return VLC_EGENERIC;
+
+    p_stream->p_sys = p_sys;
     p_stream->pf_read = Read;
     p_stream->pf_seek = p_sys->b_seek ? Seek : NULL;
     p_stream->pf_control = Control;
 
     return VLC_SUCCESS;
 }
-
-static void Close ( vlc_object_t *p_object )
-{
-    stream_t *p_stream = (stream_t *)p_object;
-    free( p_stream->p_sys );
-}



More information about the vlc-commits mailing list