[vlc-commits] demux: adaptative: add readBlock

Francois Cartegnie git at videolan.org
Thu Nov 19 14:47:39 CET 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Nov 18 21:01:30 2015 +0100| [7d7975d05879808f3d38aa54261624d0ef8f6821] | committer: Francois Cartegnie

demux: adaptative: add readBlock

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

 modules/demux/adaptative/ChunksSource.hpp          |    2 +-
 modules/demux/adaptative/Streams.cpp               |    4 ++--
 modules/demux/adaptative/Streams.hpp               |    2 +-
 modules/demux/adaptative/http/Chunk.cpp            |   21 +++++++++++++++++---
 modules/demux/adaptative/http/Chunk.h              |    8 ++++++--
 modules/demux/adaptative/plumbing/SourceStream.cpp |    3 +--
 modules/demux/smooth/playlist/MemoryChunk.cpp      |   11 ++++++++++
 modules/demux/smooth/playlist/MemoryChunk.hpp      |    1 +
 8 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/modules/demux/adaptative/ChunksSource.hpp b/modules/demux/adaptative/ChunksSource.hpp
index f4aa5ce..52ee7fe 100644
--- a/modules/demux/adaptative/ChunksSource.hpp
+++ b/modules/demux/adaptative/ChunksSource.hpp
@@ -32,7 +32,7 @@ namespace adaptative
     {
         public:
             virtual ~ChunksSource() {}
-            virtual block_t *readNextBlock(size_t) = 0;
+            virtual block_t *readNextBlock() = 0;
     };
 }
 
diff --git a/modules/demux/adaptative/Streams.cpp b/modules/demux/adaptative/Streams.cpp
index 999f0e3..e6aa9a0 100644
--- a/modules/demux/adaptative/Streams.cpp
+++ b/modules/demux/adaptative/Streams.cpp
@@ -276,7 +276,7 @@ AbstractStream::status AbstractStream::demux(mtime_t nz_deadline, bool send)
     return AbstractStream::status_demuxed;
 }
 
