[vlc-commits] demux: adaptative: encap demuxers in class

Francois Cartegnie git at videolan.org
Wed Sep 23 21:15:09 CEST 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Sep 23 15:21:06 2015 +0200| [7e853c6f06da78fcf424f23020a5cc6589a641ca] | committer: Francois Cartegnie

demux: adaptative: encap demuxers in class

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

 modules/demux/Makefile.am                          |    2 +
 modules/demux/adaptative/plumbing/Demuxer.cpp      |   81 ++++++++++++++++++++
 modules/demux/adaptative/plumbing/Demuxer.hpp      |   61 +++++++++++++++
 modules/demux/adaptative/plumbing/StreamOutput.cpp |   23 +++---
 modules/demux/adaptative/plumbing/StreamOutput.hpp |    3 +-
 5 files changed, 155 insertions(+), 15 deletions(-)

diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index 578ea1d..8fa67c9 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -301,6 +301,8 @@ libadaptative_plugin_la_SOURCES = \
     demux/adaptative/http/Sockets.cpp \
     demux/adaptative/plumbing/CommandsQueue.cpp \
     demux/adaptative/plumbing/CommandsQueue.hpp \
+    demux/adaptative/plumbing/Demuxer.cpp \
+    demux/adaptative/plumbing/Demuxer.hpp \
     demux/adaptative/plumbing/FakeESOut.cpp \
     demux/adaptative/plumbing/FakeESOut.hpp \
     demux/adaptative/plumbing/FakeESOutID.cpp \
