Skip to content

Commit

Permalink
feat: Trace mediaCapabilities.decodingInfo
Browse files Browse the repository at this point in the history
This allows us to properly log EME access that originated through
MediaCapabilities.

Change-Id: I3edb81e9d8c5f4f5c622f33a7c133a740cc30aef
  • Loading branch information
joeyparrish committed Nov 4, 2021
1 parent 85326f9 commit 0efdef6
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
7 changes: 7 additions & 0 deletions eme-trace-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ const options = {

// These will be shimmed in place.
TraceAnything.traceMember(navigator, 'requestMediaKeySystemAccess', options);
TraceAnything.traceMember(
navigator.mediaCapabilities, 'decodingInfo', combineOptions(options, {
// The result from decodingInfo is a plain object. We need to dive into
// this field in particular to find MediaKeySystemAccess instances to
// trace.
exploreResultFields: ['keySystemAccess'],
}));

// These constructors are not used directly, but this registers them to the
// tracing system so that instances we find later will be shimmed.
Expand Down
65 changes: 62 additions & 3 deletions spec/eme-trace-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ describe('EME tracing', () => {
beforeEach(async () => {
mksa = await navigator.requestMediaKeySystemAccess(
keySystem, minimalConfigs);
emeLogger.calls.reset();
});

it('getConfiguration calls', async () => {
Expand Down Expand Up @@ -112,7 +111,6 @@ describe('EME tracing', () => {
const mksa = await navigator.requestMediaKeySystemAccess(
keySystem, minimalConfigs);
mediaKeys = await mksa.createMediaKeys();
emeLogger.calls.reset();
});

it('createSession calls', () => {
Expand Down Expand Up @@ -157,7 +155,6 @@ describe('EME tracing', () => {
keySystem, minimalConfigs);
const mediaKeys = await mksa.createMediaKeys();
session = mediaKeys.createSession('temporary');
emeLogger.calls.reset();
});

it('generateRequest calls', async () => {
Expand Down Expand Up @@ -345,4 +342,66 @@ describe('EME tracing', () => {
}));
});
});

describe('logs MediaKeys created via MediaCapabilities', () => {
const basicDecodingConfig = {
type: 'media-source',
video: {
contentType: 'video/mp4; codecs="avc1.42c01e"',
width: 256,
height: 110,
bitrate: 103942,
framerate: 24,
},
keySystemConfiguration: {
keySystem: 'com.widevine.alpha',
initDataType: 'cenc',
sessionTypes: ['temporary'],
},
};

it('decodingInfo calls', async () => {
const result = await navigator.mediaCapabilities.decodingInfo(
basicDecodingConfig);

expect(emeLogger).toHaveBeenCalledWith(
jasmine.objectContaining({
'type': TraceAnything.LogTypes.Method,
'className': 'MediaCapabilities',
'methodName': 'decodingInfo',
'args': [basicDecodingConfig],
'result': result,
}));
});

// This shows that even though the result of decodingInfo is a plain,
// untyped object, the TraceAnything configuration allows the engine to
// explore the keySystemAccess field and properly shim the EME classes that
// come out of decodingInfo.
it('MediaKeys instances', async () => {
const result = await navigator.mediaCapabilities.decodingInfo(
basicDecodingConfig);
expect(result.keySystemAccess).toBeTruthy();

const mediaKeys = await result.keySystemAccess.createMediaKeys();
const session = await mediaKeys.createSession('temporary');

expect(emeLogger).toHaveBeenCalledWith(
jasmine.objectContaining({
'type': TraceAnything.LogTypes.Method,
'className': 'MediaKeySystemAccess',
'methodName': 'createMediaKeys',
'args': [],
'result': mediaKeys,
}));
expect(emeLogger).toHaveBeenCalledWith(
jasmine.objectContaining({
'type': TraceAnything.LogTypes.Method,
'className': 'MediaKeys',
'methodName': 'createSession',
'args': ['temporary'],
'result': session,
}));
});
});
});

0 comments on commit 0efdef6

Please sign in to comment.