Skip to content

Commit

Permalink
fix: Fix incompatible codec is selected in Windows Edge for Widevine (#…
Browse files Browse the repository at this point in the history
…5831)

Fixes #4242
  • Loading branch information
avelad authored Oct 30, 2023
1 parent 64b12c1 commit 5aa3597
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 46 deletions.
2 changes: 1 addition & 1 deletion lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ shaka.offline.Storage = class {
// Filter the manifest based on what we know MediaCapabilities will be able
// to play later (no point storing something we can't play).
await shaka.util.StreamUtils.filterManifestByMediaCapabilities(
manifest, config.offline.usePersistentLicense);
drmEngine, manifest, config.offline.usePersistentLicense);

// Gather all tracks.
const allTracks = [];
Expand Down
10 changes: 1 addition & 9 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -5609,15 +5609,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
*/
async filterManifestWithStreamUtils_(manifest) {
goog.asserts.assert(manifest, 'Manifest should exist!');
goog.asserts.assert(this.video_, 'Must not be destroyed');

/** @type {?shaka.extern.Variant} */
const currentVariant = this.streamingEngine_ ?
this.streamingEngine_.getCurrentVariant() : null;

await shaka.util.StreamUtils.filterManifest(
this.drmEngine_, currentVariant, manifest,
this.config_.mediaSource.codecSwitchingStrategy);
await shaka.util.StreamUtils.filterManifest(this.drmEngine_, manifest);
this.checkPlayableVariants_(manifest);
}

Expand Down
34 changes: 25 additions & 9 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
goog.provide('shaka.util.StreamUtils');

goog.require('goog.asserts');
goog.require('shaka.config.CodecSwitchingStrategy');
goog.require('shaka.log');
goog.require('shaka.media.Capabilities');
goog.require('shaka.text.TextEngine');
Expand Down Expand Up @@ -328,14 +327,11 @@ shaka.util.StreamUtils = class {
* Alters the given Manifest to filter out any unplayable streams.
*
* @param {shaka.media.DrmEngine} drmEngine
* @param {?shaka.extern.Variant} currentVariant
* @param {shaka.extern.Manifest} manifest
* @param {shaka.config.CodecSwitchingStrategy=} codecSwitchingStrategy
*/
static async filterManifest(drmEngine, currentVariant, manifest,
codecSwitchingStrategy=shaka.config.CodecSwitchingStrategy.RELOAD) {
await shaka.util.StreamUtils.filterManifestByMediaCapabilities(manifest,
manifest.offlineSessionIds.length > 0);
static async filterManifest(drmEngine, manifest) {
await shaka.util.StreamUtils.filterManifestByMediaCapabilities(
drmEngine, manifest, manifest.offlineSessionIds.length > 0);
shaka.util.StreamUtils.filterTextStreams_(manifest);
await shaka.util.StreamUtils.filterImageStreams_(manifest);
}
Expand All @@ -345,18 +341,27 @@ shaka.util.StreamUtils = class {
* Alters the given Manifest to filter out any streams unsupported by the
* platform via MediaCapabilities.decodingInfo() API.
*
* @param {shaka.media.DrmEngine} drmEngine
* @param {shaka.extern.Manifest} manifest
* @param {boolean} usePersistentLicenses
*/
static async filterManifestByMediaCapabilities(
manifest, usePersistentLicenses) {
drmEngine, manifest, usePersistentLicenses) {
goog.asserts.assert(navigator.mediaCapabilities,
'MediaCapabilities should be valid.');

await shaka.util.StreamUtils.getDecodingInfosForVariants(
manifest.variants, usePersistentLicenses, /* srcEquals= */ false,
/** preferredKeySystems= */ []);

let keySystem = null;
if (drmEngine) {
const drmInfo = drmEngine.getDrmInfo();
if (drmInfo) {
keySystem = drmInfo.keySystem;
}
}

const ContentType = shaka.util.ManifestParserUtils.ContentType;
const Capabilities = shaka.media.Capabilities;
const ManifestParserUtils = shaka.util.ManifestParserUtils;
Expand Down Expand Up @@ -433,7 +438,18 @@ shaka.util.StreamUtils = class {
}

const supported = variant.decodingInfos.some((decodingInfo) => {
return decodingInfo.supported;
if (!decodingInfo.supported) {
return false;
}
if (keySystem) {
const keySystemAccess = decodingInfo.keySystemAccess;
if (keySystemAccess) {
if (keySystemAccess.keySystem != keySystem) {
return false;
}
}
}
return true;
});
// Filter out all unsupported variants.
if (!supported) {
Expand Down
36 changes: 9 additions & 27 deletions test/util/stream_utils_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,7 @@ describe('StreamUtils', () => {
});
});

const noVariant = null;
await shaka.util.StreamUtils.filterManifest(
fakeDrmEngine, noVariant, manifest,
shaka.config.CodecSwitchingStrategy.RELOAD);
await shaka.util.StreamUtils.filterManifest(fakeDrmEngine, manifest);

// Covers a regression in which we would remove streams with codecs.
// The last two streams should be removed because their full MIME types
Expand Down Expand Up @@ -672,10 +669,7 @@ describe('StreamUtils', () => {
});
});

const noVariant = null;
await shaka.util.StreamUtils.filterManifest(
fakeDrmEngine, noVariant, manifest,
shaka.config.CodecSwitchingStrategy.RELOAD);
await shaka.util.StreamUtils.filterManifest(fakeDrmEngine, manifest);

// Covers a regression in which we would remove streams with codecs.
// The first 4 streams should be there because they are always supported.
Expand Down Expand Up @@ -714,9 +708,7 @@ describe('StreamUtils', () => {
shaka.util.StreamUtils.filterManifestByCurrentVariant =
shaka.test.Util.spyFunc(filterManifestByCurrentVariantSpy);

await shaka.util.StreamUtils.filterManifest(
fakeDrmEngine, /* currentVariant= */ null, manifest,
shaka.config.CodecSwitchingStrategy.RELOAD);
await shaka.util.StreamUtils.filterManifest(fakeDrmEngine, manifest);

expect(filterManifestByCurrentVariantSpy).not.toHaveBeenCalled();
} finally {
Expand All @@ -738,9 +730,7 @@ describe('StreamUtils', () => {
});
});

await shaka.util.StreamUtils.filterManifest(
fakeDrmEngine, /* currentVariant= */ null, manifest,
shaka.config.CodecSwitchingStrategy.RELOAD);
await shaka.util.StreamUtils.filterManifest(fakeDrmEngine, manifest);

// Covers a regression in which we would remove streams with codecs.
// The last two streams should be removed because their full MIME types
Expand All @@ -766,9 +756,7 @@ describe('StreamUtils', () => {
});
});

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

