Dash: major warnings cleanup
[vlc.git] / modules / stream_filter / dash / xml / DOMParser.cpp
blob9ed486d41355c8c054f1222e44d2adcf13c81ed9
1 /*
2 * DOMParser.cpp
3 *****************************************************************************
4 * Copyright (C) 2010 - 2011 Klagenfurt University
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>
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.
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.
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
28 #include "DOMParser.h"
30 using namespace dash::xml;
31 using namespace dash::http;
32 using namespace dash::mpd;
34 DOMParser::DOMParser (stream_t *stream)
36 this->stream = stream;
37 this->init();
39 DOMParser::~DOMParser ()
41 if(this->vlc_reader)
42 xml_ReaderDelete(this->vlc_reader);
45 Node* DOMParser::getRootNode ()
47 return this->root;
49 bool DOMParser::parse ()
51 this->vlc_xml = xml_Create(this->stream);
53 if(!this->vlc_xml)
54 return false;
56 this->vlc_reader = xml_ReaderCreate(this->vlc_xml, this->stream);
58 if(!this->vlc_reader)
59 return false;
61 this->root = this->processNode();
63 return true;
65 Node* DOMParser::processNode ()
67 const char *data;
68 int type = xml_ReaderNextNode(this->vlc_reader, &data);
69 if(type != XML_READER_TEXT && type != XML_READER_NONE && type != XML_READER_ENDELEM)
71 Node *node = new Node();
73 std::string name = data;
74 bool isEmpty = xml_ReaderIsEmptyElement(this->vlc_reader);
75 node->setName(name);
77 this->addAttributesToNode(node);
79 if(isEmpty)
80 return node;
82 Node *subnode = NULL;
84 while(subnode = this->processNode())
85 node->addSubNode(subnode);
87 return node;
89 return NULL;
91 void DOMParser::addAttributesToNode (Node *node)
93 const char *attrValue;
94 const char *attrName;
96 while((attrName = xml_ReaderNextAttr(this->vlc_reader, &attrValue)) != NULL)
98 std::string key = attrName;
99 std::string value = attrValue;
100 node->addAttribute(key, value);
103 void DOMParser::print (Node *node, int offset)
105 for(int i = 0; i < offset; i++)
106 msg_Dbg(this->stream, " ");
108 msg_Dbg(this->stream, "%s", node->getName().c_str());
110 std::vector<std::string> keys = node->getAttributeKeys();
112 for(size_t i = 0; i < keys.size(); i++)
113 msg_Dbg(this->stream, " %s=%s", keys.at(i).c_str(), node->getAttributeValue(keys.at(i)).c_str());
115 msg_Dbg(this->stream, "\n");
117 offset++;
119 for(size_t i = 0; i < node->getSubNodes().size(); i++)
121 this->print(node->getSubNodes().at(i), offset);
124 void DOMParser::init ()
126 this->root = NULL;
127 this->vlc_reader = NULL;
129 void DOMParser::print ()
131 this->print(this->root, 0);
133 Profile DOMParser::getProfile (dash::xml::Node *node)
135 std::string profile = node->getAttributeValue("profiles");
137 if(!profile.compare("urn:mpeg:mpegB:profile:dash:isoff-basic-on-demand:cm"))
138 return dash::mpd::BasicCM;
140 return dash::mpd::NotValid;
142 bool DOMParser::isDash ()
144 const uint8_t *peek, *peek_end;
146 int64_t i_size = stream_Peek(this->stream, &peek, 2048);
147 if(i_size < 1)
148 return false;
150 peek_end = peek + i_size;
151 while(peek <= peek_end)
153 const char *p = strstr((const char*)peek, "urn:mpeg:mpegB:schema:DASH:MPD:DIS2011");
154 if (p != NULL)
155 return true;
156 peek++;
159 return false;