From 01e36efec5df5533adf81963633653dd7874d71f Mon Sep 17 00:00:00 2001 From: Francois Cartegnie Date: Wed, 24 Dec 2014 19:21:38 +0100 Subject: [PATCH] demux: dash: simplify integer parsing using templates --- .../dash/mpd/IsoffMainParser.cpp | 28 +++---------------- .../stream_filter/dash/mpd/IsoffMainParser.h | 23 +++++++++++++++ 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/modules/stream_filter/dash/mpd/IsoffMainParser.cpp b/modules/stream_filter/dash/mpd/IsoffMainParser.cpp index caf29174f6..8da7adf821 100644 --- a/modules/stream_filter/dash/mpd/IsoffMainParser.cpp +++ b/modules/stream_filter/dash/mpd/IsoffMainParser.cpp @@ -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(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(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(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(node->getAttributeValue("timescale"))); return total; } diff --git a/modules/stream_filter/dash/mpd/IsoffMainParser.h b/modules/stream_filter/dash/mpd/IsoffMainParser.h index 5e56ff5875..f8212d3b39 100644 --- a/modules/stream_filter/dash/mpd/IsoffMainParser.h +++ b/modules/stream_filter/dash/mpd/IsoffMainParser.h @@ -80,6 +80,29 @@ namespace dash private: mtime_t time; }; + + template 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; + }; } } -- 2.39.2