-block_t * AbstractStream::readNextBlock(size_t toread)
+block_t * AbstractStream::readNextBlock()
 {
     if (currentChunk == NULL && !eof)
         currentChunk = segmentTracker->getNextChunk(!fakeesout->restarting(), connManager);
@@ -296,7 +296,7 @@ block_t * AbstractStream::readNextBlock(size_t toread)
 
     const bool b_segment_head_chunk = (currentChunk->getBytesRead() == 0);
 
-    block_t *block = currentChunk->read(toread);
+    block_t *block = currentChunk->readBlock();
     if(block == NULL)
     {
         delete currentChunk;
diff --git a/modules/demux/adaptative/Streams.hpp b/modules/demux/adaptative/Streams.hpp
index a419e45..7542a51 100644
--- a/modules/demux/adaptative/Streams.hpp
+++ b/modules/demux/adaptative/Streams.hpp
@@ -79,7 +79,7 @@ namespace adaptative
         void prune();
         void runUpdates();
 
-        virtual block_t *readNextBlock(size_t); /* impl */
+        virtual block_t *readNextBlock(); /* impl */
 
         virtual void fillExtraFMTInfo( es_format_t * ) const; /* impl */
         virtual void trackerEvent(const SegmentTrackerEvent &); /* impl */
diff --git a/modules/demux/adaptative/http/Chunk.cpp b/modules/demux/adaptative/http/Chunk.cpp
index 747d7d9..45f3956 100644
--- a/modules/demux/adaptative/http/Chunk.cpp
+++ b/modules/demux/adaptative/http/Chunk.cpp
@@ -90,15 +90,15 @@ size_t AbstractChunk::getBytesToRead() const
     return source->getContentLength() - bytesRead;
 }
 
-block_t * AbstractChunk::read(size_t size)
+block_t * AbstractChunk::doRead(size_t size, bool b_block)
 {
     if(!source)
         return NULL;
 
-    block_t *block = source->read(size);
+    block_t *block = (b_block) ? source->readBlock() : source->read(size);
     if(block)
     {
-	if(bytesRead == 0)
+        if(bytesRead == 0)
             block->i_flags |= BLOCK_FLAG_HEADER;
         bytesRead += block->i_buffer;
         onDownload(&block);
@@ -108,6 +108,16 @@ block_t * AbstractChunk::read(size_t size)
     return block;
 }
 
+block_t * AbstractChunk::readBlock()
+{
+    return doRead(0, true);
+}
+
+block_t * AbstractChunk::read(size_t size)
+{
+    return doRead(size, false);
+}
+
 HTTPChunkSource::HTTPChunkSource(const std::string& url, HTTPConnectionManager *manager) :
     AbstractChunkSource(),
     connection   (NULL),
@@ -214,6 +224,11 @@ bool HTTPChunkSource::prepare()
     return true;
 }
 
+block_t * HTTPChunkSource::readBlock()
+{
+    return read(HTTPChunkSource::CHUNK_SIZE);
+}
+
 block_t * HTTPChunkSource::read(size_t readsize)
 {
     if(!prepare())
diff --git a/modules/demux/adaptative/http/Chunk.h b/modules/demux/adaptative/http/Chunk.h
index a100bc3..09d8eac 100644
--- a/modules/demux/adaptative/http/Chunk.h
+++ b/modules/demux/adaptative/http/Chunk.h
@@ -45,7 +45,8 @@ namespace adaptative
             public:
                 AbstractChunkSource();
                 virtual ~AbstractChunkSource();
-                virtual block_t *   read(size_t) = 0;
+                virtual block_t *   readBlock       () = 0;
+                virtual block_t *   read            (size_t) = 0;
                 void                setParentChunk  (AbstractChunk *);
                 void                setBytesRange   (const BytesRange &);
                 const BytesRange &  getBytesRange   () const;
@@ -65,6 +66,7 @@ namespace adaptative
                 size_t              getBytesRead            () const;
                 size_t              getBytesToRead          () const;
 
+                virtual block_t *   readBlock       ();
                 virtual block_t *   read            (size_t);
                 virtual void        onDownload      (block_t **) = 0;
 
@@ -74,6 +76,7 @@ namespace adaptative
 
             private:
                 size_t              bytesRead;
+                block_t *           doRead(size_t, bool);
         };
 
         class HTTPChunkSource : public AbstractChunkSource
@@ -82,7 +85,8 @@ namespace adaptative
                 HTTPChunkSource(const std::string &url, HTTPConnectionManager *);
                 virtual ~HTTPChunkSource();
 
-                virtual block_t * read(size_t); /* impl */
+                virtual block_t *   readBlock       (); /* impl */
+                virtual block_t *   read            (size_t); /* impl */
 
                 static const size_t CHUNK_SIZE = 32768;
 
diff --git a/modules/demux/adaptative/plumbing/SourceStream.cpp b/modules/demux/adaptative/plumbing/SourceStream.cpp
index ab51a95..70e3237 100644
--- a/modules/demux/adaptative/plumbing/SourceStream.cpp
+++ b/modules/demux/adaptative/plumbing/SourceStream.cpp
@@ -71,8 +71,7 @@ ssize_t ChunksSourceStream::Read(uint8_t *buf, size_t size)
 
     while(i_toread && !b_eof)
     {
-        const size_t i_blocksize = __MAX(i_toread, http::HTTPChunkSource::CHUNK_SIZE);
-        if(!p_block && !(p_block = source->readNextBlock(i_blocksize)))
+        if(!p_block && !(p_block = source->readNextBlock()))
         {
             b_eof = true;
             break;
diff --git a/modules/demux/smooth/playlist/MemoryChunk.cpp b/modules/demux/smooth/playlist/MemoryChunk.cpp
index 4fd2353..bee571b 100644
--- a/modules/demux/smooth/playlist/MemoryChunk.cpp
+++ b/modules/demux/smooth/playlist/MemoryChunk.cpp
@@ -36,6 +36,17 @@ MemoryChunkSource::~MemoryChunkSource()
         block_Release(data);
 }
 
+block_t * MemoryChunkSource::readBlock()
+{
+    block_t *p_block = NULL;
+    if(data)
+    {
+        p_block = data;
+        data = NULL;
+    }
+    return p_block;
+}
+
 block_t * MemoryChunkSource::read(size_t toread)
 {
     if(!data)
diff --git a/modules/demux/smooth/playlist/MemoryChunk.hpp b/modules/demux/smooth/playlist/MemoryChunk.hpp
index 0bedd84..289b185 100644
--- a/modules/demux/smooth/playlist/MemoryChunk.hpp
+++ b/modules/demux/smooth/playlist/MemoryChunk.hpp
@@ -34,6 +34,7 @@ namespace smooth
                 MemoryChunkSource(block_t *);
                 virtual ~MemoryChunkSource();
 
+                virtual block_t * readBlock(); /* impl */
                 virtual block_t * read(size_t); /* impl */
 
             private:



More information about the vlc-commits mailing list