diff --git a/modules/demux/adaptive/SegmentTracker.cpp b/modules/demux/adaptive/SegmentTracker.cpp index 118a41796c3ddcd86c4c62cce49ddbf89bc4b0bf..e0d209b67d3f4cc28f03425eab0c9d88cafba89d 100644 --- a/modules/demux/adaptive/SegmentTracker.cpp +++ b/modules/demux/adaptive/SegmentTracker.cpp @@ -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 diff --git a/modules/demux/adaptive/playlist/SegmentInformation.cpp b/modules/demux/adaptive/playlist/SegmentInformation.cpp index e1a65a071b99098f360a423d13c6411889ec160b..51e33a0ec1fcf1de19eae931c49ffabb95ee49d9 100644 --- a/modules/demux/adaptive/playlist/SegmentInformation.cpp +++ b/modules/demux/adaptive/playlist/SegmentInformation.cpp @@ -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; } diff --git a/modules/demux/adaptive/playlist/SegmentInformation.hpp b/modules/demux/adaptive/playlist/SegmentInformation.hpp index 859af0051497e7e931ab0d43cdbb5e6730cfdcd2..428407629b2ab83edeab909a8a63aaae48b6afcc 100644 --- a/modules/demux/adaptive/playlist/SegmentInformation.hpp +++ b/modules/demux/adaptive/playlist/SegmentInformation.hpp @@ -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 */ diff --git a/modules/demux/adaptive/playlist/SegmentList.cpp b/modules/demux/adaptive/playlist/SegmentList.cpp index 3b8ef818e758fb73666558fd3c3a7aa1535e3785..dd3703657927e5020605dfe89c562c436bf09496 100644 --- a/modules/demux/adaptive/playlist/SegmentList.cpp +++ b/modules/demux/adaptive/playlist/SegmentList.cpp @@ -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; } diff --git a/modules/demux/adaptive/playlist/SegmentList.h b/modules/demux/adaptive/playlist/SegmentList.h index 879f1e4b0141209576c16c5e95ccceebbb6ad33b..815daebb78587e335b67f2d1f035b447d866d3c9 100644 --- a/modules/demux/adaptive/playlist/SegmentList.h +++ b/modules/demux/adaptive/playlist/SegmentList.h @@ -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; diff --git a/modules/demux/adaptive/playlist/SegmentTimeline.cpp b/modules/demux/adaptive/playlist/SegmentTimeline.cpp index c8f66323d7956285505284201c290e2ff6521743..dc6a9a10b561cdd62b0b72acff4d0608660268ea 100644 --- a/modules/demux/adaptive/playlist/SegmentTimeline.cpp +++ b/modules/demux/adaptive/playlist/SegmentTimeline.cpp @@ -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 diff --git a/modules/demux/adaptive/playlist/SegmentTimeline.h b/modules/demux/adaptive/playlist/SegmentTimeline.h index 2bfc04939dacfa260f9ac622119bf12ba699d590..4094963bf24461d923d5ae251fed0d11c2f7a633 100644 --- a/modules/demux/adaptive/playlist/SegmentTimeline.h +++ b/modules/demux/adaptive/playlist/SegmentTimeline.h @@ -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;