Move resetting the peek position to ExtractorSampleSource.

This fixes an issue where the PsExtractor would start reading
unsynchronized if sniff was called.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=117958077
This commit is contained in:
andrewlewis 2016-03-23 12:42:29 -07:00 committed by Oliver Woodman
parent 1175f50fb8
commit 8571c81076
4 changed files with 5 additions and 6 deletions

View File

@ -26,7 +26,7 @@ import java.io.IOException;
public interface ExtractorInput {
/**
* Reads up to {@code length} bytes from the input.
* Reads up to {@code length} bytes from the input and resets the peek position.
* <p>
* This method blocks until at least one byte of data can be read, the end of the input is
* detected, or an exception is thrown.
@ -128,7 +128,7 @@ public interface ExtractorInput {
* Otherwise an {@link EOFException} is thrown.
* <p>
* Calling {@link #resetPeekPosition()} resets the peek position to equal the current read
* position, so the caller can peek the same data again. Reading and skipping also reset the peek
* position, so the caller can peek the same data again. Reading or skipping also resets the peek
* position.
*
* @param target A target array into which data should be written.

View File

@ -892,8 +892,9 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
}
} catch (EOFException e) {
// Do nothing.
} finally {
input.resetPeekPosition();
}
input.resetPeekPosition();
}
if (extractor == null) {
throw new UnrecognizedInputFormatException(extractors);

View File

@ -72,7 +72,6 @@ public final class OggVorbisExtractor implements Extractor, SeekMap {
} catch (ParserException e) {
// does not happen
} finally {
input.resetPeekPosition();
scratch.reset();
}
return false;

View File

@ -147,15 +147,14 @@ import java.util.Stack;
*/
private long maybeResyncToNextLevel1Element(ExtractorInput input) throws EOFException,
IOException, InterruptedException {
input.resetPeekPosition();
while (true) {
input.resetPeekPosition();
input.peekFully(scratch, 0, MAX_ID_BYTES);
int varintLength = VarintReader.parseUnsignedVarintLength(scratch[0]);
if (varintLength != -1 && varintLength <= MAX_ID_BYTES) {
int potentialId = (int) VarintReader.assembleVarint(scratch, varintLength, false);
if (output.isLevel1Element(potentialId)) {
input.skipFully(varintLength);
input.resetPeekPosition();
return potentialId;
}
}