demux: dash: decl parser as friend class
[vlc.git] / modules / demux / adaptive / playlist / AbstractPlaylist.cpp
bloba124d68fef198662aa3ce15e224a8abbb9172ea6
1 /*
2 * AbstractAbstractPlaylist.cpp
3 *****************************************************************************
4 * Copyright (C) 2010 - 2011 Klagenfurt University
5 * Copyright (C) 2015 VideoLAN and VLC authors
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include "AbstractPlaylist.hpp"
26 #include "../tools/Helper.h"
27 #include "BasePeriod.h"
28 #include "SegmentTimeline.h"
29 #include <vlc_common.h>
30 #include <vlc_stream.h>
32 #include <algorithm>
34 using namespace adaptive::playlist;
36 AbstractPlaylist::AbstractPlaylist (vlc_object_t *p_object_) :
37 ICanonicalUrl(),
38 p_object(p_object_)
40 playbackStart.Set(0);
41 availabilityStartTime.Set( 0 );
42 availabilityEndTime.Set( 0 );
43 duration.Set( 0 );
44 minUpdatePeriod.Set( VLC_TICK_FROM_SEC(2) );
45 maxSegmentDuration.Set( 0 );
46 minBufferTime = 0;
47 timeShiftBufferDepth.Set( 0 );
48 suggestedPresentationDelay.Set( 0 );
49 b_needsUpdates = false;
52 AbstractPlaylist::~AbstractPlaylist()
54 for(size_t i = 0; i < this->periods.size(); i++)
55 delete(this->periods.at(i));
58 const std::vector<BasePeriod *>& AbstractPlaylist::getPeriods()
60 return periods;
63 void AbstractPlaylist::addBaseUrl(const std::string &url)
65 baseUrls.push_back(url);
68 void AbstractPlaylist::setPlaylistUrl(const std::string &url)
70 playlistUrl = url;
73 void AbstractPlaylist::addPeriod(BasePeriod *period)
75 periods.push_back(period);
78 void AbstractPlaylist::setType(const std::string &type_)
80 type = type_;
83 void AbstractPlaylist::setMinBuffering( vlc_tick_t min )
85 minBufferTime = min;
88 vlc_tick_t AbstractPlaylist::getMinBuffering() const
90 return std::max(minBufferTime, VLC_TICK_FROM_SEC(6));
93 vlc_tick_t AbstractPlaylist::getMaxBuffering() const
95 const vlc_tick_t minbuf = getMinBuffering();
96 return std::max(minbuf, VLC_TICK_FROM_SEC(60));
99 Url AbstractPlaylist::getUrlSegment() const
101 Url ret;
103 if (!baseUrls.empty())
104 ret = Url(baseUrls.front());
106 if( !ret.hasScheme() && !playlistUrl.empty() )
107 ret.prepend( Url(playlistUrl) );
109 return ret;
112 vlc_object_t * AbstractPlaylist::getVLCObject() const
114 return p_object;
117 BasePeriod* AbstractPlaylist::getFirstPeriod()
119 std::vector<BasePeriod *> periods = getPeriods();
121 if( !periods.empty() )
122 return periods.front();
123 else
124 return NULL;
127 BasePeriod* AbstractPlaylist::getNextPeriod(BasePeriod *period)
129 std::vector<BasePeriod *> periods = getPeriods();
131 for(size_t i = 0; i < periods.size(); i++)
133 if(periods.at(i) == period && (i + 1) < periods.size())
134 return periods.at(i + 1);
137 return NULL;
140 bool AbstractPlaylist::needsUpdates() const
142 return b_needsUpdates;
145 void AbstractPlaylist::mergeWith(AbstractPlaylist *updatedAbstractPlaylist, vlc_tick_t prunebarrier)
147 availabilityEndTime.Set(updatedAbstractPlaylist->availabilityEndTime.Get());
149 for(size_t i = 0; i < periods.size() && i < updatedAbstractPlaylist->periods.size(); i++)
150 periods.at(i)->mergeWith(updatedAbstractPlaylist->periods.at(i), prunebarrier);
153 void AbstractPlaylist::pruneByPlaybackTime(vlc_tick_t time)
155 for(size_t i = 0; i < periods.size(); i++)
156 periods.at(i)->pruneByPlaybackTime(time);