229bae7e by Gary Katsevman

Resolution best variant plus one.

If we have a perfect resolution match for playlist and player, use that
playlist. Otherwise, get the next highest resolution matched playlist,
even if bigger than the player.
1 parent 021896e3
...@@ -426,7 +426,10 @@ videojs.Hls.prototype.selectPlaylist = function () { ...@@ -426,7 +426,10 @@ videojs.Hls.prototype.selectPlaylist = function () {
426 bandwidthPlaylists = [], 426 bandwidthPlaylists = [],
427 i = sortedPlaylists.length, 427 i = sortedPlaylists.length,
428 variant, 428 variant,
429 oldvariant,
430 ret,
429 bandwidthBestVariant, 431 bandwidthBestVariant,
432 resolutionPlusOne,
430 resolutionBestVariant; 433 resolutionBestVariant;
431 434
432 sortedPlaylists.sort(videojs.Hls.comparePlaylistBandwidth); 435 sortedPlaylists.sort(videojs.Hls.comparePlaylistBandwidth);
...@@ -462,6 +465,7 @@ videojs.Hls.prototype.selectPlaylist = function () { ...@@ -462,6 +465,7 @@ videojs.Hls.prototype.selectPlaylist = function () {
462 // iterate through the bandwidth-filtered playlists and find 465 // iterate through the bandwidth-filtered playlists and find
463 // best rendition by player dimension 466 // best rendition by player dimension
464 while (i--) { 467 while (i--) {
468 oldvariant = variant;
465 variant = bandwidthPlaylists[i]; 469 variant = bandwidthPlaylists[i];
466 470
467 // ignore playlists without resolution information 471 // ignore playlists without resolution information
...@@ -472,18 +476,29 @@ videojs.Hls.prototype.selectPlaylist = function () { ...@@ -472,18 +476,29 @@ videojs.Hls.prototype.selectPlaylist = function () {
472 continue; 476 continue;
473 } 477 }
474 478
479
475 // since the playlists are sorted, the first variant that has 480 // since the playlists are sorted, the first variant that has
476 // dimensions less than or equal to the player size is the 481 // dimensions less than or equal to the player size is the best
477 // best 482 if (variant.attributes.RESOLUTION.width === player.width() &&
478 if (variant.attributes.RESOLUTION.width <= player.width() && 483 variant.attributes.RESOLUTION.height === player.height()) {
479 variant.attributes.RESOLUTION.height <= player.height()) { 484 // if we have the exact resolution as the player use it
485 resolutionPlusOne = null;
486 resolutionBestVariant = variant;
487 break;
488 } else if (variant.attributes.RESOLUTION.width < player.width() &&
489 variant.attributes.RESOLUTION.height < player.height()) {
490 // if we don't have an exact match, see if we have a good higher quality variant to use
491 if (oldvariant.attributes && oldvariant.attributes.RESOLUTION &&
492 oldvariant.attributes.RESOLUTION.width && oldvariant.attributes.RESOLUTION.height) {
493 resolutionPlusOne = oldvariant;
494 }
480 resolutionBestVariant = variant; 495 resolutionBestVariant = variant;
481 break; 496 break;
482 } 497 }
483 } 498 }
484 499
485 // fallback chain of variants 500 // fallback chain of variants
486 return resolutionBestVariant || bandwidthBestVariant || sortedPlaylists[0]; 501 return resolutionPlusOne || resolutionBestVariant || bandwidthBestVariant || sortedPlaylists[0];
487 }; 502 };
488 503
489 /** 504 /**
......