]> git.sesse.net Git - vlc/blobdiff - modules/stream_filter/dash/mpd/BasicCMManager.cpp
stream_filter: dash: deduplicate code
[vlc] / modules / stream_filter / dash / mpd / BasicCMManager.cpp
index fd1fee1ba2c4c904f5bf05c3a2e70cb1029f38c1..bf45a2f2a48e278724a75b333ef1eed63c8530ef 100644 (file)
@@ -7,19 +7,19 @@
  * 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
+ * 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 General Public License for more details.
+ * 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.
+ * 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"
 #include "BasicCMManager.h"
 
 using namespace dash::mpd;
-using namespace dash::exception;
 
-BasicCMManager::BasicCMManager  (MPD *mpd)
+BasicCMManager::BasicCMManager(MPD *mpd) :
+    IMPDManager(mpd)
 {
-    this->mpd = mpd;
-}
-BasicCMManager::~BasicCMManager ()
-{
-    delete this->mpd;
-}
-
-std::vector<ISegment*>  BasicCMManager::getSegments             (Representation *rep)
-{
-    std::vector<ISegment *> retSegments;
-    try
-    {
-        SegmentInfo* info = rep->getSegmentInfo();
-        InitSegment* init = info->getInitSegment();
-
-        retSegments.push_back(init);
-
-        std::vector<Segment *> segments = info->getSegments();
 
-        for(size_t i = 0; i < segments.size(); i++)
-            retSegments.push_back(segments.at(i));
-    }
-    catch(ElementNotPresentException &e)
-    {
-        /*TODO Debug */
-    }
-
-    return retSegments;
-}
-const std::vector<Period*>&    BasicCMManager::getPeriods              () const
-{
-    return this->mpd->getPeriods();
 }
 
-Representation*         BasicCMManager::getBestRepresentation   (Period *period)
-{
-    std::vector<Group *> groups = period->getGroups();
-
-    long            bitrate  = 0;
-    Representation  *best    = NULL;
-
-    for(size_t i = 0; i < groups.size(); i++)
-    {
-        std::vector<Representation *> reps = groups.at(i)->getRepresentations();
-        for(size_t j = 0; j < reps.size(); j++)
-        {
-            try
-            {
-                long currentBitrate = atol(reps.at(j)->getBandwidth().c_str());
-                if(currentBitrate > bitrate)
-                {
-                    bitrate = currentBitrate;
-                    best    = reps.at(j);
-                }
-            }
-            catch(AttributeNotPresentException &e)
-            {
-                /* TODO DEBUG */
-            }
-        }
-    }
-
-    return best;
-}
-Period*                 BasicCMManager::getFirstPeriod          ()
+std::vector<Segment*>   BasicCMManager::getSegments( const Representation *rep )
 {
-    std::vector<Period *> periods = this->mpd->getPeriods();
-
-    if(periods.size() == 0)
-        return NULL;
+    std::vector<Segment *>          retSegments;
+    SegmentInfo*                    info = rep->getSegmentInfo();
+    Segment*                        initSegment = info->getInitialisationSegment();
 
-    return periods.at(0);
+    if ( initSegment )
+        retSegments.push_back( initSegment );
+    retSegments.insert( retSegments.end(), info->getSegments().begin(),
+                                            info->getSegments().end() );
+    return retSegments;
 }
-Representation*         BasicCMManager::getRepresentation       (Period *period, long bitrate)
-{
-    std::vector<Group *> groups = period->getGroups();
-
-    Representation  *best       = NULL;
-    long            bestDif  = -1;
 
-    for(size_t i = 0; i < groups.size(); i++)
-    {
-        std::vector<Representation *> reps = groups.at(i)->getRepresentations();
-        for(size_t j = 0; j < reps.size(); j++)
-        {
-            try
-            {
-                long currentBitrate = atol(reps.at(j)->getBandwidth().c_str());
-                long dif = bitrate - currentBitrate;
-
-                if(bestDif == -1)
-                {
-                    bestDif = dif;
-                    best = reps.at(j);
-                }
-                else
-                {
-                    if(dif >= 0 && dif < bestDif)
-                    {
-                        bestDif = dif;
-                        best = reps.at(j);
-                    }
-                }
-
-            }
-            catch(AttributeNotPresentException &e)
-            {
-                /* TODO DEBUG */
-            }
-        }
-    }
-
-    return best;
-}
-Period*                 BasicCMManager::getNextPeriod           (Period *period)
+Representation*         BasicCMManager::getRepresentation (Period *period, uint64_t bitrate, int, int ) const
 {
-    std::vector<Period *> periods = this->mpd->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;
+    return IMPDManager::getRepresentation(period, bitrate);
 }