-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
videoPreference
config option for HDR/SDR VIDEO-RANGE selection…
… and priority Resolves #2489
- Loading branch information
1 parent
202ba5f
commit a297c2b
Showing
7 changed files
with
145 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { type VideoRange, VideoRangeValues } from '../types/level'; | ||
import type { VideoSelectionOption } from '../types/media-playlist'; | ||
|
||
/** | ||
* @returns Whether we can detect and validate HDR capability within the window context | ||
*/ | ||
export function isHdrSupported() { | ||
if (typeof matchMedia === 'function') { | ||
const mediaQueryList = matchMedia('(dynamic-range: high)'); | ||
const badQuery = matchMedia('bad query'); | ||
if (mediaQueryList.media !== badQuery.media) { | ||
return mediaQueryList.matches === true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Sanitizes inputs to return the active video selection options for HDR/SDR. | ||
* When both inputs are null: | ||
* | ||
* `{ preferHdr: false, allowedVideoRanges: [] }` | ||
* | ||
* When `currentVideoRange` non-null, maintain the active range: | ||
* | ||
* `{ preferHdr: currentVideoRange !== 'SDR', allowedVideoRanges: [currentVideoRange] }` | ||
* | ||
* When VideoSelectionOption non-null: | ||
* | ||
* - Allow all video ranges if `allowedVideoRanges` unspecified. | ||
* - If `preferHdr` is non-null use the value to filter `allowedVideoRanges`. | ||
* - Else check window for HDR support and set `preferHdr` to the result. | ||
* | ||
* @param currentVideoRange | ||
* @param videoPreference | ||
*/ | ||
export function getVideoSelectionOptions( | ||
currentVideoRange: VideoRange | undefined, | ||
videoPreference: VideoSelectionOption | undefined, | ||
) { | ||
let preferHdr = false; | ||
let allowedVideoRanges: Array<VideoRange> = []; | ||
|
||
if (currentVideoRange) { | ||
preferHdr = currentVideoRange !== 'SDR'; | ||
allowedVideoRanges = [currentVideoRange]; | ||
} | ||
|
||
if (videoPreference) { | ||
allowedVideoRanges = | ||
videoPreference.allowedVideoRanges || VideoRangeValues.slice(0); | ||
preferHdr = | ||
videoPreference.preferHdr !== undefined | ||
? videoPreference.preferHdr | ||
: isHdrSupported(); | ||
|
||
if (preferHdr) { | ||
allowedVideoRanges = allowedVideoRanges.filter( | ||
(range: VideoRange) => range !== 'SDR', | ||
); | ||
} else { | ||
allowedVideoRanges = ['SDR']; | ||
} | ||
} | ||
|
||
return { | ||
preferHdr, | ||
allowedVideoRanges, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters