Skip to content

Commit

Permalink
fix: Fix waiting for empty init datas (#6292)
Browse files Browse the repository at this point in the history
Issue #6228
  • Loading branch information
theodab authored and avelad committed Apr 8, 2024
1 parent 1a62c24 commit e75505a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/media/drm_engine.js
Expand Up @@ -697,9 +697,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

0 comments on commit e75505a

Please sign in to comment.