Commit 002015ca authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptative: simplify using BytesRange

parent 35014185
......@@ -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;
......
......@@ -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
......
......@@ -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;
};
}
}
......
......@@ -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);
......
......@@ -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);
......
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