]> git.sesse.net Git - vlc/commitdiff
stream_filter: dash: move representation selection into logic
authorFrancois Cartegnie <fcvlcdev@free.fr>
Tue, 18 Nov 2014 21:58:33 +0000 (22:58 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Thu, 18 Dec 2014 20:23:48 +0000 (21:23 +0100)
12 files changed:
modules/stream_filter/Makefile.am
modules/stream_filter/dash/adaptationlogic/AlwaysBestAdaptationLogic.cpp
modules/stream_filter/dash/adaptationlogic/AlwaysBestAdaptationLogic.h
modules/stream_filter/dash/adaptationlogic/RateBasedAdaptationLogic.cpp
modules/stream_filter/dash/adaptationlogic/Representationselectors.cpp [new file with mode: 0644]
modules/stream_filter/dash/adaptationlogic/Representationselectors.hpp [new file with mode: 0644]
modules/stream_filter/dash/mpd/BasicCMManager.cpp
modules/stream_filter/dash/mpd/BasicCMManager.h
modules/stream_filter/dash/mpd/IMPDManager.cpp
modules/stream_filter/dash/mpd/IMPDManager.h
modules/stream_filter/dash/mpd/IsoffMainManager.cpp
modules/stream_filter/dash/mpd/IsoffMainManager.h

index 532b00f0809d9f2f0a1fd28b773ac88fbacc6141..94516a4f6bfa71ac3a0db249ec7ecef2441d0c9d 100644 (file)
@@ -19,6 +19,8 @@ libdash_plugin_la_SOURCES = \
     stream_filter/dash/adaptationlogic/IDownloadRateObserver.h \
     stream_filter/dash/adaptationlogic/RateBasedAdaptationLogic.h \
     stream_filter/dash/adaptationlogic/RateBasedAdaptationLogic.cpp \
+    stream_filter/dash/adaptationlogic/Representationselectors.hpp \
+    stream_filter/dash/adaptationlogic/Representationselectors.cpp \
     stream_filter/dash/buffer/BlockBuffer.cpp \
     stream_filter/dash/buffer/BlockBuffer.h \
     stream_filter/dash/buffer/IBufferObserver.h \
index e5ef3b64d9e839781ee1a30369e61ff69607dae8..349fad6feb52967ce15752547de4020260d146da 100644 (file)
@@ -70,20 +70,22 @@ const Representation *AlwaysBestAdaptationLogic::getCurrentRepresentation() cons
 
 void    AlwaysBestAdaptationLogic::initSchedule ()
 {
-    if(this->mpdManager != NULL)
+    if(mpdManager)
     {
-        std::vector<Period *> periods = this->mpdManager->getPeriods();
+        std::vector<Period *> periods = mpdManager->getPeriods();
+        std::vector<Period *>::const_iterator it;
+        RepresentationSelector selector;
 
-        for(size_t i = 0; i < periods.size(); i++)
+        for(it=periods.begin(); it!=periods.end(); it++)
         {
-            Representation *best = this->mpdManager->getBestRepresentation(periods.at(i));
-
-            if(best != NULL)
+            Representation *best = selector.select(*it);
+            if(best)
             {
                 std::vector<Segment *> segments = best->getSegments();
-                for(size_t j = 0; j < segments.size(); j++)
+                std::vector<Segment *>::const_iterator segIt;
+                for(segIt=segments.begin(); segIt!=segments.end(); segIt++)
                 {
-                    this->schedule.push_back(segments.at(j));
+                    schedule.push_back(*segIt);
                 }
             }
         }
index 98cf26719fddf37207c0bd739e625ef6dd9df8ea..40b239f1715dd7ab0831894f0b95cbc117e37660 100644 (file)
@@ -26,6 +26,7 @@
 #define ALWAYSBESTADAPTATIONLOGIC_H_
 
 #include "adaptationlogic/AbstractAdaptationLogic.h"
+#include "Representationselectors.hpp"
 #include "http/Chunk.h"
 #include "xml/Node.h"
 #include "mpd/IMPDManager.h"
index 938f8d9dbc2bc8fc4a11ca68d3f0081d6feefb42..1b99970d6b15fccd7289adba30fbcc87a06edb9f 100644 (file)
@@ -26,6 +26,7 @@
 #endif
 
 #include "RateBasedAdaptationLogic.h"
+#include "Representationselectors.hpp"
 
 using namespace dash::logic;
 using namespace dash::xml;
@@ -46,20 +47,11 @@ RateBasedAdaptationLogic::RateBasedAdaptationLogic  (IMPDManager *mpdManager, st
 
 Chunk*  RateBasedAdaptationLogic::getNextChunk()
 {
-    if(this->mpdManager == NULL)
-        return NULL;
-
     if(this->currentPeriod == NULL)
         return NULL;
 
-    uint64_t bitrate = this->getBpsAvg();
-
-    if(this->getBufferPercent() < MINBUFFER)
-        bitrate = 0;
-
-    Representation *rep = this->mpdManager->getRepresentation(this->currentPeriod, bitrate, this->width, this->height);
-
-    if ( rep == NULL )
+    const Representation *rep = getCurrentRepresentation();
+    if (!rep)
         return NULL;
 
     std::vector<Segment *> segments = rep->getSegments();
@@ -86,5 +78,20 @@ Chunk*  RateBasedAdaptationLogic::getNextChunk()
 
 const Representation *RateBasedAdaptationLogic::getCurrentRepresentation() const
 {
-    return this->mpdManager->getRepresentation( this->currentPeriod, this->getBpsAvg() );
+    if(currentPeriod == NULL)
+        return NULL;
+
+    uint64_t bitrate = this->getBpsAvg();
+    if(getBufferPercent() < MINBUFFER)
+        bitrate = 0;
+
+    RepresentationSelector selector;
+    Representation *rep = selector.select(currentPeriod, bitrate, width, height);
+    if ( rep == NULL )
+    {
+        rep = selector.select(currentPeriod);
+        if ( rep == NULL )
+            return NULL;
+    }
+    return rep;
 }
diff --git a/modules/stream_filter/dash/adaptationlogic/Representationselectors.cpp b/modules/stream_filter/dash/adaptationlogic/Representationselectors.cpp
new file mode 100644 (file)
index 0000000..fae06cb
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * 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) const
+{
+    return select(period, std::numeric_limits<uint64_t>::max());
+}
+
+Representation * RepresentationSelector::select(Period *period, uint64_t bitrate) const
+{
+    if (period == NULL)
+        return NULL;
+
+    std::vector<AdaptationSet *> adaptSets = period->getAdaptationSets();
+
+    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)
+            best = candidate;
+    }
+    return best;
+}
+
+Representation * RepresentationSelector::select(Period *period, 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();
+    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, bitrate);
+    else
+        return select(resMatchReps, 0, bitrate);
+}
+
+Representation * RepresentationSelector::select(std::vector<Representation *>& reps,
+                                                uint64_t minbitrate, uint64_t maxbitrate) const
+{
+    Representation  *candidate = NULL;
+    std::vector<Representation *>::const_iterator repIt;
+    for(repIt=reps.begin(); repIt!=reps.end(); repIt++)
+    {
+        if ( (*repIt)->getBandwidth() < maxbitrate &&
+             (*repIt)->getBandwidth() > minbitrate )
+        {
+            candidate = (*repIt);
+            minbitrate = (*repIt)->getBandwidth();
+        }
+    }
+    return candidate;
+}
diff --git a/modules/stream_filter/dash/adaptationlogic/Representationselectors.hpp b/modules/stream_filter/dash/adaptationlogic/Representationselectors.hpp
new file mode 100644 (file)
index 0000000..6748c7e
--- /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) const;
+            virtual Representation * select(Period *period, uint64_t bitrate) const;
+            virtual Representation * select(Period *period, 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
index 44029ebce79bb9c8d0b92550ce4798af3287405d..57911c5436b1803951f3950dafe89ac08aaba342 100644 (file)
@@ -34,8 +34,3 @@ BasicCMManager::BasicCMManager(MPD *mpd) :
 {
 
 }
-
-Representation*         BasicCMManager::getRepresentation (Period *period, uint64_t bitrate, int, int ) const
-{
-    return IMPDManager::getRepresentation(period, bitrate);
-}
index b69d67f3a4764e55a1aa0f21dc88f36bdf6d6c20..4094711556ee65d7576dec06f010cf44db3b2230 100644 (file)
@@ -42,8 +42,6 @@ namespace dash
             public:
                 BasicCMManager          (MPD *mpd);
 
-                Representation*                 getRepresentation (Period *period, uint64_t bitrate,
-                                                                   int width, int height) const;
         };
     }
 }
