[vlc-commits] demux: dash: simplify integer parsing using templates

Francois Cartegnie git at videolan.org
Wed Dec 24 19:24:29 CET 2014


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Dec 24 19:21:38 2014 +0100| [01e36efec5df5533adf81963633653dd7874d71f] | committer: Francois Cartegnie

demux: dash: simplify integer parsing using templates

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=01e36efec5df5533adf81963633653dd7874d71f
---

 modules/stream_filter/dash/mpd/IsoffMainParser.cpp |   28 +++-----------------
 modules/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 caf2917..8da7adf 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<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;
 }
 
diff --git a/modules/stream_filter/dash/mpd/IsoffMainParser.h b/modules/stream_filter/dash/mpd/IsoffMainParser.h
index 5e56ff5..f8212d3 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<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;
+        };
     }
 }
 



More information about the vlc-commits mailing list