From 2eb6fe7d81c15912a2252f229d317ae03f618a33 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 17 Jan 2022 20:22:33 +0100 Subject: [PATCH] Downsize on error only before the first frame The purpose of automatic downscaling on error is to make mirroring work by just starting scrcpy without an explicit -m value, even if the encoder could not encode at the screen definition. It is only useful when we detect an encoding failure before the first frame. Downsizing later could be surprising, so disable it. PR #2947 --- .../src/main/java/com/genymobile/scrcpy/ScreenEncoder.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java index 10ba9fac..06f06a9d 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java +++ b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java @@ -41,6 +41,8 @@ public class ScreenEncoder implements Device.RotationListener { private final boolean downsizeOnError; private long ptsOrigin; + private boolean firstFrameSent; + public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, List codecOptions, String encoderName, boolean downsizeOnError) { this.sendFrameMeta = sendFrameMeta; @@ -99,7 +101,7 @@ public class ScreenEncoder implements Device.RotationListener { codec.stop(); } catch (Exception e) { Ln.e("Encoding error: " + e.getClass().getName() + ": " + e.getMessage()); - if (!downsizeOnError) { + if (!downsizeOnError || firstFrameSent) { // Fail immediately throw e; } @@ -157,6 +159,7 @@ public class ScreenEncoder implements Device.RotationListener { } IO.writeFully(fd, codecBuffer); + firstFrameSent = true; } } finally { if (outputBufferId >= 0) {