c6b4a49f by David LaPalomento

Don't abort a playlist request just to re-issue the same request

Check the outstanding request URL before aborting playlist requests when a switch is requested. Don't filter out requests that are generated as a result of another request finishing in the switcher simulator. Actual playlist switching is showing up in the graph now.
1 parent 6038397b
......@@ -147,10 +147,17 @@
return;
}
loader.state = 'SWITCHING_MEDIA';
// abort any outstanding playlist refreshes
// there is already an outstanding playlist request
if (request) {
if (resolveUrl(loader.master.uri, playlist.uri) === request.url) {
// requesting to switch to the same playlist multiple times
// has no effect after the first
return;
}
request.abort();
request = null;
}
......
......@@ -563,6 +563,7 @@ xhr = videojs.Hls.xhr = function(url, callback) {
request = new window.XMLHttpRequest();
request.open(options.method, url);
request.url = url;
if (options.responseType) {
request.responseType = options.responseType;
......
......@@ -349,6 +349,27 @@
strictEqual(requests.length, 0, 'no requests is sent');
});
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,
'#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('high.m3u8');
strictEqual(requests.length, 1, 'made only one request');
ok(!requests[0].aborted, 'request not aborted');
});
test('throws an error if a media switch is initiated too early', function() {
var loader = new videojs.Hls.PlaylistLoader('master.m3u8');
......
......@@ -135,7 +135,7 @@
var master = '#EXTM3U\n' +
options.playlists.reduce(function(playlists, value) {
return playlists +
'#EXT-X-STREAM-INF:' + value + '\n' +
'#EXT-X-STREAM-INF:BANDWIDTH=' + value + '\n' +
'playlist-' + value + '\n';
}, ''),
buffered = 0,
......@@ -171,26 +171,23 @@
});
// deliver responses if they're ready
requests = requests.reduce(function(remaining, request) {
requests.forEach(function(request, i) {
var arrival = request.startTime + propagationDelay,
segmentSize = +request.url.match(/(\d+)-\d+$/)[1] * segmentDuration;
segmentSize;
// playlist responses
if (/playlist-\d+$/.test(request.url)) {
// playlist responses have no trasmission time
// for simplicity, playlist responses have zero trasmission time
if (t === arrival) {
request.respond(200, null, playlistResponse(+requests[0].url.match(/\d+$/)));
return remaining;
// the request is completed
return requests.splice(requests.indexOf(request), 1);
}
// the response has not arrived. re-enqueue it for later.
return remaining.concat(request);
return;
}
// segment responses
if (t >= arrival) {
request.delivered += results.bandwidth[t].bandwidth;
}
segmentSize = +request.url.match(/(\d+)-\d+$/)[1] * segmentDuration;
// segment response headers arrive after the propogation delay
if (t === arrival) {
results.playlists.push({
......@@ -205,12 +202,18 @@
if (request.delivered >= segmentSize) {
buffered += segmentDuration;
request.status = 200;
request.response = new Uint8Array(segmentSize);
request.response = new Uint8Array(segmentSize * 0.125);
request.setResponseBody('');
return remaining;
// the request is completed
return requests.splice(requests.indexOf(request), 1);
}
// transmit the bits for this tick
if (t >= arrival) {
request.delivered += results.bandwidth[t].bandwidth;
}
// response has not arrived fully, re-enqueue it for later
return remaining.concat(request);
// response has not arrived fully
return;
}, []);
// simulate playback
......