[vlc-commits] demux: dash: handle format string min width in segment number

Francois Cartegnie git at videolan.org
Wed Dec 31 16:22:32 CET 2014


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Dec 31 16:08:45 2014 +0100| [7000945e3b4759ac6a9b7596279cb37edd0d1ca9] | committer: Francois Cartegnie

demux: dash: handle format string min width in segment number

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

 modules/demux/dash/mpd/Url.cpp |   60 ++++++++++++++++++++++++++++++----------
 modules/demux/dash/mpd/Url.hpp |    1 +
 2 files changed, 46 insertions(+), 15 deletions(-)

diff --git a/modules/demux/dash/mpd/Url.cpp b/modules/demux/dash/mpd/Url.cpp
index a95346b..3fdda9b 100644
--- a/modules/demux/dash/mpd/Url.cpp
+++ b/modules/demux/dash/mpd/Url.cpp
@@ -85,6 +85,25 @@ Url::Component::Component(const std::string & str, const SegmentTemplate *templ_
     templ = templ_;
 }
 
+size_t Url::Component::getSegmentNumber(size_t index, const Representation *rep) const
+{
+    index += templ->getStartIndex();
+    /* live streams / templated */
+    if(rep->getMPD()->isLive() && templ->duration.Get())
+    {
+        mtime_t playbackstart = rep->getMPD()->playbackStart.Get();
+        mtime_t streamstart = rep->getMPD()->getAvailabilityStartTime();
+        streamstart += rep->getPeriodStart();
+        mtime_t duration = templ->duration.Get();
+        uint64_t timescale = templ->timescale.Get() ?
+                             templ->timescale.Get() :
+                             rep->getTimescale();
+        if(duration && timescale)
+            index += (playbackstart - streamstart) * timescale / duration;
+    }
+    return index;
+}
+
 std::string Url::Component::contextualize(size_t index, const Representation *rep) const
 {
     std::string ret(component);
@@ -100,27 +119,38 @@ std::string Url::Component::contextualize(size_t index, const Representation *re
         ret.replace(pos, std::string("$Time$").length(), ss.str());
     }
 
-
     pos = ret.find("$Number$");
     if(pos != std::string::npos)
     {
-        index += templ->getStartIndex();
         std::stringstream ss;
-        /* live streams / templated */
-        if(rep->getMPD()->isLive() && templ->duration.Get())
+        ss << getSegmentNumber(index, rep);
+        ret.replace(pos, std::string("$Number$").length(), ss.str());
+    }
+    else
+    {
+        pos = ret.find("$Number%");
+        size_t tokenlength = std::string("$Number%").length();
+        size_t fmtstart = pos + tokenlength;
+        if(pos != std::string::npos && fmtstart < ret.length())
         {
-            mtime_t playbackstart = rep->getMPD()->playbackStart.Get();
-            mtime_t streamstart = rep->getMPD()->getAvailabilityStartTime();
-            streamstart += rep->getPeriodStart();
-            mtime_t duration = templ->duration.Get();
-            uint64_t timescale = templ->timescale.Get() ?
-                                 templ->timescale.Get() :
-                                 rep->getTimescale();
-            if(duration && timescale)
-                index += (playbackstart - streamstart) * timescale / duration;
+            size_t fmtend = ret.find('$', fmtstart);
+            if(fmtend != std::string::npos)
+            {
+                std::istringstream iss(ret.substr(fmtstart, fmtend - fmtstart + 1));
+                try
+                {
+                    size_t width;
+                    iss >> width;
+                    if (iss.peek() != '$')
+                        throw VLC_EGENERIC;
+                    std::stringstream oss;
+                    oss.width(width); /* set format string length */
+                    oss.fill('0');
+                    oss << getSegmentNumber(index, rep);
+                    ret.replace(pos, fmtend - pos + 1, oss.str());
+                } catch(int) {}
+            }
         }
-        ss << index;
-        ret.replace(pos, std::string("$Number$").length(), ss.str());
     }
 
     pos = ret.find("$Bandwidth$");
diff --git a/modules/demux/dash/mpd/Url.hpp b/modules/demux/dash/mpd/Url.hpp
index 9f73237..4523d8f 100644
--- a/modules/demux/dash/mpd/Url.hpp
+++ b/modules/demux/dash/mpd/Url.hpp
@@ -41,6 +41,7 @@ namespace dash
 
                     protected:
                         std::string contextualize(size_t, const Representation *) const;
+                        size_t getSegmentNumber(size_t, const Representation *) const;
                         std::string component;
                         const SegmentTemplate *templ;
                 };



More information about the vlc-commits mailing list