From df74cceb6fe115bd39e862612a14a1e1483b1529 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 10 Nov 2024 18:46:51 +0100 Subject: [PATCH] Use camera prepare() step For consistency with screen capture. Refs b60e1747809cce58793a8c0d54b499df87a6a975 --- .../scrcpy/video/CameraCapture.java | 23 ++++++++++--------- .../scrcpy/video/SurfaceCapture.java | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/video/CameraCapture.java b/server/src/main/java/com/genymobile/scrcpy/video/CameraCapture.java index 7385283e34..0ec404eb2b 100644 --- a/server/src/main/java/com/genymobile/scrcpy/video/CameraCapture.java +++ b/server/src/main/java/com/genymobile/scrcpy/video/CameraCapture.java @@ -80,14 +80,21 @@ protected void init() throws IOException { throw new IOException("No matching camera found"); } + Ln.i("Using camera '" + cameraId + "'"); + cameraDevice = openCamera(cameraId); + } catch (CameraAccessException | InterruptedException e) { + throw new IOException(e); + } + } + + @Override + public void prepare() throws IOException { + try { size = selectSize(cameraId, explicitSize, maxSize, aspectRatio, highSpeed); if (size == null) { throw new IOException("Could not select camera size"); } - - Ln.i("Using camera '" + cameraId + "'"); - cameraDevice = openCamera(cameraId); - } catch (CameraAccessException | InterruptedException e) { + } catch (CameraAccessException e) { throw new IOException(e); } } @@ -232,13 +239,7 @@ public boolean setMaxSize(int maxSize) { } this.maxSize = maxSize; - try { - size = selectSize(cameraId, null, maxSize, aspectRatio, highSpeed); - return size != null; - } catch (CameraAccessException e) { - Ln.w("Could not select camera size", e); - return false; - } + return true; } @SuppressLint("MissingPermission") diff --git a/server/src/main/java/com/genymobile/scrcpy/video/SurfaceCapture.java b/server/src/main/java/com/genymobile/scrcpy/video/SurfaceCapture.java index de9e1b275d..d0d93f54d8 100644 --- a/server/src/main/java/com/genymobile/scrcpy/video/SurfaceCapture.java +++ b/server/src/main/java/com/genymobile/scrcpy/video/SurfaceCapture.java @@ -46,7 +46,7 @@ public final void init(CaptureListener listener) throws ConfigurationException, /** * Called once before each capture starts, before {@link #getSize()}. */ - public void prepare() throws ConfigurationException { + public void prepare() throws ConfigurationException, IOException { // empty by default }