diff --git a/app/data/bash-completion/scrcpy b/app/data/bash-completion/scrcpy index b6f550c558..1cf750ac06 100644 --- a/app/data/bash-completion/scrcpy +++ b/app/data/bash-completion/scrcpy @@ -23,6 +23,7 @@ _scrcpy() { --kill-adb-on-close -K --hid-keyboard --legacy-paste + --list-camera-sizes --list-cameras --list-displays --list-encoders diff --git a/app/data/zsh-completion/_scrcpy b/app/data/zsh-completion/_scrcpy index 3ba2c4b8eb..926bc0a11a 100644 --- a/app/data/zsh-completion/_scrcpy +++ b/app/data/zsh-completion/_scrcpy @@ -30,6 +30,7 @@ arguments=( '--kill-adb-on-close[Kill adb when scrcpy terminates]' {-K,--hid-keyboard}'[Simulate a physical keyboard by using HID over AOAv2]' '--legacy-paste[Inject computer clipboard text as a sequence of key events on Ctrl+v]' + '--list-camera-sizes[List the valid camera capture sizes]' '--list-cameras[List cameras available on the device]' '--list-displays[List displays available on the device]' '--list-encoders[List video and audio encoders available on the device]' diff --git a/app/scrcpy.1 b/app/scrcpy.1 index 30d15b4d60..428254dd18 100644 --- a/app/scrcpy.1 +++ b/app/scrcpy.1 @@ -155,6 +155,10 @@ Inject computer clipboard text as a sequence of key events on Ctrl+v (like MOD+S This is a workaround for some devices not behaving as expected when setting the device clipboard programmatically. +.TP +.B \-\-list\-camera\-sizes +List the valid camera capture sizes. + .TP .B \-\-list\-cameras List cameras available on the device. diff --git a/app/src/cli.c b/app/src/cli.c index c9382c5b68..788a629b56 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -82,6 +82,7 @@ enum { OPT_TIME_LIMIT, OPT_PAUSE_ON_EXIT, OPT_LIST_CAMERAS, + OPT_LIST_CAMERA_SIZES, }; struct sc_option { @@ -326,6 +327,11 @@ static const struct sc_option options[] = { .longopt = "list-cameras", .text = "List device cameras.", }, + { + .longopt_id = OPT_LIST_CAMERA_SIZES, + .longopt = "list-camera-sizes", + .text = "List the valid camera capture sizes.", + }, { .longopt_id = OPT_LIST_DISPLAYS, .longopt = "list-displays", @@ -2007,6 +2013,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[], case OPT_LIST_CAMERAS: opts->list |= SC_OPTION_LIST_CAMERAS; break; + case OPT_LIST_CAMERA_SIZES: + opts->list |= SC_OPTION_LIST_CAMERA_SIZES; + break; case OPT_REQUIRE_AUDIO: opts->require_audio = true; break; diff --git a/app/src/options.h b/app/src/options.h index e960968a7c..070a2b0090 100644 --- a/app/src/options.h +++ b/app/src/options.h @@ -183,6 +183,7 @@ struct scrcpy_options { #define SC_OPTION_LIST_ENCODERS 0x1 #define SC_OPTION_LIST_DISPLAYS 0x2 #define SC_OPTION_LIST_CAMERAS 0x4 +#define SC_OPTION_LIST_CAMERA_SIZES 0x8 uint8_t list; }; diff --git a/app/src/server.c b/app/src/server.c index 571b813cac..424c67e916 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -320,6 +320,9 @@ execute_server(struct sc_server *server, if (params->list & SC_OPTION_LIST_CAMERAS) { ADD_PARAM("list_cameras=true"); } + if (params->list & SC_OPTION_LIST_CAMERA_SIZES) { + ADD_PARAM("list_camera_sizes=true"); + } #undef ADD_PARAM diff --git a/server/src/main/java/com/genymobile/scrcpy/LogUtils.java b/server/src/main/java/com/genymobile/scrcpy/LogUtils.java index d609adcd37..7806cf515a 100644 --- a/server/src/main/java/com/genymobile/scrcpy/LogUtils.java +++ b/server/src/main/java/com/genymobile/scrcpy/LogUtils.java @@ -7,6 +7,8 @@ import android.hardware.camera2.CameraAccessException; import android.hardware.camera2.CameraCharacteristics; import android.hardware.camera2.CameraManager; +import android.hardware.camera2.params.StreamConfigurationMap; +import android.media.MediaCodec; import java.util.List; @@ -79,7 +81,7 @@ private static String getCameraFacingName(int facing) { } } - public static String buildCameraListMessage() { + public static String buildCameraListMessage(boolean includeSizes) { StringBuilder builder = new StringBuilder("List of cameras:"); CameraManager cameraManager = ServiceManager.getCameraManager(); try { @@ -96,6 +98,14 @@ public static String buildCameraListMessage() { Rect activeSize = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE); builder.append(activeSize.width()).append("x").append(activeSize.height()).append(')'); + + if (includeSizes) { + StreamConfigurationMap configs = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); + android.util.Size[] sizes = configs.getOutputSizes(MediaCodec.class); + for (android.util.Size size : sizes) { + builder.append("\n - ").append(size.getWidth()).append('x').append(size.getHeight()); + } + } } } } catch (CameraAccessException e) { diff --git a/server/src/main/java/com/genymobile/scrcpy/Options.java b/server/src/main/java/com/genymobile/scrcpy/Options.java index 0a3032cf17..c96004046d 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Options.java +++ b/server/src/main/java/com/genymobile/scrcpy/Options.java @@ -39,6 +39,7 @@ public class Options { private boolean listEncoders; private boolean listDisplays; private boolean listCameras; + private boolean listCameraSizes; // Options not used by the scrcpy client, but useful to use scrcpy-server directly private boolean sendDeviceMeta = true; // send device name and size @@ -155,7 +156,7 @@ public boolean getPowerOn() { } public boolean getList() { - return listEncoders || listDisplays || listCameras; + return listEncoders || listDisplays || listCameras || listCameraSizes; } public boolean getListEncoders() { @@ -170,6 +171,10 @@ public boolean getListCameras() { return listCameras; } + public boolean getListCameraSizes() { + return listCameraSizes; + } + public boolean getSendDeviceMeta() { return sendDeviceMeta; } @@ -320,6 +325,9 @@ public static Options parse(String... args) { case "list_cameras": options.listCameras = Boolean.parseBoolean(value); break; + case "list_camera_sizes": + options.listCameraSizes = Boolean.parseBoolean(value); + break; case "send_device_meta": options.sendDeviceMeta = Boolean.parseBoolean(value); break; diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index 2129dbc01f..4dbc00fe42 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -208,9 +208,9 @@ private static void internalMain(String... args) throws Exception { if (options.getListDisplays()) { Ln.i(LogUtils.buildDisplayListMessage()); } - if (options.getListCameras()) { + if (options.getListCameras() || options.getListCameraSizes()) { Workarounds.apply(false, true); - Ln.i(LogUtils.buildCameraListMessage()); + Ln.i(LogUtils.buildCameraListMessage(options.getListCameraSizes())); } // Just print the requested data, do not mirror return;