diff --git a/lib/dash/segment_template.js b/lib/dash/segment_template.js index 1d9aa83a78..95a15237f7 100644 --- a/lib/dash/segment_template.js +++ b/lib/dash/segment_template.js @@ -273,7 +273,7 @@ shaka.dash.SegmentTemplate = class { const presentationTimeline = context.presentationTimeline; - // Capture valutes that could change as the parsing context moves on to + // Capture values that could change as the parsing context moves on to // other parts of the manifest. const periodStart = context.periodInfo.start; const periodDuration = context.periodInfo.duration; @@ -341,11 +341,14 @@ shaka.dash.SegmentTemplate = class { return availablePresentationPositions; }; - // We must limit the initial SegmentIndex in size, to avoid consuming too - // much CPU or memory for content with gigantic timeShiftBufferDepth (which - // can have values up to and including Infinity). + // For Live, we must limit the initial SegmentIndex in size, to avoid + // consuming too much CPU or memory for content with gigantic + // timeShiftBufferDepth (which can have values up to and including + // Infinity). const range = computeAvailablePositionRange(); - const minPosition = Math.max(range[0], range[1] - segmentLimit); + const minPosition = context.dynamic ? + Math.max(range[0], range[1] - segmentLimit + 1) : + range[0]; const maxPosition = range[1]; const references = []; diff --git a/test/dash/dash_parser_segment_template_unit.js b/test/dash/dash_parser_segment_template_unit.js index 47328d5cf3..13a189a536 100644 --- a/test/dash/dash_parser_segment_template_unit.js +++ b/test/dash/dash_parser_segment_template_unit.js @@ -129,6 +129,44 @@ describe('DashParser SegmentTemplate', () => { const manifest = await parser.start('dummy://foo', playerInterface); expect(manifest.presentationTimeline.getSeekRangeStart()).toBe(30); }); + + it('limits segment count for Live', async () => { + const source = Dash.makeSimpleManifestText([ + '', + ]); + + const config = shaka.util.PlayerConfiguration.createDefault().manifest; + config.dash.initialSegmentLimit = 100; + parser.configure(config); + + fakeNetEngine.setResponseText('dummy://foo', source); + const manifest = await parser.start('dummy://foo', playerInterface); + const stream = manifest.variants[0].video; + await stream.createSegmentIndex(); + goog.asserts.assert(stream.segmentIndex, 'Should have created index'); + + const segments = Array.from(stream.segmentIndex); + expect(segments.length).toBe(config.dash.initialSegmentLimit); + }); + + it('doesn\'t limit segment count for VOD', async () => { + const source = Dash.makeSimpleManifestText([ + '', + ], /* duration= */ 200); + + const config = shaka.util.PlayerConfiguration.createDefault().manifest; + config.dash.initialSegmentLimit = 100; + parser.configure(config); + + fakeNetEngine.setResponseText('dummy://foo', source); + const manifest = await parser.start('dummy://foo', playerInterface); + const stream = manifest.variants[0].video; + await stream.createSegmentIndex(); + goog.asserts.assert(stream.segmentIndex, 'Should have created index'); + + const segments = Array.from(stream.segmentIndex); + expect(segments.length).toBe(200); + }); }); describe('index', () => {