Consolidate handling of decoder exceptions

This commit is contained in:
Cameron Gutman 2017-06-10 16:57:37 -07:00
parent babd92c8c0
commit 6340ec6c6d

View File

@ -279,12 +279,12 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer {
return 0; return 0;
} }
private void handleDecoderException(Exception e, ByteBuffer buf, int codecFlags) { private void handleDecoderException(Exception e, ByteBuffer buf, int codecFlags, boolean throwOnTransient) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (e instanceof CodecException) { if (e instanceof CodecException) {
CodecException codecExc = (CodecException) e; CodecException codecExc = (CodecException) e;
if (codecExc.isTransient()) { if (codecExc.isTransient() && !throwOnTransient) {
// We'll let transient exceptions go // We'll let transient exceptions go
LimeLog.warning(codecExc.getDiagnosticInfo()); LimeLog.warning(codecExc.getDiagnosticInfo());
return; return;
@ -352,7 +352,7 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer {
} }
} }
} catch (Exception e) { } catch (Exception e) {
handleDecoderException(e, null, 0); handleDecoderException(e, null, 0, false);
} }
} }
} }
@ -392,11 +392,11 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer {
startTime = MediaCodecHelper.getMonotonicMillis(); startTime = MediaCodecHelper.getMonotonicMillis();
try { try {
while (rendererThread.isAlive() && index < 0 && !stopping) { while (index < 0 && !stopping) {
index = videoDecoder.dequeueInputBuffer(10000); index = videoDecoder.dequeueInputBuffer(10000);
} }
} catch (Exception e) { } catch (Exception e) {
handleDecoderException(e, null, 0); handleDecoderException(e, null, 0, true);
return MediaCodec.INFO_TRY_AGAIN_LATER; return MediaCodec.INFO_TRY_AGAIN_LATER;
} }
@ -467,31 +467,13 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer {
} }
private boolean queueInputBuffer(int inputBufferIndex, int offset, int length, long timestampUs, int codecFlags) { private boolean queueInputBuffer(int inputBufferIndex, int offset, int length, long timestampUs, int codecFlags) {
// Try 25 times to submit the input buffer before throwing a real exception
int i;
Exception lastException = null;
for (i = 0; i < 25; i++) {
try { try {
videoDecoder.queueInputBuffer(inputBufferIndex, videoDecoder.queueInputBuffer(inputBufferIndex,
offset, length, offset, length,
timestampUs, codecFlags); timestampUs, codecFlags);
break;
} catch (Exception e) {
handleDecoderException(e, null, codecFlags);
lastException = e;
}
}
if (i == 25 && totalFrames > 0 && !stopping) {
throw new RendererException(this, lastException, null, codecFlags);
}
else if (i != 25) {
// Queued input buffer
return true; return true;
} } catch (Exception e) {
else { handleDecoderException(e, null, codecFlags, true);
// Failed to queue
return false; return false;
} }
} }
@ -505,14 +487,10 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer {
try { try {
buf = videoDecoder.getInputBuffer(inputBufferIndex); buf = videoDecoder.getInputBuffer(inputBufferIndex);
} catch (Exception e) { } catch (Exception e) {
if (totalFrames > 0 && !stopping) { handleDecoderException(e, null, 0, true);
throw new RendererException(this, e, null, 0);
}
else {
return null; return null;
} }
} }
}
else { else {
buf = legacyInputBuffers[inputBufferIndex]; buf = legacyInputBuffers[inputBufferIndex];