[vlc-commits] demux: adaptive: delegate chunk source creation to manager

Francois Cartegnie git at videolan.org
Wed Apr 7 18:29:03 UTC 2021


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Mar 18 21:03:29 2021 +0100| [3de1584a8dfda97871aa0696629ffc06f7864f94] | committer: Francois Cartegnie

demux: adaptive: delegate chunk source creation to manager

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

 modules/demux/adaptive/http/Chunk.cpp              |  5 ++---
 modules/demux/adaptive/http/Chunk.h                | 23 ++++++++++++----------
 .../demux/adaptive/http/HTTPConnectionManager.cpp  | 17 ++++++++++++++++
 .../demux/adaptive/http/HTTPConnectionManager.h    |  9 +++++++++
 modules/demux/adaptive/playlist/Segment.cpp        | 11 +++++------
 modules/demux/adaptive/tools/Retrieve.cpp          |  2 +-
 6 files changed, 47 insertions(+), 20 deletions(-)

diff --git a/modules/demux/adaptive/http/Chunk.cpp b/modules/demux/adaptive/http/Chunk.cpp
index b3e749ec5a..018e3640d9 100644
--- a/modules/demux/adaptive/http/Chunk.cpp
+++ b/modules/demux/adaptive/http/Chunk.cpp
@@ -523,9 +523,8 @@ block_t * HTTPChunkBufferedSource::read(size_t readsize)
 }
 
 HTTPChunk::HTTPChunk(const std::string &url, AbstractConnectionManager *manager,
-                     const adaptive::ID &id, ChunkType type, const BytesRange &range,
-                     bool access):
-    AbstractChunk(new HTTPChunkSource(url, manager, id, type, range, access))
+                     const adaptive::ID &id, ChunkType type, const BytesRange &range):
+    AbstractChunk(manager->makeSource(url, id, type, range))
 {
 }
 
