Commit 69bf846c authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptive: return both playback time and duration in same method

parent 08ce6b02
......@@ -252,10 +252,13 @@ void SegmentTracker::setPositionByNumber(uint64_t segnumber, bool restarted)
mtime_t SegmentTracker::getPlaybackTime() const
{
if(curRepresentation)
return curRepresentation->getPlaybackTimeBySegmentNumber(next);
else
return 0;
mtime_t time, duration;
if(curRepresentation &&
curRepresentation->getPlaybackTimeDurationBySegmentNumber(next, &time, &duration))
{
return time;
}
return 0;
}
mtime_t SegmentTracker::getMinAheadTime() const
......
......@@ -329,31 +329,36 @@ bool SegmentInformation::getSegmentNumberByTime(mtime_t time, uint64_t *ret) con
return false;
}
mtime_t SegmentInformation::getPlaybackTimeBySegmentNumber(uint64_t number) const
bool SegmentInformation::getPlaybackTimeDurationBySegmentNumber(uint64_t number,
mtime_t *time, mtime_t *duration) const
{
SegmentList *segList;
MediaSegmentTemplate *mediaTemplate;
mtime_t time = 0;
if( (mediaTemplate = inheritSegmentTemplate()) )
{
uint64_t timescale = mediaTemplate->inheritTimescale();
stime_t stime, sduration;
if(mediaTemplate->segmentTimeline.Get())
{
time = mediaTemplate->segmentTimeline.Get()->
getScaledPlaybackTimeByElementNumber(number);
mediaTemplate->segmentTimeline.Get()->
getScaledPlaybackTimeDurationBySegmentNumber(number, &stime, &sduration);
}
else
{
time = number * mediaTemplate->duration.Get();
stime = number * mediaTemplate->duration.Get();
sduration = mediaTemplate->duration.Get();
}
time = CLOCK_FREQ * time / timescale;
*time = CLOCK_FREQ * stime / timescale;
*duration = CLOCK_FREQ * sduration / timescale;
return true;
}
else if ( (segList = inheritSegmentList()) )
{
time = segList->getPlaybackTimeBySegmentNumber(number);
return segList->getPlaybackTimeDurationBySegmentNumber(number, time, duration);
}
return time;
return false;
}
SegmentInformation * SegmentInformation::getChildByID(const ID &id)
......@@ -424,8 +429,9 @@ void SegmentInformation::pruneBySegmentNumber(uint64_t num)
uint64_t SegmentInformation::translateSegmentNumber(uint64_t num, const SegmentInformation *from) const
{
mtime_t time = from->getPlaybackTimeBySegmentNumber(num);
getSegmentNumberByTime(time, &num);
mtime_t time, duration;
if( from->getPlaybackTimeDurationBySegmentNumber(num, &time, &duration) )
getSegmentNumberByTime(time, &num);
return num;
}
......
......@@ -78,7 +78,7 @@ namespace adaptive
ISegment * getSegment(SegmentInfoType, uint64_t = 0) const;
ISegment * getNextSegment(SegmentInfoType, uint64_t, uint64_t *, bool *) const;
bool getSegmentNumberByTime(mtime_t, uint64_t *) const;
mtime_t getPlaybackTimeBySegmentNumber(uint64_t) const;
bool getPlaybackTimeDurationBySegmentNumber(uint64_t, mtime_t *, mtime_t *) const;
uint64_t getLiveStartSegmentNumber(uint64_t) const;
virtual void mergeWith(SegmentInformation *, mtime_t);
virtual void mergeWithTimeline(SegmentTimeline *); /* ! don't use with global merge */
......
......@@ -125,18 +125,21 @@ bool SegmentList::getSegmentNumberByScaledTime(stime_t time, uint64_t *ret) cons
return SegmentInfoCommon::getSegmentNumberByScaledTime(allsubsegments, time, ret);
}
mtime_t SegmentList::getPlaybackTimeBySegmentNumber(uint64_t number)
bool SegmentList::getPlaybackTimeDurationBySegmentNumber(uint64_t number,
mtime_t *time, mtime_t *dur) const
{
*time = *dur = VLC_TS_INVALID;
if(segments.empty())
return VLC_TS_INVALID;
return false;
const uint64_t timescale = inheritTimescale();
const ISegment *first = segments.front();
if(first->getSequenceNumber() > number)
return VLC_TS_INVALID;
return false;
stime_t time = first->startTime.Get();
std::vector<ISegment *>::iterator it = segments.begin();
*time = first->startTime.Get();
std::vector<ISegment *>::const_iterator it = segments.begin();
for(it = segments.begin(); it != segments.end(); ++it)
{
const ISegment *seg = *it;
......@@ -147,13 +150,17 @@ mtime_t SegmentList::getPlaybackTimeBySegmentNumber(uint64_t number)
}
else if(seg->duration.Get())
{
time += seg->duration.Get();
*time += seg->duration.Get();
*dur = seg->duration.Get();
}
else
{
time += duration.Get();
*time += duration.Get();
*dur = duration.Get();
}
}
return VLC_TS_0 + CLOCK_FREQ * time / timescale;
*time = VLC_TS_0 + CLOCK_FREQ * *time / timescale;
*dur = VLC_TS_0 + CLOCK_FREQ * *dur / timescale;
return true;
}
......@@ -48,7 +48,7 @@ namespace adaptive
void pruneBySegmentNumber(uint64_t);
void pruneByPlaybackTime(mtime_t);
bool getSegmentNumberByScaledTime(stime_t, uint64_t *) const;
mtime_t getPlaybackTimeBySegmentNumber(uint64_t);
bool getPlaybackTimeDurationBySegmentNumber(uint64_t, mtime_t *, mtime_t *) const;
private:
std::vector<ISegment *> segments;
......
......@@ -112,9 +112,11 @@ uint64_t SegmentTimeline::getElementNumberByScaledPlaybackTime(stime_t scaled) c
return prevnumber;
}
stime_t SegmentTimeline::getScaledPlaybackTimeByElementNumber(uint64_t number) const
bool SegmentTimeline::getScaledPlaybackTimeDurationBySegmentNumber(uint64_t number,
stime_t *time, stime_t *duration) const
{
stime_t totalscaledtime = 0;
stime_t lastduration = 0;
std::list<Element *>::const_iterator it;
for(it = elements.begin(); it != elements.end(); ++it)
......@@ -127,6 +129,8 @@ stime_t SegmentTimeline::getScaledPlaybackTimeByElementNumber(uint64_t number) c
totalscaledtime = el->t;
}
lastduration = el->d;
if(number <= el->number)
break;
......@@ -139,7 +143,16 @@ stime_t SegmentTimeline::getScaledPlaybackTimeByElementNumber(uint64_t number) c
totalscaledtime += (el->d * (el->r + 1));
}
return totalscaledtime;
*time = totalscaledtime;
*duration = lastduration;
return true;
}
stime_t SegmentTimeline::getScaledPlaybackTimeByElementNumber(uint64_t number) const
{
stime_t time, duration;
(void) getScaledPlaybackTimeDurationBySegmentNumber(number, &time, &duration);
return time;
}
uint64_t SegmentTimeline::maxElementNumber() const
......
......@@ -42,6 +42,7 @@ namespace adaptive
virtual ~SegmentTimeline();
void addElement(uint64_t, stime_t d, uint64_t r = 0, stime_t t = 0);
uint64_t getElementNumberByScaledPlaybackTime(stime_t) const;
bool getScaledPlaybackTimeDurationBySegmentNumber(uint64_t, mtime_t *, mtime_t *) const;
stime_t getScaledPlaybackTimeByElementNumber(uint64_t) const;
stime_t getMinAheadScaledTime(uint64_t) const;
uint64_t maxElementNumber() const;
......
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