Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix waiting for empty init datas #6292

Merged
merged 6 commits into from Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/media/drm_engine.js
Expand Up @@ -700,9 +700,12 @@ shaka.media.DrmEngine = class {
initDataOverride.initDataType, initDataOverride.initData);
}

// If we have no sessions, we need to resolve the promise right now or else
// it will never get resolved.
if (!initDatas.length) {
// If there were no sessions to load, we need to resolve the promise right
// now or else it will never get resolved.
// We determine this by checking areAllSessionsLoaded_, rather than checking
// the number of initDatas, since the newInitData method can reject init
// datas in some circumstances.
if (this.areAllSessionsLoaded_()) {
this.allSessionsLoaded_.resolve();
}

Expand Down
16 changes: 16 additions & 0 deletions test/media/drm_engine_unit.js
Expand Up @@ -163,6 +163,22 @@ describe('DrmEngine', () => {
});
});


describe('createOrLoad', () => {
it('does not hang when given empty init data for offline', async () => {
tweakDrmInfos((drmInfos) => {
// An empty uint8array, like we make for fairplay content.
drmInfos[0].initData = [
{initData: new Uint8Array(0), initDataType: 'cenc', keyId: null},
];
});
await drmEngine.initForStorage(
manifest.variants, /* usePersistentLicenses= */ false);
await drmEngine.createOrLoad();
expect(drmEngine.initialized()).toBe(true);
}, /* timeout= */ 1000);
});

describe('init', () => {
it('stops on first available key system', async () => {
// Accept both drm.abc and drm.def. Only one can be chosen.
Expand Down
3 changes: 2 additions & 1 deletion test/test/externs/jasmine.js
Expand Up @@ -467,8 +467,9 @@ var xdescribe = function(name, callback) {};
/**
* @param {string} name
* @param {jasmine.Callback} callback
* @param {number=} timeout
*/
var it = function(name, callback) {};
var it = function(name, callback, timeout) {};


/**
Expand Down