Misc clean-ups in ImageRenderer

Add some missing empty lines and use checkStateNotNull() everywhere.

PiperOrigin-RevId: 592173300
This commit is contained in:
christosts 2023-12-19 03:03:28 -08:00 committed by Copybara-Service
parent 087c07e596
commit 3bb233a911

View File

@ -18,7 +18,6 @@ package androidx.media3.exoplayer.image;
import static androidx.media3.common.C.FIRST_FRAME_NOT_RENDERED; import static androidx.media3.common.C.FIRST_FRAME_NOT_RENDERED;
import static androidx.media3.common.C.FIRST_FRAME_NOT_RENDERED_ONLY_ALLOWED_IF_STARTED; import static androidx.media3.common.C.FIRST_FRAME_NOT_RENDERED_ONLY_ALLOWED_IF_STARTED;
import static androidx.media3.common.C.FIRST_FRAME_RENDERED; import static androidx.media3.common.C.FIRST_FRAME_RENDERED;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState; import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.common.util.Assertions.checkStateNotNull; import static androidx.media3.common.util.Assertions.checkStateNotNull;
import static androidx.media3.exoplayer.source.SampleStream.FLAG_REQUIRE_FORMAT; import static androidx.media3.exoplayer.source.SampleStream.FLAG_REQUIRE_FORMAT;
@ -141,7 +140,7 @@ public class ImageRenderer extends BaseRenderer {
int result = readSource(formatHolder, flagsOnlyBuffer, FLAG_REQUIRE_FORMAT); int result = readSource(formatHolder, flagsOnlyBuffer, FLAG_REQUIRE_FORMAT);
if (result == C.RESULT_FORMAT_READ) { if (result == C.RESULT_FORMAT_READ) {
// Note that this works because we only expect to enter this if-condition once per playback. // Note that this works because we only expect to enter this if-condition once per playback.
inputFormat = checkNotNull(formatHolder.format); inputFormat = checkStateNotNull(formatHolder.format);
initDecoder(); initDecoder();
} else if (result == C.RESULT_BUFFER_READ) { } else if (result == C.RESULT_BUFFER_READ) {
// End of stream read having not read a format. // End of stream read having not read a format.
@ -269,7 +268,7 @@ public class ImageRenderer extends BaseRenderer {
checkStateNotNull(inputFormat); checkStateNotNull(inputFormat);
initDecoder(); initDecoder();
} else { } else {
checkNotNull(outputBuffer).release(); checkStateNotNull(outputBuffer).release();
outputBuffer = null; outputBuffer = null;
if (offsetQueue.isEmpty()) { if (offsetQueue.isEmpty()) {
outputStreamEnded = true; outputStreamEnded = true;
@ -334,7 +333,7 @@ public class ImageRenderer extends BaseRenderer {
if (decoderReinitializationState == REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM_THEN_WAIT) { if (decoderReinitializationState == REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM_THEN_WAIT) {
checkStateNotNull(inputBuffer); checkStateNotNull(inputBuffer);
inputBuffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM); inputBuffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
checkNotNull(decoder).queueInputBuffer(inputBuffer); checkStateNotNull(decoder).queueInputBuffer(inputBuffer);
inputBuffer = null; inputBuffer = null;
decoderReinitializationState = REINITIALIZATION_STATE_WAIT_END_OF_STREAM; decoderReinitializationState = REINITIALIZATION_STATE_WAIT_END_OF_STREAM;
return false; return false;
@ -347,12 +346,12 @@ public class ImageRenderer extends BaseRenderer {
// Input buffers with no data that are also non-EOS, only carry the timestamp for a grid // Input buffers with no data that are also non-EOS, only carry the timestamp for a grid
// tile. These buffers are not queued. // tile. These buffers are not queued.
boolean shouldQueueBuffer = boolean shouldQueueBuffer =
checkNotNull(inputBuffer.data).remaining() > 0 checkStateNotNull(inputBuffer.data).remaining() > 0
|| checkNotNull(inputBuffer).isEndOfStream(); || checkStateNotNull(inputBuffer).isEndOfStream();
if (shouldQueueBuffer) { if (shouldQueueBuffer) {
checkNotNull(decoder).queueInputBuffer(checkNotNull(inputBuffer)); checkStateNotNull(decoder).queueInputBuffer(checkStateNotNull(inputBuffer));
} }
if (checkNotNull(inputBuffer).isEndOfStream()) { if (checkStateNotNull(inputBuffer).isEndOfStream()) {
inputStreamEnded = true; inputStreamEnded = true;
inputBuffer = null; inputBuffer = null;
return false; return false;
@ -362,11 +361,11 @@ public class ImageRenderer extends BaseRenderer {
if (shouldQueueBuffer) { if (shouldQueueBuffer) {
inputBuffer = null; inputBuffer = null;
} else { } else {
checkNotNull(inputBuffer).clear(); checkStateNotNull(inputBuffer).clear();
} }
return true; return true;
case C.RESULT_FORMAT_READ: case C.RESULT_FORMAT_READ:
inputFormat = checkNotNull(formatHolder.format); inputFormat = checkStateNotNull(formatHolder.format);
decoderReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM_THEN_WAIT; decoderReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM_THEN_WAIT;
return true; return true;
default: default: