Skip to content

Commit a8bc7e2

Browse files
aveladtykus160
andauthored
feat(ABR): Add abr.removeLatencyFromFirstPacketTime config (#8446)
Co-authored-by: Wojciech Tyczyński <[email protected]>
1 parent d14384d commit a8bc7e2

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

demo/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ shakaDemo.Config = class {
343343
/* canBeDecimal= */ true,
344344
/* canBeZero= */ true)
345345
.addBoolInput_('Prefer Network Information bandwidth',
346-
'abr.preferNetworkInformationBandwidth');
346+
'abr.preferNetworkInformationBandwidth')
347+
.addBoolInput_('Remove latency from first packet time',
348+
'abr.removeLatencyFromFirstPacketTime');
347349
this.addRestrictionsSection_('abr', 'Adaptation Restrictions');
348350
}
349351

externs/shaka/player.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,8 @@ shaka.extern.AdsConfiguration;
22662266
* safeMarginSwitch: number,
22672267
* cacheLoadThreshold: number,
22682268
* minTimeToSwitch: number,
2269-
* preferNetworkInformationBandwidth: boolean
2269+
* preferNetworkInformationBandwidth: boolean,
2270+
* removeLatencyFromFirstPacketTime: boolean
22702271
* }}
22712272
*
22722273
* @property {boolean} enabled
@@ -2359,6 +2360,11 @@ shaka.extern.AdsConfiguration;
23592360
* trust the information provided by the browser.
23602361
* <br>
23612362
* Defaults to <code>false</code>.
2363+
* @property {boolean} removeLatencyFromFirstPacketTime
2364+
* If true, we remove the latency from first packet time. This time is
2365+
* used to calculate the real bandwidth.
2366+
* <br>
2367+
* Defaults to <code>true</code>.
23622368
* @exportDoc
23632369
*/
23642370
shaka.extern.AbrConfiguration;

lib/abr/simple_abr_manager.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,19 +340,24 @@ shaka.abr.SimpleAbrManager = class {
340340
* @export
341341
*/
342342
segmentDownloaded(deltaTimeMs, numBytes, allowSwitch, request, context) {
343-
if (deltaTimeMs < this.config_.cacheLoadThreshold) {
343+
let realTimeMs = deltaTimeMs;
344+
if (this.config_.removeLatencyFromFirstPacketTime &&
345+
request && request.packetNumber === 1 && request.timeToFirstByte) {
346+
realTimeMs = deltaTimeMs - request.timeToFirstByte;
347+
}
348+
if (realTimeMs < this.config_.cacheLoadThreshold) {
344349
// The time indicates that it could be a cache response, so we should
345350
// ignore this value.
346351
return;
347352
}
348353
shaka.log.v2('Segment downloaded:',
349354
'contentType=' + (request && request.contentType),
350-
'deltaTimeMs=' + deltaTimeMs,
355+
'deltaTimeMs=' + realTimeMs,
351356
'numBytes=' + numBytes,
352357
'lastTimeChosenMs=' + this.lastTimeChosenMs_,
353358
'enabled=' + this.enabled_);
354-
goog.asserts.assert(deltaTimeMs >= 0, 'expected a non-negative duration');
355-
this.bandwidthEstimator_.sample(deltaTimeMs, numBytes);
359+
goog.asserts.assert(realTimeMs >= 0, 'expected a non-negative duration');
360+
this.bandwidthEstimator_.sample(realTimeMs, numBytes);
356361

357362
if (allowSwitch && (this.lastTimeChosenMs_ != null) && this.enabled_) {
358363
this.suggestStreams_();

lib/util/player_configuration.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ shaka.util.PlayerConfiguration = class {
388388
cacheLoadThreshold: 20,
389389
minTimeToSwitch: shaka.util.Platform.isApple() ? 0.5 : 0,
390390
preferNetworkInformationBandwidth: false,
391+
removeLatencyFromFirstPacketTime: true,
391392
};
392393

393394
const cmcd = {

0 commit comments

Comments
 (0)