[vlc-commits] demux: adaptive: refactor demux creation with factory interface

Francois Cartegnie git at videolan.org
Wed Feb 21 13:59:03 CET 2018


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Feb 21 12:36:03 2018 +0100| [7bbd00f21e68b640a5a61ac4a8f9a5f0c9ca0827] | committer: Francois Cartegnie

demux: adaptive: refactor demux creation with factory interface

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7bbd00f21e68b640a5a61ac4a8f9a5f0c9ca0827
---

 modules/demux/adaptive/Streams.cpp          | 35 ++++++++++++++
 modules/demux/adaptive/Streams.hpp          |  7 ++-
 modules/demux/adaptive/plumbing/Demuxer.hpp |  6 +++
 modules/demux/dash/DASHStream.cpp           | 19 ++------
 modules/demux/dash/DASHStream.hpp           |  3 +-
 modules/demux/hls/HLSStreams.cpp            | 74 +++++++++++++----------------
 modules/demux/hls/HLSStreams.hpp            |  3 +-
 modules/demux/smooth/SmoothStream.cpp       | 26 ++--------
 modules/demux/smooth/SmoothStream.hpp       |  3 +-
 9 files changed, 95 insertions(+), 81 deletions(-)

diff --git a/modules/demux/adaptive/Streams.cpp b/modules/demux/adaptive/Streams.cpp
index 06756fdd01..6bdd2139ae 100644
--- a/modules/demux/adaptive/Streams.cpp
+++ b/modules/demux/adaptive/Streams.cpp
@@ -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)
diff --git a/modules/demux/adaptive/Streams.hpp b/modules/demux/adaptive/Streams.hpp
index b6c188d081..0e1ca07b4e 100644
--- a/modules/demux/adaptive/Streams.hpp
+++ b/modules/demux/adaptive/Streams.hpp
@@ -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();
 
diff --git a/modules/demux/adaptive/plumbing/Demuxer.hpp b/modules/demux/adaptive/plumbing/Demuxer.hpp
index 3e9b8b9182..15f79d6da9 100644
--- a/modules/demux/adaptive/plumbing/Demuxer.hpp
+++ b/modules/demux/adaptive/plumbing/Demuxer.hpp
@@ -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
diff --git a/modules/demux/dash/DASHStream.cpp b/modules/demux/dash/DASHStream.cpp
index 551ae45612..307178de4d 100644
--- a/modules/demux/dash/DASHStream.cpp
+++ b/modules/demux/dash/DASHStream.cpp
@@ -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;
 }
 
diff --git a/modules/demux/dash/DASHStream.hpp b/modules/demux/dash/DASHStream.hpp
index b8ba6e5961..946615f51b 100644
--- a/modules/demux/dash/DASHStream.hpp
+++ b/modules/demux/dash/DASHStream.hpp
@@ -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
diff --git a/modules/demux/hls/HLSStreams.cpp b/modules/demux/hls/HLSStreams.cpp
index c54c7fee27..3f5d4dccb5 100644
--- a/modules/demux/hls/HLSStreams.cpp
+++ b/modules/demux/hls/HLSStreams.cpp
@@ -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
 {
diff --git a/modules/demux/hls/HLSStreams.hpp b/modules/demux/hls/HLSStreams.hpp
index ab067f71b8..669c54cdfe 100644
--- a/modules/demux/hls/HLSStreams.hpp
+++ b/modules/demux/hls/HLSStreams.hpp
@@ -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 *);
diff --git a/modules/demux/smooth/SmoothStream.cpp b/modules/demux/smooth/SmoothStream.cpp
index 01864c1432..7ebe886c88 100644
--- a/modules/demux/smooth/SmoothStream.cpp
+++ b/modules/demux/smooth/SmoothStream.cpp
@@ -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)
diff --git a/modules/demux/smooth/SmoothStream.hpp b/modules/demux/smooth/SmoothStream.hpp
index d3af79fdb7..69fdfba18d 100644
--- a/modules/demux/smooth/SmoothStream.hpp
+++ b/modules/demux/smooth/SmoothStream.hpp
@@ -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



More information about the vlc-commits mailing list