Skip to content

Commit

Permalink
Merge pull request #3765 from i8beef/master
Browse files Browse the repository at this point in the history
ignoreDevicePixelRatio option
  • Loading branch information
robwalch committed Feb 9, 2022
2 parents 0c5bd8b + 1549959 commit 5784545
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
23 changes: 12 additions & 11 deletions api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ export type HlsConfig = {
enableWorker: boolean;
enableSoftwareAES: boolean;
minAutoBitrate: number;
ignoreDevicePixelRatio: boolean;
loader: {
new (confg: HlsConfig): Loader<LoaderContext>;
};
Expand Down Expand Up @@ -2161,17 +2162,17 @@ export interface UserdataSample {
// Warnings were encountered during analysis:
//
// src/config.ts:163:3 - (ae-forgotten-export) The symbol "ILogger" needs to be exported by the entry point hls.d.ts
// src/config.ts:172:3 - (ae-forgotten-export) The symbol "AudioStreamController" needs to be exported by the entry point hls.d.ts
// src/config.ts:173:3 - (ae-forgotten-export) The symbol "AudioTrackController" needs to be exported by the entry point hls.d.ts
// src/config.ts:175:3 - (ae-forgotten-export) The symbol "SubtitleStreamController" needs to be exported by the entry point hls.d.ts
// src/config.ts:176:3 - (ae-forgotten-export) The symbol "SubtitleTrackController" needs to be exported by the entry point hls.d.ts
// src/config.ts:177:3 - (ae-forgotten-export) The symbol "TimelineController" needs to be exported by the entry point hls.d.ts
// src/config.ts:179:3 - (ae-forgotten-export) The symbol "EMEController" needs to be exported by the entry point hls.d.ts
// src/config.ts:182:3 - (ae-forgotten-export) The symbol "CMCDController" needs to be exported by the entry point hls.d.ts
// src/config.ts:184:3 - (ae-forgotten-export) The symbol "AbrController" needs to be exported by the entry point hls.d.ts
// src/config.ts:185:3 - (ae-forgotten-export) The symbol "BufferController" needs to be exported by the entry point hls.d.ts
// src/config.ts:186:3 - (ae-forgotten-export) The symbol "CapLevelController" needs to be exported by the entry point hls.d.ts
// src/config.ts:187:3 - (ae-forgotten-export) The symbol "FPSController" needs to be exported by the entry point hls.d.ts
// src/config.ts:173:3 - (ae-forgotten-export) The symbol "AudioStreamController" needs to be exported by the entry point hls.d.ts
// src/config.ts:174:3 - (ae-forgotten-export) The symbol "AudioTrackController" needs to be exported by the entry point hls.d.ts
// src/config.ts:176:3 - (ae-forgotten-export) The symbol "SubtitleStreamController" needs to be exported by the entry point hls.d.ts
// src/config.ts:177:3 - (ae-forgotten-export) The symbol "SubtitleTrackController" needs to be exported by the entry point hls.d.ts
// src/config.ts:178:3 - (ae-forgotten-export) The symbol "TimelineController" needs to be exported by the entry point hls.d.ts
// src/config.ts:180:3 - (ae-forgotten-export) The symbol "EMEController" needs to be exported by the entry point hls.d.ts
// src/config.ts:183:3 - (ae-forgotten-export) The symbol "CMCDController" needs to be exported by the entry point hls.d.ts
// src/config.ts:185:3 - (ae-forgotten-export) The symbol "AbrController" needs to be exported by the entry point hls.d.ts
// src/config.ts:186:3 - (ae-forgotten-export) The symbol "BufferController" needs to be exported by the entry point hls.d.ts
// src/config.ts:187:3 - (ae-forgotten-export) The symbol "CapLevelController" needs to be exported by the entry point hls.d.ts
// src/config.ts:188:3 - (ae-forgotten-export) The symbol "FPSController" needs to be exported by the entry point hls.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
8 changes: 8 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- [`Hls.DefaultConfig get/set`](#hlsdefaultconfig-getset)
- [`capLevelToPlayerSize`](#capleveltoplayersize)
- [`capLevelOnFPSDrop`](#caplevelonfpsdrop)
- ['ignoreDevicePixelRatio'](#ignoreDevicePixelRatio)
- [`debug`](#debug)
- [`autoStartLoad`](#autostartload)
- [`startPosition`](#startposition)
Expand Down Expand Up @@ -419,6 +420,13 @@ This configuration will be applied by default to all instances.
then the quality level is dropped and capped at this lower level.
- when set to false, levels will not be limited. All available levels could be used in auto-quality mode taking only bandwidth into consideration.

### `ignoreDevicePixelRatio`

(default: `false`)

- when set to true, calculations related to player size will ignore browser `devicePixelRatio`.
- when set to false, calculations related to player size will respect browser `devicePixelRatio`.

### `debug`

(default: `false`)
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export type HlsConfig = {
enableWorker: boolean;
enableSoftwareAES: boolean;
minAutoBitrate: number;
ignoreDevicePixelRatio: boolean;
loader: { new (confg: HlsConfig): Loader<LoaderContext> };
fetchSetup?: (context: LoaderContext, initParams: any) => Request;
xhrSetup?: (xhr: XMLHttpRequest, url: string) => void;
Expand Down Expand Up @@ -211,6 +212,7 @@ export const hlsDefaultConfig: HlsConfig = {
debug: false, // used by logger
capLevelOnFPSDrop: false, // used by fps-controller
capLevelToPlayerSize: false, // used by cap-level-controller
ignoreDevicePixelRatio: 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
17 changes: 10 additions & 7 deletions src/controller/cap-level-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,23 @@ class CapLevelController implements ComponentAPI {
}

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

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

static get contentScaleFactor(): number {
get contentScaleFactor(): number {
let pixelRatio = 1;
try {
pixelRatio = self.devicePixelRatio;
} catch (e) {
/* no-op */
if (!this.hls.config.ignoreDevicePixelRatio) {
try {
pixelRatio = self.devicePixelRatio;
} catch (e) {
/* no-op */
}
}

return pixelRatio;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/controller/cap-level-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('CapLevelController', function () {
it('gets width and height attributes when the media element is not in the DOM', function () {
media.setAttribute('width', 320);
media.setAttribute('height', 240);
const pixelRatio = CapLevelController.contentScaleFactor;
const pixelRatio = capLevelController.contentScaleFactor;
const bounds = capLevelController.getDimensions();
expect(bounds.width).to.equal(320);
expect(bounds.height).to.equal(240);
Expand All @@ -125,7 +125,7 @@ describe('CapLevelController', function () {
media.style.width = '1280px';
media.style.height = '720px';
document.querySelector('#test-fixture').appendChild(media);
const pixelRatio = CapLevelController.contentScaleFactor;
const pixelRatio = capLevelController.contentScaleFactor;
const bounds = capLevelController.getDimensions();
expect(bounds.width).to.equal(1280);
expect(bounds.height).to.equal(720);
Expand Down

0 comments on commit 5784545

Please sign in to comment.