]> git.sesse.net Git - vlc/blob - modules/stream_filter/dash/mpd/IsoffMainManager.cpp
dash: added byte range requests
[vlc] / modules / stream_filter / dash / mpd / IsoffMainManager.cpp
1 /*
2  * IsoffMainManager.cpp
3  *****************************************************************************
4  * Copyright (C) 2010 - 2012 Klagenfurt University
5  *
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>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include "IsoffMainManager.h"
30
31 using namespace dash::mpd;
32
33 IsoffMainManager::IsoffMainManager  (MPD *mpd)
34 {
35     this->mpd = mpd;
36 }
37 IsoffMainManager::~IsoffMainManager ()
38 {
39     delete this->mpd;
40 }
41
42 std::vector<Segment*>       IsoffMainManager::getSegments           (const Representation *rep)
43 {
44     std::vector<Segment *>  retSegments;
45     SegmentList*            list= rep->getSegmentList();
46     Segment*                initSegment = rep->getSegmentBase()->getInitSegment();
47
48     if(initSegment)
49         retSegments.push_back(initSegment);
50
51     retSegments.insert(retSegments.end(), list->getSegments().begin(), list->getSegments().end());
52     return retSegments;
53 }
54 const std::vector<Period*>& IsoffMainManager::getPeriods            () const
55 {
56     return this->mpd->getPeriods();
57 }
58 Representation*             IsoffMainManager::getBestRepresentation (Period *period)
59 {
60     std::vector<AdaptationSet *> adaptationSets = period->getAdaptationSets();
61
62     int             bitrate  = 0;
63     Representation  *best    = NULL;
64
65     for(size_t i = 0; i < adaptationSets.size(); i++)
66     {
67         std::vector<Representation *> reps = adaptationSets.at(i)->getRepresentations();
68         for(size_t j = 0; j < reps.size(); j++)
69         {
70             int currentBitrate = reps.at(j)->getBandwidth();
71
72             if(currentBitrate > bitrate)
73             {
74                 bitrate = currentBitrate;
75                 best    = reps.at(j);
76             }
77         }
78     }
79     return best;
80 }
81 Period*                     IsoffMainManager::getFirstPeriod        ()
82 {
83     std::vector<Period *> periods = this->mpd->getPeriods();
84
85     if(periods.size() == 0)
86         return NULL;
87
88     return periods.at(0);
89 }
90 Representation*             IsoffMainManager::getRepresentation     (Period *period, int bitrate )
91 {
92     std::vector<AdaptationSet *> adaptationSets = period->getAdaptationSets();
93
94     Representation  *best = NULL;
95     std::cout << "Searching for best representation with bitrate: " << bitrate << std::endl;
96
97     for(size_t i = 0; i < adaptationSets.size(); i++)
98     {
99         std::vector<Representation *> reps = adaptationSets.at(i)->getRepresentations();
100         for( size_t j = 0; j < reps.size(); j++ )
101         {
102             int currentBitrate = reps.at(j)->getBandwidth();
103
104             if(best == NULL || (currentBitrate > best->getBandwidth() && currentBitrate < bitrate))
105             {
106                 std::cout << "Found a better Representation bandwidth=" << reps.at(j)->getBandwidth() << " in adaptationSet #" << i << std::endl;
107                 best = reps.at( j );
108             }
109         }
110     }
111     return best;
112 }
113 Period*                     IsoffMainManager::getNextPeriod         (Period *period)
114 {
115     std::vector<Period *> periods = this->mpd->getPeriods();
116
117     for(size_t i = 0; i < periods.size(); i++)
118     {
119         if(periods.at(i) == period && (i + 1) < periods.size())
120             return periods.at(i + 1);
121     }
122
123     return NULL;
124 }
125 const MPD*                  IsoffMainManager::getMPD                () const
126 {
127     return this->mpd;
128 }