1e9ba128 by jrivera

Fix two bugs in the blacklisting facility

* Moved blacklisting to above the rendition selection line so that we don't try to select the rendition that was just blacklisted
* Playlist Loader now emits the playlist it was trying to load so that it can be blacklisted when initial load was unsuccessful
1 parent 3b1a5651
......@@ -110,6 +110,7 @@
if (error) {
loader.error = {
playlist: loader.master.playlists[url],
status: xhr.status,
message: 'HLS playlist request error at URL: ' + url,
responseText: xhr.responseText,
......
......@@ -909,10 +909,19 @@ videojs.HlsHandler.prototype.setBandwidth = function(xhr) {
this.tech_.trigger('bandwidthupdate');
};
/*
* Blacklists a playlist when an error occurs for a set amount of time
* making it unavailable for selection by the rendition selection algorithm
* and then forces a new playlist (rendition) selection.
*/
videojs.HlsHandler.prototype.blacklistCurrentPlaylist_ = function(error) {
var currentPlaylist, nextPlaylist;
currentPlaylist = this.playlists.media();
// If the `error` was generated by the playlist loader, it will contain
// the playlist we were trying to load (but failed) and that should be
// blacklisted instead of the currently selected playlist which is likely
// out-of-date in this scenario
currentPlaylist = error.playlist || this.playlists.media();
// If there is no current playlist, then an error occurred while we were
// trying to load the master OR while we were disposing of the tech
......@@ -921,15 +930,15 @@ videojs.HlsHandler.prototype.blacklistCurrentPlaylist_ = function(error) {
return this.mediaSource.endOfStream('network');
}
// Blacklist this playlist
currentPlaylist.excludeUntil = Date.now() + blacklistDuration;
// Select a new playlist
nextPlaylist = this.selectPlaylist();
if (nextPlaylist) {
videojs.log.warn('Problem encountered with the current HLS playlist. Switching to another playlist.');
// Blacklist this playlist
currentPlaylist.excludeUntil = Date.now() + blacklistDuration;
return this.playlists.media(nextPlaylist);
} else {
videojs.log.warn('Problem encountered with the current HLS playlist. No suitable alternatives found.');
......
......@@ -1514,6 +1514,33 @@ test('segment 404 should trigger blacklisting of media', function () {
ok(media.excludeUntil > 0, 'original media blacklisted for some time');
});
test('playlist 404 should blacklist media', function () {
var media, url;
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
openMediaSource(player);
player.tech_.hls.bandwidth = 1e10;
requests[0].respond(200, null,
'#EXTM3U\n' +
'#EXT-X-STREAM-INF:BANDWIDTH=1000\n' +
'media.m3u8\n' +
'#EXT-X-STREAM-INF:BANDWIDTH=1\n' +
'media1.m3u8\n'); // master
equal(player.tech_.hls.playlists.media_, undefined, 'no media is initially set');
requests[1].respond(400); // media
url = requests[1].url.slice(requests[1].url.lastIndexOf('/') + 1);
media = player.tech_.hls.playlists.master.playlists[url];
ok(media.excludeUntil > 0, 'original media blacklisted for some time');
});
test('seeking in an empty playlist is a non-erroring noop', function() {
var requestsLength;
......