From a44e9ab32acb5eebfc3e4f40095faa424e9db91c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Mon, 16 Aug 2021 08:41:19 +0200 Subject: [PATCH] Fix: Add support to file type in mediaCapabilities implementation (#3570) If it's srcEquals, the 'type' element of the input object when querying mediaCapabilities should be 'file'. Otherwise it should be 'media-source' . Issue: #3530 Change-Id: I8d54f5215f27c663ffdcfef0ec41182139d7f5d7 --- lib/media/drm_engine.js | 13 ++++++++++++- lib/player.js | 1 + lib/util/stream_utils.js | 13 ++++++++----- test/util/stream_utils_unit.js | 20 ++++++++++++++++++-- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/lib/media/drm_engine.js b/lib/media/drm_engine.js index 9c6879501b..4eddd74e17 100644 --- a/lib/media/drm_engine.js +++ b/lib/media/drm_engine.js @@ -126,6 +126,9 @@ shaka.media.DrmEngine = class { /** @const {!shaka.util.Destroyer} */ this.destroyer_ = new shaka.util.Destroyer(() => this.destroyNow_()); + + /** @private {boolean} */ + this.srcEquals_ = false; } /** @override */ @@ -181,6 +184,7 @@ shaka.media.DrmEngine = class { this.config_ = null; this.onError_ = () => {}; this.playerInterface_ = null; + this.srcEquals_ = false; } /** @@ -194,6 +198,13 @@ shaka.media.DrmEngine = class { this.config_ = config; } + /** + * @param {!boolean} value + */ + setSrcEquals(value) { + this.srcEquals_ = value; + } + /** * Initialize the drm engine for storing and deleting stored content. * @@ -356,7 +367,7 @@ shaka.media.DrmEngine = class { // in the drm infos, and before queryMediaKeys_(). if (useMediaCapabilities) { await shaka.util.StreamUtils.getDecodingInfosForVariants(variants, - this.usePersistentLicenses_); + this.usePersistentLicenses_, this.srcEquals_); } else { configsByKeySystem = this.prepareMediaKeyConfigsForVariants_(variants); diff --git a/lib/player.js b/lib/player.js index 1b3f9fbbf5..4fdada3f64 100644 --- a/lib/player.js +++ b/lib/player.js @@ -2069,6 +2069,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget { decodingInfos: [], }; + this.drmEngine_.setSrcEquals(/* srcEquals= */ true); await this.drmEngine_.initForPlayback( [variant], /* offlineSessionIds= */ []); await this.drmEngine_.attach(has.mediaElement); diff --git a/lib/util/stream_utils.js b/lib/util/stream_utils.js index 2eaed03cf7..4f765212db 100644 --- a/lib/util/stream_utils.js +++ b/lib/util/stream_utils.js @@ -337,7 +337,7 @@ shaka.util.StreamUtils = class { 'MediaCapabilities should be valid.'); await shaka.util.StreamUtils.getDecodingInfosForVariants( - manifest.variants, usePersistentLicenses); + manifest.variants, usePersistentLicenses, /* srcEquals= */ false); manifest.variants = manifest.variants.filter((variant) => { const video = variant.video; // See: https://github.com/google/shaka-player/issues/3380 @@ -410,9 +410,11 @@ shaka.util.StreamUtils = class { * * @param {!Array.} variants * @param {boolean} usePersistentLicenses + * @param {boolean} srcEquals * @exportDoc */ - static async getDecodingInfosForVariants(variants, usePersistentLicenses) { + static async getDecodingInfosForVariants(variants, usePersistentLicenses, + srcEquals) { const gotDecodingInfo = variants.some((variant) => variant.decodingInfos.length); if (gotDecodingInfo) { @@ -436,7 +438,7 @@ shaka.util.StreamUtils = class { for (const variant of variants) { /** @type {!Array.} */ const decodingConfigs = shaka.util.StreamUtils.getDecodingConfigs_( - variant, usePersistentLicenses); + variant, usePersistentLicenses, srcEquals); for (const config of decodingConfigs) { operations.push(getVariantDecodingInfos(variant, config)); @@ -451,17 +453,18 @@ shaka.util.StreamUtils = class { * results for each variant. * @param {!shaka.extern.Variant} variant * @param {boolean} usePersistentLicenses + * @param {boolean} srcEquals * @return {!Array.} * @private */ - static getDecodingConfigs_(variant, usePersistentLicenses) { + static getDecodingConfigs_(variant, usePersistentLicenses, srcEquals) { const audio = variant.audio; const video = variant.video; const ContentType = shaka.util.ManifestParserUtils.ContentType; /** @type {!MediaDecodingConfiguration} */ const mediaDecodingConfig = { - type: 'media-source', + type: srcEquals ? 'file' : 'media-source', }; if (video) { diff --git a/test/util/stream_utils_unit.js b/test/util/stream_utils_unit.js index da7534722d..2d5a209315 100644 --- a/test/util/stream_utils_unit.js +++ b/test/util/stream_utils_unit.js @@ -488,7 +488,23 @@ describe('StreamUtils', () => { }); await StreamUtils.getDecodingInfosForVariants(manifest.variants, - /* usePersistentLicenses= */false); + /* usePersistentLicenses= */false, /* srcEquals= */ false); + expect(manifest.variants.length).toBeTruthy(); + expect(manifest.variants[0].decodingInfos.length).toBe(1); + expect(manifest.variants[0].decodingInfos[0].supported).toBeTruthy(); + }); + + it('for srcEquals content', async () => { + manifest = shaka.test.ManifestGenerator.generate((manifest) => { + manifest.addVariant(0, (variant) => { + variant.addVideo(1, (stream) => { + stream.mime('video/mp4', 'avc1.4d400d'); + }); + }); + }); + + await StreamUtils.getDecodingInfosForVariants(manifest.variants, + /* usePersistentLicenses= */false, /* srcEquals= */ true); expect(manifest.variants.length).toBeTruthy(); expect(manifest.variants[0].decodingInfos.length).toBe(1); expect(manifest.variants[0].decodingInfos[0].supported).toBeTruthy(); @@ -517,7 +533,7 @@ describe('StreamUtils', () => { }); await StreamUtils.getDecodingInfosForVariants(manifest.variants, - /* usePersistentLicenses= */false); + /* usePersistentLicenses= */false, /* srcEquals= */ false); expect(manifest.variants.length).toBe(1); expect(manifest.variants[0].decodingInfos.length).toBe(0); });