@@ -335,6 +335,52 @@ shaka.media.ContentWorkarounds = class {
335335 boxView . setUint32 ( ContentWorkarounds . BOX_SIZE_OFFSET_ , newBoxSize ) ;
336336 }
337337 }
338+
339+ /**
340+ * Transform the init segment into a new init segment buffer that indicates
341+ * EC-3 as audio codec instead of AC-3. Even though any EC-3 decoder should
342+ * be able to decode AC-3 streams, there are platforms that do not accept
343+ * AC-3 as codec.
344+ *
345+ * Should only be called for MP4 init segments, and only on platforms that
346+ * need this workaround. Returns a new buffer containing the modified init
347+ * segment.
348+ *
349+ * @param {!BufferSource } initSegmentBuffer
350+ * @return {!Uint8Array }
351+ */
352+ static fakeEC3 ( initSegmentBuffer ) {
353+ const ContentWorkarounds = shaka . media . ContentWorkarounds ;
354+ const initSegment = shaka . util . BufferUtils . toUint8 ( initSegmentBuffer ) ;
355+ const ancestorBoxes = [ ] ;
356+
357+ const onSimpleAncestorBox = ( box ) => {
358+ ancestorBoxes . push ( { start : box . start , size : box . size } ) ;
359+ shaka . util . Mp4Parser . children ( box ) ;
360+ } ;
361+
362+ new shaka . util . Mp4Parser ( )
363+ . box ( 'moov' , onSimpleAncestorBox )
364+ . box ( 'trak' , onSimpleAncestorBox )
365+ . box ( 'mdia' , onSimpleAncestorBox )
366+ . box ( 'minf' , onSimpleAncestorBox )
367+ . box ( 'stbl' , onSimpleAncestorBox )
368+ . box ( 'stsd' , ( box ) => {
369+ ancestorBoxes . push ( { start : box . start , size : box . size } ) ;
370+ const stsdBoxView = shaka . util . BufferUtils . toDataView (
371+ initSegment , box . start ) ;
372+ for ( let i = 0 ; i < box . size ; i ++ ) {
373+ const codecTag = stsdBoxView . getUint32 ( i ) ;
374+ if ( codecTag == ContentWorkarounds . BOX_TYPE_AC_3_ ) {
375+ stsdBoxView . setUint32 ( i , ContentWorkarounds . BOX_TYPE_EC_3_ ) ;
376+ } else if ( codecTag == ContentWorkarounds . BOX_TYPE_DAC3_ ) {
377+ stsdBoxView . setUint32 ( i , ContentWorkarounds . BOX_TYPE_DEC3_ ) ;
378+ }
379+ }
380+ } ) . parse ( initSegment ) ;
381+
382+ return initSegment ;
383+ }
338384} ;
339385
340386/**
@@ -470,3 +516,35 @@ shaka.media.ContentWorkarounds.BOX_TYPE_ENCV_ = 0x656e6376;
470516 * @private
471517 */
472518shaka . media . ContentWorkarounds . BOX_TYPE_ENCA_ = 0x656e6361 ;
519+
520+ /**
521+ * Box type for "ac-3".
522+ *
523+ * @const {number}
524+ * @private
525+ */
526+ shaka . media . ContentWorkarounds . BOX_TYPE_AC_3_ = 0x61632d33 ;
527+
528+ /**
529+ * Box type for "dac3".
530+ *
531+ * @const {number}
532+ * @private
533+ */
534+ shaka . media . ContentWorkarounds . BOX_TYPE_DAC3_ = 0x64616333 ;
535+
536+ /**
537+ * Box type for "ec-3".
538+ *
539+ * @const {number}
540+ * @private
541+ */
542+ shaka . media . ContentWorkarounds . BOX_TYPE_EC_3_ = 0x65632d33 ;
543+
544+ /**
545+ * Box type for "dec3".
546+ *
547+ * @const {number}
548+ * @private
549+ */
550+ shaka . media . ContentWorkarounds . BOX_TYPE_DEC3_ = 0x64656333 ;
0 commit comments