Commit 79edf7cc by kimvde Committed by Oliver Woodman

FlacExtractor: add condition for zero-length reads

This improves readability by making clearer that reading no bytes from
the input in readFrames() is an expected case if the buffer is full.

PiperOrigin-RevId: 288711841
parent 216518eb
...@@ -256,16 +256,19 @@ public final class FlacExtractor implements Extractor { ...@@ -256,16 +256,19 @@ public final class FlacExtractor implements Extractor {
// Copy more bytes into the buffer. // Copy more bytes into the buffer.
int currentLimit = buffer.limit(); int currentLimit = buffer.limit();
boolean foundEndOfInput = false;
if (currentLimit < BUFFER_LENGTH) {
int bytesRead = int bytesRead =
input.read( input.read(
buffer.data, /* offset= */ currentLimit, /* length= */ BUFFER_LENGTH - currentLimit); buffer.data, /* offset= */ currentLimit, /* length= */ BUFFER_LENGTH - currentLimit);
boolean foundEndOfInput = bytesRead == C.RESULT_END_OF_INPUT; foundEndOfInput = bytesRead == C.RESULT_END_OF_INPUT;
if (!foundEndOfInput) { if (!foundEndOfInput) {
buffer.setLimit(currentLimit + bytesRead); buffer.setLimit(currentLimit + bytesRead);
} else if (buffer.bytesLeft() == 0) { } else if (buffer.bytesLeft() == 0) {
outputSampleMetadata(); outputSampleMetadata();
return Extractor.RESULT_END_OF_INPUT; return Extractor.RESULT_END_OF_INPUT;
} }
}
// Search for a frame. // Search for a frame.
int positionBeforeFindingAFrame = buffer.getPosition(); int positionBeforeFindingAFrame = buffer.getPosition();
......
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