Add --list-cameras
Add an option to list the device cameras. Co-authored-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
committed by
Romain Vimont
parent
de10be8153
commit
5bba202f01
@@ -23,6 +23,7 @@ _scrcpy() {
|
|||||||
--kill-adb-on-close
|
--kill-adb-on-close
|
||||||
-K --hid-keyboard
|
-K --hid-keyboard
|
||||||
--legacy-paste
|
--legacy-paste
|
||||||
|
--list-cameras
|
||||||
--list-displays
|
--list-displays
|
||||||
--list-encoders
|
--list-encoders
|
||||||
--lock-video-orientation
|
--lock-video-orientation
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ arguments=(
|
|||||||
'--kill-adb-on-close[Kill adb when scrcpy terminates]'
|
'--kill-adb-on-close[Kill adb when scrcpy terminates]'
|
||||||
{-K,--hid-keyboard}'[Simulate a physical keyboard by using HID over AOAv2]'
|
{-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]'
|
'--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-displays[List displays available on the device]'
|
||||||
'--list-encoders[List video and audio encoders 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)'
|
'--lock-video-orientation=[Lock video orientation]:orientation:(unlocked initial 0 1 2 3)'
|
||||||
|
|||||||
@@ -155,6 +155,9 @@ 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.
|
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
|
.TP
|
||||||
.B \-\-list\-encoders
|
.B \-\-list\-encoders
|
||||||
List video and audio encoders available on the device.
|
List video and audio encoders available on the device.
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ enum {
|
|||||||
OPT_AUDIO_SOURCE,
|
OPT_AUDIO_SOURCE,
|
||||||
OPT_KILL_ADB_ON_CLOSE,
|
OPT_KILL_ADB_ON_CLOSE,
|
||||||
OPT_TIME_LIMIT,
|
OPT_TIME_LIMIT,
|
||||||
|
OPT_LIST_CAMERAS,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sc_option {
|
struct sc_option {
|
||||||
@@ -312,6 +313,11 @@ static const struct sc_option options[] = {
|
|||||||
"This is a workaround for some devices not behaving as "
|
"This is a workaround for some devices not behaving as "
|
||||||
"expected when setting the device clipboard programmatically.",
|
"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_id = OPT_LIST_DISPLAYS,
|
||||||
.longopt = "list-displays",
|
.longopt = "list-displays",
|
||||||
@@ -1944,6 +1950,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
"platform).");
|
"platform).");
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
case OPT_LIST_CAMERAS:
|
||||||
|
opts->list_cameras = true;
|
||||||
|
break;
|
||||||
case OPT_LIST_ENCODERS:
|
case OPT_LIST_ENCODERS:
|
||||||
opts->list_encoders = true;
|
opts->list_encoders = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -81,5 +81,6 @@ const struct scrcpy_options scrcpy_options_default = {
|
|||||||
.require_audio = false,
|
.require_audio = false,
|
||||||
.list_encoders = false,
|
.list_encoders = false,
|
||||||
.list_displays = false,
|
.list_displays = false,
|
||||||
|
.list_cameras = false,
|
||||||
.kill_adb_on_close = false,
|
.kill_adb_on_close = false,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -181,6 +181,7 @@ struct scrcpy_options {
|
|||||||
bool require_audio;
|
bool require_audio;
|
||||||
bool list_encoders;
|
bool list_encoders;
|
||||||
bool list_displays;
|
bool list_displays;
|
||||||
|
bool list_cameras;
|
||||||
bool kill_adb_on_close;
|
bool kill_adb_on_close;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -381,6 +381,7 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
.power_on = options->power_on,
|
.power_on = options->power_on,
|
||||||
.list_encoders = options->list_encoders,
|
.list_encoders = options->list_encoders,
|
||||||
.list_displays = options->list_displays,
|
.list_displays = options->list_displays,
|
||||||
|
.list_cameras = options->list_cameras,
|
||||||
.kill_adb_on_close = options->kill_adb_on_close,
|
.kill_adb_on_close = options->kill_adb_on_close,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -399,7 +400,8 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
|
|
||||||
server_started = true;
|
server_started = true;
|
||||||
|
|
||||||
if (options->list_encoders || options->list_displays) {
|
if (options->list_encoders || options->list_displays
|
||||||
|
|| options->list_cameras) {
|
||||||
bool ok = await_for_server(NULL);
|
bool ok = await_for_server(NULL);
|
||||||
ret = ok ? SCRCPY_EXIT_SUCCESS : SCRCPY_EXIT_FAILURE;
|
ret = ok ? SCRCPY_EXIT_SUCCESS : SCRCPY_EXIT_FAILURE;
|
||||||
goto end;
|
goto end;
|
||||||
|
|||||||
@@ -316,6 +316,9 @@ execute_server(struct sc_server *server,
|
|||||||
if (params->list_displays) {
|
if (params->list_displays) {
|
||||||
ADD_PARAM("list_displays=true");
|
ADD_PARAM("list_displays=true");
|
||||||
}
|
}
|
||||||
|
if (params->list_cameras) {
|
||||||
|
ADD_PARAM("list_cameras=true");
|
||||||
|
}
|
||||||
|
|
||||||
#undef ADD_PARAM
|
#undef ADD_PARAM
|
||||||
|
|
||||||
@@ -895,7 +898,8 @@ run_server(void *data) {
|
|||||||
|
|
||||||
// If --list-* is passed, then the server just prints the requested data
|
// If --list-* is passed, then the server just prints the requested data
|
||||||
// then exits.
|
// then exits.
|
||||||
if (params->list_encoders || params->list_displays) {
|
if (params->list_encoders || params->list_displays
|
||||||
|
|| params->list_cameras) {
|
||||||
sc_pid pid = execute_server(server, params);
|
sc_pid pid = execute_server(server, params);
|
||||||
if (pid == SC_PROCESS_NONE) {
|
if (pid == SC_PROCESS_NONE) {
|
||||||
goto error_connection_failed;
|
goto error_connection_failed;
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ struct sc_server_params {
|
|||||||
bool power_on;
|
bool power_on;
|
||||||
bool list_encoders;
|
bool list_encoders;
|
||||||
bool list_displays;
|
bool list_displays;
|
||||||
|
bool list_cameras;
|
||||||
bool kill_adb_on_close;
|
bool kill_adb_on_close;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ package com.genymobile.scrcpy;
|
|||||||
import com.genymobile.scrcpy.wrappers.DisplayManager;
|
import com.genymobile.scrcpy.wrappers.DisplayManager;
|
||||||
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
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;
|
import java.util.List;
|
||||||
|
|
||||||
public final class LogUtils {
|
public final class LogUtils {
|
||||||
@@ -60,4 +66,48 @@ public final class LogUtils {
|
|||||||
}
|
}
|
||||||
return builder.toString();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public class Options {
|
|||||||
|
|
||||||
private boolean listEncoders;
|
private boolean listEncoders;
|
||||||
private boolean listDisplays;
|
private boolean listDisplays;
|
||||||
|
private boolean listCameras;
|
||||||
|
|
||||||
// Options not used by the scrcpy client, but useful to use scrcpy-server directly
|
// Options not used by the scrcpy client, but useful to use scrcpy-server directly
|
||||||
private boolean sendDeviceMeta = true; // send device name and size
|
private boolean sendDeviceMeta = true; // send device name and size
|
||||||
@@ -161,6 +162,10 @@ public class Options {
|
|||||||
return listDisplays;
|
return listDisplays;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getListCameras() {
|
||||||
|
return listCameras;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean getSendDeviceMeta() {
|
public boolean getSendDeviceMeta() {
|
||||||
return sendDeviceMeta;
|
return sendDeviceMeta;
|
||||||
}
|
}
|
||||||
@@ -306,6 +311,9 @@ public class Options {
|
|||||||
case "list_displays":
|
case "list_displays":
|
||||||
options.listDisplays = Boolean.parseBoolean(value);
|
options.listDisplays = Boolean.parseBoolean(value);
|
||||||
break;
|
break;
|
||||||
|
case "list_cameras":
|
||||||
|
options.listCameras = Boolean.parseBoolean(value);
|
||||||
|
break;
|
||||||
case "send_device_meta":
|
case "send_device_meta":
|
||||||
options.sendDeviceMeta = Boolean.parseBoolean(value);
|
options.sendDeviceMeta = Boolean.parseBoolean(value);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.genymobile.scrcpy;
|
|||||||
|
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Looper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -99,7 +100,8 @@ public final class Server {
|
|||||||
boolean audio = options.getAudio();
|
boolean audio = options.getAudio();
|
||||||
boolean sendDummyByte = options.getSendDummyByte();
|
boolean sendDummyByte = options.getSendDummyByte();
|
||||||
|
|
||||||
Workarounds.apply(audio);
|
boolean camera = true;
|
||||||
|
Workarounds.apply(audio, camera);
|
||||||
|
|
||||||
List<AsyncProcessor> asyncProcessors = new ArrayList<>();
|
List<AsyncProcessor> asyncProcessors = new ArrayList<>();
|
||||||
|
|
||||||
@@ -180,7 +182,7 @@ public final class Server {
|
|||||||
|
|
||||||
Ln.initLogLevel(options.getLogLevel());
|
Ln.initLogLevel(options.getLogLevel());
|
||||||
|
|
||||||
if (options.getListEncoders() || options.getListDisplays()) {
|
if (options.getListEncoders() || options.getListDisplays() || options.getListCameras()) {
|
||||||
if (options.getCleanup()) {
|
if (options.getCleanup()) {
|
||||||
CleanUp.unlinkSelf();
|
CleanUp.unlinkSelf();
|
||||||
}
|
}
|
||||||
@@ -192,6 +194,10 @@ public final class Server {
|
|||||||
if (options.getListDisplays()) {
|
if (options.getListDisplays()) {
|
||||||
Ln.i(LogUtils.buildDisplayListMessage());
|
Ln.i(LogUtils.buildDisplayListMessage());
|
||||||
}
|
}
|
||||||
|
if (options.getListCameras()) {
|
||||||
|
Workarounds.apply(false, true);
|
||||||
|
Ln.i(LogUtils.buildCameraListMessage());
|
||||||
|
}
|
||||||
// Just print the requested data, do not mirror
|
// Just print the requested data, do not mirror
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,14 +28,13 @@ public final class Workarounds {
|
|||||||
// not instantiable
|
// not instantiable
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void apply(boolean audio) {
|
public static void apply(boolean audio, boolean camera) {
|
||||||
Workarounds.prepareMainLooper();
|
Workarounds.prepareMainLooper();
|
||||||
|
|
||||||
boolean mustFillAppInfo = false;
|
boolean mustFillAppInfo = false;
|
||||||
boolean mustFillBaseContext = false;
|
boolean mustFillBaseContext = false;
|
||||||
boolean mustFillAppContext = false;
|
boolean mustFillAppContext = false;
|
||||||
|
|
||||||
|
|
||||||
if (Build.BRAND.equalsIgnoreCase("meizu")) {
|
if (Build.BRAND.equalsIgnoreCase("meizu")) {
|
||||||
// Workarounds must be applied for Meizu phones:
|
// Workarounds must be applied for Meizu phones:
|
||||||
// - <https://github.com/Genymobile/scrcpy/issues/240>
|
// - <https://github.com/Genymobile/scrcpy/issues/240>
|
||||||
@@ -65,6 +64,10 @@ public final class Workarounds {
|
|||||||
mustFillAppContext = true;
|
mustFillAppContext = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (camera) {
|
||||||
|
mustFillAppInfo = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (mustFillAppInfo) {
|
if (mustFillAppInfo) {
|
||||||
Workarounds.fillAppInfo();
|
Workarounds.fillAppInfo();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
package com.genymobile.scrcpy.wrappers;
|
package com.genymobile.scrcpy.wrappers;
|
||||||
|
|
||||||
|
import com.genymobile.scrcpy.FakeContext;
|
||||||
|
import com.genymobile.scrcpy.Workarounds;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.hardware.camera2.CameraManager;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.IInterface;
|
import android.os.IInterface;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
@@ -26,6 +32,7 @@ public final class ServiceManager {
|
|||||||
private static StatusBarManager statusBarManager;
|
private static StatusBarManager statusBarManager;
|
||||||
private static ClipboardManager clipboardManager;
|
private static ClipboardManager clipboardManager;
|
||||||
private static ActivityManager activityManager;
|
private static ActivityManager activityManager;
|
||||||
|
private static CameraManager cameraManager;
|
||||||
|
|
||||||
private ServiceManager() {
|
private ServiceManager() {
|
||||||
/* not instantiable */
|
/* not instantiable */
|
||||||
@@ -129,4 +136,16 @@ public final class ServiceManager {
|
|||||||
|
|
||||||
return activityManager;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user