Pass Options instance directly

Many constructors take a lot of parameters copied from Options. For
simplicity, just pass the Options instance.
This commit is contained in:
Romain Vimont 2024-11-14 20:25:12 +01:00
parent 794595e3f0
commit bd9d93194b
7 changed files with 45 additions and 42 deletions

View File

@ -128,7 +128,7 @@ public final class Server {
if (control) { if (control) {
ControlChannel controlChannel = connection.getControlChannel(); ControlChannel controlChannel = connection.getControlChannel();
controller = new Controller(options.getDisplayId(), controlChannel, cleanUp, options.getClipboardAutosync(), options.getPowerOn()); controller = new Controller(controlChannel, cleanUp, options);
asyncProcessors.add(controller); asyncProcessors.add(controller);
} }
@ -147,8 +147,7 @@ public final class Server {
if (audioCodec == AudioCodec.RAW) { if (audioCodec == AudioCodec.RAW) {
audioRecorder = new AudioRawRecorder(audioCapture, audioStreamer); audioRecorder = new AudioRawRecorder(audioCapture, audioStreamer);
} else { } else {
audioRecorder = new AudioEncoder(audioCapture, audioStreamer, options.getAudioBitRate(), options.getAudioCodecOptions(), audioRecorder = new AudioEncoder(audioCapture, audioStreamer, options);
options.getAudioEncoder());
} }
asyncProcessors.add(audioRecorder); asyncProcessors.add(audioRecorder);
} }
@ -160,18 +159,15 @@ public final class Server {
if (options.getVideoSource() == VideoSource.DISPLAY) { if (options.getVideoSource() == VideoSource.DISPLAY) {
NewDisplay newDisplay = options.getNewDisplay(); NewDisplay newDisplay = options.getNewDisplay();
if (newDisplay != null) { if (newDisplay != null) {
surfaceCapture = new NewDisplayCapture(controller, newDisplay, options.getMaxSize()); surfaceCapture = new NewDisplayCapture(controller, options);
} else { } else {
assert options.getDisplayId() != Device.DISPLAY_ID_NONE; assert options.getDisplayId() != Device.DISPLAY_ID_NONE;
surfaceCapture = new ScreenCapture(controller, options.getDisplayId(), options.getMaxSize(), options.getCrop(), surfaceCapture = new ScreenCapture(controller, options);
options.getLockVideoOrientation());
} }
} else { } else {
surfaceCapture = new CameraCapture(options.getCameraId(), options.getCameraFacing(), options.getCameraSize(), surfaceCapture = new CameraCapture(options);
options.getMaxSize(), options.getCameraAspectRatio(), options.getCameraFps(), options.getCameraHighSpeed());
} }
SurfaceEncoder surfaceEncoder = new SurfaceEncoder(surfaceCapture, videoStreamer, options.getVideoBitRate(), options.getMaxFps(), SurfaceEncoder surfaceEncoder = new SurfaceEncoder(surfaceCapture, videoStreamer, options);
options.getVideoCodecOptions(), options.getVideoEncoder(), options.getDownsizeOnError());
asyncProcessors.add(surfaceEncoder); asyncProcessors.add(surfaceEncoder);
if (controller != null) { if (controller != null) {

View File

@ -2,6 +2,7 @@ package com.genymobile.scrcpy.audio;
import com.genymobile.scrcpy.AndroidVersions; import com.genymobile.scrcpy.AndroidVersions;
import com.genymobile.scrcpy.AsyncProcessor; import com.genymobile.scrcpy.AsyncProcessor;
import com.genymobile.scrcpy.Options;
import com.genymobile.scrcpy.device.ConfigurationException; import com.genymobile.scrcpy.device.ConfigurationException;
import com.genymobile.scrcpy.device.Streamer; import com.genymobile.scrcpy.device.Streamer;
import com.genymobile.scrcpy.util.Codec; import com.genymobile.scrcpy.util.Codec;
@ -67,12 +68,12 @@ public final class AudioEncoder implements AsyncProcessor {
private boolean ended; private boolean ended;
public AudioEncoder(AudioCapture capture, Streamer streamer, int bitRate, List<CodecOption> codecOptions, String encoderName) { public AudioEncoder(AudioCapture capture, Streamer streamer, Options options) {
this.capture = capture; this.capture = capture;
this.streamer = streamer; this.streamer = streamer;
this.bitRate = bitRate; this.bitRate = options.getAudioBitRate();
this.codecOptions = codecOptions; this.codecOptions = options.getAudioCodecOptions();
this.encoderName = encoderName; this.encoderName = options.getAudioEncoder();
} }
private static MediaFormat createFormat(String mimeType, int bitRate, List<CodecOption> codecOptions) { private static MediaFormat createFormat(String mimeType, int bitRate, List<CodecOption> codecOptions) {

View File

@ -3,6 +3,7 @@ package com.genymobile.scrcpy.control;
import com.genymobile.scrcpy.AndroidVersions; import com.genymobile.scrcpy.AndroidVersions;
import com.genymobile.scrcpy.AsyncProcessor; import com.genymobile.scrcpy.AsyncProcessor;
import com.genymobile.scrcpy.CleanUp; import com.genymobile.scrcpy.CleanUp;
import com.genymobile.scrcpy.Options;
import com.genymobile.scrcpy.device.Device; import com.genymobile.scrcpy.device.Device;
import com.genymobile.scrcpy.device.DeviceApp; import com.genymobile.scrcpy.device.DeviceApp;
import com.genymobile.scrcpy.device.Point; import com.genymobile.scrcpy.device.Point;
@ -97,12 +98,12 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
// Used for resetting video encoding on RESET_VIDEO message // Used for resetting video encoding on RESET_VIDEO message
private SurfaceCapture surfaceCapture; private SurfaceCapture surfaceCapture;
public Controller(int displayId, ControlChannel controlChannel, CleanUp cleanUp, boolean clipboardAutosync, boolean powerOn) { public Controller(ControlChannel controlChannel, CleanUp cleanUp, Options options) {
this.displayId = displayId; this.displayId = options.getDisplayId();
this.controlChannel = controlChannel; this.controlChannel = controlChannel;
this.cleanUp = cleanUp; this.cleanUp = cleanUp;
this.clipboardAutosync = clipboardAutosync; this.clipboardAutosync = options.getClipboardAutosync();
this.powerOn = powerOn; this.powerOn = options.getPowerOn();
initPointers(); initPointers();
sender = new DeviceMessageSender(controlChannel); sender = new DeviceMessageSender(controlChannel);

View File

@ -1,6 +1,7 @@
package com.genymobile.scrcpy.video; package com.genymobile.scrcpy.video;
import com.genymobile.scrcpy.AndroidVersions; import com.genymobile.scrcpy.AndroidVersions;
import com.genymobile.scrcpy.Options;
import com.genymobile.scrcpy.device.ConfigurationException; import com.genymobile.scrcpy.device.ConfigurationException;
import com.genymobile.scrcpy.device.Size; import com.genymobile.scrcpy.device.Size;
import com.genymobile.scrcpy.util.HandlerExecutor; import com.genymobile.scrcpy.util.HandlerExecutor;
@ -58,15 +59,14 @@ public class CameraCapture extends SurfaceCapture {
private final AtomicBoolean disconnected = new AtomicBoolean(); private final AtomicBoolean disconnected = new AtomicBoolean();
public CameraCapture(String explicitCameraId, CameraFacing cameraFacing, Size explicitSize, int maxSize, CameraAspectRatio aspectRatio, int fps, public CameraCapture(Options options) {
boolean highSpeed) { this.explicitCameraId = options.getCameraId();
this.explicitCameraId = explicitCameraId; this.cameraFacing = options.getCameraFacing();
this.cameraFacing = cameraFacing; this.explicitSize = options.getCameraSize();
this.explicitSize = explicitSize; this.maxSize = options.getMaxSize();
this.maxSize = maxSize; this.aspectRatio = options.getCameraAspectRatio();
this.aspectRatio = aspectRatio; this.fps = options.getCameraFps();
this.fps = fps; this.highSpeed = options.getCameraHighSpeed();
this.highSpeed = highSpeed;
} }
@Override @Override

View File

@ -1,6 +1,7 @@
package com.genymobile.scrcpy.video; package com.genymobile.scrcpy.video;
import com.genymobile.scrcpy.AndroidVersions; import com.genymobile.scrcpy.AndroidVersions;
import com.genymobile.scrcpy.Options;
import com.genymobile.scrcpy.control.PositionMapper; import com.genymobile.scrcpy.control.PositionMapper;
import com.genymobile.scrcpy.device.DisplayInfo; import com.genymobile.scrcpy.device.DisplayInfo;
import com.genymobile.scrcpy.device.NewDisplay; import com.genymobile.scrcpy.device.NewDisplay;
@ -43,10 +44,11 @@ public class NewDisplayCapture extends SurfaceCapture {
private Size size; private Size size;
private int dpi; private int dpi;
public NewDisplayCapture(VirtualDisplayListener vdListener, NewDisplay newDisplay, int maxSize) { public NewDisplayCapture(VirtualDisplayListener vdListener, Options options) {
this.vdListener = vdListener; this.vdListener = vdListener;
this.newDisplay = newDisplay; this.newDisplay = options.getNewDisplay();
this.maxSize = maxSize; assert newDisplay != null;
this.maxSize = options.getMaxSize();
} }
@Override @Override

View File

@ -1,8 +1,10 @@
package com.genymobile.scrcpy.video; package com.genymobile.scrcpy.video;
import com.genymobile.scrcpy.AndroidVersions; import com.genymobile.scrcpy.AndroidVersions;
import com.genymobile.scrcpy.Options;
import com.genymobile.scrcpy.control.PositionMapper; import com.genymobile.scrcpy.control.PositionMapper;
import com.genymobile.scrcpy.device.ConfigurationException; import com.genymobile.scrcpy.device.ConfigurationException;
import com.genymobile.scrcpy.device.Device;
import com.genymobile.scrcpy.device.DisplayInfo; import com.genymobile.scrcpy.device.DisplayInfo;
import com.genymobile.scrcpy.device.Size; import com.genymobile.scrcpy.device.Size;
import com.genymobile.scrcpy.util.Ln; import com.genymobile.scrcpy.util.Ln;
@ -48,12 +50,13 @@ public class ScreenCapture extends SurfaceCapture {
private IRotationWatcher rotationWatcher; private IRotationWatcher rotationWatcher;
private IDisplayFoldListener displayFoldListener; private IDisplayFoldListener displayFoldListener;
public ScreenCapture(VirtualDisplayListener vdListener, int displayId, int maxSize, Rect crop, int lockVideoOrientation) { public ScreenCapture(VirtualDisplayListener vdListener, Options options) {
this.vdListener = vdListener; this.vdListener = vdListener;
this.displayId = displayId; this.displayId = options.getDisplayId();
this.maxSize = maxSize; assert displayId != Device.DISPLAY_ID_NONE;
this.crop = crop; this.maxSize = options.getMaxSize();
this.lockVideoOrientation = lockVideoOrientation; this.crop = options.getCrop();
this.lockVideoOrientation = options.getLockVideoOrientation();
} }
@Override @Override

View File

@ -2,6 +2,7 @@ package com.genymobile.scrcpy.video;
import com.genymobile.scrcpy.AndroidVersions; import com.genymobile.scrcpy.AndroidVersions;
import com.genymobile.scrcpy.AsyncProcessor; import com.genymobile.scrcpy.AsyncProcessor;
import com.genymobile.scrcpy.Options;
import com.genymobile.scrcpy.device.ConfigurationException; import com.genymobile.scrcpy.device.ConfigurationException;
import com.genymobile.scrcpy.device.Size; import com.genymobile.scrcpy.device.Size;
import com.genymobile.scrcpy.device.Streamer; import com.genymobile.scrcpy.device.Streamer;
@ -51,15 +52,14 @@ public class SurfaceEncoder implements AsyncProcessor {
private final CaptureReset reset = new CaptureReset(); private final CaptureReset reset = new CaptureReset();
public SurfaceEncoder(SurfaceCapture capture, Streamer streamer, int videoBitRate, float maxFps, List<CodecOption> codecOptions, public SurfaceEncoder(SurfaceCapture capture, Streamer streamer, Options options) {
String encoderName, boolean downsizeOnError) {
this.capture = capture; this.capture = capture;
this.streamer = streamer; this.streamer = streamer;
this.videoBitRate = videoBitRate; this.videoBitRate = options.getVideoBitRate();
this.maxFps = maxFps; this.maxFps = options.getMaxFps();
this.codecOptions = codecOptions; this.codecOptions = options.getVideoCodecOptions();
this.encoderName = encoderName; this.encoderName = options.getVideoEncoder();
this.downsizeOnError = downsizeOnError; this.downsizeOnError = options.getDownsizeOnError();
} }
private void streamCapture() throws IOException, ConfigurationException { private void streamCapture() throws IOException, ConfigurationException {