Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions src/main_thread/tracks_store/tracks_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,10 @@ export default class TracksStore extends EventEmitter<ITracksStoreEvents> {
periodObj[bufferType].dispatcher = dispatcher;

dispatcher.addEventListener("noPlayableRepresentation", () => {
this.onNoPlayableRepresentation(period, bufferType);
const events = this.onNoPlayableRepresentation(period, bufferType);
for (const event of events) {
this.trigger("noPlayableTrack", event);
}
});
dispatcher.addEventListener("noPlayableLockedRepresentation", () => {
// TODO check that it doesn't already lead to segment loading or MediaSource
Expand Down Expand Up @@ -651,23 +654,27 @@ export default class TracksStore extends EventEmitter<ITracksStoreEvents> {
}

// Check that we're not both disabling audio and video here
if (storedSettings === null) {
const periodItem = getPeriodItem(this._storedPeriodInfo, period.id);
if (periodItem !== undefined) {
const hasNoTrackAtAll = ["audio" as const, "video" as const].every(
(ttype) => periodItem[ttype].storedSettings === null,
);
if (hasNoTrackAtAll) {
const err = new MediaError(
"NO_AUDIO_VIDEO_TRACKS",
"No audio and no video tracks are set.",
// Use a setTimeout(..., 0) to let a time window for an audio/video track switch when
// receiving a "noPlayableTrack" event
setTimeout(() => {
if (storedSettings === null) {
const periodItem = getPeriodItem(this._storedPeriodInfo, period.id);
if (periodItem !== undefined) {
const hasNoTrackAtAll = ["audio" as const, "video" as const].every(
(ttype) => periodItem[ttype].storedSettings === null,
);
this.trigger("error", err);
this.dispose();
return [];
if (hasNoTrackAtAll) {
const err = new MediaError(
"NO_AUDIO_VIDEO_TRACKS",
"No audio and no video tracks are set.",
);
this.trigger("error", err);
this.dispose();
return [];
}
}
}
}
}, 0);

typeInfo.dispatcher?.updateTrack(storedSettings);
return noPlayableTrackToTrigger;
Expand Down
52 changes: 51 additions & 1 deletion tests/integration/scenarios/drm_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ describe("DRM: Basic use cases", function () {
...opts,
});
if (isNullOrUndefined(error)) {
await waitForPlayerState(player, "LOADED", ["LOADING"]);
try {
await waitForPlayerState(player, "LOADED", ["LOADING"]);
} catch (err) {
throw player.getError() ?? err;
}
expect(player.getError()).toBeNull();
} else {
await waitForPlayerState(player, "STOPPED", ["LOADING"]);
Expand Down Expand Up @@ -688,4 +692,50 @@ describe("DRM: Basic use cases", function () {
expect(player.getAudioRepresentation().id).toEqual("15-585f233f");
expect(player.getError()).toBeNull();
});

it("should let a time window for an audio track reset if no license for video can be fetched while audio is disabled", async function () {
lockLowestBitrates(player);
const noPlayableTracksReceived = [];
player.addEventListener("newAvailablePeriods", (periods) => {
expect(player.getVideoTrack(periods[0].id)).not.toBeNull();
player.disableAudioTrack(periods[0].id);
});
player.addEventListener("noPlayableTrack", (npt) => {
noPlayableTracksReceived.push(npt);
const period = player.getAvailablePeriods()[0];
player.setAudioTrack({
periodId: period.id,
trackId: player.getAvailableAudioTracks(period.id)[0].id,
});
});
// RxPlayer.LogLevel = "DEBUG";
await loadEncryptedContent({
onVideoTracksNotPlayable: "continue",
keySystems: [
{
type: "com.microsoft.playready",
onKeyOutputRestricted: "fallback",
getLicense: generateGetLicenseForFakeLicense({
failingKeyIds: {
"90953e096cb249a3a2607a5fefead499": {
fallbackOnLastTry: true,
},
"80399bf58a2140148053e27e748e98c0": {
fallbackOnLastTry: true,
},
"80399bf58a2140148053e27e748e98c1": {
fallbackOnLastTry: true,
},
},
}),
},
],
});
expect(player.getAvailableVideoTracks()).toEqual([]);
expect(noPlayableTracksReceived.length).toEqual(1);
expect(noPlayableTracksReceived[0].trackType).toEqual("video");
expect(noPlayableTracksReceived[0].period.id).toEqual(
player.getAvailablePeriods()[0].id,
);
});
});
5 changes: 1 addition & 4 deletions vitest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ export default defineConfig({
reporters: "dot",
include: [
// integration tests
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to remove that line

"tests/integration/scenarios/**/*.[jt]s?(x)",
"tests/integration/**/*.test.[jt]s?(x)",
// memory tests
"tests/memory/**/*.[jt]s?(x)",
"tests/integration/scenarios/**/drm_base.[jt]s?(x)",
],
globalSetup: "tests/globalSetup.mjs",
browser: getBrowserConfig(process.env.BROWSER_CONFIG ?? "chrome"),
Expand Down
Loading