Commit 1a4b8ae2 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: adaptative: add minAheadTime for live playlists

parent 4b7af730
......@@ -225,6 +225,16 @@ mtime_t SegmentTracker::getSegmentStart() const
return 0;
}
mtime_t SegmentTracker::getMinAheadTime() const
{
BaseRepresentation *rep = curRepresentation;
if(!rep)
rep = logic->getNextRepresentation(adaptationSet, NULL);
if(rep)
return rep->getMinAheadTime(count);
return 0;
}
void SegmentTracker::registerListener(SegmentTrackerListenerInterface *listener)
{
listeners.push_back(listener);
......
......@@ -100,6 +100,7 @@ namespace adaptative
bool setPositionByTime(mtime_t, bool, bool);
void setPositionByNumber(uint64_t, bool);
mtime_t getSegmentStart() const;
mtime_t getMinAheadTime() const;
void registerListener(SegmentTrackerListenerInterface *);
void pruneFromCurrent();
void updateSelected();
......
......@@ -120,6 +120,13 @@ mtime_t AbstractStream::getPCR() const
return pcr;
}
mtime_t AbstractStream::getMinAheadTime() const
{
if(!segmentTracker)
return 0;
return segmentTracker->getMinAheadTime();
}
mtime_t AbstractStream::getBufferingLevel() const
{
return fakeesout->commandsqueue.getBufferingLevel();
......
......@@ -66,6 +66,7 @@ namespace adaptative
bool isEOF() const;
mtime_t getPCR() const;
mtime_t getBufferingLevel() const;
mtime_t getMinAheadTime() const;
mtime_t getFirstDTS() const;
int esCount() const;
bool seekAble() const;
......
......@@ -82,6 +82,34 @@ bool BaseRepresentation::consistentSegmentNumber() const
return b_consistent;
}
mtime_t BaseRepresentation::getMinAheadTime(uint64_t curnum) const
{
std::vector<ISegment *> seglist;
getSegments(INFOTYPE_MEDIA, seglist);
if(seglist.size() == 1 && seglist.front()->isTemplate())
{
const MediaSegmentTemplate *templ = dynamic_cast<MediaSegmentTemplate *>(seglist.front());
const SegmentTimeline *timeline;
if(templ && (timeline = templ->segmentTimeline.Get()))
{
const uint64_t timescale = templ->inheritTimescale();
return timeline->getMinAheadScaledTime(curnum) * CLOCK_FREQ / timescale;
}
}
mtime_t minTime = 0;
std::vector<ISegment *>::const_iterator it;
for(it = seglist.begin(); it != seglist.end(); ++it)
{
const ISegment *seg = *it;
if(seg->getSequenceNumber() > curnum)
minTime += seg->duration.Get() * CLOCK_FREQ / inheritTimescale();
}
return minTime;
}
void BaseRepresentation::debug(vlc_object_t *obj, int indent) const
{
std::string text(indent, ' ');
......
......@@ -61,6 +61,8 @@ namespace adaptative
virtual bool needsUpdate() const;
bool consistentSegmentNumber () const;
virtual mtime_t getMinAheadTime (uint64_t) const;
virtual void debug (vlc_object_t *,int = 0) const;
/* for segment templates */
......
......@@ -59,6 +59,30 @@ void SegmentTimeline::addElement(uint64_t number, stime_t d, uint64_t r, stime_t
}
}
mtime_t SegmentTimeline::getMinAheadScaledTime(uint64_t number) const
{
stime_t totalscaledtime = 0;
std::list<Element *>::const_reverse_iterator it;
for(it = elements.rbegin(); it != elements.rend(); ++it)
{
const Element *el = *it;
if(number < el->number)
{
totalscaledtime += (el->d * (el->r + 1));
break;
}
else if(number <= el->number + el->r)
{
totalscaledtime += el->d * (el->number + el->r - number);
}
else break;
}
return totalscaledtime;
}
uint64_t SegmentTimeline::getElementNumberByScaledPlaybackTime(stime_t scaled) const
{
uint64_t prevnumber = 0;
......
......@@ -47,6 +47,7 @@ namespace adaptative
void addElement(uint64_t, stime_t d, uint64_t r = 0, stime_t t = 0);
uint64_t getElementNumberByScaledPlaybackTime(stime_t) const;
stime_t getScaledPlaybackTimeByElementNumber(uint64_t) const;
stime_t getMinAheadScaledTime(uint64_t) const;
uint64_t maxElementNumber() const;
uint64_t minElementNumber() const;
size_t pruneBySequenceNumber(uint64_t);
......
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