Commit 01e36efe authored by François Cartegnie's avatar François Cartegnie 🤞
Browse files

demux: dash: simplify integer parsing using templates

parent 2860a192
......@@ -115,28 +115,13 @@ size_t IsoffMainParser::parseSegmentTemplate(Node *templateNode, SegmentInformat
mediaTemplate->setSourceUrl(mediaurl);
if(templateNode->hasAttribute("startNumber"))
{
std::istringstream in(templateNode->getAttributeValue("startNumber"));
size_t i;
in >> i;
mediaTemplate->setStartIndex(i);
}
mediaTemplate->setStartIndex(Integer<uint64_t>(templateNode->getAttributeValue("startNumber")));
if(templateNode->hasAttribute("duration"))
{
std::istringstream in(templateNode->getAttributeValue("duration"));
size_t i;
in >> i;
mediaTemplate->duration.Set(i);
}
mediaTemplate->duration.Set(Integer<mtime_t>(templateNode->getAttributeValue("duration")));
if(templateNode->hasAttribute("timescale"))
{
std::istringstream in(templateNode->getAttributeValue("timescale"));
size_t i;
in >> i;
mediaTemplate->timescale.Set(i);
}
mediaTemplate->timescale.Set(Integer<uint64_t>(templateNode->getAttributeValue("timescale")));
InitSegmentTemplate *initTemplate = NULL;
......@@ -164,12 +149,7 @@ size_t IsoffMainParser::parseSegmentInformation(Node *node, SegmentInformation *
if(node->hasAttribute("bitstreamSwitching"))
info->setBitstreamSwitching(node->getAttributeValue("bitstreamSwitching") == "true");
if(node->hasAttribute("timescale"))
{
std::istringstream in(node->getAttributeValue("timescale"));
uint64_t i;
in >> i;
info->timescale.Set(i);
}
info->timescale.Set(Integer<uint64_t>(node->getAttributeValue("timescale")));
return total;
}
......
......@@ -80,6 +80,29 @@ namespace dash
private:
mtime_t time;
};
template<typename T> class Integer
{
public:
Integer(const std::string &str)
{
try
{
std::istringstream in(str);
in >> value;
} catch (int) {
value = 0;
}
}
operator T() const
{
return value;
}
private:
T value;
};
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment