17f9278f by David LaPalomento

Merge pull request #180 from videojs/dont-downshift

Don't downshift in smart shifting.
2 parents 4b0e7317 35f858f4
......@@ -109,7 +109,7 @@ videojs.Hls.prototype.handleSourceOpen = function() {
this.playlists = new videojs.Hls.PlaylistLoader(this.src_, settings.withCredentials);
this.playlists.on('loadedmetadata', videojs.bind(this, function() {
var selectedPlaylist, loaderHandler, newBitrate, segmentDuration,
var selectedPlaylist, loaderHandler, oldBitrate, newBitrate, segmentDuration,
segmentDlTime, setupEvents, threshold;
setupEvents = function() {
......@@ -127,8 +127,10 @@ videojs.Hls.prototype.handleSourceOpen = function() {
oldMediaPlaylist = this.playlists.media();
this.bandwidth = this.playlists.bandwidth;
selectedPlaylist = this.selectPlaylist();
oldBitrate = oldMediaPlaylist.attributes &&
oldMediaPlaylist.attributes.BANDWIDTH || 0;
newBitrate = selectedPlaylist.attributes &&
selectedPlaylist.attributes.BANDWIDTH;
selectedPlaylist.attributes.BANDWIDTH || 0;
segmentDuration = oldMediaPlaylist.segments &&
oldMediaPlaylist.segments[this.mediaIndex].duration ||
oldMediaPlaylist.targetDuration;
......@@ -143,7 +145,7 @@ videojs.Hls.prototype.handleSourceOpen = function() {
// request which is a somewhat small file.
threshold = 10;
if (segmentDlTime <= threshold) {
if (newBitrate > oldBitrate && segmentDlTime <= threshold) {
this.playlists.media(selectedPlaylist);
loaderHandler = videojs.bind(this, function() {
setupEvents.call(this);
......
......@@ -368,7 +368,7 @@ test('downloads media playlists after loading the master', function() {
'first segment requested');
});
test('downloads a second media playlist before playback, if bandwidth is high', function() {
test('upshift if initial bandwidth is high', function() {
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
......@@ -378,11 +378,12 @@ test('downloads a second media playlist before playback, if bandwidth is high',
standardXHRResponse(requests[0]);
player.hls.playlists.setBandwidth = function() {
player.hls.playlists.bandwidth = 100000;
player.hls.playlists.bandwidth = 1000000000;
};
standardXHRResponse(requests[1]);
standardXHRResponse(requests[2]);
standardXHRResponse(requests[3]);
strictEqual(requests[0].url, 'manifest/master.m3u8', 'master playlist requested');
......@@ -394,12 +395,41 @@ test('downloads a second media playlist before playback, if bandwidth is high',
strictEqual(requests[2].url,
window.location.origin +
window.location.pathname.split('/').slice(0, -1).join('/') +
'/manifest/media1.m3u8',
'/manifest/media3.m3u8',
'media playlist requested');
strictEqual(requests[3].url,
window.location.origin +
window.location.pathname.split('/').slice(0, -1).join('/') +
'/manifest/media1-00001.ts',
'/manifest/media3-00001.ts',
'first segment requested');
});
test('dont downshift if bandwidth is low', function() {
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
openMediaSource(player);
standardXHRResponse(requests[0]);
player.hls.playlists.setBandwidth = function() {
player.hls.playlists.bandwidth = 100;
};
standardXHRResponse(requests[1]);
standardXHRResponse(requests[2]);
strictEqual(requests[0].url, 'manifest/master.m3u8', 'master playlist requested');
strictEqual(requests[1].url,
window.location.origin +
window.location.pathname.split('/').slice(0, -1).join('/') +
'/manifest/media.m3u8',
'media playlist requested');
strictEqual(requests[2].url,
window.location.origin +
window.location.pathname.split('/').slice(0, -1).join('/') +
'/manifest/media-00001.ts',
'first segment requested');
});
......