From 006de0ccbb2237ad240058bbe35300452c49e2ce Mon Sep 17 00:00:00 2001 From: stefangehrer <125955242+stefangehrer@users.noreply.github.com> Date: Wed, 29 Jan 2025 09:42:20 +0100 Subject: [PATCH] fix: Fix AC-3 playback on Tizen 3.0 devices (#7969) Fixes https://github.com/shaka-project/shaka-player/issues/7955 --- lib/media/content_workarounds.js | 78 ++++++++++++++++++++++++++ lib/media/media_source_engine.js | 13 +++++ lib/util/platform.js | 13 +++++ lib/util/stream_utils.js | 5 ++ test/media/media_source_engine_unit.js | 6 ++ 5 files changed, 115 insertions(+) diff --git a/lib/media/content_workarounds.js b/lib/media/content_workarounds.js index 6f4b1f7d70..424b04e0cd 100644 --- a/lib/media/content_workarounds.js +++ b/lib/media/content_workarounds.js @@ -347,6 +347,52 @@ shaka.media.ContentWorkarounds = class { boxView.setUint32(ContentWorkarounds.BOX_SIZE_OFFSET_, newBoxSize); } } + + /** + * Transform the init segment into a new init segment buffer that indicates + * EC-3 as audio codec instead of AC-3. Even though any EC-3 decoder should + * be able to decode AC-3 streams, there are platforms that do not accept + * AC-3 as codec. + * + * Should only be called for MP4 init segments, and only on platforms that + * need this workaround. Returns a new buffer containing the modified init + * segment. + * + * @param {!BufferSource} initSegmentBuffer + * @return {!Uint8Array} + */ + static fakeEC3(initSegmentBuffer) { + const ContentWorkarounds = shaka.media.ContentWorkarounds; + const initSegment = shaka.util.BufferUtils.toUint8(initSegmentBuffer); + const ancestorBoxes = []; + + const onSimpleAncestorBox = (box) => { + ancestorBoxes.push({start: box.start, size: box.size}); + shaka.util.Mp4Parser.children(box); + }; + + new shaka.util.Mp4Parser() + .box('moov', onSimpleAncestorBox) + .box('trak', onSimpleAncestorBox) + .box('mdia', onSimpleAncestorBox) + .box('minf', onSimpleAncestorBox) + .box('stbl', onSimpleAncestorBox) + .box('stsd', (box) => { + ancestorBoxes.push({start: box.start, size: box.size}); + const stsdBoxView = shaka.util.BufferUtils.toDataView( + initSegment, box.start); + for (let i=0; i { /** @type {!jasmine.Spy} */ let requiresEncryptionInfoInAllInitSegmentsSpy; /** @type {!jasmine.Spy} */ + let requiresEC3InitSegments; + /** @type {!jasmine.Spy} */ let fakeEncryptionSpy; /** @type {!shaka.media.MediaSourceEngine} */ @@ -214,6 +216,9 @@ describe('MediaSourceEngine', () => { requiresEncryptionInfoInAllInitSegmentsSpy = spyOn(shaka.util.Platform, 'requiresEncryptionInfoInAllInitSegments').and.returnValue(false); + requiresEC3InitSegments = spyOn(shaka.util.Platform, + 'requiresEC3InitSegments').and.returnValue(false); + fakeEncryptionSpy = spyOn(shaka.media.ContentWorkarounds, 'fakeEncryption') .and.callFake((data) => data + 100); @@ -544,6 +549,7 @@ describe('MediaSourceEngine', () => { describe('appendBuffer', () => { beforeEach(async () => { + requiresEC3InitSegments.and.returnValue(false); captureEvents(audioSourceBuffer, ['updateend', 'error']); captureEvents(videoSourceBuffer, ['updateend', 'error']); const initObject = new Map();