Make auto-downsize on error optional

Add --no-downsize-on-error option to disable attempts to use a lower
definition on MediaCodec error.

PR #2947 <https://github.com/Genymobile/scrcpy/pull/2947>
This commit is contained in:
Romain Vimont 2022-01-15 23:01:14 +01:00
parent 26b4104844
commit 15bf27afdd
10 changed files with 48 additions and 2 deletions

View file

@ -140,6 +140,12 @@ By default, scrcpy automatically synchronizes the computer clipboard to the devi
This option disables this automatic synchronization. This option disables this automatic synchronization.
.TP
.B \-\-no\-downsize\-on\-error
By default, on MediaCodec error, scrcpy automatically tries again with a lower definition.
This option disables this behavior.
.TP .TP
.B \-n, \-\-no\-control .B \-n, \-\-no\-control
Disable device control (mirror the device in read\-only). Disable device control (mirror the device in read\-only).

View file

@ -52,6 +52,7 @@
#define OPT_NO_CLIPBOARD_AUTOSYNC 1032 #define OPT_NO_CLIPBOARD_AUTOSYNC 1032
#define OPT_TCPIP 1033 #define OPT_TCPIP 1033
#define OPT_RAW_KEY_EVENTS 1034 #define OPT_RAW_KEY_EVENTS 1034
#define OPT_NO_DOWNSIZE_ON_ERROR 1035
struct sc_option { struct sc_option {
char shortopt; char shortopt;
@ -236,6 +237,13 @@ static const struct sc_option options[] = {
"is preserved.\n" "is preserved.\n"
"Default is 0 (unlimited).", "Default is 0 (unlimited).",
}, },
{
.longopt_id = OPT_NO_DOWNSIZE_ON_ERROR,
.longopt = "no-downsize-on-error",
.text = "By default, on MediaCodec error, scrcpy automatically tries "
"again with a lower definition.\n"
"This option disables this behavior.",
},
{ {
.longopt_id = OPT_NO_CLIPBOARD_AUTOSYNC, .longopt_id = OPT_NO_CLIPBOARD_AUTOSYNC,
.longopt = "no-clipboard-autosync", .longopt = "no-clipboard-autosync",
@ -1489,6 +1497,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
opts->tcpip = true; opts->tcpip = true;
opts->tcpip_dst = optarg; opts->tcpip_dst = optarg;
break; break;
case OPT_NO_DOWNSIZE_ON_ERROR:
opts->downsize_on_error = false;
break;
case OPT_V4L2_SINK: case OPT_V4L2_SINK:
#ifdef HAVE_V4L2 #ifdef HAVE_V4L2
opts->v4l2_device = optarg; opts->v4l2_device = optarg;

View file

@ -54,6 +54,7 @@ const struct scrcpy_options scrcpy_options_default = {
.legacy_paste = false, .legacy_paste = false,
.power_off_on_close = false, .power_off_on_close = false,
.clipboard_autosync = true, .clipboard_autosync = true,
.downsize_on_error = true,
.tcpip = false, .tcpip = false,
.tcpip_dst = NULL, .tcpip_dst = NULL,
}; };

View file

@ -129,6 +129,7 @@ struct scrcpy_options {
bool legacy_paste; bool legacy_paste;
bool power_off_on_close; bool power_off_on_close;
bool clipboard_autosync; bool clipboard_autosync;
bool downsize_on_error;
bool tcpip; bool tcpip;
const char *tcpip_dst; const char *tcpip_dst;
}; };

View file

@ -364,6 +364,7 @@ scrcpy(struct scrcpy_options *options) {
.force_adb_forward = options->force_adb_forward, .force_adb_forward = options->force_adb_forward,
.power_off_on_close = options->power_off_on_close, .power_off_on_close = options->power_off_on_close,
.clipboard_autosync = options->clipboard_autosync, .clipboard_autosync = options->clipboard_autosync,
.downsize_on_error = options->downsize_on_error,
.tcpip = options->tcpip, .tcpip = options->tcpip,
.tcpip_dst = options->tcpip_dst, .tcpip_dst = options->tcpip_dst,
}; };

View file

