ec044877 by Garrett Singer

Don’t process update end until buffered value has been set

In Firefox, the updateend event is triggered for both removing from the buffer and adding to the buffer. To prevent our update end handler from executing on removals, we wait for segmentInfo to have a filled in buffered value before we continue processing.
1 parent 2722c820
...@@ -1229,13 +1229,20 @@ videojs.HlsHandler.prototype.updateEndHandler_ = function () { ...@@ -1229,13 +1229,20 @@ videojs.HlsHandler.prototype.updateEndHandler_ = function () {
1229 seekable, 1229 seekable,
1230 timelineUpdate; 1230 timelineUpdate;
1231 1231
1232 this.pendingSegment_ = null;
1233
1234 // stop here if the update errored or was aborted 1232 // stop here if the update errored or was aborted
1235 if (!segmentInfo) { 1233 if (!segmentInfo) {
1236 return; 1234 return;
1237 } 1235 }
1238 1236
1237 // In Firefox, the updateend event is triggered for both removing from the buffer and
1238 // adding to the buffer. To prevent this code from executing on removals, we wait for
1239 // segmentInfo to have a filled in buffered value before we continue processing.
1240 if (!segmentInfo.buffered) {
1241 return;
1242 }
1243
1244 this.pendingSegment_ = null;
1245
1239 playlist = this.playlists.media(); 1246 playlist = this.playlists.media();
1240 segments = playlist.segments; 1247 segments = playlist.segments;
1241 currentMediaIndex = segmentInfo.mediaIndex + (segmentInfo.mediaSequence - playlist.mediaSequence); 1248 currentMediaIndex = segmentInfo.mediaIndex + (segmentInfo.mediaSequence - playlist.mediaSequence);
......
...@@ -2906,6 +2906,40 @@ test('does not download segments if preload option set to none', function() { ...@@ -2906,6 +2906,40 @@ test('does not download segments if preload option set to none', function() {
2906 equal(requests.length, 0, 'did not download any segments'); 2906 equal(requests.length, 0, 'did not download any segments');
2907 }); 2907 });
2908 2908
2909 test('does not process update end until buffered value has been set', function() {
2910 var drainBufferCallCount = 0, origDrainBuffer;
2911
2912 player.src({
2913 src: 'master.m3u8',
2914 type: 'application/vnd.apple.mpegurl'
2915 });
2916 origDrainBuffer = player.tech_.hls.drainBuffer;
2917 player.tech_.hls.drainBuffer = function() {
2918 drainBufferCallCount++;
2919 };
2920
2921 openMediaSource(player);
2922 standardXHRResponse(requests.shift()); // master
2923 standardXHRResponse(requests.shift()); // media
2924
2925 equal(drainBufferCallCount, 0, 'drainBuffer not called yet');
2926
2927 standardXHRResponse(requests.shift()); // segment
2928
2929 ok(player.tech_.hls.pendingSegment_, 'pending segment exists');
2930 equal(drainBufferCallCount, 1, 'drainBuffer called');
2931
2932 player.tech_.hls.sourceBuffer.trigger('updateend');
2933 ok(player.tech_.hls.pendingSegment_, 'pending segment exists');
2934
2935 player.tech_.hls.drainBuffer = origDrainBuffer;
2936 player.tech_.hls.drainBuffer();
2937 ok(player.tech_.hls.pendingSegment_, 'pending segment exists');
2938
2939 player.tech_.hls.sourceBuffer.trigger('updateend');
2940 ok(!player.tech_.hls.pendingSegment_, 'pending segment cleared out');
2941 });
2942
2909 module('Buffer Inspection'); 2943 module('Buffer Inspection');
2910 2944
2911 test('detects time range end-point changed by updates', function() { 2945 test('detects time range end-point changed by updates', function() {
......