[vlc-commits] demux: adaptive: add common chunk/chunk source interface

Francois Cartegnie git at videolan.org
Mon Mar 15 20:56:27 UTC 2021


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Mar 12 10:11:10 2021 +0100| [51293726f526342aa9805b292a3dfceb32e84003] | committer: Francois Cartegnie

demux: adaptive: add common chunk/chunk source interface

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

 modules/demux/adaptive/Streams.cpp               |  2 +-
 modules/demux/adaptive/Streams.hpp               |  3 +-
 modules/demux/adaptive/http/Chunk.cpp            | 11 ++++++--
 modules/demux/adaptive/http/Chunk.h              | 36 +++++++++++++++---------
 modules/demux/adaptive/playlist/SegmentChunk.cpp |  2 +-
 modules/demux/smooth/playlist/MemoryChunk.cpp    |  5 ++++
 modules/demux/smooth/playlist/MemoryChunk.hpp    |  1 +
 7 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/modules/demux/adaptive/Streams.cpp b/modules/demux/adaptive/Streams.cpp
index ce305f7f07..fbaca03307 100644
--- a/modules/demux/adaptive/Streams.cpp
+++ b/modules/demux/adaptive/Streams.cpp
@@ -573,7 +573,7 @@ block_t * AbstractStream::readNextBlock()
 
     demuxfirstchunk = false;
 
-    if (currentChunk->isEmpty())
+    if (!currentChunk->hasMoreData())
     {
         delete currentChunk;
         currentChunk = nullptr;
diff --git a/modules/demux/adaptive/Streams.hpp b/modules/demux/adaptive/Streams.hpp
index 2e5cf214e3..f80cd266fa 100644
--- a/modules/demux/adaptive/Streams.hpp
+++ b/modules/demux/adaptive/Streams.hpp
@@ -39,6 +39,7 @@ namespace adaptive
     namespace http
     {
         class AbstractConnectionManager;
+        class ChunkInterface;
     }
 
     namespace playlist
@@ -126,7 +127,7 @@ namespace adaptive
         AbstractConnectionManager *connManager; /* not owned */
         SegmentTracker *segmentTracker;
 
-        SegmentChunk *currentChunk;
+        ChunkInterface *currentChunk;
         bool eof;
         std::string language;
         std::string description;
diff --git a/modules/demux/adaptive/http/Chunk.cpp b/modules/demux/adaptive/http/Chunk.cpp
index 4843169eb2..04ac40f4a9 100644
--- a/modules/demux/adaptive/http/Chunk.cpp
+++ b/modules/demux/adaptive/http/Chunk.cpp
@@ -82,7 +82,7 @@ AbstractChunk::~AbstractChunk()
     delete source;
 }
 
-std::string AbstractChunk::getContentType()
+std::string AbstractChunk::getContentType() const
 {
     return source->getContentType();
 }
@@ -123,9 +123,9 @@ block_t * AbstractChunk::doRead(size_t size, bool b_block)
     return block;
 }
 
-bool AbstractChunk::isEmpty() const
+bool AbstractChunk::hasMoreData() const
 {
-    return !source->hasMoreData();
+    return source->hasMoreData();
 }
 
 block_t * AbstractChunk::readBlock()
@@ -185,6 +185,11 @@ bool HTTPChunkSource::hasMoreData() const
     else return true;
 }
 
+size_t HTTPChunkSource::getBytesRead() const
+{
+    return consumed;
+}
+
 block_t * HTTPChunkSource::read(size_t readsize)
 {
     mutex_locker locker {lock};
diff --git a/modules/demux/adaptive/http/Chunk.h b/modules/demux/adaptive/http/Chunk.h
index c596c953fd..41f360a54c 100644
--- a/modules/demux/adaptive/http/Chunk.h
+++ b/modules/demux/adaptive/http/Chunk.h
@@ -52,18 +52,27 @@ namespace adaptive
             Key,
         };
 
