Skip to content

Commit

Permalink
fix: Fix cast support for HLG HDR (#7632)
Browse files Browse the repository at this point in the history
Also document what is recognized, how, and why those strings are used.
  • Loading branch information
joeyparrish committed Nov 19, 2024
1 parent 2f4d09d commit 4280979
Show file tree
Hide file tree
Showing 4 changed files with 462 additions and 231 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module.exports = {
'no-empty': ['error', {'allowEmptyCatch': true}],
'no-misleading-character-class': 'error',
'no-template-curly-in-string': 'error',
'no-fallthrough': ['error', {'allowEmptyCase': true}],
// TODO: Try to re-enable this if possible. Right now, it produces way too
// many false-positives with eslint 7. It worked well enough in eslint 5.
// 'require-atomic-updates': 'error',
Expand Down
41 changes: 36 additions & 5 deletions lib/polyfill/media_capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,43 @@ shaka.polyfill.MediaCapabilities = class {
if (videoConfig.framerate) {
displayType += `; framerate=${videoConfig.framerate}`;
}
if (videoConfig.transferFunction === 'pq') {
// A "PQ" transfer function indicates this is an HDR-capable stream;
// "smpte2084" is the published standard. We need to inform the platform
// this query is specifically for HDR.
displayType += '; eotf=smpte2084';

// Don't trust Closure types here. Although transferFunction is string or
// undefined, we don't want to count on the input type. A switch statement
// will, however, differentiate between null and undefined. So we default
// to a blank string.
const transferFunction = videoConfig.transferFunction || '';

// Based on internal sources. Googlers, see go/cast-hdr-queries for source.
switch (transferFunction) {
// The empty case falls through to SDR.
case '':
// These are the only 3 values defined by MCap as of November 2024.
case 'srgb':
// https://en.wikipedia.org/wiki/Standard-dynamic-range_video
// https://en.wikipedia.org/wiki/SRGB
// https://en.wikipedia.org/wiki/Rec._709
// This is SDR, standardized in BT 709.
// The platform recognizes "eotf=bt709", but we can also omit it.
break;

case 'pq':
// https://en.wikipedia.org/wiki/Perceptual_quantizer
// This HDR transfer function is standardized as SMPTE ST 2084.
displayType += '; eotf=smpte2084';
break;

case 'hlg':
// https://en.wikipedia.org/wiki/Hybrid_log%E2%80%93gamma
// This HDR transfer function is standardized as ARIB STD-B67.
displayType += '; eotf=arib-std-b67';
break;

default:
// An unrecognized transfer function. Reject this query.
return false;
}

let result = false;
if (displayType in shaka.polyfill.MediaCapabilities
.memoizedCanDisplayTypeRequests_) {
Expand Down
Loading

0 comments on commit 4280979

Please sign in to comment.