mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Skip more than one ID3 header.
Issue: 713
This commit is contained in:
parent
90f9f7314d
commit
37ebec6e82
1 changed files with 16 additions and 10 deletions
|
|
@ -74,17 +74,21 @@ public final class Mp3Extractor implements Extractor {
|
||||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||||
ParsableByteArray scratch = new ParsableByteArray(4);
|
ParsableByteArray scratch = new ParsableByteArray(4);
|
||||||
int startPosition = 0;
|
int startPosition = 0;
|
||||||
input.peekFully(scratch.data, 0, 3);
|
while (true) {
|
||||||
if (scratch.readUnsignedInt24() == ID3_TAG) {
|
input.peekFully(scratch.data, 0, 3);
|
||||||
|
scratch.setPosition(0);
|
||||||
|
if (scratch.readUnsignedInt24() != ID3_TAG) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
input.advancePeekPosition(3);
|
input.advancePeekPosition(3);
|
||||||
input.peekFully(scratch.data, 0, 4);
|
input.peekFully(scratch.data, 0, 4);
|
||||||
int headerLength = ((scratch.data[0] & 0x7F) << 21) | ((scratch.data[1] & 0x7F) << 14)
|
int headerLength = ((scratch.data[0] & 0x7F) << 21) | ((scratch.data[1] & 0x7F) << 14)
|
||||||
| ((scratch.data[2] & 0x7F) << 7) | (scratch.data[3] & 0x7F);
|
| ((scratch.data[2] & 0x7F) << 7) | (scratch.data[3] & 0x7F);
|
||||||
input.advancePeekPosition(headerLength);
|
input.advancePeekPosition(headerLength);
|
||||||
startPosition = 3 + 3 + 4 + headerLength;
|
startPosition += 3 + 3 + 4 + headerLength;
|
||||||
} else {
|
|
||||||
input.resetPeekPosition();
|
|
||||||
}
|
}
|
||||||
|
input.resetPeekPosition();
|
||||||
|
input.advancePeekPosition(startPosition);
|
||||||
|
|
||||||
// Try to find four consecutive valid MPEG audio frames.
|
// Try to find four consecutive valid MPEG audio frames.
|
||||||
int headerPosition = startPosition;
|
int headerPosition = startPosition;
|
||||||
|
|
@ -238,9 +242,12 @@ public final class Mp3Extractor implements Extractor {
|
||||||
|
|
||||||
// Skip any ID3 header at the start of the file.
|
// Skip any ID3 header at the start of the file.
|
||||||
if (startPosition == 0) {
|
if (startPosition == 0) {
|
||||||
inputBuffer.read(extractorInput, scratch.data, 0, 3);
|
while (true) {
|
||||||
scratch.setPosition(0);
|
inputBuffer.read(extractorInput, scratch.data, 0, 3);
|
||||||
if (scratch.readUnsignedInt24() == ID3_TAG) {
|
scratch.setPosition(0);
|
||||||
|
if (scratch.readUnsignedInt24() != ID3_TAG) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
extractorInput.skipFully(3);
|
extractorInput.skipFully(3);
|
||||||
extractorInput.readFully(scratch.data, 0, 4);
|
extractorInput.readFully(scratch.data, 0, 4);
|
||||||
int headerLength = ((scratch.data[0] & 0x7F) << 21) | ((scratch.data[1] & 0x7F) << 14)
|
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);
|
extractorInput.skipFully(headerLength);
|
||||||
inputBuffer.reset();
|
inputBuffer.reset();
|
||||||
startPosition = getPosition(extractorInput, inputBuffer);
|
startPosition = getPosition(extractorInput, inputBuffer);
|
||||||
} else {
|
|
||||||
inputBuffer.returnToMark();
|
|
||||||
}
|
}
|
||||||
|
inputBuffer.returnToMark();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to find four consecutive valid MPEG audio frames.
|
// Try to find four consecutive valid MPEG audio frames.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue