From 31a5d0c2bfab4d8f74b116d634f63a0f3a79889a Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 26 Jan 2022 10:23:09 +0100 Subject: [PATCH] Move call to send device name and size This will allow to optionally disable it. PR #2971 --- .../java/com/genymobile/scrcpy/DesktopConnection.java | 9 +++------ server/src/main/java/com/genymobile/scrcpy/Server.java | 4 +++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java b/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java index 40cb088c..ca20c1d8 100644 --- a/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java +++ b/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java @@ -46,7 +46,7 @@ public final class DesktopConnection implements Closeable { return localSocket; } - public static DesktopConnection open(Device device, boolean tunnelForward, boolean control) throws IOException { + public static DesktopConnection open(boolean tunnelForward, boolean control) throws IOException { LocalSocket videoSocket; LocalSocket controlSocket = null; if (tunnelForward) { @@ -78,10 +78,7 @@ public final class DesktopConnection implements Closeable { } } - DesktopConnection connection = new DesktopConnection(videoSocket, controlSocket); - Size videoSize = device.getScreenInfo().getVideoSize(); - connection.send(Device.getDeviceName(), videoSize.getWidth(), videoSize.getHeight()); - return connection; + return new DesktopConnection(videoSocket, controlSocket); } public void close() throws IOException { @@ -95,7 +92,7 @@ public final class DesktopConnection implements Closeable { } } - private void send(String deviceName, int width, int height) throws IOException { + public void sendDeviceMeta(String deviceName, int width, int height) throws IOException { byte[] buffer = new byte[DEVICE_NAME_FIELD_LENGTH + 4]; byte[] deviceNameBytes = deviceName.getBytes(StandardCharsets.UTF_8); diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index 9d7a62e3..6dc0b2c6 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -67,7 +67,9 @@ public final class Server { boolean tunnelForward = options.isTunnelForward(); boolean control = options.getControl(); - try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward, control)) { + try (DesktopConnection connection = DesktopConnection.open(tunnelForward, control)) { + Size videoSize = device.getScreenInfo().getVideoSize(); + connection.sendDeviceMeta(Device.getDeviceName(), videoSize.getWidth(), videoSize.getHeight()); ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate(), options.getMaxFps(), codecOptions, options.getEncoderName(), options.getDownsizeOnError());