Skip to content

Commit

Permalink
feat(ABR): Add preferNetworkInformationBandwidth config (#7090)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Jul 23, 2024
1 parent 1d5c7d2 commit 6425b91
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ shakaDemo.Config = class {
.addNumberInput_('Minimum time to switch',
'abr.minTimeToSwitch',
/* canBeDecimal= */ true,
/* canBeZero= */ true);
/* canBeZero= */ true)
.addBoolInput_('Prefer Network Information bandwidth',
'abr.preferNetworkInformationBandwidth');
this.addRetrictionsSection_('abr', 'Adaptation Restrictions');
}

Expand Down
10 changes: 9 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,8 @@ shaka.extern.AdsConfiguration;
* clearBufferSwitch: boolean,
* safeMarginSwitch: number,
* cacheLoadThreshold: number,
* minTimeToSwitch: number
* minTimeToSwitch: number,
* preferNetworkInformationBandwidth: boolean
* }}
*
* @property {boolean} enabled
Expand Down Expand Up @@ -2008,6 +2009,13 @@ shaka.extern.AdsConfiguration;
* <br>
* Defaults to <code>0</code> seconds except in Apple browsers whose default
* value is <code>0.5</code> seconds.
* @property {boolean} preferNetworkInformationBandwidth
* If true, use the Network Information API bandwidth estimation in the
* current AbrManager, if it is available in the browser environment. This
* way Shaka Player will never estimate the bandwidth and we will always
* trust the information provided by the browser.
* <br>
* Defaults to <code>false</code>.
* @exportDoc
*/
shaka.extern.AbrConfiguration;
Expand Down
5 changes: 5 additions & 0 deletions lib/abr/simple_abr_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ shaka.abr.SimpleAbrManager = class {
*/
getBandwidthEstimate() {
const defaultBandwidthEstimate = this.getDefaultBandwidth_();
if (navigator.connection && navigator.connection.downlink &&
this.config_.useNetworkInformation &&
this.config_.preferNetworkInformationBandwidth) {
return defaultBandwidthEstimate;
}
const bandwidthEstimate = this.bandwidthEstimator_.getBandwidthEstimate(
defaultBandwidthEstimate);
if (this.cmsdManager_) {
Expand Down
1 change: 1 addition & 0 deletions lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ shaka.util.PlayerConfiguration = class {
safeMarginSwitch: 0,
cacheLoadThreshold: 20,
minTimeToSwitch: shaka.util.Platform.isApple() ? 0.5 : 0,
preferNetworkInformationBandwidth: false,
};

const cmcd = {
Expand Down

0 comments on commit 6425b91

Please sign in to comment.