Allow the latency compensator to be dynamic
This commit is contained in:
parent
4d5de61148
commit
d8ead6d954
@ -13,7 +13,7 @@ It will:
|
|||||||
|
|
||||||
const BUFFER_LIMIT = 10; // Max number of buffering events before we stop compensating for latency.
|
const BUFFER_LIMIT = 10; // Max number of buffering events before we stop compensating for latency.
|
||||||
const MIN_BUFFER_DURATION = 300; // Min duration a buffer event must last to be counted.
|
const MIN_BUFFER_DURATION = 300; // Min duration a buffer event must last to be counted.
|
||||||
const SPEEDUP_RATE = 1.06; // The playback rate when compensating for latency.
|
const MAX_SPEEDUP_RATE = 1.07; // The playback rate when compensating for latency.
|
||||||
const TIMEOUT_DURATION = 20_000; // The amount of time we stop handling latency after certain events.
|
const TIMEOUT_DURATION = 20_000; // The amount of time we stop handling latency after certain events.
|
||||||
const CHECK_TIMER_INTERVAL = 5_000; // How often we check if we should be compensating for latency.
|
const CHECK_TIMER_INTERVAL = 5_000; // How often we check if we should be compensating for latency.
|
||||||
const BUFFERING_AMNESTY_DURATION = 2 * 1000 * 60; // How often until a buffering event expires.
|
const BUFFERING_AMNESTY_DURATION = 2 * 1000 * 60; // How often until a buffering event expires.
|
||||||
@ -63,6 +63,14 @@ class LatencyCompensator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let proposedPlaybackRate = bandwidthRatio * 0.2;
|
||||||
|
console.log('proposed rate', proposedPlaybackRate, this.running);
|
||||||
|
|
||||||
|
proposedPlaybackRate = Math.max(
|
||||||
|
Math.min(proposedPlaybackRate, MAX_SPEEDUP_RATE),
|
||||||
|
1.0
|
||||||
|
);
|
||||||
|
console.log('playback rate', proposedPlaybackRate, this.running);
|
||||||
try {
|
try {
|
||||||
const segment = getCurrentlyPlayingSegment(tech);
|
const segment = getCurrentlyPlayingSegment(tech);
|
||||||
if (!segment) {
|
if (!segment) {
|
||||||
@ -85,7 +93,7 @@ class LatencyCompensator {
|
|||||||
const latency = now - segmentTime;
|
const latency = now - segmentTime;
|
||||||
|
|
||||||
if (latency > this.maxLatencyThreshold) {
|
if (latency > this.maxLatencyThreshold) {
|
||||||
this.start();
|
this.start(proposedPlaybackRate);
|
||||||
} else if (latency < this.minLatencyThreshold) {
|
} else if (latency < this.minLatencyThreshold) {
|
||||||
this.stop();
|
this.stop();
|
||||||
}
|
}
|
||||||
@ -94,13 +102,13 @@ class LatencyCompensator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start(rate = 1.0) {
|
||||||
if (this.running || this.disabled) {
|
if (this.inTimeout || this.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.running = true;
|
this.running = true;
|
||||||
this.player.playbackRate(SPEEDUP_RATE);
|
this.player.playbackRate(rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
@ -129,7 +137,6 @@ class LatencyCompensator {
|
|||||||
endTimeout() {
|
endTimeout() {
|
||||||
clearTimeout(this.timeoutTimer);
|
clearTimeout(this.timeoutTimer);
|
||||||
this.inTimeout = false;
|
this.inTimeout = false;
|
||||||
this.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePlaying() {
|
handlePlaying() {
|
||||||
|
@ -4,6 +4,7 @@ import videojs from '/js/web_modules/videojs/dist/video.min.js';
|
|||||||
import { getLocalStorage, setLocalStorage } from '../utils/helpers.js';
|
import { getLocalStorage, setLocalStorage } from '../utils/helpers.js';
|
||||||
import { PLAYER_VOLUME, URL_STREAM } from '../utils/constants.js';
|
import { PLAYER_VOLUME, URL_STREAM } from '../utils/constants.js';
|
||||||
import PlaybackMetrics from '../metrics/playback.js';
|
import PlaybackMetrics from '../metrics/playback.js';
|
||||||
|
import LatencyCompensator from './latencyCompensator.js';
|
||||||
|
|
||||||
const VIDEO_ID = 'video';
|
const VIDEO_ID = 'video';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user