Display and control your Android device
Forward video constraints to subclasses directly
Romain Vimont4b60bf0bda2f
diff --git a/server/src/main/java/com/genymobile/scrcpy/video/CameraCapture.java b/server/src/main/java/com/genymobile/scrcpy/video/CameraCapture.javaindex 4124854c..37edf0e1 100644--- a/server/src/main/java/com/genymobile/scrcpy/video/CameraCapture.java+++ b/server/src/main/java/com/genymobile/scrcpy/video/CameraCapture.java@@ -68,6 +68,8 @@ public class CameraCapture extends SurfaceCapture {private final boolean initialTorch;private float zoom;+ private VideoConstraints videoConstraints;+private String cameraId;private Size captureSize;private Size videoSize; // after OpenGL transforms@@ -104,7 +106,9 @@ public class CameraCapture extends SurfaceCapture {}@Override- protected void init() throws ConfigurationException, IOException {+ protected void init(VideoConstraints videoConstraints) throws ConfigurationException, IOException {+ this.videoConstraints = videoConstraints;+cameraThread = new HandlerThread("camera");cameraThread.start();cameraHandler = new Handler(cameraThread.getLooper());@@ -126,7 +130,7 @@ public class CameraCapture extends SurfaceCapture {@Overridepublic void prepare() throws IOException {try {- int maxSize = getVideoConstraints().getMaxSize();+ int maxSize = videoConstraints.getMaxSize();captureSize = selectSize(cameraId, explicitSize, maxSize, aspectRatio, highSpeed);if (captureSize == null) {throw new IOException("Could not select camera size");@@ -148,7 +152,7 @@ public class CameraCapture extends SurfaceCapture {filter.addAngle(angle);transform = filter.getInverseTransform();- videoSize = filter.getOutputSize().constrain(getVideoConstraints());+ videoSize = filter.getOutputSize().constrain(videoConstraints);}private static String selectCamera(String explicitCameraId, CameraFacing cameraFacing) throws CameraAccessException, ConfigurationException {diff --git a/server/src/main/java/com/genymobile/scrcpy/video/NewDisplayCapture.java b/server/src/main/java/com/genymobile/scrcpy/video/NewDisplayCapture.javaindex e0ec2141..33f14784 100644--- a/server/src/main/java/com/genymobile/scrcpy/video/NewDisplayCapture.java+++ b/server/src/main/java/com/genymobile/scrcpy/video/NewDisplayCapture.java@@ -59,6 +59,8 @@ public class NewDisplayCapture extends SurfaceCapture {private final boolean vdDestroyContent;private final boolean vdSystemDecorations;+ private VideoConstraints videoConstraints;+private VirtualDisplay virtualDisplay;private Size videoSize;private Size displaySize; // the logical size of the display (including rotation)@@ -82,7 +84,9 @@ public class NewDisplayCapture extends SurfaceCapture {}@Override- protected void init() {+ protected void init(VideoConstraints videoConstraints) {+ this.videoConstraints = videoConstraints;+displaySize = newDisplay.getSize();dpi = newDisplay.getDpi();if (displaySize == null || dpi == 0) {@@ -110,7 +114,7 @@ public class NewDisplayCapture extends SurfaceCapture {}// Align the physical display size to avoid unnecessary mismatches with the output size- displaySize = displaySize.align(getVideoConstraints().getAlignment());+ displaySize = displaySize.align(videoConstraints.getAlignment());if (!newDisplay.hasExplicitDpi()) {dpi = scaleDpi(mainDisplaySize, mainDisplayDpi, displaySize);@@ -125,7 +129,7 @@ public class NewDisplayCapture extends SurfaceCapture {displayRotation = displayInfo.getRotation();// Align the physical display size to avoid unnecessary mismatches with the output size- displaySize = displayInfo.getSize().align(getVideoConstraints().getAlignment());+ displaySize = displayInfo.getSize().align(videoConstraints.getAlignment());}VideoFilter filter = new VideoFilter(displaySize);@@ -139,7 +143,7 @@ public class NewDisplayCapture extends SurfaceCapture {filter.addAngle(angle);Size outputSize = filter.getOutputSize();- Size filteredSize = outputSize.constrain(getVideoConstraints());+ Size filteredSize = outputSize.constrain(videoConstraints);if (!filteredSize.equals(outputSize)) {filter.addResize(filteredSize);}diff --git a/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java b/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.javaindex adabdfb0..ca6da768 100644--- a/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java+++ b/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java@@ -36,6 +36,8 @@ public class ScreenCapture extends SurfaceCapture {private Orientation captureOrientation;private final float angle;+ private VideoConstraints videoConstraints;+private DisplayInfo displayInfo;private Size videoSize;@@ -60,7 +62,8 @@ public class ScreenCapture extends SurfaceCapture {}@Override- public void init() {+ public void init(VideoConstraints videoConstraints) {+ this.videoConstraints = videoConstraints;displayMonitor.start(displayId, this::invalidate);}@@ -98,7 +101,7 @@ public class ScreenCapture extends SurfaceCapture {filter.addAngle(angle);transform = filter.getInverseTransform();- videoSize = filter.getOutputSize().constrain(getVideoConstraints());+ videoSize = filter.getOutputSize().constrain(videoConstraints);}@Overridediff --git a/server/src/main/java/com/genymobile/scrcpy/video/SurfaceCapture.java b/server/src/main/java/com/genymobile/scrcpy/video/SurfaceCapture.javaindex 908aff1e..7c39f649 100644--- a/server/src/main/java/com/genymobile/scrcpy/video/SurfaceCapture.java+++ b/server/src/main/java/com/genymobile/scrcpy/video/SurfaceCapture.java@@ -17,7 +17,6 @@ public abstract class SurfaceCapture {}private CaptureListener listener;- private VideoConstraints constraints;/*** Notify the listener that the capture has been invalidated (for example, because its size changed, or due to a manual user request).@@ -29,19 +28,20 @@ public abstract class SurfaceCapture {/*** Called once before the first capture starts.*/- public final void init(CaptureListener listener, VideoConstraints constraints) throws ConfigurationException, IOException {+ public final void init(CaptureListener listener, VideoConstraints videoConstraints) throws ConfigurationException, IOException {this.listener = listener;- this.constraints = constraints;- init();+ init(videoConstraints);}/*** Called once before the first capture starts.+ *+ * @param videoConstraints the video constraints*/- protected abstract void init() throws ConfigurationException, IOException;+ protected abstract void init(VideoConstraints videoConstraints) throws ConfigurationException, IOException;/**- * Called after the last capture ends (if and only if {@link #init()} has been called).+ * Called after the last capture ends (if and only if {@link #init(VideoConstraints)} has been called).*/public abstract void release();@@ -81,13 +81,4 @@ public abstract class SurfaceCapture {public boolean isClosed() {return false;}-- /**- * Return the video constraints.- *- * @return the video constraints- */- protected VideoConstraints getVideoConstraints() {- return constraints;- }}