diff --git a/modules/demux/adaptative/plumbing/Demuxer.cpp b/modules/demux/adaptative/plumbing/Demuxer.cpp
new file mode 100644
index 0000000..e006890
--- /dev/null
+++ b/modules/demux/adaptative/plumbing/Demuxer.cpp
@@ -0,0 +1,81 @@
+/*
+ * Demuxer.cpp
+ *****************************************************************************
+ * Copyright © 2015 - VideoLAN and VLC Authors
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#include "Demuxer.hpp"
+#include <vlc_stream.h>
+
+using namespace adaptative;
+
+AbstractDemuxer::AbstractDemuxer()
+{
+    b_startsfromzero = false;
+    b_reinitsonseek =true;
+}
+
+AbstractDemuxer::~AbstractDemuxer()
+{
+
+}
+
+bool AbstractDemuxer::alwaysStartsFromZero() const
+{
+    return b_startsfromzero;
+}
+
+bool AbstractDemuxer::reinitsOnSeek() const
+{
+    return b_reinitsonseek;
+}
+
+StreamDemux::StreamDemux(demux_t *p_realdemux_, const std::string &name_, es_out_t *out)
+    : AbstractDemuxer()
+{
+    demuxstream = NULL;
+    p_es_out = out;
+    name = name_;
+    p_realdemux = p_realdemux_;
+
+    restart();
+
+    if(!demuxstream)
+        throw VLC_EGENERIC;
+}
+
+StreamDemux::~StreamDemux()
+{
+    if (demuxstream)
+        stream_Delete(demuxstream);
+}
+
+bool StreamDemux::feed(block_t *p_block, bool)
+{
+    stream_DemuxSend(demuxstream, p_block);
+    return true;
+}
+
+bool StreamDemux::restart()
+{
+    if(demuxstream)
+        stream_Delete(demuxstream);
+
+    demuxstream = stream_DemuxNew(p_realdemux, name.c_str(), p_es_out);
+    if(!demuxstream)
+        return false;
+    return true;
+}
diff --git a/modules/demux/adaptative/plumbing/Demuxer.hpp b/modules/demux/adaptative/plumbing/Demuxer.hpp
new file mode 100644
index 0000000..ff5ee3b
--- /dev/null
+++ b/modules/demux/adaptative/plumbing/Demuxer.hpp
@@ -0,0 +1,61 @@
+/*
+ * Demuxer.hpp
+ *****************************************************************************
+ * Copyright © 2015 - VideoLAN and VLC Authors
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifndef DEMUXER_HPP
+#define DEMUXER_HPP
+
+#include <vlc_common.h>
+#include <string>
+
+namespace adaptative
+{
+
+    class AbstractDemuxer
+    {
+        public:
+            AbstractDemuxer();
+            virtual ~AbstractDemuxer();
+            virtual bool restart() = 0;
+            virtual bool feed(block_t *, bool) = 0;
+            bool alwaysStartsFromZero() const;
+            bool reinitsOnSeek() const;
+
+        protected:
+            bool b_startsfromzero;
+            bool b_reinitsonseek;
+    };
+
+    class StreamDemux : public AbstractDemuxer
+    {
+        public:
+            StreamDemux(demux_t *, const std::string &, es_out_t *);
+            virtual ~StreamDemux();
+            virtual bool restart(); /* impl */
+            virtual bool feed(block_t *, bool); /* impl */
+
+        private:
+            stream_t *demuxstream;
+            demux_t *p_realdemux;
+            std::string name;
+            es_out_t *p_es_out;
+    };
+
+}
+
+#endif // DEMUXER_HPP
diff --git a/modules/demux/adaptative/plumbing/StreamOutput.cpp b/modules/demux/adaptative/plumbing/StreamOutput.cpp
index c19425a..79ff020 100644
--- a/modules/demux/adaptative/plumbing/StreamOutput.cpp
+++ b/modules/demux/adaptative/plumbing/StreamOutput.cpp
@@ -54,7 +54,7 @@ BaseStreamOutput::BaseStreamOutput(demux_t *demux, const StreamFormat &format, c
 {
     this->name = name;
     seekable = true;
-    demuxstream = NULL;
+    demuxer = NULL;
 
     CommandsFactory *factory = new CommandsFactory();
 
@@ -77,15 +77,14 @@ BaseStreamOutput::BaseStreamOutput(demux_t *demux, const StreamFormat &format, c
     }
     fakeesout->setExtraInfoProvider( this );
 
-    demuxstream = stream_DemuxNew(realdemux, name.c_str(), fakeesout->getEsOut());
-    if(!demuxstream)
+    demuxer = new StreamDemux(realdemux, name, fakeesout->getEsOut());
+    if(!demuxer)
         throw VLC_EGENERIC;
 }
 
 BaseStreamOutput::~BaseStreamOutput()
 {
-    if (demuxstream)
-        stream_Delete(demuxstream);
+    delete demuxer;
 
     if(fakeesout)
         delete fakeesout;
@@ -106,15 +105,15 @@ int BaseStreamOutput::esCount() const
     return fakeesout->esCount();
 }
 
-void BaseStreamOutput::pushBlock(block_t *block, bool)
+void BaseStreamOutput::pushBlock(block_t *block, bool b)
 {
-    stream_DemuxSend(demuxstream, block);
+    static_cast<void>(demuxer->feed(block, b));
 }
 
 bool BaseStreamOutput::seekAble() const
 {
     bool b_canswitch = switchAllowed();
-    return (demuxstream && seekable && b_canswitch);
+    return (demuxer && seekable && b_canswitch);
 }
 
 void BaseStreamOutput::setPosition(mtime_t nztime)
@@ -132,16 +131,12 @@ void BaseStreamOutput::setPosition(mtime_t nztime)
 
 bool BaseStreamOutput::restart()
 {
-    stream_Delete(demuxstream);
-    demuxstream = stream_DemuxNew(realdemux, name.c_str(), fakeesout->getEsOut());
-    if(!demuxstream)
-        return false;
-    return true;
+    return demuxer->restart();
 }
 
 bool BaseStreamOutput::reinitsOnSeek() const
 {
-    return true;
+    return demuxer->reinitsOnSeek();
 }
 
 bool BaseStreamOutput::switchAllowed() const
diff --git a/modules/demux/adaptative/plumbing/StreamOutput.hpp b/modules/demux/adaptative/plumbing/StreamOutput.hpp
index 97d22ef..f3df128 100644
--- a/modules/demux/adaptative/plumbing/StreamOutput.hpp
+++ b/modules/demux/adaptative/plumbing/StreamOutput.hpp
@@ -30,6 +30,7 @@
 #include <vlc_es.h>
 #include "../StreamFormat.hpp"
 #include "FakeESOut.hpp"
+#include "Demuxer.hpp"
 
 namespace adaptative
 {
@@ -97,7 +98,7 @@ namespace adaptative
 
     protected:
         FakeESOut *fakeesout; /* to intercept/proxy what is sent from demuxstream */
-        stream_t *demuxstream;
+        AbstractDemuxer *demuxer;
         bool      seekable;
         std::string name;
 



More information about the vlc-commits mailing list