@@ -347,6 +347,52 @@ shaka.media.ContentWorkarounds = class {
347
347
boxView . setUint32 ( ContentWorkarounds . BOX_SIZE_OFFSET_ , newBoxSize ) ;
348
348
}
349
349
}
350
+
351
+ /**
352
+ * Transform the init segment into a new init segment buffer that indicates
353
+ * EC-3 as audio codec instead of AC-3. Even though any EC-3 decoder should
354
+ * be able to decode AC-3 streams, there are platforms that do not accept
355
+ * AC-3 as codec.
356
+ *
357
+ * Should only be called for MP4 init segments, and only on platforms that
358
+ * need this workaround. Returns a new buffer containing the modified init
359
+ * segment.
360
+ *
361
+ * @param {!BufferSource } initSegmentBuffer
362
+ * @return {!Uint8Array }
363
+ */
364
+ static fakeEC3 ( initSegmentBuffer ) {
365
+ const ContentWorkarounds = shaka . media . ContentWorkarounds ;
366
+ const initSegment = shaka . util . BufferUtils . toUint8 ( initSegmentBuffer ) ;
367
+ const ancestorBoxes = [ ] ;
368
+
369
+ const onSimpleAncestorBox = ( box ) => {
370
+ ancestorBoxes . push ( { start : box . start , size : box . size } ) ;
371
+ shaka . util . Mp4Parser . children ( box ) ;
372
+ } ;
373
+
374
+ new shaka . util . Mp4Parser ( )
375
+ . box ( 'moov' , onSimpleAncestorBox )
376
+ . box ( 'trak' , onSimpleAncestorBox )
377
+ . box ( 'mdia' , onSimpleAncestorBox )
378
+ . box ( 'minf' , onSimpleAncestorBox )
379
+ . box ( 'stbl' , onSimpleAncestorBox )
380
+ . box ( 'stsd' , ( box ) => {
381
+ ancestorBoxes . push ( { start : box . start , size : box . size } ) ;
382
+ const stsdBoxView = shaka . util . BufferUtils . toDataView (
383
+ initSegment , box . start ) ;
384
+ for ( let i = 0 ; i < box . size ; i ++ ) {
385
+ const codecTag = stsdBoxView . getUint32 ( i ) ;
386
+ if ( codecTag == ContentWorkarounds . BOX_TYPE_AC_3_ ) {
387
+ stsdBoxView . setUint32 ( i , ContentWorkarounds . BOX_TYPE_EC_3_ ) ;
388
+ } else if ( codecTag == ContentWorkarounds . BOX_TYPE_DAC3_ ) {
389
+ stsdBoxView . setUint32 ( i , ContentWorkarounds . BOX_TYPE_DEC3_ ) ;
390
+ }
391
+ }
392
+ } ) . parse ( initSegment ) ;
393
+
394
+ return initSegment ;
395
+ }
350
396
} ;
351
397
352
398
/**
@@ -482,3 +528,35 @@ shaka.media.ContentWorkarounds.BOX_TYPE_ENCV_ = 0x656e6376;
482
528
* @private
483
529
*/
484
530
shaka . media . ContentWorkarounds . BOX_TYPE_ENCA_ = 0x656e6361 ;
531
+
532
+ /**
533
+ * Box type for "ac-3".
534
+ *
535
+ * @const {number}
536
+ * @private
537
+ */
538
+ shaka . media . ContentWorkarounds . BOX_TYPE_AC_3_ = 0x61632d33 ;
539
+
540
+ /**
541
+ * Box type for "dac3".
542
+ *
543
+ * @const {number}
544
+ * @private
545
+ */
546
+ shaka . media . ContentWorkarounds . BOX_TYPE_DAC3_ = 0x64616333 ;
547
+
548
+ /**
549
+ * Box type for "ec-3".
550
+ *
551
+ * @const {number}
552
+ * @private
553
+ */
554
+ shaka . media . ContentWorkarounds . BOX_TYPE_EC_3_ = 0x65632d33 ;
555
+
556
+ /**
557
+ * Box type for "dec3".
558
+ *
559
+ * @const {number}
560
+ * @private
561
+ */
562
+ shaka . media . ContentWorkarounds . BOX_TYPE_DEC3_ = 0x64656333 ;
0 commit comments