Mp3Extractor: Avoid outputting non-zero position seek frame as a sample

Checking inputPosition == 0 isn't sufficient because the synchronization
at the top of read() may advance the input (i.e. in the case where there's
some garbage prior to the seek frame).

PiperOrigin-RevId: 261086901
This commit is contained in:
olly 2019-08-01 10:34:11 +01:00 committed by Oliver Woodman
parent 561949a225
commit a2cf427b4b

View File

@ -116,7 +116,7 @@ public final class Mp3Extractor implements Extractor {
private Seeker seeker;
private long basisTimeUs;
private long samplesRead;
private int firstSamplePosition;
private long firstSamplePosition;
private int sampleBytesRemaining;
public Mp3Extractor() {
@ -214,10 +214,13 @@ public final class Mp3Extractor implements Extractor {
/* selectionFlags= */ 0,
/* language= */ null,
(flags & FLAG_DISABLE_ID3_METADATA) != 0 ? null : metadata));
firstSamplePosition = (int) input.getPosition();
} else if (input.getPosition() == 0 && firstSamplePosition != 0) {
// Skip past the seek frame.
input.skipFully(firstSamplePosition);
firstSamplePosition = input.getPosition();
} else if (firstSamplePosition != 0) {
long inputPosition = input.getPosition();
if (inputPosition < firstSamplePosition) {
// Skip past the seek frame.
input.skipFully((int) (firstSamplePosition - inputPosition));
}
}
return readSample(input);
}