Skip to content

Commit

Permalink
Merge pull request video-dev#32 from AxelDelmas/lateLiveFix
Browse files Browse the repository at this point in the history
Proposal for issue video-dev#31
  • Loading branch information
mangui committed Oct 16, 2015
2 parents 525bb79 + 60dc0e3 commit 6d0ebb7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
9 changes: 9 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ configuration parameters could be provided to hls.js upon instantiation of Hls O
maxBufferLength : 30,
maxBufferSize : 60*1000*1000,
liveSyncDurationCount : 3,
liveMaxLatencyDurationCount: 10,
enableWorker : true,
fragLoadingTimeOut : 20000,
fragLoadingMaxRetry : 6,
Expand Down Expand Up @@ -223,6 +224,14 @@ edge of live delay, expressed in multiple of ```EXT-X-TARGETDURATION```.
if set to 3, playback will start from fragment N-3, N being the last fragment of the live playlist.
decreasing this value is likely to cause playback stalls.
#### ```liveMaxLatencyDurationCount```
(default Infinity)
maximum delay allowed from edge of live, expressed in multiple of ```EXT-X-TARGETDURATION```.
if set to 10, the player will seek back to ```liveSyncDurationCount``` whenever the next fragment to be loaded is older than N-10, N being the last fragment of the live playlist.
If set, this value must be stricly superior to ```liveSyncDurationCount```
a value too close from ```liveSyncDurationCount``` is likely to cause playback stalls.
#### ```enableWorker```
(default true)
Expand Down
4 changes: 2 additions & 2 deletions src/controller/buffer-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ class BufferController {
if (levelDetails.live) {
// check if requested position is within seekable boundaries :
//logger.log(`start/pos/bufEnd/seeking:${start.toFixed(3)}/${pos.toFixed(3)}/${bufferEnd.toFixed(3)}/${this.video.seeking}`);
if (bufferEnd < start) {
if (bufferEnd < Math.max(start,end-this.config.liveMaxLatencyDurationCount*levelDetails.targetduration)) {
this.seekAfterBuffered = start + Math.max(0, levelDetails.totalduration - this.config.liveSyncDurationCount * levelDetails.targetduration);
logger.log(`buffer end: ${bufferEnd} is located before start of live sliding playlist, media position will be reseted to: ${this.seekAfterBuffered.toFixed(3)}`);
logger.log(`buffer end: ${bufferEnd} is located too far from the end of live sliding playlist, media position will be reseted to: ${this.seekAfterBuffered.toFixed(3)}`);
bufferEnd = this.seekAfterBuffered;
}
if (this.startFragmentRequested && !levelDetails.PTSKnown) {
Expand Down
6 changes: 6 additions & 0 deletions src/hls.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Hls {
maxBufferLength: 30,
maxBufferSize: 60 * 1000 * 1000,
liveSyncDurationCount:3,
liveMaxLatencyDurationCount: Infinity,
maxMaxBufferLength: 600,
enableWorker: true,
fragLoadingTimeOut: 20000,
Expand All @@ -60,6 +61,11 @@ class Hls {
if (prop in config) { continue; }
config[prop] = configDefault[prop];
}

if (config.liveMaxLatencyDurationCount !== undefined && config.liveMaxLatencyDurationCount <= config.liveSyncDurationCount) {
throw new Error('Illegal hls.js configuration: "liveMaxLatencyDurationCount" must be strictly superior to "liveSyncDurationCount" in player configuration');
}

enableLogs(config.debug);
this.config = config;
// observer setup
Expand Down

0 comments on commit 6d0ebb7

Please sign in to comment.