Commit 0e944452 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: adaptative: add stream factory

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