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 *****************************************************************************/
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
;
39 DOMParser::~DOMParser ()
42 xml_ReaderDelete(this->vlc_reader
);
45 Node
* DOMParser::getRootNode ()
49 bool DOMParser::parse ()
51 this->vlc_xml
= xml_Create(this->stream
);
56 this->vlc_reader
= xml_ReaderCreate(this->vlc_xml
, this->stream
);
61 this->root
= this->processNode();
65 Node
* DOMParser::processNode ()
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
);
77 this->addAttributesToNode(node
);
84 while(subnode
= this->processNode())
85 node
->addSubNode(subnode
);
91 void DOMParser::addAttributesToNode (Node
*node
)
93 const char *attrValue
;
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");
119 for(size_t i
= 0; i
< node
->getSubNodes().size(); i
++)
121 this->print(node
->getSubNodes().at(i
), offset
);
124 void DOMParser::init ()
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);
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");