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) { ...@@ -948,6 +948,12 @@ videojs.Hls.prototype.drainBuffer = function(event) {
948 return; 948 return;
949 } 949 }
950 950
951 // the pending segment has already been appended and we're waiting
952 // for updateend to fire
953 if (this.pendingSegment_.buffered) {
954 return;
955 }
956
951 // we can't append more data if the source buffer is busy processing 957 // we can't append more data if the source buffer is busy processing
952 // what we've already sent 958 // what we've already sent
953 if (this.sourceBuffer.updating) { 959 if (this.sourceBuffer.updating) {
......
...@@ -1180,16 +1180,24 @@ test('only makes one segment request at a time', function() { ...@@ -1180,16 +1180,24 @@ test('only makes one segment request at a time', function() {
1180 }); 1180 });
1181 1181
1182 test('only appends one segment at a time', function() { 1182 test('only appends one segment at a time', function() {
1183 var appends = 0;
1183 player.src({ 1184 player.src({
1184 src: 'manifest/media.m3u8', 1185 src: 'manifest/media.m3u8',
1185 type: 'application/vnd.apple.mpegurl' 1186 type: 'application/vnd.apple.mpegurl'
1186 }); 1187 });
1187 openMediaSource(player); 1188 openMediaSource(player);
1188 standardXHRResponse(requests.pop()); // media.m3u8 1189 standardXHRResponse(requests.pop()); // media.m3u8
1190 player.tech_.hls.sourceBuffer.appendBuffer = function() {
1191 appends++;
1192 };
1193
1189 standardXHRResponse(requests.pop()); // segment 0 1194 standardXHRResponse(requests.pop()); // segment 0
1190 1195
1191 player.tech_.hls.checkBuffer_(); 1196 player.tech_.hls.checkBuffer_();
1192 equal(requests.length, 0, 'did not request while updating'); 1197 equal(requests.length, 0, 'did not request while updating');
1198
1199 player.tech_.hls.checkBuffer_();
1200 equal(appends, 1, 'appended once');
1193 }); 1201 });
1194 1202
1195 test('waits to download new segments until the media playlist is stable', function() { 1203 test('waits to download new segments until the media playlist is stable', function() {
......