Merge pull request #205 from videojs/onceux-hls-stalling
Fixing discontinuity seek
Showing
2 changed files
with
61 additions
and
6 deletions
... | @@ -611,12 +611,17 @@ videojs.Hls.prototype.drainBuffer = function(event) { | ... | @@ -611,12 +611,17 @@ videojs.Hls.prototype.drainBuffer = function(event) { |
611 | // until it empties before calling it when a discontinuity is | 611 | // until it empties before calling it when a discontinuity is |
612 | // next in the buffer | 612 | // next in the buffer |
613 | if (segment.discontinuity) { | 613 | if (segment.discontinuity) { |
614 | if (event.type !== 'waiting') { | 614 | if (event.type === 'waiting') { |
615 | this.sourceBuffer.abort(); | ||
616 | // tell the SWF where playback is continuing in the stitched timeline | ||
617 | this.el().vjs_setProperty('currentTime', segmentOffset * 0.001); | ||
618 | } else if (event.type === 'timeupdate') { | ||
619 | return; | ||
620 | } else if (typeof offset !== 'number') { | ||
621 | //if the discontinuity is reached under normal conditions, ie not a seek, | ||
622 | //the buffer already contains data and does not need to be refilled, | ||
615 | return; | 623 | return; |
616 | } | 624 | } |
617 | this.sourceBuffer.abort(); | ||
618 | // tell the SWF where playback is continuing in the stitched timeline | ||
619 | this.el().vjs_setProperty('currentTime', segmentOffset * 0.001); | ||
620 | } | 625 | } |
621 | 626 | ||
622 | // transmux the segment data from MP2T to FLV | 627 | // transmux the segment data from MP2T to FLV | ... | ... |
... | @@ -1186,7 +1186,7 @@ test('waits until the buffer is empty before appending bytes at a discontinuity' | ... | @@ -1186,7 +1186,7 @@ test('waits until the buffer is empty before appending bytes at a discontinuity' |
1186 | var aborts = 0, setTime, currentTime, bufferEnd; | 1186 | var aborts = 0, setTime, currentTime, bufferEnd; |
1187 | 1187 | ||
1188 | player.src({ | 1188 | player.src({ |
1189 | src: 'disc.m3u8', | 1189 | src: 'discontinuity.m3u8', |
1190 | type: 'application/vnd.apple.mpegurl' | 1190 | type: 'application/vnd.apple.mpegurl' |
1191 | }); | 1191 | }); |
1192 | openMediaSource(player); | 1192 | openMediaSource(player); |
... | @@ -1233,7 +1233,7 @@ test('clears the segment buffer on seek', function() { | ... | @@ -1233,7 +1233,7 @@ test('clears the segment buffer on seek', function() { |
1233 | videojs.Hls.SegmentParser = mockSegmentParser(tags); | 1233 | videojs.Hls.SegmentParser = mockSegmentParser(tags); |
1234 | 1234 | ||
1235 | player.src({ | 1235 | player.src({ |
1236 | src: 'disc.m3u8', | 1236 | src: 'discontinuity.m3u8', |
1237 | type: 'application/vnd.apple.mpegurl' | 1237 | type: 'application/vnd.apple.mpegurl' |
1238 | }); | 1238 | }); |
1239 | openMediaSource(player); | 1239 | openMediaSource(player); |
... | @@ -1278,6 +1278,56 @@ test('clears the segment buffer on seek', function() { | ... | @@ -1278,6 +1278,56 @@ test('clears the segment buffer on seek', function() { |
1278 | strictEqual(aborts, 1, 'cleared the segment buffer on a seek'); | 1278 | strictEqual(aborts, 1, 'cleared the segment buffer on a seek'); |
1279 | }); | 1279 | }); |
1280 | 1280 | ||
1281 | test('continues playing after seek to discontinuity', function() { | ||
1282 | var aborts = 0, tags = [], currentTime, bufferEnd, oldCurrentTime; | ||
1283 | |||
1284 | videojs.Hls.SegmentParser = mockSegmentParser(tags); | ||
1285 | |||
1286 | player.src({ | ||
1287 | src: 'discontinuity.m3u8', | ||
1288 | type: 'application/vnd.apple.mpegurl' | ||
1289 | }); | ||
1290 | openMediaSource(player); | ||
1291 | oldCurrentTime = player.currentTime; | ||
1292 | player.currentTime = function(time) { | ||
1293 | if (time !== undefined) { | ||
1294 | return oldCurrentTime.call(player, time); | ||
1295 | } | ||
1296 | return currentTime; | ||
1297 | }; | ||
1298 | player.buffered = function() { | ||
1299 | return videojs.createTimeRange(0, bufferEnd); | ||
1300 | }; | ||
1301 | player.hls.sourceBuffer.abort = function() { | ||
1302 | aborts++; | ||
1303 | }; | ||
1304 | |||
1305 | requests.pop().respond(200, null, | ||
1306 | '#EXTM3U\n' + | ||
1307 | '#EXTINF:10,0\n' + | ||
1308 | '1.ts\n' + | ||
1309 | '#EXT-X-DISCONTINUITY\n' + | ||
1310 | '#EXTINF:10,0\n' + | ||
1311 | '2.ts\n'); | ||
1312 | standardXHRResponse(requests.pop()); | ||
1313 | |||
1314 | currentTime = 1; | ||
1315 | bufferEnd = 10; | ||
1316 | player.trigger('timeupdate'); | ||
1317 | |||
1318 | standardXHRResponse(requests.pop()); | ||
1319 | |||
1320 | // seek to the discontinuity | ||
1321 | player.currentTime(10); | ||
1322 | tags.push({ pts: 0, bytes: 0 }); | ||
1323 | standardXHRResponse(requests.pop()); | ||
1324 | strictEqual(aborts, 1, 'aborted once for the seek'); | ||
1325 | |||
1326 | // the source buffer empties. is 2.ts still in the segment buffer? | ||
1327 | player.trigger('waiting'); | ||
1328 | strictEqual(aborts, 1, 'cleared the segment buffer on a seek'); | ||
1329 | }); | ||
1330 | |||
1281 | test('resets the switching algorithm if a request times out', function() { | 1331 | test('resets the switching algorithm if a request times out', function() { |
1282 | player.src({ | 1332 | player.src({ |
1283 | src: 'master.m3u8', | 1333 | src: 'master.m3u8', | ... | ... |
-
Please register or sign in to post a comment