Commit 002015ca authored by Francois Cartegnie's avatar Francois Cartegnie

demux: adaptative: simplify using BytesRange

parent 35014185
...@@ -332,11 +332,7 @@ block_t * AbstractStream::readNextBlock(size_t) ...@@ -332,11 +332,7 @@ block_t * AbstractStream::readNextBlock(size_t)
/* New chunk, do query */ /* New chunk, do query */
if(chunk->getBytesRead() == 0) if(chunk->getBytesRead() == 0)
{ {
BytesRange bytesRange; if(chunk->getConnection()->query(chunk->getPath(), chunk->getBytesRange()) != VLC_SUCCESS)
if(chunk->usesByteRange())
bytesRange = BytesRange(chunk->getStartByte(), chunk->getEndByte());
if(chunk->getConnection()->query(chunk->getPath(), bytesRange) != VLC_SUCCESS)
{ {
currentChunk = NULL; currentChunk = NULL;
delete chunk; delete chunk;
......
...@@ -33,8 +33,6 @@ ...@@ -33,8 +33,6 @@
using namespace adaptative::http; using namespace adaptative::http;
Chunk::Chunk (const std::string& url) : Chunk::Chunk (const std::string& url) :
startByte (0),
endByte (0),
port (0), port (0),
length (0), length (0),
bytesRead (0), bytesRead (0),
...@@ -78,34 +76,21 @@ Chunk::~Chunk() ...@@ -78,34 +76,21 @@ Chunk::~Chunk()
connection->setUsed(false); connection->setUsed(false);
} }
size_t Chunk::getEndByte () const const BytesRange & Chunk::getBytesRange() const
{ {
return endByte; return bytesRange;
}
size_t Chunk::getStartByte () const
{
return startByte;
} }
const std::string& Chunk::getUrl () const const std::string& Chunk::getUrl () const
{ {
return url; 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 const std::string& Chunk::getScheme () const
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#ifndef CHUNK_H_ #ifndef CHUNK_H_
#define CHUNK_H_ #define CHUNK_H_
#include "BytesRange.hpp"
#include <vector> #include <vector>
#include <string> #include <string>
#include <stdint.h> #include <stdint.h>
...@@ -43,8 +44,7 @@ namespace adaptative ...@@ -43,8 +44,7 @@ namespace adaptative
Chunk (const std::string &url); Chunk (const std::string &url);
virtual ~Chunk (); virtual ~Chunk ();
size_t getEndByte () const; const BytesRange & getBytesRange () const;
size_t getStartByte () const;
const std::string& getUrl () const; const std::string& getUrl () const;
const std::string& getScheme () const; const std::string& getScheme () const;
const std::string& getHostname () const; const std::string& getHostname () const;
...@@ -57,9 +57,7 @@ namespace adaptative ...@@ -57,9 +57,7 @@ namespace adaptative
void setConnection (HTTPConnection *connection); void setConnection (HTTPConnection *connection);
void setBytesRead (size_t bytes); void setBytesRead (size_t bytes);
void setLength (size_t length); void setLength (size_t length);
void setEndByte (size_t endByte); void setBytesRange (const BytesRange &);
void setStartByte (size_t startByte);
bool usesByteRange () const;
virtual void onDownload (block_t **) {} virtual void onDownload (block_t **) {}
...@@ -68,13 +66,13 @@ namespace adaptative ...@@ -68,13 +66,13 @@ namespace adaptative
std::string scheme; std::string scheme;
std::string path; std::string path;
std::string hostname; std::string hostname;
size_t startByte;
size_t endByte;
int port; int port;
BytesRange bytesRange;
size_t length; size_t length;
size_t bytesRead; size_t bytesRead;
HTTPConnection *connection; HTTPConnection *connection;
}; };
} }
} }
......
...@@ -74,7 +74,7 @@ bool HTTPConnectionManager::connectChunk(Chunk *chunk) ...@@ -74,7 +74,7 @@ bool HTTPConnectionManager::connectChunk(Chunk *chunk)
return true; return true;
msg_Dbg(stream, "Retrieving %s @%zu", chunk->getUrl().c_str(), 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; const int sockettype = (chunk->getScheme() == "https") ? TLSSocket::TLS : Socket::REGULAR;
HTTPConnection *conn = getConnection(chunk->getHostname(), chunk->getPort(), sockettype); HTTPConnection *conn = getConnection(chunk->getHostname(), chunk->getPort(), sockettype);
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "Segment.h" #include "Segment.h"
#include "BaseRepresentation.h" #include "BaseRepresentation.h"
#include "SegmentChunk.hpp" #include "SegmentChunk.hpp"
#include "../http/BytesRange.hpp"
#include <cassert> #include <cassert>
using namespace adaptative::http; using namespace adaptative::http;
...@@ -82,10 +83,7 @@ SegmentChunk* ISegment::toChunk(size_t index, BaseRepresentation *ctxrep) ...@@ -82,10 +83,7 @@ SegmentChunk* ISegment::toChunk(size_t index, BaseRepresentation *ctxrep)
} }
if(startByte != endByte) if(startByte != endByte)
{ chunk->setBytesRange(BytesRange(startByte, endByte));
chunk->setStartByte(startByte);
chunk->setEndByte(endByte);
}
chunk->setRepresentation(ctxrep); chunk->setRepresentation(ctxrep);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment