Skip to content

Commit

Permalink
test: Codec tests no longer depend on browser support
Browse files Browse the repository at this point in the history
We no longer have to rely on browser support for a codec to check
Streamer support for a codec.  We can check the manifest right after
parsing, and ignore any playback errors.

This also adds a test case for PR #74 (HEVC support) which was too
difficult to add before this refactor.

Change-Id: I37edb8ff7c94134e74e7a86f85c5b44bf4b38e24
  • Loading branch information
joeyparrish committed Jun 8, 2021
1 parent d154fc7 commit 89254b4
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"karma-jasmine": "^2.0.1",
"karma-junit-reporter": "^1.2.0",
"karma-spec-reporter": "^0.0.32",
"shaka-player": "^3.0.4"
"shaka-player": "^3.1.0"
},
"repository": {
"type": "git",
Expand Down
72 changes: 62 additions & 10 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,40 @@ function drmTests(manifestUrl, format) {
}

function codecTests(manifestUrl, format) {
// Returns the audio codecs and video codecs, in that order.
// Will not fail due to a lack of browser support for any codec.
async function getAudioAndVideoCodecs(manifestUrl) {
// In case the browser can't play it, check the manifest early in the
// loading of the content. We should at least be able to check the tracks
// before they are filtered out.
let codecs = null;
player.addEventListener('manifestparsed', () => {
const trackList = player.getVariantTracks();
const audioCodecList = trackList.map(track => track.audioCodec)
.filter((x) => x != null);
const videoCodecList = trackList.map(track => track.videoCodec)
.filter((x) => x != null);
codecs = audioCodecList.concat(videoCodecList);
});

try {
await player.load(manifestUrl);
} catch (error) {
// It's fine if the browser can't play any given codec.
// Most browsers won't play HEVC, for example, as of 2021-06-08.
// Any other error should be propagated up and fail the test.
if (error.code != shaka.util.Error.Code.CONTENT_UNSUPPORTED_BY_BROWSER) {
throw error;
}
}

// Ensure that our event handler fired. If not, fail the test.
if (codecs == null) {
throw new Error('manifestparsed event never fired!');
}
return codecs;
}

it('has output codecs matching the codecs in config ' + format, async () => {
const inputConfigDict = {
'inputs': [
Expand All @@ -550,13 +584,9 @@ function codecTests(manifestUrl, format) {
'video_codecs': ['h264'],
};
await startStreamer(inputConfigDict, pipelineConfigDict);
await player.load(manifestUrl);

const trackList = player.getVariantTracks();
const videoCodecList = trackList.map(track => track.videoCodec);
const audioCodecList = trackList.map(track => track.audioCodec);
expect(videoCodecList).toEqual(['avc1.4d400c']);
expect(audioCodecList).toEqual(['mp4a.40.2']);
const codecList = await getAudioAndVideoCodecs(manifestUrl);
expect(codecList).toEqual(['mp4a.40.2', 'avc1.4d400c']);
});

it('supports AV1 ' + format, async () => {
Expand All @@ -576,11 +606,33 @@ function codecTests(manifestUrl, format) {
'video_codecs': ['av1'],
};
await startStreamer(inputConfigDict, pipelineConfigDict);
await player.load(manifestUrl);

const trackList = player.getVariantTracks();
const videoCodecList = trackList.map(track => track.videoCodec);
expect(videoCodecList).toEqual(['av01.0.00M.08']);
const codecList = await getAudioAndVideoCodecs(manifestUrl);
expect(codecList).toEqual(['av01.0.00M.08']);
});

it('supports HEVC ' + format, async () => {
const inputConfigDict = {
'inputs': [
{
'name': TEST_DIR + 'Sintel.2010.720p.Small.mkv',
'media_type': 'video',
// Keep this test short by only encoding 1s of content.
'end_time': '0:01',
},
],
};
const pipelineConfigDict = {
'streaming_mode': 'vod',
'resolutions': ['144p'],
'video_codecs': ['hevc'],
};
await startStreamer(inputConfigDict, pipelineConfigDict);

let codecList = await getAudioAndVideoCodecs(manifestUrl);
// In HLS, we get "hvc1", but in DASH, it's "hev1". Accept both.
codecList = codecList.map((x) => x.replace('hvc1', 'hev1'));
expect(codecList).toEqual(['hev1.1.6.L60.90']);
});
}

Expand Down

0 comments on commit 89254b4

Please sign in to comment.