Guard against negative media index due to manifest vs actual timing differences (#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
Showing
2 changed files
with
22 additions
and
5 deletions
... | @@ -264,6 +264,10 @@ export const getMediaIndexForTime_ = function(playlist, time, expired) { | ... | @@ -264,6 +264,10 @@ export const getMediaIndexForTime_ = function(playlist, time, expired) { |
264 | return 0; | 264 | return 0; |
265 | } | 265 | } |
266 | 266 | ||
267 | if (time === 0 && !expired) { | ||
268 | return 0; | ||
269 | } | ||
270 | |||
267 | expired = expired || 0; | 271 | expired = expired || 0; |
268 | 272 | ||
269 | // find segments with known timing information that bound the | 273 | // find segments with known timing information that bound the | ... | ... |
... | @@ -468,11 +468,6 @@ function() { | ... | @@ -468,11 +468,6 @@ function() { |
468 | media = loader.media(); | 468 | media = loader.media(); |
469 | 469 | ||
470 | QUnit.equal( | 470 | QUnit.equal( |
471 | Playlist.getMediaIndexForTime_(media, 0), | ||
472 | -1, | ||
473 | 'the lowest returned value is negative one' | ||
474 | ); | ||
475 | QUnit.equal( | ||
476 | Playlist.getMediaIndexForTime_(media, 45), | 471 | Playlist.getMediaIndexForTime_(media, 45), |
477 | -1, | 472 | -1, |
478 | 'expired content returns negative one' | 473 | 'expired content returns negative one' |
... | @@ -483,6 +478,11 @@ function() { | ... | @@ -483,6 +478,11 @@ function() { |
483 | 'expired content returns negative one' | 478 | 'expired content returns negative one' |
484 | ); | 479 | ); |
485 | QUnit.equal( | 480 | QUnit.equal( |
481 | Playlist.getMediaIndexForTime_(media, 0), | ||
482 | 0, | ||
483 | 'time of 0 with no expired time returns first segment' | ||
484 | ); | ||
485 | QUnit.equal( | ||
486 | Playlist.getMediaIndexForTime_(media, 50 + 100), | 486 | Playlist.getMediaIndexForTime_(media, 50 + 100), |
487 | 0, | 487 | 0, |
488 | 'calculates the earliest available position' | 488 | 'calculates the earliest available position' |
... | @@ -628,3 +628,16 @@ QUnit.test('accounts for expired time when calculating media index', function() | ... | @@ -628,3 +628,16 @@ QUnit.test('accounts for expired time when calculating media index', function() |
628 | 'calculates within the second segment' | 628 | 'calculates within the second segment' |
629 | ); | 629 | ); |
630 | }); | 630 | }); |
631 | |||
632 | QUnit.test('returns index 0 when time is 0 and expired is falsy', function() { | ||
633 | QUnit.equal( | ||
634 | Playlist.getMediaIndexForTime_({segments: []}, 0, 0), | ||
635 | 0, | ||
636 | 'returns 0 when time is 0 and expired is 0' | ||
637 | ); | ||
638 | QUnit.equal( | ||
639 | Playlist.getMediaIndexForTime_({segments: []}, 0), | ||
640 | 0, | ||
641 | 'returns 0 when time is 0 and expired is undefined' | ||
642 | ); | ||
643 | }); | ... | ... |
-
Please register or sign in to post a comment