Skip to content

Commit

Permalink
Add --list-camera-sizes
Browse files Browse the repository at this point in the history
Add an option to list the device camera declared sizes.

PR #4213 <#4213>
  • Loading branch information
rom1v committed Oct 31, 2023
1 parent eff1108 commit f63a3ca
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/data/bash-completion/scrcpy
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ _scrcpy() {
--kill-adb-on-close
-K --hid-keyboard
--legacy-paste
--list-camera-sizes
--list-cameras
--list-displays
--list-encoders
Expand Down
1 change: 1 addition & 0 deletions app/data/zsh-completion/_scrcpy
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand Down
3 changes: 3 additions & 0 deletions app/scrcpy.1
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ 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.

.B \-\-list\-camera\-sizes
List the valid camera capture sizes.

.B \-\-list\-cameras
List cameras available on the device.

Expand Down
9 changes: 9 additions & 0 deletions app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ enum {
OPT_TIME_LIMIT,
OPT_PAUSE_ON_EXIT,
OPT_LIST_CAMERAS,
OPT_LIST_CAMERA_SIZES,
};

struct sc_option {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions app/src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
3 changes: 3 additions & 0 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion server/src/main/java/com/genymobile/scrcpy/LogUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion server/src/main/java/com/genymobile/scrcpy/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -155,7 +156,7 @@ public boolean getPowerOn() {
}

public boolean getList() {
return listEncoders || listDisplays || listCameras;
return listEncoders || listDisplays || listCameras || listCameraSizes;
}

public boolean getListEncoders() {
Expand All @@ -170,6 +171,10 @@ public boolean getListCameras() {
return listCameras;
}

public boolean getListCameraSizes() {
return listCameraSizes;
}

public boolean getSendDeviceMeta() {
return sendDeviceMeta;
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/com/genymobile/scrcpy/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f63a3ca

Please sign in to comment.