441895be by Tom Johnson

fix bug in rendition sort algorithm to include a fallback sort by bandwidth in t…

…he case of same resolution renditions if available and add tests
1 parent a27bbe10
......@@ -73,20 +73,23 @@ var
playlistResolution = function(left, right) {
var leftWidth, rightWidth;
if(left.attributes && left.attributes.RESOLUTION && left.attributes.RESOLUTION.width) {
if (left.attributes && left.attributes.RESOLUTION && left.attributes.RESOLUTION.width) {
leftWidth = left.attributes.RESOLUTION.width;
}
leftWidth = leftWidth || window.Number.MAX_VALUE;
if(right.attributes && right.attributes.RESOLUTION && right.attributes.RESOLUTION.width) {
if (right.attributes && right.attributes.RESOLUTION && right.attributes.RESOLUTION.width) {
rightWidth = right.attributes.RESOLUTION.width;
}
rightWidth = rightWidth || window.Number.MAX_VALUE;
return leftWidth - rightWidth;
if (leftWidth === rightWidth && left.attributes.BANDWIDTH && right.attributes.BANDWIDTH) {
return left.attributes.BANDWIDTH - right.attributes.BANDWIDTH;
} else {
return leftWidth - rightWidth;
}
},
/**
......
......@@ -436,6 +436,36 @@ test('uses the lowest bitrate if no other is suitable', function() {
'the lowest bitrate stream is selected');
});
test('selects the correct rendition by player dimensions', function() {
var playlist;
player.hls('manifest/master.m3u8');
videojs.mediaSources[player.currentSrc()].trigger({
type: 'sourceopen'
});
player.width(640);
player.height(360);
player.hls.bandwidth = 3000000;
playlist = player.hls.selectPlaylist();
deepEqual(playlist.attributes.RESOLUTION, {width:396,height:224},'should return the correct resolution by player dimensions');
equal(playlist.attributes.BANDWIDTH, 440000, 'should have the expected bandwidth in case of multiple');
player.width(1920);
player.height(1080);
player.hls.bandwidth = 3000000;
playlist = player.hls.selectPlaylist();
deepEqual(playlist.attributes.RESOLUTION, {width:960,height:540},'should return the correct resolution by player dimensions');
equal(playlist.attributes.BANDWIDTH, 1928000, 'should have the expected bandwidth in case of multiple');
});
test('does not download the next segment if the buffer is full', function() {
player.hls('manifest/media.m3u8');
player.currentTime = function() {
......