Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--no-playback, --no-video-playback, --no-audio-playback #4033

Merged
merged 10 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/data/bash-completion/scrcpy
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ _scrcpy() {
-M --hid-mouse
-m --max-size=
--no-audio
--no-audio-playback
--no-cleanup
--no-clipboard-autosync
--no-downsize-on-error
-n --no-control
-N --no-mirror
-N --no-playback
--no-key-repeat
--no-mipmaps
--no-power-on
--no-video
--no-video-playback
--otg
-p --port=
--power-off-on-close
Expand Down
4 changes: 3 additions & 1 deletion app/data/zsh-completion/_scrcpy
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ arguments=(
{-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-audio-playback[Disable audio playback]'
'--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]'
{-n,--no-control}'[Disable device control \(mirror the device in read only\)]'
{-N,--no-mirror}'[Do not mirror device \(only when recording or V4L2 sink is enabled\)]'
{-N,--no-playback}'[Disable video and audio playback]'
'--no-key-repeat[Do not forward repeated key events when a key is held down]'
'--no-mipmaps[Disable the generation of mipmaps]'
'--no-power-on[Do not power on the device on start]'
'--no-video[Disable video forwarding]'
'--no-video-playback[Disable video playback]'
'--otg[Run in OTG mode \(simulating physical keyboard and mouse\)]'
{-p,--port=}'[\[port\[\:port\]\] Set the TCP port \(range\) used by the client to listen]'
'--power-off-on-close[Turn the device screen off when closing scrcpy]'
Expand Down
12 changes: 10 additions & 2 deletions app/scrcpy.1
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ Also see \fB\-\-hid\-keyboard\fR.
.B \-\-no\-audio
Disable audio forwarding.

.TP
.B \-\-no\-audio\-playback
Disable audio playback on the computer.

.TP
.B \-\-no\-cleanup
By default, scrcpy removes the server binary from the device and restores the device state (show touches, stay awake and power mode) on exit.
Expand All @@ -210,8 +214,8 @@ This option disables this behavior.
Disable device control (mirror the device in read\-only).

.TP
.B \-N, \-\-no\-mirror
Do not mirror device video or audio on the computer (only when recording or V4L2 sink is enabled).
.B \-N, \-\-no\-playback
Disable video and audio playback on the computer (equivalent to --no-video-playback --no-audio-playback).

.TP
.B \-\-no\-key\-repeat
Expand All @@ -229,6 +233,10 @@ Do not power on the device on start.
.B \-\-no\-video
Disable video forwarding.

.TP
.B \-\-no\-video\-playback
Disable video playback on the computer.

.TP
.B \-\-otg
Run in OTG mode: simulate physical keyboard and mouse, as if the computer keyboard and mouse were plugged directly to the device via an OTG cable.
Expand Down
116 changes: 72 additions & 44 deletions app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ enum {
OPT_AUDIO_OUTPUT_BUFFER,
OPT_NO_DISPLAY,
OPT_NO_VIDEO,
OPT_NO_AUDIO_PLAYBACK,
OPT_NO_VIDEO_PLAYBACK,
};

struct sc_option {
Expand Down Expand Up @@ -351,6 +353,11 @@ static const struct sc_option options[] = {
.longopt = "no-audio",
.text = "Disable audio forwarding.",
},
{
.longopt_id = OPT_NO_AUDIO_PLAYBACK,
.longopt = "no-audio-playback",
.text = "Disable audio playback on the computer.",
},
{
.longopt_id = OPT_NO_CLEANUP,
.longopt = "no-cleanup",
Expand Down Expand Up @@ -382,9 +389,9 @@ static const struct sc_option options[] = {
},
{
.shortopt = 'N',
.longopt = "no-mirror",
.text = "Do not mirror device video or audio on the computer (only "
"when recording or V4L2 sink is enabled).",
.longopt = "no-playback",
.text = "Disable video and audio playback on the computer (equivalent "
"to --no-video-playback --no-audio-playback).",
},
{
// deprecated
Expand Down Expand Up @@ -413,6 +420,11 @@ static const struct sc_option options[] = {
.longopt = "no-video",
.text = "Disable video forwarding.",
},
{
.longopt_id = OPT_NO_VIDEO_PLAYBACK,
.longopt = "no-video-playback",
.text = "Disable video playback on the computer.",
},
{
.longopt_id = OPT_OTG,
.longopt = "otg",
Expand Down Expand Up @@ -1671,10 +1683,17 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
opts->control = false;
break;
case OPT_NO_DISPLAY:
LOGW("--no-display is deprecated, use --no-mirror instead.");
LOGW("--no-display is deprecated, use --no-playback instead.");
// fall through
case 'N':
opts->mirror = false;
opts->video_playback = false;
opts->audio_playback = false;
break;
case OPT_NO_VIDEO_PLAYBACK:
opts->video_playback = false;
break;
case OPT_NO_AUDIO_PLAYBACK:
opts->audio_playback = false;
break;
case 'p':
if (!parse_port_range(optarg, &opts->port_range)) {
Expand Down Expand Up @@ -1872,7 +1891,8 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
}
break;
#else
LOGE("V4L2 (--v4l2-buffer) is only available on Linux.");
LOGE("V4L2 (--v4l2-buffer) is disabled (or unsupported on this "
"platform).");
return false;
#endif
case OPT_LIST_ENCODERS:
Expand Down Expand Up @@ -1923,14 +1943,52 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
return false;
}

bool otg = false;
bool v4l2 = false;
#ifdef HAVE_USB
otg = opts->otg;
#endif
#ifdef HAVE_V4L2
if (!opts->mirror && !opts->record_filename && !opts->v4l2_device) {
LOGE("-N/--no-mirror requires either screen recording (-r/--record)"
" or sink to v4l2loopback device (--v4l2-sink)");
v4l2 = !!opts->v4l2_device;
#endif

if (!opts->video) {
opts->video_playback = false;
}

if (!opts->audio) {
opts->audio_playback = false;
}

if (!opts->video_playback && !otg) {
// If video playback is disabled and OTG are disabled, then there is
// no way to control the device.
opts->control = false;
}

if (opts->video && !opts->video_playback && !opts->record_filename
&& !v4l2) {
LOGI("No video playback, no recording, no V4L2 sink: video disabled");
opts->video = false;
}

if (opts->audio && !opts->audio_playback && !opts->record_filename) {
LOGI("No audio playback, no recording: audio disabled");
opts->audio = false;
}

if (!opts->video && !opts->audio && !otg) {
LOGE("No video, no audio, no OTG: nothing to do");
return false;
}

if (opts->v4l2_device) {
if (!opts->video && !otg) {
// If video is disabled, then scrcpy must exit on audio failure.
opts->require_audio = true;
}

#ifdef HAVE_V4L2
if (v4l2) {
if (opts->lock_video_orientation ==
SC_LOCK_VIDEO_ORIENTATION_UNLOCKED) {
LOGI("Video orientation is locked for v4l2 sink. "
Expand All @@ -1948,18 +2006,8 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
LOGE("V4L2 buffer value without V4L2 sink\n");
return false;
}
#else
if (!opts->mirror && !opts->record_filename) {
LOGE("-N/--no-mirror requires screen recording (-r/--record)");
return false;
}
#endif

if (opts->audio && !opts->mirror && !opts->record_filename) {
LOGI("No mirror and no recording: audio disabled");
opts->audio = false;
}

if ((opts->tunnel_host || opts->tunnel_port) && !opts->force_adb_forward) {
LOGI("Tunnel host/port is set, "
"--force-adb-forward automatically enabled.");
Expand Down Expand Up @@ -2039,11 +2087,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
}
}

#ifdef HAVE_USB

# ifdef _WIN32
if (!opts->otg && (opts->keyboard_input_mode == SC_KEYBOARD_INPUT_MODE_HID
|| opts->mouse_input_mode == SC_MOUSE_INPUT_MODE_HID)) {
if (!otg && (opts->keyboard_input_mode == SC_KEYBOARD_INPUT_MODE_HID
|| opts->mouse_input_mode == SC_MOUSE_INPUT_MODE_HID)) {
LOGE("On Windows, it is not possible to open a USB device already open "
"by another process (like adb).");
LOGE("Therefore, -K/--hid-keyboard and -M/--hid-mouse may only work in "
Expand All @@ -2052,7 +2098,7 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
}
# endif

if (opts->otg) {
if (otg) {
// OTG mode is compatible with only very few options.
// Only report obvious errors.
if (opts->record_filename) {
Expand All @@ -2079,28 +2125,10 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
LOGE("OTG mode: could not select display");
return false;
}
# ifdef HAVE_V4L2
if (opts->v4l2_device) {
if (v4l2) {
LOGE("OTG mode: could not sink to V4L2 device");
return false;
}
# endif
}
#endif

#ifdef HAVE_USB
if (!(opts->mirror && opts->video) && !opts->otg) {
#else
if (!(opts->mirror && opts->video)) {
#endif
// If video mirroring is disabled and OTG are disabled, then there is
// no way to control the device.
opts->control = false;
}

if (!opts->video) {
// If video is disabled, then scrcpy must exit on audio failure.
opts->require_audio = true;
}

return true;
Expand Down
11 changes: 6 additions & 5 deletions app/src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ const struct scrcpy_options scrcpy_options_default = {
.audio_codec_options = NULL,
.video_encoder = NULL,
.audio_encoder = NULL,
#ifdef HAVE_V4L2
.v4l2_device = NULL,
#endif
.log_level = SC_LOG_LEVEL_INFO,
.video_codec = SC_CODEC_H264,
.audio_codec = SC_CODEC_OPUS,
Expand Down Expand Up @@ -42,17 +39,21 @@ const struct scrcpy_options scrcpy_options_default = {
.window_height = 0,
.display_id = 0,
.display_buffer = 0,
.v4l2_buffer = 0,
.audio_buffer = SC_TICK_FROM_MS(50),
.audio_output_buffer = SC_TICK_FROM_MS(5),
#ifdef HAVE_V4L2
.v4l2_device = NULL,
.v4l2_buffer = 0,
#endif
#ifdef HAVE_USB
.otg = false,
#endif
.show_touches = false,
.fullscreen = false,
.always_on_top = false,
.control = true,
.mirror = true,
.video_playback = true,
.audio_playback = true,
.turn_screen_off = false,
.key_inject_mode = SC_KEY_INJECT_MODE_MIXED,
.window_borderless = false,
Expand Down
11 changes: 6 additions & 5 deletions app/src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ struct scrcpy_options {
const char *audio_codec_options;
const char *video_encoder;
const char *audio_encoder;
#ifdef HAVE_V4L2
const char *v4l2_device;
#endif
enum sc_log_level log_level;
enum sc_codec video_codec;
enum sc_codec audio_codec;
Expand All @@ -137,17 +134,21 @@ struct scrcpy_options {
uint16_t window_height;
uint32_t display_id;
sc_tick display_buffer;
sc_tick v4l2_buffer;
sc_tick audio_buffer;
sc_tick audio_output_buffer;
#ifdef HAVE_V4L2
const char *v4l2_device;
sc_tick v4l2_buffer;
#endif
#ifdef HAVE_USB
bool otg;
#endif
bool show_touches;
bool fullscreen;
bool always_on_top;
bool control;
bool mirror;
bool video_playback;
bool audio_playback;
bool turn_screen_off;
enum sc_key_inject_mode key_inject_mode;
bool window_borderless;
Expand Down
Loading