Commit 3bb8d715 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: adaptative: add chunk prepare

parent 422cceae
...@@ -115,6 +115,7 @@ HTTPChunkSource::HTTPChunkSource(const std::string& url, HTTPConnectionManager * ...@@ -115,6 +115,7 @@ HTTPChunkSource::HTTPChunkSource(const std::string& url, HTTPConnectionManager *
consumed (0), consumed (0),
port (0) port (0)
{ {
prepared = false;
if(!init(url)) if(!init(url))
throw VLC_EGENERIC; throw VLC_EGENERIC;
} }
...@@ -188,26 +189,35 @@ block_t * HTTPChunkSource::consume(size_t readsize) ...@@ -188,26 +189,35 @@ block_t * HTTPChunkSource::consume(size_t readsize)
return p_block; return p_block;
} }
block_t * HTTPChunkSource::read(size_t readsize) bool HTTPChunkSource::prepare()
{ {
if(prepared)
return true;
if(!connManager || !parentChunk) if(!connManager || !parentChunk)
return NULL; return false;
if(!connection) if(!connection)
{ {
connection = connManager->getConnection(scheme, hostname, port); connection = connManager->getConnection(scheme, hostname, port);
if(!connection) if(!connection)
return NULL; return false;
} }
if(consumed == 0)
{
if( connection->query(path, bytesRange) != VLC_SUCCESS ) if( connection->query(path, bytesRange) != VLC_SUCCESS )
return NULL; return false;
/* Because we don't know Chunk size at start, we need to get size /* Because we don't know Chunk size at start, we need to get size
from content length */ from content length */
contentLength = connection->getContentLength(); contentLength = connection->getContentLength();
} prepared = true;
return true;
}
block_t * HTTPChunkSource::read(size_t readsize)
{
if(!prepare())
return NULL;
if(consumed == contentLength && consumed > 0) if(consumed == contentLength && consumed > 0)
return NULL; return NULL;
......
...@@ -87,10 +87,12 @@ namespace adaptative ...@@ -87,10 +87,12 @@ namespace adaptative
static const size_t CHUNK_SIZE = 32768; static const size_t CHUNK_SIZE = 32768;
protected: protected:
virtual bool prepare();
virtual block_t * consume(size_t); virtual block_t * consume(size_t);
HTTPConnection *connection; HTTPConnection *connection;
HTTPConnectionManager *connManager; HTTPConnectionManager *connManager;
size_t consumed; /* read pointer */ size_t consumed; /* read pointer */
bool prepared;
private: private:
bool init(const std::string &); bool init(const std::string &);
......
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