diff --git a/modules/demux/adaptive/http/Chunk.h b/modules/demux/adaptive/http/Chunk.h
index fd72fc601f..f9257cbe75 100644
--- a/modules/demux/adaptive/http/Chunk.h
+++ b/modules/demux/adaptive/http/Chunk.h
@@ -109,10 +109,9 @@ namespace adaptive
         class HTTPChunkSource : public AbstractChunkSource,
                                 public BackendPrefInterface
         {
+            friend class HTTPConnectionManager;
+
             public:
-                HTTPChunkSource(const std::string &url, AbstractConnectionManager *,
-                                const ID &, ChunkType, const BytesRange &,
-                                bool = false);
                 virtual ~HTTPChunkSource();
 
                 virtual block_t *   readBlock       ()  override;
@@ -124,6 +123,10 @@ namespace adaptive
                 static const size_t CHUNK_SIZE = 32768;
 
             protected:
+                HTTPChunkSource(const std::string &url, AbstractConnectionManager *,
+                                const ID &, ChunkType, const BytesRange &,
+                                bool = false);
+
                 virtual bool        prepare();
                 AbstractConnection    *connection;
                 AbstractConnectionManager *connManager;
@@ -143,23 +146,24 @@ namespace adaptive
 
         class HTTPChunkBufferedSource : public HTTPChunkSource
         {
+            friend class HTTPConnectionManager;
             friend class Downloader;
 
             public:
-                HTTPChunkBufferedSource(const std::string &url, AbstractConnectionManager *,
-                                        const ID &, ChunkType, const BytesRange &,
-                                        bool = false);
                 virtual ~HTTPChunkBufferedSource();
                 virtual block_t *  readBlock       ()  override;
                 virtual block_t *  read            (size_t)  override;
                 virtual bool       hasMoreData     () const  override;
-                void               hold();
-                void               release();
 
             protected:
+                HTTPChunkBufferedSource(const std::string &url, AbstractConnectionManager *,
+                                        const ID &, ChunkType, const BytesRange &,
+                                        bool = false);
                 virtual bool       prepare()  override;
                 void               bufferize(size_t);
                 bool               isDone() const;
+                void               hold();
+                void               release();
 
             private:
                 block_t            *p_head; /* read cache buffer */
@@ -175,8 +179,7 @@ namespace adaptive
         {
             public:
                 HTTPChunk(const std::string &url, AbstractConnectionManager *,
-                          const ID &, ChunkType, const BytesRange &,
-                          bool = false);
+                          const ID &, ChunkType, const BytesRange &);
                 virtual ~HTTPChunk();
 
             protected:
diff --git a/modules/demux/adaptive/http/HTTPConnectionManager.cpp b/modules/demux/adaptive/http/HTTPConnectionManager.cpp
index c7672f565d..4a1b60b9ec 100644
--- a/modules/demux/adaptive/http/HTTPConnectionManager.cpp
+++ b/modules/demux/adaptive/http/HTTPConnectionManager.cpp
@@ -152,6 +152,23 @@ AbstractConnection * HTTPConnectionManager::getConnection(ConnectionParams &para
     return conn;
 }
 
+AbstractChunkSource *HTTPConnectionManager::makeSource(const std::string &url,
+                                                       const ID &id, ChunkType type,
+                                                       const BytesRange &range)
+{
+    switch(type)
+    {
+        case ChunkType::Init:
+        case ChunkType::Index:
+        case ChunkType::Segment:
+            return new HTTPChunkBufferedSource(url, this, id, type, range);
+        case ChunkType::Key:
+        case ChunkType::Playlist:
+        default:
+            return new HTTPChunkSource(url, this, id, type, range, true);
+    }
+}
+
 void HTTPConnectionManager::start(AbstractChunkSource *source)
 {
     HTTPChunkBufferedSource *src = dynamic_cast<HTTPChunkBufferedSource *>(source);
diff --git a/modules/demux/adaptive/http/HTTPConnectionManager.h b/modules/demux/adaptive/http/HTTPConnectionManager.h
index a0cada5483..24490204a1 100644
--- a/modules/demux/adaptive/http/HTTPConnectionManager.h
+++ b/modules/demux/adaptive/http/HTTPConnectionManager.h
@@ -26,6 +26,7 @@
 #define HTTPCONNECTIONMANAGER_H_
 
 #include "../logic/IDownloadRateObserver.h"
+#include "BytesRange.hpp"
 
 #include <vlc_common.h>
 
@@ -42,6 +43,7 @@ namespace adaptive
         class AbstractConnection;
         class Downloader;
         class AbstractChunkSource;
+        enum class ChunkType;
 
         class AbstractConnectionManager : public IDownloadRateObserver
         {
@@ -50,6 +52,10 @@ namespace adaptive
                 ~AbstractConnectionManager();
                 virtual void    closeAllConnections () = 0;
                 virtual AbstractConnection * getConnection(ConnectionParams &) = 0;
+                virtual AbstractChunkSource *makeSource(const std::string &,
+                                                        const ID &, ChunkType,
+                                                        const BytesRange &) = 0;
+
                 virtual void start(AbstractChunkSource *) = 0;
                 virtual void cancel(AbstractChunkSource *) = 0;
 
@@ -72,6 +78,9 @@ namespace adaptive
 
                 virtual void    closeAllConnections ()  override;
                 virtual AbstractConnection * getConnection(ConnectionParams &)  override;
+                virtual AbstractChunkSource *makeSource(const std::string &,
+                                                        const ID &, ChunkType,
+                                                        const BytesRange &) override;
 
                 virtual void start(AbstractChunkSource *)  override;
                 virtual void cancel(AbstractChunkSource *)  override;
diff --git a/modules/demux/adaptive/playlist/Segment.cpp b/modules/demux/adaptive/playlist/Segment.cpp
index 2ecf8225b3..f841ee2ad5 100644
--- a/modules/demux/adaptive/playlist/Segment.cpp
+++ b/modules/demux/adaptive/playlist/Segment.cpp
@@ -81,12 +81,11 @@ SegmentChunk* ISegment::toChunk(SharedResources *res, AbstractConnectionManager
     BytesRange range;
     if(startByte != endByte)
         range = BytesRange(startByte, endByte);
-    HTTPChunkBufferedSource *source =
-            new (std::nothrow) HTTPChunkBufferedSource(url, connManager,
-                                                       rep->getAdaptationSet()->getID(),
-                                                       ChunkType::Segment,
-                                                       range);
-    if( source )
+    AbstractChunkSource *source = connManager->makeSource(url,
+                                                          rep->getAdaptationSet()->getID(),
+                                                          ChunkType::Segment,
+                                                          range);
+    if(source)
     {
         SegmentChunk *chunk = createChunk(source, rep);
         if(chunk)
diff --git a/modules/demux/adaptive/tools/Retrieve.cpp b/modules/demux/adaptive/tools/Retrieve.cpp
index 044bc49cfc..67c71b06d7 100644
--- a/modules/demux/adaptive/tools/Retrieve.cpp
+++ b/modules/demux/adaptive/tools/Retrieve.cpp
@@ -39,7 +39,7 @@ block_t * Retrieve::HTTP(SharedResources *resources, ChunkType type,
     try
     {
         datachunk = new HTTPChunk(uri, resources->getConnManager(),
-                                  ID(), type, BytesRange(), true);
+                                  ID(), type, BytesRange());
     } catch (...) {
         return nullptr;
     }



More information about the vlc-commits mailing list