From 5f0480c0398bb3370d3a68182a0a4f950c56d824 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sat, 12 Oct 2024 09:23:31 +0200 Subject: [PATCH] Ignore first displayFoldChanged event An event is posted on registration to signal the initial state. This had no impact when the listener was registered from Device (before it was moved to ScreenCapture), because this first initial event was already triggered when ScreenCapture started listening. But now, it causes the first encoding to be reset immediately. To avoid that, ignore the first event. Refs PR #5370 --- .../java/com/genymobile/scrcpy/video/ScreenCapture.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java b/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java index af9a9283..df7cd8f2 100644 --- a/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java +++ b/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java @@ -75,8 +75,17 @@ public class ScreenCapture extends SurfaceCapture { if (Build.VERSION.SDK_INT >= AndroidVersions.API_29_ANDROID_10) { displayFoldListener = new IDisplayFoldListener.Stub() { + + private boolean first = true; + @Override public void onDisplayFoldChanged(int displayId, boolean folded) { + if (first) { + // An event is posted on registration to signal the initial state. Ignore it to avoid restarting encoding. + first = false; + return; + } + if (ScreenCapture.this.displayId != displayId) { // Ignore events related to other display ids return;