3 *****************************************************************************
4 * Copyright (C) 2010 - 2012 Klagenfurt University
6 * Created on: Jan 27, 2010
7 * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
8 * Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published
12 * by the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
29 #include "IsoffMainManager.h"
31 using namespace dash::mpd;
33 IsoffMainManager::IsoffMainManager (MPD *mpd)
37 IsoffMainManager::~IsoffMainManager ()
42 std::vector<Segment*> IsoffMainManager::getSegments (const Representation *rep)
44 std::vector<Segment *> retSegments;
45 SegmentList* list= rep->getSegmentList();
46 Segment* initSegment = rep->getSegmentBase()->getInitSegment();
49 retSegments.push_back(initSegment);
51 retSegments.insert(retSegments.end(), list->getSegments().begin(), list->getSegments().end());
54 const std::vector<Period*>& IsoffMainManager::getPeriods () const
56 return this->mpd->getPeriods();
58 Representation* IsoffMainManager::getBestRepresentation (Period *period)
60 std::vector<AdaptationSet *> adaptationSets = period->getAdaptationSets();
63 Representation *best = NULL;
65 for(size_t i = 0; i < adaptationSets.size(); i++)
67 std::vector<Representation *> reps = adaptationSets.at(i)->getRepresentations();
68 for(size_t j = 0; j < reps.size(); j++)
70 int currentBitrate = reps.at(j)->getBandwidth();
72 if(currentBitrate > bitrate)
74 bitrate = currentBitrate;
81 Period* IsoffMainManager::getFirstPeriod ()
83 std::vector<Period *> periods = this->mpd->getPeriods();
85 if(periods.size() == 0)
90 Representation* IsoffMainManager::getRepresentation (Period *period, int bitrate) const
95 std::vector<AdaptationSet *> adaptationSets = period->getAdaptationSets();
97 Representation *best = NULL;
98 std::cout << "Searching for best representation with bitrate: " << bitrate << std::endl;
100 for(size_t i = 0; i < adaptationSets.size(); i++)
102 std::vector<Representation *> reps = adaptationSets.at(i)->getRepresentations();
103 for( size_t j = 0; j < reps.size(); j++ )
105 int currentBitrate = reps.at(j)->getBandwidth();
107 if(best == NULL || (currentBitrate > best->getBandwidth() && currentBitrate < bitrate))
109 std::cout << "Found a better Representation bandwidth=" << reps.at(j)->getBandwidth() << " in adaptationSet #" << i << std::endl;
116 Period* IsoffMainManager::getNextPeriod (Period *period)
118 std::vector<Period *> periods = this->mpd->getPeriods();
120 for(size_t i = 0; i < periods.size(); i++)
122 if(periods.at(i) == period && (i + 1) < periods.size())
123 return periods.at(i + 1);
128 const MPD* IsoffMainManager::getMPD () const
132 Representation* IsoffMainManager::getRepresentation (Period *period, int bitrate, int width, int height) const
137 std::vector<AdaptationSet *> adaptationSets = period->getAdaptationSets();
139 std::cout << "Searching for best representation with bitrate: " << bitrate << " and resolution: " << width << "x" << height << std::endl;
141 std::vector<Representation *> resMatchReps;
146 for(size_t i = 0; i < adaptationSets.size(); i++)
148 std::vector<Representation *> reps = adaptationSets.at(i)->getRepresentations();
149 for( size_t j = 0; j < reps.size(); j++ )
151 if(reps.at(j)->getWidth() == width && reps.at(j)->getHeight() == height)
152 resMatchReps.push_back(reps.at(j));
154 if(reps.at(j)->getHeight() < height)
156 lowerWidth = reps.at(j)->getWidth();
157 lowerHeight = reps.at(j)->getHeight();
162 if(resMatchReps.size() == 0)
163 return this->getRepresentation(period, bitrate, lowerWidth, lowerHeight);
165 Representation *best = NULL;
166 for( size_t j = 0; j < resMatchReps.size(); j++ )
168 int currentBitrate = resMatchReps.at(j)->getBandwidth();
170 if(best == NULL || (currentBitrate > best->getBandwidth() && currentBitrate < bitrate))
172 std::cout << "Found a better Representation bandwidth=" << resMatchReps.at(j)->getBandwidth()
173 << " and resolution: " << resMatchReps.at(j)->getWidth() << "x" << resMatchReps.at(j)->getHeight() << std::endl;
174 best = resMatchReps.at(j);