[vlc-commits] demux: adaptive: allow to force access for some segments

Francois Cartegnie git at videolan.org
Mon Jul 30 10:16:57 CEST 2018


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Jul 27 12:45:31 2018 +0200| [58a26f0d7d52e7ec4478dff8fda338445fefb54e] | committer: Francois Cartegnie

demux: adaptive: allow to force access for some segments

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

 modules/demux/adaptive/http/Chunk.cpp              | 12 ++++----
 modules/demux/adaptive/http/Chunk.h                | 10 +++----
 modules/demux/adaptive/http/ConnectionParams.hpp   | 14 ++++++++-
 modules/demux/adaptive/http/HTTPConnection.cpp     | 34 ++++++++++++++++++++--
 modules/demux/adaptive/http/HTTPConnection.hpp     | 11 +++++++
 .../demux/adaptive/http/HTTPConnectionManager.cpp  |  5 +---
 6 files changed, 68 insertions(+), 18 deletions(-)

diff --git a/modules/demux/adaptive/http/Chunk.cpp b/modules/demux/adaptive/http/Chunk.cpp
index 36e911ed56..a4269e31fc 100644
--- a/modules/demux/adaptive/http/Chunk.cpp
+++ b/modules/demux/adaptive/http/Chunk.cpp
@@ -127,7 +127,7 @@ block_t * AbstractChunk::read(size_t size)
 }
 
 HTTPChunkSource::HTTPChunkSource(const std::string& url, AbstractConnectionManager *manager,
-                                 const adaptive::ID &id) :
+                                 const adaptive::ID &id, bool access) :
     AbstractChunkSource(),
     connection   (NULL),
     connManager  (manager),
@@ -136,6 +136,7 @@ HTTPChunkSource::HTTPChunkSource(const std::string& url, AbstractConnectionManag
     prepared = false;
     eof = false;
     sourceid = id;
+    setUseAccess(access);
     if(!init(url))
         eof = true;
 }
@@ -149,6 +150,7 @@ HTTPChunkSource::~HTTPChunkSource()
 bool HTTPChunkSource::init(const std::string &url)
 {
     params = ConnectionParams(url);
+    params.setUseAccess(usesAccess());
 
     if(params.getScheme() != "http" && params.getScheme() != "https")
         return false;
@@ -272,8 +274,8 @@ block_t * HTTPChunkSource::readBlock()
 }
 
 HTTPChunkBufferedSource::HTTPChunkBufferedSource(const std::string& url, AbstractConnectionManager *manager,
-                                                 const adaptive::ID &sourceid) :
-    HTTPChunkSource(url, manager, sourceid),
+                                                 const adaptive::ID &sourceid, bool access) :
+    HTTPChunkSource(url, manager, sourceid, access),
     p_head     (NULL),
     pp_tail    (&p_head),
     buffered     (0)
@@ -490,8 +492,8 @@ block_t * HTTPChunkBufferedSource::read(size_t readsize)
 }
 
 HTTPChunk::HTTPChunk(const std::string &url, AbstractConnectionManager *manager,
-                     const adaptive::ID &id):
-    AbstractChunk(new HTTPChunkSource(url, manager, id))
+                     const adaptive::ID &id, bool access):
+    AbstractChunk(new HTTPChunkSource(url, manager, id, access))
 {
 
 }
diff --git a/modules/demux/adaptive/http/Chunk.h b/modules/demux/adaptive/http/Chunk.h
index 8470696457..3bf3b44263 100644
--- a/modules/demux/adaptive/http/Chunk.h
+++ b/modules/demux/adaptive/http/Chunk.h
@@ -82,11 +82,12 @@ namespace adaptive
                 block_t *           doRead(size_t, bool);
         };
 
-        class HTTPChunkSource : public AbstractChunkSource
+        class HTTPChunkSource : public AbstractChunkSource,
+                                public BackendPrefInterface
         {
             public:
                 HTTPChunkSource(const std::string &url, AbstractConnectionManager *,
-                                const ID &);
+                                const ID &, bool = false);
                 virtual ~HTTPChunkSource();
 
                 virtual block_t *   readBlock       (); /* impl */
@@ -116,7 +117,7 @@ namespace adaptive
 
             public:
                 HTTPChunkBufferedSource(const std::string &url, AbstractConnectionManager *,
-                                        const ID &);
+                                        const ID &, bool = false);
                 virtual ~HTTPChunkBufferedSource();
                 virtual block_t *  readBlock       (); /* reimpl */
                 virtual block_t *  read            (size_t); /* reimpl */
@@ -145,12 +146,11 @@ namespace adaptive
         {
             public:
                 HTTPChunk(const std::string &url, AbstractConnectionManager *,
-                          const ID &);
+                          const ID &, bool = false);
                 virtual ~HTTPChunk();
 
                 virtual void        onDownload      (block_t **) {} /* impl */
         };
-
     }
 }
 
