[vlc-commits] stream_filter: dash: add MP4 atoms reader

Francois Cartegnie git at videolan.org
Thu Dec 18 22:39:52 CET 2014


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Nov 23 12:46:23 2014 +0100| [8853765534bd0fd315ecf000562724dbfc8f7517] | committer: Francois Cartegnie

stream_filter: dash: add MP4 atoms reader

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

 modules/stream_filter/Makefile.am              |   10 ++-
 modules/stream_filter/dash/Streams.hpp         |   10 +++
 modules/stream_filter/dash/mp4/AtomsReader.cpp |   84 ++++++++++++++++++++++++
 modules/stream_filter/dash/mp4/AtomsReader.hpp |   52 +++++++++++++++
 modules/stream_filter/dash/mpd/Segment.cpp     |    2 +
 5 files changed, 157 insertions(+), 1 deletion(-)

diff --git a/modules/stream_filter/Makefile.am b/modules/stream_filter/Makefile.am
index fff34fb..ebc3137 100644
--- a/modules/stream_filter/Makefile.am
+++ b/modules/stream_filter/Makefile.am
@@ -84,6 +84,8 @@ libdash_plugin_la_SOURCES = \
     stream_filter/dash/mpd/SegmentTimeline.h \
     stream_filter/dash/mpd/TrickModeType.cpp \
     stream_filter/dash/mpd/TrickModeType.h \
+    stream_filter/dash/mp4/AtomsReader.cpp \
+    stream_filter/dash/mp4/AtomsReader.hpp \
     stream_filter/dash/xml/DOMHelper.cpp \
     stream_filter/dash/xml/DOMHelper.h \
     stream_filter/dash/xml/DOMParser.cpp \
@@ -98,8 +100,14 @@ libdash_plugin_la_SOURCES = \
     stream_filter/dash/DASHManager.h \
     stream_filter/dash/Helper.cpp \
     stream_filter/dash/Helper.h
+
+libdash_plugin_la_SOURCES += demux/mp4/libmp4.c demux/mp4/libmp4.h
+
 libdash_plugin_la_CXXFLAGS = $(AM_CFLAGS) -I$(srcdir)/stream_filter/dash
-libdash_plugin_la_LIBADD = $(SOCKET_LIBS)
+libdash_plugin_la_LIBADD = $(SOCKET_LIBS) $(LIBM)
+if HAVE_ZLIB
+libdash_plugin_la_LIBADD += -lz
+endif
 stream_filter_LTLIBRARIES += libdash_plugin.la
 
 libsmooth_plugin_la_SOURCES = \
diff --git a/modules/stream_filter/dash/Streams.hpp b/modules/stream_filter/dash/Streams.hpp
new file mode 100644
index 0000000..2aebce9
--- /dev/null
+++ b/modules/stream_filter/dash/Streams.hpp
@@ -0,0 +1,10 @@
+#ifndef STREAM_HPP
+#define STREAM_HPP
+
+class Stream
+{
+public:
+    Stream();
+};
+
+#endif // STREAM_HPP
diff --git a/modules/stream_filter/dash/mp4/AtomsReader.cpp b/modules/stream_filter/dash/mp4/AtomsReader.cpp
new file mode 100644
index 0000000..1a04671
--- /dev/null
+++ b/modules/stream_filter/dash/mp4/AtomsReader.cpp
@@ -0,0 +1,84 @@
+/*
+ * AtomsReader.cpp
+ *****************************************************************************
+ * Copyright (C) 2014 - VideoLAN 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 "AtomsReader.hpp"
+#include "mpd/Representation.h"
+#include "mpd/MPD.h"
+
+using namespace dash::mp4;
+using namespace dash::mpd;
+
+AtomsReader::AtomsReader(ISegment *segment_)
+{
+    segment = segment_;
+    rootbox = NULL;
+}
+
+AtomsReader::~AtomsReader()
+{
+    vlc_object_t *object = segment->getRepresentation()->getMPD()->getVLCObject();
+    while(rootbox && rootbox->p_first)
+    {
+        MP4_Box_t *p_next = rootbox->p_first->p_next;
+        MP4_BoxFree( (stream_t *)object, rootbox->p_first );
+        rootbox->p_first = p_next;
+    }
+    delete rootbox;
+}
+
+bool AtomsReader::parseBlock(void *buffer, size_t size)
+{
+    if(!segment->getRepresentation())
+        return false;
+    vlc_object_t *object = segment->getRepresentation()->getMPD()->getVLCObject();
+    stream_t *stream = stream_MemoryNew( object, (uint8_t *)buffer, size, true);
+    if (stream)
+    {
+        rootbox = new MP4_Box_t;
+        if(!rootbox)
+        {
+            stream_Delete(stream);
+            return false;
+        }
+        memset(rootbox, 0, sizeof(*rootbox));
+        rootbox->i_type = ATOM_root;
+        rootbox->i_size = size;
+        if ( MP4_ReadBoxContainerChildren( stream, rootbox, 0 ) == 1 )
+        {
+#ifndef NDEBUG
+            MP4_BoxDumpStructure(stream, rootbox);
+#endif
+            MP4_Box_t *sidxbox = MP4_BoxGet(rootbox, "sidx");
+            if (sidxbox)
+            {
+                MP4_Box_data_sidx_t *sidx = sidxbox->data.p_sidx;
+                size_t offset = sidx->i_first_offset;
+                for(uint16_t i=0; i<sidx->i_reference_count; i++)
+                {
+                    std::cerr << " offset " << offset << std::endl;
+                    offset += sidx->p_items[i].i_referenced_size;
+                }
+            }
+            std::cerr << "index seg " << ((uint8_t *)buffer)[4] << ((uint8_t *)buffer)[5] << std::endl;
+        }
+        stream_Delete(stream);
+    }
+
+    return true;
+}
diff --git a/modules/stream_filter/dash/mp4/AtomsReader.hpp b/modules/stream_filter/dash/mp4/AtomsReader.hpp
new file mode 100644
index 0000000..6114393
--- /dev/null
+++ b/modules/stream_filter/dash/mp4/AtomsReader.hpp
@@ -0,0 +1,52 @@
+/*
+ * AtomsReader.hpp
+ *****************************************************************************
+ * Copyright (C) 2014 - VideoLAN 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 ATOMSREADER_HPP
+#define ATOMSREADER_HPP
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "mpd/Segment.h"
+#include <vlc_common.h>
+#include <vlc_stream.h>
+extern "C" {
+#include "../../demux/mp4/libmp4.h"
+}
+
+namespace dash
+{
+    namespace mp4
+    {
+        class AtomsReader
+        {
+            public:
+                AtomsReader(dash::mpd::ISegment *);
+                ~AtomsReader();
+                bool parseBlock(void *, size_t);
+
+            protected:
+                dash::mpd::ISegment *segment;
+                MP4_Box_t *rootbox;
+        };
+    }
+}
+
+#endif // ATOMSREADER_HPP
diff --git a/modules/stream_filter/dash/mpd/Segment.cpp b/modules/stream_filter/dash/mpd/Segment.cpp
index 1dc20e8..2228624 100644
--- a/modules/stream_filter/dash/mpd/Segment.cpp
+++ b/modules/stream_filter/dash/mpd/Segment.cpp
@@ -27,6 +27,8 @@
 
 #include "Segment.h"
 #include "Representation.h"
+#include "MPD.h"
+#include "mp4/AtomsReader.hpp"
 
 #include <cassert>
 



More information about the vlc-commits mailing list