Skip to content

Commit

Permalink
Calculate segment availability range according to effective segment t…
Browse files Browse the repository at this point in the history
…imeline if timeShiftBufferDepth is not defined (#3294)
  • Loading branch information
Bertrand Berthelot committed Jun 25, 2020
1 parent 3a27c93 commit dea628c
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions src/dash/utils/TimelineConverter.js
Expand Up @@ -31,17 +31,25 @@
import EventBus from '../../core/EventBus';
import Events from '../../core/events/Events';
import FactoryMaker from '../../core/FactoryMaker';
import DashConstants from '../constants/DashConstants';
import DashManifestModel from '../models/DashManifestModel';

function TimelineConverter() {

let context = this.context;
let eventBus = EventBus(context).getInstance();
const context = this.context;
const eventBus = EventBus(context).getInstance();

let instance,
dashManifestModel,
clientServerTimeShift,
isClientServerTimeSyncCompleted,
expectedLiveEdge;

function setup() {
dashManifestModel = DashManifestModel(context).getInstance();
reset();
}

function initialize() {
resetInitialSettings();
eventBus.on(Events.TIME_SYNCHRONIZATION_COMPLETED, onTimeSyncComplete, this);
Expand Down Expand Up @@ -147,6 +155,12 @@ function TimelineConverter() {

// Dynamic Range Finder
const d = voRepresentation.segmentDuration || (voRepresentation.segments && voRepresentation.segments.length ? voRepresentation.segments[voRepresentation.segments.length - 1].duration : 0);

// Specific use case of SegmentTimeline without timeShiftBufferDepth
if (voRepresentation.segmentInfoType === DashConstants.SEGMENT_TIMELINE && voPeriod.mpd.timeShiftBufferDepth === Number.POSITIVE_INFINITY) {
return calcSegmentAvailabilityRangeFromTimeline(voRepresentation);
}

const now = calcPresentationTimeFromWallTime(new Date(), voPeriod);
const periodEnd = voPeriod.start + voPeriod.duration;
range.start = Math.max((now - voPeriod.mpd.timeShiftBufferDepth), voPeriod.start);
Expand All @@ -159,6 +173,36 @@ function TimelineConverter() {
return range;
}

function calcSegmentAvailabilityRangeFromTimeline(voRepresentation) {
const adaptation = voRepresentation.adaptation.period.mpd.manifest.Period_asArray[voRepresentation.adaptation.period.index].AdaptationSet_asArray[voRepresentation.adaptation.index];
const representation = dashManifestModel.getRepresentationFor(voRepresentation.index, adaptation);

const timeline = representation.SegmentTemplate.SegmentTimeline;
const timescale = representation.SegmentTemplate.timescale;
const segments = timeline.S_asArray;
const range = { start: 0, end: 0 };
let d = 0;
let segment,
repeat,
i,
len;

range.start = segments[0].t / timescale;

for (i = 0, len = segments.length; i < len; i++) {
segment = segments[i];
repeat = 0;
if (segment.hasOwnProperty('r')) {
repeat = segment.r;
}
d += (segment.d / timescale) * (1 + repeat);
}

range.end = range.start + d;

return range;
}

function getPeriodEnd(voRepresentation, isDynamic) {
// Static Range Finder
const voPeriod = voRepresentation.adaptation.period;
Expand Down Expand Up @@ -232,8 +276,9 @@ function TimelineConverter() {
reset: reset
};

setup();
return instance;
}

TimelineConverter.__dashjs_factory_name = 'TimelineConverter';
export default FactoryMaker.getSingletonFactory(TimelineConverter);
export default FactoryMaker.getSingletonFactory(TimelineConverter);

0 comments on commit dea628c

Please sign in to comment.