]> git.sesse.net Git - vlc/blob - modules/demux/dash/mpd/MPD.cpp
demux: dash: parse maxSegmentDuration & minUpdatePeriod
[vlc] / modules / demux / dash / mpd / MPD.cpp
1 /*
2  * MPD.cpp
3  *****************************************************************************
4  * Copyright (C) 2010 - 2011 Klagenfurt University
5  *
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>
9  *
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.
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 Lesser 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 Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include "MPD.h"
29 #include "Helper.h"
30 #include "dash.hpp"
31 #include "SegmentTimeline.h"
32 #include <vlc_common.h>
33 #include <vlc_stream.h>
34
35 using namespace dash::mpd;
36
37 MPD::MPD (stream_t *stream_, Profile profile_) :
38     ICanonicalUrl(),
39     stream(stream_),
40     profile( profile_ )
41 {
42     playbackStart.Set(0);
43     availabilityStartTime.Set( 0 );
44     availabilityEndTime.Set( 0 );
45     duration.Set( 0 );
46     minUpdatePeriod.Set( 0 );
47     maxSegmentDuration.Set( 0 );
48     minBufferTime.Set( 0 );
49     timeShiftBufferDepth.Set( 0 );
50     programInfo.Set( NULL );
51 }
52
53 MPD::~MPD   ()
54 {
55     for(size_t i = 0; i < this->periods.size(); i++)
56         delete(this->periods.at(i));
57
58     for(size_t i = 0; i < this->baseUrls.size(); i++)
59         delete(this->baseUrls.at(i));
60
61     delete(programInfo.Get());
62 }
63
64 const std::vector<Period*>&    MPD::getPeriods             ()
65 {
66     return this->periods;
67 }
68
69 void                    MPD::addBaseUrl             (BaseUrl *url)
70 {
71     this->baseUrls.push_back(url);
72 }
73 void                    MPD::addPeriod              (Period *period)
74 {
75     this->periods.push_back(period);
76 }
77
78 bool                    MPD::isLive() const
79 {
80     if(type.empty())
81     {
82         Profile live(Profile::ISOLive);
83         return profile == live;
84     }
85     else
86         return (type != "static");
87 }
88
89 void MPD::setType(const std::string &type_)
90 {
91     type = type_;
92 }
93
94 Profile MPD::getProfile() const
95 {
96     return profile;
97 }
98 Url MPD::getUrlSegment() const
99 {
100     if (!baseUrls.empty())
101         return Url(baseUrls.front()->getUrl());
102     else
103     {
104         std::stringstream ss;
105         ss << stream->psz_access << "://" << Helper::getDirectoryPath(stream->psz_path) << "/";
106         return Url(ss.str());
107     }
108 }
109
110 vlc_object_t * MPD::getVLCObject() const
111 {
112     return VLC_OBJECT(stream);
113 }
114
115 Period* MPD::getFirstPeriod()
116 {
117     std::vector<Period *> periods = getPeriods();
118
119     if( !periods.empty() )
120         return periods.front();
121     else
122         return NULL;
123 }
124
125 Period* MPD::getNextPeriod(Period *period)
126 {
127     std::vector<Period *> periods = getPeriods();
128
129     for(size_t i = 0; i < periods.size(); i++)
130     {
131         if(periods.at(i) == period && (i + 1) < periods.size())
132             return periods.at(i + 1);
133     }
134
135     return NULL;
136 }
137
138 void MPD::mergeWith(MPD *updatedMPD)
139 {
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++)
143     {
144         std::vector<SegmentTimeline *> timelines;
145         std::vector<SegmentTimeline *> timelinesUpdate;
146         periods.at(i)->collectTimelines(&timelines);
147         updatedMPD->periods.at(i)->collectTimelines(&timelinesUpdate);
148
149         for(size_t j = 0; j < timelines.size() && j < timelinesUpdate.size(); j++)
150             timelines.at(j)->mergeWith(*timelinesUpdate.at(j));
151     }
152 }