@@ -285,12 +285,17 @@ private void setCheckingAdtsHeaderState() {
285
285
bytesRead = 0 ;
286
286
}
287
287
288
- /** Sets the state to STATE_READING_AAC_PCE. */
288
+ /** Sets the state to STATE_READING_AAC_PCE.
289
+ *
290
+ * @param outputToUse TrackOutput object to write the sample to
291
+ * @param currentSampleDuration Duration of the sample to be read
292
+ * @param sampleSize Size of the sample
293
+ */
289
294
private void setReadingAacPceState (
290
295
TrackOutput outputToUse , long currentSampleDuration , int sampleSize ) {
291
296
state = STATE_READING_AAC_PCE ;
292
297
bytesRead = 0 ;
293
- currentOutput = outputToUse ;
298
+ this . currentOutput = outputToUse ;
294
299
this .currentSampleDuration = currentSampleDuration ;
295
300
this .sampleSize = sampleSize ;
296
301
pceBuffer = new ParsableBitArray (new byte [min (sampleSize , AAC_PCE_MAX_SIZE )]);
@@ -567,43 +572,50 @@ private void parseAdtsHeader() throws ParserException {
567
572
568
573
@ RequiresNonNull ({"pendingOutputFormat" , "pceBuffer" })
569
574
void readAacProgramConfigElement () {
575
+ // See ISO 13818-7 Advanced Audio Coding (2006) Table 36 for PCE tag encoding.
570
576
if (pceBuffer .readBits (3 ) == 5 /* PCE tag */ ) {
571
- // See ` ISO 13818-7 Advanced Audio Coding (2006) Table 25` for format of a PCE
572
- pceBuffer .skipBits (10 ); // Element instance tag , profile, sample frequency index
577
+ // See ISO 13818-7 Advanced Audio Coding (2006) Table 25 for syntax of a PCE.
578
+ pceBuffer .skipBits (10 ); // element_instance_tag(4) , profile(2), element_instance_tag(4)
573
579
574
580
int channelBits = 0 ;
575
- channelBits += pceBuffer .readBits (4 ) * 5 ; // Front channel elements
576
- channelBits += pceBuffer .readBits (4 ) * 5 ; // Side channel elements
577
- channelBits += pceBuffer .readBits (4 ) * 5 ; // Back channel elements
578
- channelBits += pceBuffer .readBits (2 ) * 4 ; // LFE channel elements
579
- channelBits += pceBuffer .readBits (3 ) * 4 ; // Data elements
580
- channelBits += pceBuffer .readBits (4 ) * 5 ; // Coupling channel elements
581
-
582
- if (pceBuffer .readBit ()) {
583
- pceBuffer .skipBits (4 ); // Mono mixdown
581
+ // num_front_channel_elements, front_element_is_cpe(1), front_element_tag_select(4)
582
+ channelBits += pceBuffer .readBits (4 ) * 5 ;
583
+ // num_side_channel_elements, side_element_is_cpe(1), side_element_tag_select(4)
584
+ channelBits += pceBuffer .readBits (4 ) * 5 ;
585
+ // num_back_channel_elements, back_element_is_cpe(1), back_element_tag_select(4)
586
+ channelBits += pceBuffer .readBits (4 ) * 5 ;
587
+ // num_lfe_channel_elements, lfe_element_tag_select(4)
588
+ channelBits += pceBuffer .readBits (2 ) * 4 ;
589
+ // num_assoc_data_elements, assoc_data_element_tag_select(4)
590
+ channelBits += pceBuffer .readBits (3 ) * 4 ;
591
+ // num_valid_cc_elements, cc_element_is_ind_sw(1), valid_cc_element_tag_select(4)
592
+ channelBits += pceBuffer .readBits (4 ) * 5 ;
593
+
594
+ if (pceBuffer .readBit ()) { // mono_mixdown_present
595
+ pceBuffer .skipBits (4 ); // mono_mixdown_element_number
584
596
}
585
597
586
- if (pceBuffer .readBit ()) {
587
- pceBuffer .skipBits (4 ); // Stereo mixdown
598
+ if (pceBuffer .readBit ()) { // stereo_mixdown_present
599
+ pceBuffer .skipBits (4 ); // stereo_mixdown_element_number
588
600
}
589
601
590
- if (pceBuffer .readBit ()) {
591
- pceBuffer .skipBits (3 ); // Matrix mixdown
602
+ if (pceBuffer .readBit ()) { // matrix_mixdown_idx_present
603
+ pceBuffer .skipBits (3 ); // matrix_mixdown_idx(2), matrix_mixdown_idx(1)
592
604
}
593
605
594
- // Beyond this point, pceBuffer may be empty, so check before consuming.
595
-
596
- int numAlignmentBits = 8 - (pceBuffer .getPosition () + channelBits + 7 ) % 8 - 1 ;
606
+ int numAlignmentBits = 8 - (pceBuffer .getPosition () + channelBits + 7 ) % 8 - 1 ; // byte_alignment
607
+ int commentSizeBits = 8 ; // comment_field_bytes
597
608
598
- if (pceBuffer .bitsLeft () >= channelBits + numAlignmentBits + 8 )
609
+ // Beyond this point, pceBuffer may be empty, so check before consuming.
610
+ if (pceBuffer .bitsLeft () >= channelBits + numAlignmentBits + commentSizeBits )
599
611
{
600
612
pceBuffer .skipBits (channelBits );
601
613
602
614
// Store PCE size excluding initial PCE tag, alignment bits and comment for later.
603
615
int numPceBits = pceBuffer .getPosition () - 3 /* PCE tag */ ;
604
616
605
617
pceBuffer .skipBits (numAlignmentBits );
606
- int commentSize = pceBuffer .readBits (8 );
618
+ int commentSize = pceBuffer .readBits (commentSizeBits );
607
619
608
620
if (sampleSize >= pceBuffer .getBytePosition () + commentSize )
609
621
{
0 commit comments