Skip more than one ID3 header.

Issue: 713
This commit is contained in:
Oliver Woodman 2015-08-17 17:12:33 +01:00
parent 90f9f7314d
commit 37ebec6e82

View file

@ -74,17 +74,21 @@ public final class Mp3Extractor implements Extractor {
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
ParsableByteArray scratch = new ParsableByteArray(4);
int startPosition = 0;
input.peekFully(scratch.data, 0, 3);
if (scratch.readUnsignedInt24() == ID3_TAG) {
while (true) {
input.peekFully(scratch.data, 0, 3);
scratch.setPosition(0);
if (scratch.readUnsignedInt24() != ID3_TAG) {
break;
}
input.advancePeekPosition(3);
input.peekFully(scratch.data, 0, 4);
int headerLength = ((scratch.data[0] & 0x7F) << 21) | ((scratch.data[1] & 0x7F) << 14)
| ((scratch.data[2] & 0x7F) << 7) | (scratch.data[3] & 0x7F);
input.advancePeekPosition(headerLength);
startPosition = 3 + 3 + 4 + headerLength;
} else {
input.resetPeekPosition();
startPosition += 3 + 3 + 4 + headerLength;
}
input.resetPeekPosition();
input.advancePeekPosition(startPosition);
// Try to find four consecutive valid MPEG audio frames.
int headerPosition = startPosition;
@ -238,9 +242,12 @@ public final class Mp3Extractor implements Extractor {
// Skip any ID3 header at the start of the file.
if (startPosition == 0) {
inputBuffer.read(extractorInput, scratch.data, 0, 3);
scratch.setPosition(0);
if (scratch.readUnsignedInt24() == ID3_TAG) {
while (true) {
inputBuffer.read(extractorInput, scratch.data, 0, 3);
scratch.setPosition(0);
if (scratch.readUnsignedInt24() != ID3_TAG) {
break;
}
extractorInput.skipFully(3);
extractorInput.readFully(scratch.data, 0, 4);
int headerLength = ((scratch.data[0] & 0x7F) << 21) | ((scratch.data[1] & 0x7F) << 14)
@ -248,9 +255,8 @@ public final class Mp3Extractor implements Extractor {
extractorInput.skipFully(headerLength);
inputBuffer.reset();
startPosition = getPosition(extractorInput, inputBuffer);
} else {
inputBuffer.returnToMark();
}
inputBuffer.returnToMark();
}
// Try to find four consecutive valid MPEG audio frames.