Skip to content

Commit

Permalink
fix: put devicePixelRatio behind useDevicePixelRatio option
Browse files Browse the repository at this point in the history
Port #785 to master
  • Loading branch information
gkatsev committed May 13, 2020
1 parent 8953c3a commit 83b6fa6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,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 @@ -252,7 +252,7 @@ export const simpleSelector = function(
* bandwidth variance
*/
export const lastBandwidthSelector = function() {
const pixelRatio = window.devicePixelRatio || 1;
const pixelRatio = this.useDevicePixelRatio ? window.devicePixelRatio || 1 : 1;

return simpleSelector(
this.playlists.master,
Expand All @@ -279,13 +279,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 @@ -425,6 +425,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 @@ -468,6 +469,7 @@ class HlsHandler extends Component {
// grab options passed to player.src
[
'withCredentials',
'useDevicePixelRatio',
'limitRenditionByPlayerDimensions',
'bandwidth',
'smoothQualityChange',
Expand All @@ -483,6 +485,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 @@ -26,6 +26,11 @@ const options = [{
default: true,
test: false,
alt: false
}, {
name: 'useDevicePixelRatio',
default: false,
test: true,
alt: false
}, {
name: 'bandwidth',
default: 4194304,
Expand Down

0 comments on commit 83b6fa6

Please sign in to comment.