[vlc-commits] demux: adaptive: always create chunk with range

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


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Mar 18 13:48:11 2021 +0100| [a5a67754cc0e059eb383273be09466d19845c809] | committer: Francois Cartegnie

demux: adaptive: always create chunk with range

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

 modules/demux/adaptive/http/Chunk.cpp       | 28 +++++++++++++---------------
 modules/demux/adaptive/http/Chunk.h         | 12 +++++++-----
 modules/demux/adaptive/playlist/Segment.cpp | 14 ++++++++------
 modules/demux/adaptive/tools/Retrieve.cpp   |  3 ++-
 4 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/modules/demux/adaptive/http/Chunk.cpp b/modules/demux/adaptive/http/Chunk.cpp
index 2e02b1af11..b3e749ec5a 100644
--- a/modules/demux/adaptive/http/Chunk.cpp
+++ b/modules/demux/adaptive/http/Chunk.cpp
@@ -38,11 +38,14 @@
 using namespace adaptive::http;
 using vlc::threads::mutex_locker;
 
-AbstractChunkSource::AbstractChunkSource(ChunkType t)
+AbstractChunkSource::AbstractChunkSource(ChunkType t, const BytesRange &range)
 {
     type = t;
     contentLength = 0;
     requeststatus = RequestStatus::Success;
+    bytesRange = range;
+    if(bytesRange.isValid() && bytesRange.getEndByte())
+        contentLength = bytesRange.getEndByte() - bytesRange.getStartByte();
 }
 
 AbstractChunkSource::~AbstractChunkSource()
@@ -50,13 +53,6 @@ AbstractChunkSource::~AbstractChunkSource()
 
 }
 
-void AbstractChunkSource::setBytesRange(const BytesRange &range)
-{
-    bytesRange = range;
-    if(bytesRange.isValid() && bytesRange.getEndByte())
-        contentLength = bytesRange.getEndByte() - bytesRange.getStartByte();
-}
-
 const BytesRange & AbstractChunkSource::getBytesRange() const
 {
     return bytesRange;
@@ -145,8 +141,9 @@ block_t * AbstractChunk::read(size_t size)
 }
 
 HTTPChunkSource::HTTPChunkSource(const std::string& url, AbstractConnectionManager *manager,
-                                 const adaptive::ID &id, ChunkType t, bool access) :
-    AbstractChunkSource(t),
+                                 const adaptive::ID &id, ChunkType t, const BytesRange &range,
+                                 bool access) :
+    AbstractChunkSource(t, range),
     connection   (nullptr),
     connManager  (manager),
     consumed     (0)
@@ -314,8 +311,9 @@ block_t * HTTPChunkSource::readBlock()
 
 HTTPChunkBufferedSource::HTTPChunkBufferedSource(const std::string& url, AbstractConnectionManager *manager,
                                                  const adaptive::ID &sourceid,
-                                                 ChunkType type, bool access) :
-    HTTPChunkSource(url, manager, sourceid, type, access),
+                                                 ChunkType type, const BytesRange &range,
+                                                 bool access) :
+    HTTPChunkSource(url, manager, sourceid, type, range, access),
     p_head     (nullptr),
     pp_tail    (&p_head),
     buffered     (0)
@@ -525,10 +523,10 @@ block_t * HTTPChunkBufferedSource::read(size_t readsize)
 }
 
 HTTPChunk::HTTPChunk(const std::string &url, AbstractConnectionManager *manager,
-                     const adaptive::ID &id, ChunkType type, bool access):
-    AbstractChunk(new HTTPChunkSource(url, manager, id, type, access))
+                     const adaptive::ID &id, ChunkType type, const BytesRange &range,
+                     bool access):
+    AbstractChunk(new HTTPChunkSource(url, manager, id, type, range, access))
 {
-
 }
 
 HTTPChunk::~HTTPChunk()
diff --git a/modules/demux/adaptive/http/Chunk.h b/modules/demux/adaptive/http/Chunk.h
index 7ddb356ae5..fd72fc601f 100644
--- a/modules/demux/adaptive/http/Chunk.h
+++ b/modules/demux/adaptive/http/Chunk.h
@@ -68,9 +68,8 @@ namespace adaptive
         class AbstractChunkSource : public ChunkInterface
         {
             public:
-                AbstractChunkSource(ChunkType);
+                AbstractChunkSource(ChunkType, const BytesRange & = BytesRange());
                 virtual ~AbstractChunkSource();
-                void                setBytesRange   (const BytesRange &);
                 const BytesRange &  getBytesRange   () const;
                 ChunkType           getChunkType    () const;
                 virtual std::string getContentType  () const override;
@@ -112,7 +111,8 @@ namespace adaptive
         {
             public:
                 HTTPChunkSource(const std::string &url, AbstractConnectionManager *,
-                                const ID &, ChunkType, bool = false);
+                                const ID &, ChunkType, const BytesRange &,
+                                bool = false);
                 virtual ~HTTPChunkSource();
 
                 virtual block_t *   readBlock       ()  override;
@@ -147,7 +147,8 @@ namespace adaptive
 
             public:
                 HTTPChunkBufferedSource(const std::string &url, AbstractConnectionManager *,
-                                        const ID &, ChunkType, bool = false);
+                                        const ID &, ChunkType, const BytesRange &,
+                                        bool = false);
                 virtual ~HTTPChunkBufferedSource();
                 virtual block_t *  readBlock       ()  override;
                 virtual block_t *  read            (size_t)  override;
@@ -174,7 +175,8 @@ namespace adaptive
         {
             public:
                 HTTPChunk(const std::string &url, AbstractConnectionManager *,
-                          const ID &, ChunkType, bool = false);
+                          const ID &, ChunkType, const BytesRange &,
+                          bool = false);
                 virtual ~HTTPChunk();
 
             protected:
diff --git a/modules/demux/adaptive/playlist/Segment.cpp b/modules/demux/adaptive/playlist/Segment.cpp
index e0ec87199f..2ecf8225b3 100644
--- a/modules/demux/adaptive/playlist/Segment.cpp
+++ b/modules/demux/adaptive/playlist/Segment.cpp
@@ -78,14 +78,16 @@ SegmentChunk* ISegment::toChunk(SharedResources *res, AbstractConnectionManager
                                 size_t index, BaseRepresentation *rep)
 {
     const std::string url = getUrlSegment().toString(index, rep);
-    HTTPChunkBufferedSource *source = new (std::nothrow) HTTPChunkBufferedSource(url, connManager,
-                                                                                 rep->getAdaptationSet()->getID(),
-                                                                                 ChunkType::Segment);
+    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 )
     {
-        if(startByte != endByte)
-            source->setBytesRange(BytesRange(startByte, endByte));
-
         SegmentChunk *chunk = createChunk(source, rep);
         if(chunk)
         {
diff --git a/modules/demux/adaptive/tools/Retrieve.cpp b/modules/demux/adaptive/tools/Retrieve.cpp
index 6bbdab5b24..044bc49cfc 100644
--- a/modules/demux/adaptive/tools/Retrieve.cpp
+++ b/modules/demux/adaptive/tools/Retrieve.cpp
@@ -38,7 +38,8 @@ block_t * Retrieve::HTTP(SharedResources *resources, ChunkType type,
     HTTPChunk *datachunk;
     try
     {
-        datachunk = new HTTPChunk(uri, resources->getConnManager(), ID(), type, true);
+        datachunk = new HTTPChunk(uri, resources->getConnManager(),
+                                  ID(), type, BytesRange(), true);
     } catch (...) {
         return nullptr;
     }



More information about the vlc-commits mailing list