Commit 3924bed4 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptive: add connection manager interface

parent 4000668d
......@@ -685,7 +685,7 @@ void PlaylistManager::updateControlsContentType()
}
}
AbstractAdaptationLogic *PlaylistManager::createLogic(AbstractAdaptationLogic::LogicType type, HTTPConnectionManager *conn)
AbstractAdaptationLogic *PlaylistManager::createLogic(AbstractAdaptationLogic::LogicType type, AbstractConnectionManager *conn)
{
switch(type)
{
......
......@@ -36,7 +36,7 @@ namespace adaptive
namespace http
{
class HTTPConnectionManager;
class AbstractConnectionManager;
}
using namespace playlist;
......@@ -89,9 +89,9 @@ namespace adaptive
/* local factories */
virtual AbstractAdaptationLogic *createLogic(AbstractAdaptationLogic::LogicType,
HTTPConnectionManager *);
AbstractConnectionManager *);
HTTPConnectionManager *conManager;
AbstractConnectionManager *conManager;
AbstractAdaptationLogic::LogicType logicType;
AbstractAdaptationLogic *logic;
AbstractPlaylist *playlist;
......
......@@ -112,7 +112,8 @@ void SegmentTracker::reset()
format = StreamFormat::UNSUPPORTED;
}
SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed, HTTPConnectionManager *connManager)
SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed,
AbstractConnectionManager *connManager)
{
BaseRepresentation *rep = NULL, *prevRep = NULL;
ISegment *segment;
......
......@@ -29,7 +29,7 @@ namespace adaptive
{
namespace http
{
class HTTPConnectionManager;
class AbstractConnectionManager;
}
namespace logic
......@@ -94,7 +94,7 @@ namespace adaptive
StreamFormat getCurrentFormat() const;
bool segmentsListReady() const;
void reset();
SegmentChunk* getNextChunk(bool, HTTPConnectionManager *);
SegmentChunk* getNextChunk(bool, AbstractConnectionManager *);
bool setPositionByTime(mtime_t, bool, bool);
void setPositionByNumber(uint64_t, bool);
mtime_t getPlaybackTime() const; /* Current segment start time if selected */
......
......@@ -53,7 +53,7 @@ AbstractStream::AbstractStream(demux_t * demux_)
vlc_mutex_init(&lock);
}
bool AbstractStream::init(const StreamFormat &format_, SegmentTracker *tracker, HTTPConnectionManager *conn)
bool AbstractStream::init(const StreamFormat &format_, SegmentTracker *tracker, AbstractConnectionManager *conn)
{
/* Don't even try if not supported or already init */
if((unsigned)format_ == StreamFormat::UNSUPPORTED || demuxersource)
......
......@@ -38,7 +38,7 @@ namespace adaptive
namespace http
{
class HTTPConnectionManager;
class AbstractConnectionManager;
}
namespace playlist
......@@ -56,7 +56,7 @@ namespace adaptive
public:
AbstractStream(demux_t *);
virtual ~AbstractStream();
bool init(const StreamFormat &, SegmentTracker *, HTTPConnectionManager *);
bool init(const StreamFormat &, SegmentTracker *, AbstractConnectionManager *);
void setLanguage(const std::string &);
void setDescription(const std::string &);
......@@ -109,7 +109,7 @@ namespace adaptive
demux_t *p_realdemux;
StreamFormat format;
HTTPConnectionManager *connManager; /* not owned */
AbstractConnectionManager *connManager; /* not owned */
SegmentTracker *segmentTracker;
SegmentChunk *currentChunk;
......@@ -131,7 +131,7 @@ namespace adaptive
public:
virtual ~AbstractStreamFactory() {}
virtual AbstractStream *create(demux_t*, const StreamFormat &,
SegmentTracker *, HTTPConnectionManager *) const = 0;
SegmentTracker *, AbstractConnectionManager *) const = 0;
};
}
#endif // STREAMS_HPP
......@@ -116,7 +116,7 @@ block_t * AbstractChunk::read(size_t size)
return doRead(size, false);
}
HTTPChunkSource::HTTPChunkSource(const std::string& url, HTTPConnectionManager *manager) :
HTTPChunkSource::HTTPChunkSource(const std::string& url, AbstractConnectionManager *manager) :
AbstractChunkSource(),
connection (NULL),
connManager (manager),
......@@ -231,7 +231,7 @@ block_t * HTTPChunkSource::readBlock()
return read(HTTPChunkSource::CHUNK_SIZE);
}
HTTPChunkBufferedSource::HTTPChunkBufferedSource(const std::string& url, HTTPConnectionManager *manager) :
HTTPChunkBufferedSource::HTTPChunkBufferedSource(const std::string& url, AbstractConnectionManager *manager) :
HTTPChunkSource(url, manager),
p_head (NULL),
pp_tail (&p_head),
......@@ -257,7 +257,7 @@ HTTPChunkBufferedSource::~HTTPChunkBufferedSource()
buffered = 0;
vlc_mutex_unlock(&lock);
connManager->downloader->cancel(this);
connManager->cancel(this);
vlc_cond_destroy(&avail);
vlc_mutex_destroy(&lock);
......@@ -443,7 +443,7 @@ block_t * HTTPChunkBufferedSource::read(size_t readsize)
return p_block;
}
HTTPChunk::HTTPChunk(const std::string &url, HTTPConnectionManager *manager):
HTTPChunk::HTTPChunk(const std::string &url, AbstractConnectionManager *manager):
AbstractChunk(new HTTPChunkSource(url, manager))
{
......
......@@ -38,7 +38,7 @@ namespace adaptive
namespace http
{
class AbstractConnection;
class HTTPConnectionManager;
class AbstractConnectionManager;
class AbstractChunk;
class AbstractChunkSource
......@@ -82,7 +82,7 @@ namespace adaptive
class HTTPChunkSource : public AbstractChunkSource
{
public:
HTTPChunkSource(const std::string &url, HTTPConnectionManager *);
HTTPChunkSource(const std::string &url, AbstractConnectionManager *);
virtual ~HTTPChunkSource();
virtual block_t * readBlock (); /* impl */
......@@ -94,7 +94,7 @@ namespace adaptive
protected:
virtual bool prepare();
AbstractConnection *connection;
HTTPConnectionManager *connManager;
AbstractConnectionManager *connManager;
size_t consumed; /* read pointer */
bool prepared;
bool eof;
......@@ -109,7 +109,7 @@ namespace adaptive
friend class Downloader;
public:
HTTPChunkBufferedSource(const std::string &url, HTTPConnectionManager *);
HTTPChunkBufferedSource(const std::string &url, AbstractConnectionManager *);
virtual ~HTTPChunkBufferedSource();
virtual block_t * readBlock (); /* reimpl */
virtual block_t * read (size_t); /* reimpl */
......@@ -134,7 +134,7 @@ namespace adaptive
class HTTPChunk : public AbstractChunk
{
public:
HTTPChunk(const std::string &url, HTTPConnectionManager *);
HTTPChunk(const std::string &url, AbstractConnectionManager *);
virtual ~HTTPChunk();
virtual void onDownload (block_t **) {} /* impl */
......
......@@ -34,9 +34,31 @@
using namespace adaptive::http;
HTTPConnectionManager::HTTPConnectionManager (vlc_object_t *p_object_, ConnectionFactory *factory_) :
p_object (p_object_),
rateObserver (NULL)
AbstractConnectionManager::AbstractConnectionManager(vlc_object_t *p_object_)
: IDownloadRateObserver()
{
p_object = p_object_;
rateObserver = NULL;
}
AbstractConnectionManager::~AbstractConnectionManager()
{
}
void AbstractConnectionManager::updateDownloadRate(size_t size, mtime_t time)
{
if(rateObserver)
rateObserver->updateDownloadRate(size, time);
}
void AbstractConnectionManager::setDownloadRateObserver(IDownloadRateObserver *obs)
{
rateObserver = obs;
}
HTTPConnectionManager::HTTPConnectionManager (vlc_object_t *p_object_, ConnectionFactory *factory_)
: AbstractConnectionManager( p_object_ )
{
vlc_mutex_init(&lock);
downloader = new (std::nothrow) Downloader();
......@@ -116,13 +138,16 @@ AbstractConnection * HTTPConnectionManager::getConnection(ConnectionParams &para
return conn;
}
void HTTPConnectionManager::updateDownloadRate(size_t size, mtime_t time)
void HTTPConnectionManager::start(AbstractChunkSource *source)
{
if(rateObserver)
rateObserver->updateDownloadRate(size, time);
HTTPChunkBufferedSource *src = dynamic_cast<HTTPChunkBufferedSource *>(source);
if(src)
downloader->schedule(src);
}
void HTTPConnectionManager::setDownloadRateObserver(IDownloadRateObserver *obs)
void HTTPConnectionManager::cancel(AbstractChunkSource *source)
{
rateObserver = obs;
HTTPChunkBufferedSource *src = dynamic_cast<HTTPChunkBufferedSource *>(source);
if(src)
downloader->cancel(src);
}
......@@ -39,26 +39,45 @@ namespace adaptive
class ConnectionFactory;
class AbstractConnection;
class Downloader;
class AbstractChunkSource;
class HTTPConnectionManager : public IDownloadRateObserver
class AbstractConnectionManager : public IDownloadRateObserver
{
public:
AbstractConnectionManager(vlc_object_t *);
~AbstractConnectionManager();
virtual void closeAllConnections () = 0;
virtual AbstractConnection * getConnection(ConnectionParams &) = 0;
virtual void start(AbstractChunkSource *) = 0;
virtual void cancel(AbstractChunkSource *) = 0;
virtual void updateDownloadRate(size_t, mtime_t); /* impl */
void setDownloadRateObserver(IDownloadRateObserver *);
protected:
vlc_object_t *p_object;
private:
IDownloadRateObserver *rateObserver;
};
class HTTPConnectionManager : public AbstractConnectionManager
{
public:
HTTPConnectionManager (vlc_object_t *p_object, ConnectionFactory * = NULL);
virtual ~HTTPConnectionManager ();
void closeAllConnections ();
AbstractConnection * getConnection(ConnectionParams &);
virtual void closeAllConnections () /* impl */;
virtual AbstractConnection * getConnection(ConnectionParams &) /* impl */;
virtual void updateDownloadRate(size_t, mtime_t); /* reimpl */
void setDownloadRateObserver(IDownloadRateObserver *);
Downloader *downloader;
virtual void start(AbstractChunkSource *) /* impl */;
virtual void cancel(AbstractChunkSource *) /* impl */;
private:
void releaseAllConnections ();
Downloader *downloader;
vlc_mutex_t lock;
std::vector<AbstractConnection *> connectionPool;
vlc_object_t *p_object;
IDownloadRateObserver *rateObserver;
ConnectionFactory *factory;
AbstractConnection * reuseConnection(ConnectionParams &);
};
......
......@@ -66,7 +66,7 @@ void ISegment::onChunkDownload(block_t **, SegmentChunk *, BaseRepresentation *)
}
SegmentChunk* ISegment::toChunk(size_t index, BaseRepresentation *rep, HTTPConnectionManager *connManager)
SegmentChunk* ISegment::toChunk(size_t index, BaseRepresentation *rep, AbstractConnectionManager *connManager)
{
const std::string url = getUrlSegment().toString(index, rep);
HTTPChunkBufferedSource *source = new (std::nothrow) HTTPChunkBufferedSource(url, connManager);
......@@ -78,7 +78,7 @@ SegmentChunk* ISegment::toChunk(size_t index, BaseRepresentation *rep, HTTPConne
SegmentChunk *chunk = new (std::nothrow) SegmentChunk(this, source, rep);
if( chunk )
{
connManager->downloader->schedule(source);
connManager->start(source);
return chunk;
}
else
......
......@@ -37,7 +37,7 @@ namespace adaptive
{
namespace http
{
class HTTPConnectionManager;
class AbstractConnectionManager;
}
namespace playlist
......@@ -58,7 +58,7 @@ namespace adaptive
* That is basically true when using an Url, and false
* when using an UrlTemplate
*/
virtual SegmentChunk* toChunk (size_t, BaseRepresentation *, HTTPConnectionManager *);
virtual SegmentChunk* toChunk (size_t, BaseRepresentation *, AbstractConnectionManager *);
virtual void setByteRange (size_t start, size_t end);
virtual void setSequenceNumber(uint64_t);
virtual uint64_t getSequenceNumber() const;
......
......@@ -72,7 +72,7 @@ AbstractDemuxer * DASHStream::createDemux(const StreamFormat &format)
}
AbstractStream * DASHStreamFactory::create(demux_t *realdemux, const StreamFormat &format,
SegmentTracker *tracker, HTTPConnectionManager *manager) const
SegmentTracker *tracker, AbstractConnectionManager *manager) const
{
AbstractStream *stream = new (std::nothrow) DASHStream(realdemux);
if(stream && !stream->init(format, tracker, manager))
......
......@@ -40,7 +40,7 @@ namespace dash
{
public:
virtual AbstractStream *create(demux_t*, const StreamFormat &,
SegmentTracker *, HTTPConnectionManager *) const;
SegmentTracker *, AbstractConnectionManager *) const;
};
}
......
......@@ -135,7 +135,7 @@ block_t * HLSStream::checkBlock(block_t *p_block, bool b_first)
}
AbstractStream * HLSStreamFactory::create(demux_t *realdemux, const StreamFormat &,
SegmentTracker *tracker, HTTPConnectionManager *manager) const
SegmentTracker *tracker, AbstractConnectionManager *manager) const
{
HLSStream *stream = new (std::nothrow) HLSStream(realdemux);
if(stream && !stream->init(StreamFormat(StreamFormat::UNKNOWN), tracker, manager))
......
......@@ -45,7 +45,7 @@ namespace hls
{
public:
virtual AbstractStream *create(demux_t*, const StreamFormat &,
SegmentTracker *, HTTPConnectionManager *) const;
SegmentTracker *, AbstractConnectionManager *) const;
};
}
......
......@@ -61,7 +61,7 @@ block_t * SmoothStream::checkBlock(block_t *p_block, bool)
}
AbstractStream * SmoothStreamFactory::create(demux_t *realdemux, const StreamFormat &format,
SegmentTracker *tracker, HTTPConnectionManager *manager) const
SegmentTracker *tracker, AbstractConnectionManager *manager) const
{
SmoothStream *stream = new (std::nothrow) SmoothStream(realdemux);
if(stream && !stream->init(format,tracker, manager))
......
......@@ -40,7 +40,7 @@ namespace smooth
{
public:
virtual AbstractStream *create(demux_t*, const StreamFormat &,
SegmentTracker *, HTTPConnectionManager *) const;
SegmentTracker *, AbstractConnectionManager *) const;
};
}
......
......@@ -306,7 +306,7 @@ block_t * ForgedInitSegment::buildMoovBox()
return moov;
}
SegmentChunk* ForgedInitSegment::toChunk(size_t, BaseRepresentation *rep, HTTPConnectionManager *)
SegmentChunk* ForgedInitSegment::toChunk(size_t, BaseRepresentation *rep, AbstractConnectionManager *)
{
block_t *moov = buildMoovBox();
if(moov)
......
......@@ -39,7 +39,7 @@ namespace smooth
ForgedInitSegment(ICanonicalUrl *parent, const std::string &,
uint64_t, uint64_t);
virtual ~ForgedInitSegment();
virtual SegmentChunk* toChunk(size_t, BaseRepresentation *, HTTPConnectionManager *); /* reimpl */
virtual SegmentChunk* toChunk(size_t, BaseRepresentation *, AbstractConnectionManager *); /* reimpl */
void setWaveFormatEx(const std::string &);
void setCodecPrivateData(const std::string &);
void setChannels(uint16_t);
......
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