Expand All @@ -784,9 +772,7 @@ describe('StreamUtils', () => {
});
});

await shaka.util.StreamUtils.filterManifest(
fakeDrmEngine, /* currentVariant= */ null, manifest,
shaka.config.CodecSwitchingStrategy.RELOAD);
await shaka.util.StreamUtils.filterManifest(fakeDrmEngine, manifest);

expect(manifest.variants.length).toBe(1);
});
Expand All @@ -808,8 +794,7 @@ describe('StreamUtils', () => {
});
});

await shaka.util.StreamUtils.filterManifest(
fakeDrmEngine, /* currentVariant= */ null, manifest);
await shaka.util.StreamUtils.filterManifest(fakeDrmEngine, manifest);

expect(manifest.variants.length).toBe(2);
});
Expand All @@ -831,8 +816,7 @@ describe('StreamUtils', () => {
});
});

await shaka.util.StreamUtils.filterManifest(
fakeDrmEngine, /* currentVariant= */ null, manifest);
await shaka.util.StreamUtils.filterManifest(fakeDrmEngine, manifest);

expect(manifest.variants.length).toBe(2);
});
Expand All @@ -849,9 +833,7 @@ describe('StreamUtils', () => {
});
});

await shaka.util.StreamUtils.filterManifest(
fakeDrmEngine, /* currentVariant= */ null, manifest,
shaka.config.CodecSwitchingStrategy.RELOAD);
await shaka.util.StreamUtils.filterManifest(fakeDrmEngine, manifest);

expect(manifest.variants.length).toBe(1);
});
Expand Down

0 comments on commit 5aa3597

Please sign in to comment.