diff --git a/app/src/adb/adb.c b/app/src/adb/adb.c index 8742c4d0..4ddb93f3 100644 --- a/app/src/adb/adb.c +++ b/app/src/adb/adb.c @@ -204,6 +204,14 @@ sc_adb_start_server(struct sc_intr *intr, unsigned flags) { return process_check_success_intr(intr, pid, "adb start-server", flags); } +bool +sc_adb_kill_server(struct sc_intr *intr, unsigned flags) { + const char *const argv[] = SC_ADB_COMMAND("kill-server"); + + sc_pid pid = sc_adb_execute(argv, flags); + return process_check_success_intr(intr, pid, "adb kill-server", flags); +} + bool sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port, const char *device_socket_name, unsigned flags) { diff --git a/app/src/adb/adb.h b/app/src/adb/adb.h index 6ea6e897..10e8f293 100644 --- a/app/src/adb/adb.h +++ b/app/src/adb/adb.h @@ -36,6 +36,9 @@ sc_adb_execute(const char *const argv[], unsigned flags); bool sc_adb_start_server(struct sc_intr *intr, unsigned flags); +bool +sc_adb_kill_server(struct sc_intr *intr, unsigned flags); + bool sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port, const char *device_socket_name, unsigned flags); diff --git a/app/src/usb/scrcpy_otg.c b/app/src/usb/scrcpy_otg.c index 1eaa2537..1c53410e 100644 --- a/app/src/usb/scrcpy_otg.c +++ b/app/src/usb/scrcpy_otg.c @@ -2,6 +2,7 @@ #include +#include "adb/adb.h" #include "events.h" #include "screen_otg.h" #include "util/log.h" @@ -75,6 +76,15 @@ scrcpy_otg(struct scrcpy_options *options) { bool aoa_started = false; bool aoa_initialized = false; +#ifdef _WIN32 + // On Windows, only one process could open a USB device + // + 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 = { .on_disconnected = sc_usb_on_disconnected, };