Skip to content

Commit

Permalink
fix: Fix AC-3 playback on Tizen 3.0 devices when transmuxing (#7972)
Browse files Browse the repository at this point in the history
Related to #7955
Also adds test for
#7969
  • Loading branch information
avelad committed Jan 29, 2025
1 parent ac3b8dd commit 933052e
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 9 deletions.
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ module.exports = (config) => {
{pattern: 'test/test/assets/7401/*', included: false},
{pattern: 'test/test/assets/6339/*', included: false},
{pattern: 'test/test/assets/dash-aes-128/*', included: false},
{pattern: 'test/test/assets/dash-audio-ac3/*', included: false},
{pattern: 'test/test/assets/dash-clearkey/*', included: false},
{pattern: 'test/test/assets/dash-mpd-alternate/*', included: false},
{pattern: 'test/test/assets/dash-vr/*', included: false},
Expand Down
7 changes: 6 additions & 1 deletion lib/transmuxer/ac3_transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ goog.require('shaka.util.Error');
goog.require('shaka.util.Id3Utils');
goog.require('shaka.util.ManifestParserUtils');
goog.require('shaka.util.Mp4Generator');
goog.require('shaka.util.Platform');
goog.require('shaka.util.Uint8ArrayUtils');


Expand Down Expand Up @@ -86,7 +87,11 @@ shaka.transmuxer.Ac3Transmuxer = class {
*/
convertCodecs(contentType, mimeType) {
if (this.isAc3Container_(mimeType)) {
return 'audio/mp4; codecs="ac-3"';
if (shaka.util.Platform.requiresEC3InitSegments()) {
return 'audio/mp4; codecs="ec-3"';
} else {
return 'audio/mp4; codecs="ac-3"';
}
}
return mimeType;
}
Expand Down
23 changes: 19 additions & 4 deletions lib/util/mp4_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ goog.provide('shaka.util.Mp4Generator');

goog.require('goog.asserts');
goog.require('shaka.util.ManifestParserUtils');
goog.require('shaka.util.Platform');
goog.require('shaka.util.Uint8ArrayUtils');


Expand Down Expand Up @@ -298,6 +299,20 @@ shaka.util.Mp4Generator = class {
stsd_(streamInfo) {
const Mp4Generator = shaka.util.Mp4Generator;
const ContentType = shaka.util.ManifestParserUtils.ContentType;
let audioCodec = 'aac';
if (streamInfo.codecs.includes('mp3')) {
audioCodec = 'mp3';
} else if (streamInfo.codecs.includes('ac-3')) {
if (shaka.util.Platform.requiresEC3InitSegments()) {
audioCodec = 'ec-3';
} else {
audioCodec = 'ac-3';
}
} else if (streamInfo.codecs.includes('ec-3')) {
audioCodec = 'ec-3';
} else if (streamInfo.codecs.includes('opus')) {
audioCodec = 'opus';
}
let bytes = new Uint8Array([]);
switch (streamInfo.type) {
case ContentType.VIDEO:
Expand All @@ -308,13 +323,13 @@ shaka.util.Mp4Generator = class {
}
break;
case ContentType.AUDIO:
if (streamInfo.codecs.includes('mp3')) {
if (audioCodec == 'mp3') {
bytes = this.mp3_(streamInfo);
} else if (streamInfo.codecs.includes('ac-3')) {
} else if (audioCodec == 'ac-3') {
bytes = this.ac3_(streamInfo);
} else if (streamInfo.codecs.includes('ec-3')) {
} else if (audioCodec == 'ec-3') {
bytes = this.ec3_(streamInfo);
} else if (streamInfo.codecs.includes('opus')) {
} else if (audioCodec == 'opus') {
bytes = this.opus_(streamInfo);
} else {
bytes = this.mp4a_(streamInfo);
Expand Down
79 changes: 79 additions & 0 deletions test/media/content_workarounds_integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

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

/** @type {!jasmine.Spy} */
let onErrorSpy;

/** @type {!HTMLVideoElement} */
let video;
/** @type {shaka.Player} */
let player;
/** @type {!shaka.util.EventManager} */
let eventManager;

let compiledShaka;

/** @type {!shaka.test.Waiter} */
let waiter;

beforeAll(async () => {
video = shaka.test.UiUtils.createVideoElement();
document.body.appendChild(video);
compiledShaka =
await shaka.test.Loader.loadShaka(getClientArg('uncompiled'));
});

beforeEach(async () => {
await shaka.test.TestScheme.createManifests(compiledShaka, '_compiled');
player = new compiledShaka.Player();
await player.attach(video);

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

// Grab event manager from the uncompiled library:
eventManager = new shaka.util.EventManager();
waiter = new shaka.test.Waiter(eventManager);
waiter.setPlayer(player);

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

afterEach(async () => {
eventManager.release();
await player.destroy();
});

afterAll(() => {
document.body.removeChild(video);
});

// Check that fakeEC3 workaround is applied on the platforms where it is
// needed.
it('supports AC-3 if platform supports it', async () => {
if (!await Util.isTypeSupported('audio/mp4; codecs="ac-3"')) {
pending('Codec AC-3 is not supported by the platform.');
}
await player.load('/base/test/test/assets/dash-audio-ac3/dash.mpd');
await video.play();
expect(player.isLive()).toBe(false);

// Wait for the video to start playback. If it takes longer than 10
// seconds, fail the test.
await waiter.waitForMovementOrFailOnTimeout(video, 10);

// Play for 5 seconds, but stop early if the video ends. If it takes
// longer than 30 seconds, fail the test.
await waiter.waitUntilPlayheadReachesOrFailOnTimeout(video, 5, 30);

await player.unload();
});
});
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 17 additions & 0 deletions test/test/assets/dash-audio-ac3/dash.mpd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--Generated with https://github.com/shaka-project/shaka-packager version v3.4.0-1f0a4d1-release-->
<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">
<Period id="0">
<AdaptationSet id="0" contentType="audio" startWithSAP="1" segmentAlignment="true">
<Representation id="0" bandwidth="195101" codecs="ac-3" mimeType="audio/mp4" audioSamplingRate="44100">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
<SegmentTemplate timescale="44100" initialization="audio_und_2c_192k_ac3_init.mp4" media="audio_und_2c_192k_ac3_$Number$.mp4" startNumber="1">
<SegmentTimeline>
<S t="0" d="89088"/>
<S t="89088" d="87312"/>
</SegmentTimeline>
</SegmentTemplate>
</Representation>
</AdaptationSet>
</Period>
</MPD>
4 changes: 0 additions & 4 deletions test/test/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,6 @@ shaka.test.Util = class {
const baseMimeType = MimeUtils.getBasicType(mimetype);
const codecs = StreamUtils.getCorrectAudioCodecs(
MimeUtils.getCodecs(mimetype), baseMimeType);
if (codecs == 'ac-3' && shaka.util.Platform.isTizen()) {
// AC3 is flaky in some Tizen devices, so we need omit it for now.
return false;
}
// AudioConfiguration
mediaDecodingConfig.audio = {
contentType: MimeUtils.getFullOrConvertedType(
Expand Down
4 changes: 4 additions & 0 deletions test/transmuxer/transmuxer_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ describe('Transmuxer Player', () => {
if (!await Util.isTypeSupported('audio/mp4; codecs="ac-3"')) {
pending('Codec AC-3 is not supported by the platform.');
}
// This tests is flaky in some Tizen devices, so we need omit it for now.
if (shaka.util.Platform.isTizen()) {
pending('Disabled on Tizen.');
}

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

0 comments on commit 933052e

Please sign in to comment.