Skip to content

Commit

Permalink
fix: seeking in segment timeline returns incorrect index (#5716)
Browse files Browse the repository at this point in the history
Resolves #5664
  • Loading branch information
littlespex authored and joeyparrish committed Oct 4, 2023
1 parent b96d53c commit 15b8da0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/media/segment_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ shaka.media.MetaSegmentIndex = class extends shaka.media.SegmentIndex {
}

numPassedInEarlierIndexes += index.numEvicted_ +
index.references.length;
index.getNumReferences();
}

return null;
Expand All @@ -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;
Expand Down
42 changes: 42 additions & 0 deletions test/dash/dash_parser_segment_template_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,48 @@ describe('DashParser SegmentTemplate', () => {
expect(pos).toBe(1);
});

it('finds correct position in multiperiod content', async () => {
const source = [
'<MPD type="static" availabilityStartTime="1970-01-01T00:00:00Z">',
' <Period duration="PT30S">',
' <AdaptationSet mimeType="video/mp4">',
' <Representation bandwidth="500">',
' <BaseURL>http://example.com</BaseURL>',
' <SegmentTemplate startNumber="0"',
' media="$Number$-$Time$-$Bandwidth$.mp4">',
' <SegmentTimeline>',
' <S t="0" d="5" r="6" />',
' </SegmentTimeline>',
' </SegmentTemplate>',
' </Representation>',
' </AdaptationSet>',
' </Period>',
' <Period duration="PT30S">',
' <AdaptationSet mimeType="video/mp4">',
' <Representation bandwidth="500">',
' <BaseURL>http://example.com</BaseURL>',
' <SegmentTemplate startNumber="6"',
' media="$Number$-$Time$-$Bandwidth$.mp4">',
' <SegmentTimeline>',
' <S t="0" d="5" r="6" />',
' </SegmentTimeline>',
' </SegmentTemplate>',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].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));
Expand Down

0 comments on commit 15b8da0

Please sign in to comment.