diff --git a/lib/media/drm_engine.js b/lib/media/drm_engine.js index ddc833fa43..33755e9bea 100644 --- a/lib/media/drm_engine.js +++ b/lib/media/drm_engine.js @@ -125,6 +125,9 @@ shaka.media.DrmEngine = class { /** @const {!shaka.util.Destroyer} */ this.destroyer_ = new shaka.util.Destroyer(() => this.destroyNow_()); + + /** @private {boolean} */ + this.srcEquals_ = false; } /** @override */ @@ -180,6 +183,7 @@ shaka.media.DrmEngine = class { this.config_ = null; this.onError_ = () => {}; this.playerInterface_ = null; + this.srcEquals_ = false; } /** @@ -193,6 +197,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. * @@ -351,7 +362,7 @@ shaka.media.DrmEngine = class { // We should get the decodingInfo results for the variants after we filling // in the drm infos, and before queryMediaKeys_(). await shaka.util.StreamUtils.getDecodingInfosForVariants(variants, - this.usePersistentLicenses_); + this.usePersistentLicenses_, this.srcEquals_); const hasDrmInfo = hadDrmInfo || Object.keys(this.config_.servers).length; // An unencrypted content is initialized. diff --git a/lib/player.js b/lib/player.js index b826a7591c..d0cc045662 100644 --- a/lib/player.js +++ b/lib/player.js @@ -2058,6 +2058,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 929daebbf7..6a7d4d00c7 100644 --- a/lib/util/stream_utils.js +++ b/lib/util/stream_utils.js @@ -423,7 +423,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 @@ -456,9 +456,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) { @@ -482,7 +484,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)); @@ -497,17 +499,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 f8802d1e72..d121031fcf 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); }); @@ -820,7 +836,7 @@ describe('StreamUtils', () => { }); await StreamUtils.getDecodingInfosForVariants(manifest.variants, - /* usePersistentLicenses= */false); + /* usePersistentLicenses= */false, /* srcEquals= */ false); shaka.util.StreamUtils.chooseCodecsAndFilterManifest(manifest, /* preferredVideoCodecs= */[],