From a9429efa34b3cbdc57847cb37d3621b889522c7f Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 23 Jan 2022 21:46:57 +0100 Subject: [PATCH] Fix downsize on error before first frame Retry with a lower definition if MediaCodec fails before the first frame, not the first packet. In practice, the first packet is a config packet without any frame, and MediaCodec might fail just after. Refs 2eb6fe7d81c15912a2252f229d317ae03f618a33 Refs #2963 --- .../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 e4e87c72..4c23dd92 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java +++ b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java @@ -159,7 +159,10 @@ public class ScreenEncoder implements Device.RotationListener { } IO.writeFully(fd, codecBuffer); - firstFrameSent = true; + if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG) == 0) { + // If this is not a config packet, then it contains a frame + firstFrameSent = true; + } } } finally { if (outputBufferId >= 0) {