index ac91b13eb028985d90c22e81374ef21e97fd34dc..47a128e535d8a41ecaa95c5be57982eae0e78180 100644 (file)
@@ -69,35 +69,3 @@ const MPD* IMPDManager::getMPD() const
 {
     return mpd;
 }
-
-Representation* IMPDManager::getBestRepresentation(Period *period) const
-{
-    return getRepresentation(period, std::numeric_limits<uint64_t>::max());
-}
-
-Representation* IMPDManager::getRepresentation(Period *period, uint64_t bitrate ) const
-{
-    if (period == NULL)
-        return NULL;
-
-    std::vector<AdaptationSet *>    adaptSet = period->getAdaptationSets();
-
-    Representation  *best = NULL;
-
-    for(size_t i = 0; i < adaptSet.size(); i++)
-    {
-        std::vector<Representation *> reps = adaptSet.at(i)->getRepresentations();
-        for( size_t j = 0; j < reps.size(); j++ )
-        {
-            uint64_t currentBitrate = reps.at(j)->getBandwidth();
-
-            if ( best == NULL ||
-                 ( currentBitrate > best->getBandwidth() &&
-                   currentBitrate < bitrate ) )
-            {
-                best = reps.at( j );
-            }
-        }
-    }
-    return best;
-}
index efb820cb7959b5fca2dad8381b8564e7bf6c083c..bc472d9daa8feb7ea7835349b3f0ce85001e4884 100644 (file)
@@ -42,11 +42,8 @@ namespace dash
                 virtual const std::vector<Period *>&    getPeriods              () const;
                 virtual Period*                         getFirstPeriod          () const;
                 virtual Period*                         getNextPeriod           (Period *period);
