Commit 0e944452 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptative: add stream factory

parent 9a3c24a6
......@@ -52,6 +52,7 @@ PlaylistManager::PlaylistManager( AbstractPlaylist *pl,
conManager ( NULL ),
logicType ( type ),
playlist ( pl ),
streamOutputFactory( NULL ),
stream ( stream ),
nextPlaylistupdate ( 0 )
{
......@@ -90,11 +91,13 @@ bool PlaylistManager::start(demux_t *demux)
}
SegmentTracker *tracker = new (std::nothrow) SegmentTracker(logic, playlist);
DefaultStreamOutputFactory defaultfactory;
try
{
if(!tracker)
throw VLC_ENOMEM;
streams[type]->create(demux, logic, tracker);
streams[type]->create(demux, logic, tracker,
(streamOutputFactory) ? *streamOutputFactory : defaultfactory );
} catch (int) {
delete streams[type];
delete logic;
......
......@@ -41,6 +41,8 @@ namespace adaptative
using namespace logic;
using namespace http;
class AbstractStreamFactory;
class PlaylistManager
{
public:
......@@ -60,11 +62,13 @@ namespace adaptative
virtual bool updatePlaylist();
protected:
/* local factories */
virtual AbstractAdaptationLogic *createLogic(AbstractAdaptationLogic::LogicType);
HTTPConnectionManager *conManager;
AbstractAdaptationLogic::LogicType logicType;
AbstractPlaylist *playlist;
AbstractStreamOutputFactory *streamOutputFactory;
stream_t *stream;
Stream *streams[StreamTypeCount];
mtime_t nextPlaylistupdate;
......
......@@ -90,20 +90,10 @@ StreamFormat Stream::mimeToFormat(const std::string &mime)
return format;
}
void Stream::create(demux_t *demux, AbstractAdaptationLogic *logic, SegmentTracker *tracker)
void Stream::create(demux_t *demux, AbstractAdaptationLogic *logic,
SegmentTracker *tracker, AbstractStreamOutputFactory &factory)
{
switch(format)
{
case StreamFormat::MP4:
output = new MP4StreamOutput(demux);
break;
case StreamFormat::MPEG2TS:
output = new MPEG2TSStreamOutput(demux);
break;
default:
throw VLC_EBADVAR;
break;
}
output = factory.create(demux, format);
adaptationLogic = logic;
segmentTracker = tracker;
}
......@@ -452,6 +442,24 @@ void AbstractStreamOutput::esOutDestroy(es_out_t *fakees)
}
/* !Static callbacks */
AbstractStreamOutput *DefaultStreamOutputFactory::create(demux_t *demux, int format) const
{
switch(format)
{
case StreamFormat::MP4:
return new MP4StreamOutput(demux);
case StreamFormat::MPEG2TS:
return new MPEG2TSStreamOutput(demux);
default:
throw VLC_EBADVAR;
break;
}
return NULL;
}
MP4StreamOutput::MP4StreamOutput(demux_t *demux) :
AbstractStreamOutput(demux)
{
......
......@@ -46,6 +46,7 @@ namespace adaptative
class AbstractStreamOutput;
class AbstractStreamOutputFactory;
using namespace http;
using namespace logic;
......@@ -59,7 +60,8 @@ namespace adaptative
bool operator==(const Stream &) const;
static StreamType mimeToType(const std::string &mime);
static StreamFormat mimeToFormat(const std::string &mime);
void create(demux_t *, AbstractAdaptationLogic *, SegmentTracker *);
void create(demux_t *, AbstractAdaptationLogic *,
SegmentTracker *, AbstractStreamOutputFactory &);
bool isEOF() const;
mtime_t getPCR() const;
int getGroup() const;
......@@ -127,6 +129,18 @@ namespace adaptative
void sendToDecoderUnlocked(mtime_t);
};
class AbstractStreamOutputFactory
{
public:
virtual AbstractStreamOutput *create(demux_t*, int streamType) const = 0;
};
class DefaultStreamOutputFactory : public AbstractStreamOutputFactory
{
public:
virtual AbstractStreamOutput *create(demux_t*, int streamType) const;
};
class MP4StreamOutput : public AbstractStreamOutput
{
public:
......
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