@ -234,6 +234,10 @@ execute_server(struct sc_server *server,
// By default, clipboard_autosync is true // By default, clipboard_autosync is true
ADD_PARAM("clipboard_autosync=false"); ADD_PARAM("clipboard_autosync=false");
} }
if (!params->downsize_on_error) {
// By default, downsize_on_error is true
ADD_PARAM("downsize_on_error=false");
}
#undef ADD_PARAM #undef ADD_PARAM
#undef STRBOOL #undef STRBOOL

View file

@ -42,6 +42,7 @@ struct sc_server_params {
bool force_adb_forward; bool force_adb_forward;
bool power_off_on_close; bool power_off_on_close;
bool clipboard_autosync; bool clipboard_autosync;
bool downsize_on_error;
bool tcpip; bool tcpip;
const char *tcpip_dst; const char *tcpip_dst;
}; };

View file

@ -21,6 +21,7 @@ public class Options {
private String encoderName; private String encoderName;
private boolean powerOffScreenOnClose; private boolean powerOffScreenOnClose;
private boolean clipboardAutosync = true; private boolean clipboardAutosync = true;
private boolean downsizeOnError = true;
public Ln.Level getLogLevel() { public Ln.Level getLogLevel() {
return logLevel; return logLevel;
@ -149,4 +150,12 @@ public class Options {
public void setClipboardAutosync(boolean clipboardAutosync) { public void setClipboardAutosync(boolean clipboardAutosync) {
this.clipboardAutosync = clipboardAutosync; this.clipboardAutosync = clipboardAutosync;
} }
public boolean getDownsizeOnError() {
return downsizeOnError;
}
public void setDownsizeOnError(boolean downsizeOnError) {
this.downsizeOnError = downsizeOnError;
}
} }

View file

@ -38,14 +38,17 @@ public class ScreenEncoder implements Device.RotationListener {
private final int bitRate; private final int bitRate;
private final int maxFps; private final int maxFps;
private final boolean sendFrameMeta; private final boolean sendFrameMeta;
private final boolean downsizeOnError;
private long ptsOrigin; private long ptsOrigin;
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, List<CodecOption> codecOptions, String encoderName) { public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, List<CodecOption> codecOptions, String encoderName,
boolean downsizeOnError) {
this.sendFrameMeta = sendFrameMeta; this.sendFrameMeta = sendFrameMeta;
this.bitRate = bitRate; this.bitRate = bitRate;
this.maxFps = maxFps; this.maxFps = maxFps;
this.codecOptions = codecOptions; this.codecOptions = codecOptions;
this.encoderName = encoderName; this.encoderName = encoderName;
this.downsizeOnError = downsizeOnError;
} }
@Override @Override
@ -96,6 +99,11 @@ public class ScreenEncoder implements Device.RotationListener {
codec.stop(); codec.stop();
} catch (Exception e) { } catch (Exception e) {
Ln.e("Encoding error: " + e.getClass().getName() + ": " + e.getMessage()); Ln.e("Encoding error: " + e.getClass().getName() + ": " + e.getMessage());
if (!downsizeOnError) {
// Fail immediately
throw e;
}
int newMaxSize = chooseMaxSizeFallback(screenInfo.getVideoSize()); int newMaxSize = chooseMaxSizeFallback(screenInfo.getVideoSize());
if (newMaxSize == 0) { if (newMaxSize == 0) {
// Definitively fail // Definitively fail

View file

@ -70,7 +70,7 @@ public final class Server {
try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward, control)) { try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward, control)) {
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.getEncoderName(), options.getDownsizeOnError());
Thread controllerThread = null; Thread controllerThread = null;
Thread deviceMessageSenderThread = null; Thread deviceMessageSenderThread = null;
@ -237,6 +237,10 @@ public final class Server {
boolean clipboardAutosync = Boolean.parseBoolean(value); boolean clipboardAutosync = Boolean.parseBoolean(value);
options.setClipboardAutosync(clipboardAutosync); options.setClipboardAutosync(clipboardAutosync);
break; break;
case "downsize_on_error":
boolean downsizeOnError = Boolean.parseBoolean(value);
options.setDownsizeOnError(downsizeOnError);
break;
default: default:
Ln.w("Unknown server option: " + key); Ln.w("Unknown server option: " + key);
break; break;