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(cast): Use cast platform APIs in MediaCapabilties polyfill #4727

Merged
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
aa973af
Initial fix with temp debug logs.
JulianDomingo Nov 17, 2022
0ee3554
Removed console debug logs after verifying eotf param on a 4K HDR Rok…
JulianDomingo Nov 18, 2022
4873f27
Updated comment on smpte2048 check.
JulianDomingo Nov 18, 2022
2d56c99
Merge branch 'main' into 4726-account-for-extended-mime-type-paramete…
JulianDomingo Nov 19, 2022
ef09c30
Added existence check for transferFunction parameter.
JulianDomingo Nov 19, 2022
51a96ea
Handled review comments (iter #0) and added unit tests. Also correcte…
JulianDomingo Nov 19, 2022
9588678
Fixed unit test linting errors.
JulianDomingo Nov 19, 2022
b60d59a
Restored cast namespace after polyfill test executions.
JulianDomingo Nov 19, 2022
bf81981
Use window.cast instead of cast for namespace checking.
JulianDomingo Nov 19, 2022
279b029
Sanity check to confirm issue with CDT() support on Selenium lab test…
JulianDomingo Nov 22, 2022
1dd0722
Updated canDisplayType() checks to guard against instable implementat…
JulianDomingo Nov 22, 2022
6a8cf51
Fall back to MediaSource.isTypeSupported() if cast APIs aren't availa…
JulianDomingo Nov 22, 2022
d0701ea
Removed window.cast to trigger CAST_API_UNAVAILABLE error for lab chr…
JulianDomingo Nov 23, 2022
720fe11
Verifying lab tests fail without check for cast.__platform__ and cast…
JulianDomingo Nov 23, 2022
8465a99
Re-instated deleted code from previous commit, which prevented cast l…
JulianDomingo Nov 23, 2022
be1065a
Handling PR review comments.
JulianDomingo Nov 29, 2022
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
80 changes: 71 additions & 9 deletions lib/polyfill/media_capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,37 +96,54 @@ shaka.polyfill.MediaCapabilities = class {
return res;
}

const videoConfig = mediaDecodingConfig['video'];
const audioConfig = mediaDecodingConfig['audio'];

if (mediaDecodingConfig.type == 'media-source') {
if (!shaka.util.Platform.supportsMediaSource()) {
return res;
}
// Use 'MediaSource.isTypeSupported' to check if the stream is supported.
if (mediaDecodingConfig['video']) {
const contentType = mediaDecodingConfig['video'].contentType;
const isSupported = MediaSource.isTypeSupported(contentType);
// Cast platforms will instead use canDisplayType() which accepts extended
// MIME type parameters.
// See: https://github.com/shaka-project/shaka-player/issues/4726
if (videoConfig) {
const contentType = videoConfig.contentType;
let isSupported;
if (shaka.util.Platform.isChromecast()) {
isSupported = shaka.polyfill.MediaCapabilities.canDisplayType_({
contentType,
width: videoConfig.width,
height: videoConfig.height,
frameRate: videoConfig.frameRate,
transferFunction: videoConfig.transferFunction,
});
} else {
isSupported = MediaSource.isTypeSupported(contentType);
}
if (!isSupported) {
return res;
}
}

if (mediaDecodingConfig['audio']) {
const contentType = mediaDecodingConfig['audio'].contentType;
if (audioConfig) {
const contentType = audioConfig.contentType;
const isSupported = MediaSource.isTypeSupported(contentType);
if (!isSupported) {
return res;
}
}
} else if (mediaDecodingConfig.type == 'file') {
if (mediaDecodingConfig['video']) {
const contentType = mediaDecodingConfig['video'].contentType;
if (videoConfig) {
const contentType = videoConfig.contentType;
const isSupported = shaka.util.Platform.supportsMediaType(contentType);
if (!isSupported) {
return res;
}
}

if (mediaDecodingConfig['audio']) {
const contentType = mediaDecodingConfig['audio'].contentType;
if (audioConfig) {
const contentType = audioConfig.contentType;
const isSupported = shaka.util.Platform.supportsMediaType(contentType);
if (!isSupported) {
return res;
Expand Down Expand Up @@ -217,6 +234,51 @@ shaka.polyfill.MediaCapabilities = class {
return res;
}

/**
* Checks if the given media parameters of the video or audio streams are
* supported by the platform.
JulianDomingo marked this conversation as resolved.
Show resolved Hide resolved
* @param {{
* contentType: string,
* width: (number|undefined),
* height: (number|undefined),
* frameRate: (number|undefined),
* transferFunction: (string|undefined)
* }} options canDisplayType() options.
* contentType: A valid MIME type and (optionally) a codecs parameter.
* width: Describes the stream horizontal resolution in pixels.
* height: Describes the stream vertical resolution in pixels.
* frameRate: Describes the frame rate of the stream.
* transferFunction: Describes the video transfer function supported by
* the rendering capabilities of the user agent.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all of these come from videoConfig, I feel like you should just pass that instead of creating a new record type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks

* @return {boolean} `true` when the stream can be displayed on a Cast device.
* @private
*/
static canDisplayType_({
contentType,
width = undefined,
height = undefined,
frameRate = undefined,
transferFunction = undefined,
}) {
if (!cast.__platform__) {
JulianDomingo marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
let displayType = contentType;
if (width && height) {
displayType += `; width=${width}; height=${height}`;
}
if (frameRate) {
displayType += `; framerate=${frameRate}`;
}
if (transferFunction && transferFunction.toLowerCase() === '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';
}
return cast.__platform__.canDisplayType(displayType);
}

/**
* A method for generating a key for the MediaKeySystemAccessRequests cache.
*
Expand Down