15
15
*/
16
16
package androidx .media3 .extractor .ts ;
17
17
18
+ import static androidx .media3 .common .util .Assertions .checkNotNull ;
18
19
import static java .lang .Math .min ;
19
20
20
21
import androidx .annotation .Nullable ;
33
34
import androidx .media3 .extractor .ExtractorOutput ;
34
35
import androidx .media3 .extractor .TrackOutput ;
35
36
import androidx .media3 .extractor .ts .TsPayloadReader .TrackIdGenerator ;
37
+ import com .google .common .collect .ImmutableList ;
36
38
import java .util .Arrays ;
37
39
import java .util .Collections ;
38
40
import org .checkerframework .checker .nullness .qual .EnsuresNonNull ;
@@ -191,6 +193,7 @@ public void consume(ParsableByteArray data) throws ParserException {
191
193
}
192
194
break ;
193
195
case STATE_READING_AAC_PCE :
196
+ checkNotNull (pceBuffer );
194
197
if (continueRead (data , pceBuffer .data , pceBuffer .data .length )) {
195
198
readAacProgramConfigElement ();
196
199
}
@@ -571,8 +574,12 @@ private void parseAdtsHeader() throws ParserException {
571
574
}
572
575
}
573
576
574
- @ RequiresNonNull ({ "pendingOutputFormat" , "pceBuffer" } )
577
+ @ RequiresNonNull ("currentOutput" )
575
578
void readAacProgramConfigElement () {
579
+ checkNotNull (pendingOutputFormat );
580
+ checkNotNull (pceBuffer );
581
+
582
+
576
583
// See ISO 13818-7 Advanced Audio Coding (2006) Table 36 for PCE tag encoding.
577
584
if (pceBuffer .readBits (3 ) == 5 /* PCE tag */ ) {
578
585
// See ISO 13818-7 Advanced Audio Coding (2006) Table 25 for syntax of a PCE.
@@ -624,16 +631,15 @@ void readAacProgramConfigElement() {
624
631
625
632
int configSize = oldConfig .length ;
626
633
configSize += (numPceBits + 7 ) / 8 + 1 ; // Byte align and add a zero length comment.
627
- byte [] newConfig = new byte [ configSize ] ;
634
+ byte [] newConfig = Arrays . copyOf ( oldConfig , configSize ) ;
628
635
629
- System .arraycopy (oldConfig , 0 , newConfig , 0 , oldConfig .length );
630
636
pceBuffer .setPosition (3 /* PCE tag */ );
631
637
pceBuffer .readBits (newConfig , oldConfig .length , numPceBits );
632
638
633
639
pendingOutputFormat =
634
640
pendingOutputFormat
635
641
.buildUpon ()
636
- .setInitializationData (Collections . singletonList (newConfig ))
642
+ .setInitializationData (ImmutableList . of (newConfig ))
637
643
.build ();
638
644
639
645
// Submit PCE-appended output format.
@@ -643,13 +649,13 @@ void readAacProgramConfigElement() {
643
649
}
644
650
}
645
651
646
- pendingOutputFormat = null ;
647
-
648
652
// Pass through all accumulated data as sample data.
649
653
ParsableByteArray data = new ParsableByteArray (pceBuffer .data );
650
- pceBuffer = null ;
651
654
setReadingSampleState (currentOutput , currentSampleDuration , 0 , sampleSize );
652
655
readSample (data );
656
+
657
+ pendingOutputFormat = null ;
658
+ pceBuffer = null ;
653
659
}
654
660
655
661
/** Reads the rest of the sample */
@@ -669,7 +675,7 @@ private void readSample(ParsableByteArray data) {
669
675
670
676
@ EnsuresNonNull ({"output" , "currentOutput" , "id3Output" })
671
677
private void assertTracksCreated () {
672
- Assertions . checkNotNull (output );
678
+ checkNotNull (output );
673
679
Util .castNonNull (currentOutput );
674
680
Util .castNonNull (id3Output );
675
681
}
0 commit comments