mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-12-19 06:24:19 +01:00
Add option to specify the camera zoom
Add --camera-zoom to specify the camera zoom. TODO ref 6243. Signed-off-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
@@ -44,6 +44,7 @@ public class Options {
|
||||
private Size cameraSize;
|
||||
private CameraFacing cameraFacing;
|
||||
private CameraAspectRatio cameraAspectRatio;
|
||||
private float cameraZoom = 1;
|
||||
private int cameraFps;
|
||||
private boolean cameraHighSpeed;
|
||||
private boolean cameraTorch;
|
||||
@@ -169,6 +170,10 @@ public class Options {
|
||||
return cameraAspectRatio;
|
||||
}
|
||||
|
||||
public float getCameraZoom() {
|
||||
return cameraZoom;
|
||||
}
|
||||
|
||||
public int getCameraFps() {
|
||||
return cameraFps;
|
||||
}
|
||||
@@ -473,6 +478,11 @@ public class Options {
|
||||
options.cameraAspectRatio = parseCameraAspectRatio(value);
|
||||
}
|
||||
break;
|
||||
case "camera_zoom":
|
||||
if (!value.isEmpty()) {
|
||||
options.cameraZoom = Float.parseFloat(value);
|
||||
}
|
||||
break;
|
||||
case "camera_fps":
|
||||
options.cameraFps = Integer.parseInt(value);
|
||||
break;
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.media.MediaCodecList;
|
||||
import android.os.Build;
|
||||
import android.util.Range;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -172,6 +173,18 @@ public final class LogUtils {
|
||||
Ln.w("Could not get available frame rates for camera " + id, e);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= AndroidVersions.API_30_ANDROID_11) {
|
||||
try {
|
||||
Range<Float> zoomRange = characteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE);
|
||||
if (zoomRange != null) {
|
||||
String zoom = getFormattedZoomRange(zoomRange);
|
||||
builder.append(", zoom-range=").append(zoom);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Ln.w("Could not get available zoom ranges for camera " + id, e);
|
||||
}
|
||||
}
|
||||
|
||||
builder.append(')');
|
||||
|
||||
if (includeSizes) {
|
||||
@@ -226,6 +239,11 @@ public final class LogUtils {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String getFormattedZoomRange(Range<Float> range) {
|
||||
DecimalFormat format = new DecimalFormat("#.##");
|
||||
return "[" + format.format(range.getLower()) + ", " + format.format(range.getUpper()) + "]";
|
||||
}
|
||||
|
||||
public static String buildAppListMessage() {
|
||||
List<DeviceApp> apps = Device.listApps();
|
||||
return buildAppListMessage("List of apps:", apps);
|
||||
|
||||
@@ -65,10 +65,12 @@ public class CameraCapture extends SurfaceCapture {
|
||||
private final Orientation captureOrientation;
|
||||
private final float angle;
|
||||
private final boolean initialTorch;
|
||||
private float zoom;
|
||||
|
||||
private String cameraId;
|
||||
private Size captureSize;
|
||||
private Size videoSize; // after OpenGL transforms
|
||||
private Range<Float> zoomRange;
|
||||
|
||||
private AffineMatrix transform;
|
||||
private OpenGLRunner glRunner;
|
||||
@@ -98,6 +100,7 @@ public class CameraCapture extends SurfaceCapture {
|
||||
assert captureOrientation != null;
|
||||
this.angle = options.getAngle();
|
||||
this.initialTorch = options.getCameraTorch();
|
||||
this.zoom = options.getCameraZoom();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -288,6 +291,14 @@ public class CameraCapture extends SurfaceCapture {
|
||||
return;
|
||||
}
|
||||
|
||||
CameraManager cameraManager = ServiceManager.getCameraManager();
|
||||
try {
|
||||
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
|
||||
zoomRange = characteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE);
|
||||
} catch (CameraAccessException e) {
|
||||
Ln.w("Could not get camera characteristics");
|
||||
}
|
||||
|
||||
try {
|
||||
requestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
|
||||
requestBuilder.addTarget(captureSurface);
|
||||
@@ -299,6 +310,11 @@ public class CameraCapture extends SurfaceCapture {
|
||||
Ln.i("Turn camera torch on");
|
||||
requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_TORCH);
|
||||
}
|
||||
if (zoom != 1) {
|
||||
zoom = clampZoom(zoom);
|
||||
Ln.i("Set camera zoom: " + zoom);
|
||||
requestBuilder.set(CaptureRequest.CONTROL_ZOOM_RATIO, zoom);
|
||||
}
|
||||
|
||||
CaptureRequest request = requestBuilder.build();
|
||||
setRepeatingRequest(session, request);
|
||||
@@ -456,6 +472,15 @@ public class CameraCapture extends SurfaceCapture {
|
||||
});
|
||||
}
|
||||
|
||||
private float clampZoom(float value) {
|
||||
assertCameraThread();
|
||||
if (zoomRange == null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return zoomRange.clamp(value);
|
||||
}
|
||||
|
||||
private void assertCameraThread() {
|
||||
assert Thread.currentThread() == cameraThread;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user