diff --git a/modules/demux/adaptative/Streams.cpp b/modules/demux/adaptative/Streams.cpp index a0f48a3553..b99d7e6a0d 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 7972ed9338..382ffc862a 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 8f71752c75..0d9dd32b8c 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 #include #include @@ -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 a792fcb7c5..aca4e5389e 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 3cdb3f245f..40f49fc8fa 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 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);