Add --no-kill-adb-before-otg option

Add an option not to kill the adb daemon on Windows if --otg is
specified.

Refs #4028 <https://github.com/Genymobile/scrcpy/issues/4028>
PR #4035 <https://github.com/Genymobile/scrcpy/pull/4035>

Signed-off-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
Self Not Found 2023-06-01 21:10:06 +02:00 committed by Romain Vimont
parent fc52b24503
commit fbeb53009a
4 changed files with 31 additions and 4 deletions

View File

@ -77,6 +77,7 @@ enum {
OPT_NO_AUDIO_PLAYBACK, OPT_NO_AUDIO_PLAYBACK,
OPT_NO_VIDEO_PLAYBACK, OPT_NO_VIDEO_PLAYBACK,
OPT_AUDIO_SOURCE, OPT_AUDIO_SOURCE,
OPT_NO_KILL_ADB_BEFORE_OTG,
}; };
struct sc_option { struct sc_option {
@ -411,6 +412,16 @@ static const struct sc_option options[] = {
.longopt = "no-key-repeat", .longopt = "no-key-repeat",
.text = "Do not forward repeated key events when a key is held down.", .text = "Do not forward repeated key events when a key is held down.",
}, },
{
.longopt_id = OPT_NO_KILL_ADB_BEFORE_OTG,
.longopt = "no-kill-adb-before-otg",
// with .text, the option is not documented on other platforms
#ifdef _WIN32
.text = "By default, scrcpy kills the adb daemon on Windows if --otg "
"is specified.\n"
"This option avoids to kill the adb daemon.",
#endif
},
{ {
.longopt_id = OPT_NO_MIPMAPS, .longopt_id = OPT_NO_MIPMAPS,
.longopt = "no-mipmaps", .longopt = "no-mipmaps",
@ -1944,6 +1955,14 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
return false; return false;
} }
break; break;
case OPT_NO_KILL_ADB_BEFORE_OTG:
#ifdef _WIN32
opts->kill_adb_before_otg = false;
break;
#else
LOGE("--no-kill-adb-before-otg only exists on Windows.");
return false;
#endif
default: default:
// getopt prints the error message on stderr // getopt prints the error message on stderr
return false; return false;

View File

@ -48,6 +48,9 @@ const struct scrcpy_options scrcpy_options_default = {
#endif #endif
#ifdef HAVE_USB #ifdef HAVE_USB
.otg = false, .otg = false,
#endif
#ifdef _WIN32
.kill_adb_before_otg = true,
#endif #endif
.show_touches = false, .show_touches = false,
.fullscreen = false, .fullscreen = false,

View File

@ -148,6 +148,9 @@ struct scrcpy_options {
#endif #endif
#ifdef HAVE_USB #ifdef HAVE_USB
bool otg; bool otg;
#endif
#ifdef _WIN32
bool kill_adb_before_otg;
#endif #endif
bool show_touches; bool show_touches;
bool fullscreen; bool fullscreen;

View File

@ -83,10 +83,12 @@ scrcpy_otg(struct scrcpy_options *options) {
#ifdef _WIN32 #ifdef _WIN32
// On Windows, only one process could open a USB device // On Windows, only one process could open a USB device
// <https://github.com/Genymobile/scrcpy/issues/2773> // <https://github.com/Genymobile/scrcpy/issues/2773>
LOGI("Killing adb daemon (if any)..."); if (options->kill_adb_before_otg) {
unsigned flags = SC_ADB_NO_STDOUT | SC_ADB_NO_STDERR | SC_ADB_NO_LOGERR; LOGI("Killing adb daemon (if any)...");
// uninterruptible (intr == NULL), but in practice it's very quick unsigned flags = SC_ADB_NO_STDOUT | SC_ADB_NO_STDERR | SC_ADB_NO_LOGERR;
sc_adb_kill_server(NULL, flags); // uninterruptible (intr == NULL), but in practice it's very quick
sc_adb_kill_server(NULL, flags);
}
#endif #endif
static const struct sc_usb_callbacks cbs = { static const struct sc_usb_callbacks cbs = {