mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-03-07 12:44:29 +01:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8db995aaee | ||
|
|
04ef1c1e9d | ||
|
|
84f564cc54 | ||
|
|
9d9095d8f7 | ||
|
|
0b47251dee | ||
|
|
d129a97098 | ||
|
|
2bd4cb6d5d | ||
|
|
6eaaf41dfd | ||
|
|
c0aa9c65c7 |
@@ -14,7 +14,6 @@ _scrcpy() {
|
||||
--camera-id=
|
||||
--camera-facing=
|
||||
--camera-fps=
|
||||
--camera-high-speed
|
||||
--camera-size=
|
||||
--crop=
|
||||
-d --select-usb
|
||||
|
||||
@@ -18,7 +18,6 @@ arguments=(
|
||||
'--audio-output-buffer=[Configure the size of the SDL audio output buffer (in milliseconds)]'
|
||||
{-b,--video-bit-rate=}'[Encode the video at the given bit-rate]'
|
||||
'--camera-ar=[Select the camera size by its aspect ratio]'
|
||||
'--camera-high-speed=[Enable high-speed camera capture mode]'
|
||||
'--camera-id=[Specify the camera id to mirror]'
|
||||
'--camera-facing=[Select the device camera by its facing direction]:facing:(front back external)'
|
||||
'--camera-fps=[Specify the camera capture frame rate]'
|
||||
|
||||
@@ -81,12 +81,6 @@ Select the camera size by its aspect ratio (+/- 10%).
|
||||
|
||||
Possible values are "sensor" (use the camera sensor aspect ratio), "<num>:<den>" (e.g. "4:3") and "<value>" (e.g. "1.6").
|
||||
|
||||
.TP
|
||||
.B \-\-camera\-high\-speed
|
||||
Enable high-speed camera capture mode.
|
||||
|
||||
This mode is restricted to specific resolutions and frame rates, listed by --list-camera-sizes.
|
||||
|
||||
.TP
|
||||
.BI "\-\-camera\-id " id
|
||||
Specify the device camera id to mirror.
|
||||
|
||||
@@ -89,7 +89,6 @@ enum {
|
||||
OPT_CAMERA_FACING,
|
||||
OPT_CAMERA_AR,
|
||||
OPT_CAMERA_FPS,
|
||||
OPT_CAMERA_HIGH_SPEED,
|
||||
};
|
||||
|
||||
struct sc_option {
|
||||
@@ -230,13 +229,6 @@ static const struct sc_option options[] = {
|
||||
.text = "Select the device camera by its facing direction.\n"
|
||||
"Possible values are \"front\", \"back\" and \"external\".",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_CAMERA_HIGH_SPEED,
|
||||
.longopt = "camera-high-speed",
|
||||
.text = "Enable high-speed camera capture mode.\n"
|
||||
"This mode is restricted to specific resolutions and frame "
|
||||
"rates, listed by --list-camera-sizes.",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_CAMERA_SIZE,
|
||||
.longopt = "camera-size",
|
||||
@@ -2188,9 +2180,6 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_CAMERA_HIGH_SPEED:
|
||||
opts->camera_high_speed = true;
|
||||
break;
|
||||
default:
|
||||
// getopt prints the error message on stderr
|
||||
return false;
|
||||
@@ -2290,6 +2279,12 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
return false;
|
||||
}
|
||||
|
||||
if (opts->lock_video_orientation !=
|
||||
SC_LOCK_VIDEO_ORIENTATION_UNLOCKED) {
|
||||
LOGE("--lock-video-orientation is not supported for camera");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (opts->camera_id && opts->camera_facing != SC_CAMERA_FACING_ANY) {
|
||||
LOGE("Could not specify both --camera-id and --camera-facing");
|
||||
return false;
|
||||
@@ -2307,11 +2302,6 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
}
|
||||
}
|
||||
|
||||
if (opts->camera_high_speed && !opts->camera_fps) {
|
||||
LOGE("--camera-high-speed requires an explicit --camera-fps value");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (opts->control) {
|
||||
LOGI("Camera video source: control disabled");
|
||||
opts->control = false;
|
||||
@@ -2319,8 +2309,6 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
} else if (opts->camera_id
|
||||
|| opts->camera_ar
|
||||
|| opts->camera_facing != SC_CAMERA_FACING_ANY
|
||||
|| opts->camera_fps
|
||||
|| opts->camera_high_speed
|
||||
|| opts->camera_size) {
|
||||
LOGE("Camera options are only available with --video-source=camera");
|
||||
return false;
|
||||
|
||||
@@ -86,6 +86,5 @@ const struct scrcpy_options scrcpy_options_default = {
|
||||
.audio = true,
|
||||
.require_audio = false,
|
||||
.kill_adb_on_close = false,
|
||||
.camera_high_speed = false,
|
||||
.list = 0,
|
||||
};
|
||||
|
||||
@@ -199,7 +199,6 @@ struct scrcpy_options {
|
||||
bool audio;
|
||||
bool require_audio;
|
||||
bool kill_adb_on_close;
|
||||
bool camera_high_speed;
|
||||
#define SC_OPTION_LIST_ENCODERS 0x1
|
||||
#define SC_OPTION_LIST_DISPLAYS 0x2
|
||||
#define SC_OPTION_LIST_CAMERAS 0x4
|
||||
|
||||
@@ -386,7 +386,6 @@ scrcpy(struct scrcpy_options *options) {
|
||||
.cleanup = options->cleanup,
|
||||
.power_on = options->power_on,
|
||||
.kill_adb_on_close = options->kill_adb_on_close,
|
||||
.camera_high_speed = options->camera_high_speed,
|
||||
.list = options->list,
|
||||
};
|
||||
|
||||
|
||||
@@ -311,9 +311,6 @@ execute_server(struct sc_server *server,
|
||||
if (params->camera_fps) {
|
||||
ADD_PARAM("camera_fps=%" PRIu16, params->camera_fps);
|
||||
}
|
||||
if (params->camera_high_speed) {
|
||||
ADD_PARAM("camera_high_speed=true");
|
||||
}
|
||||
if (params->show_touches) {
|
||||
ADD_PARAM("show_touches=true");
|
||||
}
|
||||
|
||||
@@ -63,7 +63,6 @@ struct sc_server_params {
|
||||
bool cleanup;
|
||||
bool power_on;
|
||||
bool kill_adb_on_close;
|
||||
bool camera_high_speed;
|
||||
uint8_t list;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.graphics.Rect;
|
||||
import android.hardware.camera2.CameraAccessException;
|
||||
import android.hardware.camera2.CameraCaptureSession;
|
||||
import android.hardware.camera2.CameraCharacteristics;
|
||||
import android.hardware.camera2.CameraConstrainedHighSpeedCaptureSession;
|
||||
import android.hardware.camera2.CameraDevice;
|
||||
import android.hardware.camera2.CameraManager;
|
||||
import android.hardware.camera2.CaptureFailure;
|
||||
@@ -41,7 +40,6 @@ public class CameraCapture extends SurfaceCapture {
|
||||
private int maxSize;
|
||||
private final CameraAspectRatio aspectRatio;
|
||||
private final int fps;
|
||||
private final boolean highSpeed;
|
||||
|
||||
private String cameraId;
|
||||
private Size size;
|
||||
@@ -53,15 +51,13 @@ public class CameraCapture extends SurfaceCapture {
|
||||
|
||||
private final AtomicBoolean disconnected = new AtomicBoolean();
|
||||
|
||||
public CameraCapture(String explicitCameraId, CameraFacing cameraFacing, Size explicitSize, int maxSize, CameraAspectRatio aspectRatio, int fps,
|
||||
boolean highSpeed) {
|
||||
public CameraCapture(String explicitCameraId, CameraFacing cameraFacing, Size explicitSize, int maxSize, CameraAspectRatio aspectRatio, int fps) {
|
||||
this.explicitCameraId = explicitCameraId;
|
||||
this.cameraFacing = cameraFacing;
|
||||
this.explicitSize = explicitSize;
|
||||
this.maxSize = maxSize;
|
||||
this.aspectRatio = aspectRatio;
|
||||
this.fps = fps;
|
||||
this.highSpeed = highSpeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,7 +73,7 @@ public class CameraCapture extends SurfaceCapture {
|
||||
throw new IOException("No matching camera found");
|
||||
}
|
||||
|
||||
size = selectSize(cameraId, explicitSize, maxSize, aspectRatio, highSpeed);
|
||||
size = selectSize(cameraId, explicitSize, maxSize, aspectRatio);
|
||||
if (size == null) {
|
||||
throw new IOException("Could not select camera size");
|
||||
}
|
||||
@@ -116,8 +112,7 @@ public class CameraCapture extends SurfaceCapture {
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.N)
|
||||
private static Size selectSize(String cameraId, Size explicitSize, int maxSize, CameraAspectRatio aspectRatio, boolean highSpeed)
|
||||
throws CameraAccessException {
|
||||
private static Size selectSize(String cameraId, Size explicitSize, int maxSize, CameraAspectRatio aspectRatio) throws CameraAccessException {
|
||||
if (explicitSize != null) {
|
||||
return explicitSize;
|
||||
}
|
||||
@@ -126,7 +121,7 @@ public class CameraCapture extends SurfaceCapture {
|
||||
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
|
||||
|
||||
StreamConfigurationMap configs = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
|
||||
android.util.Size[] sizes = highSpeed ? configs.getHighSpeedVideoSizes() : configs.getOutputSizes(MediaCodec.class);
|
||||
android.util.Size[] sizes = configs.getOutputSizes(MediaCodec.class);
|
||||
Stream<android.util.Size> stream = Arrays.stream(sizes);
|
||||
if (maxSize > 0) {
|
||||
stream = stream.filter(it -> it.getWidth() <= maxSize && it.getHeight() <= maxSize);
|
||||
@@ -160,10 +155,7 @@ public class CameraCapture extends SurfaceCapture {
|
||||
float distance2 = Math.abs(1 - arRatio2);
|
||||
|
||||
// Reverse the order because lower distance is better
|
||||
cmp = Float.compare(distance2, distance1);
|
||||
if (cmp != 0) {
|
||||
return cmp;
|
||||
}
|
||||
return Float.compare(distance2, distance1);
|
||||
}
|
||||
|
||||
// Greater height is better
|
||||
@@ -226,7 +218,7 @@ public class CameraCapture extends SurfaceCapture {
|
||||
|
||||
this.maxSize = maxSize;
|
||||
try {
|
||||
size = selectSize(cameraId, null, maxSize, aspectRatio, highSpeed);
|
||||
size = selectSize(cameraId, null, maxSize, aspectRatio);
|
||||
return true;
|
||||
} catch (CameraAccessException e) {
|
||||
Ln.w("Could not select camera size", e);
|
||||
@@ -287,9 +279,7 @@ public class CameraCapture extends SurfaceCapture {
|
||||
CompletableFuture<CameraCaptureSession> future = new CompletableFuture<>();
|
||||
OutputConfiguration outputConfig = new OutputConfiguration(surface);
|
||||
List<OutputConfiguration> outputs = Arrays.asList(outputConfig);
|
||||
|
||||
int sessionType = highSpeed ? SessionConfiguration.SESSION_HIGH_SPEED : SessionConfiguration.SESSION_REGULAR;
|
||||
SessionConfiguration sessionConfig = new SessionConfiguration(sessionType, outputs, cameraExecutor,
|
||||
SessionConfiguration sessionConfig = new SessionConfiguration(SessionConfiguration.SESSION_REGULAR, outputs, cameraExecutor,
|
||||
new CameraCaptureSession.StateCallback() {
|
||||
@Override
|
||||
public void onConfigured(CameraCaptureSession session) {
|
||||
@@ -324,7 +314,7 @@ public class CameraCapture extends SurfaceCapture {
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.S)
|
||||
private void setRepeatingRequest(CameraCaptureSession session, CaptureRequest request) throws CameraAccessException, InterruptedException {
|
||||
CameraCaptureSession.CaptureCallback callback = new CameraCaptureSession.CaptureCallback() {
|
||||
session.setRepeatingRequest(request, new CameraCaptureSession.CaptureCallback() {
|
||||
@Override
|
||||
public void onCaptureStarted(CameraCaptureSession session, CaptureRequest request, long timestamp, long frameNumber) {
|
||||
// Called for each frame captured, do nothing
|
||||
@@ -334,15 +324,7 @@ public class CameraCapture extends SurfaceCapture {
|
||||
public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request, CaptureFailure failure) {
|
||||
Ln.w("Camera capture failed: frame " + failure.getFrameNumber());
|
||||
}
|
||||
};
|
||||
|
||||
if (highSpeed) {
|
||||
CameraConstrainedHighSpeedCaptureSession highSpeedSession = (CameraConstrainedHighSpeedCaptureSession) session;
|
||||
List<CaptureRequest> requests = highSpeedSession.createHighSpeedRequestList(request);
|
||||
highSpeedSession.setRepeatingBurst(requests, callback, cameraHandler);
|
||||
} else {
|
||||
session.setRepeatingRequest(request, callback, cameraHandler);
|
||||
}
|
||||
}, cameraHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,10 +11,7 @@ import android.hardware.camera2.params.StreamConfigurationMap;
|
||||
import android.media.MediaCodec;
|
||||
import android.util.Range;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public final class LogUtils {
|
||||
@@ -106,27 +103,18 @@ public final class LogUtils {
|
||||
|
||||
// Capture frame rates for low-FPS mode are the same for every resolution
|
||||
Range<Integer>[] lowFpsRanges = characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
|
||||
SortedSet<Integer> uniqueLowFps = getUniqueSet(lowFpsRanges);
|
||||
TreeSet<Integer> uniqueLowFps = new TreeSet<>();
|
||||
for (Range<Integer> range : lowFpsRanges) {
|
||||
uniqueLowFps.add(range.getUpper());
|
||||
}
|
||||
builder.append("fps=").append(uniqueLowFps).append(')');
|
||||
|
||||
if (includeSizes) {
|
||||
StreamConfigurationMap configs = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
|
||||
|
||||
android.util.Size[] sizes = configs.getOutputSizes(MediaCodec.class);
|
||||
for (android.util.Size size : sizes) {
|
||||
builder.append("\n - ").append(size.getWidth()).append('x').append(size.getHeight());
|
||||
}
|
||||
|
||||
android.util.Size[] highSpeedSizes = configs.getHighSpeedVideoSizes();
|
||||
if (highSpeedSizes.length > 0) {
|
||||
builder.append("\n High speed capture (--camera-high-speed):");
|
||||
for (android.util.Size size : highSpeedSizes) {
|
||||
Range<Integer>[] highFpsRanges = configs.getHighSpeedVideoFpsRanges();
|
||||
SortedSet<Integer> uniqueHighFps = getUniqueSet(highFpsRanges);
|
||||
builder.append("\n - ").append(size.getWidth()).append("x").append(size.getHeight());
|
||||
builder.append(" (fps=").append(uniqueHighFps).append(')');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,12 +123,4 @@ public final class LogUtils {
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static SortedSet<Integer> getUniqueSet(Range<Integer>[] ranges) {
|
||||
SortedSet<Integer> set = new TreeSet<>();
|
||||
for (Range<Integer> range : ranges) {
|
||||
set.add(range.getUpper());
|
||||
}
|
||||
return set;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ public class Options {
|
||||
private CameraFacing cameraFacing;
|
||||
private CameraAspectRatio cameraAspectRatio;
|
||||
private int cameraFps;
|
||||
private boolean cameraHighSpeed;
|
||||
private boolean showTouches;
|
||||
private boolean stayAwake;
|
||||
private List<CodecOption> videoCodecOptions;
|
||||
@@ -142,10 +141,6 @@ public class Options {
|
||||
return cameraFps;
|
||||
}
|
||||
|
||||
public boolean getCameraHighSpeed() {
|
||||
return cameraHighSpeed;
|
||||
}
|
||||
|
||||
public boolean getShowTouches() {
|
||||
return showTouches;
|
||||
}
|
||||
@@ -397,9 +392,6 @@ public class Options {
|
||||
case "camera_fps":
|
||||
options.cameraFps = Integer.parseInt(value);
|
||||
break;
|
||||
case "camera_high_speed":
|
||||
options.cameraHighSpeed = Boolean.parseBoolean(value);
|
||||
break;
|
||||
case "send_device_meta":
|
||||
options.sendDeviceMeta = Boolean.parseBoolean(value);
|
||||
break;
|
||||
|
||||
@@ -144,7 +144,7 @@ public final class Server {
|
||||
surfaceCapture = new ScreenCapture(device);
|
||||
} else {
|
||||
surfaceCapture = new CameraCapture(options.getCameraId(), options.getCameraFacing(), options.getCameraSize(),
|
||||
options.getMaxSize(), options.getCameraAspectRatio(), options.getCameraFps(), options.getCameraHighSpeed());
|
||||
options.getMaxSize(), options.getCameraAspectRatio(), options.getCameraFps());
|
||||
}
|
||||
SurfaceEncoder surfaceEncoder = new SurfaceEncoder(surfaceCapture, videoStreamer, options.getVideoBitRate(), options.getMaxFps(),
|
||||
options.getVideoCodecOptions(), options.getVideoEncoder(), options.getDownsizeOnError());
|
||||
|
||||
Reference in New Issue
Block a user