Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segment availability range if no timeShiftBufferDepth #3294

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);