Commit 8571c810 by andrewlewis Committed by Oliver Woodman

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
parent 1175f50f
...@@ -26,7 +26,7 @@ import java.io.IOException; ...@@ -26,7 +26,7 @@ import java.io.IOException;
public interface ExtractorInput { 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> * <p>
* This method blocks until at least one byte of data can be read, the end of the input is * 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. * detected, or an exception is thrown.
...@@ -128,7 +128,7 @@ public interface ExtractorInput { ...@@ -128,7 +128,7 @@ public interface ExtractorInput {
* Otherwise an {@link EOFException} is thrown. * Otherwise an {@link EOFException} is thrown.
* <p> * <p>
* Calling {@link #resetPeekPosition()} resets the peek position to equal the current read * 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. * position.
* *
* @param target A target array into which data should be written. * @param target A target array into which data should be written.
......
...@@ -892,8 +892,9 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu ...@@ -892,8 +892,9 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
} }
} catch (EOFException e) { } catch (EOFException e) {
// Do nothing. // Do nothing.
} finally {
input.resetPeekPosition();
} }
input.resetPeekPosition();
} }
if (extractor == null) { if (extractor == null) {
throw new UnrecognizedInputFormatException(extractors); throw new UnrecognizedInputFormatException(extractors);
......
...@@ -72,7 +72,6 @@ public final class OggVorbisExtractor implements Extractor, SeekMap { ...@@ -72,7 +72,6 @@ public final class OggVorbisExtractor implements Extractor, SeekMap {
} catch (ParserException e) { } catch (ParserException e) {
// does not happen // does not happen
} finally { } finally {
input.resetPeekPosition();
scratch.reset(); scratch.reset();
} }
return false; return false;
......
...@@ -147,15 +147,14 @@ import java.util.Stack; ...@@ -147,15 +147,14 @@ import java.util.Stack;
*/ */
private long maybeResyncToNextLevel1Element(ExtractorInput input) throws EOFException, private long maybeResyncToNextLevel1Element(ExtractorInput input) throws EOFException,
IOException, InterruptedException { IOException, InterruptedException {
input.resetPeekPosition();
while (true) { while (true) {
input.resetPeekPosition();
input.peekFully(scratch, 0, MAX_ID_BYTES); input.peekFully(scratch, 0, MAX_ID_BYTES);
int varintLength = VarintReader.parseUnsignedVarintLength(scratch[0]); int varintLength = VarintReader.parseUnsignedVarintLength(scratch[0]);
if (varintLength != -1 && varintLength <= MAX_ID_BYTES) { if (varintLength != -1 && varintLength <= MAX_ID_BYTES) {
int potentialId = (int) VarintReader.assembleVarint(scratch, varintLength, false); int potentialId = (int) VarintReader.assembleVarint(scratch, varintLength, false);
if (output.isLevel1Element(potentialId)) { if (output.isLevel1Element(potentialId)) {
input.skipFully(varintLength); input.skipFully(varintLength);
input.resetPeekPosition();
return potentialId; return potentialId;
} }
} }
......
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