mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-06-17 06:10:58 +00:00
Implement fallbacks for a failed codec restart or reset
This commit is contained in:
@@ -529,24 +529,52 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer implements C
|
|||||||
nextInputBufferIndex = -1;
|
nextInputBufferIndex = -1;
|
||||||
outputBufferQueue.clear();
|
outputBufferQueue.clear();
|
||||||
|
|
||||||
if (needsReset) {
|
// For "recoverable" exceptions, we can just stop, reconfigure, and restart.
|
||||||
// For "non-recoverable" exceptions, we have to release and recreate the decoder.
|
if (needsRestart) {
|
||||||
|
LimeLog.warning("Trying to restart decoder after CodecException");
|
||||||
|
try {
|
||||||
|
videoDecoder.stop();
|
||||||
|
configureAndStartDecoder(configuredFormat);
|
||||||
|
needsRestart = false;
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
// Something went wrong during the restart, let's use a bigger hammer
|
||||||
|
// and try a reset instead.
|
||||||
|
needsRestart = false;
|
||||||
|
needsReset = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For "non-recoverable" exceptions on L+, we can call reset() to recover
|
||||||
|
// without having to recreate the entire decoder again.
|
||||||
|
if (needsReset && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
LimeLog.warning("Trying to reset decoder after CodecException");
|
LimeLog.warning("Trying to reset decoder after CodecException");
|
||||||
|
try {
|
||||||
|
videoDecoder.reset();
|
||||||
|
configureAndStartDecoder(configuredFormat);
|
||||||
|
needsReset = false;
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
// Something went wrong during the reset, we'll have to resort to
|
||||||
|
// releasing and recreating the decoder now.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we _still_ haven't managed to recover, go for the nuclear option and just
|
||||||
|
// throw away the old decoder and reinitialize a new one from scratch.
|
||||||
|
if (needsReset) {
|
||||||
|
LimeLog.warning("Trying to recreate decoder after CodecException");
|
||||||
videoDecoder.release();
|
videoDecoder.release();
|
||||||
int err = initializeDecoder();
|
int err = initializeDecoder();
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
throw new IllegalStateException("Decoder reset failed: " + err);
|
throw new IllegalStateException("Decoder reset failed: " + err);
|
||||||
}
|
}
|
||||||
}
|
needsReset = false;
|
||||||
else {
|
|
||||||
// For "recoverable" exceptions, we can just stop, reconfigure, and restart.
|
|
||||||
LimeLog.warning("Trying to recover decoder after CodecException");
|
|
||||||
videoDecoder.stop();
|
|
||||||
configureAndStartDecoder(configuredFormat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wake all quiesced threads and allow them to begin work again
|
// Wake all quiesced threads and allow them to begin work again
|
||||||
needsReset = needsRestart = false;
|
|
||||||
codecRecoveryThreadQuiescedFlags = 0;
|
codecRecoveryThreadQuiescedFlags = 0;
|
||||||
codecRecoveryMonitor.notifyAll();
|
codecRecoveryMonitor.notifyAll();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user