[vlc-commits] demux: adaptive: make chunk data probe able

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


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

demux: adaptive: make chunk data probe able

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

 modules/demux/adaptive/http/Chunk.cpp | 87 +++++++++++++++++++++++++++++++++++
 modules/demux/adaptive/http/Chunk.h   | 22 +++++++++
 2 files changed, 109 insertions(+)

diff --git a/modules/demux/adaptive/http/Chunk.cpp b/modules/demux/adaptive/http/Chunk.cpp
index 04ac40f4a9..d5d9a8f337 100644
--- a/modules/demux/adaptive/http/Chunk.cpp
+++ b/modules/demux/adaptive/http/Chunk.cpp
@@ -530,3 +530,90 @@ HTTPChunk::~HTTPChunk()
 {
 
 }
+
+ProbeableChunk::ProbeableChunk(ChunkInterface *source)
+{
+    this->source = source;
+    peekblock = nullptr;
+}
+
+ProbeableChunk::~ProbeableChunk()
+{
+    if(peekblock)
+        block_Release(peekblock);
+    delete source;
+}
+
+std::string ProbeableChunk::getContentType() const
+{
+    return source->getContentType();
+}
+
+RequestStatus ProbeableChunk::getRequestStatus() const
+{
+    return source->getRequestStatus();
+}
+
+block_t * ProbeableChunk::readBlock()
+{
+    if(peekblock == nullptr)
+        return source->readBlock();
+    block_t *b = peekblock;
+    peekblock = nullptr;
+    return b;
+}
+
+block_t * ProbeableChunk::read(size_t sz)
+{
+    if(peekblock == nullptr)
+        return source->read(sz);
+    if(sz < peekblock->i_buffer)
+    {
+        block_t *b = block_Alloc(sz);
+        if(b)
+        {
+            memcpy(b->p_buffer, peekblock->p_buffer, sz);
+            b->i_flags = peekblock->i_flags;
+            peekblock->i_flags = 0;
+            peekblock->p_buffer += sz;
+            peekblock->i_buffer -= sz;
+        }
+        return b;
+    }
+    else
+    {
+        block_t *append = sz > peekblock->i_buffer ? source->read(sz - peekblock->i_buffer)
+                                                   : nullptr;
+        if(append)
+        {
+            peekblock = block_Realloc(peekblock, 0, sz);
+            if(peekblock)
+                memcpy(&peekblock->p_buffer[peekblock->i_buffer - append->i_buffer],
+                       append->p_buffer, append->i_buffer);
+            block_Release(append);
+        }
+        block_t *b = peekblock;
+        peekblock = nullptr;
+        return b;
+    }
+}
+
+bool ProbeableChunk::hasMoreData() const
+{
+    return (peekblock || source->hasMoreData());
+}
+
+size_t ProbeableChunk::getBytesRead() const
+{
+    return source->getBytesRead() - (peekblock ? peekblock->i_buffer : 0);
+}
+
+size_t ProbeableChunk::peek(const uint8_t **pp)
+{
+    if(!peekblock)
+        peekblock = source->readBlock();
+    if(!peekblock)
+        return 0;
+    *pp = peekblock->p_buffer;
+    return peekblock->i_buffer;
+}
diff --git a/modules/demux/adaptive/http/Chunk.h b/modules/demux/adaptive/http/Chunk.h
index 41f360a54c..7cdf04f9cd 100644
--- a/modules/demux/adaptive/http/Chunk.h
+++ b/modules/demux/adaptive/http/Chunk.h
@@ -55,6 +55,7 @@ namespace adaptive
         class ChunkInterface
         {
             public:
+                virtual ~ChunkInterface() {}
                 virtual std::string getContentType  () const = 0;
                 virtual RequestStatus getRequestStatus() const = 0;
 
@@ -178,6 +179,27 @@ namespace adaptive
             protected:
                 virtual void        onDownload      (block_t **)  override {}
         };
+
+        class ProbeableChunk : public ChunkInterface
+        {
+            public:
+                ProbeableChunk(ChunkInterface *);
+                virtual ~ProbeableChunk();
+
+                virtual std::string getContentType  () const override;
+                virtual RequestStatus getRequestStatus() const override;
+
+                virtual block_t *   readBlock       () override;
+                virtual block_t *   read            (size_t) override;
+                virtual bool        hasMoreData     () const override;
+                virtual size_t      getBytesRead    () const override;
+
+                size_t peek(const uint8_t **);
+
+            private:
+                ChunkInterface *source;
+                block_t *peekblock;
+        };
     }
 }
 



More information about the vlc-commits mailing list