diff --git a/lib/media/content_workarounds.js b/lib/media/content_workarounds.js index 22587b6d8a..e136031689 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();