Skip to content

Commit

Permalink
fix(Prefetch): Ensure prefetched segments are continuous (shaka-proje…
Browse files Browse the repository at this point in the history
  • Loading branch information
tykus160 authored Jun 25, 2024
1 parent b5f1ee9 commit db679e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/media/segment_prefetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,14 @@ shaka.media.SegmentPrefetch = class {
shaka.log.debug(logPrefix, 'missing iterator');
return;
}
let reference = this.iterator_.next().value;
if (skipFirst) {
reference = this.iterator_.next().value;
this.iterator_.next();
}
if (!reference) {
return;
}
while (this.segmentPrefetchMap_.size < this.prefetchLimit_ &&
reference != null) {
while (this.segmentPrefetchMap_.size < this.prefetchLimit_) {
const reference = this.iterator_.next().value;
if (!reference) {
break;
}
// By default doesn't prefech preload partial segments when using
// byterange
let prefetchAllowed = true;
Expand All @@ -125,7 +124,6 @@ shaka.media.SegmentPrefetch = class {
reference.isLastPartial()) {
break;
}
reference = this.iterator_.next().value;
}
this.clearInitSegments_();
}
Expand Down
20 changes: 20 additions & 0 deletions test/media/segment_prefetch_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@ describe('SegmentPrefetch', () => {
expect(op).toBeNull();
await expectSegmentsPrefetched(1);
});

it('properly iterates on subsequent prefetchSegments calls', async () => {
segmentPrefetch.resetLimit(1);
segmentPrefetch.prefetchSegmentsByTime(references[0].startTime);
let op = segmentPrefetch.getPrefetchedSegment(references[1]);
expect(op).toBeNull();
await expectSegmentsPrefetched(0, 1);

// Evict our only one prefetched segment.
segmentPrefetch.evict(references[1].endTime);
op = segmentPrefetch.getPrefetchedSegment(references[0]);
expect(op).toBeNull();

// Underlying iterator should traverse to next element, regardless
// of specified time.
segmentPrefetch.prefetchSegmentsByTime(references[0].startTime);
op = segmentPrefetch.getPrefetchedSegment(references[0]);
expect(op).toBeNull();
await expectSegmentsPrefetched(1, 1);
});
});

describe('clearAll', () => {
Expand Down

0 comments on commit db679e0

Please sign in to comment.