b65573ad by David LaPalomento

Switch to fully-loaded playlists immediately

Don't re-request playlists that have already been fully loaded. If the loader is in the middle of requesting a new playlist and is asked to switch back to a loaded one, abort the outstanding request. Update playlist loader state diagram.
1 parent 4f97809b
......@@ -150,12 +150,21 @@
playlist = loader.master.playlists[playlist];
}
if (playlist.uri === media.uri) {
// switching to the currently active playlist is a no-op
// switch to fully loaded playlists immediately
if (loader.master.playlists[playlist.uri].endList) {
if (request) {
request.abort();
request = null;
}
loader.state = 'HAVE_METADATA';
media = playlist;
return;
}
// switching to the active playlist is a no-op
if (playlist.uri === media.uri) {
return;
}
loader.state = 'SWITCHING_MEDIA';
......
......@@ -348,9 +348,78 @@
'#EXT-X-ENDLIST\n');
loader.media('low.m3u8');
strictEqual(requests.length, 0, 'no requests is sent');
strictEqual(requests.length, 0, 'no requests are sent');
});
test('switching to the active live playlist is a no-op', function() {
var loader = new videojs.Hls.PlaylistLoader('master.m3u8');
requests.pop().respond(200, null,
'#EXTM3U\n' +
'#EXT-X-STREAM-INF:BANDWIDTH=1\n' +
'low.m3u8\n' +
'#EXT-X-STREAM-INF:BANDWIDTH=2\n' +
'high.m3u8\n');
requests.pop().respond(200, null,
'#EXTM3U\n' +
'#EXT-X-MEDIA-SEQUENCE:0\n' +
'#EXTINF:10,\n' +
'low-0.ts\n');
loader.media('low.m3u8');
strictEqual(requests.length, 0, 'no requests are sent');
});
test('switches back to loaded playlists without re-requesting them', function() {
var loader = new videojs.Hls.PlaylistLoader('master.m3u8');
requests.pop().respond(200, null,
'#EXTM3U\n' +
'#EXT-X-STREAM-INF:BANDWIDTH=1\n' +
'low.m3u8\n' +
'#EXT-X-STREAM-INF:BANDWIDTH=2\n' +
'high.m3u8\n');
requests.pop().respond(200, null,
'#EXTM3U\n' +
'#EXT-X-MEDIA-SEQUENCE:0\n' +
'#EXTINF:10,\n' +
'low-0.ts\n' +
'#EXT-X-ENDLIST\n');
loader.media('high.m3u8');
requests.pop().respond(200, null,
'#EXTM3U\n' +
'#EXT-X-MEDIA-SEQUENCE:0\n' +
'#EXTINF:10,\n' +
'high-0.ts\n' +
'#EXT-X-ENDLIST\n');
loader.media('low.m3u8');
strictEqual(requests.length, 0, 'no outstanding requests');
strictEqual(loader.state, 'HAVE_METADATA', 'returned to loaded playlist');
});
test('aborts outstanding requests if switching back to an already loaded playlist', function() {
var loader = new videojs.Hls.PlaylistLoader('master.m3u8');
requests.pop().respond(200, null,
'#EXTM3U\n' +
'#EXT-X-STREAM-INF:BANDWIDTH=1\n' +
'low.m3u8\n' +
'#EXT-X-STREAM-INF:BANDWIDTH=2\n' +
'high.m3u8\n');
requests.pop().respond(200, null,
'#EXTM3U\n' +
'#EXT-X-MEDIA-SEQUENCE:0\n' +
'#EXTINF:10,\n' +
'low-0.ts\n' +
'#EXT-X-ENDLIST\n');
loader.media('high.m3u8');
loader.media('low.m3u8');
strictEqual(requests.length, 1, 'requested high playlist');
ok(requests[0].aborted, 'aborted playlist request');
strictEqual(loader.state, 'HAVE_METADATA', 'returned to loaded playlist');
strictEqual(loader.media(), loader.master.playlists[0], 'switched to loaded playlist');
});
test('does not abort requests when the same playlist is re-requested', function() {
var loader = new videojs.Hls.PlaylistLoader('master.m3u8');
requests.pop().respond(200, null,
......