3 *****************************************************************************
4 * Copyright (C) 2010 - 2012 Klagenfurt University
6 * Created on: Jan 27, 2012
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 *****************************************************************************/
29 #include "IsoffMainParser.h"
30 #include "xml/DOMHelper.h"
31 #include <vlc_strings.h>
33 using namespace dash::mpd;
34 using namespace dash::xml;
36 IsoffMainParser::IsoffMainParser (Node *root, stream_t *p_stream) :
37 IMPDParser(root, NULL, p_stream, NULL)
40 IsoffMainParser::~IsoffMainParser ()
44 bool IsoffMainParser::parse ()
54 void IsoffMainParser::setMPDAttributes ()
56 const std::map<std::string, std::string> attr = this->root->getAttributes();
58 std::map<std::string, std::string>::const_iterator it;
60 it = attr.find("mediaPresentationDuration");
62 this->mpd->setDuration(str_duration(it->second.c_str()));
64 it = attr.find("minBufferTime");
66 this->mpd->setMinBufferTime(str_duration( it->second.c_str()));
70 void IsoffMainParser::setAdaptationSets (Node *periodNode, Period *period)
72 std::vector<Node *> adaptationSets = DOMHelper::getElementByTagName(periodNode, "AdaptationSet", false);
74 for(size_t i = 0; i < adaptationSets.size(); i++)
76 AdaptationSet *adaptationSet = new AdaptationSet();
77 this->setRepresentations(adaptationSets.at(i), adaptationSet);
78 period->addAdaptationSet(adaptationSet);
81 void IsoffMainParser::setRepresentations (Node *adaptationSetNode, AdaptationSet *adaptationSet)
83 std::vector<Node *> representations = DOMHelper::getElementByTagName(adaptationSetNode, "Representation", false);
85 for(size_t i = 0; i < representations.size(); i++)
87 this->currentRepresentation = new Representation;
88 Node *repNode = representations.at(i);
90 if(repNode->hasAttribute("width"))
91 this->currentRepresentation->setWidth(atoi(repNode->getAttributeValue("width").c_str()));
93 if(repNode->hasAttribute("height"))
94 this->currentRepresentation->setHeight(atoi(repNode->getAttributeValue("height").c_str()));
96 if(repNode->hasAttribute("bandwidth"))
97 this->currentRepresentation->setBandwidth(atoi(repNode->getAttributeValue("bandwidth").c_str()));
99 this->setSegmentBase(repNode, this->currentRepresentation);
100 this->setSegmentList(repNode, this->currentRepresentation);
101 adaptationSet->addRepresentation(this->currentRepresentation);
104 void IsoffMainParser::setSegmentBase (dash::xml::Node *repNode, Representation *rep)
106 std::vector<Node *> segmentBase = DOMHelper::getElementByTagName(repNode, "SegmentBase", false);
108 if(segmentBase.size() > 0)
110 SegmentBase *base = new SegmentBase();
111 this->setInitSegment(segmentBase.at(0), base);
112 rep->setSegmentBase(base);
115 void IsoffMainParser::setSegmentList (dash::xml::Node *repNode, Representation *rep)
117 std::vector<Node *> segmentList = DOMHelper::getElementByTagName(repNode, "SegmentList", false);
119 if(segmentList.size() > 0)
121 SegmentList *list = new SegmentList();
122 this->setSegments(segmentList.at(0), list);
123 rep->setSegmentList(list);
127 void IsoffMainParser::setInitSegment (dash::xml::Node *segBaseNode, SegmentBase *base)
129 std::vector<Node *> initSeg = DOMHelper::getElementByTagName(segBaseNode, "Initialisation", false);
131 if(initSeg.size() == 0)
132 initSeg = DOMHelper::getElementByTagName(segBaseNode, "Initialization", false);
134 if(initSeg.size() > 0)
136 Segment *seg = new Segment( this->currentRepresentation );
137 seg->setSourceUrl(initSeg.at(0)->getAttributeValue("sourceURL"));
139 if(initSeg.at(0)->hasAttribute("range"))
141 std::string range = initSeg.at(0)->getAttributeValue("range");
142 size_t pos = range.find("-");
143 seg->setByteRange(atoi(range.substr(0, pos).c_str()), atoi(range.substr(pos + 1, range.size()).c_str()));
146 for(size_t i = 0; i < this->mpd->getBaseUrls().size(); i++)
147 seg->addBaseUrl(this->mpd->getBaseUrls().at(i));
149 base->addInitSegment(seg);
152 void IsoffMainParser::setSegments (dash::xml::Node *segListNode, SegmentList *list)
154 std::vector<Node *> segments = DOMHelper::getElementByTagName(segListNode, "SegmentURL", false);
156 for(size_t i = 0; i < segments.size(); i++)
158 Segment *seg = new Segment( this->currentRepresentation );
159 seg->setSourceUrl(segments.at(i)->getAttributeValue("media"));
161 if(segments.at(i)->hasAttribute("mediaRange"))
163 std::string range = segments.at(i)->getAttributeValue("mediaRange");
164 size_t pos = range.find("-");
165 seg->setByteRange(atoi(range.substr(0, pos).c_str()), atoi(range.substr(pos + 1, range.size()).c_str()));
168 for(size_t j = 0; j < this->mpd->getBaseUrls().size(); j++)
169 seg->addBaseUrl(this->mpd->getBaseUrls().at(j));
171 list->addSegment(seg);
174 void IsoffMainParser::print ()
178 msg_Dbg(p_stream, "MPD profile=%d mediaPresentationDuration=%ld minBufferTime=%ld", mpd->getProfile(),
180 mpd->getMinBufferTime());
181 std::vector<BaseUrl *>::const_iterator h;
182 for(h = mpd->getBaseUrls().begin(); h != mpd->getBaseUrls().end(); h++)
183 msg_Dbg(p_stream, "BaseUrl=%s", (*h)->getUrl().c_str());
185 std::vector<Period *>::const_iterator i;
186 for(i = mpd->getPeriods().begin(); i != mpd->getPeriods().end(); i++)
188 msg_Dbg(p_stream, " Period");
189 std::vector<AdaptationSet *>::const_iterator j;
190 for(j = (*i)->getAdaptationSets().begin(); j != (*i)->getAdaptationSets().end(); j++)
192 msg_Dbg(p_stream, " AdaptationSet");
193 std::vector<Representation *>::const_iterator k;
194 for(k = (*j)->getRepresentations().begin(); k != (*j)->getRepresentations().begin(); k++)
196 msg_Dbg(p_stream, " Representation");
197 msg_Dbg(p_stream, " InitSeg url=%s", (*k)->getSegmentBase()->getInitSegment()->getSourceUrl().c_str());
198 std::vector<Segment *>::const_iterator l;
199 for(l = (*k)->getSegmentList()->getSegments().begin();
200 l < (*k)->getSegmentList()->getSegments().end(); l++)
202 msg_Dbg(p_stream, " Segment url=%s", (*l)->getSourceUrl().c_str());