IsoffMainParser.cpp 7.92 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
90
91
92
93
94
95
96
97
98
99
100
101
        this->currentRepresentation = new Representation;
        Node *repNode = representations.at(i);

        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);
102
103
104
105
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
    }
}
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);

131
132
133
    if(initSeg.size() == 0)
        initSeg = DOMHelper::getElementByTagName(segBaseNode, "Initialization", false);

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

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

161
        if(segments.at(i)->hasAttribute("mediaRange"))
162
        {
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()));
166
167
        }

Christopher Mueller's avatar
Christopher Mueller committed
168
169
        for(size_t j = 0; j < this->mpd->getBaseUrls().size(); j++)
            seg->addBaseUrl(this->mpd->getBaseUrls().at(j));
170
171
172
173
174
175

        list->addSegment(seg);
    }
}
void    IsoffMainParser::print              ()
{
176
    if(mpd)
177
    {
178
179
180
181
        msg_Dbg(p_stream, "MPD profile=%s mediaPresentationDuration=%ld minBufferTime=%ld",
                static_cast<std::string>(mpd->getProfile()).c_str(),
                mpd->getDuration(),
                mpd->getMinBufferTime());
182
183
184
185
186
187
        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++)
188
        {
189
190
191
            msg_Dbg(p_stream, " Period");
            std::vector<AdaptationSet *>::const_iterator j;
            for(j = (*i)->getAdaptationSets().begin(); j != (*i)->getAdaptationSets().end(); j++)
192
            {
193
194
                msg_Dbg(p_stream, "  AdaptationSet");
                std::vector<Representation *>::const_iterator k;
195
                for(k = (*j)->getRepresentations().begin(); k != (*j)->getRepresentations().end(); k++)
196
                {
197
198
                    msg_Dbg(p_stream, "   Representation");
                    msg_Dbg(p_stream, "    InitSeg url=%s", (*k)->getSegmentBase()->getInitSegment()->getSourceUrl().c_str());
199
200
201

                    const SegmentList *segmentList = (*k)->getSegmentList();
                    if (segmentList)
202
                    {
203
204
205
206
207
208
                        std::vector<Segment *>::const_iterator l;
                        for(l = segmentList->getSegments().begin();
                            l < segmentList->getSegments().end(); l++)
                        {
                            msg_Dbg(p_stream, "    Segment url=%s", (*l)->getSourceUrl().c_str());
                        }
209
210
211
212
213
214
                    }
                }
            }
        }
    }
}