Move call to send device name and size

This will allow to optionally disable it.

PR #2971 <https://github.com/Genymobile/scrcpy/pull/2971>
This commit is contained in:
Romain Vimont 2022-01-26 10:23:09 +01:00
parent f289d206ea
commit 31a5d0c2bf
2 changed files with 6 additions and 7 deletions

View file

@ -46,7 +46,7 @@ public final class DesktopConnection implements Closeable {
return localSocket; 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 videoSocket;
LocalSocket controlSocket = null; LocalSocket controlSocket = null;
if (tunnelForward) { if (tunnelForward) {
@ -78,10 +78,7 @@ public final class DesktopConnection implements Closeable {
} }
} }
DesktopConnection connection = new DesktopConnection(videoSocket, controlSocket); return new DesktopConnection(videoSocket, controlSocket);
Size videoSize = device.getScreenInfo().getVideoSize();
connection.send(Device.getDeviceName(), videoSize.getWidth(), videoSize.getHeight());
return connection;
} }
public void close() throws IOException { 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[] buffer = new byte[DEVICE_NAME_FIELD_LENGTH + 4];
byte[] deviceNameBytes = deviceName.getBytes(StandardCharsets.UTF_8); byte[] deviceNameBytes = deviceName.getBytes(StandardCharsets.UTF_8);

View file

@ -67,7 +67,9 @@ public final class Server {
boolean tunnelForward = options.isTunnelForward(); boolean tunnelForward = options.isTunnelForward();
boolean control = options.getControl(); 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, ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate(), options.getMaxFps(), codecOptions,
options.getEncoderName(), options.getDownsizeOnError()); options.getEncoderName(), options.getDownsizeOnError());