Skip to content

Commit 0457253

Browse files
yume-chanrom1v
andcommitted
Add --no-audio option
Audio will be enabled by default (when supported). Add an option to disable it. PR #3757 <#3757> Co-authored-by: Romain Vimont <[email protected]> Signed-off-by: Romain Vimont <[email protected]>
1 parent 484f38b commit 0457253

File tree

10 files changed

+31
-0
lines changed

10 files changed

+31
-0
lines changed

app/data/bash-completion/scrcpy

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ _scrcpy() {
2323
--max-fps=
2424
-M --hid-mouse
2525
-m --max-size=
26+
--no-audio
2627
--no-cleanup
2728
--no-clipboard-autosync
2829
--no-downsize-on-error

app/data/zsh-completion/_scrcpy

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ arguments=(
2929
'--max-fps=[Limit the frame rate of screen capture]'
3030
{-M,--hid-mouse}'[Simulate a physical mouse by using HID over AOAv2]'
3131
{-m,--max-size=}'[Limit both the width and height of the video to value]'
32+
'--no-audio[Disable audio forwarding]'
3233
'--no-cleanup[Disable device cleanup actions on exit]'
3334
'--no-clipboard-autosync[Disable automatic clipboard synchronization]'
3435
'--no-downsize-on-error[Disable lowering definition on MediaCodec error]'

app/src/cli.c

+9
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ enum {
5959
OPT_PRINT_FPS,
6060
OPT_NO_POWER_ON,
6161
OPT_CODEC,
62+
OPT_NO_AUDIO,
6263
};
6364

6465
struct sc_option {
@@ -267,6 +268,11 @@ static const struct sc_option options[] = {
267268
"is preserved.\n"
268269
"Default is 0 (unlimited).",
269270
},
271+
{
272+
.longopt_id = OPT_NO_AUDIO,
273+
.longopt = "no-audio",
274+
.text = "Disable audio forwarding.",
275+
},
270276
{
271277
.longopt_id = OPT_NO_CLEANUP,
272278
.longopt = "no-cleanup",
@@ -1630,6 +1636,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
16301636
case OPT_NO_DOWNSIZE_ON_ERROR:
16311637
opts->downsize_on_error = false;
16321638
break;
1639+
case OPT_NO_AUDIO:
1640+
opts->audio = false;
1641+
break;
16331642
case OPT_NO_CLEANUP:
16341643
opts->cleanup = false;
16351644
break;

app/src/options.c

+1
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@ const struct scrcpy_options scrcpy_options_default = {
6767
.cleanup = true,
6868
.start_fps_counter = false,
6969
.power_on = true,
70+
.audio = true,
7071
};

app/src/options.h

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ struct scrcpy_options {
147147
bool cleanup;
148148
bool start_fps_counter;
149149
bool power_on;
150+
bool audio;
150151
};
151152

152153
extern const struct scrcpy_options scrcpy_options_default;

app/src/scrcpy.c

+1
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ scrcpy(struct scrcpy_options *options) {
312312
.lock_video_orientation = options->lock_video_orientation,
313313
.control = options->control,
314314
.display_id = options->display_id,
315+
.audio = options->audio,
315316
.show_touches = options->show_touches,
316317
.stay_awake = options->stay_awake,
317318
.codec_options = options->codec_options,

app/src/server.c

+3
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ execute_server(struct sc_server *server,
217217
ADD_PARAM("log_level=%s", log_level_to_server_string(params->log_level));
218218
ADD_PARAM("bit_rate=%" PRIu32, params->bit_rate);
219219

220+
if (!params->audio) {
221+
ADD_PARAM("audio=false");
222+
}
220223
if (params->codec != SC_CODEC_H264) {
221224
ADD_PARAM("codec=%s", sc_server_get_codec_name(params->codec));
222225
}

app/src/server.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct sc_server_params {
3838
int8_t lock_video_orientation;
3939
bool control;
4040
uint32_t display_id;
41+
bool audio;
4142
bool show_touches;
4243
bool stay_awake;
4344
bool force_adb_forward;

server/src/main/java/com/genymobile/scrcpy/Options.java

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class Options {
88

99
private Ln.Level logLevel = Ln.Level.DEBUG;
1010
private int scid = -1; // 31-bit non-negative value, or -1
11+
private boolean audio = true;
1112
private int maxSize;
1213
private VideoCodec codec = VideoCodec.H264;
1314
private int bitRate = 8000000;
@@ -49,6 +50,14 @@ public void setScid(int scid) {
4950
this.scid = scid;
5051
}
5152

53+
public boolean getAudio() {
54+
return audio;
55+
}
56+
57+
public void setAudio(boolean audio) {
58+
this.audio = audio;
59+
}
60+
5261
public int getMaxSize() {
5362
return maxSize;
5463
}

server/src/main/java/com/genymobile/scrcpy/Server.java

+4
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ private static Options createOptions(String... args) {
169169
Ln.Level level = Ln.Level.valueOf(value.toUpperCase(Locale.ENGLISH));
170170
options.setLogLevel(level);
171171
break;
172+
case "audio":
173+
boolean audio = Boolean.parseBoolean(value);
174+
options.setAudio(audio);
175+
break;
172176
case "codec":
173177
VideoCodec codec = VideoCodec.findByName(value);
174178
if (codec == null) {

0 commit comments

Comments
 (0)