Extract method in MediaCodecRenderer

Deduplicates a bit of code

PiperOrigin-RevId: 236621851
This commit is contained in:
aquilescanta 2019-03-04 11:10:19 +00:00 committed by Oliver Woodman
parent 8fce3ce678
commit 7a1b8a9585

View File

@ -635,22 +635,9 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
renderToEndOfStream(); renderToEndOfStream();
return; return;
} }
if (inputFormat == null) { if (inputFormat == null && !readToFlagsOnlyBuffer(/* requireFormat= */ true)) {
// We don't have a format yet, so try and read one.
flagsOnlyBuffer.clear();
int result = readSource(formatHolder, flagsOnlyBuffer, true);
if (result == C.RESULT_FORMAT_READ) {
onInputFormatChanged(formatHolder.format);
} else if (result == C.RESULT_BUFFER_READ) {
// End of stream read having not read a format.
Assertions.checkState(flagsOnlyBuffer.isEndOfStream());
inputStreamEnded = true;
processEndOfStream();
return;
} else {
// We still don't have a format and can't make progress without one. // We still don't have a format and can't make progress without one.
return; return;
}
} }
// We have a format. // We have a format.
maybeInitCodec(); maybeInitCodec();
@ -666,15 +653,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
// updated, and so that we have the most recent format should the codec be initialized. We may // updated, and so that we have the most recent format should the codec be initialized. We may
// also reach the end of the stream. Note that readSource will not read a sample into a // also reach the end of the stream. Note that readSource will not read a sample into a
// flags-only buffer. // flags-only buffer.
flagsOnlyBuffer.clear(); readToFlagsOnlyBuffer(/* requireFormat= */ false);
int result = readSource(formatHolder, flagsOnlyBuffer, false);
if (result == C.RESULT_FORMAT_READ) {
onInputFormatChanged(formatHolder.format);
} else if (result == C.RESULT_BUFFER_READ) {
Assertions.checkState(flagsOnlyBuffer.isEndOfStream());
inputStreamEnded = true;
processEndOfStream();
}
} }
decoderCounters.ensureUpdated(); decoderCounters.ensureUpdated();
} }
@ -737,6 +716,21 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
return false; return false;
} }
/** Reads into {@link #flagsOnlyBuffer} and returns whether a format was read. */
private boolean readToFlagsOnlyBuffer(boolean requireFormat) throws ExoPlaybackException {
flagsOnlyBuffer.clear();
int result = readSource(formatHolder, flagsOnlyBuffer, requireFormat);
if (result == C.RESULT_FORMAT_READ) {
onInputFormatChanged(formatHolder.format);
return true;
} else if (result == C.RESULT_BUFFER_READ) {
Assertions.checkState(flagsOnlyBuffer.isEndOfStream());
inputStreamEnded = true;
processEndOfStream();
}
return false;
}
private void maybeInitCodecWithFallback( private void maybeInitCodecWithFallback(
MediaCrypto crypto, boolean mediaCryptoRequiresSecureDecoder) MediaCrypto crypto, boolean mediaCryptoRequiresSecureDecoder)
throws DecoderInitializationException { throws DecoderInitializationException {