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() { ...@@ -109,7 +109,7 @@ videojs.Hls.prototype.handleSourceOpen = function() {
109 this.playlists = new videojs.Hls.PlaylistLoader(this.src_, settings.withCredentials); 109 this.playlists = new videojs.Hls.PlaylistLoader(this.src_, settings.withCredentials);
110 110
111 this.playlists.on('loadedmetadata', videojs.bind(this, function() { 111 this.playlists.on('loadedmetadata', videojs.bind(this, function() {
112 var selectedPlaylist, loaderHandler, newBitrate, segmentDuration, 112 var selectedPlaylist, loaderHandler, oldBitrate, newBitrate, segmentDuration,
113 segmentDlTime, setupEvents, threshold; 113 segmentDlTime, setupEvents, threshold;
114 114
115 setupEvents = function() { 115 setupEvents = function() {
...@@ -127,8 +127,10 @@ videojs.Hls.prototype.handleSourceOpen = function() { ...@@ -127,8 +127,10 @@ videojs.Hls.prototype.handleSourceOpen = function() {
127 oldMediaPlaylist = this.playlists.media(); 127 oldMediaPlaylist = this.playlists.media();
128 this.bandwidth = this.playlists.bandwidth; 128 this.bandwidth = this.playlists.bandwidth;
129 selectedPlaylist = this.selectPlaylist(); 129 selectedPlaylist = this.selectPlaylist();
130 oldBitrate = oldMediaPlaylist.attributes &&
131 oldMediaPlaylist.attributes.BANDWIDTH || 0;
130 newBitrate = selectedPlaylist.attributes && 132 newBitrate = selectedPlaylist.attributes &&
131 selectedPlaylist.attributes.BANDWIDTH; 133 selectedPlaylist.attributes.BANDWIDTH || 0;
132 segmentDuration = oldMediaPlaylist.segments && 134 segmentDuration = oldMediaPlaylist.segments &&
133 oldMediaPlaylist.segments[this.mediaIndex].duration || 135 oldMediaPlaylist.segments[this.mediaIndex].duration ||
134 oldMediaPlaylist.targetDuration; 136 oldMediaPlaylist.targetDuration;
...@@ -143,7 +145,7 @@ videojs.Hls.prototype.handleSourceOpen = function() { ...@@ -143,7 +145,7 @@ videojs.Hls.prototype.handleSourceOpen = function() {
143 // request which is a somewhat small file. 145 // request which is a somewhat small file.
144 threshold = 10; 146 threshold = 10;
145 147
146 if (segmentDlTime <= threshold) { 148 if (newBitrate > oldBitrate && segmentDlTime <= threshold) {
147 this.playlists.media(selectedPlaylist); 149 this.playlists.media(selectedPlaylist);
148 loaderHandler = videojs.bind(this, function() { 150 loaderHandler = videojs.bind(this, function() {
149 setupEvents.call(this); 151 setupEvents.call(this);
......
...@@ -368,7 +368,7 @@ test('downloads media playlists after loading the master', function() { ...@@ -368,7 +368,7 @@ test('downloads media playlists after loading the master', function() {
368 'first segment requested'); 368 'first segment requested');
369 }); 369 });
370 370
371 test('downloads a second media playlist before playback, if bandwidth is high', function() { 371 test('upshift if initial bandwidth is high', function() {
372 player.src({ 372 player.src({
373 src: 'manifest/master.m3u8', 373 src: 'manifest/master.m3u8',
374 type: 'application/vnd.apple.mpegurl' 374 type: 'application/vnd.apple.mpegurl'
...@@ -378,11 +378,12 @@ test('downloads a second media playlist before playback, if bandwidth is high', ...@@ -378,11 +378,12 @@ test('downloads a second media playlist before playback, if bandwidth is high',
378 standardXHRResponse(requests[0]); 378 standardXHRResponse(requests[0]);
379 379
380 player.hls.playlists.setBandwidth = function() { 380 player.hls.playlists.setBandwidth = function() {
381 player.hls.playlists.bandwidth = 100000; 381 player.hls.playlists.bandwidth = 1000000000;
382 }; 382 };
383 383
384 standardXHRResponse(requests[1]); 384 standardXHRResponse(requests[1]);
385 standardXHRResponse(requests[2]); 385 standardXHRResponse(requests[2]);
386
386 standardXHRResponse(requests[3]); 387 standardXHRResponse(requests[3]);
387 388
388 strictEqual(requests[0].url, 'manifest/master.m3u8', 'master playlist requested'); 389 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', ...@@ -394,12 +395,41 @@ test('downloads a second media playlist before playback, if bandwidth is high',
394 strictEqual(requests[2].url, 395 strictEqual(requests[2].url,
395 window.location.origin + 396 window.location.origin +
396 window.location.pathname.split('/').slice(0, -1).join('/') + 397 window.location.pathname.split('/').slice(0, -1).join('/') +
397 '/manifest/media1.m3u8', 398 '/manifest/media3.m3u8',
398 'media playlist requested'); 399 'media playlist requested');
399 strictEqual(requests[3].url, 400 strictEqual(requests[3].url,
400 window.location.origin + 401 window.location.origin +
401 window.location.pathname.split('/').slice(0, -1).join('/') + 402 window.location.pathname.split('/').slice(0, -1).join('/') +
402 '/manifest/media1-00001.ts', 403 '/manifest/media3-00001.ts',
404 'first segment requested');
405 });
406
407 test('dont downshift if bandwidth is low', function() {
408 player.src({
409 src: 'manifest/master.m3u8',
410 type: 'application/vnd.apple.mpegurl'
411 });
412 openMediaSource(player);
413
414 standardXHRResponse(requests[0]);
415
416 player.hls.playlists.setBandwidth = function() {
417 player.hls.playlists.bandwidth = 100;
418 };
419
420 standardXHRResponse(requests[1]);
421 standardXHRResponse(requests[2]);
422
423 strictEqual(requests[0].url, 'manifest/master.m3u8', 'master playlist requested');
424 strictEqual(requests[1].url,
425 window.location.origin +
426 window.location.pathname.split('/').slice(0, -1).join('/') +
427 '/manifest/media.m3u8',
428 'media playlist requested');
429 strictEqual(requests[2].url,
430 window.location.origin +
431 window.location.pathname.split('/').slice(0, -1).join('/') +
432 '/manifest/media-00001.ts',
403 'first segment requested'); 433 'first segment requested');
404 }); 434 });
405 435
......