[vlc-commits] demux: adaptative: refactor atoms reader

Francois Cartegnie git at videolan.org
Fri Oct 30 21:19:40 CET 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Oct 30 12:39:26 2015 +0100| [d84d78033334c09fd773c9a7551bda5505e65a53] | committer: Francois Cartegnie

demux: adaptative: refactor atoms reader

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

 modules/demux/Makefile.am                          |    6 +-
 .../demux/{dash => adaptative}/mp4/AtomsReader.cpp |   35 ++++--------
 .../demux/{dash => adaptative}/mp4/AtomsReader.hpp |   11 +---
 modules/demux/dash/mp4/IndexReader.cpp             |   58 ++++++++++++++++++++
 modules/demux/dash/mp4/IndexReader.hpp             |   49 +++++++++++++++++
 modules/demux/dash/mpd/DASHSegment.cpp             |    6 +-
 6 files changed, 126 insertions(+), 39 deletions(-)

diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index 5ea22b2..1dec223 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -292,6 +292,8 @@ libadaptative_plugin_la_SOURCES = \
     demux/adaptative/logic/RateBasedAdaptationLogic.cpp \
     demux/adaptative/logic/Representationselectors.hpp \
     demux/adaptative/logic/Representationselectors.cpp \
+    demux/adaptative/mp4/AtomsReader.cpp \
+    demux/adaptative/mp4/AtomsReader.hpp \
     demux/adaptative/http/BytesRange.cpp \
     demux/adaptative/http/BytesRange.hpp \
     demux/adaptative/http/Chunk.cpp \
@@ -362,8 +364,8 @@ libadaptative_dash_SOURCES = \
     demux/dash/mpd/Representation.h \
     demux/dash/mpd/TrickModeType.cpp \
     demux/dash/mpd/TrickModeType.h \
-    demux/dash/mp4/AtomsReader.cpp \
-    demux/dash/mp4/AtomsReader.hpp \
+    demux/dash/mp4/IndexReader.cpp \
+    demux/dash/mp4/IndexReader.hpp \
     demux/dash/DASHManager.cpp \
     demux/dash/DASHManager.h \
     demux/dash/DASHStream.cpp \
diff --git a/modules/demux/dash/mp4/AtomsReader.cpp b/modules/demux/adaptative/mp4/AtomsReader.cpp
similarity index 64%
rename from modules/demux/dash/mp4/AtomsReader.cpp
rename to modules/demux/adaptative/mp4/AtomsReader.cpp
index 044962d..e2f357f 100644
--- a/modules/demux/dash/mp4/AtomsReader.cpp
+++ b/modules/demux/adaptative/mp4/AtomsReader.cpp
@@ -18,11 +18,8 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 #include "AtomsReader.hpp"
-#include "../mpd/Representation.h"
-#include "../mpd/MPD.h"
 
-using namespace dash::mp4;
-using namespace dash::mpd;
+using namespace adaptative::mp4;
 
 AtomsReader::AtomsReader(vlc_object_t *object_)
 {
@@ -32,6 +29,11 @@ AtomsReader::AtomsReader(vlc_object_t *object_)
 
 AtomsReader::~AtomsReader()
 {
+    clean();
+}
+
+void AtomsReader::clean()
+{
     while(rootbox && rootbox->p_first)
     {
         MP4_Box_t *p_next = rootbox->p_first->p_next;
@@ -39,12 +41,13 @@ AtomsReader::~AtomsReader()
         rootbox->p_first = p_next;
     }
     delete rootbox;
+    rootbox = NULL;
 }
 
-bool AtomsReader::parseBlock(block_t *p_block, BaseRepresentation *rep)
+bool AtomsReader::parseBlock(block_t *p_block)
 {
-    if(!rep)
-        return false;
+    if(rootbox)
+        clean();
 
     stream_t *stream = stream_MemoryNew( object, p_block->p_buffer, p_block->i_buffer, true);
     if (stream)
@@ -63,24 +66,6 @@ bool AtomsReader::parseBlock(block_t *p_block, BaseRepresentation *rep)
 #ifndef NDEBUG
             MP4_BoxDumpStructure(stream, rootbox);
 #endif
-            MP4_Box_t *sidxbox = MP4_BoxGet(rootbox, "sidx");
-            if (sidxbox)
-            {
-                Representation::SplitPoint point;
-                std::vector<Representation::SplitPoint> splitlist;
-                MP4_Box_data_sidx_t *sidx = sidxbox->data.p_sidx;
-                point.offset = sidx->i_first_offset;
-                point.time = 0;
-                for(uint16_t i=0; i<sidx->i_reference_count && sidx->i_timescale; i++)
-                {
-                    splitlist.push_back(point);
-                    point.offset += sidx->p_items[i].i_referenced_size;
-                    point.time += CLOCK_FREQ * sidx->p_items[i].i_subsegment_duration /
-                                  sidx->i_timescale;
-                }
-                rep->SplitUsingIndex(splitlist);
-                rep->getPlaylist()->debug();
-            }
         }
         stream_Delete(stream);
     }
