Skip to content

Commit

Permalink
Add --no-kill-adb-before-otg option
Browse files Browse the repository at this point in the history
Add an option not to kill the adb daemon on Windows if --otg is
specified.

Refs #4028 <#4028>
PR #4035 <#4035>

Signed-off-by: Romain Vimont <[email protected]>
  • Loading branch information
wh201906 authored and rom1v committed Jun 1, 2023
1 parent fc52b24 commit fbeb530
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
19 changes: 19 additions & 0 deletions app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ enum {
OPT_NO_AUDIO_PLAYBACK,
OPT_NO_VIDEO_PLAYBACK,
OPT_AUDIO_SOURCE,
OPT_NO_KILL_ADB_BEFORE_OTG,
};

struct sc_option {
Expand Down Expand Up @@ -411,6 +412,16 @@ static const struct sc_option options[] = {
.longopt = "no-key-repeat",
.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 = "no-mipmaps",
Expand Down Expand Up @@ -1944,6 +1955,14 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
return false;
}
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:
// getopt prints the error message on stderr
return false;
Expand Down
3 changes: 3 additions & 0 deletions app/src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const struct scrcpy_options scrcpy_options_default = {
#endif
#ifdef HAVE_USB
.otg = false,
#endif
#ifdef _WIN32
.kill_adb_before_otg = true,
#endif
.show_touches = false,
.fullscreen = false,
Expand Down
3 changes: 3 additions & 0 deletions app/src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ struct scrcpy_options {
#endif
#ifdef HAVE_USB
bool otg;
#endif
#ifdef _WIN32
bool kill_adb_before_otg;
#endif
bool show_touches;
bool fullscreen;
Expand Down
10 changes: 6 additions & 4 deletions app/src/usb/scrcpy_otg.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ scrcpy_otg(struct scrcpy_options *options) {
#ifdef _WIN32
// On Windows, only one process could open a USB device
// <https://github.com/Genymobile/scrcpy/issues/2773>
LOGI("Killing adb daemon (if any)...");
unsigned flags = SC_ADB_NO_STDOUT | SC_ADB_NO_STDERR | SC_ADB_NO_LOGERR;
// uninterruptible (intr == NULL), but in practice it's very quick
sc_adb_kill_server(NULL, flags);
if (options->kill_adb_before_otg) {
LOGI("Killing adb daemon (if any)...");
unsigned flags = SC_ADB_NO_STDOUT | SC_ADB_NO_STDERR | SC_ADB_NO_LOGERR;
// uninterruptible (intr == NULL), but in practice it's very quick
sc_adb_kill_server(NULL, flags);
}
#endif

static const struct sc_usb_callbacks cbs = {
Expand Down

0 comments on commit fbeb530

Please sign in to comment.