demux: dash: move everything under demux/
authorFrancois Cartegnie <fcvlcdev@free.fr>
Fri, 26 Dec 2014 17:35:30 +0000 (18:35 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Fri, 26 Dec 2014 18:28:43 +0000 (19:28 +0100)
185 files changed:
modules/demux/Makefile.am
modules/demux/dash/DASHManager.cpp [new file with mode: 0644]
modules/demux/dash/DASHManager.h [new file with mode: 0644]
modules/demux/dash/Helper.cpp [new file with mode: 0644]
modules/demux/dash/Helper.h [new file with mode: 0644]
modules/demux/dash/Properties.hpp [new file with mode: 0644]
modules/demux/dash/Streams.cpp [new file with mode: 0644]
modules/demux/dash/Streams.hpp [new file with mode: 0644]
modules/demux/dash/StreamsType.hpp [new file with mode: 0644]
modules/demux/dash/adaptationlogic/AbstractAdaptationLogic.cpp [new file with mode: 0644]
modules/demux/dash/adaptationlogic/AbstractAdaptationLogic.h [new file with mode: 0644]
modules/demux/dash/adaptationlogic/AdaptationLogicFactory.cpp [new file with mode: 0644]
modules/demux/dash/adaptationlogic/AdaptationLogicFactory.h [new file with mode: 0644]
modules/demux/dash/adaptationlogic/AlwaysBestAdaptationLogic.cpp [new file with mode: 0644]
modules/demux/dash/adaptationlogic/AlwaysBestAdaptationLogic.h [new file with mode: 0644]
modules/demux/dash/adaptationlogic/AlwaysLowestAdaptationLogic.cpp [new file with mode: 0644]
modules/demux/dash/adaptationlogic/AlwaysLowestAdaptationLogic.hpp [new file with mode: 0644]
modules/demux/dash/adaptationlogic/IAdaptationLogic.h [new file with mode: 0644]
modules/demux/dash/adaptationlogic/IDownloadRateObserver.h [new file with mode: 0644]
modules/demux/dash/adaptationlogic/RateBasedAdaptationLogic.cpp [new file with mode: 0644]
modules/demux/dash/adaptationlogic/RateBasedAdaptationLogic.h [new file with mode: 0644]
modules/demux/dash/adaptationlogic/Representationselectors.cpp [new file with mode: 0644]
modules/demux/dash/adaptationlogic/Representationselectors.hpp [new file with mode: 0644]
modules/demux/dash/buffer/BlockBuffer.cpp [new file with mode: 0644]
modules/demux/dash/buffer/BlockBuffer.h [new file with mode: 0644]
modules/demux/dash/buffer/IBufferObserver.h [new file with mode: 0644]
modules/demux/dash/dash.cpp [new file with mode: 0644]
modules/demux/dash/dash.hpp [new file with mode: 0644]
modules/demux/dash/http/Chunk.cpp [new file with mode: 0644]
modules/demux/dash/http/Chunk.h [new file with mode: 0644]
modules/demux/dash/http/HTTPConnection.cpp [new file with mode: 0644]
modules/demux/dash/http/HTTPConnection.h [new file with mode: 0644]
modules/demux/dash/http/HTTPConnectionManager.cpp [new file with mode: 0644]
modules/demux/dash/http/HTTPConnectionManager.h [new file with mode: 0644]
modules/demux/dash/http/IHTTPConnection.cpp [new file with mode: 0644]
modules/demux/dash/http/IHTTPConnection.h [new file with mode: 0644]
modules/demux/dash/http/PersistentConnection.cpp [new file with mode: 0644]
modules/demux/dash/http/PersistentConnection.h [new file with mode: 0644]
modules/demux/dash/mp4/AtomsReader.cpp [new file with mode: 0644]
modules/demux/dash/mp4/AtomsReader.hpp [new file with mode: 0644]
modules/demux/dash/mpd/AdaptationSet.cpp [new file with mode: 0644]
modules/demux/dash/mpd/AdaptationSet.h [new file with mode: 0644]
modules/demux/dash/mpd/BaseUrl.h [new file with mode: 0644]
modules/demux/dash/mpd/CommonAttributesElements.cpp [new file with mode: 0644]
modules/demux/dash/mpd/CommonAttributesElements.h [new file with mode: 0644]
modules/demux/dash/mpd/ContentDescription.cpp [new file with mode: 0644]
modules/demux/dash/mpd/ContentDescription.h [new file with mode: 0644]
modules/demux/dash/mpd/ICanonicalUrl.hpp [new file with mode: 0644]
modules/demux/dash/mpd/IMPDParser.cpp [new file with mode: 0644]
modules/demux/dash/mpd/IMPDParser.h [new file with mode: 0644]
modules/demux/dash/mpd/IsoffMainParser.cpp [new file with mode: 0644]
modules/demux/dash/mpd/IsoffMainParser.h [new file with mode: 0644]
modules/demux/dash/mpd/MPD.cpp [new file with mode: 0644]
modules/demux/dash/mpd/MPD.h [new file with mode: 0644]
modules/demux/dash/mpd/MPDFactory.cpp [new file with mode: 0644]
modules/demux/dash/mpd/MPDFactory.h [new file with mode: 0644]
modules/demux/dash/mpd/Period.cpp [new file with mode: 0644]
modules/demux/dash/mpd/Period.h [new file with mode: 0644]
modules/demux/dash/mpd/Profile.cpp [new file with mode: 0644]
modules/demux/dash/mpd/Profile.hpp [new file with mode: 0644]
modules/demux/dash/mpd/ProgramInformation.cpp [new file with mode: 0644]
modules/demux/dash/mpd/ProgramInformation.h [new file with mode: 0644]
modules/demux/dash/mpd/Representation.cpp [new file with mode: 0644]
modules/demux/dash/mpd/Representation.h [new file with mode: 0644]
modules/demux/dash/mpd/Segment.cpp [new file with mode: 0644]
modules/demux/dash/mpd/Segment.h [new file with mode: 0644]
modules/demux/dash/mpd/SegmentBase.cpp [new file with mode: 0644]
modules/demux/dash/mpd/SegmentBase.h [new file with mode: 0644]
modules/demux/dash/mpd/SegmentInfo.cpp [new file with mode: 0644]
modules/demux/dash/mpd/SegmentInfo.h [new file with mode: 0644]
modules/demux/dash/mpd/SegmentInfoCommon.cpp [new file with mode: 0644]
modules/demux/dash/mpd/SegmentInfoCommon.h [new file with mode: 0644]
modules/demux/dash/mpd/SegmentInfoDefault.cpp [new file with mode: 0644]
modules/demux/dash/mpd/SegmentInfoDefault.h [new file with mode: 0644]
modules/demux/dash/mpd/SegmentInformation.cpp [new file with mode: 0644]
modules/demux/dash/mpd/SegmentInformation.hpp [new file with mode: 0644]
modules/demux/dash/mpd/SegmentList.cpp [new file with mode: 0644]
modules/demux/dash/mpd/SegmentList.h [new file with mode: 0644]
modules/demux/dash/mpd/SegmentTemplate.cpp [new file with mode: 0644]
modules/demux/dash/mpd/SegmentTemplate.h [new file with mode: 0644]
modules/demux/dash/mpd/SegmentTimeline.cpp [new file with mode: 0644]
modules/demux/dash/mpd/SegmentTimeline.h [new file with mode: 0644]
modules/demux/dash/mpd/TrickModeType.cpp [new file with mode: 0644]
modules/demux/dash/mpd/TrickModeType.h [new file with mode: 0644]
modules/demux/dash/mpd/Url.cpp [new file with mode: 0644]
modules/demux/dash/mpd/Url.hpp [new file with mode: 0644]
modules/demux/dash/xml/DOMHelper.cpp [new file with mode: 0644]
modules/demux/dash/xml/DOMHelper.h [new file with mode: 0644]
modules/demux/dash/xml/DOMParser.cpp [new file with mode: 0644]
modules/demux/dash/xml/DOMParser.h [new file with mode: 0644]
modules/demux/dash/xml/Node.cpp [new file with mode: 0644]
modules/demux/dash/xml/Node.h [new file with mode: 0644]
modules/stream_filter/Makefile.am
modules/stream_filter/dash/DASHManager.cpp [deleted file]
modules/stream_filter/dash/DASHManager.h [deleted file]
modules/stream_filter/dash/Helper.cpp [deleted file]
modules/stream_filter/dash/Helper.h [deleted file]
modules/stream_filter/dash/Properties.hpp [deleted file]
modules/stream_filter/dash/Streams.cpp [deleted file]
modules/stream_filter/dash/Streams.hpp [deleted file]
modules/stream_filter/dash/StreamsType.hpp [deleted file]
modules/stream_filter/dash/adaptationlogic/AbstractAdaptationLogic.cpp [deleted file]
modules/stream_filter/dash/adaptationlogic/AbstractAdaptationLogic.h [deleted file]
modules/stream_filter/dash/adaptationlogic/AdaptationLogicFactory.cpp [deleted file]
modules/stream_filter/dash/adaptationlogic/AdaptationLogicFactory.h [deleted file]
modules/stream_filter/dash/adaptationlogic/AlwaysBestAdaptationLogic.cpp [deleted file]
modules/stream_filter/dash/adaptationlogic/AlwaysBestAdaptationLogic.h [deleted file]
modules/stream_filter/dash/adaptationlogic/AlwaysLowestAdaptationLogic.cpp [deleted file]
modules/stream_filter/dash/adaptationlogic/AlwaysLowestAdaptationLogic.hpp [deleted file]
modules/stream_filter/dash/adaptationlogic/IAdaptationLogic.h [deleted file]
modules/stream_filter/dash/adaptationlogic/IDownloadRateObserver.h [deleted file]
modules/stream_filter/dash/adaptationlogic/RateBasedAdaptationLogic.cpp [deleted file]
modules/stream_filter/dash/adaptationlogic/RateBasedAdaptationLogic.h [deleted file]
modules/stream_filter/dash/adaptationlogic/Representationselectors.cpp [deleted file]
modules/stream_filter/dash/adaptationlogic/Representationselectors.hpp [deleted file]
modules/stream_filter/dash/buffer/BlockBuffer.cpp [deleted file]
modules/stream_filter/dash/buffer/BlockBuffer.h [deleted file]
modules/stream_filter/dash/buffer/IBufferObserver.h [deleted file]
modules/stream_filter/dash/dash.cpp [deleted file]
modules/stream_filter/dash/dash.hpp [deleted file]
modules/stream_filter/dash/http/Chunk.cpp [deleted file]
modules/stream_filter/dash/http/Chunk.h [deleted file]
modules/stream_filter/dash/http/HTTPConnection.cpp [deleted file]
modules/stream_filter/dash/http/HTTPConnection.h [deleted file]
modules/stream_filter/dash/http/HTTPConnectionManager.cpp [deleted file]
modules/stream_filter/dash/http/HTTPConnectionManager.h [deleted file]
modules/stream_filter/dash/http/IHTTPConnection.cpp [deleted file]
modules/stream_filter/dash/http/IHTTPConnection.h [deleted file]
modules/stream_filter/dash/http/PersistentConnection.cpp [deleted file]
modules/stream_filter/dash/http/PersistentConnection.h [deleted file]
modules/stream_filter/dash/mp4/AtomsReader.cpp [deleted file]
modules/stream_filter/dash/mp4/AtomsReader.hpp [deleted file]
modules/stream_filter/dash/mpd/AdaptationSet.cpp [deleted file]
modules/stream_filter/dash/mpd/AdaptationSet.h [deleted file]
modules/stream_filter/dash/mpd/BaseUrl.h [deleted file]
modules/stream_filter/dash/mpd/CommonAttributesElements.cpp [deleted file]
modules/stream_filter/dash/mpd/CommonAttributesElements.h [deleted file]
modules/stream_filter/dash/mpd/ContentDescription.cpp [deleted file]
modules/stream_filter/dash/mpd/ContentDescription.h [deleted file]
modules/stream_filter/dash/mpd/ICanonicalUrl.hpp [deleted file]
modules/stream_filter/dash/mpd/IMPDParser.cpp [deleted file]
modules/stream_filter/dash/mpd/IMPDParser.h [deleted file]
modules/stream_filter/dash/mpd/IsoffMainParser.cpp [deleted file]
modules/stream_filter/dash/mpd/IsoffMainParser.h [deleted file]
modules/stream_filter/dash/mpd/MPD.cpp [deleted file]
modules/stream_filter/dash/mpd/MPD.h [deleted file]
modules/stream_filter/dash/mpd/MPDFactory.cpp [deleted file]
modules/stream_filter/dash/mpd/MPDFactory.h [deleted file]
modules/stream_filter/dash/mpd/Period.cpp [deleted file]
modules/stream_filter/dash/mpd/Period.h [deleted file]
modules/stream_filter/dash/mpd/Profile.cpp [deleted file]
modules/stream_filter/dash/mpd/Profile.hpp [deleted file]
modules/stream_filter/dash/mpd/ProgramInformation.cpp [deleted file]
modules/stream_filter/dash/mpd/ProgramInformation.h [deleted file]
modules/stream_filter/dash/mpd/Representation.cpp [deleted file]
modules/stream_filter/dash/mpd/Representation.h [deleted file]
modules/stream_filter/dash/mpd/Segment.cpp [deleted file]
modules/stream_filter/dash/mpd/Segment.h [deleted file]
modules/stream_filter/dash/mpd/SegmentBase.cpp [deleted file]
modules/stream_filter/dash/mpd/SegmentBase.h [deleted file]
modules/stream_filter/dash/mpd/SegmentInfo.cpp [deleted file]
modules/stream_filter/dash/mpd/SegmentInfo.h [deleted file]
modules/stream_filter/dash/mpd/SegmentInfoCommon.cpp [deleted file]
modules/stream_filter/dash/mpd/SegmentInfoCommon.h [deleted file]
modules/stream_filter/dash/mpd/SegmentInfoDefault.cpp [deleted file]
modules/stream_filter/dash/mpd/SegmentInfoDefault.h [deleted file]
modules/stream_filter/dash/mpd/SegmentInformation.cpp [deleted file]
modules/stream_filter/dash/mpd/SegmentInformation.hpp [deleted file]
modules/stream_filter/dash/mpd/SegmentList.cpp [deleted file]
modules/stream_filter/dash/mpd/SegmentList.h [deleted file]
modules/stream_filter/dash/mpd/SegmentTemplate.cpp [deleted file]
modules/stream_filter/dash/mpd/SegmentTemplate.h [deleted file]
modules/stream_filter/dash/mpd/SegmentTimeline.cpp [deleted file]
modules/stream_filter/dash/mpd/SegmentTimeline.h [deleted file]
modules/stream_filter/dash/mpd/TrickModeType.cpp [deleted file]
modules/stream_filter/dash/mpd/TrickModeType.h [deleted file]
modules/stream_filter/dash/mpd/Url.cpp [deleted file]
modules/stream_filter/dash/mpd/Url.hpp [deleted file]
modules/stream_filter/dash/xml/DOMHelper.cpp [deleted file]
modules/stream_filter/dash/xml/DOMHelper.h [deleted file]
modules/stream_filter/dash/xml/DOMParser.cpp [deleted file]
modules/stream_filter/dash/xml/DOMParser.h [deleted file]
modules/stream_filter/dash/xml/Node.cpp [deleted file]
modules/stream_filter/dash/xml/Node.h [deleted file]
po/POTFILES.in

index b66483f..9b78049 100644 (file)
@@ -236,3 +236,107 @@ endif
 if HAVE_DVBPSI
 demux_LTLIBRARIES += libts_plugin.la
 endif
+
+libdash_plugin_la_SOURCES = \
+    demux/dash/adaptationlogic/AbstractAdaptationLogic.cpp \
+    demux/dash/adaptationlogic/AbstractAdaptationLogic.h \
+    demux/dash/adaptationlogic/AdaptationLogicFactory.cpp \
+    demux/dash/adaptationlogic/AdaptationLogicFactory.h \
+    demux/dash/adaptationlogic/AlwaysBestAdaptationLogic.cpp \
+    demux/dash/adaptationlogic/AlwaysBestAdaptationLogic.h \
+    demux/dash/adaptationlogic/AlwaysLowestAdaptationLogic.cpp \
+    demux/dash/adaptationlogic/AlwaysLowestAdaptationLogic.hpp \
+    demux/dash/adaptationlogic/IAdaptationLogic.h \
+    demux/dash/adaptationlogic/IDownloadRateObserver.h \
+    demux/dash/adaptationlogic/RateBasedAdaptationLogic.h \
+    demux/dash/adaptationlogic/RateBasedAdaptationLogic.cpp \
+    demux/dash/adaptationlogic/Representationselectors.hpp \
+    demux/dash/adaptationlogic/Representationselectors.cpp \
+    demux/dash/buffer/BlockBuffer.cpp \
+    demux/dash/buffer/BlockBuffer.h \
+    demux/dash/buffer/IBufferObserver.h \
+    demux/dash/http/Chunk.cpp \
+    demux/dash/http/Chunk.h \
+    demux/dash/http/HTTPConnection.cpp \
+    demux/dash/http/HTTPConnection.h \
+    demux/dash/http/HTTPConnectionManager.cpp \
+    demux/dash/http/HTTPConnectionManager.h \
+    demux/dash/http/IHTTPConnection.cpp \
+    demux/dash/http/IHTTPConnection.h \
+    demux/dash/http/PersistentConnection.cpp \
+    demux/dash/http/PersistentConnection.h \
+    demux/dash/mpd/AdaptationSet.cpp \
+    demux/dash/mpd/AdaptationSet.h \
+    demux/dash/mpd/BaseUrl.h \
+    demux/dash/mpd/CommonAttributesElements.cpp \
+    demux/dash/mpd/CommonAttributesElements.h \
+    demux/dash/mpd/ContentDescription.cpp \
+    demux/dash/mpd/ContentDescription.h \
+    demux/dash/mpd/ICanonicalUrl.hpp \
+    demux/dash/mpd/IMPDParser.cpp \
+    demux/dash/mpd/IMPDParser.h \
+    demux/dash/mpd/IsoffMainParser.cpp \
+    demux/dash/mpd/IsoffMainParser.h \
+    demux/dash/mpd/MPD.cpp \
+    demux/dash/mpd/MPD.h \
+    demux/dash/mpd/MPDFactory.cpp \
+    demux/dash/mpd/MPDFactory.h \
+    demux/dash/mpd/Period.cpp \
+    demux/dash/mpd/Period.h \
+    demux/dash/mpd/Profile.cpp \
+    demux/dash/mpd/Profile.hpp \
+    demux/dash/mpd/ProgramInformation.cpp \
+    demux/dash/mpd/ProgramInformation.h \
+    demux/dash/mpd/Representation.cpp \
+    demux/dash/mpd/Representation.h \
+    demux/dash/mpd/Segment.cpp \
+    demux/dash/mpd/Segment.h \
+    demux/dash/mpd/SegmentBase.cpp \
+    demux/dash/mpd/SegmentBase.h \
+    demux/dash/mpd/SegmentInfo.cpp \
+    demux/dash/mpd/SegmentInfo.h \
+    demux/dash/mpd/SegmentInfoCommon.cpp \
+    demux/dash/mpd/SegmentInfoCommon.h \
+    demux/dash/mpd/SegmentInfoDefault.cpp \
+    demux/dash/mpd/SegmentInfoDefault.h \
+    demux/dash/mpd/SegmentInformation.cpp \
+    demux/dash/mpd/SegmentInformation.hpp \
+    demux/dash/mpd/SegmentList.cpp \
+    demux/dash/mpd/SegmentList.h \
+    demux/dash/mpd/SegmentTemplate.cpp \
+    demux/dash/mpd/SegmentTemplate.h \
+    demux/dash/mpd/SegmentTimeline.cpp \
+    demux/dash/mpd/SegmentTimeline.h \
+    demux/dash/mpd/TrickModeType.cpp \
+    demux/dash/mpd/TrickModeType.h \
+    demux/dash/mpd/Url.cpp \
+    demux/dash/mpd/Url.hpp \
+    demux/dash/mp4/AtomsReader.cpp \
+    demux/dash/mp4/AtomsReader.hpp \
+    demux/dash/xml/DOMHelper.cpp \
+    demux/dash/xml/DOMHelper.h \
+    demux/dash/xml/DOMParser.cpp \
+    demux/dash/xml/DOMParser.h \
+    demux/dash/xml/Node.cpp \
+    demux/dash/xml/Node.h \
+    demux/dash/dash.cpp \
+    demux/dash/dash.hpp \
+    demux/dash/DASHManager.cpp \
+    demux/dash/DASHManager.h \
+    demux/dash/Helper.cpp \
+    demux/dash/Helper.h \
+    demux/dash/Properties.hpp \
+    demux/dash/StreamsType.hpp \
+    demux/dash/Streams.cpp \
+    demux/dash/Streams.hpp
+
+libdash_plugin_la_SOURCES += demux/mp4/libmp4.c demux/mp4/libmp4.h
+
+libdash_plugin_la_CXXFLAGS = $(AM_CFLAGS) -I$(srcdir)/demux/dash
+libdash_plugin_la_LIBADD = $(SOCKET_LIBS) $(LIBM)
+if HAVE_ZLIB
+libdash_plugin_la_LIBADD += -lz
+endif
+demux_LTLIBRARIES += libdash_plugin.la
+
+
diff --git a/modules/demux/dash/DASHManager.cpp b/modules/demux/dash/DASHManager.cpp
new file mode 100644 (file)
index 0000000..edd4132
--- /dev/null
@@ -0,0 +1,143 @@
+/*****************************************************************************
+ * DASHManager.cpp
+ *****************************************************************************
+ * Copyright © 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#define __STDC_CONSTANT_MACROS
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "DASHManager.h"
+#include "adaptationlogic/AdaptationLogicFactory.h"
+
+using namespace dash;
+using namespace dash::http;
+using namespace dash::logic;
+using namespace dash::mpd;
+using namespace dash::buffer;
+
+DASHManager::DASHManager    ( MPD *mpd,
+                              IAdaptationLogic::LogicType type, stream_t *stream) :
+             conManager     ( NULL ),
+             logicType      ( type ),
+             mpd            ( mpd ),
+             stream         ( stream )
+{
+    for(int i=0; i<Streams::count; i++)
+        streams[i] = NULL;
+}
+
+DASHManager::~DASHManager   ()
+{
+    delete conManager;
+    for(int i=0; i<Streams::count; i++)
+        delete streams[i];
+}
+
+bool DASHManager::start(demux_t *demux)
+{
+    const Period *period = mpd->getFirstPeriod();
+    if(!period)
+        return false;
+
+    for(int i=0; i<Streams::count; i++)
+    {
+        Streams::Type type = static_cast<Streams::Type>(i);
+        const AdaptationSet *set = period->getAdaptationSet(type);
+        if(set)
+        {
+            streams[type] = new Streams::Stream(set->getMimeType());
+            try
+            {
+                streams[type]->create(demux, AdaptationLogicFactory::create( logicType, mpd ) );
+            } catch (int) {
+                delete streams[type];
+                streams[type] = NULL;
+            }
+        }
+    }
+
+    conManager = new HTTPConnectionManager(stream);
+    if(!conManager)
+        return false;
+
+    mpd->playbackStart.Set(time(NULL));
+
+    return true;
+}
+
+size_t DASHManager::read()
+{
+    size_t i_ret = 0;
+    for(int type=0; type<Streams::count; type++)
+    {
+        if(!streams[type])
+            continue;
+        i_ret += streams[type]->read(conManager);
+    }
+    return i_ret;
+}
+
+mtime_t DASHManager::getPCR() const
+{
+    mtime_t pcr = VLC_TS_INVALID;
+    for(int type=0; type<Streams::count; type++)
+    {
+        if(!streams[type])
+            continue;
+        if(pcr == VLC_TS_INVALID || pcr > streams[type]->getPCR())
+            pcr = streams[type]->getPCR();
+    }
+    return pcr;
+}
+
+int DASHManager::getGroup() const
+{
+    for(int type=0; type<Streams::count; type++)
+    {
+        if(!streams[type])
+            continue;
+        return streams[type]->getGroup();
+    }
+    return -1;
+}
+
+int DASHManager::esCount() const
+{
+    int es = 0;
+    for(int type=0; type<Streams::count; type++)
+    {
+        if(!streams[type])
+            continue;
+        es += streams[type]->esCount();
+    }
+    return es;
+}
+
+mtime_t DASHManager::getDuration() const
+{
+    if (mpd->isLive())
+        return 0;
+    else
+        return CLOCK_FREQ * mpd->getDuration();
+}
diff --git a/modules/demux/dash/DASHManager.h b/modules/demux/dash/DASHManager.h
new file mode 100644 (file)
index 0000000..0457a58
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * DASHManager.h
+ *****************************************************************************
+ * Copyright © 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 DASHMANAGER_H_
+#define DASHMANAGER_H_
+
+#include "http/HTTPConnectionManager.h"
+#include "adaptationlogic/IAdaptationLogic.h"
+#include "mpd/MPD.h"
+
+namespace dash
+{
+    class DASHManager
+    {
+        public:
+            DASHManager( mpd::MPD *mpd,
+                         logic::IAdaptationLogic::LogicType type, stream_t *stream);
+            virtual ~DASHManager    ();
+
+            bool    start         (demux_t *);
+            size_t  read();
+            mtime_t getDuration() const;
+            mtime_t getPCR() const;
+            int     getGroup() const;
+            int     esCount() const;
+
+        private:
+            http::HTTPConnectionManager         *conManager;
+            logic::IAdaptationLogic::LogicType  logicType;
+            mpd::MPD                            *mpd;
+            stream_t                            *stream;
+            Streams::Stream                     *streams[Streams::count];
+    };
+
+}
+
+#endif /* DASHMANAGER_H_ */
diff --git a/modules/demux/dash/Helper.cpp b/modules/demux/dash/Helper.cpp
new file mode 100644 (file)
index 0000000..b26dbce
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Helper.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2012 Klagenfurt University
+ *
+ * Created on: Feb 20, 2012
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "Helper.h"
+#include <algorithm>
+using namespace dash;
+
+std::string Helper::combinePaths        (const std::string &path1, const std::string &path2)
+{
+    if ( path2.length() == 0 )
+        return path1;
+    else if ( path1.length() == 0 )
+        return path2;
+
+    char path1Last  = path1.at(path1.size() - 1);
+    char path2First = path2.at(0);
+
+    if(path1Last == '/' && path2First == '/')
+        return path1 + path2.substr(1, path2.size());
+
+    if(path1Last != '/' && path2First != '/')
+        return path1 + "/" + path2;
+
+    return path1 + path2;
+}
+std::string Helper::getDirectoryPath    (const std::string &path)
+{
+    int pos = path.find_last_of('/');
+
+    return path.substr(0, pos);
+}
+
+bool Helper::ifind(std::string haystack, std::string needle)
+{
+    transform(haystack.begin(), haystack.end(), haystack.begin(), toupper);
+    transform(needle.begin(), needle.end(), needle.begin(), toupper);
+    return haystack.find(needle) != std::string::npos;
+}
diff --git a/modules/demux/dash/Helper.h b/modules/demux/dash/Helper.h
new file mode 100644 (file)
index 0000000..4d33bae
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Helper.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2012 Klagenfurt University
+ *
+ * Created on: Feb 20, 2012
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 HELPER_H_
+#define HELPER_H_
+
+#include <string>
+
+namespace dash
+{
+    class Helper
+    {
+        public:
+            static std::string combinePaths     (const std::string &path1, const std::string &path2);
+            static std::string getDirectoryPath (const std::string &path);
+            static bool        ifind            (std::string haystack, std::string needle);
+    };
+}
+
+#endif /* HELPER_H_ */
diff --git a/modules/demux/dash/Properties.hpp b/modules/demux/dash/Properties.hpp
new file mode 100644 (file)
index 0000000..f05b574
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Inheritables.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 PROPERTIES_HPP
+#define PROPERTIES_HPP
+
+namespace dash
+{
+    template <typename T> class Property
+    {
+        public:
+            Property() {}
+
+            T & Set(const T &i)
+            {
+                return value = i;
+            }
+
+            T const & Get() const
+            {
+                return value;
+            }
+
+        private:
+            T value;
+    };
+}
+#endif // PROPERTIES_HPP
diff --git a/modules/demux/dash/Streams.cpp b/modules/demux/dash/Streams.cpp
new file mode 100644 (file)
index 0000000..e7be308
--- /dev/null
@@ -0,0 +1,316 @@
+/*
+ * Streams.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.
+ *****************************************************************************/
+#define __STDC_CONSTANT_MACROS
+#include "Streams.hpp"
+#include "adaptationlogic/IAdaptationLogic.h"
+#include "adaptationlogic/AdaptationLogicFactory.h"
+#include <vlc_stream.h>
+#include <vlc_demux.h>
+
+using namespace dash::Streams;
+using namespace dash::http;
+using namespace dash::logic;
+
+Stream::Stream(const std::string &mime)
+{
+    init(mimeToType(mime), mimeToFormat(mime));
+}
+
+Stream::Stream(const Type type, const Format format)
+{
+    init(type, format);
+}
+
+void Stream::init(const Type type_, const Format format_)
+{
+    type = type_;
+    format = format_;
+    output = NULL;
+    adaptationLogic = NULL;
+    currentChunk = NULL;
+    eof = false;
+}
+
+Stream::~Stream()
+{
+    delete currentChunk;
+    delete adaptationLogic;
+    delete output;
+}
+
+Type Stream::mimeToType(const std::string &mime)
+{
+    Type mimetype;
+    if (!mime.compare(0, 6, "video/"))
+        mimetype = Streams::VIDEO;
+    else if (!mime.compare(0, 6, "audio/"))
+        mimetype = Streams::AUDIO;
+    else if (!mime.compare(0, 12, "application/"))
+        mimetype = Streams::APPLICATION;
+    else /* unknown of unsupported */
+        mimetype = Streams::UNKNOWN;
+    return mimetype;
+}
+
+Format Stream::mimeToFormat(const std::string &mime)
+{
+    Format format = Streams::UNSUPPORTED;
+    std::string::size_type pos = mime.find("/");
+    if(pos != std::string::npos)
+    {
+        std::string tail = mime.substr(pos + 1);
+        if(tail == "mp4")
+            format = Streams::MP4;
+        else if (tail == "mp2t")
+            format = Streams::MPEG2TS;
+    }
+    return format;
+}
+
+void Stream::create(demux_t *demux, IAdaptationLogic *logic)
+{
+    adaptationLogic = logic;
+    switch(format)
+    {
+        case Streams::MP4:
+            output = new MP4StreamOutput(demux);
+            break;
+        case Streams::MPEG2TS:
+            output = new MPEG2TSStreamOutput(demux);
+            break;
+        default:
+            throw VLC_EBADVAR;
+            break;
+    }
+}
+
+bool Stream::isEOF() const
+{
+    return false;
+}
+
+mtime_t Stream::getPCR() const
+{
+    return output->getPCR();
+}
+
+int Stream::getGroup() const
+{
+    return output->getGroup();
+}
+
+int Stream::esCount() const
+{
+    return output->esCount();
+}
+
+bool Stream::operator ==(const Stream &stream) const
+{
+    return stream.type == type;
+}
+
+Chunk * Stream::getChunk()
+{
+    if (currentChunk == NULL)
+    {
+        currentChunk = adaptationLogic->getNextChunk(type);
+        if (currentChunk == NULL)
+            eof = true;
+    }
+    return currentChunk;
+}
+
+size_t Stream::read(HTTPConnectionManager *connManager)
+{
+    Chunk *chunk = getChunk();
+    if(!chunk)
+        return 0;
+
+    if(!chunk->getConnection())
+    {
+       if(!connManager->connectChunk(chunk))
+        return 0;
+    }
+
+    size_t readsize = 0;
+
+    /* Because we don't know Chunk size at start, we need to get size
+       from content length */
+    if(chunk->getBytesRead() == 0)
+    {
+        if(chunk->getConnection()->query(chunk->getPath()) == false)
+            readsize = 32768; /* we don't handle retry here :/ */
+        else
+            readsize = chunk->getBytesToRead();
+    }
+    else
+    {
+        readsize = chunk->getBytesToRead();
+    }
+
+    if (readsize > 128000)
+        readsize = 32768;
+
+    block_t *block = block_Alloc(readsize);
+    if(!block)
+        return 0;
+
+    mtime_t time = mdate();
+    ssize_t ret = chunk->getConnection()->read(block->p_buffer, readsize);
+    time = mdate() - time;
+
+    if(ret <= 0)
+    {
+        block_Release(block);
+        chunk->getConnection()->releaseChunk();
+        currentChunk = NULL;
+        delete chunk;
+        return 0;
+    }
+    else
+    {
+        block->i_buffer = (size_t)ret;
+
+        adaptationLogic->updateDownloadRate(block->i_buffer, time);
+
+        if (chunk->getBytesToRead() == 0)
+        {
+            chunk->onDownload(block->p_buffer, block->i_buffer);
+            chunk->getConnection()->releaseChunk();
+            currentChunk = NULL;
+            delete chunk;
+        }
+    }
+
+    readsize = block->i_buffer;
+
+    output->pushBlock(block);
+
+    return readsize;
+}
+
+AbstractStreamOutput::AbstractStreamOutput(demux_t *demux)
+{
+    realdemux = demux;
+    demuxstream = NULL;
+    pcr = VLC_TS_0;
+    group = -1;
+    escount = 0;
+
+    fakeesout = new es_out_t;
+    if (!fakeesout)
+        throw VLC_ENOMEM;
+
+    fakeesout->pf_add = esOutAdd;
+    fakeesout->pf_control = esOutControl;
+    fakeesout->pf_del = esOutDel;
+    fakeesout->pf_destroy = esOutDestroy;
+    fakeesout->pf_send = esOutSend;
+    fakeesout->p_sys = (es_out_sys_t*) this;
+}
+
+AbstractStreamOutput::~AbstractStreamOutput()
+{
+    if (demuxstream)
+        stream_Delete(demuxstream);
+    delete fakeesout;
+}
+
+mtime_t AbstractStreamOutput::getPCR() const
+{
+    return pcr;
+}
+
+int AbstractStreamOutput::getGroup() const
+{
+    return group;
+}
+
+int AbstractStreamOutput::esCount() const
+{
+    return escount;
+}
+
+void AbstractStreamOutput::pushBlock(block_t *block)
+{
+    stream_DemuxSend(demuxstream, block);
+}
+
+/* Static callbacks */
+es_out_id_t * AbstractStreamOutput::esOutAdd(es_out_t *fakees, const es_format_t *p_fmt)
+{
+    AbstractStreamOutput *me = (AbstractStreamOutput *) fakees->p_sys;
+    me->escount++;
+    return me->realdemux->out->pf_add(me->realdemux->out, p_fmt);
+}
+
+int AbstractStreamOutput::esOutSend(es_out_t *fakees, es_out_id_t *p_es, block_t *p_block)
+{
+    AbstractStreamOutput *me = (AbstractStreamOutput *) fakees->p_sys;
+    return me->realdemux->out->pf_send(me->realdemux->out, p_es, p_block);
+}
+
+void AbstractStreamOutput::esOutDel(es_out_t *fakees, es_out_id_t *p_es)
+{
+    AbstractStreamOutput *me = (AbstractStreamOutput *) fakees->p_sys;
+    me->escount--;
+    me->realdemux->out->pf_del(me->realdemux->out, p_es);
+}
+
+int AbstractStreamOutput::esOutControl(es_out_t *fakees, int i_query, va_list args)
+{
+    AbstractStreamOutput *me = (AbstractStreamOutput *) fakees->p_sys;
+    if (i_query == ES_OUT_SET_PCR )
+    {
+        me->pcr = (int64_t)va_arg( args, int64_t );
+        return VLC_SUCCESS;
+    }
+    else if( i_query == ES_OUT_SET_GROUP_PCR )
+    {
+        me->group = (int) va_arg( args, int );
+        me->pcr = (int64_t)va_arg( args, int64_t );
+        return VLC_SUCCESS;
+    }
+
+    return me->realdemux->out->pf_control(me->realdemux->out, i_query, args);
+}
+
+void AbstractStreamOutput::esOutDestroy(es_out_t *fakees)
+{
+    AbstractStreamOutput *me = (AbstractStreamOutput *) fakees->p_sys;
+    me->realdemux->out->pf_destroy(me->realdemux->out);
+}
+/* !Static callbacks */
+
+MP4StreamOutput::MP4StreamOutput(demux_t *demux) :
+    AbstractStreamOutput(demux)
+{
+    demuxstream = stream_DemuxNew(demux, "mp4", fakeesout);
+    if(!demuxstream)
+        throw VLC_EGENERIC;
+}
+
+MPEG2TSStreamOutput::MPEG2TSStreamOutput(demux_t *demux) :
+    AbstractStreamOutput(demux)
+{
+    demuxstream = stream_DemuxNew(demux, "ts", fakeesout);
+    if(!demuxstream)
+        throw VLC_EGENERIC;
+}
diff --git a/modules/demux/dash/Streams.hpp b/modules/demux/dash/Streams.hpp
new file mode 100644 (file)
index 0000000..387ad97
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * Streams.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 STREAM_HPP
+#define STREAM_HPP
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <string>
+#include <vlc_common.h>
+#include "StreamsType.hpp"
+#include "adaptationlogic/IAdaptationLogic.h"
+#include "http/HTTPConnectionManager.h"
+#include "http/Chunk.h"
+
+namespace dash
+{
+    namespace Streams
+    {
+        class AbstractStreamOutput;
+
+        class Stream
+        {
+            public:
+                Stream(const std::string &mime);
+                Stream(const Type, const Format);
+                ~Stream();
+                bool operator==(const Stream &) const;
+                static Type mimeToType(const std::string &mime);
+                static Format mimeToFormat(const std::string &mime);
+                void create(demux_t *, logic::IAdaptationLogic *);
+                bool isEOF() const;
+                mtime_t getPCR() const;
+                int getGroup() const;
+                int esCount() const;
+                size_t read(http::HTTPConnectionManager *);
+
+            private:
+                http::Chunk *getChunk();
+                void init(const Type, const Format);
+                Type type;
+                Format format;
+                AbstractStreamOutput *output;
+                logic::IAdaptationLogic *adaptationLogic;
+                http::Chunk *currentChunk;
+                bool eof;
+        };
+
+        class AbstractStreamOutput
+        {
+            public:
+                AbstractStreamOutput(demux_t *);
+                virtual ~AbstractStreamOutput();
+
+                virtual void pushBlock(block_t *);
+                mtime_t getPCR() const;
+                int getGroup() const;
+                int esCount() const;
+
+            protected:
+                mtime_t   pcr;
+                int       group;
+                int       escount;
+                es_out_t *fakeesout; /* to intercept/proxy what is sent from demuxstream */
+                stream_t *demuxstream;
+
+            private:
+                demux_t  *realdemux;
+                static es_out_id_t *esOutAdd(es_out_t *, const es_format_t *);
+                static int esOutSend(es_out_t *, es_out_id_t *, block_t *);
+                static void esOutDel(es_out_t *, es_out_id_t *);
+                static int esOutControl(es_out_t *, int, va_list);
+                static void esOutDestroy(es_out_t *);
+        };
+
+        class MP4StreamOutput : public AbstractStreamOutput
+        {
+            public:
+                MP4StreamOutput(demux_t *);
+                virtual ~MP4StreamOutput(){}
+        };
+
+        class MPEG2TSStreamOutput : public AbstractStreamOutput
+        {
+            public:
+                MPEG2TSStreamOutput(demux_t *);
+                virtual ~MPEG2TSStreamOutput(){}
+        };
+    }
+}
+#endif // STREAMS_HPP
diff --git a/modules/demux/dash/StreamsType.hpp b/modules/demux/dash/StreamsType.hpp
new file mode 100644 (file)
index 0000000..d4ffd64
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * StreamsType.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 STREAMSTYPE_HPP
+#define STREAMSTYPE_HPP
+
+namespace dash
+{
+    namespace Streams
+    {
+        enum Type
+        {
+            UNKNOWN = 0,
+            VIDEO,
+            AUDIO,
+            APPLICATION
+        };
+
+        enum Format
+        {
+            UNSUPPORTED = 0,
+            MP4,
+            MPEG2TS
+        };
+
+        static const int count = APPLICATION + 1;
+    }
+}
+
+#endif
diff --git a/modules/demux/dash/adaptationlogic/AbstractAdaptationLogic.cpp b/modules/demux/dash/adaptationlogic/AbstractAdaptationLogic.cpp
new file mode 100644 (file)
index 0000000..5fa0b53
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * AbstractAdaptationLogic.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "AbstractAdaptationLogic.h"
+
+using namespace dash::logic;
+using namespace dash::mpd;
+using namespace dash::http;
+
+AbstractAdaptationLogic::AbstractAdaptationLogic    (MPD *mpd_) :
+                         mpd                        (mpd_),
+                         currentPeriod              (mpd->getFirstPeriod())
+{
+    reset();
+}
+
+AbstractAdaptationLogic::~AbstractAdaptationLogic   ()
+{
+}
+
+void AbstractAdaptationLogic::reset()
+{
+    count = 0;
+    prevRepresentation = NULL;
+}
+
+Chunk*  AbstractAdaptationLogic::getNextChunk(Streams::Type type)
+{
+    if(!currentPeriod)
+        return NULL;
+
+    Representation *rep;
+
+    if(prevRepresentation && !prevRepresentation->canBitswitch())
+        rep = prevRepresentation;
+    else
+        rep = getCurrentRepresentation(type);
+
+    if ( rep == NULL )
+            return NULL;
+
+    bool reinit = count && (rep != prevRepresentation);
+    prevRepresentation = rep;
+
+    std::vector<ISegment *> segments = rep->getSegments();
+    ISegment *first = segments.empty() ? NULL : segments.front();
+
+    if (reinit && first && first->getClassId() == InitSegment::CLASSID_INITSEGMENT)
+        return first->toChunk(count, rep);
+
+    bool b_templated = (first && !first->isSingleShot());
+
+    if (count == segments.size() && !b_templated)
+    {
+        currentPeriod = mpd->getNextPeriod(currentPeriod);
+        reset();
+        return getNextChunk(type);
+    }
+
+    ISegment *seg = NULL;
+    if ( segments.size() > count )
+    {
+        seg = segments.at( count );
+    }
+    else if(b_templated)
+    {
+        seg = segments.back();
+    }
+
+    if(seg)
+    {
+        Chunk *chunk = seg->toChunk(count, rep);
+        count++;
+        seg->done();
+        return chunk;
+    }
+    return NULL;
+}
+
+void AbstractAdaptationLogic::updateDownloadRate    (size_t, mtime_t)
+{
+}
diff --git a/modules/demux/dash/adaptationlogic/AbstractAdaptationLogic.h b/modules/demux/dash/adaptationlogic/AbstractAdaptationLogic.h
new file mode 100644 (file)
index 0000000..06fd58f
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * AbstractAdaptationLogic.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 ABSTRACTADAPTATIONLOGIC_H_
+#define ABSTRACTADAPTATIONLOGIC_H_
+
+#include "adaptationlogic/IAdaptationLogic.h"
+#include "http/Chunk.h"
+#include "mpd/MPD.h"
+#include "mpd/Period.h"
+#include "mpd/Representation.h"
+
+struct stream_t;
+
+namespace dash
+{
+    namespace logic
+    {
+        class AbstractAdaptationLogic : public IAdaptationLogic
+        {
+            public:
+                AbstractAdaptationLogic             (mpd::MPD *mpd);
+                virtual ~AbstractAdaptationLogic    ();
+                virtual void reset                  ();
+
+                virtual dash::http::Chunk*  getNextChunk            (Streams::Type);
+
+                virtual void                updateDownloadRate     (size_t, mtime_t);
+
+            protected:
+                dash::mpd::MPD         *mpd;
+                dash::mpd::Period      *currentPeriod;
+                size_t                  count;
+                mpd::Representation    *prevRepresentation;
+        };
+    }
+}
+
+#endif /* ABSTRACTADAPTATIONLOGIC_H_ */
diff --git a/modules/demux/dash/adaptationlogic/AdaptationLogicFactory.cpp b/modules/demux/dash/adaptationlogic/AdaptationLogicFactory.cpp
new file mode 100644 (file)
index 0000000..aef3416
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * AdaptationLogicFactory.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "AdaptationLogicFactory.h"
+#include "adaptationlogic/AlwaysBestAdaptationLogic.h"
+#include "adaptationlogic/RateBasedAdaptationLogic.h"
+#include "adaptationlogic/AlwaysLowestAdaptationLogic.hpp"
+
+using namespace dash::logic;
+using namespace dash::mpd;
+
+IAdaptationLogic* AdaptationLogicFactory::create ( IAdaptationLogic::LogicType logic,
+                                                   MPD *mpd)
+{
+    switch(logic)
+    {
+        case IAdaptationLogic::AlwaysBest:      return new AlwaysBestAdaptationLogic    (mpd);
+        case IAdaptationLogic::AlwaysLowest:    return new AlwaysLowestAdaptationLogic  (mpd);
+        case IAdaptationLogic::FixedRate:       return new FixedRateAdaptationLogic     (mpd);
+        case IAdaptationLogic::Default:
+        case IAdaptationLogic::RateBased:       return new RateBasedAdaptationLogic     (mpd);
+        default:
+            return NULL;
+    }
+}
diff --git a/modules/demux/dash/adaptationlogic/AdaptationLogicFactory.h b/modules/demux/dash/adaptationlogic/AdaptationLogicFactory.h
new file mode 100644 (file)
index 0000000..db78b2a
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * AdaptationLogicFactory.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 ADAPTATIONLOGICFACTORY_H_
+#define ADAPTATIONLOGICFACTORY_H_
+
+#include "adaptationlogic/IAdaptationLogic.h"
+
+struct stream_t;
+
+namespace dash
+{
+    namespace logic
+    {
+        class AdaptationLogicFactory
+        {
+            public:
+                static IAdaptationLogic* create (IAdaptationLogic::LogicType logic, mpd::MPD *mpd);
+        };
+    }
+}
+
+#endif /* ADAPTATIONLOGICFACTORY_H_ */
diff --git a/modules/demux/dash/adaptationlogic/AlwaysBestAdaptationLogic.cpp b/modules/demux/dash/adaptationlogic/AlwaysBestAdaptationLogic.cpp
new file mode 100644 (file)
index 0000000..a4cbbec
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * AlwaysBestAdaptationLogic.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "AlwaysBestAdaptationLogic.h"
+#include "Representationselectors.hpp"
+
+using namespace dash::logic;
+using namespace dash::mpd;
+
+AlwaysBestAdaptationLogic::AlwaysBestAdaptationLogic    (MPD *mpd) :
+                           AbstractAdaptationLogic      (mpd)
+{
+}
+
+Representation *AlwaysBestAdaptationLogic::getCurrentRepresentation(Streams::Type type) const
+{
+    RepresentationSelector selector;
+    return selector.select(currentPeriod, type);
+}
diff --git a/modules/demux/dash/adaptationlogic/AlwaysBestAdaptationLogic.h b/modules/demux/dash/adaptationlogic/AlwaysBestAdaptationLogic.h
new file mode 100644 (file)
index 0000000..c3b21ea
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * AlwaysBestAdaptationLogic.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 ALWAYSBESTADAPTATIONLOGIC_H_
+#define ALWAYSBESTADAPTATIONLOGIC_H_
+
+#include "adaptationlogic/AbstractAdaptationLogic.h"
+
+namespace dash
+{
+    namespace logic
+    {
+        class AlwaysBestAdaptationLogic : public AbstractAdaptationLogic
+        {
+            public:
+                AlwaysBestAdaptationLogic           (mpd::MPD *mpd);
+
+                virtual mpd::Representation *getCurrentRepresentation(Streams::Type) const;
+        };
+    }
+}
+
+#endif /* ALWAYSBESTADAPTATIONLOGIC_H_ */
diff --git a/modules/demux/dash/adaptationlogic/AlwaysLowestAdaptationLogic.cpp b/modules/demux/dash/adaptationlogic/AlwaysLowestAdaptationLogic.cpp
new file mode 100644 (file)
index 0000000..1d4a1c2
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * AlwaysLowestAdaptationLogic.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 "AlwaysLowestAdaptationLogic.hpp"
+#include "Representationselectors.hpp"
+
+using namespace dash::logic;
+using namespace dash::mpd;
+
+AlwaysLowestAdaptationLogic::AlwaysLowestAdaptationLogic(mpd::MPD *mpd):
+    AbstractAdaptationLogic(mpd)
+{
+}
+
+Representation *AlwaysLowestAdaptationLogic::getCurrentRepresentation(Streams::Type type) const
+{
+    RepresentationSelector selector;
+    return selector.select(currentPeriod, type, 0);
+}
diff --git a/modules/demux/dash/adaptationlogic/AlwaysLowestAdaptationLogic.hpp b/modules/demux/dash/adaptationlogic/AlwaysLowestAdaptationLogic.hpp
new file mode 100644 (file)
index 0000000..2ff7ae5
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * AlwaysLowestAdaptationLogic.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 ALWAYSLOWESTADAPTATIONLOGIC_HPP
+#define ALWAYSLOWESTADAPTATIONLOGIC_HPP
+
+#include "AbstractAdaptationLogic.h"
+
+namespace dash
+{
+    namespace logic
+    {
+        class AlwaysLowestAdaptationLogic : public AbstractAdaptationLogic
+        {
+            public:
+                AlwaysLowestAdaptationLogic(mpd::MPD *mpd);
+
+                virtual dash::mpd::Representation*    getCurrentRepresentation(Streams::Type) const;
+        };
+    }
+}
+
+#endif // ALWAYSLOWESTADAPTATIONLOGIC_HPP
diff --git a/modules/demux/dash/adaptationlogic/IAdaptationLogic.h b/modules/demux/dash/adaptationlogic/IAdaptationLogic.h
new file mode 100644 (file)
index 0000000..e9abecc
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * IAdaptationLogic.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 IADAPTATIONLOGIC_H_
+#define IADAPTATIONLOGIC_H_
+
+#include <http/Chunk.h>
+#include <adaptationlogic/IDownloadRateObserver.h>
+#include "mpd/Representation.h"
+#include "buffer/IBufferObserver.h"
+#include "StreamsType.hpp"
+
+namespace dash
+{
+    namespace logic
+    {
+        class IAdaptationLogic : public IDownloadRateObserver
+        {
+            public:
+
+                enum LogicType
+                {
+                    Default,
+                    AlwaysBest,
+                    AlwaysLowest,
+                    RateBased,
+                    FixedRate
+                };
+
+                virtual dash::http::Chunk*                  getNextChunk            (Streams::Type) = 0;
+                virtual dash::mpd::Representation*          getCurrentRepresentation(Streams::Type) const    = 0;
+        };
+    }
+}
+
+#endif /* IADAPTATIONLOGIC_H_ */
diff --git a/modules/demux/dash/adaptationlogic/IDownloadRateObserver.h b/modules/demux/dash/adaptationlogic/IDownloadRateObserver.h
new file mode 100644 (file)
index 0000000..361471d
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * IDownloadRateObserver.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 IDOWNLOADRATEOBSERVER_H_
+#define IDOWNLOADRATEOBSERVER_H_
+
+#include <stdint.h>
+
+namespace dash
+{
+    namespace logic
+    {
+        class IDownloadRateObserver
+        {
+            public:
+                virtual void updateDownloadRate(size_t, mtime_t) = 0;
+                virtual ~IDownloadRateObserver(){}
+        };
+    }
+}
+
+#endif /* IDOWNLOADRATEOBSERVER_H_ */
diff --git a/modules/demux/dash/adaptationlogic/RateBasedAdaptationLogic.cpp b/modules/demux/dash/adaptationlogic/RateBasedAdaptationLogic.cpp
new file mode 100644 (file)
index 0000000..8851190
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * RateBasedAdaptationLogic.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "RateBasedAdaptationLogic.h"
+#include "Representationselectors.hpp"
+
+#include <vlc_common.h>
+#include <vlc_variables.h>
+
+using namespace dash::logic;
+using namespace dash::mpd;
+
+RateBasedAdaptationLogic::RateBasedAdaptationLogic  (MPD *mpd) :
+                          AbstractAdaptationLogic   (mpd),
+                          bpsAvg(0), bpsSamplecount(0),
+                          currentBps(0)
+{
+    width  = var_InheritInteger(mpd->getVLCObject(), "dash-prefwidth");
+    height = var_InheritInteger(mpd->getVLCObject(), "dash-prefheight");
+}
+
+Representation *RateBasedAdaptationLogic::getCurrentRepresentation(Streams::Type type) const
+{
+    if(currentPeriod == NULL)
+        return NULL;
+
+    RepresentationSelector selector;
+    Representation *rep = selector.select(currentPeriod, type, currentBps, width, height);
+    if ( rep == NULL )
+    {
+        rep = selector.select(currentPeriod, type);
+        if ( rep == NULL )
+            return NULL;
+    }
+    return rep;
+}
+
+void RateBasedAdaptationLogic::updateDownloadRate(size_t size, mtime_t time)
+{
+    if(unlikely(time == 0))
+        return;
+
+    size_t current = size * 8000 / time;
+
+    if (current >= bpsAvg)
+        bpsAvg = bpsAvg + (current - bpsAvg) / (bpsSamplecount + 1);
+    else
+        bpsAvg = bpsAvg - (bpsAvg - current) / (bpsSamplecount + 1);
+
+    bpsSamplecount++;
+
+    if(bpsSamplecount % 5 == 0)
+        currentBps = bpsAvg;
+}
+
+FixedRateAdaptationLogic::FixedRateAdaptationLogic(mpd::MPD *mpd) :
+    AbstractAdaptationLogic(mpd)
+{
+    currentBps = var_InheritInteger( mpd->getVLCObject(), "dash-prefbw" ) * 8192;
+}
+
+Representation *FixedRateAdaptationLogic::getCurrentRepresentation(Streams::Type type) const
+{
+    if(currentPeriod == NULL)
+        return NULL;
+
+    RepresentationSelector selector;
+    Representation *rep = selector.select(currentPeriod, type, currentBps);
+    if ( rep == NULL )
+    {
+        rep = selector.select(currentPeriod, type);
+        if ( rep == NULL )
+            return NULL;
+    }
+    return rep;
+}
diff --git a/modules/demux/dash/adaptationlogic/RateBasedAdaptationLogic.h b/modules/demux/dash/adaptationlogic/RateBasedAdaptationLogic.h
new file mode 100644 (file)
index 0000000..105069a
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * RateBasedAdaptationLogic.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 RATEBASEDADAPTATIONLOGIC_H_
+#define RATEBASEDADAPTATIONLOGIC_H_
+
+#include "adaptationlogic/AbstractAdaptationLogic.h"
+
+#define MINBUFFER 30
+
+namespace dash
+{
+    namespace logic
+    {
+        class RateBasedAdaptationLogic : public AbstractAdaptationLogic
+        {
+            public:
+                RateBasedAdaptationLogic            (mpd::MPD *mpd);
+
+                dash::mpd::Representation *getCurrentRepresentation(Streams::Type) const;
+                virtual void updateDownloadRate(size_t, mtime_t);
+
+            private:
+                int                     width;
+                int                     height;
+                size_t                  bpsAvg;
+                size_t                  bpsSamplecount;
+                size_t                  currentBps;
+        };
+
+        class FixedRateAdaptationLogic : public AbstractAdaptationLogic
+        {
+            public:
+                FixedRateAdaptationLogic(mpd::MPD *mpd);
+
+                dash::mpd::Representation *getCurrentRepresentation(Streams::Type) const;
+
+            private:
+                size_t                  currentBps;
+        };
+    }
+}
+
+#endif /* RATEBASEDADAPTATIONLOGIC_H_ */
diff --git a/modules/demux/dash/adaptationlogic/Representationselectors.cpp b/modules/demux/dash/adaptationlogic/Representationselectors.cpp
new file mode 100644 (file)
index 0000000..697a96e
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Representationselectors.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 "Representationselectors.hpp"
+#include <limits>
+
+using namespace dash::logic;
+
+RepresentationSelector::RepresentationSelector()
+{
+}
+
+Representation * RepresentationSelector::select(Period *period, Streams::Type type) const
+{
+    return select(period, type, std::numeric_limits<uint64_t>::max());
+}
+Representation * RepresentationSelector::select(Period *period, Streams::Type type, uint64_t bitrate) const
+{
+    if (period == NULL)
+        return NULL;
+
+    std::vector<AdaptationSet *> adaptSets = period->getAdaptationSets(type);
+    Representation  *best = NULL;
+
+    std::vector<AdaptationSet *>::const_iterator adaptIt;
+    for(adaptIt=adaptSets.begin(); adaptIt!=adaptSets.end(); adaptIt++)
+    {
+        std::vector<Representation *> reps = (*adaptIt)->getRepresentations();
+        Representation *candidate = select(reps, (best)?best->getBandwidth():0, bitrate);
+        if (candidate)
+        {
+            if (candidate->getBandwidth() > bitrate) /* none matched, returned lowest */
+                return candidate;
+            best = candidate;
+        }
+    }
+    return best;
+}
+
+Representation * RepresentationSelector::select(Period *period, Streams::Type type, uint64_t bitrate,
+                                                int width, int height) const
+{
+    if(period == NULL)
+        return NULL;
+
+    std::vector<Representation *> resMatchReps;
+
+    /* subset matching WxH */
+    std::vector<AdaptationSet *> adaptSets = period->getAdaptationSets(type);
+    std::vector<AdaptationSet *>::const_iterator adaptIt;
+    for(adaptIt=adaptSets.begin(); adaptIt!=adaptSets.end(); adaptIt++)
+    {
+        std::vector<Representation *> reps = (*adaptIt)->getRepresentations();
+        std::vector<Representation *>::const_iterator repIt;
+        for(repIt=reps.begin(); repIt!=reps.end(); repIt++)
+        {
+            if((*repIt)->getWidth() == width && (*repIt)->getHeight() == height)
+                resMatchReps.push_back(*repIt);
+        }
+    }
+
+    if(resMatchReps.empty())
+        return select(period, type, bitrate);
+    else
+        return select(resMatchReps, 0, bitrate);
+}
+
+Representation * RepresentationSelector::select(std::vector<Representation *>& reps,
+                                                uint64_t minbitrate, uint64_t maxbitrate) const
+{
+    Representation  *candidate = NULL, *lowest = NULL;
+    std::vector<Representation *>::const_iterator repIt;
+    for(repIt=reps.begin(); repIt!=reps.end(); repIt++)
+    {
+        if ( !lowest || (*repIt)->getBandwidth() < lowest->getBandwidth())
+            lowest = *repIt;
+
+        if ( (*repIt)->getBandwidth() < maxbitrate &&
+             (*repIt)->getBandwidth() > minbitrate )
+        {
+            candidate = (*repIt);
+            minbitrate = (*repIt)->getBandwidth();
+        }
+    }
+
+    if (!candidate)
+        return candidate = lowest;
+
+    return candidate;
+}
diff --git a/modules/demux/dash/adaptationlogic/Representationselectors.hpp b/modules/demux/dash/adaptationlogic/Representationselectors.hpp
new file mode 100644 (file)
index 0000000..0d89c1f
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Representationselectors.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 REPRESENTATIONSELECTORS_HPP
+#define REPRESENTATIONSELECTORS_HPP
+#include "mpd/Representation.h"
+#include "mpd/Period.h"
+
+using namespace dash::mpd;
+
+namespace dash
+{
+    namespace logic
+    {
+
+        class RepresentationSelector
+        {
+        public:
+            RepresentationSelector();
+            virtual ~RepresentationSelector() {}
+            virtual Representation * select(Period *period, Streams::Type) const;
+            virtual Representation * select(Period *period, Streams::Type, uint64_t bitrate) const;
+            virtual Representation * select(Period *period, Streams::Type, uint64_t bitrate,
+                                            int width, int height) const;
+        protected:
+            virtual Representation * select(std::vector<Representation *>&reps,
+                                            uint64_t minbitrate, uint64_t maxbitrate) const;
+        };
+
+    }
+}
+
+#endif // REPRESENTATIONSELECTORS_HPP
diff --git a/modules/demux/dash/buffer/BlockBuffer.cpp b/modules/demux/dash/buffer/BlockBuffer.cpp
new file mode 100644 (file)
index 0000000..b7d5c5b
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * BlockBuffer.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "buffer/BlockBuffer.h"
+
+using namespace dash::buffer;
+
+BlockBuffer::BlockBuffer    () :
+             sizeBytes      (0),
+             isEOF          (false)
+
+{
+    fifo = block_FifoNew();
+    if(!fifo)
+        throw VLC_ENOMEM;
+}
+BlockBuffer::~BlockBuffer   ()
+{
+    block_FifoRelease(fifo);
+}
+
+int BlockBuffer::peek(const uint8_t **pp_peek, unsigned int len)
+{
+    block_t *p_block = block_FifoShow(fifo);
+    if(!p_block)
+        return 0;
+
+    *pp_peek = p_block->p_buffer;
+    return __MIN(len, p_block->i_buffer);
+}
+
+block_t * BlockBuffer::get()
+{
+    block_t *p_block = block_FifoGet(fifo);
+    if(p_block)
+        notify();
+    return p_block;
+}
+
+void BlockBuffer::put(block_t *block)
+{
+    block_FifoPut(fifo, block);
+    notify();
+}
+
+void BlockBuffer::setEOF(bool value)
+{
+    isEOF = value;
+    block_FifoWake(fifo);
+}
+
+bool BlockBuffer::getEOF()
+{
+    return isEOF;
+}
+
+void    BlockBuffer::attach               (IBufferObserver *observer)
+{
+    this->bufferObservers.push_back(observer);
+}
+void    BlockBuffer::notify               ()
+{
+//    for(size_t i = 0; i < this->bufferObservers.size(); i++)
+//        this->bufferObservers.at(i)->bufferLevelChanged(this->sizeMicroSec, ((float)this->sizeMicroSec / this->capacityMicroSec) * 100);
+}
diff --git a/modules/demux/dash/buffer/BlockBuffer.h b/modules/demux/dash/buffer/BlockBuffer.h
new file mode 100644 (file)
index 0000000..6913ff0
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * BlockBuffer.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 BLOCKBUFFER_H_
+#define BLOCKBUFFER_H_
+
+#include "buffer/IBufferObserver.h"
+
+#include <vlc_stream.h>
+#include <vector>
+
+#define DEFAULTBUFFERLENGTH 30000000
+#define INTIALPEEKSIZE      32768
+
+namespace dash
+{
+    namespace buffer
+    {
+        class BlockBuffer
+        {
+            public:
+                BlockBuffer           ();
+                virtual ~BlockBuffer  ();
+
+                void    put           (block_t *block);
+                block_t *get          ();
+                int     peek          (const uint8_t **pp_peek, unsigned int i_peek);
+                void    setEOF        (bool value);
+                bool    getEOF        ();
+                void    attach        (IBufferObserver *observer);
+                void    notify        ();
+
+            private:
+                size_t              sizeBytes;
+                bool                isEOF;
+                block_fifo_t        *fifo;
+
+                std::vector<IBufferObserver *> bufferObservers;
+        };
+    }
+}
+
+#endif /* BLOCKBUFFER_H_ */
diff --git a/modules/demux/dash/buffer/IBufferObserver.h b/modules/demux/dash/buffer/IBufferObserver.h
new file mode 100644 (file)
index 0000000..b12985b
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * IBufferObserver.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 IBUFFEROBSERVER_H_
+#define IBUFFEROBSERVER_H_
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+
+namespace dash
+{
+    namespace buffer
+    {
+        class IBufferObserver
+        {
+            public:
+                virtual ~IBufferObserver(){}
+                virtual void bufferLevelChanged(mtime_t bufferedMicroSec, int bufferedPercent) = 0;
+        };
+    }
+}
+
+#endif /* IBUFFEROBSERVER_H_ */
diff --git a/modules/demux/dash/dash.cpp b/modules/demux/dash/dash.cpp
new file mode 100644 (file)
index 0000000..8d397f7
--- /dev/null
@@ -0,0 +1,261 @@
+/*****************************************************************************
+ * dash.cpp: DASH module
+ *****************************************************************************
+ * Copyright © 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#define __STDC_CONSTANT_MACROS 1
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdint.h>
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_demux.h>
+#include <vlc_meta.h>
+
+#include <errno.h>
+
+#include "dash.hpp"
+#include "xml/DOMParser.h"
+#include "mpd/MPDFactory.h"
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+static int  Open    (vlc_object_t *);
+static void Close   (vlc_object_t *);
+
+#define DASH_WIDTH_TEXT N_("Preferred Width")
+#define DASH_WIDTH_LONGTEXT N_("Preferred Width")
+
+#define DASH_HEIGHT_TEXT N_("Preferred Height")
+#define DASH_HEIGHT_LONGTEXT N_("Preferred Height")
+
+#define DASH_BW_TEXT N_("Fixed Bandwidth in KiB/s")
+#define DASH_BW_LONGTEXT N_("Preferred bandwidth for non adaptative streams")
+
+#define DASH_LOGIC_TEXT N_("Adaptation Logic")
+
+static const int pi_logics[] = {dash::logic::IAdaptationLogic::RateBased,
+                                dash::logic::IAdaptationLogic::FixedRate,
+                                dash::logic::IAdaptationLogic::AlwaysLowest,
+                                dash::logic::IAdaptationLogic::AlwaysBest};
+
+static const char *const ppsz_logics[] = { N_("Bandwidth Adaptive"),
+                                           N_("Fixed Bandwidth"),
+                                           N_("Lowest Bandwidth/Quality"),
+                                           N_("Highest Bandwith/Quality")};
+
+vlc_module_begin ()
+        set_shortname( N_("DASH"))
+        set_description( N_("Dynamic Adaptive Streaming over HTTP") )
+        set_capability( "demux", 10 )
+        set_category( CAT_INPUT )
+        set_subcategory( SUBCAT_INPUT_DEMUX )
+        add_integer( "dash-logic",      dash::logic::IAdaptationLogic::Default,
+                                             DASH_LOGIC_TEXT, NULL, false )
+            change_integer_list( pi_logics, ppsz_logics )
+        add_integer( "dash-prefwidth",  480, DASH_WIDTH_TEXT,  DASH_WIDTH_LONGTEXT,  true )
+        add_integer( "dash-prefheight", 360, DASH_HEIGHT_TEXT, DASH_HEIGHT_LONGTEXT, true )
+        add_integer( "dash-prefbw",     250, DASH_BW_TEXT,     DASH_BW_LONGTEXT,     false )
+        set_callbacks( Open, Close )
+vlc_module_end ()
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+
+static int  Demux( demux_t * );
+static int  Control         (demux_t *p_demux, int i_query, va_list args);
+
+/*****************************************************************************
+ * Open:
+ *****************************************************************************/
+static int Open(vlc_object_t *p_obj)
+{
+    demux_t *p_demux = (demux_t*) p_obj;
+
+    bool b_mimematched = false;
+    char *psz_mime = stream_ContentType(p_demux->s);
+    if(psz_mime)
+    {
+        b_mimematched = !strcmp(psz_mime, "application/dash+xml");
+        free(psz_mime);
+    }
+
+    if(!b_mimematched && !dash::xml::DOMParser::isDash(p_demux->s))
+        return VLC_EGENERIC;
+
+    //Build a XML tree
+    dash::xml::DOMParser        parser(p_demux->s);
+    if( !parser.parse() )
+    {
+        msg_Err( p_demux, "Could not parse MPD" );
+        return VLC_EGENERIC;
+    }
+
+    //Begin the actual MPD parsing:
+    dash::mpd::MPD *mpd = dash::mpd::MPDFactory::create(parser.getRootNode(), p_demux->s, parser.getProfile());
+    if(mpd == NULL)
+    {
+        msg_Err( p_demux, "Cannot create/unknown MPD for profile");
+        return VLC_EGENERIC;
+    }
+
+    demux_sys_t        *p_sys = (demux_sys_t *) malloc(sizeof(demux_sys_t));
+    if (unlikely(p_sys == NULL))
+        return VLC_ENOMEM;
+
+    p_sys->p_mpd = mpd;
+    int logic = var_InheritInteger( p_obj, "dash-logic" );
+    dash::DASHManager*p_dashManager = new dash::DASHManager(p_sys->p_mpd,
+            static_cast<dash::logic::IAdaptationLogic::LogicType>(logic),
+            p_demux->s);
+
+    dash::mpd::Period *period = mpd->getFirstPeriod();
+    if(period && !p_dashManager->start(p_demux))
+    {
+        delete p_dashManager;
+        free( p_sys );
+        return VLC_EGENERIC;
+    }
+    p_sys->p_dashManager    = p_dashManager;
+    p_demux->p_sys         = p_sys;
+    p_demux->pf_demux      = Demux;
+    p_demux->pf_control    = Control;
+
+    msg_Dbg(p_obj,"opening mpd file (%s)", p_demux->s->psz_path);
+
+    return VLC_SUCCESS;
+}
+/*****************************************************************************
+ * Close:
+ *****************************************************************************/
+static void Close(vlc_object_t *p_obj)
+{
+    demux_t                            *p_demux       = (demux_t*) p_obj;
+    demux_sys_t                        *p_sys          = (demux_sys_t *) p_demux->p_sys;
+    dash::DASHManager                   *p_dashManager  = p_sys->p_dashManager;
+
+    delete p_dashManager;
+    free(p_sys);
+}
+/*****************************************************************************
+ * Callbacks:
+ *****************************************************************************/
+static int Demux(demux_t *p_demux)
+{
+    demux_sys_t *p_sys = p_demux->p_sys;
+    if ( p_sys->p_dashManager->read() > 0 )
+    {
+        if ( p_sys->p_dashManager->esCount() )
+        {
+            mtime_t pcr = p_sys->p_dashManager->getPCR();
+            int group = p_sys->p_dashManager->getGroup();
+            if(group > 0)
+                es_out_Control(p_demux->out, ES_OUT_SET_GROUP_PCR, group, pcr);
+            else
+                es_out_Control(p_demux->out, ES_OUT_SET_PCR, pcr);
+        }
+        return VLC_DEMUXER_SUCCESS;
+    }
+    else
+        return VLC_DEMUXER_EOF;
+}
+
+static int  Control         (demux_t *p_demux, int i_query, va_list args)
+{
+    demux_sys_t *p_sys = p_demux->p_sys;
+
+    switch (i_query)
+    {
+        case DEMUX_CAN_SEEK:
+            *(va_arg (args, bool *)) = false;
+            break;
+
+        case DEMUX_CAN_CONTROL_PACE:
+            *(va_arg (args, bool *)) = true;
+            break;
+
+        case DEMUX_CAN_PAUSE:
+            *(va_arg (args, bool *)) = p_sys->p_mpd->isLive();
+            break;
+
+        case DEMUX_GET_TIME:
+            *(va_arg (args, int64_t *)) = p_sys->p_dashManager->getPCR();
+            break;
+
+        case DEMUX_GET_LENGTH:
+            *(va_arg (args, int64_t *)) = p_sys->p_dashManager->getDuration();
+            break;
+
+        case DEMUX_GET_POSITION:
+            if(!p_sys->p_dashManager->getDuration())
+                return VLC_EGENERIC;
+
+            *(va_arg (args, double *)) = (double) p_sys->p_dashManager->getPCR()
+                                         / p_sys->p_dashManager->getDuration();
+            break;
+
+        case DEMUX_GET_PTS_DELAY:
+            *va_arg (args, int64_t *) = INT64_C(1000) *
+                var_InheritInteger(p_demux, "network-caching");
+             break;
+
+        case DEMUX_GET_META:
+        {
+            if(!p_sys->p_mpd->getProgramInformation())
+                break;
+
+            vlc_meta_t *p_meta = (vlc_meta_t *) va_arg (args, vlc_meta_t*);
+            vlc_meta_t *meta = vlc_meta_New();
+            if (meta == NULL)
+                return VLC_EGENERIC;
+
+            if(!p_sys->p_mpd->getProgramInformation()->getTitle().empty())
+                vlc_meta_SetTitle(meta, p_sys->p_mpd->getProgramInformation()->getTitle().c_str());
+
+            if(!p_sys->p_mpd->getProgramInformation()->getSource().empty())
+                vlc_meta_SetPublisher(meta, p_sys->p_mpd->getProgramInformation()->getSource().c_str());
+
+            if(!p_sys->p_mpd->getProgramInformation()->getCopyright().empty())
+                vlc_meta_SetCopyright(meta, p_sys->p_mpd->getProgramInformation()->getCopyright().c_str());
+
+            if(!p_sys->p_mpd->getProgramInformation()->getMoreInformationUrl().empty())
+                vlc_meta_SetURL(meta, p_sys->p_mpd->getProgramInformation()->getMoreInformationUrl().c_str());
+
+            vlc_meta_Merge(p_meta, meta);
+            vlc_meta_Delete(meta);
+            break;
+        }
+
+        default:
+            return VLC_EGENERIC;
+    }
+    return VLC_SUCCESS;
+}
diff --git a/modules/demux/dash/dash.hpp b/modules/demux/dash/dash.hpp
new file mode 100644 (file)
index 0000000..3aaf3cd
--- /dev/null
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ * dash.hpp: DASH module
+ *****************************************************************************
+ * Copyright © 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 "DASHManager.h"
+
+struct demux_sys_t
+{
+        dash::DASHManager   *p_dashManager;
+        dash::mpd::MPD      *p_mpd;
+};
diff --git a/modules/demux/dash/http/Chunk.cpp b/modules/demux/dash/http/Chunk.cpp
new file mode 100644 (file)
index 0000000..0e3f157
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * Chunk.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "Chunk.h"
+
+using namespace dash::http;
+
+Chunk::Chunk        (const std::string& url) :
+       startByte    (0),
+       endByte      (0),
+       bitrate      (1),
+       port         (0),
+       length       (0),
+       bytesRead    (0),
+       bytesToRead  (0),
+       connection   (NULL)
+{
+    this->url = url;
+
+    if(url.compare(0, 7, "http://"))
+        throw VLC_EGENERIC;
+
+    vlc_url_t url_components;
+    vlc_UrlParse(&url_components, url.c_str(), 0);
+
+    if(url_components.psz_path)
+        path = url_components.psz_path;
+    port = url_components.i_port ? url_components.i_port : 80;
+    if(url_components.psz_host)
+        hostname = url_components.psz_host;
+
+    vlc_UrlClean(&url_components);
+
+    if(path.empty() || hostname.empty())
+        throw VLC_EGENERIC;
+}
+
+size_t              Chunk::getEndByte           () const
+{
+    return endByte;
+}
+size_t              Chunk::getStartByte         () const
+{
+    return startByte;
+}
+const std::string&  Chunk::getUrl               () const
+{
+    return url;
+}
+void                Chunk::setEndByte           (size_t endByte)
+{
+    this->endByte = endByte;
+    if (endByte > startByte)
+        bytesToRead = endByte - startByte;
+}
+void                Chunk::setStartByte         (size_t startByte)
+{
+    this->startByte = startByte;
+    if (endByte > startByte)
+        bytesToRead = endByte - startByte;
+}
+void                Chunk::addOptionalUrl       (const std::string& url)
+{
+    this->optionalUrls.push_back(url);
+}
+bool                Chunk::usesByteRange        () const
+{
+    return (startByte != endByte);
+}
+
+void                Chunk::setBitrate           (uint64_t bitrate)
+{
+    this->bitrate = bitrate;
+}
+int                 Chunk::getBitrate           ()
+{
+    return this->bitrate;
+}
+const std::string&  Chunk::getHostname          () const
+{
+    return hostname;
+}
+const std::string&  Chunk::getPath              () const
+{
+    return this->path;
+}
+int                 Chunk::getPort              () const
+{
+    return this->port;
+}
+uint64_t            Chunk::getLength            () const
+{
+    return this->length;
+}
+void                Chunk::setLength            (uint64_t length)
+{
+    this->length = length;
+}
+uint64_t            Chunk::getBytesRead         () const
+{
+    return this->bytesRead;
+}
+void                Chunk::setBytesRead         (uint64_t bytes)
+{
+    this->bytesRead = bytes;
+}
+
+void                Chunk::setBytesToRead         (uint64_t bytes)
+{
+    bytesToRead = bytes;
+}
+
+uint64_t            Chunk::getBytesToRead       () const
+{
+        return length - bytesRead;
+}
+
+size_t              Chunk::getPercentDownloaded () const
+{
+    return (size_t)(((float)this->bytesRead / this->length) * 100);
+}
+HTTPConnection*     Chunk::getConnection           () const
+{
+    return this->connection;
+}
+void                Chunk::setConnection   (HTTPConnection *connection)
+{
+    this->connection = connection;
+}
diff --git a/modules/demux/dash/http/Chunk.h b/modules/demux/dash/http/Chunk.h
new file mode 100644 (file)
index 0000000..86a5aba
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Chunk.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 CHUNK_H_
+#define CHUNK_H_
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_url.h>
+
+#include "HTTPConnection.h"
+
+#include <vector>
+#include <string>
+#include <stdint.h>
+
+namespace dash
+{
+    namespace http
+    {
+        class Chunk
+        {
+            public:
+                Chunk           (const std::string &url);
+                virtual ~Chunk  () {}
+
+                size_t              getEndByte              () const;
+                size_t              getStartByte            () const;
+                const std::string&  getUrl                  () const;
+                const std::string&  getHostname             () const;
+                const std::string&  getPath                 () const;
+                int                 getPort                 () const;
+                uint64_t            getLength               () const;
+                uint64_t            getBytesRead            () const;
+                uint64_t            getBytesToRead          () const;
+                size_t              getPercentDownloaded    () const;
+                HTTPConnection*     getConnection           () const;
+
+                void                setConnection   (HTTPConnection *connection);
+                void                setBytesRead    (uint64_t bytes);
+                void                setBytesToRead  (uint64_t bytes);
+                void                setLength       (uint64_t length);
+                void                setEndByte      (size_t endByte);
+                void                setStartByte    (size_t startByte);
+                void                addOptionalUrl  (const std::string& url);
+                bool                usesByteRange   () const;
+                void                setBitrate      (uint64_t bitrate);
+                int                 getBitrate      ();
+
+                virtual void        onDownload      (void *, size_t) {}
+
+            private:
+                std::string                 url;
+                std::string                 path;
+                std::string                 hostname;
+                std::vector<std::string>    optionalUrls;
+                size_t                      startByte;
+                size_t                      endByte;
+                int                         bitrate;
+                int                         port;
+                uint64_t                    length;
+                uint64_t                    bytesRead;
+                uint64_t                    bytesToRead;
+                HTTPConnection             *connection;
+        };
+    }
+}
+
+#endif /* CHUNK_H_ */
diff --git a/modules/demux/dash/http/HTTPConnection.cpp b/modules/demux/dash/http/HTTPConnection.cpp
new file mode 100644 (file)
index 0000000..32746f0
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * HTTPConnection.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "HTTPConnection.h"
+#include "Chunk.h"
+
+#include <sstream>
+
+using namespace dash::http;
+
+HTTPConnection::HTTPConnection  (stream_t *stream, Chunk *chunk_) :
+                IHTTPConnection (stream)
+{
+    toRead = 0;
+    chunk = NULL;
+    bindChunk(chunk_);
+}
+
+std::string HTTPConnection::buildRequestHeader(const std::string &path) const
+{
+    std::string req = IHTTPConnection::buildRequestHeader(path);
+    return req.append("Connection: close\r\n");
+}
+
+void HTTPConnection::bindChunk(Chunk *chunk_)
+{
+    if(chunk_ == chunk)
+        return;
+    if (chunk_)
+        chunk_->setConnection(this);
+    chunk = chunk_;
+}
+
+void HTTPConnection::releaseChunk()
+{
+    if(chunk)
+    {
+        chunk->setConnection(NULL);
+        chunk = NULL;
+    }
+}
+
+void HTTPConnection::onHeader(const std::string &key,
+                              const std::string &value)
+{
+    if(key == "Content-Length")
+    {
+        std::istringstream ss(value);
+        size_t length;
+        ss >> length;
+        chunk->setLength(length);
+        toRead = length;
+    }
+}
+
+std::string HTTPConnection::extraRequestHeaders() const
+{
+    std::stringstream ss;
+    if(chunk->usesByteRange())
+    {
+        ss << "Range: bytes=" << chunk->getStartByte() << "-";
+        if(chunk->getEndByte())
+            ss << chunk->getEndByte();
+        ss << "\r\n";
+    }
+    return ss.str();
+}
+
+bool HTTPConnection::isAvailable() const
+{
+    return chunk == NULL;
+}
+
+void HTTPConnection::disconnect()
+{
+    toRead = 0;
+}
diff --git a/modules/demux/dash/http/HTTPConnection.h b/modules/demux/dash/http/HTTPConnection.h
new file mode 100644 (file)
index 0000000..8171012
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * HTTPConnection.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 HTTPCONNECTION_H_
+#define HTTPCONNECTION_H_
+
+#include <string>
+
+#include "http/IHTTPConnection.h"
+#include "Helper.h"
+
+namespace dash
+{
+    namespace http
+    {
+        class Chunk;
+        class HTTPConnection : public IHTTPConnection
+        {
+            public:
+                HTTPConnection          (stream_t *stream, Chunk *chunk = NULL);
+                virtual void    bindChunk   (Chunk *chunk);
+                virtual void    onHeader    (const std::string &line,
+                                             const std::string &value);
+                virtual bool    isAvailable () const;
+                virtual void    disconnect  ();
+                virtual void    releaseChunk();
+
+            protected:
+                size_t toRead;
+                Chunk *chunk;
+                virtual std::string extraRequestHeaders() const;
+                virtual std::string buildRequestHeader(const std::string &path) const;
+        };
+    }
+}
+
+#endif /* HTTPCONNECTION_H_ */
diff --git a/modules/demux/dash/http/HTTPConnectionManager.cpp b/modules/demux/dash/http/HTTPConnectionManager.cpp
new file mode 100644 (file)
index 0000000..65318be
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * HTTPConnectionManager.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "HTTPConnectionManager.h"
+#include "http/Chunk.h"
+
+#include <vlc_stream.h>
+
+using namespace dash::http;
+
+const uint64_t  HTTPConnectionManager::CHUNKDEFAULTBITRATE    = 1;
+
+HTTPConnectionManager::HTTPConnectionManager    (stream_t *stream) :
+                       stream                   (stream)
+{
+}
+HTTPConnectionManager::~HTTPConnectionManager   ()
+{
+    this->closeAllConnections();
+}
+
+void                                HTTPConnectionManager::closeAllConnections      ()
+{
+    releaseAllConnections();
+    vlc_delete_all(this->connectionPool);
+}
+
+void HTTPConnectionManager::releaseAllConnections()
+{
+    std::vector<PersistentConnection *>::iterator it;
+    for(it = connectionPool.begin(); it != connectionPool.end(); it++)
+        (*it)->releaseChunk();
+}
+
+PersistentConnection * HTTPConnectionManager::getConnectionForHost(const std::string &hostname)
+{
+    std::vector<PersistentConnection *>::const_iterator it;
+    for(it = connectionPool.begin(); it != connectionPool.end(); it++)
+    {
+        if(!(*it)->getHostname().compare(hostname) && (*it)->isAvailable())
+            return *it;
+    }
+    return NULL;
+}
+
+bool HTTPConnectionManager::connectChunk(Chunk *chunk)
+{
+    if(chunk == NULL)
+        return false;
+    if(chunk->getConnection())
+        return true;
+
+    msg_Dbg(stream, "Retrieving %s", chunk->getUrl().c_str());
+
+    PersistentConnection *conn = getConnectionForHost(chunk->getHostname());
+    if(!conn)
+    {
+        conn = new PersistentConnection(stream, chunk);
+        if(!conn)
+            return false;
+        connectionPool.push_back(conn);
+        if (!chunk->getConnection()->connect(chunk->getHostname(), chunk->getPort()))
+            return false;
+    }
+
+    conn->bindChunk(chunk);
+
+    if(chunk->getBitrate() <= 0)
+        chunk->setBitrate(HTTPConnectionManager::CHUNKDEFAULTBITRATE);
+
+    return true;
+}
diff --git a/modules/demux/dash/http/HTTPConnectionManager.h b/modules/demux/dash/http/HTTPConnectionManager.h
new file mode 100644 (file)
index 0000000..2232a1e
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * HTTPConnectionManager.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 HTTPCONNECTIONMANAGER_H_
+#define HTTPCONNECTIONMANAGER_H_
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "http/PersistentConnection.h"
+#include "adaptationlogic/IDownloadRateObserver.h"
+
+#include <vlc_common.h>
+#include <vector>
+
+namespace dash
+{
+    namespace http
+    {
+        class HTTPConnectionManager
+        {
+            public:
+                HTTPConnectionManager           (stream_t *stream);
+                virtual ~HTTPConnectionManager  ();
+
+                void    closeAllConnections ();
+                void    releaseAllConnections ();
+                bool    connectChunk        (Chunk *chunk);
+
+            private:
+                std::vector<PersistentConnection *>                 connectionPool;
+                stream_t                                            *stream;
+
+                static const uint64_t   CHUNKDEFAULTBITRATE;
+
+                PersistentConnection *                  getConnectionForHost    (const std::string &hostname);
+        };
+    }
+}
+
+#endif /* HTTPCONNECTIONMANAGER_H_ */
diff --git a/modules/demux/dash/http/IHTTPConnection.cpp b/modules/demux/dash/http/IHTTPConnection.cpp
new file mode 100644 (file)
index 0000000..8e1074e
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * IHTTPConnection.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 "IHTTPConnection.h"
+#include "Chunk.h"
+#include "Helper.h"
+#include "dash.hpp"
+
+#include <vlc_network.h>
+#include <vlc_stream.h>
+
+#include <sstream>
+
+using namespace dash::http;
+
+IHTTPConnection::IHTTPConnection(stream_t *stream_)
+{
+    stream = stream_;
+    httpSocket = -1;
+    psz_useragent = var_InheritString(stream, "http-user-agent");
+}
+
+IHTTPConnection::~IHTTPConnection()
+{
+    disconnect();
+    free(psz_useragent);
+}
+
+bool IHTTPConnection::connect(const std::string &hostname, int port)
+{
+    httpSocket = net_ConnectTCP(stream, hostname.c_str(), port);
+    this->hostname = hostname;
+
+    if(httpSocket == -1)
+        return false;
+
+    return true;
+}
+
+bool IHTTPConnection::connected() const
+{
+    return (httpSocket != -1);
+}
+
+void IHTTPConnection::disconnect()
+{
+    if (httpSocket >= 0)
+    {
+        net_Close(httpSocket);
+        httpSocket = -1;
+    }
+}
+
+bool IHTTPConnection::query(const std::string &path)
+{
+    std::string header = buildRequestHeader(path);
+    header.append("\r\n");
+    if (!send( header ) || !parseReply())
+        return false;
+    return true;
+}
+
+ssize_t IHTTPConnection::read(void *p_buffer, size_t len)
+{
+    ssize_t size = net_Read(stream, httpSocket, NULL, p_buffer, len, true);
+    if(size <= 0)
+        return -1;
+    else
+        return size;
+}
+
+bool IHTTPConnection::send(const std::string &data)
+{
+    return send(data.c_str(), data.length());
+}
+
+bool IHTTPConnection::send(const void *buf, size_t size)
+{
+    if (size == 0)
+        return true;
+
+    if (httpSocket == -1)
+        return false;
+
+    ssize_t ret = net_Write(stream, httpSocket, NULL, buf, size);
+    if (ret <= 0)
+        return false;
+
+    if ( (size_t)ret < size )
+        send( ((uint8_t*)buf) + ret, size - ret );
+
+    return true;
+}
+
+bool IHTTPConnection::parseReply()
+{
+    std::string line = readLine();
+
+    if(line.empty())
+        return false;
+
+    if (line.compare(0, 9, "HTTP/1.1 ")!=0)
+        return false;
+
+    std::istringstream ss(line.substr(9));
+    int replycode;
+    ss >> replycode;
+    if (replycode != 200 && replycode != 206)
+        return false;
+
+    readLine();
+
+    while(!line.empty() && line.compare("\r\n"))
+    {
+        size_t split = line.find_first_of(':');
+        size_t value = split + 1;
+
+        while(line.at(value) == ' ')
+            value++;
+
+        onHeader(line.substr(0, split), line.substr(value));
+        line = readLine();
+    }
+
+    return true;
+}
+
+std::string IHTTPConnection::readLine()
+{
+    std::stringstream ss;
+    char c[1];
+    ssize_t size = net_Read(stream, httpSocket, NULL, c, 1, false);
+
+    while(size >= 0)
+    {
+        ss << c[0];
+        if(c[0] == '\n')
+            break;
+
+        size = net_Read(stream, httpSocket, NULL, c, 1, false);
+    }
+
+    if(size > 0)
+        return ss.str();
+
+    return "";
+}
+
+std::string IHTTPConnection::buildRequestHeader(const std::string &path) const
+{
+    std::stringstream req;
+    req << "GET " << path << " HTTP/1.1\r\n" <<
+           "Host: " << hostname << "\r\n" <<
+           "User-Agent: " << std::string(psz_useragent) << "\r\n";
+    req << extraRequestHeaders();
+    return req.str();
+}
diff --git a/modules/demux/dash/http/IHTTPConnection.h b/modules/demux/dash/http/IHTTPConnection.h
new file mode 100644 (file)
index 0000000..c3e597f
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * IHTTPConnection.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 IHTTPCONNECTION_H_
+#define IHTTPCONNECTION_H_
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <string>
+
+namespace dash
+{
+    namespace http
+    {
+        class IHTTPConnection
+        {
+            public:
+                IHTTPConnection(stream_t *stream);
+                virtual ~IHTTPConnection();
+
+                virtual bool    connect     (const std::string& hostname, int port = 80);
+                virtual bool    connected   () const;
+                virtual bool    query       (const std::string& path);
+                virtual bool    send        (const void *buf, size_t size);
+                virtual ssize_t read        (void *p_buffer, size_t len);
+                virtual void    disconnect  ();
+                virtual bool    send        (const std::string &data);
+
+            protected:
+
+                virtual void    onHeader    (const std::string &key,
+                                             const std::string &value) = 0;
+                virtual std::string extraRequestHeaders() const = 0;
+                virtual std::string buildRequestHeader(const std::string &path) const;
+
+                bool parseReply();
+                std::string readLine();
+                std::string hostname;
+                char * psz_useragent;
+                stream_t   *stream;
+
+            private:
+                int         httpSocket;
+        };
+    }
+}
+
+#endif /* IHTTPCONNECTION_H_ */
diff --git a/modules/demux/dash/http/PersistentConnection.cpp b/modules/demux/dash/http/PersistentConnection.cpp
new file mode 100644 (file)
index 0000000..4ea965d
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * PersistentConnection.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2012 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "PersistentConnection.h"
+#include "Chunk.h"
+
+#include <vlc_network.h>
+
+using namespace dash::http;
+
+PersistentConnection::PersistentConnection  (stream_t *stream, Chunk *chunk) :
+                      HTTPConnection        (stream, chunk)
+{
+    queryOk = false;
+    retries = 0;
+}
+#include <cassert>
+ssize_t PersistentConnection::read(void *p_buffer, size_t len)
+{
+    if(!chunk)
+        return -1;
+
+    if(len == 0)
+        return 0;
+
+    if(chunk->getBytesRead() == 0 && !queryOk)
+    {
+        if(!query(chunk->getPath()))
+            return -1;
+    }
+
+    assert(connected() && queryOk);
+
+    if(chunk->getBytesToRead() == 0)
+        return 0;
+
+    if(len > chunk->getBytesToRead())
+        len = chunk->getBytesToRead();
+
+    ssize_t ret = IHTTPConnection::read(p_buffer, len);
+    if(ret <= 0)
+    {
+        chunk->setStartByte(chunk->getStartByte() + chunk->getBytesRead());
+        chunk->setBytesRead(0);
+        disconnect();
+        if(retries++ == retryCount || !query(chunk->getPath()))
+            return -1;
+
+        return read(p_buffer, len);
+    }
+
+    retries = 0;
+    chunk->setBytesRead(chunk->getBytesRead() + ret);
+
+    return ret;
+}
+
+bool PersistentConnection::query(const std::string &path)
+{
+    if(!connected() &&
+       !connect(chunk->getHostname(), chunk->getPort()))
+        return false;
+
+    queryOk = IHTTPConnection::query(path);
+    return queryOk;
+}
+
+bool PersistentConnection::connect(const std::string &hostname, int port)
+{
+    assert(!connected());
+    assert(!queryOk);
+    return IHTTPConnection::connect(hostname, port);
+}
+
+void PersistentConnection::releaseChunk()
+{
+    if(!chunk)
+        return;
+    if(toRead > 0 && connected()) /* We can't resend request if we haven't finished reading */
+        disconnect();
+    HTTPConnection::releaseChunk();
+}
+
+void PersistentConnection::disconnect()
+{
+    queryOk = false;
+    IHTTPConnection::disconnect();
+}
+
+const std::string& PersistentConnection::getHostname() const
+{
+    return hostname;
+}
+
+std::string PersistentConnection::buildRequestHeader(const std::string &path) const
+{
+    return IHTTPConnection::buildRequestHeader(path);
+}
diff --git a/modules/demux/dash/http/PersistentConnection.h b/modules/demux/dash/http/PersistentConnection.h
new file mode 100644 (file)
index 0000000..0a6f9db
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * PersistentConnection.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2012 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 PERSISTENTCONNECTION_H_
+#define PERSISTENTCONNECTION_H_
+
+#include "HTTPConnection.h"
+#include <deque>
+
+namespace dash
+{
+    namespace http
+    {
+        class PersistentConnection : public HTTPConnection
+        {
+            public:
+                PersistentConnection(stream_t *stream, Chunk *chunk = NULL);
+
+                virtual bool        connect     (const std::string &hostname, int port = 80);
+                virtual bool        query       (const std::string& path);
+                virtual ssize_t     read        (void *p_buffer, size_t len);
+                virtual void        disconnect  ();
+                virtual void        releaseChunk();
+
+                const std::string&  getHostname () const;
+
+            private:
+                bool                queryOk;
+                int                 retries;
+
+            protected:
+                static const int    retryCount = 5;
+                virtual std::string buildRequestHeader(const std::string &path) const;
+        };
+    }
+}
+
+#endif /* PERSISTENTCONNECTION_H_ */
diff --git a/modules/demux/dash/mp4/AtomsReader.cpp b/modules/demux/dash/mp4/AtomsReader.cpp
new file mode 100644 (file)
index 0000000..d7333d7
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * 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(vlc_object_t *object_)
+{
+    object = object_;
+    rootbox = NULL;
+}
+
+AtomsReader::~AtomsReader()
+{
+    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, Representation *rep)
+{
+    if(!rep)
+        return false;
+
+    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)
+            {
+                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; i++)
+                {
+                    splitlist.push_back(point);
+                    point.offset += sidx->p_items[i].i_referenced_size;
+                    point.time += sidx->p_items[i].i_subsegment_duration;
+                }
+                rep->SplitUsingIndex(splitlist);
+            }
+        }
+        stream_Delete(stream);
+    }
+
+    return true;
+}
diff --git a/modules/demux/dash/mp4/AtomsReader.hpp b/modules/demux/dash/mp4/AtomsReader.hpp
new file mode 100644 (file)
index 0000000..507e98a
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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 <vlc_common.h>
+#include <vlc_stream.h>
+extern "C" {
+#include "../../demux/mp4/libmp4.h"
+}
+
+namespace dash
+{
+    namespace mpd
+    {
+        class Representation;
+    }
+    namespace mp4
+    {
+        class AtomsReader
+        {
+            public:
+                AtomsReader(vlc_object_t *);
+                ~AtomsReader();
+                bool parseBlock(void *, size_t, dash::mpd::Representation *);
+
+            protected:
+                vlc_object_t *object;
+                MP4_Box_t *rootbox;
+        };
+    }
+}
+
+#endif // ATOMSREADER_HPP
diff --git a/modules/demux/dash/mpd/AdaptationSet.cpp b/modules/demux/dash/mpd/AdaptationSet.cpp
new file mode 100644 (file)
index 0000000..306d73c
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * AdaptationSet.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "AdaptationSet.h"
+
+#include <vlc_common.h>
+#include <vlc_arrays.h>
+
+#include "SegmentTemplate.h"
+#include "SegmentInfoDefault.h"
+#include "Period.h"
+
+using namespace dash::mpd;
+
+AdaptationSet::AdaptationSet(Period *period) :
+    SegmentInformation( period ),
+    subsegmentAlignmentFlag( false ),
+    segmentInfoDefault( NULL ),
+    isBitstreamSwitching( false )
+{
+}
+
+AdaptationSet::~AdaptationSet   ()
+{
+    delete this->segmentInfoDefault;
+    vlc_delete_all( this->representations );
+}
+
+const std::string& AdaptationSet::getMimeType() const
+{
+    if (mimeType.empty() && !representations.empty())
+        return representations.front()->getMimeType();
+    else
+        return mimeType;
+}
+
+bool                AdaptationSet::getSubsegmentAlignmentFlag() const
+{
+    return this->subsegmentAlignmentFlag;
+}
+
+void AdaptationSet::setSubsegmentAlignmentFlag(bool alignment)
+{
+    this->subsegmentAlignmentFlag = alignment;
+}
+
+std::vector<Representation*>&    AdaptationSet::getRepresentations       ()
+{
+    return this->representations;
+}
+
+const Representation *AdaptationSet::getRepresentationById(const std::string &id) const
+{
+    std::vector<Representation*>::const_iterator    it = this->representations.begin();
+    std::vector<Representation*>::const_iterator    end = this->representations.end();
+
+    while ( it != end )
+    {
+        if ( (*it)->getId() == id )
+            return *it;
+        ++it;
+    }
+    return NULL;
+}
+
+const SegmentInfoDefault *AdaptationSet::getSegmentInfoDefault() const
+{
+    return this->segmentInfoDefault;
+}
+
+void AdaptationSet::setSegmentInfoDefault(const SegmentInfoDefault *seg)
+{
+    if ( seg != NULL )
+        this->segmentInfoDefault = seg;
+}
+
+void                            AdaptationSet::addRepresentation        (Representation *rep)
+{
+    this->representations.push_back(rep);
+}
+
+
+void AdaptationSet::setBitstreamSwitching  (bool value)
+{
+    this->isBitstreamSwitching = value;
+}
+
+bool AdaptationSet::getBitstreamSwitching  () const
+{
+    return this->isBitstreamSwitching;
+}
+
+Url AdaptationSet::getUrlSegment() const
+{
+    return getParentUrlSegment();
+}
+
+std::vector<std::string> AdaptationSet::toString(int indent) const
+{
+    std::vector<std::string> ret;
+    std::string text(indent, ' ');
+    text.append("AdaptationSet");
+    ret.push_back(text);
+    std::vector<Representation *>::const_iterator k;
+    for(k = representations.begin(); k != representations.end(); k++)
+    {
+        std::vector<std::string> debug = (*k)->toString(indent + 1);
+        ret.insert(ret.end(), debug.begin(), debug.end());
+    }
+    return ret;
+}
diff --git a/modules/demux/dash/mpd/AdaptationSet.h b/modules/demux/dash/mpd/AdaptationSet.h
new file mode 100644 (file)
index 0000000..e47ecda
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * AdaptationSet.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 ADAPTATIONSET_H_
+#define ADAPTATIONSET_H_
+
+#include <vector>
+#include <string>
+#include <map>
+
+#include "mpd/Representation.h"
+#include "mpd/CommonAttributesElements.h"
+#include "mpd/SegmentInformation.hpp"
+
+namespace dash
+{
+    namespace mpd
+    {
+        class SegmentInfoDefault;
+        class Period;
+        class SegmentTemplate;
+
+        class AdaptationSet : public CommonAttributesElements,
+                              public SegmentInformation
+        {
+            public:
+                AdaptationSet(Period *);
+                virtual ~AdaptationSet();
+
+                virtual const std::string&      getMimeType() const; /*reimpl*/
+                bool                            getSubsegmentAlignmentFlag() const;
+                void                            setSubsegmentAlignmentFlag( bool alignment );
+                std::vector<Representation *>&  getRepresentations      ();
+                const Representation*           getRepresentationById   ( const std::string &id ) const;
+                const SegmentInfoDefault*       getSegmentInfoDefault() const;
+                void                            setSegmentInfoDefault( const SegmentInfoDefault* seg );
+                void                            setBitstreamSwitching(bool value);
+                bool                            getBitstreamSwitching() const;
+                void                            addRepresentation( Representation *rep );
+                virtual Url                     getUrlSegment() const; /* reimpl */
+                std::vector<std::string>        toString(int = 0) const;
+
+            private:
+                bool                            subsegmentAlignmentFlag;
+                std::vector<Representation *>   representations;
+                const SegmentInfoDefault*       segmentInfoDefault;
+                bool                            isBitstreamSwitching;
+        };
+    }
+}
+
+#endif /* ADAPTATIONSET_H_ */
diff --git a/modules/demux/dash/mpd/BaseUrl.h b/modules/demux/dash/mpd/BaseUrl.h
new file mode 100644 (file)
index 0000000..08e8203
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * BaseUrl.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 BASEURL_H_
+#define BASEURL_H_
+
+#include <string>
+
+namespace dash
+{
+    namespace mpd
+    {
+        class BaseUrl
+        {
+            public:
+            BaseUrl         (const std::string& url) : url(url) {}
+                virtual ~BaseUrl()                  {}
+
+                const std::string& getUrl() const { return this->url; }
+
+            private:
+                std::string url;
+        };
+    }
+}
+
+#endif /* BASEURL_H_ */
diff --git a/modules/demux/dash/mpd/CommonAttributesElements.cpp b/modules/demux/dash/mpd/CommonAttributesElements.cpp
new file mode 100644 (file)
index 0000000..a27bab8
--- /dev/null
@@ -0,0 +1,194 @@
+/*****************************************************************************
+ * CommonAttributesElements.cpp: Defines the common attributes and elements
+ *                               for some Dash elements.
+ *****************************************************************************
+ * Copyright © 2011 VideoLAN
+ *
+ * Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "CommonAttributesElements.h"
+
+#include "mpd/ContentDescription.h"
+
+#include <vlc_common.h>
+#include <vlc_arrays.h>
+
+using namespace dash::mpd;
+
+CommonAttributesElements::CommonAttributesElements() :
+    width( -1 ),
+    height( -1 ),
+    parX( 1 ),
+    parY( 1 ),
+    frameRate( -1 )
+{
+}
+
+CommonAttributesElements::~CommonAttributesElements()
+{
+    vlc_delete_all( this->contentProtections );
+    vlc_delete_all( this->accessibilities );
+    vlc_delete_all( this->ratings );
+    vlc_delete_all( this->viewpoints );
+}
+
+const std::string&      CommonAttributesElements::getMimeType() const
+{
+    return this->mimeType;
+}
+
+void                    CommonAttributesElements::setMimeType( const std::string &mimeType )
+{
+    this->mimeType = mimeType;
+}
+
+int     CommonAttributesElements::getWidth                () const
+{
+    return this->width;
+}
+
+void    CommonAttributesElements::setWidth( int width )
+{
+    if ( width > 0 )
+        this->width = width;
+}
+
+int     CommonAttributesElements::getHeight               () const
+{
+    return this->height;
+}
+
+void    CommonAttributesElements::setHeight( int height )
+{
+    if ( height > 0 )
+        this->height = height;
+}
+
+int     CommonAttributesElements::getParX                 () const
+{
+    return this->parX;
+}
+
+void    CommonAttributesElements::setParX( int parX )
+{
+    if ( parX > 0 )
+        this->parX = parX;
+}
+
+int         CommonAttributesElements::getParY                 () const
+{
+    return this->parY;
+}
+
+void        CommonAttributesElements::setParY( int parY )
+{
+    if ( parY > 0 )
+        this->setParY( parY );
+}
+
+const std::list<std::string>& CommonAttributesElements::getLang() const
+{
+    return this->lang;
+}
+
+void    CommonAttributesElements::addLang( const std::string &lang )
+{
+    if ( lang.empty() == false )
+        this->lang.push_back( lang );
+}
+
+int                 CommonAttributesElements::getFrameRate            () const
+{
+    return this->frameRate;
+}
+
+void            CommonAttributesElements::setFrameRate( int frameRate )
+{
+    if ( frameRate > 0 )
+        this->frameRate = frameRate;
+}
+
+const std::list<std::string>&   CommonAttributesElements::getNumberOfChannels() const
+{
+    return this->channels;
+}
+
+void    CommonAttributesElements::addChannel( const std::string &channel )
+{
+    if ( channel.empty() == false )
+        this->channels.push_back( channel );
+}
+
+const std::list<int>&   CommonAttributesElements::getSamplingRates() const
+{
+    return this->sampleRates;
+}
+
+void    CommonAttributesElements::addSampleRate( int sampleRate )
+{
+    if ( sampleRate > 0 )
+        this->sampleRates.push_back( sampleRate );
+}
+
+const std::list<ContentDescription*> &CommonAttributesElements::getContentProtections() const
+{
+    return this->contentProtections;
+}
+
+void CommonAttributesElements::addContentProtection(ContentDescription *desc)
+{
+    if ( desc != NULL )
+        this->contentProtections.push_back( desc );
+}
+
+const std::list<ContentDescription*> &CommonAttributesElements::getAccessibilities() const
+{
+    return this->accessibilities;
+}
+
+void CommonAttributesElements::addAccessibility(ContentDescription *desc)
+{
+    if ( desc )
+        this->accessibilities.push_back( desc );
+}
+
+const std::list<ContentDescription*> &CommonAttributesElements::getRatings() const
+{
+    return this->ratings;
+}
+
+void CommonAttributesElements::addRating(ContentDescription *desc)
+{
+    if ( desc )
+        this->ratings.push_back( desc );
+}
+
+const std::list<ContentDescription*> &CommonAttributesElements::getViewpoints() const
+{
+    return this->viewpoints;
+}
+
+void CommonAttributesElements::addViewpoint(ContentDescription *desc)
+{
+    if ( desc )
+        this->viewpoints.push_back( desc );
+}
diff --git a/modules/demux/dash/mpd/CommonAttributesElements.h b/modules/demux/dash/mpd/CommonAttributesElements.h
new file mode 100644 (file)
index 0000000..eb42a27
--- /dev/null
@@ -0,0 +1,86 @@
+/*****************************************************************************
+ * CommonAttributesElements.h: Defines the common attributes and elements
+ *                             for some Dash elements.
+ *****************************************************************************
+ * Copyright © 2011 VideoLAN
+ *
+ * Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
+ *
+ * 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 COMMONATTRIBUTESELEMENTS_H
+#define COMMONATTRIBUTESELEMENTS_H
+
+#include <list>
+#include <string>
+
+namespace dash
+{
+    namespace mpd
+    {
+        class   ContentDescription;
+
+        class CommonAttributesElements
+        {
+            public:
+                CommonAttributesElements();
+                virtual ~CommonAttributesElements();
+                virtual const std::string&      getMimeType() const;
+                void                            setMimeType( const std::string &mimeType );
+                int                             getWidth() const;
+                void                            setWidth( int width );
+                int                             getHeight() const;
+                void                            setHeight( int height );
+                int                             getParX() const;
+                void                            setParX( int parX );
+                int                             getParY() const;
+                void                            setParY( int parY );
+                int                             getFrameRate() const;
+                void                            setFrameRate( int frameRate );
+                const std::list<std::string>&   getLang() const;
+                void                            addLang( const std::string &lang );
+                const std::list<std::string>&   getNumberOfChannels() const;
+                void                            addChannel( const std::string &channel );
+                const std::list<int>&           getSamplingRates() const;
+                void                            addSampleRate( int sampleRate );
+                const std::list<ContentDescription*>&   getContentProtections() const;
+                void                                    addContentProtection( ContentDescription *desc );
+                const std::list<ContentDescription*>&   getAccessibilities() const;
+                void                                    addAccessibility( ContentDescription *desc );
+                const std::list<ContentDescription*>&   getRatings() const;
+                void                                    addRating( ContentDescription* desc );
+                const std::list<ContentDescription*>&   getViewpoints() const;
+                void                                    addViewpoint( ContentDescription *desc );
+
+            protected:
+                std::string                         mimeType;
+                int                                 width;
+                int                                 height;
+                int                                 parX;
+                int                                 parY;
+                int                                 frameRate;
+                std::list<std::string>              lang;
+                std::list<std::string>              channels;
+                std::list<int>                      sampleRates;
+                std::list<ContentDescription*>      contentProtections;
+                std::list<ContentDescription*>      accessibilities;
+                std::list<ContentDescription*>      ratings;
+                std::list<ContentDescription*>      viewpoints;
+        };
+    }
+}
+
+#endif // COMMONATTRIBUTESELEMENTS_H
diff --git a/modules/demux/dash/mpd/ContentDescription.cpp b/modules/demux/dash/mpd/ContentDescription.cpp
new file mode 100644 (file)
index 0000000..d551658
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * ContentDescription.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "ContentDescription.h"
+
+using namespace dash::mpd;
+
+void ContentDescription::setSchemeIdUri(const std::string &uri)
+{
+    if ( uri.empty() == false )
+        this->schemeIdUri = uri;
+}
+
+const std::string&      ContentDescription::getSchemeIdUri() const
+{
+    return this->schemeIdUri;
+}
+
+const std::string& ContentDescription::getSchemeInformation() const
+{
+    return this->schemeInformation;
+}
+
+void                    ContentDescription::setSchemeInformation( const std::string &schemeInfo )
+{
+    if ( schemeInfo.empty() == false )
+        this->schemeInformation = schemeInfo;
+}
diff --git a/modules/demux/dash/mpd/ContentDescription.h b/modules/demux/dash/mpd/ContentDescription.h
new file mode 100644 (file)
index 0000000..606034a
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * ContentDescription.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 CONTENTDESCRIPTION_H_
+#define CONTENTDESCRIPTION_H_
+
+#include <string>
+
+namespace dash
+{
+    namespace mpd
+    {
+        class ContentDescription
+        {
+            public:
+                const std::string&          getSchemeIdUri() const;
+                void                        setSchemeIdUri( const std::string &uri );
+                const std::string&          getSchemeInformation() const;
+                void                        setSchemeInformation( const std::string &schemeInfo );
+
+            private:
+                std::string                 schemeIdUri;
+                std::string                 schemeInformation;
+        };
+    }
+}
+
+#endif /* CONTENTDESCRIPTION_H_ */
diff --git a/modules/demux/dash/mpd/ICanonicalUrl.hpp b/modules/demux/dash/mpd/ICanonicalUrl.hpp
new file mode 100644 (file)
index 0000000..7f0a3e3
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * ICanonicalUrl.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 CANONICALURL_HPP
+#define CANONICALURL_HPP
+
+#include "Url.hpp"
+
+namespace dash
+{
+    namespace mpd
+    {
+        class ICanonicalUrl
+        {
+            public:
+                ICanonicalUrl( const ICanonicalUrl *parent = NULL ) { parentUrlMember = parent; }
+                virtual Url getUrlSegment() const = 0;
+
+            protected:
+                Url getParentUrlSegment() const {
+                    return (parentUrlMember) ? parentUrlMember->getUrlSegment()
+                                             : Url();
+                }
+
+            private:
+                const ICanonicalUrl *parentUrlMember;
+        };
+    }
+}
+
+#endif // CANONICALURL_HPP
diff --git a/modules/demux/dash/mpd/IMPDParser.cpp b/modules/demux/dash/mpd/IMPDParser.cpp
new file mode 100644 (file)
index 0000000..898c3a4
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * IMPDParser.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 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 "IMPDParser.h"
+#include "xml/DOMHelper.h"
+
+using namespace dash::mpd;
+using namespace dash::xml;
+
+IMPDParser::IMPDParser(Node *root_, MPD *mpd_, stream_t *stream, Representation *rep)
+{
+    root = root_;
+    mpd = mpd_;
+    currentRepresentation = rep;
+    p_stream = stream;
+}
+
+void IMPDParser::setMPDBaseUrl(Node *root)
+{
+    std::vector<Node *> baseUrls = DOMHelper::getChildElementByTagName(root, "BaseURL");
+
+    for(size_t i = 0; i < baseUrls.size(); i++)
+    {
+        BaseUrl *url = new BaseUrl(baseUrls.at(i)->getText());
+        mpd->addBaseUrl(url);
+    }
+}
+
+MPD* IMPDParser::getMPD()
+{
+    return mpd;
+}
diff --git a/modules/demux/dash/mpd/IMPDParser.h b/modules/demux/dash/mpd/IMPDParser.h
new file mode 100644 (file)
index 0000000..f7f0c4b
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * IMPDParser.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 IMPDPARSER_H_
+#define IMPDPARSER_H_
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "mpd/MPD.h"
+#include "xml/DOMParser.h"
+
+#include <vlc_common.h>
+
+namespace dash
+{
+    namespace mpd
+    {
+        class IMPDParser
+        {
+            public:
+                IMPDParser(dash::xml::Node *, MPD*, stream_t*, Representation*);
+                virtual ~IMPDParser(){}
+                virtual bool    parse  (Profile profile) = 0;
+                virtual MPD*    getMPD ();
+                virtual void    setMPDBaseUrl(dash::xml::Node *root);
+                virtual void    setAdaptationSets(dash::xml::Node *periodNode, Period *period) = 0;
+
+            protected:
+                dash::xml::Node *root;
+                MPD             *mpd;
+                stream_t        *p_stream;
+                Representation  *currentRepresentation;
+        };
+    }
+}
+
+#endif /* IMPDPARSER_H_ */
diff --git a/modules/demux/dash/mpd/IsoffMainParser.cpp b/modules/demux/dash/mpd/IsoffMainParser.cpp
new file mode 100644 (file)
index 0000000..7e9ba65
--- /dev/null
@@ -0,0 +1,465 @@
+/*
+ * IsoffMainParser.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2012 Klagenfurt University
+ *
+ * Created on: Jan 27, 2012
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "IsoffMainParser.h"
+#include "SegmentTemplate.h"
+#include "SegmentInfoDefault.h"
+#include "ProgramInformation.h"
+#include "xml/DOMHelper.h"
+#include <vlc_strings.h>
+#include <vlc_stream.h>
+#include <cstdio>
+#include <sstream>
+
+using namespace dash::mpd;
+using namespace dash::xml;
+
+IsoffMainParser::IsoffMainParser    (Node *root, stream_t *p_stream) :
+                 IMPDParser(root, NULL, p_stream, NULL)
+{
+}
+IsoffMainParser::~IsoffMainParser   ()
+{
+}
+
+bool    IsoffMainParser::parse              (Profile profile)
+{
+    mpd = new MPD(p_stream, profile);
+    setMPDAttributes();
+    parseProgramInformation(DOMHelper::getFirstChildElementByName(root, "ProgramInformation"), mpd);
+    setMPDBaseUrl(root);
+    parsePeriods(root);
+
+    print();
+    return true;
+}
+
+void    IsoffMainParser::setMPDAttributes   ()
+{
+    const std::map<std::string, std::string> attr = this->root->getAttributes();
+
+    std::map<std::string, std::string>::const_iterator it;
+
+    it = attr.find("mediaPresentationDuration");
+    if(it != attr.end())
+        this->mpd->setDuration(IsoTime(it->second));
+
+    it = attr.find("minBufferTime");
+    if(it != attr.end())
+        this->mpd->setMinBufferTime(IsoTime(it->second));
+
+    it = attr.find("type");
+    if(it != attr.end())
+        mpd->setType(it->second);
+
+    it = attr.find("availabilityStartTime");
+    if(it != attr.end())
+        mpd->setAvailabilityStartTime(UTCTime(it->second));
+
+    it = attr.find("timeShiftBufferDepth");
+        if(it != attr.end())
+            mpd->setTimeShiftBufferDepth(IsoTime(it->second));
+}
+
+void IsoffMainParser::parsePeriods(Node *root)
+{
+    std::vector<Node *> periods = DOMHelper::getElementByTagName(root, "Period", false);
+    std::vector<Node *>::const_iterator it;
+
+    for(it = periods.begin(); it != periods.end(); it++)
+    {
+        Period *period = new (std::nothrow) Period(mpd);
+        if (!period)
+            continue;
+        parseSegmentInformation(*it, period);
+        if((*it)->hasAttribute("start"))
+            period->startTime.Set(IsoTime((*it)->getAttributeValue("start")));
+        setAdaptationSets(*it, period);
+        mpd->addPeriod(period);
+    }
+}
+
+size_t IsoffMainParser::parseSegmentTemplate(Node *templateNode, SegmentInformation *info)
+{
+    size_t total = 0;
+    if (templateNode == NULL || !templateNode->hasAttribute("media"))
+        return total;
+
+    std::string mediaurl = templateNode->getAttributeValue("media");
+    SegmentTemplate *mediaTemplate = NULL;
+    if(mediaurl.empty() || !(mediaTemplate = new (std::nothrow) SegmentTemplate(info)) )
+        return total;
+    mediaTemplate->setSourceUrl(mediaurl);
+
+    if(templateNode->hasAttribute("startNumber"))
+        mediaTemplate->setStartIndex(Integer<uint64_t>(templateNode->getAttributeValue("startNumber")));
+
+    if(templateNode->hasAttribute("duration"))
+        mediaTemplate->duration.Set(Integer<mtime_t>(templateNode->getAttributeValue("duration")));
+
+    if(templateNode->hasAttribute("timescale"))
+        mediaTemplate->timescale.Set(Integer<uint64_t>(templateNode->getAttributeValue("timescale")));
+
+    InitSegmentTemplate *initTemplate = NULL;
+
+    if(templateNode->hasAttribute("initialization"))
+    {
+        std::string initurl = templateNode->getAttributeValue("initialization");
+        if(!initurl.empty() && (initTemplate = new (std::nothrow) InitSegmentTemplate(info)))
+            initTemplate->setSourceUrl(initurl);
+    }
+
+    info->setSegmentTemplate(mediaTemplate, SegmentInformation::INFOTYPE_MEDIA);
+    info->setSegmentTemplate(initTemplate, SegmentInformation::INFOTYPE_INIT);
+
+    total += ( mediaTemplate != NULL );
+
+    return total;
+}
+
+size_t IsoffMainParser::parseSegmentInformation(Node *node, SegmentInformation *info)
+{
+    size_t total = 0;
+    parseSegmentBase(DOMHelper::getFirstChildElementByName(node, "SegmentBase"), info);
+    total += parseSegmentList(DOMHelper::getFirstChildElementByName(node, "SegmentList"), info);
+    total += parseSegmentTemplate(DOMHelper::getFirstChildElementByName(node, "SegmentTemplate" ), info);
+    if(node->hasAttribute("bitstreamSwitching"))
+        info->setBitstreamSwitching(node->getAttributeValue("bitstreamSwitching") == "true");
+    if(node->hasAttribute("timescale"))
+        info->timescale.Set(Integer<uint64_t>(node->getAttributeValue("timescale")));
+    return total;
+}
+
+void    IsoffMainParser::setAdaptationSets  (Node *periodNode, Period *period)
+{
+    std::vector<Node *> adaptationSets = DOMHelper::getElementByTagName(periodNode, "AdaptationSet", false);
+    std::vector<Node *>::const_iterator it;
+
+    for(it = adaptationSets.begin(); it != adaptationSets.end(); it++)
+    {
+        AdaptationSet *adaptationSet = new AdaptationSet(period);
+        if(!adaptationSet)
+            continue;
+        if((*it)->hasAttribute("mimeType"))
+            adaptationSet->setMimeType((*it)->getAttributeValue("mimeType"));
+
+        parseSegmentInformation( *it, adaptationSet );
+
+        setRepresentations((*it), adaptationSet);
+        period->addAdaptationSet(adaptationSet);
+    }
+}
+void    IsoffMainParser::setRepresentations (Node *adaptationSetNode, AdaptationSet *adaptationSet)
+{
+    std::vector<Node *> representations = DOMHelper::getElementByTagName(adaptationSetNode, "Representation", false);
+
+    for(size_t i = 0; i < representations.size(); i++)
+    {
+        this->currentRepresentation = new Representation(adaptationSet, getMPD());
+        Node *repNode = representations.at(i);
+
+        std::vector<Node *> baseUrls = DOMHelper::getChildElementByTagName(repNode, "BaseURL");
+        if(!baseUrls.empty())
+            currentRepresentation->setBaseUrl( new BaseUrl( baseUrls.front()->getText() ) );
+
+        if(repNode->hasAttribute("id"))
+            currentRepresentation->setId(repNode->getAttributeValue("id"));
+
+        if(repNode->hasAttribute("width"))
+            this->currentRepresentation->setWidth(atoi(repNode->getAttributeValue("width").c_str()));
+
+        if(repNode->hasAttribute("height"))
+            this->currentRepresentation->setHeight(atoi(repNode->getAttributeValue("height").c_str()));
+
+        if(repNode->hasAttribute("bandwidth"))
+            this->currentRepresentation->setBandwidth(atoi(repNode->getAttributeValue("bandwidth").c_str()));
+
+        if(repNode->hasAttribute("mimeType"))
+            currentRepresentation->setMimeType(repNode->getAttributeValue("mimeType"));
+
+        size_t totalmediasegments = parseSegmentInformation(repNode, currentRepresentation);
+        if(!totalmediasegments)
+        {
+            /* unranged & segment less representation, add fake segment */
+            SegmentList *list = new SegmentList();
+            Segment *seg = new Segment(currentRepresentation);
+            if(list && seg)
+            {
+                list->addSegment(seg);
+                currentRepresentation->setSegmentList(list);
+            }
+            else
+            {
+                delete seg;
+                delete list;
+            }
+        }
+
+        adaptationSet->addRepresentation(this->currentRepresentation);
+    }
+}
+
+void IsoffMainParser::parseSegmentBase(Node * segmentBaseNode, SegmentInformation *info)
+{
+    if(!segmentBaseNode)
+        return;
+
+    else if(segmentBaseNode->hasAttribute("indexRange"))
+    {
+        SegmentList *list = new SegmentList();
+        Segment *seg;
+
+        size_t start = 0, end = 0;
+        if (std::sscanf(segmentBaseNode->getAttributeValue("indexRange").c_str(), "%zu-%zu", &start, &end) == 2)
+        {
+            seg = new IndexSegment(info);
+            seg->setByteRange(start, end);
+            list->addSegment(seg);
+            /* index must be before data, so data starts at index end */
+            seg = new Segment(info);
+            seg->setByteRange(end + 1, 0);
+        }
+        else
+        {
+            seg = new Segment(info);
+        }
+
+        list->addSegment(seg);
+        info->setSegmentList(list);
+
+        std::vector<Node *> initSeg = DOMHelper::getElementByTagName(segmentBaseNode, "Initialization", false);
+        if(!initSeg.empty())
+        {
+            SegmentBase *base = new SegmentBase();
+            setInitSegment(segmentBaseNode, base);
+            info->setSegmentBase(base);
+        }
+    }
+    else
+    {
+        SegmentBase *base = new SegmentBase();
+        setInitSegment(segmentBaseNode, base);
+        info->setSegmentBase(base);
+    }
+}
+
+size_t IsoffMainParser::parseSegmentList(Node * segListNode, SegmentInformation *info)
+{
+    size_t total = 0;
+    if(segListNode)
+    {
+        std::vector<Node *> segments = DOMHelper::getElementByTagName(segListNode, "SegmentURL", false);
+        SegmentList *list;
+        if(!segments.empty() && (list = new (std::nothrow) SegmentList()))
+        {
+            std::vector<Node *>::const_iterator it;
+            for(it = segments.begin(); it != segments.end(); it++)
+            {
+                Node *segmentURL = *it;
+                std::string mediaUrl = segmentURL->getAttributeValue("media");
+                if(mediaUrl.empty())
+                    continue;
+
+                Segment *seg = new (std::nothrow) Segment(info);
+                if(!seg)
+                    continue;
+
+                seg->setSourceUrl(segmentURL->getAttributeValue("media"));
+
+                if(segmentURL->hasAttribute("mediaRange"))
+                {
+                    std::string range = segmentURL->getAttributeValue("mediaRange");
+                    size_t pos = range.find("-");
+                    seg->setByteRange(atoi(range.substr(0, pos).c_str()), atoi(range.substr(pos + 1, range.size()).c_str()));
+                }
+
+                list->addSegment(seg);
+                total++;
+            }
+
+            info->setSegmentList(list);
+        }
+    }
+    return total;
+}
+
+void    IsoffMainParser::setInitSegment     (dash::xml::Node *segBaseNode, SegmentBase *base)
+{
+    std::vector<Node *> initSeg = DOMHelper::getElementByTagName(segBaseNode, "Initialisation", false);
+
+    if(initSeg.size() == 0)
+        initSeg = DOMHelper::getElementByTagName(segBaseNode, "Initialization", false);
+
+    if(initSeg.size() > 0)
+    {
+        Segment *seg = new InitSegment( currentRepresentation );
+        seg->setSourceUrl(initSeg.at(0)->getAttributeValue("sourceURL"));
+
+        if(initSeg.at(0)->hasAttribute("range"))
+        {
+            std::string range = initSeg.at(0)->getAttributeValue("range");
+            size_t pos = range.find("-");
+            seg->setByteRange(atoi(range.substr(0, pos).c_str()), atoi(range.substr(pos + 1, range.size()).c_str()));
+        }
+
+        base->addInitSegment(seg);
+    }
+}
+
+void IsoffMainParser::parseProgramInformation(Node * node, MPD *mpd)
+{
+    if(!node)
+        return;
+
+    ProgramInformation *info = new (std::nothrow) ProgramInformation();
+    if (info)
+    {
+        Node *child = DOMHelper::getFirstChildElementByName(node, "Title");
+        if(child)
+            info->setTitle(child->getText());
+
+        child = DOMHelper::getFirstChildElementByName(node, "Source");
+        if(child)
+            info->setSource(child->getText());
+
+        child = DOMHelper::getFirstChildElementByName(node, "Copyright");
+        if(child)
+            info->setCopyright(child->getText());
+
+        if(node->hasAttribute("moreInformationURL"))
+            info->setMoreInformationUrl(node->getAttributeValue("moreInformationURL"));
+
+        mpd->setProgramInformation(info);
+    }
+}
+
+void    IsoffMainParser::print              ()
+{
+    if(mpd)
+    {
+        msg_Dbg(p_stream, "MPD profile=%s mediaPresentationDuration=%ld minBufferTime=%ld",
+                static_cast<std::string>(mpd->getProfile()).c_str(),
+                mpd->getDuration(),
+                mpd->getMinBufferTime());
+        msg_Dbg(p_stream, "BaseUrl=%s", mpd->getUrlSegment().toString().c_str());
+
+        std::vector<Period *>::const_iterator i;
+        for(i = mpd->getPeriods().begin(); i != mpd->getPeriods().end(); i++)
+        {
+            std::vector<std::string> debug = (*i)->toString();
+            std::vector<std::string>::const_iterator l;
+            for(l = debug.begin(); l < debug.end(); l++)
+            {
+                msg_Dbg(p_stream, "%s", (*l).c_str());
+            }
+        }
+    }
+}
+
+IsoTime::IsoTime(const std::string &str)
+{
+    time = str_duration(str.c_str());
+}
+
+IsoTime::operator mtime_t () const
+{
+    return time;
+}
+
+/* i_year: year - 1900  i_month: 0-11  i_mday: 1-31 i_hour: 0-23 i_minute: 0-59 i_second: 0-59 */
+static int64_t vlc_timegm( int i_year, int i_month, int i_mday, int i_hour, int i_minute, int i_second )
+{
+    static const int pn_day[12+1] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
+    int64_t i_day;
+
+    if( i_year < 70 ||
+        i_month < 0 || i_month > 11 || i_mday < 1 || i_mday > 31 ||
+        i_hour < 0 || i_hour > 23 || i_minute < 0 || i_minute > 59 || i_second < 0 || i_second > 59 )
+        return -1;
+
+    /* Count the number of days */
+    i_day = 365 * (i_year-70) + pn_day[i_month] + i_mday - 1;
+#define LEAP(y) ( ((y)%4) == 0 && (((y)%100) != 0 || ((y)%400) == 0) ? 1 : 0)
+    for( int i = 70; i < i_year; i++ )
+        i_day += LEAP(1900+i);
+    if( i_month > 1 )
+        i_day += LEAP(1900+i_year);
+#undef LEAP
+    /**/
+    return ((24*i_day + i_hour)*60 + i_minute)*60 + i_second;
+}
+
+UTCTime::UTCTime(const std::string &str)
+{
+    enum { YEAR = 0, MON, DAY, HOUR, MIN, SEC, TZ };
+    int values[7] = {0};
+    std::istringstream in(str);
+
+    try
+    {
+        /* Date */
+        for(int i=YEAR;i<=DAY && !in.eof();i++)
+        {
+            if(i!=YEAR)
+                in.ignore(1);
+            in >> values[i];
+        }
+        /* Time */
+        if (!in.eof() && in.peek() == 'T')
+        {
+            for(int i=HOUR;i<=SEC && !in.eof();i++)
+            {
+                in.ignore(1);
+                in >> values[i];
+            }
+        }
+        /* Timezone */
+        if (!in.eof() && in.peek() == 'Z')
+        {
+            in.ignore(1);
+            while(!in.eof())
+            {
+                if(in.peek() == '+')
+                    continue;
+                in >> values[TZ];
+                break;
+            }
+        }
+
+        time = vlc_timegm( values[YEAR] - 1900, values[MON] - 1, values[DAY],
+                           values[HOUR], values[MIN], values[SEC] );
+        time += values[TZ] * 3600;
+    } catch(int) {
+        time = 0;
+    }
+}
+
+UTCTime::operator mtime_t () const
+{
+    return time;
+}
diff --git a/modules/demux/dash/mpd/IsoffMainParser.h b/modules/demux/dash/mpd/IsoffMainParser.h
new file mode 100644 (file)
index 0000000..0c98b46
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * IsoffMainParser.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2012 Klagenfurt University
+ *
+ * Created on: Jan 27, 2012
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 ISOFFMAINPARSER_H_
+#define ISOFFMAINPARSER_H_
+
+#include "xml/Node.h"
+#include "mpd/IMPDParser.h"
+#include "mpd/AdaptationSet.h"
+#include "mpd/BaseUrl.h"
+#include "mpd/SegmentBase.h"
+#include "mpd/SegmentList.h"
+#include "mpd/Segment.h"
+
+#include <cstdlib>
+#include <sstream>
+
+namespace dash
+{
+    namespace mpd
+    {
+        class IsoffMainParser : public IMPDParser
+        {
+            public:
+                IsoffMainParser             (dash::xml::Node *root, stream_t *p_stream);
+                virtual ~IsoffMainParser    ();
+
+                bool    parse  (Profile profile);
+                void    print  ();
+
+            private:
+                void    setMPDAttributes    ();
+                void    setAdaptationSets   (dash::xml::Node *periodNode, Period *period);
+                void    setRepresentations  (dash::xml::Node *adaptationSetNode, AdaptationSet *adaptationSet);
+                void    setInitSegment      (dash::xml::Node *segBaseNode, SegmentBase *base);
+                void    parsePeriods        (dash::xml::Node *);
+                size_t  parseSegmentInformation(dash::xml::Node *, SegmentInformation *);
+                void    parseSegmentBase    (dash::xml::Node *, SegmentInformation *);
+                size_t  parseSegmentList    (dash::xml::Node *, SegmentInformation *);
+                size_t  parseSegmentTemplate(dash::xml::Node *, SegmentInformation *);
+                void    parseProgramInformation(dash::xml::Node *, MPD *);
+        };
+
+        class IsoTime
+        {
+            public:
+                IsoTime(const std::string&);
+                operator mtime_t() const;
+
+            private:
+                mtime_t time;
+        };
+
+        class UTCTime
+        {
+            public:
+                UTCTime(const std::string&);
+                operator mtime_t() const;
+
+            private:
+                mtime_t time;
+        };
+
+        template<typename T> class Integer
+        {
+            public:
+                Integer(const std::string &str)
+                {
+                    try
+                    {
+                        std::istringstream in(str);
+                        in >> value;
+                    } catch (int) {
+                        value = 0;
+                    }
+                }
+
+                operator T() const
+                {
+                    return value;
+                }
+
+            private:
+                T value;
+        };
+    }
+}
+
+#endif /* ISOFFMAINPARSER_H_ */
diff --git a/modules/demux/dash/mpd/MPD.cpp b/modules/demux/dash/mpd/MPD.cpp
new file mode 100644 (file)
index 0000000..71a3787
--- /dev/null
@@ -0,0 +1,209 @@
+/*
+ * MPD.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "MPD.h"
+#include "Helper.h"
+#include "dash.hpp"
+#include <vlc_common.h>
+#include <vlc_stream.h>
+
+using namespace dash::mpd;
+
+MPD::MPD (stream_t *stream_, Profile profile_) :
+    ICanonicalUrl(),
+    stream(stream_),
+    profile( profile_ ),
+    availabilityStartTime( 0 ),
+    availabilityEndTime( 0 ),
+    duration( 0 ),
+    minUpdatePeriod( -1 ),
+    minBufferTime( 0 ),
+    timeShiftBufferDepth( 0 ),
+    programInfo( NULL )
+{
+    playbackStart.Set(0);
+}
+
+MPD::~MPD   ()
+{
+    for(size_t i = 0; i < this->periods.size(); i++)
+        delete(this->periods.at(i));
+
+    for(size_t i = 0; i < this->baseUrls.size(); i++)
+        delete(this->baseUrls.at(i));
+
+    delete(this->programInfo);
+}
+
+const std::vector<Period*>&    MPD::getPeriods             () const
+{
+    return this->periods;
+}
+
+time_t      MPD::getDuration() const
+{
+    return this->duration;
+}
+
+void MPD::setDuration(time_t duration)
+{
+    if ( duration >= 0 )
+        this->duration = duration;
+}
+
+time_t MPD::getMinUpdatePeriod() const
+{
+    return this->minUpdatePeriod;
+}
+
+void MPD::setMinUpdatePeriod(time_t period)
+{
+    if ( period >= 0 )
+        this->minUpdatePeriod = period;
+}
+
+time_t MPD::getMinBufferTime() const
+{
+    return this->minBufferTime;
+}
+
+void MPD::setMinBufferTime(time_t time)
+{
+    if ( time >= 0 )
+        this->minBufferTime = time;
+}
+
+time_t MPD::getTimeShiftBufferDepth() const
+{
+    return this->timeShiftBufferDepth;
+}
+
+void MPD::setTimeShiftBufferDepth(time_t depth)
+{
+    if ( depth >= 0 )
+        this->timeShiftBufferDepth = depth;
+}
+
+const ProgramInformation*     MPD::getProgramInformation  () const
+{
+    return this->programInfo;
+}
+
+void                    MPD::addBaseUrl             (BaseUrl *url)
+{
+    this->baseUrls.push_back(url);
+}
+void                    MPD::addPeriod              (Period *period)
+{
+    this->periods.push_back(period);
+}
+void                    MPD::setProgramInformation  (ProgramInformation *progInfo)
+{
+    this->programInfo = progInfo;
+}
+
+bool                    MPD::isLive() const
+{
+    if(type.empty())
+    {
+        Profile live(Profile::ISOLive);
+        return profile == live;
+    }
+    else
+        return (type != "static");
+}
+
+void MPD::setType(const std::string &type_)
+{
+    type = type_;
+}
+
+time_t MPD::getAvailabilityStartTime() const
+{
+    return this->availabilityStartTime;
+}
+
+void MPD::setAvailabilityStartTime(time_t time)
+{
+    if ( time >=0 )
+        this->availabilityStartTime = time;
+}
+
+time_t MPD::getAvailabilityEndTime() const
+{
+    return this->availabilityEndTime;
+}
+
+void MPD::setAvailabilityEndTime(time_t time)
+{
+    if ( time >= 0 )
+        this->availabilityEndTime = time;
+}
+
+Profile MPD::getProfile() const
+{
+    return profile;
+}
+Url MPD::getUrlSegment() const
+{
+    if (!baseUrls.empty())
+        return Url(baseUrls.front()->getUrl());
+    else
+    {
+        std::stringstream ss;
+        ss << stream->psz_access << "://" << Helper::getDirectoryPath(stream->psz_path) << "/";
+        return Url(ss.str());
+    }
+}
+
+vlc_object_t * MPD::getVLCObject() const
+{
+    return VLC_OBJECT(stream);
+}
+
+Period* MPD::getFirstPeriod() const
+{
+    std::vector<Period *> periods = getPeriods();
+
+    if( !periods.empty() )
+        return periods.front();
+    else
+        return NULL;
+}
+
+Period* MPD::getNextPeriod(Period *period)
+{
+    std::vector<Period *> periods = getPeriods();
+
+    for(size_t i = 0; i < periods.size(); i++)
+    {
+        if(periods.at(i) == period && (i + 1) < periods.size())
+            return periods.at(i + 1);
+    }
+
+    return NULL;
+}
diff --git a/modules/demux/dash/mpd/MPD.h b/modules/demux/dash/mpd/MPD.h
new file mode 100644 (file)
index 0000000..fbff060
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * MPD.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 MPD_H_
+#define MPD_H_
+
+#include <vector>
+#include <string>
+#include <map>
+
+#include "mpd/Period.h"
+#include "mpd/BaseUrl.h"
+#include "mpd/ICanonicalUrl.hpp"
+#include "mpd/ProgramInformation.h"
+#include "mpd/Profile.hpp"
+#include "Properties.hpp"
+
+namespace dash
+{
+    namespace mpd
+    {
+        class MPD : public ICanonicalUrl
+        {
+            public:
+                MPD(stream_t *, Profile);
+                virtual ~MPD();
+
+                Profile                         getProfile() const;
+                bool                            isLive() const;
+                time_t                          getAvailabilityStartTime() const;
+                void                            setAvailabilityStartTime( time_t time );
+                time_t                          getAvailabilityEndTime() const;
+                void                            setAvailabilityEndTime( time_t time );
+                void                            setType(const std::string &);
+                time_t                          getDuration() const;
+                void                            setDuration( time_t duration );
+                time_t                          getMinUpdatePeriod() const;
+                void                            setMinUpdatePeriod( time_t period );
+                time_t                          getMinBufferTime() const;
+                void                            setMinBufferTime( time_t time );
+                time_t                          getTimeShiftBufferDepth() const;
+                void                            setTimeShiftBufferDepth( time_t depth );
+                const ProgramInformation*       getProgramInformation() const;
+
+                void    addPeriod               (Period *period);
+                void    addBaseUrl              (BaseUrl *url);
+                void    setProgramInformation   (ProgramInformation *progInfo);
+
+                virtual Url         getUrlSegment() const; /* impl */
+                vlc_object_t *      getVLCObject()  const;
+
+                virtual const std::vector<Period *>&    getPeriods() const;
+                virtual Period*                         getFirstPeriod() const;
+                virtual Period*                         getNextPeriod(Period *period);
+
+                Property<time_t>                    playbackStart;
+
+            private:
+                stream_t                           *stream;
+                Profile                             profile;
+                time_t                              availabilityStartTime;
+                time_t                              availabilityEndTime;
+                time_t                              duration;
+                time_t                              minUpdatePeriod;
+                time_t                              minBufferTime;
+                time_t                              timeShiftBufferDepth;
+                std::vector<Period *>               periods;
+                std::vector<BaseUrl *>              baseUrls;
+                ProgramInformation                  *programInfo;
+                std::string                         type;
+        };
+    }
+}
+#endif /* MPD_H_ */
diff --git a/modules/demux/dash/mpd/MPDFactory.cpp b/modules/demux/dash/mpd/MPDFactory.cpp
new file mode 100644 (file)
index 0000000..ba1e399
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * MPDFactory.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2012 Klagenfurt University
+ *
+ * Created on: Jan 27, 2012
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "MPDFactory.h"
+
+using namespace dash::xml;
+using namespace dash::mpd;
+
+MPD* MPDFactory::create             (dash::xml::Node *root, stream_t *p_stream, Profile profile)
+{
+    IMPDParser *parser = NULL;
+
+    switch( profile )
+    {
+        case Profile::ISOOnDemand:
+        case Profile::ISOMain:
+        case Profile::ISOLive:
+        case Profile::MPEG2TSSimple:
+            parser = new IsoffMainParser(root, p_stream);
+        default:
+            break;
+    }
+
+    if(!parser)
+        return NULL;
+
+    MPD* mpd = NULL;
+    if(parser->parse(profile))
+        mpd = parser->getMPD();
+
+    delete parser;
+
+    return mpd;
+}
diff --git a/modules/demux/dash/mpd/MPDFactory.h b/modules/demux/dash/mpd/MPDFactory.h
new file mode 100644 (file)
index 0000000..79e0a37
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * MPDFactory.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2012 Klagenfurt University
+ *
+ * Created on: Jan 27, 2012
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 MPDFACTORY_H_
+#define MPDFACTORY_H_
+
+#include "mpd/MPD.h"
+#include "mpd/IsoffMainParser.h"
+
+namespace dash
+{
+    namespace mpd
+    {
+        class MPDFactory
+        {
+            public:
+                static MPD* create(dash::xml::Node *root, stream_t *p_stream, Profile profile);
+        };
+    }
+}
+
+#endif /* MPDFACTORY_H_ */
diff --git a/modules/demux/dash/mpd/Period.cpp b/modules/demux/dash/mpd/Period.cpp
new file mode 100644 (file)
index 0000000..607f3d0
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Period.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "Period.h"
+#include "MPD.h"
+
+#include <vlc_common.h>
+#include <vlc_arrays.h>
+
+using namespace dash::mpd;
+
+Period::Period(MPD *mpd) :
+    SegmentInformation( mpd )
+{
+    duration.Set(0);
+    startTime.Set(0);
+}
+
+Period::~Period ()
+{
+    vlc_delete_all( this->adaptationSets );
+}
+
+const std::vector<AdaptationSet*>&  Period::getAdaptationSets() const
+{
+    return this->adaptationSets;
+}
+
+const std::vector<AdaptationSet*>   Period::getAdaptationSets(Streams::Type type) const
+{
+    std::vector<AdaptationSet*> list;
+    std::vector<AdaptationSet*>::const_iterator it;
+    for(it = adaptationSets.begin(); it!= adaptationSets.end(); it++)
+    {
+        if( Streams::Stream::mimeToType((*it)->getMimeType()) == type )
+            list.push_back(*it);
+    }
+    return list;
+}
+
+void                                Period::addAdaptationSet(AdaptationSet *adaptationSet)
+{
+    if ( adaptationSet != NULL )
+        this->adaptationSets.push_back(adaptationSet);
+}
+
+AdaptationSet * Period::getAdaptationSet(Streams::Type type) const
+{
+    std::vector<AdaptationSet *>::const_iterator it;
+    for(it = adaptationSets.begin(); it != adaptationSets.end(); it++)
+    {
+        if ( Streams::Stream::mimeToType((*it)->getMimeType()) == type )
+            return *it;
+    }
+    return NULL;
+}
+
+Url Period::getUrlSegment() const
+{
+    return getParentUrlSegment();
+}
+
+std::vector<std::string> Period::toString(int indent) const
+{
+    std::vector<std::string> ret;
+    std::string text(indent, ' ');
+    text.append("Period");
+    ret.push_back(text);
+    std::vector<AdaptationSet *>::const_iterator k;
+    for(k = adaptationSets.begin(); k != adaptationSets.end(); k++)
+    {
+        std::vector<std::string> debug = (*k)->toString(indent + 1);
+        ret.insert(ret.end(), debug.begin(), debug.end());
+    }
+    return ret;
+}
+
+mtime_t Period::getPeriodStart() const
+{
+    return startTime.Get();
+}
diff --git a/modules/demux/dash/mpd/Period.h b/modules/demux/dash/mpd/Period.h
new file mode 100644 (file)
index 0000000..919d779
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Period.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 PERIOD_H_
+#define PERIOD_H_
+
+#include <vector>
+#include <string>
+
+#include "mpd/AdaptationSet.h"
+#include "mpd/ICanonicalUrl.hpp"
+#include "mpd/SegmentInformation.hpp"
+#include "Properties.hpp"
+#include "Streams.hpp"
+
+namespace dash
+{
+    namespace mpd
+    {
+        class MPD;
+
+        class Period : public SegmentInformation
+        {
+            public:
+                Period(MPD *);
+                virtual ~Period ();
+
+                const std::vector<AdaptationSet *>& getAdaptationSets   () const;
+                const std::vector<AdaptationSet *>  getAdaptationSets   (Streams::Type) const;
+                AdaptationSet *                     getAdaptationSet    (Streams::Type) const;
+                void                                addAdaptationSet    (AdaptationSet *AdaptationSet);
+                std::vector<std::string>            toString            (int = 0) const;
+
+                virtual Url getUrlSegment() const; /* reimpl */
+                virtual mtime_t getPeriodStart() const; /* reimpl */
+
+                Property<mtime_t> duration;
+                Property<mtime_t> startTime;
+
+            private:
+                std::vector<AdaptationSet *>    adaptationSets;
+        };
+    }
+}
+
+#endif /* PERIOD_H_ */
diff --git a/modules/demux/dash/mpd/Profile.cpp b/modules/demux/dash/mpd/Profile.cpp
new file mode 100644 (file)
index 0000000..617bfa6
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Profile.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "Profile.hpp"
+
+using namespace dash::mpd;
+
+struct
+{
+    const Profile::Name name;
+    const char * urn;
+}
+const urnmap[] =
+{
+    { Profile::Full,         "urn:mpeg:dash:profile:full:2011" },
+    { Profile::ISOOnDemand,  "urn:mpeg:dash:profile:isoff-on-demand:2011" },
+    { Profile::ISOOnDemand,  "urn:mpeg:mpegB:profile:dash:isoff-basic-on-demand:cm" },
+    { Profile::ISOOnDemand,  "urn:mpeg:dash:profile:isoff-ondemand:2011" },
+    { Profile::ISOMain,      "urn:mpeg:dash:profile:isoff-main:2011" },
+    { Profile::ISOLive,      "urn:mpeg:dash:profile:isoff-live:2011" },
+    { Profile::MPEG2TSMain,  "urn:mpeg:dash:profile:mp2t-main:2011" },
+    { Profile::MPEG2TSSimple,"urn:mpeg:dash:profile:mp2t-simple:2011" },
+    { Profile::Unknown,      "" },
+};
+
+Profile::Profile(Name name)
+{
+    type = name;
+}
+
+Profile::Profile(const std::string &urn)
+{
+    type = getNameByURN(urn);
+}
+
+Profile::Name Profile::getNameByURN(const std::string &urn) const
+{
+    for( int i=0; urnmap[i].name != Unknown; i++ )
+    {
+        if ( urn == urnmap[i].urn )
+            return urnmap[i].name;
+    }
+    return Unknown;
+}
+
+Profile::operator Profile::Name ()
+{
+    return type;
+}
+
+Profile::operator std::string ()
+{
+    for( int i=0; urnmap[i].name != Unknown; i++ )
+    {
+        if ( urnmap[i].name == type )
+            return std::string( urnmap[i].urn );
+    }
+    return std::string();
+}
+
+bool Profile::operator==(Profile &profile) const
+{
+    return profile.type == type;
+}
diff --git a/modules/demux/dash/mpd/Profile.hpp b/modules/demux/dash/mpd/Profile.hpp
new file mode 100644 (file)
index 0000000..9b44231
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Profile.hpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 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 PROFILE_HPP
+#define PROFILE_HPP
+
+#include <string>
+
+namespace dash
+{
+    namespace mpd
+    {
+        class Profile
+        {
+            public:
+                enum Name
+                {
+                    Unknown,
+                    Full,
+                    ISOOnDemand,
+                    ISOMain,
+                    ISOLive,
+                    MPEG2TSMain,
+                    MPEG2TSSimple,
+                };
+                Profile(Name);
+                Profile(const std::string &);
+                bool operator==(Profile &) const;
+                operator Profile::Name ();
+                operator std::string ();
+
+            private:
+                Name getNameByURN(const std::string &) const;
+                Name type;
+        };
+    }
+}
+#endif // PROFILE_HPP
diff --git a/modules/demux/dash/mpd/ProgramInformation.cpp b/modules/demux/dash/mpd/ProgramInformation.cpp
new file mode 100644 (file)
index 0000000..5731bd9
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * ProgramInformation.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "ProgramInformation.h"
+
+using namespace dash::mpd;
+
+const std::string &ProgramInformation::getSource() const
+{
+    return this->source;
+}
+
+void ProgramInformation::setSource(const std::string &source)
+{
+    this->source = source;
+}
+
+const std::string &ProgramInformation::getCopyright() const
+{
+    return this->copyright;
+}
+
+void ProgramInformation::setCopyright(const std::string &copyright)
+{
+    this->copyright = copyright;
+}
+
+void ProgramInformation::setMoreInformationUrl(const std::string &url)
+{
+    this->moreInformationUrl = url;
+}
+
+const std::string & ProgramInformation::getMoreInformationUrl() const
+{
+    return moreInformationUrl;
+}
+
+const std::string &ProgramInformation::getTitle() const
+{
+    return this->title;
+}
+
+void        ProgramInformation::setTitle                (const std::string &title)
+{
+    this->title = title;
+}
diff --git a/modules/demux/dash/mpd/ProgramInformation.h b/modules/demux/dash/mpd/ProgramInformation.h
new file mode 100644 (file)
index 0000000..6a4c97e
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * ProgramInformation.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 PROGRAMINFORMATION_H_
+#define PROGRAMINFORMATION_H_
+
+#include <string>
+#include <map>
+
+namespace dash
+{
+    namespace mpd
+    {
+        class ProgramInformation
+        {
+            public:
+                virtual ~ProgramInformation(){}
+
+                const std::string&  getMoreInformationUrl() const;
+                void                setMoreInformationUrl( const std::string &url );
+                const std::string&  getTitle() const;
+                void                setTitle( const std::string &title);
+                const std::string&  getSource() const;
+                void                setSource( const std::string &source);
+                const std::string&  getCopyright() const;
+                void                setCopyright( const std::string &copyright);
+
+            private:
+                std::string         moreInformationUrl;
+                std::string         title;
+                std::string         source;
+                std::string         copyright;
+        };
+    }
+}
+
+#endif /* PROGRAMINFORMATION_H_ */
diff --git a/modules/demux/dash/mpd/Representation.cpp b/modules/demux/dash/mpd/Representation.cpp
new file mode 100644 (file)
index 0000000..61aa8f1
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+ * Representation.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <cstdlib>
+
+#include "Representation.h"
+#include "mpd/AdaptationSet.h"
+#include "mpd/MPD.h"
+#include "mpd/SegmentTemplate.h"
+
+using namespace dash::mpd;
+
+Representation::Representation  ( AdaptationSet *set, MPD *mpd_ ) :
+                SegmentInformation( set ),
+                mpd             ( mpd_ ),
+                adaptationSet   ( set ),
+                bandwidth       (0),
+                qualityRanking  ( -1 ),
+                trickModeType   ( NULL ),
+                baseUrl         ( NULL ),
+                width           (0),
+                height          (0)
+{
+}
+
+Representation::~Representation ()
+{
+    delete(this->trickModeType);
+    delete baseUrl;
+}
+
+const std::string&  Representation::getId                   () const
+{
+    return this->id;
+}
+
+void    Representation::setId(const std::string &id)
+{
+    if ( id.empty() == false )
+        this->id = id;
+}
+
+uint64_t     Representation::getBandwidth            () const
+{
+    return this->bandwidth;
+}
+
+void    Representation::setBandwidth( uint64_t bandwidth )
+{
+    this->bandwidth = bandwidth;
+}
+
+
+TrickModeType*      Representation::getTrickModeType        () const
+{
+    return this->trickModeType;
+}
+
+void                Representation::setTrickMode        (TrickModeType *trickModeType)
+{
+    this->trickModeType = trickModeType;
+}
+
+
+
+int Representation::getQualityRanking() const
+{
+    return this->qualityRanking;
+}
+
+void Representation::setQualityRanking( int qualityRanking )
+{
+    if ( qualityRanking > 0 )
+        this->qualityRanking = qualityRanking;
+}
+
+const std::list<const Representation*>&     Representation::getDependencies() const
+{
+    return this->dependencies;
+}
+
+void Representation::addDependency(const Representation *dep)
+{
+    if ( dep != NULL )
+        this->dependencies.push_back( dep );
+}
+
+
+void Representation::setBaseUrl(BaseUrl *base)
+{
+    baseUrl = base;
+}
+
+void                Representation::setWidth                (int width)
+{
+    this->width = width;
+}
+int                 Representation::getWidth                () const
+{
+    return this->width;
+}
+void                Representation::setHeight               (int height)
+{
+    this->height = height;
+}
+int                 Representation::getHeight               () const
+{
+    return this->height;
+}
+
+std::vector<std::string> Representation::toString(int indent) const
+{
+    std::vector<std::string> ret;
+    std::string text(indent, ' ');
+    text.append("Representation");
+    ret.push_back(text);
+    std::vector<ISegment *> list = getSegments();
+    std::vector<ISegment *>::const_iterator l;
+    for(l = list.begin(); l < list.end(); l++)
+        ret.push_back((*l)->toString(indent + 1));
+
+    return ret;
+}
+
+Url Representation::getUrlSegment() const
+{
+    Url ret = getParentUrlSegment();
+    if (baseUrl)
+        ret.append(baseUrl->getUrl());
+    return ret;
+}
+
+MPD * Representation::getMPD() const
+{
+    return mpd;
+}
diff --git a/modules/demux/dash/mpd/Representation.h b/modules/demux/dash/mpd/Representation.h
new file mode 100644 (file)
index 0000000..67da99a
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Representation.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 REPRESENTATION_H_
+#define REPRESENTATION_H_
+
+#include <string>
+
+#include "mpd/CommonAttributesElements.h"
+#include "mpd/SegmentInfo.h"
+#include "mpd/TrickModeType.h"
+#include "mpd/SegmentBase.h"
+#include "mpd/SegmentList.h"
+#include "mpd/SegmentInformation.hpp"
+#include "mpd/BaseUrl.h"
+
+namespace dash
+{
+    namespace mpd
+    {
+        class AdaptationSet;
+        class MPD;
+
+        class Representation : public CommonAttributesElements,
+                               public SegmentInformation
+        {
+            public:
+                Representation( AdaptationSet *, MPD *mpd );
+                virtual ~Representation ();
+
+                const std::string&  getId                   () const;
+                void                setId                   ( const std::string &id );
+                /*
+                 *  @return The bitrate required for this representation
+                 *          in bits per seconds.
+                 *          Will be a valid value, as the parser refuses Representation
+                 *          without bandwidth.
+                 */
+                uint64_t            getBandwidth            () const;
+                void                setBandwidth            ( uint64_t bandwidth );
+                int                 getQualityRanking       () const;
+                void                setQualityRanking       ( int qualityRanking );
+                const std::list<const Representation*>&     getDependencies() const;
+                void                addDependency           ( const Representation* dep );
+                /**
+                 * @return  This SegmentInfo for this Representation.
+                 *          It cannot be NULL, or without any Segments in it.
+                 *          It can however have a NULL InitSegment
+                 */
+                TrickModeType*      getTrickModeType        () const;
+
+                void                setTrickMode( TrickModeType *trickModeType );
+
+                void                setWidth                (int width);
+                int                 getWidth                () const;
+                void                setHeight               (int height);
+                int                 getHeight               () const;
+                void                setBaseUrl              (BaseUrl *baseUrl);
+                MPD*                getMPD                  () const;
+
+                std::vector<std::string> toString(int = 0) const;
+                virtual Url         getUrlSegment           () const; /* impl */
+
+            private:
+                MPD                                *mpd;
+                AdaptationSet                      *adaptationSet;
+                uint64_t                            bandwidth;
+                std::string                         id;
+                int                                 qualityRanking;
+                std::list<const Representation*>    dependencies;
+                TrickModeType                       *trickModeType;
+                BaseUrl                             *baseUrl;
+                int                                 width;
+                int                                 height;
+        };
+    }
+}
+
+#endif /* REPRESENTATION_H_ */
diff --git a/modules/demux/dash/mpd/Segment.cpp b/modules/demux/dash/mpd/Segment.cpp
new file mode 100644 (file)
index 0000000..c203d6c
--- /dev/null
@@ -0,0 +1,271 @@
+/*
+ * Segment.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#define __STDC_CONSTANT_MACROS
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "Segment.h"
+#include "Representation.h"
+#include "MPD.h"
+#include "mp4/AtomsReader.hpp"
+
+#include <cassert>
+
+using namespace dash::mpd;
+using namespace dash::http;
+
+ISegment::ISegment(const ICanonicalUrl *parent):
+    ICanonicalUrl( parent ),
+    startByte  (0),
+    endByte    (0)
+{
+    debugName = "Segment";
+    classId = CLASSID_ISEGMENT;
+    startTime.Set(VLC_TS_INVALID);
+    duration.Set(0);
+}
+
+dash::http::Chunk * ISegment::getChunk(const std::string &url)
+{
+    return new (std::nothrow) SegmentChunk(this, url);
+}
+
+dash::http::Chunk* ISegment::toChunk(size_t index, Representation *ctxrep)
+{
+    Chunk *chunk;
+    try
+    {
+        chunk = getChunk(getUrlSegment().toString(index, ctxrep));
+        if (!chunk)
+            return NULL;
+    }
+    catch (int)
+    {
+        return NULL;
+    }
+
+    if(startByte != endByte)
+    {
+        chunk->setStartByte(startByte);
+        chunk->setEndByte(endByte);
+    }
+
+    return chunk;
+}
+
+bool ISegment::isSingleShot() const
+{
+    return true;
+}
+void ISegment::done()
+{
+    //Only used for a SegmentTemplate.
+}
+
+void ISegment::setByteRange(size_t start, size_t end)
+{
+    startByte = start;
+    endByte   = end;
+}
+
+size_t ISegment::getOffset() const
+{
+    return startByte;
+}
+
+std::string ISegment::toString(int indent) const
+{
+    std::stringstream ss;
+    ss << std::string(indent, ' ') << debugName << " url=" << getUrlSegment().toString();
+    if(startByte!=endByte)
+        ss << " @" << startByte << ".." << endByte;
+    return ss.str();
+}
+
+bool ISegment::contains(size_t byte) const
+{
+    if (startByte == endByte)
+        return false;
+    return (byte >= startByte &&
+            (!endByte || byte <= endByte) );
+}
+
+int ISegment::getClassId() const
+{
+    return classId;
+}
+
+ISegment::SegmentChunk::SegmentChunk(ISegment *segment_, const std::string &url) :
+    dash::http::Chunk(url)
+{
+    segment = segment_;
+}
+
+void ISegment::SegmentChunk::onDownload(void *, size_t)
+{
+
+}
+
+Segment::Segment(ICanonicalUrl *parent) :
+        ISegment(parent)
+{
+    size = -1;
+    classId = CLASSID_SEGMENT;
+}
+
+void Segment::addSubSegment(SubSegment *subsegment)
+{
+    subsegments.push_back(subsegment);
+}
+
+Segment::~Segment()
+{
+    std::vector<SubSegment*>::iterator it;
+    for(it=subsegments.begin();it!=subsegments.end();it++)
+        delete *it;
+}
+
+void                    Segment::setSourceUrl   ( const std::string &url )
+{
+    if ( url.empty() == false )
+        this->sourceUrl = url;
+}
+
+std::string Segment::toString(int indent) const
+{
+    if (subsegments.empty())
+    {
+        return ISegment::toString(indent);
+    }
+    else
+    {
+        std::string ret;
+        std::vector<SubSegment *>::const_iterator l;
+        for(l = subsegments.begin(); l != subsegments.end(); l++)
+        {
+            ret.append( (*l)->toString(indent + 1) );
+        }
+        return ret;
+    }
+}
+
+Url Segment::getUrlSegment() const
+{
+    Url ret = getParentUrlSegment();
+    if (!sourceUrl.empty())
+        ret.append(sourceUrl);
+    return ret;
+}
+
+dash::http::Chunk* Segment::toChunk(size_t index, Representation *ctxrep)
+{
+    Chunk *chunk = ISegment::toChunk(index, ctxrep);
+    if (chunk && ctxrep)
+        chunk->setBitrate(ctxrep->getBandwidth());
+    return chunk;
+}
+
+std::vector<ISegment*> Segment::subSegments()
+{
+    std::vector<ISegment*> list;
+    if(!subsegments.empty())
+    {
+        std::vector<SubSegment*>::iterator it;
+        for(it=subsegments.begin();it!=subsegments.end();it++)
+            list.push_back(*it);
+    }
+    else
+    {
+        list.push_back(this);
+    }
+    return list;
+}
+
+InitSegment::InitSegment(ICanonicalUrl *parent) :
+    Segment(parent)
+{
+    debugName = "InitSegment";
+    classId = CLASSID_INITSEGMENT;
+}
+
+IndexSegment::IndexSegment(ICanonicalUrl *parent) :
+    Segment(parent)
+{
+    debugName = "IndexSegment";
+    classId = CLASSID_INDEXSEGMENT;
+}
+
+dash::http::Chunk* IndexSegment::toChunk(size_t index, Representation *ctxrep)
+{
+    IndexSegmentChunk *chunk = dynamic_cast<IndexSegmentChunk *>(Segment::toChunk(index, ctxrep));
+    chunk->setIndexRepresentation(ctxrep);
+    return chunk;
+}
+
+dash::http::Chunk * IndexSegment::getChunk(const std::string &url)
+{
+    return new IndexSegmentChunk(this, url);
+}
+
+IndexSegment::IndexSegmentChunk::IndexSegmentChunk(ISegment *segment, const std::string &url)
+    : SegmentChunk(segment, url)
+{
+    rep = NULL;
+}
+
+void IndexSegment::IndexSegmentChunk::setIndexRepresentation(Representation *rep_)
+{
+    rep = rep_;
+}
+
+void IndexSegment::IndexSegmentChunk::onDownload(void *buffer, size_t size)
+{
+    if(!rep)
+        return;
+
+    dash::mp4::AtomsReader br(rep->getMPD()->getVLCObject());
+    br.parseBlock(buffer, size, rep);
+}
+
+SubSegment::SubSegment(Segment *main, size_t start, size_t end) :
+    ISegment(main), parent(main)
+{
+    setByteRange(start, end);
+    debugName = "SubSegment";
+    classId = CLASSID_SUBSEGMENT;
+}
+
+Url SubSegment::getUrlSegment() const
+{
+    return getParentUrlSegment();
+}
+
+std::vector<ISegment*> SubSegment::subSegments()
+{
+    std::vector<ISegment*> list;
+    list.push_back(this);
+    return list;
+}
diff --git a/modules/demux/dash/mpd/Segment.h b/modules/demux/dash/mpd/Segment.h
new file mode 100644 (file)
index 0000000..57d4677
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * Segment.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 SEGMENT_H_
+#define SEGMENT_H_
+
+#include <string>
+#include <sstream>
+#include <vector>
+#include "mpd/BaseUrl.h"
+#include "mpd/ICanonicalUrl.hpp"
+#include "http/Chunk.h"
+#include "Properties.hpp"
+
+namespace dash
+{
+    namespace mpd
+    {
+        class Representation;
+        class SubSegment;
+        class SegmentInformation;
+
+        class ISegment : public ICanonicalUrl
+        {
+            public:
+                ISegment(const ICanonicalUrl *parent);
+                virtual ~ISegment(){}
+                /**
+                 *  @return true if the segment should be dropped after being read.
+                 *          That is basically true when using an Url, and false
+                 *          when using an UrlTemplate
+                 */
+                virtual bool                            isSingleShot    () const;
+                virtual void                            done            ();
+                virtual dash::http::Chunk*              toChunk         (size_t, Representation * = NULL);
+                virtual void                            setByteRange    (size_t start, size_t end);
+                virtual size_t                          getOffset       () const;
+                virtual std::vector<ISegment*>          subSegments     () = 0;
+                virtual std::string                     toString        (int = 0) const;
+                virtual bool                            contains        (size_t byte) const;
+                int                                     getClassId      () const;
+                Property<mtime_t>       startTime;
+                Property<mtime_t>       duration;
+
+                static const int CLASSID_ISEGMENT = 0;
+
+            protected:
+                size_t                  startByte;
+                size_t                  endByte;
+                std::string             debugName;
+                int                     classId;
+
+                class SegmentChunk : public dash::http::Chunk
+                {
+                    public:
+                        SegmentChunk(ISegment *segment, const std::string &url);
+                        virtual void onDownload(void *, size_t);
+
+                    protected:
+                        ISegment *segment;
+                };
+
+                virtual dash::http::Chunk * getChunk(const std::string &);
+        };
+
+        class Segment : public ISegment
+        {
+            public:
+                Segment( ICanonicalUrl *parent );
+                ~Segment();
+                virtual void setSourceUrl( const std::string &url );
+                virtual Url getUrlSegment() const; /* impl */
+                virtual dash::http::Chunk* toChunk(size_t, Representation * = NULL);
+                virtual std::vector<ISegment*> subSegments();
+                virtual std::string toString(int = 0) const;
+                virtual void addSubSegment(SubSegment *);
+                static const int CLASSID_SEGMENT = 1;
+
+            protected:
+                std::vector<SubSegment *> subsegments;
+                std::string sourceUrl;
+                int size;
+        };
+
+        class InitSegment : public Segment
+        {
+            public:
+                InitSegment( ICanonicalUrl *parent );
+                static const int CLASSID_INITSEGMENT = 2;
+        };
+
+        class IndexSegment : public Segment
+        {
+            public:
+                IndexSegment( ICanonicalUrl *parent );
+                virtual dash::http::Chunk* toChunk(size_t, Representation * = NULL);
+                static const int CLASSID_INDEXSEGMENT = 3;
+
+            protected:
+                class IndexSegmentChunk : public SegmentChunk
+                {
+                    public:
+                        IndexSegmentChunk(ISegment *segment, const std::string &);
+                        void setIndexRepresentation(Representation *);
+                        virtual void onDownload(void *, size_t);
+
+                    private:
+                        Representation *rep;
+                };
+
+                virtual dash::http::Chunk * getChunk(const std::string &);
+        };
+
+        class SubSegment : public ISegment
+        {
+            public:
+                SubSegment(Segment *, size_t start, size_t end);
+                virtual Url getUrlSegment() const; /* impl */
+                virtual std::vector<ISegment*> subSegments();
+                static const int CLASSID_SUBSEGMENT = 4;
+            private:
+                Segment *parent;
+        };
+    }
+}
+
+#endif /* SEGMENT_H_ */
diff --git a/modules/demux/dash/mpd/SegmentBase.cpp b/modules/demux/dash/mpd/SegmentBase.cpp
new file mode 100644 (file)
index 0000000..add6b62
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * SegmentBase.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2012 Klagenfurt University
+ *
+ * Created on: Jan 27, 2012
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "SegmentBase.h"
+
+using namespace dash::mpd;
+
+SegmentBase::SegmentBase    () :
+             initSeg        (NULL)
+{
+}
+SegmentBase::~SegmentBase   ()
+{
+}
+
+void        SegmentBase::addInitSegment  (Segment *seg)
+{
+    this->initSeg = seg;
+}
+Segment*    SegmentBase::getInitSegment  ()
+{
+    return this->initSeg;
+}
diff --git a/modules/demux/dash/mpd/SegmentBase.h b/modules/demux/dash/mpd/SegmentBase.h
new file mode 100644 (file)
index 0000000..f9bd9fc
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * SegmentBase.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2012 Klagenfurt University
+ *
+ * Created on: Jan 27, 2012
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 SEGMENTBASE_H_
+#define SEGMENTBASE_H_
+
+#include "mpd/Segment.h"
+
+namespace dash
+{
+    namespace mpd
+    {
+        class SegmentBase
+        {
+            public:
+                SegmentBase             ();
+                virtual ~SegmentBase    ();
+
+                void        addInitSegment  (Segment *seg);
+                Segment*    getInitSegment  ();
+
+            private:
+                Segment *initSeg;
+        };
+    }
+}
+
+#endif /* SEGMENTBASE_H_ */
diff --git a/modules/demux/dash/mpd/SegmentInfo.cpp b/modules/demux/dash/mpd/SegmentInfo.cpp
new file mode 100644 (file)
index 0000000..aa3da57
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * SegmentInfo.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "SegmentInfo.h"
+
+using namespace dash::mpd;
+
+SegmentInfo::SegmentInfo( ICanonicalUrl *parent ) :
+    SegmentInfoCommon( parent ),
+    initSeg( NULL )
+{
+}
+
+SegmentInfo::~SegmentInfo   ()
+{
+    for(size_t i = 0; i < this->segments.size(); i++)
+        delete(this->segments.at(i));
+
+    delete(this->initSeg);
+}
+
+const std::vector<Segment*>&   SegmentInfo::getSegments        () const
+{
+    return this->segments;
+}
+
+void                    SegmentInfo::addSegment         (Segment *seg)
+{
+    this->segments.push_back(seg);
+}
+
diff --git a/modules/demux/dash/mpd/SegmentInfo.h b/modules/demux/dash/mpd/SegmentInfo.h
new file mode 100644 (file)
index 0000000..a7896cf
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * SegmentInfo.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 SEGMENTINFO_H_
+#define SEGMENTINFO_H_
+
+#include <vector>
+#include <string>
+#include <map>
+
+#include "mpd/Segment.h"
+#include "mpd/SegmentInfoCommon.h"
+#include "ICanonicalUrl.hpp"
+
+namespace dash
+{
+    namespace mpd
+    {
+        class SegmentInfo : public SegmentInfoCommon
+        {
+            public:
+                SegmentInfo             ( ICanonicalUrl * = NULL );
+                virtual ~SegmentInfo    ();
+
+                const std::vector<Segment *>&   getSegments() const;
+                void                    addSegment(Segment *seg);
+
+            private:
+                Segment                             *initSeg;
+                std::vector<Segment *>              segments;
+        };
+    }
+}
+
+#endif /* SEGMENTINFO_H_ */
diff --git a/modules/demux/dash/mpd/SegmentInfoCommon.cpp b/modules/demux/dash/mpd/SegmentInfoCommon.cpp
new file mode 100644 (file)
index 0000000..8cb0112
--- /dev/null
@@ -0,0 +1,106 @@
+/*****************************************************************************
+ * SegmentInfoCommon.cpp: Implement the common part for both SegmentInfoDefault
+ *                        and SegmentInfo
+ *****************************************************************************
+ * Copyright (C) 1998-2007 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "SegmentInfoCommon.h"
+
+#include "Segment.h"
+#include "SegmentTimeline.h"
+
+using namespace dash::mpd;
+
+SegmentInfoCommon::SegmentInfoCommon( ICanonicalUrl *parent ) :
+    ICanonicalUrl( parent ),
+    duration( -1 ),
+    startIndex( 0 ),
+    initialisationSegment( NULL ),
+    segmentTimeline( NULL )
+{
+}
+
+SegmentInfoCommon::~SegmentInfoCommon()
+{
+    delete this->segmentTimeline;
+    delete this->initialisationSegment;
+}
+
+time_t      SegmentInfoCommon::getDuration() const
+{
+    return this->duration;
+}
+
+void        SegmentInfoCommon::setDuration( time_t duration )
+{
+    if ( duration >= 0 )
+        this->duration = duration;
+}
+
+int         SegmentInfoCommon::getStartIndex() const
+{
+    return this->startIndex;
+}
+
+void        SegmentInfoCommon::setStartIndex(int startIndex)
+{
+    if ( startIndex >= 0 )
+        this->startIndex = startIndex;
+}
+
+Segment*  SegmentInfoCommon::getInitialisationSegment() const
+{
+    return this->initialisationSegment;
+}
+
+void SegmentInfoCommon::setInitialisationSegment(Segment *seg)
+{
+    if ( seg != NULL )
+        this->initialisationSegment = seg;
+}
+
+void SegmentInfoCommon::appendBaseURL(const std::string &url)
+{
+    this->baseURLs.push_back( url );
+}
+
+const SegmentTimeline *SegmentInfoCommon::getSegmentTimeline() const
+{
+    return this->segmentTimeline;
+}
+
+void SegmentInfoCommon::setSegmentTimeline( const SegmentTimeline *segTl )
+{
+    if ( segTl != NULL )
+        this->segmentTimeline = segTl;
+}
+
+Url SegmentInfoCommon::getUrlSegment() const
+{
+    Url ret = getParentUrlSegment();
+    if (!baseURLs.empty())
+        ret.append(baseURLs.front());
+    return ret;
+}
diff --git a/modules/demux/dash/mpd/SegmentInfoCommon.h b/modules/demux/dash/mpd/SegmentInfoCommon.h
new file mode 100644 (file)
index 0000000..2e4dbda
--- /dev/null
@@ -0,0 +1,66 @@
+/*****************************************************************************
+ * SegmentInfoCommon.h: Implement the common part for both SegmentInfoDefault
+ *                      and SegmentInfo
+ *****************************************************************************
+ * Copyright (C) 1998-2007 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
+ *
+ * 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 SEGMENTINFOCOMMON_H
+#define SEGMENTINFOCOMMON_H
+
+#include <string>
+#include <list>
+#include <ctime>
+#include "ICanonicalUrl.hpp"
+
+namespace dash
+{
+    namespace mpd
+    {
+        class Segment;
+        class SegmentTimeline;
+
+        class SegmentInfoCommon : public ICanonicalUrl
+        {
+            public:
+                SegmentInfoCommon( ICanonicalUrl *parent = NULL );
+                virtual ~SegmentInfoCommon();
+                time_t                  getDuration() const;
+                void                    setDuration( time_t duration );
+                int                     getStartIndex() const;
+                void                    setStartIndex( int startIndex );
+                Segment*                getInitialisationSegment() const;
+                void                    setInitialisationSegment( Segment* seg );
+                void                    appendBaseURL( const std::string& url );
+                const SegmentTimeline*  getSegmentTimeline() const;
+                void                    setSegmentTimeline( const SegmentTimeline *segTl );
+                virtual Url             getUrlSegment() const; /* impl */
+
+            private:
+                time_t                  duration;
+                int                     startIndex;
+                Segment*                initialisationSegment;
+                std::list<std::string>  baseURLs;
+                const SegmentTimeline*  segmentTimeline;
+        };
+    }
+}
+
+#endif // SEGMENTINFOCOMMON_H
diff --git a/modules/demux/dash/mpd/SegmentInfoDefault.cpp b/modules/demux/dash/mpd/SegmentInfoDefault.cpp
new file mode 100644 (file)
index 0000000..f9a3159
--- /dev/null
@@ -0,0 +1,55 @@
+/*****************************************************************************
+ * SegmentInfoDefault.cpp: Implement the SegmentInfoDefault element.
+ *****************************************************************************
+ * Copyright (C) 1998-2007 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "SegmentInfoDefault.h"
+
+using namespace dash::mpd;
+
+SegmentInfoDefault::SegmentInfoDefault()
+{
+}
+
+const std::string&      SegmentInfoDefault::getSourceURLTemplatePeriod() const
+{
+    return this->sourceURLTemplatePeriod;
+}
+
+void    SegmentInfoDefault::setSourceURLTemplatePediod( const std::string &url )
+{
+    if ( url.empty() == false )
+        this->sourceURLTemplatePeriod = url;
+}
+
+int     SegmentInfoDefault::getIndexTemplate() const
+{
+    return this->indexTemplate;
+}
+
+void    SegmentInfoDefault::setIndexTemplate( int indexTpl )
+{
+    if ( indexTpl >= 0 )
+        this->indexTemplate = indexTpl;
+}
diff --git a/modules/demux/dash/mpd/SegmentInfoDefault.h b/modules/demux/dash/mpd/SegmentInfoDefault.h
new file mode 100644 (file)
index 0000000..a15ab77
--- /dev/null
@@ -0,0 +1,52 @@
+/*****************************************************************************
+ * SegmentInfoDefault.cpp: Implement the SegmentInfoDefault element.
+ *****************************************************************************
+ * Copyright (C) 1998-2007 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
+ *
+ * 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 SEGMENTINFODEFAULT_H
+#define SEGMENTINFODEFAULT_H
+
+#include "mpd/SegmentInfoCommon.h"
+
+#include <string>
+
+namespace dash
+{
+    namespace mpd
+    {
+        class SegmentInfoDefault : public SegmentInfoCommon
+        {
+            public:
+                SegmentInfoDefault();
+                const std::string&  getSourceURLTemplatePeriod() const;
+                void                setSourceURLTemplatePediod( const std::string &url );
+                int                 getIndexTemplate() const;
+                void                setIndexTemplate( int indexTpl );
+
+            private:
+                std::string         sourceURLTemplatePeriod;
+                int                 indexTemplate;
+        };
+    }
+}
+
+
+#endif // SEGMENTINFODEFAULT_H
diff --git a/modules/demux/dash/mpd/SegmentInformation.cpp b/modules/demux/dash/mpd/SegmentInformation.cpp
new file mode 100644 (file)
index 0000000..95eb5d3
--- /dev/null
@@ -0,0 +1,222 @@
+/*
+ * SegmentInformation.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 "SegmentInformation.hpp"
+
+#include "Segment.h"
+#include "SegmentBase.h"
+#include "SegmentList.h"
+#include "SegmentTemplate.h"
+
+using namespace dash::mpd;
+using namespace std;
+
+SegmentInformation::SegmentInformation(SegmentInformation *parent_) :
+    ICanonicalUrl( parent_ )
+{
+    parent = parent_;
+    segmentBase = NULL;
+    segmentList = NULL;
+    for(int i=0; i<InfoTypeCount; i++)
+        segmentTemplate[i] = NULL;
+    bitswitch_policy = BITSWITCH_INHERIT;
+    timescale.Set(0);
+}
+
+SegmentInformation::SegmentInformation(ICanonicalUrl * parent_) :
+    ICanonicalUrl( parent_ )
+{
+    parent = NULL;
+    segmentBase = NULL;
+    segmentList = NULL;
+    for(int i=0; i<InfoTypeCount; i++)
+        segmentTemplate[i] = NULL;
+    bitswitch_policy = BITSWITCH_INHERIT;
+    timescale.Set(0);
+}
+
+SegmentInformation::~SegmentInformation()
+{
+    delete segmentBase;
+    delete segmentList;
+    for(int i=0; i<InfoTypeCount; i++)
+        delete segmentTemplate[i];
+}
+
+vector<ISegment *> SegmentInformation::getSegments() const
+{
+    vector<ISegment *> retSegments;
+
+    SegmentBase *segBase = inheritSegmentBase();
+    SegmentList *segList = inheritSegmentList();
+
+    /* init segments are always single segment */
+    if( segBase && segBase->getInitSegment() )
+    {
+        retSegments.push_back( segBase->getInitSegment() );
+    }
+    else if ( segList && segList->getInitialisationSegment() )
+    {
+        retSegments.push_back( segList->getInitialisationSegment() );
+    }
+    else if( inheritSegmentTemplate(INFOTYPE_INIT) )
+    {
+        retSegments.push_back( inheritSegmentTemplate(INFOTYPE_INIT) );
+    }
+
+    if( inheritSegmentTemplate(INFOTYPE_MEDIA) )
+    {
+        retSegments.push_back( inheritSegmentTemplate(INFOTYPE_MEDIA) );
+    }
+    else if ( segList && !segList->getSegments().empty() )
+    {
+        std::vector<Segment *>::const_iterator it;
+        for(it=segList->getSegments().begin();
+            it!=segList->getSegments().end(); it++)
+        {
+            std::vector<ISegment *> list = (*it)->subSegments();
+            retSegments.insert( retSegments.end(), list.begin(), list.end() );
+        }
+    }
+
+    return retSegments;
+}
+
+bool SegmentInformation::canBitswitch() const
+{
+    if(bitswitch_policy == BITSWITCH_INHERIT)
+        return (parent) ? parent->canBitswitch() : false;
+    else
+        return (bitswitch_policy == BITSWITCH_YES);
+}
+
+uint64_t SegmentInformation::getTimescale() const
+{
+    if (timescale.Get())
+        return timescale.Get();
+    else if (parent)
+        return parent->getTimescale();
+    else
+        return 1;
+}
+
+mtime_t SegmentInformation::getPeriodStart() const
+{
+    if(parent)
+        return parent->getPeriodStart();
+    else
+        return 0;
+}
+
+void SegmentInformation::setSegmentList(SegmentList *list)
+{
+    segmentList = list;
+}
+
+void SegmentInformation::setSegmentBase(SegmentBase *base)
+{
+    segmentBase = base;
+}
+
+void SegmentInformation::setSegmentTemplate(SegmentTemplate *templ, SegmentInfoType type)
+{
+    segmentTemplate[type] = templ;
+}
+
+static void insertIntoSegment(std::vector<Segment *> &seglist, size_t start,
+                              size_t end, mtime_t time)
+{
+    std::vector<Segment *>::iterator segIt;
+    for(segIt = seglist.begin(); segIt < seglist.end(); segIt++)
+    {
+        Segment *segment = *segIt;
+        if(segment->getClassId() == Segment::CLASSID_SEGMENT &&
+           segment->contains(end + segment->getOffset()))
+        {
+            SubSegment *subsegment = new SubSegment(segment,
+                                                    start + segment->getOffset(),
+                                                    end + segment->getOffset());
+            segment->addSubSegment(subsegment);
+            segment->startTime.Set(time);
+            break;
+        }
+    }
+}
+
+void SegmentInformation::SplitUsingIndex(std::vector<SplitPoint> &splitlist)
+{
+    std::vector<Segment *> seglist = segmentList->getSegments();
+    std::vector<SplitPoint>::const_iterator splitIt;
+    size_t start = 0, end = 0;
+    mtime_t time = 0;
+
+    for(splitIt = splitlist.begin(); splitIt < splitlist.end(); splitIt++)
+    {
+        start = end;
+        SplitPoint split = *splitIt;
+        end = split.offset;
+        if(splitIt == splitlist.begin() && split.offset == 0)
+            continue;
+        time = split.time;
+        insertIntoSegment(seglist, start, end, time);
+        end++;
+    }
+
+    if(start != 0)
+    {
+        start = end;
+        end = 0;
+        insertIntoSegment(seglist, start, end, time);
+    }
+}
+
+void SegmentInformation::setBitstreamSwitching(bool bitswitch)
+{
+    bitswitch_policy = (bitswitch) ? BITSWITCH_YES : BITSWITCH_NO;
+}
+
+SegmentBase * SegmentInformation::inheritSegmentBase() const
+{
+    if(segmentBase)
+        return segmentBase;
+    else if (parent)
+        return parent->inheritSegmentBase();
+    else
+        return NULL;
+}
+
+SegmentList * SegmentInformation::inheritSegmentList() const
+{
+    if(segmentList)
+        return segmentList;
+    else if (parent)
+        return parent->inheritSegmentList();
+    else
+        return NULL;
+}
+
+SegmentTemplate * SegmentInformation::inheritSegmentTemplate(SegmentInfoType type) const
+{
+    if(segmentTemplate[type])
+        return segmentTemplate[type];
+    else if (parent)
+        return parent->inheritSegmentTemplate(type);
+    else
+        return NULL;
+}
diff --git a/modules/demux/dash/mpd/SegmentInformation.hpp b/modules/demux/dash/mpd/SegmentInformation.hpp
new file mode 100644 (file)
index 0000000..0564fa9
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * SegmentInformation.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 SEGMENTINFORMATION_HPP
+#define SEGMENTINFORMATION_HPP
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "ICanonicalUrl.hpp"
+#include "Properties.hpp"
+#include <vlc_common.h>
+#include <vector>
+
+namespace dash
+{
+    namespace mpd
+    {
+        class ISegment;
+        class SegmentBase;
+        class SegmentList;
+        class SegmentTemplate;
+
+        /* common segment elements for period/adaptset/rep 5.3.9.1,
+         * with properties inheritance */
+        class SegmentInformation : public ICanonicalUrl
+        {
+            friend class IsoffMainParser;
+
+            public:
+                SegmentInformation( SegmentInformation * = 0 );
+                explicit SegmentInformation( ICanonicalUrl * );
+                virtual ~SegmentInformation();
+                std::vector<ISegment *> getSegments() const;
+                bool canBitswitch() const;
+                uint64_t getTimescale() const;
+                virtual mtime_t getPeriodStart() const;
+
+                class SplitPoint
+                {
+                    public:
+                        size_t offset;
+                        mtime_t time;
+                };
+                void SplitUsingIndex(std::vector<SplitPoint>&);
+
+                enum SegmentInfoType
+                {
+                    INFOTYPE_INIT = 0,
+                    INFOTYPE_MEDIA,
+                    INFOTYPE_INDEX
+                };
+                static const int InfoTypeCount = INFOTYPE_INDEX + 1;
+
+            private:
+                void setSegmentList(SegmentList *);
+                void setSegmentBase(SegmentBase *);
+                void setSegmentTemplate(SegmentTemplate *, SegmentInfoType);
+                void setBitstreamSwitching(bool);
+
+                SegmentBase *     inheritSegmentBase() const;
+                SegmentList *     inheritSegmentList() const;
+                SegmentTemplate * inheritSegmentTemplate(SegmentInfoType) const;
+
+                SegmentInformation *parent;
+                SegmentBase     *segmentBase;
+                SegmentList     *segmentList;
+                SegmentTemplate *segmentTemplate[InfoTypeCount];
+
+                enum BitswitchPolicy
+                {
+                    BITSWITCH_INHERIT,
+                    BITSWITCH_YES,
+                    BITSWITCH_NO
+                } bitswitch_policy;
+
+                Property<uint64_t> timescale;
+        };
+    }
+}
+
+#endif // SEGMENTINFORMATION_HPP
diff --git a/modules/demux/dash/mpd/SegmentList.cpp b/modules/demux/dash/mpd/SegmentList.cpp
new file mode 100644 (file)
index 0000000..6395fff
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * SegmentList.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2012 Klagenfurt University
+ *
+ * Created on: Jan 27, 2012
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "SegmentList.h"
+
+using namespace dash::mpd;
+
+SegmentList::SegmentList    ( ICanonicalUrl *parent ):
+    SegmentInfo( parent )
+{
+
+}
+SegmentList::~SegmentList   ()
+{
+}
diff --git a/modules/demux/dash/mpd/SegmentList.h b/modules/demux/dash/mpd/SegmentList.h
new file mode 100644 (file)
index 0000000..20c35ed
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * SegmentList.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2012 Klagenfurt University
+ *
+ * Created on: Jan 27, 2012
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 SEGMENTLIST_H_
+#define SEGMENTLIST_H_
+
+#include "mpd/SegmentInfo.h"
+#include "mpd/ICanonicalUrl.hpp"
+
+namespace dash
+{
+    namespace mpd
+    {
+        class SegmentList : public SegmentInfo
+        {
+            public:
+                SegmentList             ( ICanonicalUrl * = NULL );
+                virtual ~SegmentList    ();
+        };
+    }
+}
+
+#endif /* SEGMENTLIST_H_ */
diff --git a/modules/demux/dash/mpd/SegmentTemplate.cpp b/modules/demux/dash/mpd/SegmentTemplate.cpp
new file mode 100644 (file)
index 0000000..b681ddd
--- /dev/null
@@ -0,0 +1,75 @@
+/*****************************************************************************
+ * SegmentTemplate.cpp: Implement the UrlTemplate element.
+ *****************************************************************************
+ * Copyright (C) 1998-2007 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "SegmentTemplate.h"
+#include "SegmentTimeline.h"
+#include "Representation.h"
+#include "AdaptationSet.h"
+#include "SegmentInfoDefault.h"
+
+using namespace dash::mpd;
+
+SegmentTemplate::SegmentTemplate( ICanonicalUrl *parent ) :
+    Segment( parent ),
+    startIndex( 0 )
+{
+    debugName = "SegmentTemplate";
+    classId = Segment::CLASSID_SEGMENT;
+    duration.Set(0);
+    timescale.Set(0);
+}
+
+Url SegmentTemplate::getUrlSegment() const
+{
+    Url ret = getParentUrlSegment();
+    if (!sourceUrl.empty())
+    {
+        ret.append(Url::Component(sourceUrl, this));
+    }
+    return ret;
+}
+
+size_t SegmentTemplate::getStartIndex() const
+{
+    return startIndex;
+}
+
+void SegmentTemplate::setStartIndex(size_t i)
+{
+    startIndex = i;
+}
+
+bool            SegmentTemplate::isSingleShot() const
+{
+    return false;
+}
+
+InitSegmentTemplate::InitSegmentTemplate( ICanonicalUrl *parent ) :
+    SegmentTemplate(parent)
+{
+    debugName = "InitSegmentTemplate";
+    classId = InitSegment::CLASSID_INITSEGMENT;
+}
diff --git a/modules/demux/dash/mpd/SegmentTemplate.h b/modules/demux/dash/mpd/SegmentTemplate.h
new file mode 100644 (file)
index 0000000..31dbd3f
--- /dev/null
@@ -0,0 +1,58 @@
+/*****************************************************************************
+ * SegmentTemplate.cpp: Implement the UrlTemplate element.
+ *****************************************************************************
+ * Copyright (C) 1998-2007 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
+ *
+ * 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 SEGMENTTEMPLATE_H
+#define SEGMENTTEMPLATE_H
+
+#include "mpd/Segment.h"
+#include "Properties.hpp"
+
+namespace dash
+{
+    namespace mpd
+    {
+        class ICanonicalUrl;
+
+        class SegmentTemplate : public Segment
+        {
+            public:
+                SegmentTemplate( ICanonicalUrl * = NULL );
+                virtual Url             getUrlSegment() const; /* reimpl */
+                virtual bool            isSingleShot() const;
+                size_t                  getStartIndex() const;
+                void                    setStartIndex(size_t);
+                Property<mtime_t>       duration;
+                Property<uint64_t>      timescale;
+
+            private:
+                size_t                  startIndex;
+        };
+
+        class InitSegmentTemplate : public SegmentTemplate
+        {
+            public:
+                InitSegmentTemplate( ICanonicalUrl * = NULL );
+        };
+    }
+}
+#endif // SEGMENTTEMPLATE_H
diff --git a/modules/demux/dash/mpd/SegmentTimeline.cpp b/modules/demux/dash/mpd/SegmentTimeline.cpp
new file mode 100644 (file)
index 0000000..d6dcc38
--- /dev/null
@@ -0,0 +1,98 @@
+/*****************************************************************************
+ * SegmentTimeline.cpp: Implement the SegmentTimeline tag.
+ *****************************************************************************
+ * Copyright (C) 1998-2007 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "SegmentTimeline.h"
+
+#include <vlc_common.h>
+#include <vlc_arrays.h>
+
+#include <iostream>
+
+using namespace dash::mpd;
+
+SegmentTimeline::SegmentTimeline() :
+    timescale( -1 )
+{
+}
+
+SegmentTimeline::~SegmentTimeline()
+{
+    vlc_delete_all( this->elements );
+}
+
+int dash::mpd::SegmentTimeline::getTimescale() const
+{
+    return this->timescale;
+}
+
+void dash::mpd::SegmentTimeline::setTimescale(int timescale)
+{
+    this->timescale = timescale;
+}
+
+void dash::mpd::SegmentTimeline::addElement(dash::mpd::SegmentTimeline::Element *e)
+{
+    int64_t offset = 0;
+
+    for ( int i = 0; i < e->r; ++i )
+    {
+        this->elements.push_back( e );
+        e = new SegmentTimeline::Element( *e );
+        offset += e->d;
+        e->t += offset;
+    }
+    this->elements.push_back( e );
+}
+
+const SegmentTimeline::Element*    SegmentTimeline::getElement( unsigned int index ) const
+{
+    if ( this->elements.size() <= index )
+        return NULL;
+    std::list<Element*>::const_iterator     it = this->elements.begin();
+    std::list<Element*>::const_iterator     end = this->elements.end();
+    unsigned int                            i = 0;
+    while ( it != end )
+    {
+        if ( i == index )
+            return *it;
+        ++it;
+        ++i;
+    }
+    return NULL;
+}
+
+dash::mpd::SegmentTimeline::Element::Element() :
+    r( 0 )
+{
+}
+
+SegmentTimeline::Element::Element(const SegmentTimeline::Element &e) :
+    t( e.t ),
+    d( e.d ),
+    r( 0 )
+{
+}
diff --git a/modules/demux/dash/mpd/SegmentTimeline.h b/modules/demux/dash/mpd/SegmentTimeline.h
new file mode 100644 (file)
index 0000000..7763bbe
--- /dev/null
@@ -0,0 +1,60 @@
+/*****************************************************************************
+ * SegmentTimeline.cpp: Implement the SegmentTimeline tag.
+ *****************************************************************************
+ * Copyright (C) 1998-2007 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
+ *
+ * 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 SEGMENTTIMELINE_H
+#define SEGMENTTIMELINE_H
+
+#include <sys/types.h>
+#include <list>
+#include <stdint.h>
+
+namespace dash
+{
+    namespace mpd
+    {
+        class SegmentTimeline
+        {
+            public:
+                struct  Element
+                {
+                    Element();
+                    Element( const Element& e );
+                    int64_t     t;
+                    int64_t     d;
+                    int         r;
+                };
+                SegmentTimeline();
+                ~SegmentTimeline();
+                int                     getTimescale() const;
+                void                    setTimescale( int timescale );
+                void                    addElement( Element* e );
+                const Element*          getElement( unsigned int index ) const;
+
+            private:
+                int                     timescale;
+                std::list<Element*>     elements;
+        };
+    }
+}
+
+#endif // SEGMENTTIMELINE_H
diff --git a/modules/demux/dash/mpd/TrickModeType.cpp b/modules/demux/dash/mpd/TrickModeType.cpp
new file mode 100644 (file)
index 0000000..f40ea50
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * TrickModeType.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "TrickModeType.h"
+
+using namespace dash::mpd;
+
+TrickModeType::TrickModeType() :
+    alternatePlayoutRate( 1 )
+{
+}
+
+int TrickModeType::getAlternatePlayoutRate() const
+{
+    return this->alternatePlayoutRate;
+}
+
+void TrickModeType::setAlternatePlayoutRate(int playoutRate)
+{
+    this->alternatePlayoutRate = playoutRate;
+}
+
diff --git a/modules/demux/dash/mpd/TrickModeType.h b/modules/demux/dash/mpd/TrickModeType.h
new file mode 100644 (file)
index 0000000..a854c83
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * TrickModeType.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 TRICKMODETYPE_H_
+#define TRICKMODETYPE_H_
+
+#include <string>
+#include <map>
+
+namespace dash
+{
+    namespace mpd
+    {
+        class TrickModeType
+        {
+            public:
+                TrickModeType           ();
+
+                int         getAlternatePlayoutRate() const;
+                void        setAlternatePlayoutRate( int playoutRate );
+
+            private:
+                int         alternatePlayoutRate;
+        };
+    }
+}
+#endif /* TRICKMODETYPE_H_ */
diff --git a/modules/demux/dash/mpd/Url.cpp b/modules/demux/dash/mpd/Url.cpp
new file mode 100644 (file)
index 0000000..21c4148
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * Url.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 "Url.hpp"
+#include "Representation.h"
+#include "SegmentTemplate.h"
+#include "MPD.h"
+
+#include <sstream>
+using namespace dash::mpd;
+
+Url::Url()
+{
+}
+
+Url::Url(const Component & comp)
+{
+    prepend(comp);
+}
+
+Url::Url(const std::string &str)
+{
+    prepend(Component(str));
+}
+
+Url & Url::prepend(const Component & comp)
+{
+    components.insert(components.begin(), comp);
+    return *this;
+}
+
+Url & Url::append(const Component & comp)
+{
+    components.push_back(comp);
+    return *this;
+}
+
+Url & Url::prepend(const Url &url)
+{
+    components.insert(components.begin(), url.components.begin(), url.components.end());
+    return *this;
+}
+
+Url & Url::append(const Url &url)
+{
+    components.insert(components.end(), url.components.begin(), url.components.end());
+    return *this;
+}
+
+std::string Url::toString() const
+{
+    return toString(0, NULL);
+}
+
+std::string Url::toString(size_t index, const Representation *rep) const
+{
+    std::string ret;
+    std::vector<Component>::const_iterator it;
+    for(it = components.begin(); it != components.end(); it++)
+    {
+        ret.append((*it).contextualize(index, rep));
+    }
+    return ret;
+}
+
+Url::Component::Component(const std::string & str, const SegmentTemplate *templ_)
+{
+    component = str;
+    templ = templ_;
+}
+
+std::string Url::Component::contextualize(size_t index, const Representation *rep) const
+{
+    std::string ret(component);
+
+    if(!rep || !templ)
+        return ret;
+
+    size_t pos = ret.find("$Time$");
+    if(pos != std::string::npos)
+    {
+        std::stringstream ss;
+        ss << (templ->duration.Get() * index);
+        ret.replace(pos, std::string("$Time$").length(), ss.str());
+    }
+
+
+    pos = ret.find("$Number$");
+    if(pos != std::string::npos)
+    {
+        std::stringstream ss;
+        /* live streams / templated */
+        if(templ && rep->getMPD()->isLive() && templ->duration.Get())
+        {
+            mtime_t playbackstart = rep->getMPD()->playbackStart.Get();
+            mtime_t streamstart = rep->getMPD()->getAvailabilityStartTime();
+            streamstart += rep->getPeriodStart();
+            mtime_t duration = templ->duration.Get();
+            uint64_t timescale = templ->timescale.Get() ?
+                                 templ->timescale.Get() :
+                                 rep->getTimescale();
+            if(duration && timescale)
+                index += (playbackstart - streamstart) * timescale / duration;
+        }
+        ss << index;
+        ret.replace(pos, std::string("$Number$").length(), ss.str());
+    }
+
+    pos = ret.find("$Bandwidth$");
+    if(pos != std::string::npos)
+    {
+        std::stringstream ss;
+        ss << rep->getBandwidth();
+        ret.replace(pos, std::string("$Bandwidth$").length(), ss.str());
+    }
+
+    pos = ret.find("$RepresentationID$");
+    if(pos != std::string::npos)
+    {
+        std::stringstream ss;
+        ss << rep->getId();
+        ret.replace(pos, std::string("$RepresentationID$").length(), ss.str());
+    }
+
+    return ret;
+}
diff --git a/modules/demux/dash/mpd/Url.hpp b/modules/demux/dash/mpd/Url.hpp
new file mode 100644 (file)
index 0000000..9f73237
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Url.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 URL_HPP
+#define URL_HPP
+
+#include <string>
+#include <vector>
+
+namespace dash
+{
+    namespace mpd
+    {
+        class Representation;
+        class SegmentTemplate;
+
+        class Url
+        {
+            public:
+                class Component
+                {
+                    friend class Url;
+                    public:
+                        Component(const std::string &, const SegmentTemplate * = NULL);
+
+                    protected:
+                        std::string contextualize(size_t, const Representation *) const;
+                        std::string component;
+                        const SegmentTemplate *templ;
+                };
+
+                Url();
+                Url(const Component &);
+                explicit Url(const std::string &);
+                Url & prepend(const Component &);
+                Url & append(const Component &);
+                Url & append(const Url &);
+                Url & prepend(const Url &);
+                std::string toString(size_t, const Representation *) const;
+                std::string toString() const;
+
+            private:
+                std::vector<Component> components;
+        };
+    }
+}
+
+#endif // URL_HPP
diff --git a/modules/demux/dash/xml/DOMHelper.cpp b/modules/demux/dash/xml/DOMHelper.cpp
new file mode 100644 (file)
index 0000000..a00913d
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * DOMHelper.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "DOMHelper.h"
+
+using namespace dash::xml;
+
+std::vector<Node *> DOMHelper::getElementByTagName      (Node *root, const std::string& name, bool selfContain)
+{
+    std::vector<Node *> elements;
+
+    for(size_t i = 0; i < root->getSubNodes().size(); i++)
+    {
+        getElementsByTagName(root->getSubNodes().at(i), name, &elements, selfContain);
+    }
+
+    return elements;
+}
+
+std::vector<Node *> DOMHelper::getChildElementByTagName (Node *root, const std::string& name)
+{
+    std::vector<Node *> elements;
+
+    for(size_t i = 0; i < root->getSubNodes().size(); i++)
+    {
+        if( root->getSubNodes().at(i)->getName() == name )
+            elements.push_back(root->getSubNodes().at(i));
+    }
+
+    return elements;
+}
+
+void                DOMHelper::getElementsByTagName     (Node *root, const std::string& name, std::vector<Node*> *elements, bool selfContain)
+{
+    if(!selfContain && !root->getName().compare(name))
+    {
+        elements->push_back(root);
+        return;
+    }
+
+    if(!root->getName().compare(name))
+        elements->push_back(root);
+
+    for(size_t i = 0; i < root->getSubNodes().size(); i++)
+    {
+        getElementsByTagName(root->getSubNodes().at(i), name, elements, selfContain);
+    }
+}
+
+Node*           DOMHelper::getFirstChildElementByName( Node *root, const std::string &name )
+{
+    for(size_t i = 0; i < root->getSubNodes().size(); i++)
+    {
+        if( root->getSubNodes().at( i )->getName() == name )
+            return root->getSubNodes().at( i );
+    }
+    return NULL;
+}
diff --git a/modules/demux/dash/xml/DOMHelper.h b/modules/demux/dash/xml/DOMHelper.h
new file mode 100644 (file)
index 0000000..89f6400
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * DOMHelper.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 DOMHELPER_H_
+#define DOMHELPER_H_
+
+#include <vector>
+#include <string>
+
+#include "xml/Node.h"
+
+namespace dash
+{
+    namespace xml
+    {
+        class DOMHelper
+        {
+            public:
+                static std::vector<Node *> getElementByTagName      (Node *root, const std::string& name, bool selfContain);
+                static std::vector<Node *> getChildElementByTagName (Node *root, const std::string& name);
+                static Node*               getFirstChildElementByName( Node *root, const std::string& name );
+
+            private:
+                static void getElementsByTagName(Node *root, const std::string& name, std::vector<Node *> *elements, bool selfContain);
+        };
+    }
+}
+
+#endif /* DOMHELPER_H_ */
diff --git a/modules/demux/dash/xml/DOMParser.cpp b/modules/demux/dash/xml/DOMParser.cpp
new file mode 100644 (file)
index 0000000..1ebc3d5
--- /dev/null
@@ -0,0 +1,221 @@
+/*
+ * DOMParser.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "DOMParser.h"
+#include "../Helper.h"
+
+#include <vector>
+#include <stack>
+#include <vlc_xml.h>
+#include <vlc_stream.h>
+
+using namespace dash::xml;
+using namespace dash::mpd;
+
+DOMParser::DOMParser    (stream_t *stream) :
+    root( NULL ),
+    stream( stream ),
+    vlc_xml( NULL ),
+    vlc_reader( NULL )
+{
+}
+
+DOMParser::~DOMParser   ()
+{
+    delete this->root;
+    if(this->vlc_reader)
+        xml_ReaderDelete(this->vlc_reader);
+    if ( this->vlc_xml )
+        xml_Delete( this->vlc_xml );
+}
+
+Node*   DOMParser::getRootNode              ()
+{
+    return this->root;
+}
+bool    DOMParser::parse                    ()
+{
+    this->vlc_xml = xml_Create(this->stream);
+
+    if(!this->vlc_xml)
+        return false;
+
+    this->vlc_reader = xml_ReaderCreate(this->vlc_xml, this->stream);
+
+    if(!this->vlc_reader)
+        return false;
+
+    root = processNode();
+    if ( root == NULL )
+        return false;
+
+    return true;
+}
+
+Node* DOMParser::processNode()
+{
+    const char *data;
+    int type;
+    std::stack<Node *> lifo;
+
+    while( (type = xml_ReaderNextNode(vlc_reader, &data)) > 0 )
+    {
+        switch(type)
+        {
+            case XML_READER_STARTELEM:
+            {
+                bool empty = xml_ReaderIsEmptyElement(vlc_reader);
+                Node *node = new (std::nothrow) Node();
+                if(node)
+                {
+                    if(!lifo.empty())
+                        lifo.top()->addSubNode(node);
+                    lifo.push(node);
+
+                    node->setName(std::string(data));
+                    addAttributesToNode(node);
+                }
+
+                if(empty)
+                    lifo.pop();
+                break;
+            }
+
+            case XML_READER_TEXT:
+            {
+                if(!lifo.empty())
+                    lifo.top()->setText(std::string(data));
+                break;
+            }
+
+            case XML_READER_ENDELEM:
+            {
+                if(lifo.empty())
+                    return NULL;
+
+                Node *node = lifo.top();
+                lifo.pop();
+                if(lifo.empty())
+                    return node;
+            }
+
+            default:
+                break;
+        }
+    }
+
+    while( lifo.size() > 1 )
+        lifo.pop();
+
+    if(!lifo.empty())
+        delete lifo.top();
+
+    return NULL;
+}
+
+void    DOMParser::addAttributesToNode      (Node *node)
+{
+    const char *attrValue;
+    const char *attrName;
+
+    while((attrName = xml_ReaderNextAttr(this->vlc_reader, &attrValue)) != NULL)
+    {
+        std::string key     = attrName;
+        std::string value   = attrValue;
+        node->addAttribute(key, value);
+    }
+}
+void    DOMParser::print                    (Node *node, int offset)
+{
+    for(int i = 0; i < offset; i++)
+        msg_Dbg(this->stream, " ");
+
+    msg_Dbg(this->stream, "%s", node->getName().c_str());
+
+    std::vector<std::string> keys = node->getAttributeKeys();
+
+    for(size_t i = 0; i < keys.size(); i++)
+        msg_Dbg(this->stream, " %s=%s", keys.at(i).c_str(), node->getAttributeValue(keys.at(i)).c_str());
+
+    msg_Dbg(this->stream, "\n");
+
+    offset++;
+
+    for(size_t i = 0; i < node->getSubNodes().size(); i++)
+    {
+        this->print(node->getSubNodes().at(i), offset);
+    }
+}
+void    DOMParser::print                    ()
+{
+    this->print(this->root, 0);
+}
+bool    DOMParser::isDash                   (stream_t *stream)
+{
+    const std::string namespaces[] = {
+        "xmlns=\"urn:mpeg:mpegB:schema:DASH:MPD:DIS2011\"",
+        "xmlns=\"urn:mpeg:schema:dash:mpd:2011\"",
+        "xmlns=\"urn:mpeg:DASH:schema:MPD:2011\"",
+    };
+
+    const uint8_t *peek;
+    int peek_size = stream_Peek(stream, &peek, 1024);
+    if (peek_size < (int)namespaces[0].length())
+        return false;
+
+    std::string header((const char*)peek, peek_size);
+    for( size_t i=0; i<ARRAY_SIZE(namespaces); i++ )
+    {
+        if ( Helper::ifind(header, namespaces[i]) )
+            return true;
+    }
+    return false;
+}
+
+Profile DOMParser::getProfile() const
+{
+    Profile res(Profile::Unknown);
+    if(this->root == NULL)
+        return res;
+
+    std::string urn = this->root->getAttributeValue("profiles");
+    if ( urn.length() == 0 )
+        urn = this->root->getAttributeValue("profile"); //The standard spells it the both ways...
+
+
+    size_t pos;
+    size_t nextpos = -1;
+    do
+    {
+        pos = nextpos + 1;
+        nextpos = urn.find_first_of(",", pos);
+        res = Profile(urn.substr(pos, nextpos - pos));
+    }
+    while (nextpos != std::string::npos && res == Profile::Unknown);
+
+    return res;
+}
diff --git a/modules/demux/dash/xml/DOMParser.h b/modules/demux/dash/xml/DOMParser.h
new file mode 100644 (file)
index 0000000..deca094
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * DOMParser.h
+ *****************************************************************************
+ * Copyright (C) 2010 - 2011 Klagenfurt University
+ *
+ * Created on: Aug 10, 2010
+ * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
+ *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
+ *
+ * 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 DOMPARSER_H_
+#define DOMPARSER_H_
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+
+#include "xml/Node.h"
+#include "mpd/Profile.hpp"
+
+namespace dash
+{
+    namespace xml
+    {
+        class DOMParser
+        {
+            public:
+                DOMParser           (stream_t *stream);
+                virtual ~DOMParser  ();
+
+                bool                parse       ();
+                Node*               getRootNode ();
+                void                print       ();
+                static bool         isDash      (stream_t *stream);
+                mpd::Profile        getProfile  () const;
+
+            private:
+                Node                *root;
+                stream_t            *stream;
+
+                xml_t               *vlc_xml;
+                xml_reader_t        *vlc_reader;
+
+                Node*   processNode             ();
+                void    addAttributesToNode     (Node *node);
+                void    print                   (Node *node, int offset);
+        };
+    }