Commit 50541d21 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptive: simplify streams with unique init method

parent 43c91076
......@@ -35,10 +35,10 @@
using namespace adaptive;
using namespace adaptive::http;
AbstractStream::AbstractStream(demux_t * demux_, const StreamFormat &format_)
AbstractStream::AbstractStream(demux_t * demux_)
{
p_realdemux = demux_;
format = format_;
format = StreamFormat::UNSUPPORTED;
currentChunk = NULL;
eof = false;
dead = false;
......@@ -47,42 +47,50 @@ AbstractStream::AbstractStream(demux_t * demux_, const StreamFormat &format_)
discontinuity = false;
segmentTracker = NULL;
pcr = VLC_TS_INVALID;
demuxersource = NULL;
commandsqueue = NULL;
demuxer = NULL;
fakeesout = NULL;
}
/* Don't even try if not supported */
if((unsigned)format == StreamFormat::UNSUPPORTED)
throw VLC_EGENERIC;
bool AbstractStream::init(const StreamFormat &format_, SegmentTracker *tracker, HTTPConnectionManager *conn)
{
/* Don't even try if not supported or already init */
if((unsigned)format_ == StreamFormat::UNSUPPORTED || demuxersource)
return false;
demuxersource = new (std::nothrow) ChunksSourceStream( VLC_OBJECT(p_realdemux), this );
if(!demuxersource)
throw VLC_EGENERIC;
CommandsFactory *factory = new (std::nothrow) CommandsFactory();
if(!factory)
if(demuxersource)
{
CommandsFactory *factory = new (std::nothrow) CommandsFactory();
if(factory)
{
commandsqueue = new (std::nothrow) CommandsQueue(factory);
if(commandsqueue)
{
fakeesout = new (std::nothrow) FakeESOut(p_realdemux->out, commandsqueue);
if(fakeesout)
{
/* All successfull */
fakeesout->setExtraInfoProvider( this );
format = format_;
segmentTracker = tracker;
segmentTracker->registerListener(this);
connManager = conn;
return true;
}
delete commandsqueue;
commandsqueue = NULL;
}
else
{
delete factory;
}
}
delete demuxersource;
throw VLC_EGENERIC;
}
commandsqueue = new CommandsQueue(factory);
if(!commandsqueue)
{
delete factory;
delete demuxersource;
throw VLC_EGENERIC;
}
fakeesout = new (std::nothrow) FakeESOut(p_realdemux->out, commandsqueue);
if(!fakeesout)
{
delete commandsqueue;
delete demuxersource;
throw VLC_EGENERIC;
}
fakeesout->setExtraInfoProvider( this );
return false;
}
AbstractStream::~AbstractStream()
......@@ -96,14 +104,6 @@ AbstractStream::~AbstractStream()
delete commandsqueue;
}
void AbstractStream::bind(SegmentTracker *tracker, HTTPConnectionManager *conn)
{
segmentTracker = tracker;
segmentTracker->registerListener(this);
connManager = conn;
}
void AbstractStream::prepareFormatChange()
{
if(demuxer)
......
......@@ -54,9 +54,9 @@ namespace adaptive
public SegmentTrackerListenerInterface
{
public:
AbstractStream(demux_t *, const StreamFormat &);
AbstractStream(demux_t *);
virtual ~AbstractStream();
void bind(SegmentTracker *, HTTPConnectionManager *);
bool init(const StreamFormat &, SegmentTracker *, HTTPConnectionManager *);
void setLanguage(const std::string &);
void setDescription(const std::string &);
......
......@@ -25,8 +25,8 @@
using namespace dash;
DASHStream::DASHStream(demux_t *demux, const StreamFormat &format)
:AbstractStream(demux, format)
DASHStream::DASHStream(demux_t *demux)
:AbstractStream(demux)
{
}
......@@ -74,13 +74,11 @@ AbstractDemuxer * DASHStream::createDemux(const StreamFormat &format)
AbstractStream * DASHStreamFactory::create(demux_t *realdemux, const StreamFormat &format,
SegmentTracker *tracker, HTTPConnectionManager *manager) const
{
AbstractStream *stream;
try
AbstractStream *stream = new (std::nothrow) DASHStream(realdemux);
if(stream && !stream->init(format, tracker, manager))
{
stream = new DASHStream(realdemux, format);
} catch (int) {
delete stream;
return NULL;
}
stream->bind(tracker, manager);
return stream;
}
......@@ -29,7 +29,7 @@ namespace dash
class DASHStream : public AbstractStream
{
public:
DASHStream(demux_t *, const StreamFormat &);
DASHStream(demux_t *);
protected:
virtual block_t *checkBlock(block_t *, bool); /* impl */
......
......@@ -26,8 +26,8 @@
using namespace hls;
HLSStream::HLSStream(demux_t *demux, const StreamFormat &format)
:AbstractStream(demux, format)
HLSStream::HLSStream(demux_t *demux)
: AbstractStream(demux)
{
b_timestamps_offset_set = false;
i_aac_offset = 0;
......@@ -158,13 +158,11 @@ block_t * HLSStream::checkBlock(block_t *p_block, bool b_first)
AbstractStream * HLSStreamFactory::create(demux_t *realdemux, const StreamFormat &,
SegmentTracker *tracker, HTTPConnectionManager *manager) const
{
HLSStream *stream;
try
HLSStream *stream = new (std::nothrow) HLSStream(realdemux);
if(stream && !stream->init(StreamFormat(StreamFormat::UNKNOWN), tracker, manager))
{
stream = new HLSStream(realdemux, StreamFormat(StreamFormat::UNKNOWN));
} catch (int) {
delete stream;
return NULL;
}
stream->bind(tracker, manager);
return stream;
}
......@@ -29,7 +29,7 @@ namespace hls
class HLSStream : public AbstractStream
{
public:
HLSStream(demux_t *, const StreamFormat &);
HLSStream(demux_t *);
virtual bool setPosition(mtime_t, bool); /* reimpl */
protected:
......
......@@ -26,8 +26,8 @@
using namespace smooth;
SmoothStream::SmoothStream(demux_t *demux, const StreamFormat &format)
:AbstractStream(demux, format)
SmoothStream::SmoothStream(demux_t *demux)
:AbstractStream(demux)
{
}
......@@ -63,13 +63,11 @@ block_t * SmoothStream::checkBlock(block_t *p_block, bool)
AbstractStream * SmoothStreamFactory::create(demux_t *realdemux, const StreamFormat &format,
SegmentTracker *tracker, HTTPConnectionManager *manager) const
{
SmoothStream *stream;
try
SmoothStream *stream = new (std::nothrow) SmoothStream(realdemux);
if(stream && !stream->init(format,tracker, manager))
{
stream = new SmoothStream(realdemux, format);
} catch (int) {
delete stream;
return NULL;
}
stream->bind(tracker, manager);
return stream;
}
......@@ -29,7 +29,7 @@ namespace smooth
class SmoothStream : public AbstractStream
{
public:
SmoothStream(demux_t *, const StreamFormat &);
SmoothStream(demux_t *);
protected:
virtual AbstractDemuxer * createDemux(const StreamFormat &); /* impl */
......
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