Skip to content

Commit 5b12bca

Browse files
aveladjoeyparrish
authored andcommitted
fix: Fix AC-3 playback on Tizen 3.0 devices when transmuxing (#7972)
Related to #7955 Also adds test for #7969
1 parent 2217fcf commit 5b12bca

File tree

10 files changed

+126
-9
lines changed

10 files changed

+126
-9
lines changed

karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ module.exports = (config) => {
260260
{pattern: 'test/test/assets/7401/*', included: false},
261261
{pattern: 'test/test/assets/6339/*', included: false},
262262
{pattern: 'test/test/assets/dash-aes-128/*', included: false},
263+
{pattern: 'test/test/assets/dash-audio-ac3/*', included: false},
263264
{pattern: 'test/test/assets/dash-clearkey/*', included: false},
264265
{pattern: 'test/test/assets/dash-vr/*', included: false},
265266
{pattern: 'test/test/assets/hls-aes-256/*', included: false},

lib/transmuxer/ac3_transmuxer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ goog.require('shaka.util.Error');
1414
goog.require('shaka.util.Id3Utils');
1515
goog.require('shaka.util.ManifestParserUtils');
1616
goog.require('shaka.util.Mp4Generator');
17+
goog.require('shaka.util.Platform');
1718
goog.require('shaka.util.Uint8ArrayUtils');
1819

1920

@@ -86,7 +87,11 @@ shaka.transmuxer.Ac3Transmuxer = class {
8687
*/
8788
convertCodecs(contentType, mimeType) {
8889
if (this.isAc3Container_(mimeType)) {
89-
return 'audio/mp4; codecs="ac-3"';
90+
if (shaka.util.Platform.requiresEC3InitSegments()) {
91+
return 'audio/mp4; codecs="ec-3"';
92+
} else {
93+
return 'audio/mp4; codecs="ac-3"';
94+
}
9095
}
9196
return mimeType;
9297
}

lib/util/mp4_generator.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ goog.provide('shaka.util.Mp4Generator');
88

99
goog.require('goog.asserts');
1010
goog.require('shaka.util.ManifestParserUtils');
11+
goog.require('shaka.util.Platform');
1112
goog.require('shaka.util.Uint8ArrayUtils');
1213

1314

@@ -298,6 +299,20 @@ shaka.util.Mp4Generator = class {
298299
stsd_(streamInfo) {
299300
const Mp4Generator = shaka.util.Mp4Generator;
300301
const ContentType = shaka.util.ManifestParserUtils.ContentType;
302+
let audioCodec = 'aac';
303+
if (streamInfo.codecs.includes('mp3')) {
304+
audioCodec = 'mp3';
305+
} else if (streamInfo.codecs.includes('ac-3')) {
306+
if (shaka.util.Platform.requiresEC3InitSegments()) {
307+
audioCodec = 'ec-3';
308+
} else {
309+
audioCodec = 'ac-3';
310+
}
311+
} else if (streamInfo.codecs.includes('ec-3')) {
312+
audioCodec = 'ec-3';
313+
} else if (streamInfo.codecs.includes('opus')) {
314+
audioCodec = 'opus';
315+
}
301316
let bytes = new Uint8Array([]);
302317
switch (streamInfo.type) {
303318
case ContentType.VIDEO:
@@ -308,13 +323,13 @@ shaka.util.Mp4Generator = class {
308323
}
309324
break;
310325
case ContentType.AUDIO:
311-
if (streamInfo.codecs.includes('mp3')) {
326+
if (audioCodec == 'mp3') {
312327
bytes = this.mp3_(streamInfo);
313-
} else if (streamInfo.codecs.includes('ac-3')) {
328+
} else if (audioCodec == 'ac-3') {
314329
bytes = this.ac3_(streamInfo);
315-
} else if (streamInfo.codecs.includes('ec-3')) {
330+
} else if (audioCodec == 'ec-3') {
316331
bytes = this.ec3_(streamInfo);
317-
} else if (streamInfo.codecs.includes('opus')) {
332+
} else if (audioCodec == 'opus') {
318333
bytes = this.opus_(streamInfo);
319334
} else {
320335
bytes = this.mp4a_(streamInfo);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*! @license
2+
* Shaka Player
3+
* Copyright 2016 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
describe('ContentWorkarounds', () => {
8+
const Util = shaka.test.Util;
9+
10+
/** @type {!jasmine.Spy} */
11+
let onErrorSpy;
12+
13+
/** @type {!HTMLVideoElement} */
14+
let video;
15+
/** @type {shaka.Player} */
16+
let player;
17+
/** @type {!shaka.util.EventManager} */
18+
let eventManager;
19+
20+
let compiledShaka;
21+
22+
/** @type {!shaka.test.Waiter} */
23+
let waiter;
24+
25+
beforeAll(async () => {
26+
video = shaka.test.UiUtils.createVideoElement();
27+
document.body.appendChild(video);
28+
compiledShaka =
29+
await shaka.test.Loader.loadShaka(getClientArg('uncompiled'));
30+
});
31+
32+
beforeEach(async () => {
33+
await shaka.test.TestScheme.createManifests(compiledShaka, '_compiled');
34+
player = new compiledShaka.Player();
35+
await player.attach(video);
36+
37+
// Disable stall detection, which can interfere with playback tests.
38+
player.configure('streaming.stallEnabled', false);
39+
40+
// Grab event manager from the uncompiled library:
41+
eventManager = new shaka.util.EventManager();
42+
waiter = new shaka.test.Waiter(eventManager);
43+
waiter.setPlayer(player);
44+
45+
onErrorSpy = jasmine.createSpy('onError');
46+
onErrorSpy.and.callFake((event) => fail(event.detail));
47+
eventManager.listen(player, 'error', Util.spyFunc(onErrorSpy));
48+
});
49+
50+
afterEach(async () => {
51+
eventManager.release();
52+
await player.destroy();
53+
});
54+
55+
afterAll(() => {
56+
document.body.removeChild(video);
57+
});
58+
59+
// Check that fakeEC3 workaround is applied on the platforms where it is
60+
// needed.
61+
it('supports AC-3 if platform supports it', async () => {
62+
if (!await Util.isTypeSupported('audio/mp4; codecs="ac-3"')) {
63+
pending('Codec AC-3 is not supported by the platform.');
64+
}
65+
await player.load('/base/test/test/assets/dash-audio-ac3/dash.mpd');
66+
await video.play();
67+
expect(player.isLive()).toBe(false);
68+
69+
// Wait for the video to start playback. If it takes longer than 10
70+
// seconds, fail the test.
71+
await waiter.waitForMovementOrFailOnTimeout(video, 10);
72+
73+
// Play for 5 seconds, but stop early if the video ends. If it takes
74+
// longer than 30 seconds, fail the test.
75+
await waiter.waitUntilPlayheadReachesOrFailOnTimeout(video, 5, 30);
76+
77+
await player.unload();
78+
});
79+
});
47.8 KB
Binary file not shown.
47.2 KB
Binary file not shown.
740 Bytes
Binary file not shown.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--Generated with https://github.com/shaka-project/shaka-packager version v3.4.0-1f0a4d1-release-->
3+
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 DASH-MPD.xsd" profiles="urn:mpeg:dash:profile:isoff-live:2011" minBufferTime="PT2S" type="static" mediaPresentationDuration="PT4S">
4+
<Period id="0">
5+
<AdaptationSet id="0" contentType="audio" startWithSAP="1" segmentAlignment="true">
6+
<Representation id="0" bandwidth="195101" codecs="ac-3" mimeType="audio/mp4" audioSamplingRate="44100">
7+
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
8+
<SegmentTemplate timescale="44100" initialization="audio_und_2c_192k_ac3_init.mp4" media="audio_und_2c_192k_ac3_$Number$.mp4" startNumber="1">
9+
<SegmentTimeline>
10+
<S t="0" d="89088"/>
11+
<S t="89088" d="87312"/>
12+
</SegmentTimeline>
13+
</SegmentTemplate>
14+
</Representation>
15+
</AdaptationSet>
16+
</Period>
17+
</MPD>

test/test/util/util.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,6 @@ shaka.test.Util = class {
330330
const baseMimeType = MimeUtils.getBasicType(mimetype);
331331
const codecs = StreamUtils.getCorrectAudioCodecs(
332332
MimeUtils.getCodecs(mimetype), baseMimeType);
333-
if (codecs == 'ac-3' && shaka.util.Platform.isTizen()) {
334-
// AC3 is flaky in some Tizen devices, so we need omit it for now.
335-
return false;
336-
}
337333
// AudioConfiguration
338334
mediaDecodingConfig.audio = {
339335
contentType: MimeUtils.getFullOrConvertedType(

test/transmuxer/transmuxer_integration.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,10 @@ describe('Transmuxer Player', () => {
401401
if (!await Util.isTypeSupported('audio/mp4; codecs="ac-3"')) {
402402
pending('Codec AC-3 is not supported by the platform.');
403403
}
404+
// This tests is flaky in some Tizen devices, so we need omit it for now.
405+
if (shaka.util.Platform.isTizen()) {
406+
pending('Disabled on Tizen.');
407+
}
404408

405409
// eslint-disable-next-line max-len
406410
await player.load('/base/test/test/assets/hls-ts-muxed-ac3-h264/media.m3u8');

0 commit comments

Comments
 (0)