Compare commits

..

1 Commits

Author SHA1 Message Date
Simon Chan
322427f7b0 Extract SurfaceCapture from ScreenEncoder
Extract an interface SurfaceCapture from ScreenEncoder, representing a
video source which can be rendered to a Surface for encoding.

Split ScreenEncoder into:
 - ScreenCapture, implementing SurfaceCapture to capture the device
   screen,
 - SurfaceEncoder, to encode any SurfaceCapture.

This separation prepares the introduction of another SurfaceCapture
implementation to capture the camera instead of the device screen.

Co-authored-by: Romain Vimont <rom@rom1v.com>
2023-08-22 18:44:49 +02:00
18 changed files with 11 additions and 120 deletions

View File

@@ -23,7 +23,6 @@ _scrcpy() {
--kill-adb-on-close
-K --hid-keyboard
--legacy-paste
--list-cameras
--list-displays
--list-encoders
--lock-video-orientation

View File

@@ -30,7 +30,6 @@ arguments=(
'--kill-adb-on-close[Kill adb when scrcpy terminates]'
{-K,--hid-keyboard}'[Simulate a physical keyboard by using HID over AOAv2]'
'--legacy-paste[Inject computer clipboard text as a sequence of key events on Ctrl+v]'
'--list-cameras[List cameras available on the device]'
'--list-displays[List displays available on the device]'
'--list-encoders[List video and audio encoders available on the device]'
'--lock-video-orientation=[Lock video orientation]:orientation:(unlocked initial 0 1 2 3)'

View File

@@ -155,9 +155,6 @@ Inject computer clipboard text as a sequence of key events on Ctrl+v (like MOD+S
This is a workaround for some devices not behaving as expected when setting the device clipboard programmatically.
.B \-\-list\-cameras
List cameras available on the device.
.TP
.B \-\-list\-encoders
List video and audio encoders available on the device.

View File

@@ -79,7 +79,6 @@ enum {
OPT_AUDIO_SOURCE,
OPT_KILL_ADB_ON_CLOSE,
OPT_TIME_LIMIT,
OPT_LIST_CAMERAS,
};
struct sc_option {
@@ -313,11 +312,6 @@ static const struct sc_option options[] = {
"This is a workaround for some devices not behaving as "
"expected when setting the device clipboard programmatically.",
},
{
.longopt_id = OPT_LIST_CAMERAS,
.longopt = "list-cameras",
.text = "List device cameras.",
},
{
.longopt_id = OPT_LIST_DISPLAYS,
.longopt = "list-displays",
@@ -1950,9 +1944,6 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
"platform).");
return false;
#endif
case OPT_LIST_CAMERAS:
opts->list_cameras = true;
break;
case OPT_LIST_ENCODERS:
opts->list_encoders = true;
break;

View File

@@ -81,6 +81,5 @@ const struct scrcpy_options scrcpy_options_default = {
.require_audio = false,
.list_encoders = false,
.list_displays = false,
.list_cameras = false,
.kill_adb_on_close = false,
};

View File

@@ -181,7 +181,6 @@ struct scrcpy_options {
bool require_audio;
bool list_encoders;
bool list_displays;
bool list_cameras;
bool kill_adb_on_close;
};

View File

@@ -381,7 +381,6 @@ scrcpy(struct scrcpy_options *options) {
.power_on = options->power_on,
.list_encoders = options->list_encoders,
.list_displays = options->list_displays,
.list_cameras = options->list_cameras,
.kill_adb_on_close = options->kill_adb_on_close,
};
@@ -400,8 +399,7 @@ scrcpy(struct scrcpy_options *options) {
server_started = true;
if (options->list_encoders || options->list_displays
|| options->list_cameras) {
if (options->list_encoders || options->list_displays) {
bool ok = await_for_server(NULL);
ret = ok ? SCRCPY_EXIT_SUCCESS : SCRCPY_EXIT_FAILURE;
goto end;

View File

@@ -316,9 +316,6 @@ execute_server(struct sc_server *server,
if (params->list_displays) {
ADD_PARAM("list_displays=true");
}
if (params->list_cameras) {
ADD_PARAM("list_cameras=true");
}
#undef ADD_PARAM
@@ -898,8 +895,7 @@ run_server(void *data) {
// If --list-* is passed, then the server just prints the requested data
// then exits.
if (params->list_encoders || params->list_displays
|| params->list_cameras) {
if (params->list_encoders || params->list_displays) {
sc_pid pid = execute_server(server, params);
if (pid == SC_PROCESS_NONE) {
goto error_connection_failed;

View File

@@ -58,7 +58,6 @@ struct sc_server_params {
bool power_on;
bool list_encoders;
bool list_displays;
bool list_cameras;
bool kill_adb_on_close;
};

View File

@@ -3,12 +3,6 @@ package com.genymobile.scrcpy;
import com.genymobile.scrcpy.wrappers.DisplayManager;
import com.genymobile.scrcpy.wrappers.ServiceManager;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.media.MediaCodec;
import java.util.List;
public final class LogUtils {
@@ -66,48 +60,4 @@ public final class LogUtils {
}
return builder.toString();
}
private static String getCameraFacingName(int facing) {
switch (facing) {
case CameraCharacteristics.LENS_FACING_FRONT:
return "front";
case CameraCharacteristics.LENS_FACING_BACK:
return "back";
case CameraCharacteristics.LENS_FACING_EXTERNAL:
return "external";
default:
return "unknown";
}
}
public static String buildCameraListMessage() {
StringBuilder builder = new StringBuilder("List of cameras:");
CameraManager cameraManager = ServiceManager.getCameraManager();
try {
String[] cameraIds = cameraManager.getCameraIdList();
if (cameraIds == null || cameraIds.length == 0) {
builder.append("\n (none)");
} else {
for (String id : cameraIds) {
builder.append("\n --video-source=camera --camera=").append(id);
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(id);
Integer facingInteger = characteristics.get(CameraCharacteristics.LENS_FACING);
if (facingInteger != null) {
int facing = facingInteger;
builder.append(" (").append(getCameraFacingName(facing)).append(')');
}
StreamConfigurationMap configs = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
android.util.Size[] sizes = configs.getOutputSizes(MediaCodec.class);
for (android.util.Size size : sizes) {
// TODO remove (just for testing)
builder.append("\n - " + size.getWidth() + "x" + size.getHeight());
}
}
}
} catch (CameraAccessException e) {
builder.append("\n (access denied)");
}
return builder.toString();
}
}

View File

@@ -38,7 +38,6 @@ public class Options {
private boolean listEncoders;
private boolean listDisplays;
private boolean listCameras;
// Options not used by the scrcpy client, but useful to use scrcpy-server directly
private boolean sendDeviceMeta = true; // send device name and size
@@ -162,10 +161,6 @@ public class Options {
return listDisplays;
}
public boolean getListCameras() {
return listCameras;
}
public boolean getSendDeviceMeta() {
return sendDeviceMeta;
}
@@ -311,9 +306,6 @@ public class Options {
case "list_displays":
options.listDisplays = Boolean.parseBoolean(value);
break;
case "list_cameras":
options.listCameras = Boolean.parseBoolean(value);
break;
case "send_device_meta":
options.sendDeviceMeta = Boolean.parseBoolean(value);
break;

View File

@@ -2,7 +2,6 @@ package com.genymobile.scrcpy;
import android.os.BatteryManager;
import android.os.Build;
import android.os.Looper;
import java.io.IOException;
import java.util.ArrayList;
@@ -100,8 +99,7 @@ public final class Server {
boolean audio = options.getAudio();
boolean sendDummyByte = options.getSendDummyByte();
boolean camera = true;
Workarounds.apply(audio, camera);
Workarounds.apply(audio);
List<AsyncProcessor> asyncProcessors = new ArrayList<>();
@@ -182,7 +180,7 @@ public final class Server {
Ln.initLogLevel(options.getLogLevel());
if (options.getListEncoders() || options.getListDisplays() || options.getListCameras()) {
if (options.getListEncoders() || options.getListDisplays()) {
if (options.getCleanup()) {
CleanUp.unlinkSelf();
}
@@ -194,10 +192,6 @@ public final class Server {
if (options.getListDisplays()) {
Ln.i(LogUtils.buildDisplayListMessage());
}
if (options.getListCameras()) {
Workarounds.apply(false, true);
Ln.i(LogUtils.buildCameraListMessage());
}
// Just print the requested data, do not mirror
return;
}

View File

@@ -28,13 +28,14 @@ public final class Workarounds {
// not instantiable
}
public static void apply(boolean audio, boolean camera) {
public static void apply(boolean audio) {
Workarounds.prepareMainLooper();
boolean mustFillAppInfo = false;
boolean mustFillBaseContext = false;
boolean mustFillAppContext = false;
if (Build.BRAND.equalsIgnoreCase("meizu")) {
// Workarounds must be applied for Meizu phones:
// - <https://github.com/Genymobile/scrcpy/issues/240>
@@ -64,10 +65,6 @@ public final class Workarounds {
mustFillAppContext = true;
}
if (camera) {
mustFillAppInfo = true;
}
if (mustFillAppInfo) {
Workarounds.fillAppInfo();
}
@@ -157,7 +154,7 @@ public final class Workarounds {
}
}
private static void fillBaseContext() {
public static void fillBaseContext() {
try {
fillActivityThread();

View File

@@ -17,7 +17,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@SuppressLint("PrivateApi,DiscouragedPrivateApi")
public final class ActivityManager {
public class ActivityManager {
private final IInterface manager;
private Method getContentProviderExternalMethod;

View File

@@ -11,7 +11,7 @@ import android.os.IInterface;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public final class ClipboardManager {
public class ClipboardManager {
private final IInterface manager;
private Method getPrimaryClipMethod;
private Method setPrimaryClipMethod;

View File

@@ -14,7 +14,7 @@ import java.io.Closeable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public final class ContentProvider implements Closeable {
public class ContentProvider implements Closeable {
public static final String TABLE_SYSTEM = "system";
public static final String TABLE_SECURE = "secure";

View File

@@ -1,15 +1,9 @@
package com.genymobile.scrcpy.wrappers;
import com.genymobile.scrcpy.FakeContext;
import com.genymobile.scrcpy.Workarounds;
import android.annotation.SuppressLint;
import android.content.Context;
import android.hardware.camera2.CameraManager;
import android.os.IBinder;
import android.os.IInterface;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -32,7 +26,6 @@ public final class ServiceManager {
private static StatusBarManager statusBarManager;
private static ClipboardManager clipboardManager;
private static ActivityManager activityManager;
private static CameraManager cameraManager;
private ServiceManager() {
/* not instantiable */
@@ -136,16 +129,4 @@ public final class ServiceManager {
return activityManager;
}
public static CameraManager getCameraManager() {
if (cameraManager == null) {
try {
Constructor<CameraManager> ctor = CameraManager.class.getDeclaredConstructor(Context.class);
cameraManager = ctor.newInstance(FakeContext.get());
} catch (Exception e) {
throw new AssertionError(e);
}
}
return cameraManager;
}
}

View File

@@ -7,7 +7,7 @@ import android.os.IInterface;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public final class StatusBarManager {
public class StatusBarManager {
private final IInterface manager;
private Method expandNotificationsPanelMethod;