Commit 7000945e authored by Francois Cartegnie's avatar Francois Cartegnie

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

parent d1282d53
...@@ -85,6 +85,25 @@ Url::Component::Component(const std::string & str, const SegmentTemplate *templ_ ...@@ -85,6 +85,25 @@ Url::Component::Component(const std::string & str, const SegmentTemplate *templ_
templ = 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 Url::Component::contextualize(size_t index, const Representation *rep) const
{ {
std::string ret(component); std::string ret(component);
...@@ -100,27 +119,38 @@ std::string Url::Component::contextualize(size_t index, const Representation *re ...@@ -100,27 +119,38 @@ std::string Url::Component::contextualize(size_t index, const Representation *re
ret.replace(pos, std::string("$Time$").length(), ss.str()); ret.replace(pos, std::string("$Time$").length(), ss.str());
} }
pos = ret.find("$Number$"); pos = ret.find("$Number$");
if(pos != std::string::npos) if(pos != std::string::npos)
{ {
index += templ->getStartIndex();
std::stringstream ss; std::stringstream ss;
/* live streams / templated */ ss << getSegmentNumber(index, rep);
if(rep->getMPD()->isLive() && templ->duration.Get()) ret.replace(pos, std::string("$Number$").length(), ss.str());
}
else
{ {
mtime_t playbackstart = rep->getMPD()->playbackStart.Get(); pos = ret.find("$Number%");
mtime_t streamstart = rep->getMPD()->getAvailabilityStartTime(); size_t tokenlength = std::string("$Number%").length();
streamstart += rep->getPeriodStart(); size_t fmtstart = pos + tokenlength;
mtime_t duration = templ->duration.Get(); if(pos != std::string::npos && fmtstart < ret.length())
uint64_t timescale = templ->timescale.Get() ? {
templ->timescale.Get() : size_t fmtend = ret.find('$', fmtstart);
rep->getTimescale(); if(fmtend != std::string::npos)
if(duration && timescale) {
index += (playbackstart - streamstart) * timescale / duration; 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$"); pos = ret.find("$Bandwidth$");
......
...@@ -41,6 +41,7 @@ namespace dash ...@@ -41,6 +41,7 @@ namespace dash
protected: protected:
std::string contextualize(size_t, const Representation *) const; std::string contextualize(size_t, const Representation *) const;
size_t getSegmentNumber(size_t, const Representation *) const;
std::string component; std::string component;
const SegmentTemplate *templ; const SegmentTemplate *templ;
}; };
......
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