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