-        class AbstractChunkSource
+        class ChunkInterface
         {
             public:
-                AbstractChunkSource();
-                virtual ~AbstractChunkSource();
+                virtual std::string getContentType  () const = 0;
+                virtual RequestStatus getRequestStatus() const = 0;
+
                 virtual block_t *   readBlock       () = 0;
                 virtual block_t *   read            (size_t) = 0;
                 virtual bool        hasMoreData     () const = 0;
+                virtual size_t      getBytesRead    () const = 0;
+        };
+
+        class AbstractChunkSource : public ChunkInterface
+        {
+            public:
+                AbstractChunkSource();
+                virtual ~AbstractChunkSource();
                 void                setBytesRange   (const BytesRange &);
                 const BytesRange &  getBytesRange   () const;
-                virtual std::string getContentType  () const;
-                RequestStatus       getRequestStatus() const;
+                virtual std::string getContentType  () const override;
+                virtual RequestStatus getRequestStatus() const override;
 
             protected:
                 RequestStatus       requeststatus;
@@ -71,19 +80,19 @@ namespace adaptive
                 BytesRange          bytesRange;
         };
 
-        class AbstractChunk
+        class AbstractChunk : public ChunkInterface
         {
             public:
                 virtual ~AbstractChunk();
 
-                std::string         getContentType          ();
-                RequestStatus       getRequestStatus        () const;
-                size_t              getBytesRead            () const;
-                uint64_t            getStartByteInFile      () const;
-                bool                isEmpty                 () const;
+                virtual std::string   getContentType        () const override;
+                virtual RequestStatus getRequestStatus      () const override;
+                virtual size_t        getBytesRead          () const override;
+                virtual bool          hasMoreData           () const override;
+                uint64_t              getStartByteInFile    () const;
 
-                virtual block_t *   readBlock       ();
-                virtual block_t *   read            (size_t);
+                virtual block_t *   readBlock       () override;
+                virtual block_t *   read            (size_t) override;
 
             protected:
                 AbstractChunk(AbstractChunkSource *);
@@ -106,6 +115,7 @@ namespace adaptive
                 virtual block_t *   readBlock       ()  override;
                 virtual block_t *   read            (size_t)  override;
                 virtual bool        hasMoreData     () const  override;
+                virtual size_t      getBytesRead    () const  override;
                 virtual std::string getContentType  () const  override;
 
                 static const size_t CHUNK_SIZE = 32768;
diff --git a/modules/demux/adaptive/playlist/SegmentChunk.cpp b/modules/demux/adaptive/playlist/SegmentChunk.cpp
index 4182a42085..3756325d6c 100644
--- a/modules/demux/adaptive/playlist/SegmentChunk.cpp
+++ b/modules/demux/adaptive/playlist/SegmentChunk.cpp
@@ -52,7 +52,7 @@ bool SegmentChunk::decrypt(block_t **pp_block)
 
     if(encryptionSession)
     {
-        bool b_last = isEmpty();
+        bool b_last = !hasMoreData();
         p_block->i_buffer = encryptionSession->decrypt(p_block->p_buffer,
                                                        p_block->i_buffer, b_last);
         if(b_last)
diff --git a/modules/demux/smooth/playlist/MemoryChunk.cpp b/modules/demux/smooth/playlist/MemoryChunk.cpp
index 4df9459789..51ce45c0fc 100644
--- a/modules/demux/smooth/playlist/MemoryChunk.cpp
+++ b/modules/demux/smooth/playlist/MemoryChunk.cpp
@@ -45,6 +45,11 @@ bool MemoryChunkSource::hasMoreData() const
     return i_read > contentLength;
 }
 
+size_t MemoryChunkSource::getBytesRead() const
+{
+    return i_read;
+}
+
 block_t * MemoryChunkSource::readBlock()
 {
     block_t *p_block = nullptr;
diff --git a/modules/demux/smooth/playlist/MemoryChunk.hpp b/modules/demux/smooth/playlist/MemoryChunk.hpp
index 52fc8829f0..b3a3ecb2f9 100644
--- a/modules/demux/smooth/playlist/MemoryChunk.hpp
+++ b/modules/demux/smooth/playlist/MemoryChunk.hpp
@@ -37,6 +37,7 @@ namespace smooth
                 virtual block_t * readBlock() override;
                 virtual block_t * read(size_t) override;
                 virtual bool      hasMoreData() const override;
+                virtual size_t    getBytesRead() const  override;
 
             private:
                 block_t *data;



More information about the vlc-commits mailing list