Add server option send_device_meta

Similar to send_device_frame, this option allows to disable sending the
device name and size on start.

This is only useful when using the scrcpy-server alone to get a raw
H.264 stream, without using the scrcpy client.

PR #2971 <https://github.com/Genymobile/scrcpy/pull/2971>
This commit is contained in:
Romain Vimont 2022-01-26 10:24:41 +01:00
parent 6b21f4ae13
commit 3ba32c2a0d
2 changed files with 17 additions and 2 deletions

View file

@ -23,6 +23,7 @@ public class Options {
private boolean downsizeOnError = true; private boolean downsizeOnError = true;
// Options not used by the scrcpy client, but useful to use scrcpy-server directly // Options not used by the scrcpy client, but useful to use scrcpy-server directly
private boolean sendDeviceMeta = true; // send device name and size
private boolean sendFrameMeta = true; // send PTS so that the client may record properly private boolean sendFrameMeta = true; // send PTS so that the client may record properly
public Ln.Level getLogLevel() { public Ln.Level getLogLevel() {
@ -153,6 +154,14 @@ public class Options {
this.downsizeOnError = downsizeOnError; this.downsizeOnError = downsizeOnError;
} }
public boolean getSendDeviceMeta() {
return sendDeviceMeta;
}
public void setSendDeviceMeta(boolean sendDeviceMeta) {
this.sendDeviceMeta = sendDeviceMeta;
}
public boolean getSendFrameMeta() { public boolean getSendFrameMeta() {
return sendFrameMeta; return sendFrameMeta;
} }

View file

@ -68,8 +68,10 @@ public final class Server {
boolean control = options.getControl(); boolean control = options.getControl();
try (DesktopConnection connection = DesktopConnection.open(tunnelForward, control)) { try (DesktopConnection connection = DesktopConnection.open(tunnelForward, control)) {
Size videoSize = device.getScreenInfo().getVideoSize(); if (options.getSendDeviceMeta()) {
connection.sendDeviceMeta(Device.getDeviceName(), videoSize.getWidth(), videoSize.getHeight()); 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());
@ -238,6 +240,10 @@ public final class Server {
boolean downsizeOnError = Boolean.parseBoolean(value); boolean downsizeOnError = Boolean.parseBoolean(value);
options.setDownsizeOnError(downsizeOnError); options.setDownsizeOnError(downsizeOnError);
break; break;
case "send_device_meta":
boolean sendDeviceMeta = Boolean.parseBoolean(value);
options.setSendDeviceMeta(sendDeviceMeta);
break;
case "send_frame_meta": case "send_frame_meta":
boolean sendFrameMeta = Boolean.parseBoolean(value); boolean sendFrameMeta = Boolean.parseBoolean(value);
options.setSendFrameMeta(sendFrameMeta); options.setSendFrameMeta(sendFrameMeta);