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

test: Add error listener & ec3 test in codec switching integration test #6486

Merged
merged 15 commits into from May 6, 2024
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
162 changes: 160 additions & 2 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 @@ -29,12 +31,20 @@ 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 () => {
Expand All @@ -46,7 +56,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 @@ -120,7 +130,7 @@ describe('Codec Switching', () => {
});
});

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 @@ -191,4 +201,152 @@ describe('Codec Switching', () => {
await player.unload();
});
});

describe('for audio aac -> ec3', () => {
it('can switch codecs RELOAD', async () => {
if (!MediaSource.isTypeSupported('audio/mp4; codecs="ec-3"')) {
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');

await player.unload();
});

it('can switch codecs SMOOTH', async () => {
if (!shaka.util.Platform.supportsSmoothCodecSwitching()) {
pending('Mediasource.ChangeType is not considered ' +
'reliable on this device');
}
if (!MediaSource.isTypeSupported('audio/mp4; codecs="ec-3"')) {
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, 1);

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');

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

describe('for audio ec3 -> aac', () => {
it('can switch codecs RELOAD', async () => {
if (!MediaSource.isTypeSupported('audio/mp4; codecs="ec-3"')) {
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');

await player.unload();
});

it('can switch codecs SMOOTH', async () => {
if (!shaka.util.Platform.supportsSmoothCodecSwitching()) {
pending('Mediasource.ChangeType is not considered ' +
'reliable on this device');
}
if (!MediaSource.isTypeSupported('audio/mp4; codecs="ec-3"')) {
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);

variants = player.getVariantTracks();

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

await player.unload();
});
});
});
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>