Fix the min/max latency thresholds
This commit is contained in:
parent
e46f8e2a66
commit
4ed02d4e0f
@ -125,7 +125,6 @@ class LatencyCompensator {
|
|||||||
tech.vhs.stats.buffered.forEach((buffer) => {
|
tech.vhs.stats.buffered.forEach((buffer) => {
|
||||||
totalBuffered += buffer.end - buffer.start;
|
totalBuffered += buffer.end - buffer.start;
|
||||||
});
|
});
|
||||||
console.log('buffered', totalBuffered);
|
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
// Determine how much of the current playlist's bandwidth requirements
|
// Determine how much of the current playlist's bandwidth requirements
|
||||||
@ -152,48 +151,25 @@ class LatencyCompensator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// How far away from live edge do we start the compensator.
|
|
||||||
const maxLatencyThreshold = Math.min(
|
|
||||||
MAX_LATENCY,
|
|
||||||
segment.duration * 1000 * HIGHEST_LATENCY_SEGMENT_LENGTH_MULTIPLIER
|
|
||||||
);
|
|
||||||
|
|
||||||
// How far away from live edge do we stop the compensator.
|
// How far away from live edge do we stop the compensator.
|
||||||
const minLatencyThreshold = Math.max(
|
const minLatencyThreshold = Math.max(
|
||||||
MIN_LATENCY,
|
MIN_LATENCY,
|
||||||
segment.duration * 1000 * LOWEST_LATENCY_SEGMENT_LENGTH_MULTIPLIER
|
segment.duration * 1000 * LOWEST_LATENCY_SEGMENT_LENGTH_MULTIPLIER
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// How far away from live edge do we start the compensator.
|
||||||
|
const maxLatencyThreshold = Math.max(
|
||||||
|
minLatencyThreshold * 1.4,
|
||||||
|
Math.min(
|
||||||
|
segment.duration * 1000 * HIGHEST_LATENCY_SEGMENT_LENGTH_MULTIPLIER,
|
||||||
|
MAX_LATENCY
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
const segmentTime = segment.dateTimeObject.getTime();
|
const segmentTime = segment.dateTimeObject.getTime();
|
||||||
const now = new Date().getTime();
|
const now = new Date().getTime();
|
||||||
const latency = now - segmentTime;
|
const latency = now - segmentTime;
|
||||||
|
|
||||||
// Using our bandwidth ratio determine a wide guess at how fast we can play.
|
|
||||||
var proposedPlaybackRate = bandwidthRatio * 0.33;
|
|
||||||
|
|
||||||
// But limit the playback rate to a max value.
|
|
||||||
proposedPlaybackRate = Math.max(
|
|
||||||
Math.min(proposedPlaybackRate, MAX_SPEEDUP_RATE),
|
|
||||||
1.0
|
|
||||||
);
|
|
||||||
|
|
||||||
if (proposedPlaybackRate > this.playbackRate + MAX_SPEEDUP_RAMP) {
|
|
||||||
// If this proposed speed is substantially faster than the current rate,
|
|
||||||
// then allow us to ramp up by using a slower value for now.
|
|
||||||
proposedPlaybackRate = this.playbackRate + MAX_SPEEDUP_RAMP;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
'proposedPlaybackRate',
|
|
||||||
proposedPlaybackRate,
|
|
||||||
'previous',
|
|
||||||
this.playbackRate
|
|
||||||
);
|
|
||||||
|
|
||||||
// Limit to 3 decimal places of precision.
|
|
||||||
proposedPlaybackRate =
|
|
||||||
Math.round(proposedPlaybackRate * Math.pow(10, 3)) / Math.pow(10, 3);
|
|
||||||
|
|
||||||
if (latency > maxLatencyThreshold) {
|
if (latency > maxLatencyThreshold) {
|
||||||
// If the current latency exceeds the max jump amount then
|
// If the current latency exceeds the max jump amount then
|
||||||
// force jump into the future, skipping all the video in between.
|
// force jump into the future, skipping all the video in between.
|
||||||
@ -212,9 +188,40 @@ class LatencyCompensator {
|
|||||||
' to ',
|
' to ',
|
||||||
seekPosition
|
seekPosition
|
||||||
);
|
);
|
||||||
this.jump(seekPosition);
|
|
||||||
|
// Verify we have the seek position buffered before jumping.
|
||||||
|
const availableBufferedTimeEnd = tech.vhs.stats.buffered[0].end;
|
||||||
|
const availableBufferedTimeStart = tech.vhs.stats.buffered[0].start;
|
||||||
|
if (
|
||||||
|
seekPosition >
|
||||||
|
availableBufferedTimeStart <
|
||||||
|
availableBufferedTimeEnd
|
||||||
|
) {
|
||||||
|
this.jump(seekPosition);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Using our bandwidth ratio determine a wide guess at how fast we can play.
|
||||||
|
var proposedPlaybackRate = bandwidthRatio * 0.33;
|
||||||
|
|
||||||
|
// But limit the playback rate to a max value.
|
||||||
|
proposedPlaybackRate = Math.max(
|
||||||
|
Math.min(proposedPlaybackRate, MAX_SPEEDUP_RATE),
|
||||||
|
1.0
|
||||||
|
);
|
||||||
|
|
||||||
|
if (proposedPlaybackRate > this.playbackRate + MAX_SPEEDUP_RAMP) {
|
||||||
|
// If this proposed speed is substantially faster than the current rate,
|
||||||
|
// then allow us to ramp up by using a slower value for now.
|
||||||
|
proposedPlaybackRate = this.playbackRate + MAX_SPEEDUP_RAMP;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit to 3 decimal places of precision.
|
||||||
|
proposedPlaybackRate =
|
||||||
|
Math.round(proposedPlaybackRate * Math.pow(10, 3)) / Math.pow(10, 3);
|
||||||
|
|
||||||
// Otherwise start the playback rate adjustment.
|
// Otherwise start the playback rate adjustment.
|
||||||
this.start(proposedPlaybackRate);
|
this.start(proposedPlaybackRate);
|
||||||
} else if (latency <= minLatencyThreshold) {
|
} else if (latency <= minLatencyThreshold) {
|
||||||
@ -240,7 +247,7 @@ class LatencyCompensator {
|
|||||||
this.bufferingCounter
|
this.bufferingCounter
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
// console.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user