3 *****************************************************************************
4 * Copyright (C) 2010 - 2011 Klagenfurt University
6 * Created on: Aug 10, 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 it
11 * 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 Lesser 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 Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
31 #include "SegmentTimeline.h"
32 #include <vlc_common.h>
33 #include <vlc_stream.h>
35 using namespace dash::mpd;
37 MPD::MPD (stream_t *stream_, Profile profile_) :
43 availabilityStartTime.Set( 0 );
44 availabilityEndTime.Set( 0 );
46 minUpdatePeriod.Set( 0 );
47 maxSegmentDuration.Set( 0 );
48 minBufferTime.Set( 0 );
49 timeShiftBufferDepth.Set( 0 );
50 programInfo.Set( NULL );
55 for(size_t i = 0; i < this->periods.size(); i++)
56 delete(this->periods.at(i));
58 for(size_t i = 0; i < this->baseUrls.size(); i++)
59 delete(this->baseUrls.at(i));
61 delete(programInfo.Get());
64 const std::vector<Period*>& MPD::getPeriods ()
69 void MPD::addBaseUrl (BaseUrl *url)
71 this->baseUrls.push_back(url);
73 void MPD::addPeriod (Period *period)
75 this->periods.push_back(period);
78 bool MPD::isLive() const
82 Profile live(Profile::ISOLive);
83 return profile == live;
86 return (type != "static");
89 void MPD::setType(const std::string &type_)
94 Profile MPD::getProfile() const
98 Url MPD::getUrlSegment() const
100 if (!baseUrls.empty())
101 return Url(baseUrls.front()->getUrl());
104 std::stringstream ss;
105 ss << stream->psz_access << "://" << Helper::getDirectoryPath(stream->psz_path) << "/";
106 return Url(ss.str());
110 vlc_object_t * MPD::getVLCObject() const
112 return VLC_OBJECT(stream);
115 Period* MPD::getFirstPeriod()
117 std::vector<Period *> periods = getPeriods();
119 if( !periods.empty() )
120 return periods.front();
125 Period* MPD::getNextPeriod(Period *period)
127 std::vector<Period *> periods = getPeriods();
129 for(size_t i = 0; i < periods.size(); i++)
131 if(periods.at(i) == period && (i + 1) < periods.size())
132 return periods.at(i + 1);
138 void MPD::mergeWith(MPD *updatedMPD)
140 availabilityEndTime.Set(updatedMPD->availabilityEndTime.Get());
141 /* Only merge timelines for now */
142 for(size_t i = 0; i < periods.size() && i < updatedMPD->periods.size(); i++)
144 std::vector<SegmentTimeline *> timelines;
145 std::vector<SegmentTimeline *> timelinesUpdate;
146 periods.at(i)->collectTimelines(&timelines);
147 updatedMPD->periods.at(i)->collectTimelines(&timelinesUpdate);
149 for(size_t j = 0; j < timelines.size() && j < timelinesUpdate.size(); j++)
150 timelines.at(j)->mergeWith(*timelinesUpdate.at(j));