From 38a6a2b74a32ca62a2266f46284a67322e2eb52a Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 9 Sep 2017 18:44:06 -0700 Subject: [PATCH] A few fixes for decoder crash notifications --- app/src/main/java/com/limelight/Game.java | 13 +++---- app/src/main/java/com/limelight/PcView.java | 35 ++++++++++++------- .../video/MediaCodecDecoderRenderer.java | 12 +++++-- app/src/main/res/values/strings.xml | 2 +- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/limelight/Game.java b/app/src/main/java/com/limelight/Game.java index 791c29e8..f7c85982 100644 --- a/app/src/main/java/com/limelight/Game.java +++ b/app/src/main/java/com/limelight/Game.java @@ -231,7 +231,8 @@ public class Game extends Activity implements SurfaceHolder.Callback, // We must use commit because the app will crash when we return from this function tombstonePrefs.edit().putInt("CrashCount", tombstonePrefs.getInt("CrashCount", 0) + 1).commit(); } - }); + }, + tombstonePrefs.getInt("CrashCount", 0)); // Display a message to the user if H.265 was forced on but we still didn't find a decoder if (prefConfig.videoFormat == PreferenceConfiguration.FORCE_H265_ON && !decoderRenderer.isHevcSupported()) { @@ -465,11 +466,6 @@ public class Game extends Activity implements SurfaceHolder.Callback, // Destroy the capture provider inputCaptureProvider.destroy(); - - // Clear the tombstone count - if (tombstonePrefs.getInt("CrashCount", 0) != 0) { - tombstonePrefs.edit().putInt("CrashCount", 0).apply(); - } } @Override @@ -511,6 +507,11 @@ public class Game extends Activity implements SurfaceHolder.Callback, if (message != null) { Toast.makeText(this, message, Toast.LENGTH_LONG).show(); } + + // Clear the tombstone count + if (tombstonePrefs.getInt("CrashCount", 0) != 0) { + tombstonePrefs.edit().putInt("CrashCount", 0).apply(); + } } finish(); diff --git a/app/src/main/java/com/limelight/PcView.java b/app/src/main/java/com/limelight/PcView.java index 53709eb4..5f9647db 100644 --- a/app/src/main/java/com/limelight/PcView.java +++ b/app/src/main/java/com/limelight/PcView.java @@ -167,19 +167,28 @@ public class PcView extends Activity implements AdapterFragmentCallbacks { SharedPreferences prefs = getSharedPreferences("DecoderTombstone", 0); int crashCount = prefs.getInt("CrashCount", 0); - if (crashCount == 3) { - // At 3 consecutive crashes, we'll forcefully reset their settings - PreferenceConfiguration.resetStreamingSettings(this); - Dialog.displayDialog(this, - getResources().getString(R.string.title_decoding_reset), - getResources().getString(R.string.message_decoding_reset), - false); - } - else if (crashCount >= 1) { - Dialog.displayDialog(this, - getResources().getString(R.string.title_decoding_error), - getResources().getString(R.string.message_decoding_error), - false); + int lastNotifiedCrashCount = prefs.getInt("LastNotifiedCrashCount", 0); + + // Remember the last crash count we notified at, so we don't + // display the crash dialog every time the app is started until + // they stream again + if (crashCount != 0 && crashCount != lastNotifiedCrashCount) { + if (crashCount % 3 == 0) { + // At 3 consecutive crashes, we'll forcefully reset their settings + PreferenceConfiguration.resetStreamingSettings(this); + Dialog.displayDialog(this, + getResources().getString(R.string.title_decoding_reset), + getResources().getString(R.string.message_decoding_reset), + false); + } + else { + Dialog.displayDialog(this, + getResources().getString(R.string.title_decoding_error), + getResources().getString(R.string.message_decoding_error), + false); + } + + prefs.edit().putInt("LastNotifiedCrashCount", crashCount).apply(); } } diff --git a/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java b/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java index 418bbc05..61850b10 100644 --- a/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java +++ b/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java @@ -49,6 +49,8 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer { private SurfaceHolder renderTarget; private volatile boolean stopping; private CrashListener crashListener; + private boolean reportedCrash; + private int consecutiveCrashCount; private boolean needsBaselineSpsHack; private SeqParameterSet savedSps; @@ -111,11 +113,13 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer { this.renderTarget = renderTarget; } - public MediaCodecDecoderRenderer(int videoFormat, int bitrate, boolean batterySaver, CrashListener crashListener) { + public MediaCodecDecoderRenderer(int videoFormat, int bitrate, boolean batterySaver, + CrashListener crashListener, int consecutiveCrashCount) { //dumpDecoders(); this.bitrate = bitrate; this.crashListener = crashListener; + this.consecutiveCrashCount = consecutiveCrashCount; // Disable spinner threads in battery saver mode if (batterySaver) { @@ -320,7 +324,10 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer { // This isn't the first time we've had an exception processing video if (System.currentTimeMillis() - initialExceptionTimestamp >= EXCEPTION_REPORT_DELAY_MS) { // It's been over 3 seconds and we're still getting exceptions. Throw the original now. - crashListener.notifyCrash(initialException); + if (!reportedCrash) { + reportedCrash = true; + crashListener.notifyCrash(initialException); + } throw initialException; } } @@ -916,6 +923,7 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer { str += "AVC Decoder: "+((renderer.avcDecoder != null) ? renderer.avcDecoder.getName():"(none)")+"\n"; str += "HEVC Decoder: "+((renderer.hevcDecoder != null) ? renderer.hevcDecoder.getName():"(none)")+"\n"; str += "Build fingerprint: "+Build.FINGERPRINT+"\n"; + str += "Consecutive crashes: "+renderer.consecutiveCrashCount+"\n"; str += "Initial video dimensions: "+renderer.initialWidth+"x"+renderer.initialHeight+"\n"; str += "FPS target: "+renderer.refreshRate+"\n"; str += "Bitrate: "+renderer.bitrate+" Mbps \n"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6daa76d8..8572c05c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -48,7 +48,7 @@ Using remote desktop software can also cause this error. Try rebooting your machine or reinstalling GFE. Video Decoder Crashed - Moonlight has crashed due to a issue with this device\'s video decoder. Try adjusting the streaming settings if the crashes continue. + Moonlight has crashed due to a problem with this device\'s video decoder. Try adjusting the streaming settings if the crashes continue. Video Settings Reset Your device\'s video decoder continues to crash at your selected streaming settings. Your streaming settings have been reset to default.