Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower minPlaybackRateChange for non Safari browsers depending on the … #4020

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/low-latency/testplayer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ App.prototype._startIntervalHandler = function () {
self.domElements.metrics.latencyTag.innerHTML = currentLatency + ' secs';

var currentPlaybackRate = self.player.getPlaybackRate();
self.domElements.metrics.playbackrateTag.innerHTML = Math.round(currentPlaybackRate * 100) / 100;
self.domElements.metrics.playbackrateTag.innerHTML = Math.round(currentPlaybackRate * 1000) / 1000;

var currentBuffer = dashMetrics.getCurrentBufferLevel('video');
self.domElements.metrics.bufferTag.innerHTML = currentBuffer + ' secs';
Expand Down
2 changes: 1 addition & 1 deletion samples/low-latency/testplayer/testplayer.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ <h6>General</h6>
<div class="input-group input-group-sm mb-3">
<span class="input-group-text">Catch-up playback rate</span>
<input type="number" id="catchup-playback-rate" class="form-control" value="0.1"
step="0.1" max="0.5" min="0.0">
step="0.05" max="0.5" min="0.0">
</div>
</div>
<div class="col-md-3">
Expand Down
29 changes: 10 additions & 19 deletions src/streaming/controllers/CatchupController.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function CatchupController() {

let instance,
isCatchupSeekInProgress,
minPlaybackRateChange,
isSafari,
videoModel,
settings,
streamController,
Expand Down Expand Up @@ -114,11 +114,8 @@ function CatchupController() {

function _resetInitialSettings() {
isCatchupSeekInProgress = false;

// Detect safari browser (special behavior for low latency streams)
const ua = Utils.parseUserAgent();
const isSafari = ua && ua.browser && ua.browser.name && ua.browser.name.toLowerCase() === 'safari';
minPlaybackRateChange = isSafari ? 0.25 : 0.02;
isSafari = ua && ua.browser && ua.browser.name && ua.browser.name.toLowerCase() === 'safari';
}


Expand Down Expand Up @@ -219,8 +216,12 @@ function CatchupController() {
newRate = _calculateNewPlaybackRateDefault(liveCatchupPlaybackRate, currentLiveLatency, targetLiveDelay, bufferLevel, currentPlaybackRate);
}

// Obtain newRate and apply to video model
if (newRate) { // non-null
// We adjust the min change linear, depending on the maximum catchup rate. Default is 0.02 for rate 0.5.
// For Safari we stick to a fixed value because of https://bugs.webkit.org/show_bug.cgi?id=208142
const minPlaybackRateChange = isSafari ? 0.25 : 0.02 / (0.5 / liveCatchupPlaybackRate);

// Obtain newRate and apply to video model. Don't change playbackrate for small variations (don't overload element with playbackrate changes)
if (newRate && Math.abs(currentPlaybackRate - newRate) >= minPlaybackRateChange) { // non-null
logger.debug(`[CatchupController]: Setting playback rate to ${newRate}`);
videoModel.setPlaybackRate(newRate);
}
Expand Down Expand Up @@ -320,7 +321,7 @@ function CatchupController() {
* @return {number}
* @private
*/
function _calculateNewPlaybackRateDefault(liveCatchUpPlaybackRate, currentLiveLatency, liveDelay, bufferLevel, currentPlaybackRate) {
function _calculateNewPlaybackRateDefault(liveCatchUpPlaybackRate, currentLiveLatency, liveDelay, bufferLevel) {

// if we recently ran into an empty buffer we wait for the buffer to recover before applying a new rate
if (playbackStalled) {
Expand All @@ -344,11 +345,6 @@ function CatchupController() {
}
}

// don't change playbackrate for small variations (don't overload element with playbackrate changes)
if (Math.abs(currentPlaybackRate - newRate) <= minPlaybackRateChange) {
newRate = null;
}

return newRate;
}

Expand All @@ -363,7 +359,7 @@ function CatchupController() {
* @return {number}
* @private
*/
function _calculateNewPlaybackRateLolP(liveCatchUpPlaybackRate, currentLiveLatency, liveDelay, playbackBufferMin, bufferLevel, currentPlaybackRate) {
function _calculateNewPlaybackRateLolP(liveCatchUpPlaybackRate, currentLiveLatency, liveDelay, playbackBufferMin, bufferLevel) {
const cpr = liveCatchUpPlaybackRate;
let newRate;

Expand Down Expand Up @@ -400,11 +396,6 @@ function CatchupController() {
logger.debug('[LoL+ playback control_latency-based] latency: ' + currentLiveLatency + ', newRate: ' + newRate);
}

// don't change playbackrate for small variations (don't overload element with playbackrate changes)
if (Math.abs(currentPlaybackRate - newRate) <= minPlaybackRateChange) {
newRate = null;
}

return newRate
}

Expand Down