[vlc-commits] demux: adaptive: simplify streams with unique init method
Francois Cartegnie
git at videolan.org
Sat Jul 9 18:42:43 CEST 2016
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Jul 5 18:02:23 2016 +0200| [50541d217faa22bc0df9b3cbab15d4d15131ce2a] | committer: Francois Cartegnie
demux: adaptive: simplify streams with unique init method
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=50541d217faa22bc0df9b3cbab15d4d15131ce2a
---
modules/demux/adaptive/Streams.cpp | 72 ++++++++++++++++-----------------
modules/demux/adaptive/Streams.hpp | 4 +-
modules/demux/dash/DASHStream.cpp | 12 +++---
modules/demux/dash/DASHStream.hpp | 2 +-
modules/demux/hls/HLSStreams.cpp | 12 +++---
modules/demux/hls/HLSStreams.hpp | 2 +-
modules/demux/smooth/SmoothStream.cpp | 12 +++---
modules/demux/smooth/SmoothStream.hpp | 2 +-
8 files changed, 56 insertions(+), 62 deletions(-)
diff --git a/modules/demux/adaptive/Streams.cpp b/modules/demux/adaptive/Streams.cpp
index 6b85787..c0f8a4a 100644
--- a/modules/demux/adaptive/Streams.cpp
+++ b/modules/demux/adaptive/Streams.cpp
@@ -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)
diff --git a/modules/demux/adaptive/Streams.hpp b/modules/demux/adaptive/Streams.hpp
index 418c9f7..910f409 100644
--- a/modules/demux/adaptive/Streams.hpp
+++ b/modules/demux/adaptive/Streams.hpp
@@ -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 &);
diff --git a/modules/demux/dash/DASHStream.cpp b/modules/demux/dash/DASHStream.cpp
index 0ee39e3..5da17fd 100644
--- a/modules/demux/dash/DASHStream.cpp
+++ b/modules/demux/dash/DASHStream.cpp
@@ -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;
}
diff --git a/modules/demux/dash/DASHStream.hpp b/modules/demux/dash/DASHStream.hpp
index e9d169e..2831151 100644
--- a/modules/demux/dash/DASHStream.hpp
+++ b/modules/demux/dash/DASHStream.hpp
@@ -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 */
diff --git a/modules/demux/hls/HLSStreams.cpp b/modules/demux/hls/HLSStreams.cpp
index cfeb7d2..9a9e19e 100644
--- a/modules/demux/hls/HLSStreams.cpp
+++ b/modules/demux/hls/HLSStreams.cpp
@@ -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;
}
diff --git a/modules/demux/hls/HLSStreams.hpp b/modules/demux/hls/HLSStreams.hpp
index 2038a0d..5f6c3ba 100644
--- a/modules/demux/hls/HLSStreams.hpp
+++ b/modules/demux/hls/HLSStreams.hpp
@@ -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:
diff --git a/modules/demux/smooth/SmoothStream.cpp b/modules/demux/smooth/SmoothStream.cpp
index d3cbdbd..89029e7 100644
--- a/modules/demux/smooth/SmoothStream.cpp
+++ b/modules/demux/smooth/SmoothStream.cpp
@@ -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;
}
diff --git a/modules/demux/smooth/SmoothStream.hpp b/modules/demux/smooth/SmoothStream.hpp
index 07e95df..33ca4b4 100644
--- a/modules/demux/smooth/SmoothStream.hpp
+++ b/modules/demux/smooth/SmoothStream.hpp
@@ -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 */
More information about the vlc-commits
mailing list