-                virtual Representation*                 getBestRepresentation   (Period *period) const;
-                virtual Representation*                 getRepresentation       (Period *period, uint64_t bitrate) const;
                 virtual const MPD*                      getMPD                  () const;
-                virtual Representation*                 getRepresentation       (Period *period, uint64_t bitrate,
-                                                                                 int width, int height) const       = 0;
+
             protected:
                 MPD *mpd;
         };
index 064c3d7d799634874b267c767567b9f201c4fffe..58a8b60fc77de65219b1ac377ceaf360972b7250 100644 (file)
 #endif
 
 #include "IsoffMainManager.h"
+#include "../adaptationlogic/Representationselectors.hpp"
 
 using namespace dash::mpd;
+using namespace dash::logic;
 
 IsoffMainManager::IsoffMainManager(MPD *mpd) :
     IMPDManager( mpd )
@@ -36,37 +38,3 @@ IsoffMainManager::IsoffMainManager(MPD *mpd) :
 
 }
 
-Representation*             IsoffMainManager::getRepresentation     (Period *period, uint64_t bitrate, int width, int height) const
-{
-    if(period == NULL)
-        return NULL;
-
-    std::vector<AdaptationSet *> adaptationSets = period->getAdaptationSets();
-    std::vector<Representation *> resMatchReps;
-
-    for(size_t i = 0; i < adaptationSets.size(); i++)
-    {
-        std::vector<Representation *> reps = adaptationSets.at(i)->getRepresentations();
-        for( size_t j = 0; j < reps.size(); j++ )
-        {
-            if(reps.at(j)->getWidth() == width && reps.at(j)->getHeight() == height)
-                resMatchReps.push_back(reps.at(j));
-        }
-    }
-
-    if(resMatchReps.size() == 0)
-        return IMPDManager::getRepresentation(period, bitrate);
-
-    Representation  *best = NULL;
-    for( size_t j = 0; j < resMatchReps.size(); j++ )
-    {
-        uint64_t currentBitrate = resMatchReps.at(j)->getBandwidth();
-
-        if(best == NULL || (currentBitrate > best->getBandwidth() && currentBitrate < bitrate))
-        {
-            best = resMatchReps.at(j);
-        }
-    }
-
-    return best;
-}
index 244a6e46c16effe1a0c5d9f957737b6c5cfb1f10..43dd066502191194f216cedd1410ec5412cf0693 100644 (file)
@@ -43,8 +43,6 @@ namespace dash
             public:
                 IsoffMainManager            (MPD *mpd);
 
-                Representation*                 getRepresentation       (Period *period, uint64_t bitrate,
-                                                                         int width, int height) const;
         };
     }
 }