Skip to content

Commit

Permalink
feat(MediaCap): Skip filtering by DrmEngine with MediaCap enabled
Browse files Browse the repository at this point in the history
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 shaka-project#1391
Closes shaka-project#3334

Change-Id: I34fbb3e11877f02cae1d435e9dbf274ce0e691dc
  • Loading branch information
michellezhuogg committed Apr 20, 2021
1 parent 7af44ef commit 0f0c940
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
7 changes: 3 additions & 4 deletions lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down
9 changes: 1 addition & 8 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
54 changes: 36 additions & 18 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
Expand All @@ -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) => {
Expand Down

0 comments on commit 0f0c940

Please sign in to comment.