diff --git a/modules/demux/adaptive/http/ConnectionParams.hpp b/modules/demux/adaptive/http/ConnectionParams.hpp
index 9381e396b7..e8cf5cec7c 100644
--- a/modules/demux/adaptive/http/ConnectionParams.hpp
+++ b/modules/demux/adaptive/http/ConnectionParams.hpp
@@ -29,7 +29,19 @@ namespace adaptive
     {
         class Transport;
 
-        class ConnectionParams
+        class BackendPrefInterface
+        {
+            /* Design Hack for now to force fallback on regular access
+             * through hybrid connection factory */
+            public:
+                BackendPrefInterface() { useaccess = false; }
+                bool usesAccess() const { return useaccess; }
+                void setUseAccess(bool b) { useaccess = b; }
+            private:
+                bool useaccess;
+        };
+
+        class ConnectionParams : public BackendPrefInterface
         {
             public:
                 ConnectionParams();
diff --git a/modules/demux/adaptive/http/HTTPConnection.cpp b/modules/demux/adaptive/http/HTTPConnection.cpp
index 54087a17d7..dbfdc3bf70 100644
--- a/modules/demux/adaptive/http/HTTPConnection.cpp
+++ b/modules/demux/adaptive/http/HTTPConnection.cpp
@@ -89,7 +89,7 @@ HTTPConnection::~HTTPConnection()
 
 bool HTTPConnection::canReuse(const ConnectionParams &params_) const
 {
-    if( !available )
+    if( !available || params_.usesAccess() )
         return false;
 
     char *psz_proxy_url = vlc_getProxyUrl(params_.getUrl().c_str());
@@ -481,9 +481,9 @@ void StreamUrlConnection::reset()
     bytesRange = BytesRange();
 }
 
-bool StreamUrlConnection::canReuse(const ConnectionParams &) const
+bool StreamUrlConnection::canReuse(const ConnectionParams &params) const
 {
-    return available;
+    return available && params.usesAccess();
 }
 
 int StreamUrlConnection::request(const std::string &path, const BytesRange &range)
@@ -623,3 +623,31 @@ AbstractConnection * StreamUrlConnectionFactory::createConnection(vlc_object_t *
 {
     return new (std::nothrow) StreamUrlConnection(p_object);
 }
+
+ConnectionFactory::ConnectionFactory( AuthStorage *authstorage )
+{
+    native = new NativeConnectionFactory( authstorage );
+    streamurl = new StreamUrlConnectionFactory();
+}
+
+ConnectionFactory::~ConnectionFactory()
+{
+    delete native;
+    delete streamurl;
+}
+
+AbstractConnection * ConnectionFactory::createConnection(vlc_object_t *p_object,
+                                                         const ConnectionParams &params)
+{
+    bool b_streamurl = var_InheritBool(p_object, "adaptive-use-access");
+    if(!b_streamurl && !params.usesAccess())
+    {
+        return native->createConnection(p_object, params);
+    }
+    else
+    {
+        ConnectionParams paramsaccess = params;
+        paramsaccess.setUseAccess(true);
+        return streamurl->createConnection(p_object, paramsaccess);
+    }
+}
diff --git a/modules/demux/adaptive/http/HTTPConnection.hpp b/modules/demux/adaptive/http/HTTPConnection.hpp
index 19dec29a44..c95ce15798 100644
--- a/modules/demux/adaptive/http/HTTPConnection.hpp
+++ b/modules/demux/adaptive/http/HTTPConnection.hpp
@@ -153,6 +153,17 @@ namespace adaptive
                virtual ~StreamUrlConnectionFactory() {}
                virtual AbstractConnection * createConnection(vlc_object_t *, const ConnectionParams &);
        };
+
+       class ConnectionFactory : public AbstractConnectionFactory
+       {
+           public:
+               ConnectionFactory( AuthStorage * );
+               virtual ~ConnectionFactory();
+               virtual AbstractConnection * createConnection(vlc_object_t *, const ConnectionParams &);
+           private:
+               NativeConnectionFactory *native;
+               StreamUrlConnectionFactory *streamurl;
+       };
     }
 }
 
diff --git a/modules/demux/adaptive/http/HTTPConnectionManager.cpp b/modules/demux/adaptive/http/HTTPConnectionManager.cpp
index 2efa6d8343..020df8364e 100644
--- a/modules/demux/adaptive/http/HTTPConnectionManager.cpp
+++ b/modules/demux/adaptive/http/HTTPConnectionManager.cpp
@@ -73,10 +73,7 @@ HTTPConnectionManager::HTTPConnectionManager    (vlc_object_t *p_object_, AuthSt
     vlc_mutex_init(&lock);
     downloader = new (std::nothrow) Downloader();
     downloader->start();
-    if(var_InheritBool(p_object, "adaptive-use-access"))
-        factory = new (std::nothrow) StreamUrlConnectionFactory();
-    else
-        factory = new (std::nothrow) NativeConnectionFactory( storage );
+    factory = new ConnectionFactory(storage);
 }
 
 HTTPConnectionManager::~HTTPConnectionManager   ()



More information about the vlc-commits mailing list