From 3cf03e4a4bea7b93766f6e5fb66d8e8878a6a906 Mon Sep 17 00:00:00 2001 From: Simon Chan <1330321+yume-chan@users.noreply.github.com> Date: Fri, 3 Feb 2023 16:27:34 +0100 Subject: [PATCH] Add --no-audio option Audio will be enabled by default (when supported). Add an option to disable it. PR #3757 Co-authored-by: Romain Vimont Signed-off-by: Romain Vimont --- app/data/bash-completion/scrcpy | 1 + app/data/zsh-completion/_scrcpy | 1 + app/src/cli.c | 9 +++++++++ app/src/options.c | 1 + app/src/options.h | 1 + app/src/scrcpy.c | 1 + app/src/server.c | 3 +++ app/src/server.h | 1 + server/src/main/java/com/genymobile/scrcpy/Options.java | 9 +++++++++ server/src/main/java/com/genymobile/scrcpy/Server.java | 4 ++++ 10 files changed, 31 insertions(+) diff --git a/app/data/bash-completion/scrcpy b/app/data/bash-completion/scrcpy index 4590b6a8..22dc4cee 100644 --- a/app/data/bash-completion/scrcpy +++ b/app/data/bash-completion/scrcpy @@ -23,6 +23,7 @@ _scrcpy() { --max-fps= -M --hid-mouse -m --max-size= + --no-audio --no-cleanup --no-clipboard-autosync --no-downsize-on-error diff --git a/app/data/zsh-completion/_scrcpy b/app/data/zsh-completion/_scrcpy index 961565e7..17e1de9f 100644 --- a/app/data/zsh-completion/_scrcpy +++ b/app/data/zsh-completion/_scrcpy @@ -29,6 +29,7 @@ arguments=( '--max-fps=[Limit the frame rate of screen capture]' {-M,--hid-mouse}'[Simulate a physical mouse by using HID over AOAv2]' {-m,--max-size=}'[Limit both the width and height of the video to value]' + '--no-audio[Disable audio forwarding]' '--no-cleanup[Disable device cleanup actions on exit]' '--no-clipboard-autosync[Disable automatic clipboard synchronization]' '--no-downsize-on-error[Disable lowering definition on MediaCodec error]' diff --git a/app/src/cli.c b/app/src/cli.c index ab460732..c1ee1e6d 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -59,6 +59,7 @@ enum { OPT_PRINT_FPS, OPT_NO_POWER_ON, OPT_CODEC, + OPT_NO_AUDIO, }; struct sc_option { @@ -267,6 +268,11 @@ static const struct sc_option options[] = { "is preserved.\n" "Default is 0 (unlimited).", }, + { + .longopt_id = OPT_NO_AUDIO, + .longopt = "no-audio", + .text = "Disable audio forwarding.", + }, { .longopt_id = OPT_NO_CLEANUP, .longopt = "no-cleanup", @@ -1630,6 +1636,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[], case OPT_NO_DOWNSIZE_ON_ERROR: opts->downsize_on_error = false; break; + case OPT_NO_AUDIO: + opts->audio = false; + break; case OPT_NO_CLEANUP: opts->cleanup = false; break; diff --git a/app/src/options.c b/app/src/options.c index a75e584e..0854067f 100644 --- a/app/src/options.c +++ b/app/src/options.c @@ -67,4 +67,5 @@ const struct scrcpy_options scrcpy_options_default = { .cleanup = true, .start_fps_counter = false, .power_on = true, + .audio = true, }; diff --git a/app/src/options.h b/app/src/options.h index b9d237e0..7bf30011 100644 --- a/app/src/options.h +++ b/app/src/options.h @@ -147,6 +147,7 @@ struct scrcpy_options { bool cleanup; bool start_fps_counter; bool power_on; + bool audio; }; extern const struct scrcpy_options scrcpy_options_default; diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 68665125..6d63a7a1 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -312,6 +312,7 @@ scrcpy(struct scrcpy_options *options) { .lock_video_orientation = options->lock_video_orientation, .control = options->control, .display_id = options->display_id, + .audio = options->audio, .show_touches = options->show_touches, .stay_awake = options->stay_awake, .codec_options = options->codec_options, diff --git a/app/src/server.c b/app/src/server.c index 413f02ee..0ff0d3c8 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -217,6 +217,9 @@ execute_server(struct sc_server *server, ADD_PARAM("log_level=%s", log_level_to_server_string(params->log_level)); ADD_PARAM("bit_rate=%" PRIu32, params->bit_rate); + if (!params->audio) { + ADD_PARAM("audio=false"); + } if (params->codec != SC_CODEC_H264) { ADD_PARAM("codec=%s", sc_server_get_codec_name(params->codec)); } diff --git a/app/src/server.h b/app/src/server.h index c05b1e5b..95e24b41 100644 --- a/app/src/server.h +++ b/app/src/server.h @@ -38,6 +38,7 @@ struct sc_server_params { int8_t lock_video_orientation; bool control; uint32_t display_id; + bool audio; bool show_touches; bool stay_awake; bool force_adb_forward; diff --git a/server/src/main/java/com/genymobile/scrcpy/Options.java b/server/src/main/java/com/genymobile/scrcpy/Options.java index 5c59ec8e..07789974 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Options.java +++ b/server/src/main/java/com/genymobile/scrcpy/Options.java @@ -8,6 +8,7 @@ public class Options { private Ln.Level logLevel = Ln.Level.DEBUG; private int scid = -1; // 31-bit non-negative value, or -1 + private boolean audio = true; private int maxSize; private VideoCodec codec = VideoCodec.H264; private int bitRate = 8000000; @@ -49,6 +50,14 @@ public class Options { this.scid = scid; } + public boolean getAudio() { + return audio; + } + + public void setAudio(boolean audio) { + this.audio = audio; + } + public int getMaxSize() { return maxSize; } diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index d570a9fb..2aeeb79e 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -169,6 +169,10 @@ public final class Server { Ln.Level level = Ln.Level.valueOf(value.toUpperCase(Locale.ENGLISH)); options.setLogLevel(level); break; + case "audio": + boolean audio = Boolean.parseBoolean(value); + options.setAudio(audio); + break; case "codec": VideoCodec codec = VideoCodec.findByName(value); if (codec == null) {