Commit 7bbd00f2 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptive: refactor demux creation with factory interface

parent 8f095301
......@@ -561,6 +561,41 @@ void AbstractStream::setTimeOffset(mtime_t i_offset)
}
}
AbstractDemuxer * AbstractStream::createDemux(const StreamFormat &format)
{
AbstractDemuxer *ret = newDemux( p_realdemux, format,
fakeesout->getEsOut(), demuxersource );
if(ret && !ret->create())
{
delete ret;
ret = NULL;
}
else commandsqueue->Commit();
return ret;
}
AbstractDemuxer *AbstractStream::newDemux(demux_t *p_realdemux, const StreamFormat &format,
es_out_t *out, AbstractSourceStream *source) const
{
AbstractDemuxer *ret = NULL;
switch((unsigned)format)
{
case StreamFormat::MP4:
ret = new Demuxer(p_realdemux, "mp4", out, source);
break;
case StreamFormat::MPEG2TS:
ret = new Demuxer(p_realdemux, "ts", out, source);
break;
default:
case StreamFormat::UNSUPPORTED:
break;
}
return ret;
}
void AbstractStream::trackerEvent(const SegmentTrackerEvent &event)
{
switch(event.type)
......
......@@ -51,7 +51,8 @@ namespace adaptive
class AbstractStream : public ChunksSource,
public ExtraFMTInfoInterface,
public SegmentTrackerListenerInterface
public SegmentTrackerListenerInterface,
public DemuxerFactoryInterface
{
public:
AbstractStream(demux_t *);
......@@ -100,7 +101,9 @@ namespace adaptive
bool seekAble() const;
virtual void setTimeOffset(mtime_t);
virtual block_t *checkBlock(block_t *, bool) = 0;
virtual AbstractDemuxer * createDemux(const StreamFormat &) = 0;
AbstractDemuxer * createDemux(const StreamFormat &);
virtual AbstractDemuxer * newDemux(demux_t *, const StreamFormat &,
es_out_t *, AbstractSourceStream *) const; /* impl */
virtual bool startDemux();
virtual bool restartDemux();
......
......@@ -81,6 +81,12 @@ namespace adaptive
mtime_t length;
};
class DemuxerFactoryInterface
{
public:
virtual AbstractDemuxer * newDemux(demux_t *, const StreamFormat &,
es_out_t *, AbstractSourceStream *) const = 0;
};
}
#endif // DEMUXER_HPP
......@@ -35,25 +35,23 @@ block_t * DASHStream::checkBlock(block_t *p_block, bool)
return p_block;
}
AbstractDemuxer * DASHStream::createDemux(const StreamFormat &format)
AbstractDemuxer *DASHStream::newDemux(demux_t *p_realdemux, const StreamFormat &format,
es_out_t *out, AbstractSourceStream *source) const
{
AbstractDemuxer *ret = NULL;
switch((unsigned)format)
{
case StreamFormat::MP4:
ret = new Demuxer(p_realdemux, "mp4", fakeesout->getEsOut(), demuxersource);
break;
case StreamFormat::MPEG2TS:
ret = new Demuxer(p_realdemux, "ts", fakeesout->getEsOut(), demuxersource);
ret = AbstractStream::newDemux(p_realdemux, format, out, source);
break;
case StreamFormat::WEBVTT:
ret = new SlaveDemuxer(p_realdemux, "webvtt", fakeesout->getEsOut(), demuxersource);
ret = new SlaveDemuxer(p_realdemux, "webvtt", out, source);
break;
case StreamFormat::TTML:
ret = new SlaveDemuxer(p_realdemux, "ttml", fakeesout->getEsOut(), demuxersource);
ret = new SlaveDemuxer(p_realdemux, "ttml", out, source);
break;
default:
......@@ -61,13 +59,6 @@ AbstractDemuxer * DASHStream::createDemux(const StreamFormat &format)
break;
}
if(ret && !ret->create())
{
delete ret;
ret = NULL;
}
else commandsqueue->Commit();
return ret;
}
......
......@@ -33,7 +33,8 @@ namespace dash
protected:
virtual block_t *checkBlock(block_t *, bool); /* impl */
virtual AbstractDemuxer * createDemux(const StreamFormat &); /* impl */
virtual AbstractDemuxer * newDemux(demux_t *, const StreamFormat &,
es_out_t *, AbstractSourceStream *) const; /* reimpl */
};
class DASHStreamFactory : public AbstractStreamFactory
......
......@@ -67,47 +67,6 @@ void HLSStream::setTimeOffset(mtime_t i_offset)
AbstractStream::setTimeOffset(i_offset);
}
AbstractDemuxer * HLSStream::createDemux(const StreamFormat &format)
{
AbstractDemuxer *ret = NULL;
switch((unsigned)format)
{
case StreamFormat::PACKEDAAC:
ret = new Demuxer(p_realdemux, "aac", fakeesout->getEsOut(), demuxersource);
break;
case StreamFormat::MPEG2TS:
ret = new Demuxer(p_realdemux, "ts", fakeesout->getEsOut(), demuxersource);
if(ret)
ret->setCanDetectSwitches(false); /* HLS and unique PAT/PMT versions */
break;
case StreamFormat::MP4:
ret = new Demuxer(p_realdemux, "mp4", fakeesout->getEsOut(), demuxersource);
break;
case StreamFormat::WEBVTT:
ret = new Demuxer(p_realdemux, "webvttstream", fakeesout->getEsOut(), demuxersource);
if(ret)
ret->setRestartsOnEachSegment(true);
break;
default:
case StreamFormat::UNSUPPORTED:
break;
}
if(ret && !ret->create())
{
delete ret;
ret = NULL;
}
else commandsqueue->Commit();
return ret;
}
int HLSStream::ParseID3PrivTag(const uint8_t *p_payload, size_t i_payload)
{
if(i_payload == 53 &&
......@@ -163,6 +122,39 @@ block_t * HLSStream::checkBlock(block_t *p_block, bool b_first)
return p_block;
}
AbstractDemuxer *HLSStream::newDemux(demux_t *p_realdemux, const StreamFormat &format,
es_out_t *out, AbstractSourceStream *source) const
{
AbstractDemuxer *ret = NULL;
switch((unsigned)format)
{
case StreamFormat::PACKEDAAC:
ret = new Demuxer(p_realdemux, "aac", out, source);
break;
case StreamFormat::MPEG2TS:
ret = new Demuxer(p_realdemux, "ts", out, source);
if(ret)
ret->setCanDetectSwitches(false); /* HLS and unique PAT/PMT versions */
break;
case StreamFormat::MP4:
ret = AbstractStream::newDemux(p_realdemux, format, out, source);
break;
case StreamFormat::WEBVTT:
ret = new Demuxer(p_realdemux, "webvttstream", out, source);
if(ret)
ret->setRestartsOnEachSegment(true);
break;
default:
case StreamFormat::UNSUPPORTED:
break;
}
return ret;
}
AbstractStream * HLSStreamFactory::create(demux_t *realdemux, const StreamFormat &,
SegmentTracker *tracker, AbstractConnectionManager *manager) const
{
......
......@@ -33,9 +33,10 @@ namespace hls
virtual ~HLSStream();
protected:
virtual AbstractDemuxer * createDemux(const StreamFormat &); /* reimpl */
virtual void setTimeOffset(mtime_t); /* reimpl */
virtual block_t *checkBlock(block_t *, bool); /* reimpl */
virtual AbstractDemuxer * newDemux(demux_t *, const StreamFormat &,
es_out_t *, AbstractSourceStream *) const; /* reimpl */
private:
static int ID3TAG_Parse_Handler(uint32_t, const uint8_t *, size_t, void *);
......
......@@ -31,28 +31,12 @@ SmoothStream::SmoothStream(demux_t *demux)
{
}
AbstractDemuxer * SmoothStream::createDemux(const StreamFormat &format)
AbstractDemuxer *SmoothStream::newDemux(demux_t *p_realdemux, const StreamFormat &format,
es_out_t *out, AbstractSourceStream *source) const
{
AbstractDemuxer *ret = NULL;
switch((unsigned)format)
{
case StreamFormat::MP4:
ret = new Demuxer(p_realdemux, "mp4", fakeesout->getEsOut(), demuxersource);
break;
default:
case StreamFormat::UNSUPPORTED:
break;
}
if(ret && !ret->create())
{
delete ret;
ret = NULL;
}
else commandsqueue->Commit();
return ret;
if((unsigned)format != StreamFormat::MP4)
return NULL;
return AbstractStream::newDemux(p_realdemux, format, out, source);
}
block_t * SmoothStream::checkBlock(block_t *p_block, bool)
......
......@@ -32,8 +32,9 @@ namespace smooth
SmoothStream(demux_t *);
protected:
virtual AbstractDemuxer * createDemux(const StreamFormat &); /* impl */
virtual block_t *checkBlock(block_t *, bool) /* impl */;
virtual AbstractDemuxer * newDemux(demux_t *, const StreamFormat &,
es_out_t *, AbstractSourceStream *) const; /* reimpl */
};
class SmoothStreamFactory : public AbstractStreamFactory
......
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