Make camera id optional
If no camera id is provided, use the first camera available. PR #4213 <https://github.com/Genymobile/scrcpy/pull/4213>
This commit is contained in:
parent
64930e71b9
commit
7f8d079c8c
@ -2199,12 +2199,6 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opts->camera_id) {
|
|
||||||
LOGE("Camera id must be specified by --camera-id "
|
|
||||||
"(list the available ids with --list-cameras)");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!opts->camera_size) {
|
if (!opts->camera_size) {
|
||||||
LOGE("Camera size must be specified by --camera-size");
|
LOGE("Camera size must be specified by --camera-size");
|
||||||
return false;
|
return false;
|
||||||
|
@ -7,6 +7,7 @@ import android.annotation.TargetApi;
|
|||||||
import android.hardware.camera2.CameraAccessException;
|
import android.hardware.camera2.CameraAccessException;
|
||||||
import android.hardware.camera2.CameraCaptureSession;
|
import android.hardware.camera2.CameraCaptureSession;
|
||||||
import android.hardware.camera2.CameraDevice;
|
import android.hardware.camera2.CameraDevice;
|
||||||
|
import android.hardware.camera2.CameraManager;
|
||||||
import android.hardware.camera2.CaptureFailure;
|
import android.hardware.camera2.CaptureFailure;
|
||||||
import android.hardware.camera2.CaptureRequest;
|
import android.hardware.camera2.CaptureRequest;
|
||||||
import android.hardware.camera2.params.OutputConfiguration;
|
import android.hardware.camera2.params.OutputConfiguration;
|
||||||
@ -49,12 +50,30 @@ public class CameraCapture extends SurfaceCapture {
|
|||||||
cameraExecutor = new HandlerExecutor(cameraHandler);
|
cameraExecutor = new HandlerExecutor(cameraHandler);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cameraDevice = openCamera(explicitCameraId);
|
String cameraId = selectCamera(explicitCameraId);
|
||||||
|
if (cameraId == null) {
|
||||||
|
throw new IOException("No matching camera found");
|
||||||
|
}
|
||||||
|
|
||||||
|
Ln.i("Using camera '" + cameraId + "'");
|
||||||
|
cameraDevice = openCamera(cameraId);
|
||||||
} catch (CameraAccessException | InterruptedException e) {
|
} catch (CameraAccessException | InterruptedException e) {
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String selectCamera(String explicitCameraId) throws CameraAccessException {
|
||||||
|
if (explicitCameraId != null) {
|
||||||
|
return explicitCameraId;
|
||||||
|
}
|
||||||
|
|
||||||
|
CameraManager cameraManager = ServiceManager.getCameraManager();
|
||||||
|
|
||||||
|
String[] cameraIds = cameraManager.getCameraIdList();
|
||||||
|
// Use the first one
|
||||||
|
return cameraIds.length > 0 ? cameraIds[0] : null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Surface surface) throws IOException {
|
public void start(Surface surface) throws IOException {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user