From 0f0c9409c3f10848eec7a2626142e747528ba76e Mon Sep 17 00:00:00 2001 From: Michelle Zhuo Date: Mon, 19 Apr 2021 17:03:50 -0700 Subject: [PATCH] feat(MediaCap): Skip filtering by DrmEngine with MediaCap enabled When we use decodingInfo() with the drmInfo of the variants to get media keys, the decodingInfo result can tell us whether the variant's DRM is supported by the platform. Thus, filterManifestByDrm_() is no longer needed with MediaCapabilities enabled. Issue #1391 Closes #3334 Change-Id: I34fbb3e11877f02cae1d435e9dbf274ce0e691dc --- lib/offline/storage.js | 7 +++--- lib/util/stream_utils.js | 9 +------ test/player_unit.js | 54 ++++++++++++++++++++++++++-------------- 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/lib/offline/storage.js b/lib/offline/storage.js index bb1c804ab6..3f1c00067e 100644 --- a/lib/offline/storage.js +++ b/lib/offline/storage.js @@ -491,12 +491,11 @@ shaka.offline.Storage = class { manifest, config.offline.usePersistentLicense); } else { StreamUtils.filterManifestByMediaSource(manifest); + // Filter the manifest based on what we know our drm system will support + // playing later. + StreamUtils.filterManifestByDrm(manifest, drmEngine); } - // Filter the manifest based on what we know our drm system will support - // playing later. - StreamUtils.filterManifestByDrm(manifest, drmEngine); - // Gather all tracks. const allTracks = []; diff --git a/lib/util/stream_utils.js b/lib/util/stream_utils.js index 5a71739fcf..236b030f00 100644 --- a/lib/util/stream_utils.js +++ b/lib/util/stream_utils.js @@ -287,18 +287,11 @@ shaka.util.StreamUtils = class { */ static async filterManifest( drmEngine, currentVariant, manifest, useMediaCapabilities) { - // Once we use decodingInfo() with drmInfo of the variants to get media - // keys, the decodingInfo result can tell us whether the variant's DRM is - // supported by the platform. This way, filterManifestByDrm_() won't be - // needed. - // TODO: remove the first parameter 'drmEngine' and the function - // 'filterManifestByDrm_'. - shaka.util.StreamUtils.filterManifestByDrm(manifest, drmEngine); - if (useMediaCapabilities) { await shaka.util.StreamUtils.filterManifestByMediaCapabilities(manifest, manifest.offlineSessionIds.length > 0); } else { + shaka.util.StreamUtils.filterManifestByDrm(manifest, drmEngine); shaka.util.StreamUtils.filterManifestByMediaSource(manifest); } shaka.util.StreamUtils.filterManifestByCurrentVariant( diff --git a/test/player_unit.js b/test/player_unit.js index 1662a088d1..07599aeba9 100644 --- a/test/player_unit.js +++ b/test/player_unit.js @@ -2789,12 +2789,22 @@ describe('Player', () => { expect(tracks[0].id).toBe(4); }); - it('removes if key system does not support codec', async () => { + + for (const useMediaCapabilities of [true, false]) { + const isEnabled = useMediaCapabilities ? 'enabled' : 'disabled'; + it('removes if key system does not support codec with ' + + 'MediaCapabilities ' + isEnabled, async () => { + await testWithUnsupportedCodec(useMediaCapabilities); + }); + } + + async function testWithUnsupportedCodec(useMediaCapabilities) { manifest = shaka.test.ManifestGenerator.generate((manifest) => { manifest.addVariant(0, (variant) => { variant.addVideo(1, (stream) => { stream.encrypted = true; - stream.mimeType = 'video/unsupported'; + stream.mimeType = 'video'; + stream.codecs = 'unsupported'; stream.addDrmInfo('foo.bar'); }); }); @@ -2806,27 +2816,35 @@ describe('Player', () => { }); }); - // We must be careful that our video/unsupported was not filtered out - // because of MSE support. We are specifically testing EME-based - // filtering of codecs. - expect(MediaSource.isTypeSupported('video/unsupported')).toBe(true); - - const decodingResult = await navigator.mediaCapabilities.decodingInfo({ - 'video': {'contentType': 'video/unsupported'}, - }); - expect(decodingResult.supported).toBe(true); - - // Make sure that drm engine will reject the variant with an unsupported - // video mime type. - drmEngine.supportsVariant.and.callFake((variant) => { - return variant.video.mimeType != 'video/unsupported'; - }); + if (useMediaCapabilities) { + navigator.mediaCapabilities.decodingInfo = async (config) => { + await Promise.resolve(); + const videoType = config['video'] ? config['video'].contentType : ''; + if (videoType.includes('video') && + videoType.includes('unsupported')) { + return {supported: false}; + } else { + return {supported: true}; + } + }; + } else { + // We must be careful that our video/unsupported was not filtered out + // because of MSE support. We are specifically testing EME-based + // filtering of codecs. + expect(MediaSource.isTypeSupported('video/unsupported')).toBe(true); + // Make sure that drm engine will reject the variant with an unsupported + // video mime type. + drmEngine.supportsVariant.and.callFake((variant) => { + return variant.video.codecs != 'unsupported'; + }); + } + player.configure({useMediaCapabilities: useMediaCapabilities}); await player.load(fakeManifestUri, 0, fakeMimeType); const tracks = player.getVariantTracks(); expect(tracks.length).toBe(1); expect(tracks[0].id).toBe(1); - }); + } it('removes based on bandwidth', async () => { manifest = shaka.test.ManifestGenerator.generate((manifest) => {