Skip to content

Commit

Permalink
fix(dash): Don't limit segment count for VOD.
Browse files Browse the repository at this point in the history
Fixes #2677
Issue #2709
Issue #2745

Change-Id: I06e74889d5e397639a4aea46ae6fedbfa5ee1a90
  • Loading branch information
TheModMaker committed Aug 5, 2020
1 parent 5a03835 commit c403dec
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/dash/segment_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [];
Expand Down
38 changes: 38 additions & 0 deletions test/dash/dash_parser_segment_template_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
'<SegmentTemplate media="s$Number$.mp4" duration="1" />',
]);

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([
'<SegmentTemplate media="s$Number$.mp4" duration="1" />',
], /* 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', () => {
Expand Down

0 comments on commit c403dec

Please sign in to comment.