[vlc-commits] demux: adaptative: add stream factory

Francois Cartegnie git at videolan.org
Wed Jun 10 18:58:04 CEST 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu May 21 00:16:16 2015 +0200| [0e9444523a6ec1b1f1364ec7884470d9d7d30d0a] | committer: Francois Cartegnie

demux: adaptative: add stream factory

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

 modules/demux/adaptative/PlaylistManager.cpp |    5 +++-
 modules/demux/adaptative/PlaylistManager.h   |    4 +++
 modules/demux/adaptative/Streams.cpp         |   34 ++++++++++++++++----------
 modules/demux/adaptative/Streams.hpp         |   16 +++++++++++-
 4 files changed, 44 insertions(+), 15 deletions(-)

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



More information about the vlc-commits mailing list