Commit e6bafec4 by andrewlewis Committed by Oliver Woodman

Deduplicate ID3 header constants

PiperOrigin-RevId: 259479785
parent 3a53543a
......@@ -53,7 +53,7 @@ public final class Id3Peeker {
Metadata metadata = null;
while (true) {
try {
input.peekFully(scratch.data, 0, Id3Decoder.ID3_HEADER_LENGTH);
input.peekFully(scratch.data, /* offset= */ 0, Id3Decoder.ID3_HEADER_LENGTH);
} catch (EOFException e) {
// If input has less than ID3_HEADER_LENGTH, ignore the rest.
break;
......
......@@ -16,6 +16,8 @@
package com.google.android.exoplayer2.extractor.ts;
import static com.google.android.exoplayer2.extractor.ts.TsPayloadReader.FLAG_DATA_ALIGNMENT_INDICATOR;
import static com.google.android.exoplayer2.metadata.id3.Id3Decoder.ID3_HEADER_LENGTH;
import static com.google.android.exoplayer2.metadata.id3.Id3Decoder.ID3_TAG;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.audio.Ac3Util;
......@@ -44,7 +46,6 @@ public final class Ac3Extractor implements Extractor {
private static final int MAX_SNIFF_BYTES = 8 * 1024;
private static final int AC3_SYNC_WORD = 0x0B77;
private static final int MAX_SYNC_FRAME_SIZE = 2786;
private static final int ID3_TAG = 0x00494433;
private final Ac3Reader reader;
private final ParsableByteArray sampleData;
......@@ -62,10 +63,10 @@ public final class Ac3Extractor implements Extractor {
@Override
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
// Skip any ID3 headers.
ParsableByteArray scratch = new ParsableByteArray(10);
ParsableByteArray scratch = new ParsableByteArray(ID3_HEADER_LENGTH);
int startPosition = 0;
while (true) {
input.peekFully(scratch.data, 0, 10);
input.peekFully(scratch.data, /* offset= */ 0, ID3_HEADER_LENGTH);
scratch.setPosition(0);
if (scratch.readUnsignedInt24() != ID3_TAG) {
break;
......
......@@ -18,6 +18,8 @@ package com.google.android.exoplayer2.extractor.ts;
import static com.google.android.exoplayer2.audio.Ac4Util.AC40_SYNCWORD;
import static com.google.android.exoplayer2.audio.Ac4Util.AC41_SYNCWORD;
import static com.google.android.exoplayer2.extractor.ts.TsPayloadReader.FLAG_DATA_ALIGNMENT_INDICATOR;
import static com.google.android.exoplayer2.metadata.id3.Id3Decoder.ID3_HEADER_LENGTH;
import static com.google.android.exoplayer2.metadata.id3.Id3Decoder.ID3_TAG;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.audio.Ac4Util;
......@@ -52,8 +54,6 @@ public final class Ac4Extractor implements Extractor {
/** The size of the frame header, in bytes. */
private static final int FRAME_HEADER_SIZE = 7;
private static final int ID3_TAG = 0x00494433;
private final Ac4Reader reader;
private final ParsableByteArray sampleData;
......@@ -70,10 +70,10 @@ public final class Ac4Extractor implements Extractor {
@Override
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
// Skip any ID3 headers.
ParsableByteArray scratch = new ParsableByteArray(10);
ParsableByteArray scratch = new ParsableByteArray(ID3_HEADER_LENGTH);
int startPosition = 0;
while (true) {
input.peekFully(scratch.data, /* offset= */ 0, /* length= */ 10);
input.peekFully(scratch.data, /* offset= */ 0, ID3_HEADER_LENGTH);
scratch.setPosition(0);
if (scratch.readUnsignedInt24() != ID3_TAG) {
break;
......
......@@ -16,6 +16,8 @@
package com.google.android.exoplayer2.extractor.ts;
import static com.google.android.exoplayer2.extractor.ts.TsPayloadReader.FLAG_DATA_ALIGNMENT_INDICATOR;
import static com.google.android.exoplayer2.metadata.id3.Id3Decoder.ID3_HEADER_LENGTH;
import static com.google.android.exoplayer2.metadata.id3.Id3Decoder.ID3_TAG;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
......@@ -65,7 +67,6 @@ public final class AdtsExtractor implements Extractor {
public static final int FLAG_ENABLE_CONSTANT_BITRATE_SEEKING = 1;
private static final int MAX_PACKET_SIZE = 2 * 1024;
private static final int ID3_TAG = 0x00494433;
/**
* The maximum number of bytes to search when sniffing, excluding the header, before giving up.
* Frame sizes are represented by 13-bit fields, so expect a valid frame in the first 8192 bytes.
......@@ -109,7 +110,8 @@ public final class AdtsExtractor implements Extractor {
packetBuffer = new ParsableByteArray(MAX_PACKET_SIZE);
averageFrameSize = C.LENGTH_UNSET;
firstFramePosition = C.POSITION_UNSET;
scratch = new ParsableByteArray(10);
// Allocate scratch space for an ID3 header. The same buffer is also used to read 4 byte values.
scratch = new ParsableByteArray(ID3_HEADER_LENGTH);
scratchBits = new ParsableBitArray(scratch.data);
}
......@@ -209,7 +211,7 @@ public final class AdtsExtractor implements Extractor {
private int peekId3Header(ExtractorInput input) throws IOException, InterruptedException {
int firstFramePosition = 0;
while (true) {
input.peekFully(scratch.data, 0, 10);
input.peekFully(scratch.data, /* offset= */ 0, ID3_HEADER_LENGTH);
scratch.setPosition(0);
if (scratch.readUnsignedInt24() != ID3_TAG) {
break;
......
......@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.extractor.ts;
import static com.google.android.exoplayer2.extractor.ts.TsPayloadReader.FLAG_DATA_ALIGNMENT_INDICATOR;
import static com.google.android.exoplayer2.metadata.id3.Id3Decoder.ID3_HEADER_LENGTH;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
......@@ -33,8 +34,6 @@ public final class Id3Reader implements ElementaryStreamReader {
private static final String TAG = "Id3Reader";
private static final int ID3_HEADER_SIZE = 10;
private final ParsableByteArray id3Header;
private TrackOutput output;
......@@ -48,7 +47,7 @@ public final class Id3Reader implements ElementaryStreamReader {
private int sampleBytesRead;
public Id3Reader() {
id3Header = new ParsableByteArray(ID3_HEADER_SIZE);
id3Header = new ParsableByteArray(ID3_HEADER_LENGTH);
}
@Override
......@@ -81,12 +80,12 @@ public final class Id3Reader implements ElementaryStreamReader {
return;
}
int bytesAvailable = data.bytesLeft();
if (sampleBytesRead < ID3_HEADER_SIZE) {
if (sampleBytesRead < ID3_HEADER_LENGTH) {
// We're still reading the ID3 header.
int headerBytesAvailable = Math.min(bytesAvailable, ID3_HEADER_SIZE - sampleBytesRead);
int headerBytesAvailable = Math.min(bytesAvailable, ID3_HEADER_LENGTH - sampleBytesRead);
System.arraycopy(data.data, data.getPosition(), id3Header.data, sampleBytesRead,
headerBytesAvailable);
if (sampleBytesRead + headerBytesAvailable == ID3_HEADER_SIZE) {
if (sampleBytesRead + headerBytesAvailable == ID3_HEADER_LENGTH) {
// We've finished reading the ID3 header. Extract the sample size.
id3Header.setPosition(0);
if ('I' != id3Header.readUnsignedByte() || 'D' != id3Header.readUnsignedByte()
......@@ -96,7 +95,7 @@ public final class Id3Reader implements ElementaryStreamReader {
return;
}
id3Header.skipBytes(3); // version (2) + flags (1)
sampleSize = ID3_HEADER_SIZE + id3Header.readSynchSafeInt();
sampleSize = ID3_HEADER_LENGTH + id3Header.readSynchSafeInt();
}
}
// Write data to the output.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment