Commit e79147cf authored by Christopher Mueller's avatar Christopher Mueller Committed by Hugo Beauzée-Luyssen

dash: added isoffmainparser

Signed-off-by: default avatarHugo Beauzée-Luyssen <beauze.h@gmail.com>
parent e8bfbde1
......@@ -32,6 +32,8 @@ SOURCES_stream_filter_dash = \
mpd/Group.h \
mpd/IMPDManager.h \
mpd/IMPDParser.h \
mpd/IsoffMainParser.cpp \
mpd/IsoffMainParser.h \
mpd/MPD.cpp \
mpd/MPD.h \
mpd/MPDManagerFactory.cpp \
......
/*
* IsoffMainParser.cpp
*****************************************************************************
* Copyright (C) 2010 - 2012 Klagenfurt University
*
* Created on: Jan 27, 2012
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "IsoffMainParser.h"
using namespace dash::mpd;
using namespace dash::xml;
IsoffMainParser::IsoffMainParser (Node *root, stream_t *p_stream) :
root (root),
p_stream (p_stream),
mpd (NULL)
{
}
IsoffMainParser::~IsoffMainParser ()
{
}
bool IsoffMainParser::parse ()
{
this->mpd = new MPD();
this->setMPDAttributes();
this->setMPDBaseUrl();
this->setPeriods();
return true;
}
MPD* IsoffMainParser::getMPD ()
{
return this->mpd;
}
void IsoffMainParser::setMPDAttributes ()
{
const std::map<std::string, std::string> attr = this->root->getAttributes();
std::map<std::string, std::string>::const_iterator it;
it = attr.find("profiles");
if(it != attr.end())
this->mpd->setProfile(it->second);
it = attr.find("mediaPresentationDuration");
if(it != attr.end())
this->mpd->setDuration(str_duration(it->second.c_str()));
it = attr.find("minBufferTime");
if(it != attr.end())
this->mpd->setMinBufferTime(str_duration( it->second.c_str()));
}
void IsoffMainParser::setMPDBaseUrl ()
{
std::vector<Node *> baseUrls = DOMHelper::getChildElementByTagName(this->root, "BaseURL");
for(size_t i = 0; i < baseUrls.size(); i++)
{
BaseUrl *url = new BaseUrl(baseUrls.at(i)->getText());
this->mpd->addBaseUrl(url);
}
}
void IsoffMainParser::setPeriods ()
{
std::vector<Node *> periods = DOMHelper::getElementByTagName(this->root, "Period", false);
for(size_t i = 0; i < periods.size(); i++)
{
Period *period = new Period();
this->setAdaptationSets(periods.at(i), period);
this->mpd->addPeriod(period);
}
}
void IsoffMainParser::setAdaptationSets (Node *periodNode, Period *period)
{
std::vector<Node *> adaptationSets = DOMHelper::getElementByTagName(periodNode, "AdaptationSet", false);
for(size_t i = 0; i < adaptationSets.size(); i++)
{
AdaptationSet *adaptationSet = new AdaptationSet();
this->setRepresentations(adaptationSets.at(i), adaptationSet);
period->addAdaptationSet(adaptationSet);
}
}
void IsoffMainParser::setRepresentations (Node *adaptationSetNode, AdaptationSet *adaptationSet)
{
std::vector<Node *> representations = DOMHelper::getElementByTagName(adaptationSetNode, "Representation", false);
for(size_t i = 0; i < representations.size(); i++)
{
Representation *rep = new Representation;
this->setSegmentBase(representations.at(i), rep);
this->setSegmentList(representations.at(i), rep);
rep->setBandwidth(atoi(representations.at(i)->getAttributeValue("bandwidth").c_str()));
adaptationSet->addRepresentation(rep);
}
}
void IsoffMainParser::setSegmentBase (dash::xml::Node *repNode, Representation *rep)
{
std::vector<Node *> segmentBase = DOMHelper::getElementByTagName(repNode, "SegmentBase", false);
if(segmentBase.size() > 0)
{
SegmentBase *base = new SegmentBase();
this->setInitSegment(segmentBase.at(0), base);
rep->setSegmentBase(base);
}
}
void IsoffMainParser::setSegmentList (dash::xml::Node *repNode, Representation *rep)
{
std::vector<Node *> segmentList = DOMHelper::getElementByTagName(repNode, "SegmentList", false);
if(segmentList.size() > 0)
{
SegmentList *list = new SegmentList();
this->setSegments(segmentList.at(0), list);
rep->setSegmentList(list);
}
}
void IsoffMainParser::setInitSegment (dash::xml::Node *segBaseNode, SegmentBase *base)
{
std::vector<Node *> initSeg = DOMHelper::getElementByTagName(segBaseNode, "Initialisation", false);
if(initSeg.size() > 0)
{
Segment *seg = new Segment();
seg->setSourceUrl(initSeg.at(0)->getAttributeValue("sourceURL"));
if(initSeg.at(0)->hasAttribute("range"))
{
std::string range = initSeg.at(0)->getAttributeValue("range");
size_t pos = range.find("-");
seg->setByteRange(atoi(range.substr(0, pos).c_str()), atoi(range.substr(pos, range.size()).c_str()));
}
for(size_t i = 0; i < this->mpd->getBaseUrls().size(); i++)
seg->addBaseUrl(this->mpd->getBaseUrls().at(i));
base->addInitSegment(seg);
}
}
void IsoffMainParser::setSegments (dash::xml::Node *segListNode, SegmentList *list)
{
std::vector<Node *> segments = DOMHelper::getElementByTagName(segListNode, "SegmentURL", false);
for(size_t i = 0; i < segments.size(); i++)
{
Segment *seg = new Segment();
seg->setSourceUrl(segments.at(i)->getAttributeValue("media"));
if(segments.at(0)->hasAttribute("mediaRange"))
{
std::string range = segments.at(0)->getAttributeValue("mediaRange");
size_t pos = range.find("-");
seg->setByteRange(atoi(range.substr(0, pos).c_str()), atoi(range.substr(pos, range.size()).c_str()));
}
for(size_t i = 0; i < this->mpd->getBaseUrls().size(); i++)
seg->addBaseUrl(this->mpd->getBaseUrls().at(i));
list->addSegment(seg);
}
}
void IsoffMainParser::print ()
{
if(this->mpd)
{
msg_Dbg(this->p_stream, "MPD profile=%d mediaPresentationDuration=%ld minBufferTime=%ld", this->mpd->getProfile(),
this->mpd->getDuration(),
this->mpd->getMinBufferTime());
const std::vector<BaseUrl *> baseurls = this->mpd->getBaseUrls();
for(size_t i = 0; i < baseurls.size(); i++)
msg_Dbg(this->p_stream, "BaseUrl=%s", baseurls.at(i)->getUrl().c_str());
const std::vector<Period *> periods = this->mpd->getPeriods();
for(size_t i = 0; i < periods.size(); i++)
{
Period *period = periods.at(i);
msg_Dbg(this->p_stream, " Period");
for(size_t j = 0; j < period->getAdaptationSets().size(); j++)
{
AdaptationSet *aset = period->getAdaptationSets().at(j);
msg_Dbg(this->p_stream, " AdaptationSet");
for(size_t k = 0; k < aset->getRepresentations().size(); k++)
{
Representation *rep = aset->getRepresentations().at(k);
msg_Dbg(this->p_stream, " Representation");
Segment *initSeg = rep->getSegmentBase()->getInitSegment();
msg_Dbg(this->p_stream, " InitSeg url=%s", initSeg->getSourceUrl().c_str());
for(size_t l = 0; l < rep->getSegmentList()->getSegments().size(); l++)
{
Segment *seg = rep->getSegmentList()->getSegments().at(l);
msg_Dbg(this->p_stream, " Segment url=%s", seg->getSourceUrl().c_str());
}
}
}
}
}
}
/*
* IsoffMainParser.h
*****************************************************************************
* Copyright (C) 2010 - 2012 Klagenfurt University
*
* Created on: Jan 27, 2012
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef ISOFFMAINPARSER_H_
#define ISOFFMAINPARSER_H_
#include "xml/Node.h"
#include "xml/DOMHelper.h"
#include "mpd/IMPDParser.h"
#include "mpd/MPD.h"
#include "mpd/Period.h"
#include "mpd/AdaptationSet.h"
#include "mpd/Representation.h"
#include "mpd/BaseUrl.h"
#include "mpd/SegmentBase.h"
#include "mpd/SegmentList.h"
#include "mpd/Segment.h"
#include <cstdlib>
#include <sstream>
#include <vlc_common.h>
#include <vlc_stream.h>
#include <vlc_strings.h>
namespace dash
{
namespace mpd
{
class IsoffMainParser : public IMPDParser
{
public:
IsoffMainParser (dash::xml::Node *root, stream_t *p_stream);
virtual ~IsoffMainParser ();
bool parse ();
MPD* getMPD ();
void print ();
private:
dash::xml::Node *root;
stream_t *p_stream;
MPD *mpd;
void setMPDAttributes ();
void setMPDBaseUrl ();
void setPeriods ();
void setAdaptationSets (dash::xml::Node *periodNode, Period *period);
void setRepresentations (dash::xml::Node *adaptationSetNode, AdaptationSet *adaptationSet);
void setSegmentBase (dash::xml::Node *repNode, Representation *rep);
void setSegmentList (dash::xml::Node *repNode, Representation *rep);
void setInitSegment (dash::xml::Node *segBaseNode, SegmentBase *base);
void setSegments (dash::xml::Node *segListNode, SegmentList *list);
};
}
}
#endif /* ISOFFMAINPARSER_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment