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: output-restricted event handling for unplayable streams #1305

Merged
merged 6 commits into from
Aug 17, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -1061,12 +1061,40 @@ class VhsHandler extends Component {
});

this.player_.tech_.on('keystatuschange', (e) => {
if (e.status === 'output-restricted') {
this.masterPlaylistController_.blacklistCurrentPlaylist({
playlist: this.masterPlaylistController_.media(),
message: `DRM keystatus changed to ${e.status}. Playlist will fail to play. Check for HDCP content.`,
blacklistDuration: Infinity
});
if (e.status !== 'output-restricted') {
return;
}

const masterPlaylist = this.masterPlaylistController_.master();

if (!masterPlaylist || !masterPlaylist.playlists) {
return;
}

const excludedHDPlaylists = [];

// Assume all HD streams are unplayable and exclude them from ABR selection
masterPlaylist.playlists.forEach(playlist => {
if (playlist && playlist.attributes && playlist.attributes.RESOLUTION &&
playlist.attributes.RESOLUTION.height >= 720) {
if (!playlist.excludeUntil || playlist.excludeUntil < Infinity) {

playlist.excludeUntil = Infinity;
excludedHDPlaylists.push(playlist);
}
}
});

if (excludedHDPlaylists.length) {
videojs.log.warn(
'DRM keystatus changed to "output-restricted." Removing the following HD playlists ' +
'that will most likely fail to play and clearing the buffer. ' +
'This may be due to HDCP restrictions on the stream and the capabilities of the current device.',
...excludedHDPlaylists
);

// Clear the buffer before switching playlists, since it may already contain unplayable segments
this.masterPlaylistController_.fastQualityChange_();
}
});

Expand Down
71 changes: 54 additions & 17 deletions test/videojs-http-streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4618,11 +4618,20 @@ QUnit.test('configures eme for HLS on source buffer creation', function(assert)
});

QUnit.test('eme handles keystatuschange where status is output-restricted', function(assert) {
const originalWarn = videojs.log.warn;
let warning = '';
let qualitySwitches = 0;

videojs.log.warn = (...text) => {
warning += [...text].join('');
};

this.player.eme = {
options: {
previousSetting: 1
}
};

this.player.src({
src: 'manifest/master.m3u8',
type: 'application/x-mpegURL',
Expand All @@ -4635,36 +4644,64 @@ QUnit.test('eme handles keystatuschange where status is output-restricted', func

this.clock.tick(1);

const media = {
attributes: {
CODECS: 'avc1.420015, mp4a.40.2c'
const playlists = [
{
attributes: {
RESOLUTION: {
width: 1280,
height: 720
}
}
},
contentProtection: {
keySystem1: {
pssh: 'test'
{
attributes: {
RESOLUTION: {
width: 1920,
height: 1080
}
}
},
{
attributes: {
RESOLUTION: {
width: 848,
height: 480
}
}
}
};
];

this.player.tech_.vhs.playlists = {
master: { playlists: [media] },
media: () => media
master: { playlists },
media: () => playlists[0]
};

const excludes = [];
this.player.tech_.vhs.masterPlaylistController_.master = () => {
return {
playlists
};
};

this.player.tech_.vhs.masterPlaylistController_.blacklistCurrentPlaylist = (exclude) => {
excludes.push(exclude);
this.player.tech_.vhs.masterPlaylistController_.fastQualityChange_ = () => {
qualitySwitches++;
};

this.player.tech_.vhs.masterPlaylistController_.sourceUpdater_.trigger('createdsourcebuffers');
this.player.tech_.trigger({type: 'keystatuschange', status: 'output-restricted'});

assert.deepEqual(excludes, [{
blacklistDuration: Infinity,
message: 'DRM keystatus changed to output-restricted. Playlist will fail to play. Check for HDCP content.',
playlist: undefined
}], 'excluded playlist');
assert.equal(playlists[0].excludeUntil, Infinity, 'first HD playlist excluded');
assert.equal(playlists[1].excludeUntil, Infinity, 'second HD playlist excluded');
assert.equal(playlists[2].excludeUntil, undefined, 'non-HD playlist not excluded');
assert.equal(qualitySwitches, 1, 'fastQualityChange_ called once');
assert.equal(
warning,
'DRM keystatus changed to "output-restricted." Removing the following HD playlists ' +
'that will most likely fail to play and clearing the buffer. ' +
'This may be due to HDCP restrictions on the stream and the capabilities of the current device.' +
[playlists[0], playlists[1]].join('')
);

videojs.log.warn = originalWarn;
});

QUnit.test('eme handles keystatuschange where status is usable', function(assert) {
Expand Down