Skip to content

Commit

Permalink
test: Add error listener & ec3 test in codec switching integration te…
Browse files Browse the repository at this point in the history
…st (#6486)

Adding EC-3 test case for codec switching integration suite, as some
platforms, i.e. Tizen 3 do not support Opus

---------

Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
  • Loading branch information
2 people authored and joeyparrish committed May 7, 2024
1 parent 4c19d20 commit a276dd2
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 9 deletions.
1 change: 1 addition & 0 deletions karma.conf.js
Expand Up @@ -234,6 +234,7 @@ module.exports = (config) => {
{pattern: 'test/**/*.js', included: false},
{pattern: 'test/test/assets/*', included: false},
{pattern: 'test/test/assets/dash-multi-codec/*', included: false},
{pattern: 'test/test/assets/dash-multi-codec-ec3/*', included: false},
{pattern: 'test/test/assets/3675/*', included: false},
{pattern: 'test/test/assets/6339/*', included: false},
{pattern: 'test/test/assets/dash-aes-128/*', included: false},
Expand Down
15 changes: 15 additions & 0 deletions lib/util/platform.js
Expand Up @@ -185,6 +185,17 @@ shaka.util.Platform = class {
return shaka.util.Platform.userAgentContains_('CrKey');
}

/**
* Check if the current platform is a Google Chromecast with Android
* (i.e. Chromecast with GoogleTV).
*
* @return {boolean}
*/
static isAndroidCastDevice() {
const Platform = shaka.util.Platform;
return Platform.isChromecast() && Platform.isAndroid();
}

/**
* Returns a major version number for Chrome, or Chromium-based browsers.
*
Expand Down Expand Up @@ -542,6 +553,10 @@ shaka.util.Platform = class {
Platform.isWebOS4() || Platform.isWebOS5()) {
return false;
}
// Older chromecasts without GoogleTV seem to not support SMOOTH properly.
if (Platform.isChromecast() && !Platform.isAndroidCastDevice()) {
return false;
}
// See: https://chromium-review.googlesource.com/c/chromium/src/+/4577759
if (Platform.isWindows() && Platform.isEdge()) {
return false;
Expand Down
176 changes: 167 additions & 9 deletions test/codec_switching/codec_switching_integration.js
Expand Up @@ -5,6 +5,8 @@
*/

describe('Codec Switching', () => {
const Util = shaka.test.Util;

/** @type {!HTMLVideoElement} */
let video;
/** @type {shaka.Player} */
Expand All @@ -17,6 +19,21 @@ describe('Codec Switching', () => {
/** @type {!shaka.test.Waiter} */
let waiter;

function isEc3Supported() {
if (!MediaSource.isTypeSupported('audio/mp4; codecs="ec-3"')) {
return false;
}
// It seems that EC3 on Edge Windows from github actions is not working
// (in the lab EC3 is working). The EC3 detection is currently hard-coded
// to true, which leads to a failure in GitHub's environment.
// We must enable this, once it is resolved:
// https://bugs.chromium.org/p/chromium/issues/detail?id=1450313
if (shaka.util.Platform.isWindows() && shaka.util.Platform.isEdge()) {
return false;
}
return true;
}

beforeAll(async () => {
video = shaka.test.UiUtils.createVideoElement();
document.body.appendChild(video);
Expand All @@ -29,15 +46,24 @@ describe('Codec Switching', () => {
player = new compiledShaka.Player();
await player.attach(video);

// Disable allow MediaSource recoveries, which can interfere with playback
// tests.
player.configure('streaming.allowMediaSourceRecoveries', false);

// Disable stall detection, which can interfere with playback tests.
player.configure('streaming.stallEnabled', false);

eventManager = new shaka.util.EventManager();
waiter = new shaka.test.Waiter(eventManager);
waiter.setPlayer(player);

const onErrorSpy = jasmine.createSpy('onError');
onErrorSpy.and.callFake((event) => fail(event.detail));
eventManager.listen(player, 'error', Util.spyFunc(onErrorSpy));
});

afterEach(async () => {
await player.unload();
eventManager.release();
await player.destroy();
});
Expand All @@ -46,7 +72,7 @@ describe('Codec Switching', () => {
document.body.removeChild(video);
});

describe('for audio and only-audio content', () => {
describe('for audio and only-audio content aac -> opus', () => {
it('can switch codecs RELOAD', async () => {
if (!MediaSource.isTypeSupported('audio/webm; codecs="opus"')) {
pending('Codec OPUS in WEBM is not supported by the platform.');
Expand Down Expand Up @@ -77,8 +103,6 @@ describe('Codec Switching', () => {
variants = player.getVariantTracks();

expect(variants.find((v) => !!v.active).language).toBe('es');

await player.unload();
});

it('can switch codecs SMOOTH', async () => {
Expand Down Expand Up @@ -115,12 +139,10 @@ describe('Codec Switching', () => {
variants = player.getVariantTracks();

expect(variants.find((v) => !!v.active).language).toBe('es');

await player.unload();
});
});

describe('for audio', () => {
describe('for audio opus -> aac', () => {
it('can switch codecs RELOAD', async () => {
if (!MediaSource.isTypeSupported('audio/webm; codecs="opus"')) {
pending('Codec OPUS in WEBM is not supported by the platform.');
Expand Down Expand Up @@ -150,8 +172,6 @@ describe('Codec Switching', () => {
variants = player.getVariantTracks();

expect(variants.find((v) => !!v.active).language).toBe('es');

await player.unload();
});

it('can switch codecs SMOOTH', async () => {
Expand Down Expand Up @@ -187,8 +207,146 @@ describe('Codec Switching', () => {
variants = player.getVariantTracks();

expect(variants.find((v) => !!v.active).language).toBe('es');
});
});

describe('for audio aac -> ec3', () => {
it('can switch codecs RELOAD', async () => {
if (!isEc3Supported()) {
pending('Codec EC3 in MP4 is not supported by the platform.');
}

// English is AAC MP4.
const preferredAudioLanguage = 'en';
player.configure({preferredAudioLanguage: preferredAudioLanguage});
player.configure('mediaSource.codecSwitchingStrategy',
shaka.config.CodecSwitchingStrategy.RELOAD);

await player.load(
'/base/test/test/assets/dash-multi-codec-ec3/dash.mpd', 1);
await video.play();
await waiter.waitForMovementOrFailOnTimeout(video, 10);

expect(player.isLive()).toBe(false);

let variants = player.getVariantTracks();

expect(variants.length).toBe(2);
expect(variants.find((v) => !!v.active).language).toBe('en');

// Spanish is EC3.
player.selectAudioLanguage('es');
await waiter.waitUntilPlayheadReachesOrFailOnTimeout(video, 2, 45);

variants = player.getVariantTracks();

expect(variants.find((v) => !!v.active).language).toBe('es');
});

it('can switch codecs SMOOTH', async () => {
if (!shaka.util.Platform.supportsSmoothCodecSwitching()) {
pending('Mediasource.ChangeType is not considered ' +
'reliable on this device');
}
if (!isEc3Supported()) {
pending('Codec EC3 in MP4 is not supported by the platform.');
}

// English is AAC MP4.
const preferredAudioLanguage = 'en';
player.configure({preferredAudioLanguage: preferredAudioLanguage});
player.configure('mediaSource.codecSwitchingStrategy',
shaka.config.CodecSwitchingStrategy.SMOOTH);

await player.load(
'/base/test/test/assets/dash-multi-codec-ec3/dash.mpd', 1);
await video.play();
await waiter.waitForMovementOrFailOnTimeout(video, 10);

expect(player.isLive()).toBe(false);

let variants = player.getVariantTracks();

expect(variants.length).toBe(2);
expect(variants.find((v) => !!v.active).language).toBe('en');

// Spanish is EC3.
player.selectAudioLanguage('es');
await waiter.waitUntilPlayheadReachesOrFailOnTimeout(video, 2, 45);

variants = player.getVariantTracks();

expect(variants.find((v) => !!v.active).language).toBe('es');
});
});

describe('for audio ec3 -> aac', () => {
it('can switch codecs RELOAD', async () => {
if (!isEc3Supported()) {
pending('Codec EC3 in MP4 is not supported by the platform.');
}

// Spanish is EC3.
const preferredAudioLanguage = 'es';
player.configure({preferredAudioLanguage: preferredAudioLanguage});
player.configure('mediaSource.codecSwitchingStrategy',
shaka.config.CodecSwitchingStrategy.RELOAD);

await player.load(
'/base/test/test/assets/dash-multi-codec-ec3/dash.mpd', 1);
await video.play();
await waiter.waitForMovementOrFailOnTimeout(video, 10);

expect(player.isLive()).toBe(false);

let variants = player.getVariantTracks();

expect(variants.length).toBe(2);
expect(variants.find((v) => !!v.active).language).toBe('es');

// English is AAC MP4.
player.selectAudioLanguage('en');
await waiter.waitUntilPlayheadReachesOrFailOnTimeout(video, 2, 45);

variants = player.getVariantTracks();

expect(variants.find((v) => !!v.active).language).toBe('en');
});

it('can switch codecs SMOOTH', async () => {
if (!shaka.util.Platform.supportsSmoothCodecSwitching()) {
pending('Mediasource.ChangeType is not considered ' +
'reliable on this device');
}
if (!isEc3Supported()) {
pending('Codec EC3 in MP4 is not supported by the platform.');
}

// Spanish is EC3.
const preferredAudioLanguage = 'es';
player.configure({preferredAudioLanguage: preferredAudioLanguage});
player.configure('mediaSource.codecSwitchingStrategy',
shaka.config.CodecSwitchingStrategy.SMOOTH);

await player.load(
'/base/test/test/assets/dash-multi-codec-ec3/dash.mpd', 1);
await video.play();
await waiter.waitForMovementOrFailOnTimeout(video, 10);

expect(player.isLive()).toBe(false);

let variants = player.getVariantTracks();

expect(variants.length).toBe(2);
expect(variants.find((v) => !!v.active).language).toBe('es');

// English is AAC MP4.
player.selectAudioLanguage('en');
await waiter.waitUntilPlayheadReachesOrFailOnTimeout(video, 2, 45);

await player.unload();
variants = player.getVariantTracks();

expect(variants.find((v) => !!v.active).language).toBe('en');
});
});
});
Binary file not shown.
Binary file not shown.
32 changes: 32 additions & 0 deletions test/test/assets/dash-multi-codec-ec3/dash.mpd
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<!-- Generated Fri Nov 11 14:05:52 2016 by Dolby Media Generator (built 15:30:29 Oct 11 2016) -->
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dolby="http://www.dolby.com/ns/online/DASH"
xmlns="urn:mpeg:dash:schema:mpd:2011" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011" type="static" mediaPresentationDuration="PT0H1M11.880S" minBufferTime="PT1.2S" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011">
<Period>
<!-- Audio -->
<AdaptationSet mimeType="audio/mp4" lang="es" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
<Accessibility schemeIdUri="urn:tva:metadata:cs:AudioPurposeCS:2007" value="6"/>
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="main" />
<Representation id="2" codecs="ec-3" bandwidth="256000" audioSamplingRate="48000">
<AudioChannelConfiguration schemeIdUri="tag:dolby.com,2014:dash:audio_channel_configuration:2011" value="F801"/>
<BaseURL>ChID_voices_6ch_256kbps_ddp.mp4</BaseURL>
<SegmentBase indexRange="603-1078">
<Initialization range="0-602"/>
</SegmentBase>
</Representation>
</AdaptationSet>
<!-- Audio -->
<AdaptationSet mimeType="audio/mp4" lang="en" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
<Accessibility schemeIdUri="urn:tva:metadata:cs:AudioPurposeCS:2007" value="6"/>
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="alternate" />
<Representation id="3" codecs="mp4a.40.2" bandwidth="640431" audioSamplingRate="48000">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="6"/>
<BaseURL>ChID_voices_6ch_640kbps_aac.mp4</BaseURL>
<SegmentBase indexRange="652-1127">
<Initialization range="0-651"/>
</SegmentBase>
</Representation>
</AdaptationSet>
</Period>
</MPD>

0 comments on commit a276dd2

Please sign in to comment.