From 71a0f637eddc94949edfdaffdd27f813061b814f Mon Sep 17 00:00:00 2001 From: Casey Occhialini <1508707+littlespex@users.noreply.github.com> Date: Tue, 3 Oct 2023 10:36:32 -0700 Subject: [PATCH 1/2] fix: seeking in segment timeline returns incorrect index --- lib/media/segment_index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/media/segment_index.js b/lib/media/segment_index.js index ccde226551..ee763bd416 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; @@ -733,7 +733,7 @@ shaka.media.MetaSegmentIndex = class extends shaka.media.SegmentIndex { } numPassedInEarlierIndexes += index.numEvicted_ + - index.references.length; + index.getNumReferences(); sawSegments = sawSegments || index.references.length != 0; } From 102e8ec9d67ef0dba3a2bee4f8807b03ed9349c1 Mon Sep 17 00:00:00 2001 From: Casey Occhialini <1508707+littlespex@users.noreply.github.com> Date: Tue, 3 Oct 2023 13:15:22 -0700 Subject: [PATCH 2/2] chore: add regression test --- lib/media/segment_index.js | 6 +-- .../dash/dash_parser_segment_template_unit.js | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/lib/media/segment_index.js b/lib/media/segment_index.js index ee763bd416..13475555f8 100644 --- a/lib/media/segment_index.js +++ b/lib/media/segment_index.js @@ -732,9 +732,9 @@ shaka.media.MetaSegmentIndex = class extends shaka.media.SegmentIndex { return reference; } - numPassedInEarlierIndexes += index.numEvicted_ + - index.getNumReferences(); - 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 cbf0ac6d59..6906ab5296 100644 --- a/test/dash/dash_parser_segment_template_unit.js +++ b/test/dash/dash_parser_segment_template_unit.js @@ -677,6 +677,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));