Merge pull request #243 from videojs/resolution-plus-one
Resolution best variant plus one.
Showing
2 changed files
with
28 additions
and
7 deletions
... | @@ -424,7 +424,9 @@ videojs.Hls.prototype.selectPlaylist = function () { | ... | @@ -424,7 +424,9 @@ videojs.Hls.prototype.selectPlaylist = function () { |
424 | bandwidthPlaylists = [], | 424 | bandwidthPlaylists = [], |
425 | i = sortedPlaylists.length, | 425 | i = sortedPlaylists.length, |
426 | variant, | 426 | variant, |
427 | oldvariant, | ||
427 | bandwidthBestVariant, | 428 | bandwidthBestVariant, |
429 | resolutionPlusOne, | ||
428 | resolutionBestVariant; | 430 | resolutionBestVariant; |
429 | 431 | ||
430 | sortedPlaylists.sort(videojs.Hls.comparePlaylistBandwidth); | 432 | sortedPlaylists.sort(videojs.Hls.comparePlaylistBandwidth); |
... | @@ -460,6 +462,7 @@ videojs.Hls.prototype.selectPlaylist = function () { | ... | @@ -460,6 +462,7 @@ videojs.Hls.prototype.selectPlaylist = function () { |
460 | // iterate through the bandwidth-filtered playlists and find | 462 | // iterate through the bandwidth-filtered playlists and find |
461 | // best rendition by player dimension | 463 | // best rendition by player dimension |
462 | while (i--) { | 464 | while (i--) { |
465 | oldvariant = variant; | ||
463 | variant = bandwidthPlaylists[i]; | 466 | variant = bandwidthPlaylists[i]; |
464 | 467 | ||
465 | // ignore playlists without resolution information | 468 | // ignore playlists without resolution information |
... | @@ -470,18 +473,29 @@ videojs.Hls.prototype.selectPlaylist = function () { | ... | @@ -470,18 +473,29 @@ videojs.Hls.prototype.selectPlaylist = function () { |
470 | continue; | 473 | continue; |
471 | } | 474 | } |
472 | 475 | ||
476 | |||
473 | // since the playlists are sorted, the first variant that has | 477 | // since the playlists are sorted, the first variant that has |
474 | // dimensions less than or equal to the player size is the | 478 | // dimensions less than or equal to the player size is the best |
475 | // best | 479 | if (variant.attributes.RESOLUTION.width === player.width() && |
476 | if (variant.attributes.RESOLUTION.width <= player.width() && | 480 | variant.attributes.RESOLUTION.height === player.height()) { |
477 | variant.attributes.RESOLUTION.height <= player.height()) { | 481 | // if we have the exact resolution as the player use it |
482 | resolutionPlusOne = null; | ||
483 | resolutionBestVariant = variant; | ||
484 | break; | ||
485 | } else if (variant.attributes.RESOLUTION.width < player.width() && | ||
486 | variant.attributes.RESOLUTION.height < player.height()) { | ||
487 | // if we don't have an exact match, see if we have a good higher quality variant to use | ||
488 | if (oldvariant.attributes && oldvariant.attributes.RESOLUTION && | ||
489 | oldvariant.attributes.RESOLUTION.width && oldvariant.attributes.RESOLUTION.height) { | ||
490 | resolutionPlusOne = oldvariant; | ||
491 | } | ||
478 | resolutionBestVariant = variant; | 492 | resolutionBestVariant = variant; |
479 | break; | 493 | break; |
480 | } | 494 | } |
481 | } | 495 | } |
482 | 496 | ||
483 | // fallback chain of variants | 497 | // fallback chain of variants |
484 | return resolutionBestVariant || bandwidthBestVariant || sortedPlaylists[0]; | 498 | return resolutionPlusOne || resolutionBestVariant || bandwidthBestVariant || sortedPlaylists[0]; |
485 | }; | 499 | }; |
486 | 500 | ||
487 | /** | 501 | /** | ... | ... |
... | @@ -831,8 +831,8 @@ test('selects the correct rendition by player dimensions', function() { | ... | @@ -831,8 +831,8 @@ test('selects the correct rendition by player dimensions', function() { |
831 | 831 | ||
832 | playlist = player.hls.selectPlaylist(); | 832 | playlist = player.hls.selectPlaylist(); |
833 | 833 | ||
834 | deepEqual(playlist.attributes.RESOLUTION, {width:396,height:224},'should return the correct resolution by player dimensions'); | 834 | deepEqual(playlist.attributes.RESOLUTION, {width:960,height:540},'should return the correct resolution by player dimensions'); |
835 | equal(playlist.attributes.BANDWIDTH, 440000, 'should have the expected bandwidth in case of multiple'); | 835 | equal(playlist.attributes.BANDWIDTH, 1928000, 'should have the expected bandwidth in case of multiple'); |
836 | 836 | ||
837 | player.width(1920); | 837 | player.width(1920); |
838 | player.height(1080); | 838 | player.height(1080); |
... | @@ -843,6 +843,13 @@ test('selects the correct rendition by player dimensions', function() { | ... | @@ -843,6 +843,13 @@ test('selects the correct rendition by player dimensions', function() { |
843 | deepEqual(playlist.attributes.RESOLUTION, {width:960,height:540},'should return the correct resolution by player dimensions'); | 843 | deepEqual(playlist.attributes.RESOLUTION, {width:960,height:540},'should return the correct resolution by player dimensions'); |
844 | equal(playlist.attributes.BANDWIDTH, 1928000, 'should have the expected bandwidth in case of multiple'); | 844 | equal(playlist.attributes.BANDWIDTH, 1928000, 'should have the expected bandwidth in case of multiple'); |
845 | 845 | ||
846 | player.width(396); | ||
847 | player.height(224); | ||
848 | playlist = player.hls.selectPlaylist(); | ||
849 | |||
850 | deepEqual(playlist.attributes.RESOLUTION, {width:396,height:224},'should return the correct resolution by player dimensions, if exact match'); | ||
851 | equal(playlist.attributes.BANDWIDTH, 440000, 'should have the expected bandwidth in case of multiple, if exact match'); | ||
852 | |||
846 | }); | 853 | }); |
847 | 854 | ||
848 | 855 | ... | ... |
-
Please register or sign in to post a comment