Skip to content

Commit acdc660

Browse files
committed
Format and comment changes
1 parent 853862a commit acdc660

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

Diff for: libraries/extractor/src/main/java/androidx/media3/extractor/ts/AdtsReader.java

+34-22
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,17 @@ private void setCheckingAdtsHeaderState() {
285285
bytesRead = 0;
286286
}
287287

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+
*/
289294
private void setReadingAacPceState(
290295
TrackOutput outputToUse, long currentSampleDuration, int sampleSize) {
291296
state = STATE_READING_AAC_PCE;
292297
bytesRead = 0;
293-
currentOutput = outputToUse;
298+
this.currentOutput = outputToUse;
294299
this.currentSampleDuration = currentSampleDuration;
295300
this.sampleSize = sampleSize;
296301
pceBuffer = new ParsableBitArray(new byte[min(sampleSize, AAC_PCE_MAX_SIZE)]);
@@ -567,43 +572,50 @@ private void parseAdtsHeader() throws ParserException {
567572

568573
@RequiresNonNull({"pendingOutputFormat", "pceBuffer"})
569574
void readAacProgramConfigElement() {
575+
// See ISO 13818-7 Advanced Audio Coding (2006) Table 36 for PCE tag encoding.
570576
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)
573579

574580
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
584596
}
585597

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
588600
}
589601

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)
592604
}
593605

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
597608

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)
599611
{
600612
pceBuffer.skipBits(channelBits);
601613

602614
// Store PCE size excluding initial PCE tag, alignment bits and comment for later.
603615
int numPceBits = pceBuffer.getPosition() - 3 /* PCE tag */;
604616

605617
pceBuffer.skipBits(numAlignmentBits);
606-
int commentSize = pceBuffer.readBits(8);
618+
int commentSize = pceBuffer.readBits(commentSizeBits);
607619

608620
if (sampleSize >= pceBuffer.getBytePosition() + commentSize)
609621
{

Diff for: libraries/extractor/src/test/java/androidx/media3/extractor/ts/AdtsReaderTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,17 @@ public void adtsDataOnly() throws ParserException {
202202
@Test
203203
public void aacPceData() throws ParserException {
204204
data = new ParsableByteArray(AAC_PCE_TEST_DATA);
205+
205206
feed();
207+
206208
assertSampleCounts(0, 1);
207209
adtsOutput.assertSample(0, AAC_PCE_ADTS_CONTENT, 0, C.BUFFER_FLAG_KEY_FRAME, null);
208210
}
209211

210212
@Test(expected = IllegalStateException.class)
211213
public void aacPceDataFail() throws ParserException {
212-
data = new ParsableByteArray(AAC_PCE_TEST_DATA);
214+
data = new ParsableByteArray(Arrays.copyOf(AAC_PCE_TEST_DATA, AAC_PCE_TEST_DATA.length));
213215
byte[] bytes = data.getData();
214-
215216
// Remove PCE tag (first 3 bits of content).
216217
bytes[AAC_PCE_ADTS_HEADER.length] &= 0x1f;
217218
// Replace with CPE tag.

0 commit comments

Comments
 (0)