Skip to content

Commit

Permalink
Possible solution to video-dev#3647, adds option to ignore devicePixe…
Browse files Browse the repository at this point in the history
…lRatio in calculation for stream level choice calculations
  • Loading branch information
i8beef committed Mar 19, 2021
1 parent aa50fdd commit 892153f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/config.ts
Expand Up @@ -45,6 +45,7 @@ export type BufferControllerConfig = {

export type CapLevelControllerConfig = {
capLevelToPlayerSize: boolean;
playerSizeIgnoreDevicePixelRatio: boolean;
};

export type DRMSystemOptions = {
Expand Down Expand Up @@ -192,6 +193,7 @@ export const hlsDefaultConfig: HlsConfig = {
debug: false, // used by logger
capLevelOnFPSDrop: false, // used by fps-controller
capLevelToPlayerSize: false, // used by cap-level-controller
playerSizeIgnoreDevicePixelRatio: false, // used by cap-level-controller
initialLiveManifestSize: 1, // used by stream-controller
maxBufferLength: 30, // used by stream-controller
backBufferLength: Infinity, // used by buffer-controller
Expand Down
8 changes: 6 additions & 2 deletions src/controller/cap-level-controller.ts
Expand Up @@ -215,11 +215,15 @@ class CapLevelController implements ComponentAPI {
}

get mediaWidth(): number {
return this.getDimensions().width * CapLevelController.contentScaleFactor;
return this.hls.config.playerSizeIgnoreDevicePixelRatio
? this.getDimensions().width
: this.getDimensions().width * CapLevelController.contentScaleFactor;
}

get mediaHeight(): number {
return this.getDimensions().height * CapLevelController.contentScaleFactor;
return this.hls.config.playerSizeIgnoreDevicePixelRatio
? this.getDimensions().height
: this.getDimensions().height * CapLevelController.contentScaleFactor;
}

static get contentScaleFactor(): number {
Expand Down
30 changes: 30 additions & 0 deletions src/hls.ts
Expand Up @@ -545,6 +545,36 @@ export default class Hls implements HlsEventEmitter {
}
}

/**
* Get the current setting for playerSizeIgnoreDevicePixelRatio
*
* @type {boolean}
*/
get playerSizeIgnoreDevicePixelRatio(): boolean {
return this.config.playerSizeIgnoreDevicePixelRatio;
}

/**
* set dynamically set playerSizeIgnoreDevicePixelRatio against (`CapLevelController`)
*
* @type {boolean}
*/
set playerSizeIgnoreDevicePixelRatio(shouldStartCapping: boolean) {
const newPlayerSizeIgnoreDevicePixelRatio = !!shouldStartCapping;

if (newPlayerSizeIgnoreDevicePixelRatio !== this.config.playerSizeIgnoreDevicePixelRatio) {
if (newPlayerSizeIgnoreDevicePixelRatio) {
this.capLevelController.startCapping(); // If capping occurs, nextLevelSwitch will happen based on size.
} else {
this.capLevelController.stopCapping();
this.autoLevelCapping = -1;
this.streamController.nextLevelSwitch(); // Now we're uncapped, get the next level asap.
}

this.config.playerSizeIgnoreDevicePixelRatio = newPlayerSizeIgnoreDevicePixelRatio;
}
}

/**
* Capping/max level value that should be used by automatic level selection algorithm (`ABRController`)
* @type {number}
Expand Down

0 comments on commit 892153f

Please sign in to comment.