Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: put devicePixelRatio behind useDevicePixelRatio option #785

Merged
merged 3 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ This setting is `false` by default.
* Type: `boolean`
* can be used as an initialization option

##### useDevicePixelRatio
* Type: `boolean`
* can be used as an initialization option.

If true, this will take the device pixel ratio into account when doing rendition switching. This means that if you have a player with the width of `540px` in a high density display with a device pixel ratio of 2, a rendition of `1080p` will be allowed.
This setting is `false` by default.

When `limitRenditionByPlayerDimensions` is set to true, rendition
selection logic will take into account the player size and rendition
resolutions when making a decision.
Expand Down
5 changes: 3 additions & 2 deletions src/playlist-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export const simpleSelector = function(master,
* bandwidth variance
*/
export const lastBandwidthSelector = function() {
const pixelRatio = window.devicePixelRatio || 1;
const pixelRatio = this.useDevicePixelRatio ? window.devicePixelRatio || 1 : 1;

return simpleSelector(this.playlists.master,
this.systemBandwidth,
Expand All @@ -297,13 +297,14 @@ export const lastBandwidthSelector = function() {
*/
export const movingAverageBandwidthSelector = function(decay) {
let average = -1;
const pixelRatio = window.devicePixelRatio || 1;

if (decay < 0 || decay > 1) {
throw new Error('Moving average bandwidth decay must be between 0 and 1.');
}

return function() {
const pixelRatio = this.useDevicePixelRatio ? window.devicePixelRatio || 1 : 1;

if (average < 0) {
average = this.systemBandwidth;
}
Expand Down
3 changes: 3 additions & 0 deletions src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ class HlsHandler extends Component {
this.options_.withCredentials = this.options_.withCredentials || false;
this.options_.handleManifestRedirects = this.options_.handleManifestRedirects || false;
this.options_.limitRenditionByPlayerDimensions = this.options_.limitRenditionByPlayerDimensions === false ? false : true;
this.options_.useDevicePixelRatio = this.options_.useDevicePixelRatio || false;
this.options_.smoothQualityChange = this.options_.smoothQualityChange || false;
this.options_.useBandwidthFromLocalStorage =
typeof this.source_.useBandwidthFromLocalStorage !== 'undefined' ?
Expand Down Expand Up @@ -478,6 +479,7 @@ class HlsHandler extends Component {
// grab options passed to player.src
[
'withCredentials',
'useDevicePixelRatio',
'limitRenditionByPlayerDimensions',
'bandwidth',
'smoothQualityChange',
Expand All @@ -492,6 +494,7 @@ class HlsHandler extends Component {
});

this.limitRenditionByPlayerDimensions = this.options_.limitRenditionByPlayerDimensions;
this.useDevicePixelRatio = this.options_.useDevicePixelRatio;
}
/**
* called when player.src gets called, handle a new source
Expand Down
5 changes: 5 additions & 0 deletions test/configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ const options = [{
default: true,
test: false,
alt: false
}, {
name: 'useDevicePixelRatio',
default: false,
test: true,
alt: false
}, {
name: 'bandwidth',
default: 4194304,
Expand Down