66a0f5ef by David LaPalomento

Don't append segments that have already been appended

Fixes #430. If drainBuffer is called after updating is reset on the sourceBuffer but before updateend fires, a segment could be appended twice. Check to make sure a segment hasn't already been appended before proceeding with draining the buffer.
1 parent eb5c0c61
......@@ -948,6 +948,12 @@ videojs.Hls.prototype.drainBuffer = function(event) {
return;
}
// the pending segment has already been appended and we're waiting
// for updateend to fire
if (this.pendingSegment_.buffered) {
return;
}
// we can't append more data if the source buffer is busy processing
// what we've already sent
if (this.sourceBuffer.updating) {
......
......@@ -1180,16 +1180,24 @@ test('only makes one segment request at a time', function() {
});
test('only appends one segment at a time', function() {
var appends = 0;
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
openMediaSource(player);
standardXHRResponse(requests.pop()); // media.m3u8
player.tech_.hls.sourceBuffer.appendBuffer = function() {
appends++;
};
standardXHRResponse(requests.pop()); // segment 0
player.tech_.hls.checkBuffer_();
equal(requests.length, 0, 'did not request while updating');
player.tech_.hls.checkBuffer_();
equal(appends, 1, 'appended once');
});
test('waits to download new segments until the media playlist is stable', function() {
......