Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Commit

Permalink
Guard against negative media index due to manifest vs actual timing d…
Browse files Browse the repository at this point in the history
…ifferences (#794)

* Guard against negative media index due to manifest vs actual timing differences
One of the possible reasons for us getting a negative media index is that we've recorded actual segment timing information and it differs enough from the manifest's timing information that we can't properly place the first segment. In the event that we're at time 0 and the video isn't live, we can safely assume that we should get the first segment.

* Change getMediaIndexForTime to return first segment when time and expired are 0
  • Loading branch information
gesinger authored and imbcmdth committed Jul 25, 2016
1 parent f8af9a2 commit 23bf150
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ export const getMediaIndexForTime_ = function(playlist, time, expired) {
return 0;
}

if (time === 0 && !expired) {
return 0;
}

expired = expired || 0;

// find segments with known timing information that bound the
Expand Down
23 changes: 18 additions & 5 deletions test/playlist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,6 @@ function() {

media = loader.media();

QUnit.equal(
Playlist.getMediaIndexForTime_(media, 0),
-1,
'the lowest returned value is negative one'
);
QUnit.equal(
Playlist.getMediaIndexForTime_(media, 45),
-1,
Expand All @@ -482,6 +477,11 @@ function() {
-1,
'expired content returns negative one'
);
QUnit.equal(
Playlist.getMediaIndexForTime_(media, 0),
0,
'time of 0 with no expired time returns first segment'
);
QUnit.equal(
Playlist.getMediaIndexForTime_(media, 50 + 100),
0,
Expand Down Expand Up @@ -628,3 +628,16 @@ QUnit.test('accounts for expired time when calculating media index', function()
'calculates within the second segment'
);
});

QUnit.test('returns index 0 when time is 0 and expired is falsy', function() {
QUnit.equal(
Playlist.getMediaIndexForTime_({segments: []}, 0, 0),
0,
'returns 0 when time is 0 and expired is 0'
);
QUnit.equal(
Playlist.getMediaIndexForTime_({segments: []}, 0),
0,
'returns 0 when time is 0 and expired is undefined'
);
});

0 comments on commit 23bf150

Please sign in to comment.