[vlc-commits] demux: adaptative: simplify using BytesRange

Francois Cartegnie git at videolan.org
Tue Oct 27 19:13:52 CET 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Oct 16 19:31:23 2015 +0200| [002015caa142a310c7e3665fc31ed0b1f5f7a676] | committer: Francois Cartegnie

demux: adaptative: simplify using BytesRange

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

 modules/demux/adaptative/Streams.cpp               |    6 +---
 modules/demux/adaptative/http/Chunk.cpp            |   29 +++++---------------
 modules/demux/adaptative/http/Chunk.h              |   12 ++++----
 .../adaptative/http/HTTPConnectionManager.cpp      |    2 +-
 modules/demux/adaptative/playlist/Segment.cpp      |    6 ++--
 5 files changed, 16 insertions(+), 39 deletions(-)

diff --git a/modules/demux/adaptative/Streams.cpp b/modules/demux/adaptative/Streams.cpp
index a0f48a3..b99d7e6 100644
--- a/modules/demux/adaptative/Streams.cpp
+++ b/modules/demux/adaptative/Streams.cpp
@@ -332,11 +332,7 @@ block_t * AbstractStream::readNextBlock(size_t)
     /* New chunk, do query */
     if(chunk->getBytesRead() == 0)
     {
-        BytesRange bytesRange;
-        if(chunk->usesByteRange())
-            bytesRange = BytesRange(chunk->getStartByte(), chunk->getEndByte());
-
-        if(chunk->getConnection()->query(chunk->getPath(), bytesRange) != VLC_SUCCESS)
+        if(chunk->getConnection()->query(chunk->getPath(), chunk->getBytesRange()) != VLC_SUCCESS)
         {
             currentChunk = NULL;
             delete chunk;
diff --git a/modules/demux/adaptative/http/Chunk.cpp b/modules/demux/adaptative/http/Chunk.cpp
index 7972ed9..382ffc8 100644
--- a/modules/demux/adaptative/http/Chunk.cpp
+++ b/modules/demux/adaptative/http/Chunk.cpp
@@ -33,8 +33,6 @@
 using namespace adaptative::http;
 
 Chunk::Chunk        (const std::string& url) :
-       startByte    (0),
-       endByte      (0),
        port         (0),
        length       (0),
        bytesRead    (0),
@@ -78,34 +76,21 @@ Chunk::~Chunk()
         connection->setUsed(false);
 }
 
-size_t              Chunk::getEndByte           () const
+const BytesRange & Chunk::getBytesRange() const
 {
-    return endByte;
-}
-size_t              Chunk::getStartByte         () const
-{
-    return startByte;
+    return bytesRange;
 }
+
 const std::string&  Chunk::getUrl               () const
 {
     return url;
 }
-void                Chunk::setEndByte           (size_t endByte)
-{
-    this->endByte = endByte;
-    if (endByte > startByte)
-        length = endByte - startByte;
-}
-void                Chunk::setStartByte         (size_t startByte)
-{
-    this->startByte = startByte;
-    if (endByte > startByte)
-        length = endByte - startByte;
-}
 
-bool                Chunk::usesByteRange        () const
+void Chunk::setBytesRange(const BytesRange &range)
 {
-    return (startByte != endByte);
+    bytesRange = range;
+    if(bytesRange.isValid() && bytesRange.getEndByte())
+        length = bytesRange.getEndByte() - bytesRange.getStartByte();
 }
 
 const std::string&  Chunk::getScheme            () const
diff --git a/modules/demux/adaptative/http/Chunk.h b/modules/demux/adaptative/http/Chunk.h
index 8f71752..0d9dd32 100644
--- a/modules/demux/adaptative/http/Chunk.h
+++ b/modules/demux/adaptative/http/Chunk.h
@@ -25,6 +25,7 @@
 #ifndef CHUNK_H_
 #define CHUNK_H_
 
+#include "BytesRange.hpp"
 #include <vector>
 #include <string>
 #include <stdint.h>
@@ -43,8 +44,7 @@ namespace adaptative
                 Chunk           (const std::string &url);
                 virtual ~Chunk  ();
 
-                size_t              getEndByte              () const;
-                size_t              getStartByte            () const;
+                const BytesRange &  getBytesRange           () const;
                 const std::string&  getUrl                  () const;
                 const std::string&  getScheme               () const;
                 const std::string&  getHostname             () const;
@@ -57,9 +57,7 @@ namespace adaptative
                 void                setConnection   (HTTPConnection *connection);
                 void                setBytesRead    (size_t bytes);
                 void                setLength       (size_t length);
-                void                setEndByte      (size_t endByte);
-                void                setStartByte    (size_t startByte);
-                bool                usesByteRange   () const;
+                void                setBytesRange   (const BytesRange &);
 
                 virtual void        onDownload      (block_t **) {}
 
@@ -68,13 +66,13 @@ namespace adaptative
                 std::string                 scheme;
                 std::string                 path;
                 std::string                 hostname;
-                size_t                      startByte;
-                size_t                      endByte;
                 int                         port;
+                BytesRange                  bytesRange;
                 size_t                      length;
                 size_t                      bytesRead;
                 HTTPConnection             *connection;
         };
+
     }
 }
 
diff --git a/modules/demux/adaptative/http/HTTPConnectionManager.cpp b/modules/demux/adaptative/http/HTTPConnectionManager.cpp
index a792fcb..aca4e53 100644
--- a/modules/demux/adaptative/http/HTTPConnectionManager.cpp
+++ b/modules/demux/adaptative/http/HTTPConnectionManager.cpp
@@ -74,7 +74,7 @@ bool HTTPConnectionManager::connectChunk(Chunk *chunk)
         return true;
 
     msg_Dbg(stream, "Retrieving %s @%zu", chunk->getUrl().c_str(),
-            chunk->getStartByte());
+            chunk->getBytesRange().isValid() ? chunk->getBytesRange().getStartByte() : 0);
 
     const int sockettype = (chunk->getScheme() == "https") ? TLSSocket::TLS : Socket::REGULAR;
     HTTPConnection *conn = getConnection(chunk->getHostname(), chunk->getPort(), sockettype);
diff --git a/modules/demux/adaptative/playlist/Segment.cpp b/modules/demux/adaptative/playlist/Segment.cpp
index 3cdb3f2..40f49fc 100644
--- a/modules/demux/adaptative/playlist/Segment.cpp
+++ b/modules/demux/adaptative/playlist/Segment.cpp
@@ -29,6 +29,7 @@
 #include "Segment.h"
 #include "BaseRepresentation.h"
 #include "SegmentChunk.hpp"
+#include "../http/BytesRange.hpp"
 #include <cassert>
 
 using namespace adaptative::http;
@@ -82,10 +83,7 @@ SegmentChunk* ISegment::toChunk(size_t index, BaseRepresentation *ctxrep)
     }
 
     if(startByte != endByte)
-    {
-        chunk->setStartByte(startByte);
-        chunk->setEndByte(endByte);
-    }
+        chunk->setBytesRange(BytesRange(startByte, endByte));
 
     chunk->setRepresentation(ctxrep);
 



More information about the vlc-commits mailing list