]> git.sesse.net Git - vlc/blob - modules/stream_filter/dash/mpd/BasicCMParser.cpp
dash: Parser: Standard (ยง5.4.4.1) specifies there can be at most one SegmentInfo...
[vlc] / modules / stream_filter / dash / mpd / BasicCMParser.cpp
1 /*
2  * BasicCMParser.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
11  * it 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 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
22  * Foundation, 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 "BasicCMParser.h"
29
30 using namespace dash::mpd;
31 using namespace dash::xml;
32
33 BasicCMParser::BasicCMParser    (Node *root) : root(root), mpd(NULL)
34 {
35 }
36
37 BasicCMParser::~BasicCMParser   ()
38 {
39 }
40
41 bool    BasicCMParser::parse                ()
42 {
43     this->setMPD();
44     return true;
45 }
46 void    BasicCMParser::setMPD               ()
47 {
48     this->mpd = new MPD(this->root->getAttributes());
49     this->setMPDBaseUrl(this->root);
50     this->setPeriods(this->root);
51 }
52 void    BasicCMParser::setMPDBaseUrl        (Node *root)
53 {
54     std::vector<Node *> baseUrls = DOMHelper::getChildElementByTagName(root, "BaseURL");
55
56     for(size_t i = 0; i < baseUrls.size(); i++)
57     {
58         BaseUrl *url = new BaseUrl(baseUrls.at(i)->getText());
59         this->mpd->addBaseUrl(url);
60     }
61 }
62 void    BasicCMParser::setPeriods           (Node *root)
63 {
64     std::vector<Node *> periods = DOMHelper::getElementByTagName(root, "Period", false);
65
66     for(size_t i = 0; i < periods.size(); i++)
67     {
68         Period *period = new Period(periods.at(i)->getAttributes());
69         this->setGroups(periods.at(i), period);
70         this->mpd->addPeriod(period);
71     }
72 }
73 void    BasicCMParser::setGroups            (Node *root, Period *period)
74 {
75     std::vector<Node *> groups = DOMHelper::getElementByTagName(root, "Group", false);
76
77     for(size_t i = 0; i < groups.size(); i++)
78     {
79         Group *group = new Group(groups.at(i)->getAttributes());
80         this->setRepresentations(groups.at(i), group);
81         period->addGroup(group);
82     }
83 }
84 void    BasicCMParser::setRepresentations   (Node *root, Group *group)
85 {
86     std::vector<Node *> representations = DOMHelper::getElementByTagName(root, "Representation", false);
87
88     for(size_t i = 0; i < representations.size(); i++)
89     {
90         Representation *rep = new Representation(representations.at(i)->getAttributes());
91         this->setSegmentInfo(representations.at(i), rep);
92         group->addRepresentation(rep);
93     }
94 }
95 void    BasicCMParser::setSegmentInfo       (Node *root, Representation *rep)
96 {
97     Node    *segmentInfo = DOMHelper::getFirstChildElementByName( root, "SegmentInfo");
98
99     SegmentInfo *info = new SegmentInfo( segmentInfo->getAttributes() );
100     this->setInitSegment( segmentInfo, info );
101     this->setSegments(segmentInfo, info );
102     rep->setSegmentInfo(info);
103 }
104 void    BasicCMParser::setInitSegment       (Node *root, SegmentInfo *info)
105 {
106     std::vector<Node *> initSeg = DOMHelper::getChildElementByTagName(root, "InitialisationSegmentURL");
107
108     for(size_t i = 0; i < initSeg.size(); i++)
109     {
110         InitSegment *seg = new InitSegment(initSeg.at(i)->getAttributes());
111         info->setInitSegment(seg);
112         return;
113     }
114 }
115 void    BasicCMParser::setSegments          (Node *root, SegmentInfo *info)
116 {
117     std::vector<Node *> segments = DOMHelper::getElementByTagName(root, "Url", false);
118
119     for(size_t i = 0; i < segments.size(); i++)
120     {
121         Segment *seg = new Segment(segments.at(i)->getAttributes());
122         info->addSegment(seg);
123     }
124 }
125 MPD*    BasicCMParser::getMPD               ()
126 {
127     return this->mpd;
128 }