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. // Copy more bytes into the buffer.
int currentLimit = buffer.limit(); int currentLimit = buffer.limit();
int bytesRead = boolean foundEndOfInput = false;
input.read( if (currentLimit < BUFFER_LENGTH) {
buffer.data, /* offset= */ currentLimit, /* length= */ BUFFER_LENGTH - currentLimit); int bytesRead =
boolean foundEndOfInput = bytesRead == C.RESULT_END_OF_INPUT; input.read(
if (!foundEndOfInput) { buffer.data, /* offset= */ currentLimit, /* length= */ BUFFER_LENGTH - currentLimit);
buffer.setLimit(currentLimit + bytesRead); foundEndOfInput = bytesRead == C.RESULT_END_OF_INPUT;
} else if (buffer.bytesLeft() == 0) { if (!foundEndOfInput) {
outputSampleMetadata(); buffer.setLimit(currentLimit + bytesRead);
return Extractor.RESULT_END_OF_INPUT; } else if (buffer.bytesLeft() == 0) {
outputSampleMetadata();
return Extractor.RESULT_END_OF_INPUT;
}
} }
// Search for a frame. // Search for a frame.