Skip to content

Commit

Permalink
fix: Reject Opus encrypted on Firefox Android (#6115)
Browse files Browse the repository at this point in the history
Fixes #6111
  • Loading branch information
avelad committed Jan 18, 2024
1 parent 34d75b1 commit 02689f8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/util/platform.js
Expand Up @@ -220,6 +220,15 @@ shaka.util.Platform = class {
!shaka.util.Platform.isLegacyEdge();
}

/**
* Check if the current platform is Firefox.
*
* @return {boolean}
*/
static isFirefox() {
return shaka.util.Platform.userAgentContains_('Firefox');
}

/**
* Check if the current platform is from Apple.
*
Expand Down Expand Up @@ -422,6 +431,15 @@ shaka.util.Platform = class {
return navigator.platform.toLowerCase().includes('windows');
}

/**
* Return true if the platform is a Android, regardless of the browser.
*
* @return {boolean}
*/
static isAndroid() {
return shaka.util.Platform.userAgentContains_('Android');
}

/**
* Check if the user agent contains a key. This is the best way we know of
* right now to detect platforms. If there is a better way, please send a
Expand Down
14 changes: 14 additions & 0 deletions lib/util/stream_utils.js
Expand Up @@ -370,6 +370,9 @@ shaka.util.StreamUtils = class {
const StreamUtils = shaka.util.StreamUtils;
const isXboxOne = shaka.util.Platform.isXboxOne();

const isFirefoxAndroid = shaka.util.Platform.isFirefox() &&
shaka.util.Platform.isAndroid();

manifest.variants = manifest.variants.filter((variant) => {
// See: https://github.com/shaka-project/shaka-player/issues/3860
const video = variant.video;
Expand Down Expand Up @@ -425,6 +428,17 @@ shaka.util.StreamUtils = class {

const audio = variant.audio;

// See: https://github.com/shaka-project/shaka-player/issues/6111
// It seems that Firefox Android reports that it supports
// Opus + Widevine, but it is not actually supported.
// It makes sense to drop early.
if (isFirefoxAndroid && audio && audio.encrypted &&
audio.codecs.toLowerCase().includes('opus')) {
shaka.log.debug('Dropping variant - not compatible with platform',
StreamUtils.getVariantSummaryString_(variant));
return false;
}

if (audio) {
const codecs = StreamUtils.getCorrectAudioCodecs_(audio.codecs);
const fullType = MimeUtils.getFullOrConvertedType(
Expand Down

0 comments on commit 02689f8

Please sign in to comment.