Commit 7d7975d0 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptative: add readBlock

parent 3bb8d715
......@@ -32,7 +32,7 @@ namespace adaptative
{
public:
virtual ~ChunksSource() {}
virtual block_t *readNextBlock(size_t) = 0;
virtual block_t *readNextBlock() = 0;
};
}
......
......@@ -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;
......
......@@ -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 */
......
......@@ -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())
......
......@@ -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;
......
......@@ -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;
......
......@@ -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)
......
......@@ -34,6 +34,7 @@ namespace smooth
MemoryChunkSource(block_t *);
virtual ~MemoryChunkSource();
virtual block_t * readBlock(); /* impl */
virtual block_t * read(size_t); /* impl */
private:
......
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