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
This commit is contained in:
kimvde 2020-01-08 17:21:09 +00:00 committed by Oliver Woodman
parent 216518eb0e
commit 79edf7cce2

View File

@ -256,15 +256,18 @@ public final class FlacExtractor implements Extractor {
// Copy more bytes into the buffer.
int currentLimit = buffer.limit();
int bytesRead =
input.read(
buffer.data, /* offset= */ currentLimit, /* length= */ BUFFER_LENGTH - currentLimit);
boolean foundEndOfInput = bytesRead == C.RESULT_END_OF_INPUT;
if (!foundEndOfInput) {
buffer.setLimit(currentLimit + bytesRead);
} else if (buffer.bytesLeft() == 0) {
outputSampleMetadata();
return Extractor.RESULT_END_OF_INPUT;
boolean foundEndOfInput = false;
if (currentLimit < BUFFER_LENGTH) {
int bytesRead =
input.read(
buffer.data, /* offset= */ currentLimit, /* length= */ BUFFER_LENGTH - currentLimit);
foundEndOfInput = bytesRead == C.RESULT_END_OF_INPUT;
if (!foundEndOfInput) {
buffer.setLimit(currentLimit + bytesRead);
} else if (buffer.bytesLeft() == 0) {
outputSampleMetadata();
return Extractor.RESULT_END_OF_INPUT;
}
}
// Search for a frame.