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 ...@@ -73,20 +73,23 @@ var
73 playlistResolution = function(left, right) { 73 playlistResolution = function(left, right) {
74 var leftWidth, rightWidth; 74 var leftWidth, rightWidth;
75 75
76 if(left.attributes && left.attributes.RESOLUTION && left.attributes.RESOLUTION.width) { 76 if (left.attributes && left.attributes.RESOLUTION && left.attributes.RESOLUTION.width) {
77 leftWidth = left.attributes.RESOLUTION.width; 77 leftWidth = left.attributes.RESOLUTION.width;
78 } 78 }
79 79
80 leftWidth = leftWidth || window.Number.MAX_VALUE; 80 leftWidth = leftWidth || window.Number.MAX_VALUE;
81 81
82 if(right.attributes && right.attributes.RESOLUTION && right.attributes.RESOLUTION.width) { 82 if (right.attributes && right.attributes.RESOLUTION && right.attributes.RESOLUTION.width) {
83 rightWidth = right.attributes.RESOLUTION.width; 83 rightWidth = right.attributes.RESOLUTION.width;
84 } 84 }
85 85
86 rightWidth = rightWidth || window.Number.MAX_VALUE; 86 rightWidth = rightWidth || window.Number.MAX_VALUE;
87 87
88 if (leftWidth === rightWidth && left.attributes.BANDWIDTH && right.attributes.BANDWIDTH) {
89 return left.attributes.BANDWIDTH - right.attributes.BANDWIDTH;
90 } else {
88 return leftWidth - rightWidth; 91 return leftWidth - rightWidth;
89 92 }
90 }, 93 },
91 94
92 /** 95 /**
......
...@@ -436,6 +436,36 @@ test('uses the lowest bitrate if no other is suitable', function() { ...@@ -436,6 +436,36 @@ test('uses the lowest bitrate if no other is suitable', function() {
436 'the lowest bitrate stream is selected'); 436 'the lowest bitrate stream is selected');
437 }); 437 });
438 438
439 test('selects the correct rendition by player dimensions', function() {
440 var playlist;
441
442 player.hls('manifest/master.m3u8');
443
444 videojs.mediaSources[player.currentSrc()].trigger({
445 type: 'sourceopen'
446 });
447
448 player.width(640);
449 player.height(360);
450 player.hls.bandwidth = 3000000;
451
452 playlist = player.hls.selectPlaylist();
453
454 deepEqual(playlist.attributes.RESOLUTION, {width:396,height:224},'should return the correct resolution by player dimensions');
455 equal(playlist.attributes.BANDWIDTH, 440000, 'should have the expected bandwidth in case of multiple');
456
457 player.width(1920);
458 player.height(1080);
459 player.hls.bandwidth = 3000000;
460
461 playlist = player.hls.selectPlaylist();
462
463 deepEqual(playlist.attributes.RESOLUTION, {width:960,height:540},'should return the correct resolution by player dimensions');
464 equal(playlist.attributes.BANDWIDTH, 1928000, 'should have the expected bandwidth in case of multiple');
465
466 });
467
468
439 test('does not download the next segment if the buffer is full', function() { 469 test('does not download the next segment if the buffer is full', function() {
440 player.hls('manifest/media.m3u8'); 470 player.hls('manifest/media.m3u8');
441 player.currentTime = function() { 471 player.currentTime = function() {
......