]> git.sesse.net Git - vlc/commitdiff
stream_filter: dash: add alwayslowest bitrate logic
authorFrancois Cartegnie <fcvlcdev@free.fr>
Thu, 27 Nov 2014 14:35:53 +0000 (15:35 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Thu, 18 Dec 2014 20:23:50 +0000 (21:23 +0100)
modules/stream_filter/Makefile.am
modules/stream_filter/dash/adaptationlogic/AdaptationLogicFactory.cpp
modules/stream_filter/dash/adaptationlogic/AdaptationLogicFactory.h
modules/stream_filter/dash/adaptationlogic/AlwaysLowestAdaptationLogic.cpp
modules/stream_filter/dash/adaptationlogic/AlwaysLowestAdaptationLogic.hpp

index 3c002d16779032a86cc5f904b714fc3575fd8457..fff34fb0a85cd237c59dfb5d92ae14bb434d9e47 100644 (file)
@@ -15,6 +15,8 @@ libdash_plugin_la_SOURCES = \
     stream_filter/dash/adaptationlogic/AdaptationLogicFactory.h \
     stream_filter/dash/adaptationlogic/AlwaysBestAdaptationLogic.cpp \
     stream_filter/dash/adaptationlogic/AlwaysBestAdaptationLogic.h \
+    stream_filter/dash/adaptationlogic/AlwaysLowestAdaptationLogic.cpp \
+    stream_filter/dash/adaptationlogic/AlwaysLowestAdaptationLogic.hpp \
     stream_filter/dash/adaptationlogic/IAdaptationLogic.h \
     stream_filter/dash/adaptationlogic/IDownloadRateObserver.h \
     stream_filter/dash/adaptationlogic/RateBasedAdaptationLogic.h \
index 7733960414ef82f51d0071baf3f6affeb695f9a3..727bc78d3f36a70372d52b9d9c2a89e439b03021 100644 (file)
@@ -26,6 +26,9 @@
 #endif
 
 #include "AdaptationLogicFactory.h"
+#include "adaptationlogic/AlwaysBestAdaptationLogic.h"
+#include "adaptationlogic/RateBasedAdaptationLogic.h"
+#include "adaptationlogic/AlwaysLowestAdaptationLogic.hpp"
 
 using namespace dash::logic;
 using namespace dash::xml;
@@ -38,8 +41,8 @@ IAdaptationLogic* AdaptationLogicFactory::create ( IAdaptationLogic::LogicType l
     {
         case IAdaptationLogic::AlwaysBest:      return new AlwaysBestAdaptationLogic    (mpdManager);
         case IAdaptationLogic::RateBased:       return new RateBasedAdaptationLogic     (mpdManager);
+        case IAdaptationLogic::AlwaysLowest:    return new AlwaysLowestAdaptationLogic  (mpdManager);
         case IAdaptationLogic::Default:
-        case IAdaptationLogic::AlwaysLowest:
         default:
             return NULL;
     }
index 4f17f8ab3432cc5e6a1485b91d82491802b27441..855ab9e4909aa0dd5909164ad5c4d2a6927e2d27 100644 (file)
@@ -28,8 +28,6 @@
 #include "adaptationlogic/IAdaptationLogic.h"
 #include "xml/Node.h"
 #include "mpd/MPDManager.hpp"
-#include "adaptationlogic/AlwaysBestAdaptationLogic.h"
-#include "adaptationlogic/RateBasedAdaptationLogic.h"
 
 struct stream_t;
 
index c5334f62aa01184e05a19968d15d5f3fba6e72d6..38e34c24201e9ce7bc55e5bedce6ebd440da1bf5 100644 (file)
@@ -1,5 +1,68 @@
+/*
+ * 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"
 
-AlwaysLowestAdaptationLogic::AlwaysLowestAdaptationLogic()
+using namespace dash::logic;
+using namespace dash::http;
+using namespace dash::mpd;
+
+AlwaysLowestAdaptationLogic::AlwaysLowestAdaptationLogic(dash::mpd::MPDManager *mpdManager):
+    AbstractAdaptationLogic(mpdManager),
+    currentPeriod(mpdManager->getFirstPeriod()),
+    count(0)
+{
+}
+
+Chunk*  AlwaysLowestAdaptationLogic::getNextChunk()
+{
+    if(!currentPeriod)
+        return NULL;
+
+    const Representation *rep = getCurrentRepresentation();
+    if ( rep == NULL )
+            return NULL;
+
+    std::vector<ISegment *> segments = rep->getSegments();
+    if ( count == segments.size() )
+    {
+        currentPeriod = mpdManager->getNextPeriod(currentPeriod);
+        count = 0;
+        return getNextChunk();
+    }
+
+    if ( segments.size() > count )
+    {
+        ISegment *seg = segments.at( count );
+        Chunk *chunk = seg->toChunk();
+        //In case of UrlTemplate, we must stay on the same segment.
+        if ( seg->isSingleShot() == true )
+            count++;
+        seg->done();
+        return chunk;
+    }
+    return NULL;
+}
+
+const Representation *AlwaysLowestAdaptationLogic::getCurrentRepresentation() const
 {
+    RepresentationSelector selector;
+    return selector.select(currentPeriod, 0);
 }
index 3707b00b551c97183a67ff285335a793f2595747..b59cff755fb10f42673892d0417d2415bc282a62 100644 (file)
@@ -1,10 +1,44 @@
+/*
+ * 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
 
-class AlwaysLowestAdaptationLogic
+#include "AbstractAdaptationLogic.h"
+
+namespace dash
 {
-public:
-    AlwaysLowestAdaptationLogic();
-};
+    namespace logic
+    {
+        class AlwaysLowestAdaptationLogic : public AbstractAdaptationLogic
+        {
+            public:
+                AlwaysLowestAdaptationLogic(dash::mpd::MPDManager *mpdManager);
+
+                virtual dash::http::Chunk*                  getNextChunk            ();
+                virtual const dash::mpd::Representation*    getCurrentRepresentation() const;
+
+            private:
+                dash::mpd::Period *currentPeriod;
+                size_t             count;
+        };
+    }
+}
 
 #endif // ALWAYSLOWESTADAPTATIONLOGIC_HPP