Skip to content

Commit

Permalink
Fix: Allow the playback whenever the t attribute is missing in the Se…
Browse files Browse the repository at this point in the history
…gmentTimeline elements (#4174)

* fix: Allow the playback whenever the t attribute is missing

* fix: Make use of Segments in SegmentTimeline instead of timeShiftBufferDepth
  • Loading branch information
dario-fiore committed Apr 25, 2023
1 parent eb91e6b commit 377d60a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
15 changes: 10 additions & 5 deletions src/dash/utils/TimelineConverter.js
Expand Up @@ -229,7 +229,7 @@ function TimelineConverter() {
const range = { start: NaN, end: NaN };
const voPeriod = streams[0].getAdapter().getRegularPeriods()[0];
const now = calcPresentationTimeFromWallTime(new Date(), voPeriod);

if (!streams || streams.length === 0) {
return { range, now };
}
Expand Down Expand Up @@ -317,14 +317,19 @@ function TimelineConverter() {
const timescale = representation.SegmentTemplate.timescale;
const segments = timeline.S_asArray;
const range = { start: 0, end: 0 };
const segmentTime = segments[0].t;
const hasValidSegmentTime = !isNaN(segmentTime);
const enhancedSegmentTime = hasValidSegmentTime ? segmentTime : 0;
let d = 0;
let segment,
repeat,
i,
len;

range.start = calcPresentationTimeFromMediaTime(segments[0].t / timescale, voRepresentation);


if(hasValidSegmentTime) {
range.start = calcPresentationTimeFromMediaTime(enhancedSegmentTime / timescale, voRepresentation);
}

for (i = 0, len = segments.length; i < len; i++) {
segment = segments[i];
repeat = 0;
Expand All @@ -334,7 +339,7 @@ function TimelineConverter() {
d += segment.d * (1 + repeat);
}

range.end = calcPresentationTimeFromMediaTime((segments[0].t + d) / timescale, voRepresentation);
range.end = calcPresentationTimeFromMediaTime((enhancedSegmentTime + d) / timescale, voRepresentation);

return range;
}
Expand Down
41 changes: 37 additions & 4 deletions test/unit/dash.utils.TimelineConverter.js
Expand Up @@ -52,7 +52,7 @@ describe('TimelineConverter', function () {
timeShiftBuffer: {
calcFromSegmentTimeline: false
}
}
}
});
});

Expand Down Expand Up @@ -114,7 +114,7 @@ describe('TimelineConverter', function () {

beforeEach(function () {
representation.adaptation.period.mpd.manifest.type = 'dynamic';
});
});


describe('SegmentTemplate and ', function () {
Expand Down Expand Up @@ -861,8 +861,8 @@ describe('TimelineConverter', function () {
const clock = sinon.useFakeTimers(new Date().getTime());
const tsbd = 30;
const dummyRep = voHelper.getDummyTimelineRepresentation(testType);

dummyRep.adaptation.period.start = 0;
dummyRep.adaptation.period.start = 0;
dummyRep.adaptation.period.duration = 300;
streamOneMock.setRepresentation(dummyRep);

Expand Down Expand Up @@ -992,6 +992,39 @@ describe('TimelineConverter', function () {
clock.restore();
});

it('with single period with segements without t attribute', function () {
const clock = sinon.useFakeTimers(new Date().getTime());
const tsbd = 30;
const dummyRep = voHelper.getDummyTimelineRepresentation(testType);

// Remove t attribute(s) from segments
delete dummyRep.adaptation.period.mpd.manifest.Period_asArray[0].AdaptationSet_asArray[0].SegmentTemplate.SegmentTimeline_asArray.S_asArray[0].t
delete dummyRep.adaptation.period.mpd.manifest.Period_asArray[0].AdaptationSet_asArray[0].SegmentTemplate.SegmentTimeline.S_asArray[0].t
delete dummyRep.adaptation.period.mpd.manifest.Period_asArray[0].AdaptationSet_asArray[0].SegmentTemplate_asArray.SegmentTimeline_asArray.S_asArray[0].t
delete dummyRep.adaptation.period.mpd.manifest.Period_asArray[0].AdaptationSet_asArray[0].SegmentTemplate_asArray.SegmentTimeline.S_asArray[0].t

dummyRep.adaptation.period.start = 0;
dummyRep.adaptation.period.duration = Number.POSITIVE_INFINITY;;
streamOneMock.setRepresentation(dummyRep);

streamOneMock.setStreamInfo({
start: 0,
duration: Number.POSITIVE_INFINITY
});
streamOneMock.setRegularPeriods([{
mpd: {
availabilityStartTime: new Date(new Date().getTime() - tsbd * 1000),
timeShiftBufferDepth: tsbd
}
}]);
streams.push(streamOneMock);

const range = timelineConverter.calcTimeShiftBufferWindow(streams, true);
expect(range.start).to.be.equal(0);
expect(range.end).to.be.equal(30);
clock.restore();
});

it('with two periods covering whole tsbd', function () {
const clock = sinon.useFakeTimers(new Date().getTime());
const tsbd = 30;
Expand Down

0 comments on commit 377d60a

Please sign in to comment.