mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-02-16 10:31:07 +00:00
Only catch RuntimeExceptions for decoders to avoid eating important exceptions
This commit is contained in:
@@ -577,7 +577,7 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer implements C
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the exception is transient
|
// Returns true if the exception is transient
|
||||||
private boolean handleDecoderException(Exception e, ByteBuffer buf, int codecFlags) {
|
private boolean handleDecoderException(RuntimeException e, ByteBuffer buf, int codecFlags) {
|
||||||
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;
|
||||||
@@ -668,11 +668,11 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer implements C
|
|||||||
|
|
||||||
lastRenderedFrameTimeNanos = frameTimeNanos;
|
lastRenderedFrameTimeNanos = frameTimeNanos;
|
||||||
activeWindowVideoStats.totalFramesRendered++;
|
activeWindowVideoStats.totalFramesRendered++;
|
||||||
} catch (Exception ignored) {
|
} catch (RuntimeException ignored) {
|
||||||
try {
|
try {
|
||||||
// Try to avoid leaking the output buffer by releasing it without rendering
|
// Try to avoid leaking the output buffer by releasing it without rendering
|
||||||
videoDecoder.releaseOutputBuffer(nextOutputBuffer, false);
|
videoDecoder.releaseOutputBuffer(nextOutputBuffer, false);
|
||||||
} catch (Exception e) {
|
} catch (RuntimeException e) {
|
||||||
// This will leak nextOutputBuffer, but there's really nothing else we can do
|
// This will leak nextOutputBuffer, but there's really nothing else we can do
|
||||||
handleDecoderException(e, null, 0);
|
handleDecoderException(e, null, 0);
|
||||||
}
|
}
|
||||||
@@ -768,7 +768,13 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer implements C
|
|||||||
// run for a while (if there is a huge mismatch between stream FPS and display
|
// run for a while (if there is a huge mismatch between stream FPS and display
|
||||||
// refresh rate).
|
// refresh rate).
|
||||||
if (outputBufferQueue.size() == OUTPUT_BUFFER_QUEUE_LIMIT) {
|
if (outputBufferQueue.size() == OUTPUT_BUFFER_QUEUE_LIMIT) {
|
||||||
videoDecoder.releaseOutputBuffer(outputBufferQueue.take(), false);
|
try {
|
||||||
|
videoDecoder.releaseOutputBuffer(outputBufferQueue.take(), false);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// We're shutting down, so we can just drop this buffer on the floor
|
||||||
|
// and it will be reclaimed when the codec is released.
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add this buffer
|
// Add this buffer
|
||||||
@@ -796,7 +802,7 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer implements C
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (RuntimeException e) {
|
||||||
handleDecoderException(e, null, 0);
|
handleDecoderException(e, null, 0);
|
||||||
} finally {
|
} finally {
|
||||||
doCodecRecoveryIfRequired(CR_FLAG_RENDER_THREAD);
|
doCodecRecoveryIfRequired(CR_FLAG_RENDER_THREAD);
|
||||||
@@ -845,7 +851,7 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer implements C
|
|||||||
nextInputBuffer.clear();
|
nextInputBuffer.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (RuntimeException e) {
|
||||||
handleDecoderException(e, null, 0);
|
handleDecoderException(e, null, 0);
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -964,7 +970,7 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer implements C
|
|||||||
nextInputBufferIndex = -1;
|
nextInputBufferIndex = -1;
|
||||||
nextInputBuffer = null;
|
nextInputBuffer = null;
|
||||||
ret = true;
|
ret = true;
|
||||||
} catch (Exception e) {
|
} catch (RuntimeException e) {
|
||||||
if (handleDecoderException(e, null, codecFlags)) {
|
if (handleDecoderException(e, null, codecFlags)) {
|
||||||
// We encountered a transient error. In this case, just hold onto the buffer
|
// We encountered a transient error. In this case, just hold onto the buffer
|
||||||
// (to avoid leaking it), clear it, and keep it for the next frame. We'll return
|
// (to avoid leaking it), clear it, and keep it for the next frame. We'll return
|
||||||
|
|||||||
Reference in New Issue
Block a user