From 15b8da05aa70ae73957c68d00c78528a0ec7deb9 Mon Sep 17 00:00:00 2001 From: Casey Occhialini <1508707+littlespex@users.noreply.github.com> Date: Tue, 3 Oct 2023 16:37:59 -0700 Subject: [PATCH] fix: seeking in segment timeline returns incorrect index (#5716) Resolves #5664 --- lib/media/segment_index.js | 8 ++-- .../dash/dash_parser_segment_template_unit.js | 42 +++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/lib/media/segment_index.js b/lib/media/segment_index.js index 11d575ca6e..832c8a566c 100644 --- a/lib/media/segment_index.js +++ b/lib/media/segment_index.js @@ -708,7 +708,7 @@ shaka.media.MetaSegmentIndex = class extends shaka.media.SegmentIndex { } numPassedInEarlierIndexes += index.numEvicted_ + - index.references.length; + index.getNumReferences(); } return null; @@ -732,9 +732,9 @@ shaka.media.MetaSegmentIndex = class extends shaka.media.SegmentIndex { return reference; } - numPassedInEarlierIndexes += index.numEvicted_ + - index.references.length; - sawSegments = sawSegments || index.references.length != 0; + const num = index.getNumReferences(); + numPassedInEarlierIndexes += index.numEvicted_ + num; + sawSegments = sawSegments || num != 0; } return null; diff --git a/test/dash/dash_parser_segment_template_unit.js b/test/dash/dash_parser_segment_template_unit.js index b456c7b387..3fa3e83408 100644 --- a/test/dash/dash_parser_segment_template_unit.js +++ b/test/dash/dash_parser_segment_template_unit.js @@ -675,6 +675,48 @@ describe('DashParser SegmentTemplate', () => { expect(pos).toBe(1); }); + it('finds correct position in multiperiod content', async () => { + const source = [ + '', + ' ', + ' ', + ' ', + ' http://example.com', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' http://example.com', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + '', + ].join('\n'); + + fakeNetEngine.setResponseText('dummy://foo', source); + const manifest = await parser.start('dummy://foo', playerInterface); + const stream = manifest.variants[0].video; + await stream.createSegmentIndex(); + + // simulate a seek into the second period + const segmentIterator = stream.segmentIndex.getIteratorForTime(42); + const ref = segmentIterator.next().value; + expect(ref.startTime).toBe(40); + }); it('returns null if time === last end time', async () => { const info = makeTemplateInfo(makeRanges(0, 2.0, 2));