diff --git a/modules/demux/dash/mp4/AtomsReader.hpp b/modules/demux/adaptative/mp4/AtomsReader.hpp
similarity index 89%
rename from modules/demux/dash/mp4/AtomsReader.hpp
rename to modules/demux/adaptative/mp4/AtomsReader.hpp
index 9254075..376e58a 100644
--- a/modules/demux/dash/mp4/AtomsReader.hpp
+++ b/modules/demux/adaptative/mp4/AtomsReader.hpp
@@ -32,14 +32,6 @@ extern "C" {
 
 namespace adaptative
 {
-    namespace playlist
-    {
-        class BaseRepresentation;
-    }
-}
-
-namespace dash
-{
     namespace mp4
     {
         class AtomsReader
@@ -47,7 +39,8 @@ namespace dash
             public:
                 AtomsReader(vlc_object_t *);
                 ~AtomsReader();
-                bool parseBlock(block_t *, adaptative::playlist::BaseRepresentation *);
+                void clean();
+                bool parseBlock(block_t *);
 
             protected:
                 vlc_object_t *object;
diff --git a/modules/demux/dash/mp4/IndexReader.cpp b/modules/demux/dash/mp4/IndexReader.cpp
new file mode 100644
index 0000000..e691d9c
--- /dev/null
+++ b/modules/demux/dash/mp4/IndexReader.cpp
@@ -0,0 +1,58 @@
+/*
+ * IndexReader.cpp
+ *****************************************************************************
+ * Copyright (C) 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 "IndexReader.hpp"
+#include "../mpd/Representation.h"
+#include "../mpd/MPD.h"
+
+using namespace adaptative::mp4;
+using namespace dash::mp4;
+using namespace dash::mpd;
+
+IndexReader::IndexReader(vlc_object_t *obj)
+    : AtomsReader(obj)
+{
+}
+
+bool IndexReader::parseIndex(block_t *p_block, BaseRepresentation *rep)
+{
+    if(!rep || !parseBlock(p_block))
+        return false;
+
+    MP4_Box_t *sidxbox = MP4_BoxGet(rootbox, "sidx");
+    if (sidxbox)
+    {
+        Representation::SplitPoint point;
+        std::vector<Representation::SplitPoint> splitlist;
+        MP4_Box_data_sidx_t *sidx = sidxbox->data.p_sidx;
+        point.offset = sidx->i_first_offset;
+        point.time = 0;
+        for(uint16_t i=0; i<sidx->i_reference_count && sidx->i_timescale; i++)
+        {
+            splitlist.push_back(point);
+            point.offset += sidx->p_items[i].i_referenced_size;
+            point.time += CLOCK_FREQ * sidx->p_items[i].i_subsegment_duration /
+                    sidx->i_timescale;
+        }
+        rep->SplitUsingIndex(splitlist);
+        rep->getPlaylist()->debug();
+    }
+
+    return true;
+}
diff --git a/modules/demux/dash/mp4/IndexReader.hpp b/modules/demux/dash/mp4/IndexReader.hpp
new file mode 100644
index 0000000..2178057
--- /dev/null
+++ b/modules/demux/dash/mp4/IndexReader.hpp
@@ -0,0 +1,49 @@
+/*
+ * IndexReader.hpp
+ *****************************************************************************
+ * Copyright (C) 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 INDEXREADER_HPP
+#define INDEXREADER_HPP
+
+#include "../adaptative/mp4/AtomsReader.hpp"
+
+namespace adaptative
+{
+    namespace playlist
+    {
+        class BaseRepresentation;
+    }
+}
+
+namespace dash
+{
+    namespace mp4
+    {
+        using namespace adaptative::mp4;
+        using namespace adaptative::playlist;
+
+        class IndexReader : public AtomsReader
+        {
+            public:
+                IndexReader(vlc_object_t *);
+                bool parseIndex(block_t *, BaseRepresentation *);
+        };
+    }
+}
+
+#endif // INDEXREADER_HPP
diff --git a/modules/demux/dash/mpd/DASHSegment.cpp b/modules/demux/dash/mpd/DASHSegment.cpp
index 4c8c095..f4f2b9f 100644
--- a/modules/demux/dash/mpd/DASHSegment.cpp
+++ b/modules/demux/dash/mpd/DASHSegment.cpp
@@ -28,7 +28,7 @@
 
 #include "DASHSegment.h"
 #include "../adaptative/playlist/BaseRepresentation.h"
-#include "../mp4/AtomsReader.hpp"
+#include "../mp4/IndexReader.hpp"
 #include "../adaptative/playlist/AbstractPlaylist.hpp"
 #include "../adaptative/playlist/SegmentChunk.hpp"
 
@@ -46,6 +46,6 @@ void DashIndexSegment::onChunkDownload(block_t **pp_block, SegmentChunk *, BaseR
     if(!rep)
         return;
 
-    AtomsReader br(rep->getPlaylist()->getVLCObject());
-    br.parseBlock(*pp_block, rep);
+    IndexReader br(rep->getPlaylist()->getVLCObject());
+    br.parseIndex(*pp_block, rep);
 }



More information about the vlc-commits mailing list