Skip to content

Commit

Permalink
Implement alternate live latency conf params in seconds instead of # …
Browse files Browse the repository at this point in the history
…of segments
  • Loading branch information
Axel Delmas committed Mar 7, 2016
1 parent d03ea65 commit a6b8ded
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/controller/stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,11 @@ class StreamController extends EventHandler {
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.media.seeking}`);
if (bufferEnd < Math.max(start,end-config.liveMaxLatencyDurationCount*levelDetails.targetduration)) {
this.seekAfterBuffered = start + Math.max(0, levelDetails.totalduration - config.liveSyncDurationCount * levelDetails.targetduration);
let maxLatency = config.liveMaxLatencyDuration !== undefined ? config.liveMaxLatencyDuration : config.liveMaxLatencyDurationCount*levelDetails.targetduration;

if (bufferEnd < Math.max(start, end - maxLatency)) {
let targetLatency = config.liveSyncDuration !== undefined ? config.liveSyncDuration : config.liveSyncDurationCount * levelDetails.targetduration;
this.seekAfterBuffered = start + Math.max(0, levelDetails.totalduration - targetLatency);
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;
}
Expand Down Expand Up @@ -773,7 +776,8 @@ class StreamController extends EventHandler {
if (this.startFragRequested === false) {
// if live playlist, set start position to be fragment N-this.config.liveSyncDurationCount (usually 3)
if (newDetails.live) {
this.startPosition = Math.max(0, sliding + duration - this.config.liveSyncDurationCount * newDetails.targetduration);
let targetLatency = this.config.liveSyncDuration !== undefined ? this.config.liveSyncDuration : this.config.liveSyncDurationCount * newDetails.targetduration;
this.startPosition = Math.max(0, sliding + duration - targetLatency);
}
this.nextLoadPosition = this.startPosition;
}
Expand Down
11 changes: 11 additions & 0 deletions src/hls.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Hls {
maxSeekHole: 2,
liveSyncDurationCount:3,
liveMaxLatencyDurationCount: Infinity,
liveSyncDuration: undefined,
liveMaxLatencyDuration: undefined,
maxMaxBufferLength: 600,
enableWorker: true,
enableSoftwareAES: true,
Expand Down Expand Up @@ -84,6 +86,11 @@ class Hls {

constructor(config = {}) {
var defaultConfig = Hls.DefaultConfig;

if ((config.liveSyncDurationCount || config.liveMaxLatencyDurationCount) && (config.liveSyncDuration || config.liveMaxLatencyDuration)) {
throw new Error('Illegal hls.js config: don\'t mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration');
}

for (var prop in defaultConfig) {
if (prop in config) { continue; }
config[prop] = defaultConfig[prop];
Expand All @@ -93,6 +100,10 @@ class Hls {
throw new Error('Illegal hls.js config: "liveMaxLatencyDurationCount" must be gt "liveSyncDurationCount"');
}

if (config.liveMaxLatencyDuration !== undefined && config.liveMaxLatencyDuration <= config.liveSyncDuration) {
throw new Error('Illegal hls.js config: "liveMaxLatencyDuration" must be gt "liveSyncDuration"');
}

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

0 comments on commit a6b8ded

Please sign in to comment.