Display and control your Android device
Add --hwdec option
Romain Vimont1532b9783853
diff --git a/app/data/bash-completion/scrcpy b/app/data/bash-completion/scrcpyindex d3a05cdc..896d8068 100644--- a/app/data/bash-completion/scrcpy+++ b/app/data/bash-completion/scrcpy@@ -34,6 +34,7 @@ _scrcpy() {-G--gamepad=-h --help+ --hwdec=--ignore-video-encoder-constraints-K--keep-active@@ -205,6 +206,10 @@ _scrcpy() {COMPREPLY=($(compgen -W '1 2 4 8 16' -- "$cur"))return;;+ --hwdec)+ COMPREPLY=($(compgen -W 'auto disabled' -- "$cur"))+ return+ ;;--audio-bit-rate \|--audio-buffer \|-b|--video-bit-rate \diff --git a/app/data/zsh-completion/_scrcpy b/app/data/zsh-completion/_scrcpyindex bef79279..5b1aeb87 100644--- a/app/data/zsh-completion/_scrcpy+++ b/app/data/zsh-completion/_scrcpy@@ -41,6 +41,7 @@ arguments=('-G[Use UHID/AOA gamepad \(same as --gamepad=uhid or --gamepad=aoa, depending on OTG mode\)]''--gamepad=[Set the gamepad input mode]:mode:(disabled uhid aoa)'{-h,--help}'[Print the help]'+ '--hwdec=[Configure hardware video decoding on the computer]:mode:(auto disabled)''--ignore-video-encoder-constraints[Do not consider video encoder capabilities]''-K[Use UHID/AOA keyboard \(same as --keyboard=uhid or --keyboard=aoa, depending on OTG mode\)]''--keep-active[Keep the screen on by simulating user activity]'diff --git a/app/scrcpy.1 b/app/scrcpy.1index d65ffdd7..371e8f64 100644--- a/app/scrcpy.1+++ b/app/scrcpy.1@@ -235,6 +235,14 @@ Also see \fB\-\-keyboard\fR and R\fB\-\-mouse\fR..B \-h, \-\-helpPrint this help.+.TP+.BI "\-\-hwdec " mode+Configure hardware video decoding on the computer.++Possible values are "auto" (the first available hardware decoder, software decoding otherwise) and "disabled" (always use software decoding).++Default is "auto".+.TP.B \-\-ignore\-video\-encoder\-constraintsDo not consider video encoder capabilities.diff --git a/app/src/cli.c b/app/src/cli.cindex 5fffcbe2..0baedc8c 100644--- a/app/src/cli.c+++ b/app/src/cli.c@@ -111,6 +111,7 @@ enum {OPT_RENDER_FIT,OPT_IGNORE_VIDEO_ENCODER_CONSTRAINTS,OPT_NO_TERMINAL_TITLE,+ OPT_HWDEC,};struct sc_option {@@ -430,6 +431,16 @@ static const struct sc_option options[] = {.longopt = "help",.text = "Print this help.",},+ {+ .longopt_id = OPT_HWDEC,+ .longopt = "hwdec",+ .argdesc = "mode",+ .text = "Configure hardware video decoding on the computer.\n"+ "Possible values are \"auto\" (the first available hardware "+ "decoder, software decoding otherwise) and \"disabled\" "+ "(always use software decoding).\n"+ "Default is \"auto\".",+ },{.longopt_id = OPT_IGNORE_VIDEO_ENCODER_CONSTRAINTS,.longopt = "ignore-video-encoder-constraints",@@ -2487,6 +2498,22 @@ parse_render_fit(const char *optarg, enum sc_render_fit *mode) {return false;}+static bool+parse_hwdec_mode(const char *optarg, enum sc_hwdec_mode *mode) {+ if (!strcmp(optarg, "auto")) {+ *mode = SC_HWDEC_MODE_AUTO;+ return true;+ }++ if (!strcmp(optarg, "disabled")) {+ *mode = SC_HWDEC_MODE_DISABLED;+ return true;+ }++ LOGE("Unsupported hwdec mode: %s (expected auto or disabled)", optarg);+ return false;+}+static boolparse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],const char *optstring, const struct option *longopts) {@@ -2945,6 +2972,11 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],case OPT_NO_TERMINAL_TITLE:opts->update_terminal_title = false;break;+ case OPT_HWDEC:+ if (!parse_hwdec_mode(optarg, &opts->hwdec_mode)) {+ return false;+ }+ break;default:// getopt prints the error message on stderrreturn false;@@ -3033,6 +3065,23 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],}}+ if (opts->hwdec_mode != SC_HWDEC_MODE_DISABLED) {+ if (!opts->video_playback) {+ if (opts->hwdec_mode != SC_HWDEC_MODE_AUTO) {+ LOGE("Hardware decoding requires video playback");+ return false;+ }+ opts->hwdec_mode = SC_HWDEC_MODE_DISABLED;+ } else if (v4l2) {+ if (opts->hwdec_mode != SC_HWDEC_MODE_AUTO) {+ LOGE("Hardware decoding is not compatible with V4L2");+ return false;+ }+ LOGI("V4L2 sink enabled, hardware decoding disabled");+ opts->hwdec_mode = SC_HWDEC_MODE_DISABLED;+ }+ }+#ifdef HAVE_V4L2if (v4l2) {if (!opts->video) {diff --git a/app/src/options.c b/app/src/options.cindex c7e9a3fd..97b23dec 100644--- a/app/src/options.c+++ b/app/src/options.c@@ -23,6 +23,7 @@ const struct scrcpy_options scrcpy_options_default = {.audio_codec = SC_CODEC_OPUS,.video_source = SC_VIDEO_SOURCE_DISPLAY,.audio_source = SC_AUDIO_SOURCE_AUTO,+ .hwdec_mode = SC_HWDEC_MODE_AUTO,.record_format = SC_RECORD_FORMAT_AUTO,.keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_AUTO,.mouse_input_mode = SC_MOUSE_INPUT_MODE_AUTO,diff --git a/app/src/options.h b/app/src/options.hindex 5b84c2ea..ffe88fe5 100644--- a/app/src/options.h+++ b/app/src/options.h@@ -71,6 +71,11 @@ enum sc_audio_source {SC_AUDIO_SOURCE_VOICE_PERFORMANCE,};+enum sc_hwdec_mode {+ SC_HWDEC_MODE_AUTO,+ SC_HWDEC_MODE_DISABLED,+};+enum sc_camera_facing {SC_CAMERA_FACING_ANY,SC_CAMERA_FACING_FRONT,@@ -257,6 +262,7 @@ struct scrcpy_options {enum sc_codec audio_codec;enum sc_video_source video_source;enum sc_audio_source audio_source;+ enum sc_hwdec_mode hwdec_mode;enum sc_record_format record_format;enum sc_keyboard_input_mode keyboard_input_mode;enum sc_mouse_input_mode mouse_input_mode;diff --git a/doc/video.md b/doc/video.mdindex 172bc8f0..837c70ab 100644--- a/doc/video.md+++ b/doc/video.md@@ -112,6 +112,24 @@ scrcpy --video-codec=h264 --video-encoder=OMX.qcom.video.encoder.avc```+## Hardware decoding++The video stream is decoded on the computer. By default, the first available+hardware decoder is used, and software decoding is used otherwise.++Hardware decoding can be configured explicitly:++```bash+scrcpy --hwdec=auto # default+scrcpy --hwdec=disabled # software decoding+```++Hardware decoding is only supported when video playback is enabled and V4L2 is+disabled.++For now, only software decoding is available.++## OrientationThe orientation may be applied at 3 different levels: