Only try to recover from CodecExceptions or IllegalStateExceptions

This commit is contained in:
Cameron Gutman
2022-09-18 00:20:41 -05:00
parent 33c1f0a71c
commit 06099b2663
@@ -618,39 +618,43 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer implements C
return false; return false;
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && e instanceof CodecException) {
if (e instanceof CodecException) { CodecException codecExc = (CodecException) e;
CodecException codecExc = (CodecException) e;
if (codecExc.isTransient()) { if (codecExc.isTransient()) {
// We'll let transient exceptions go // We'll let transient exceptions go
LimeLog.warning(codecExc.getDiagnosticInfo()); LimeLog.warning(codecExc.getDiagnosticInfo());
return true; return true;
}
LimeLog.severe(codecExc.getDiagnosticInfo());
// We can attempt a recovery or reset at this stage to try to start decoding again
if (codecRecoveryAttempts < CR_MAX_TRIES) {
if (codecExc.isRecoverable()) {
needsRestart = true;
}
else {
needsReset = true;
} }
LimeLog.severe(codecExc.getDiagnosticInfo()); // The recovery will take place when all threads reach doCodecRecoveryIfRequired().
return false;
// We can attempt a recovery or reset at this stage to try to start decoding again
if (codecRecoveryAttempts < CR_MAX_TRIES) {
if (codecExc.isRecoverable()) {
needsRestart = true;
}
else {
needsReset = true;
}
// The recovery will take place when all threads reach doCodecRecoveryIfRequired().
return false;
}
} }
} }
else if (e instanceof IllegalStateException) {
// If we got here, this is most likely an IllegalStateException which was used prior to L // IllegalStateException was primarily used prior to the introduction of CodecException.
// to indicate codec errors (unexpected transition to the error state). Recovery from this // Recovery from this requires a full decoder reset.
// requires a full decoder reset. //
if (codecRecoveryAttempts < CR_MAX_TRIES) { // NB: CodecException is an IllegalStateException, so we must check for it first.
needsReset = true; if (codecRecoveryAttempts < CR_MAX_TRIES) {
return false; needsReset = true;
return false;
}
}
else {
// If it's not a CodecException or IllegalStateException, it's not an "expected" failure.
throw e;
} }
// Only throw if we're not in the middle of codec recovery // Only throw if we're not in the middle of codec recovery