Skip to content

Commit

Permalink
Lower minPlaybackRateChange for non Safari browsers depending on the …
Browse files Browse the repository at this point in the history
…maximum catchup rate. Otherwise the target live delay is not reached for low catchup rates. (Dash-Industry-Forum#4020)
  • Loading branch information
dsilhavy authored Aug 9, 2022
1 parent 4534b0f commit 373dc51
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
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

0 comments on commit 373dc51

Please sign in to comment.