Skip to content

Commit

Permalink
Filter out non-backward-compatible cameras
Browse files Browse the repository at this point in the history
PR #5669 <#5669>

Signed-off-by: Romain Vimont <[email protected]>
  • Loading branch information
yume-chan authored and rom1v committed Dec 22, 2024
1 parent 95c4f03 commit 2f44da7
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion server/src/main/java/com/genymobile/scrcpy/util/LogUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ private static String getCameraFacingName(int facing) {
}
}

private static boolean isCameraBackwardCompatible(CameraCharacteristics characteristics) {
int[] capabilities = characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES);
if (capabilities == null) {
return false;
}

for (int capability : capabilities) {
if (capability == CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE) {
return true;
}
}

return false;
}

public static String buildCameraListMessage(boolean includeSizes) {
StringBuilder builder = new StringBuilder("List of cameras:");
CameraManager cameraManager = ServiceManager.getCameraManager();
Expand All @@ -129,9 +144,16 @@ public static String buildCameraListMessage(boolean includeSizes) {
builder.append("\n (none)");
} else {
for (String id : cameraIds) {
builder.append("\n --camera-id=").append(id);
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(id);

if (!isCameraBackwardCompatible(characteristics)) {
// Ignore depth cameras as suggested by official documentation
// <https://developer.android.com/media/camera/camera2/camera-enumeration>
continue;
}

builder.append("\n --camera-id=").append(id);

int facing = characteristics.get(CameraCharacteristics.LENS_FACING);
builder.append(" (").append(getCameraFacingName(facing)).append(", ");

Expand Down

0 comments on commit 2f44da7

Please sign in to comment.