IsoffMainParser.cpp 7.75 KB
Newer Older
1
2
3
4
5
6
7
8
9
/*
 * 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>
 *
10
11
 * 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
12
13
14
15
16
 * 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
17
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
19
20
 *
 * You should have received a copy of the GNU Lesser General Public License
21
22
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23
24
 *****************************************************************************/

25
26
27
28
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

29
#include "IsoffMainParser.h"
30
31
#include "xml/DOMHelper.h"
#include <vlc_strings.h>
32
33
34
35
36

using namespace dash::mpd;
using namespace dash::xml;

IsoffMainParser::IsoffMainParser    (Node *root, stream_t *p_stream) :
37
                 IMPDParser(root, NULL, p_stream, NULL)
38
39
40
41
42
43
44
45
{
}
IsoffMainParser::~IsoffMainParser   ()
{
}

bool    IsoffMainParser::parse              ()
{
46
47
48
49
50
    mpd = new MPD();
    setMPDAttributes();
    setMPDBaseUrl(root);
    setPeriods(root);
    print();
51
52
    return true;
}
53

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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("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::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++)
    {
87
88
89
        this->currentRepresentation = new Representation;
        Node *repNode = representations.at(i);

90
91
92
93
        std::vector<Node *> baseUrls = DOMHelper::getChildElementByTagName(repNode, "BaseURL");
        if(!baseUrls.empty())
            currentRepresentation->setBaseUrl( new BaseUrl( baseUrls.front()->getText() ) );

94
95
96
97
98
99
100
101
102
103
104
105
        if(repNode->hasAttribute("width"))
            this->currentRepresentation->setWidth(atoi(repNode->getAttributeValue("width").c_str()));

        if(repNode->hasAttribute("height"))
            this->currentRepresentation->setHeight(atoi(repNode->getAttributeValue("height").c_str()));

        if(repNode->hasAttribute("bandwidth"))
            this->currentRepresentation->setBandwidth(atoi(repNode->getAttributeValue("bandwidth").c_str()));

        this->setSegmentBase(repNode, this->currentRepresentation);
        this->setSegmentList(repNode, this->currentRepresentation);
        adaptationSet->addRepresentation(this->currentRepresentation);
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
    }
}
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);

135
136
137
    if(initSeg.size() == 0)
        initSeg = DOMHelper::getElementByTagName(segBaseNode, "Initialization", false);

138
139
    if(initSeg.size() > 0)
    {
140
        Segment *seg = new Segment( this->currentRepresentation );
141
142
143
144
145
146
        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("-");
147
            seg->setByteRange(atoi(range.substr(0, pos).c_str()), atoi(range.substr(pos + 1, range.size()).c_str()));
148
149
150
151
152
153
154
155
156
157
158
159
160
161
        }

        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++)
    {
162
        Segment *seg = new Segment( this->currentRepresentation );
163
164
        seg->setSourceUrl(segments.at(i)->getAttributeValue("media"));

165
        if(segments.at(i)->hasAttribute("mediaRange"))
166
        {
167
            std::string range = segments.at(i)->getAttributeValue("mediaRange");
168
            size_t pos = range.find("-");
169
            seg->setByteRange(atoi(range.substr(0, pos).c_str()), atoi(range.substr(pos + 1, range.size()).c_str()));
170
171
        }

Christopher Mueller's avatar
Christopher Mueller committed
172
173
        for(size_t j = 0; j < this->mpd->getBaseUrls().size(); j++)
            seg->addBaseUrl(this->mpd->getBaseUrls().at(j));
174
175
176
177
178
179

        list->addSegment(seg);
    }
}
void    IsoffMainParser::print              ()
{
180
    if(mpd)
181
    {
182
183
184
185
        msg_Dbg(p_stream, "MPD profile=%s mediaPresentationDuration=%ld minBufferTime=%ld",
                static_cast<std::string>(mpd->getProfile()).c_str(),
                mpd->getDuration(),
                mpd->getMinBufferTime());
186
187
188
189
190
191
        std::vector<BaseUrl *>::const_iterator h;
        for(h = mpd->getBaseUrls().begin(); h != mpd->getBaseUrls().end(); h++)
            msg_Dbg(p_stream, "BaseUrl=%s", (*h)->getUrl().c_str());

        std::vector<Period *>::const_iterator i;
        for(i = mpd->getPeriods().begin(); i != mpd->getPeriods().end(); i++)
192
        {
193
194
195
            msg_Dbg(p_stream, " Period");
            std::vector<AdaptationSet *>::const_iterator j;
            for(j = (*i)->getAdaptationSets().begin(); j != (*i)->getAdaptationSets().end(); j++)
196
            {
197
198
                msg_Dbg(p_stream, "  AdaptationSet");
                std::vector<Representation *>::const_iterator k;
199
                for(k = (*j)->getRepresentations().begin(); k != (*j)->getRepresentations().end(); k++)
200
                {
201
202
203
                    std::vector<std::string> debug = (*k)->toString();
                    std::vector<std::string>::const_iterator l;
                    for(l = debug.begin(); l < debug.end(); l++)
204
                    {
205
                        msg_Dbg(p_stream, "%s", (*l).c_str());
206
207
208
209
210
211
                    }
                }
            }
        }
    }
}