Skip to content

Commit

Permalink
feat(MediaCap): Patch VP9 codec
Browse files Browse the repository at this point in the history
MediaCapabilities supports 'vp09...' codecs, but not 'vp9'. Translate
vp9 codec strings into 'vp09...', to allow such content to play with
mediaCapabilities enabled.

Change-Id: Iff7ddae379efb8a9f0766c89a62b85a325f81e93
  • Loading branch information
michellezhuogg committed Apr 29, 2021
1 parent e592d48 commit bf0644a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/polyfill/encryption_scheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ shaka.polyfill.EncryptionScheme = class {
};

// Install at a low priority so that other EME polyfills go first.
shaka.polyfill.register(shaka.polyfill.EncryptionScheme.install, -1);
shaka.polyfill.register(shaka.polyfill.EncryptionScheme.install, -2);
5 changes: 3 additions & 2 deletions lib/polyfill/media_capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,6 @@ shaka.polyfill.MediaCapabilities = class {
}
};


shaka.polyfill.register(shaka.polyfill.MediaCapabilities.install);
// Install at a lower priority than MediaSource polyfill, so that we have
// MediaSource available first.
shaka.polyfill.register(shaka.polyfill.MediaCapabilities.install, -1);
17 changes: 17 additions & 0 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ shaka.util.StreamUtils = class {
const allCodecs = video.codecs.split(',');
videoCodecs = shaka.util.ManifestParserUtils.guessCodecs(
ContentType.VIDEO, allCodecs);
videoCodecs = shaka.util.StreamUtils.patchVp9(videoCodecs);
const audioCodecs = shaka.util.ManifestParserUtils.guessCodecs(
ContentType.AUDIO, allCodecs);

Expand All @@ -462,6 +463,7 @@ shaka.util.StreamUtils = class {
spatialRendering: false,
};
}
videoCodecs = shaka.util.StreamUtils.patchVp9(videoCodecs);
const fullType = shaka.util.MimeUtils.getFullOrConvertedType(
video.mimeType, videoCodecs, ContentType.VIDEO);
// VideoConfiguration
Expand Down Expand Up @@ -591,6 +593,21 @@ shaka.util.StreamUtils = class {
return configs;
}

/**
* MediaCapabilities supports 'vp09...' codecs, but not 'vp9'. Translate vp9
* codec strings into 'vp09...', to allow such content to play with
* mediaCapabilities enabled.
*
* @param {string} codec
* @return {string}
*/
static patchVp9(codec) {
if (codec == 'vp9') {
return 'vp09.00.10.08';
}
return codec;
}


/**
* Alters the given Manifest to filter out any streams uncompatible with the
Expand Down
15 changes: 15 additions & 0 deletions test/util/stream_utils_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,21 @@ describe('StreamUtils', () => {
/* useMediaCapabilities= */ true);
expect(manifest.variants.length).toBe(1);
});

it('supports VP9 codec', async () => {
manifest = shaka.test.ManifestGenerator.generate((manifest) => {
manifest.addVariant(0, (variant) => {
variant.addVideo(1, (stream) => {
stream.mime('video/webm', 'vp9');
});
});
});

await shaka.util.StreamUtils.filterManifest(
fakeDrmEngine, /* currentVariant= */ null, manifest,
/* useMediaCapabilities= */ true);
expect(manifest.variants.length).toBe(1);
});
});

describe('chooseCodecsAndFilterManifest', () => {
Expand Down

0 comments on commit bf0644a

Please sign in to comment.