Skip to content

Commit

Permalink
Fix: Add support to file type in mediaCapabilities implementation (#3570
Browse files Browse the repository at this point in the history
)

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
  • Loading branch information
Álvaro Velad Galván authored and joeyparrish committed Oct 12, 2021
1 parent 8746794 commit 13416e7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
13 changes: 12 additions & 1 deletion lib/media/drm_engine.js
Expand Up @@ -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 */
Expand Down Expand Up @@ -180,6 +183,7 @@ shaka.media.DrmEngine = class {
this.config_ = null;
this.onError_ = () => {};
this.playerInterface_ = null;
this.srcEquals_ = false;
}

/**
Expand All @@ -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.
*
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions lib/player.js
Expand Up @@ -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);
Expand Down
13 changes: 8 additions & 5 deletions lib/util/stream_utils.js
Expand Up @@ -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
Expand Down Expand Up @@ -456,9 +456,11 @@ shaka.util.StreamUtils = class {
*
* @param {!Array.<shaka.extern.Variant>} 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) {
Expand All @@ -482,7 +484,7 @@ shaka.util.StreamUtils = class {
for (const variant of variants) {
/** @type {!Array.<!MediaDecodingConfiguration>} */
const decodingConfigs = shaka.util.StreamUtils.getDecodingConfigs_(
variant, usePersistentLicenses);
variant, usePersistentLicenses, srcEquals);

for (const config of decodingConfigs) {
operations.push(getVariantDecodingInfos(variant, config));
Expand All @@ -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.<!MediaDecodingConfiguration>}
* @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) {
Expand Down
22 changes: 19 additions & 3 deletions test/util/stream_utils_unit.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -820,7 +836,7 @@ describe('StreamUtils', () => {
});

await StreamUtils.getDecodingInfosForVariants(manifest.variants,
/* usePersistentLicenses= */false);
/* usePersistentLicenses= */false, /* srcEquals= */ false);

shaka.util.StreamUtils.chooseCodecsAndFilterManifest(manifest,
/* preferredVideoCodecs= */[],
Expand Down

0 comments on commit 13416e7

Please sign in to comment.