Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
103.02k stars 10.01k forks source link

Unable to list camera sizes on S20+ #4852

Closed parkerlreed closed 3 weeks ago

parkerlreed commented 1 month ago

Environment

Describe the bug

Listing cameras works as expected but then going to list sizes results in a crash.

On errors, please provide the output of the console (and adb logcat if relevant).

$ scrcpy --list-cameras
scrcpy 2.4 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     -->   (usb)  R5CNB05JENH                     device  SM_G986U1
/usr/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 156.0 MB/s (69007 bytes in 0.000s)
[server] INFO: Device: [samsung] samsung SM-G986U1 (Android 13)
[server] INFO: List of cameras:
    --camera-id=0    (back, 4032x3024, fps=[15, 24, 30])
    --camera-id=1    (front, 3648x2736, fps=[15, 24, 30])
    --camera-id=2    (back, 4032x3024, fps=[15, 24, 30])
    --camera-id=3    (front, 3216x2208, fps=[15, 24, 30])
    --camera-id=4    (back, 640x480, fps=[5, 10, 15, 20])
$ scrcpy --list-camera-sizes
scrcpy 2.4 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     -->   (usb)  R5CNB05JENH                     device  SM_G986U1
/usr/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 155.4 MB/s (69007 bytes in 0.000s)
[server] INFO: Device: [samsung] samsung SM-G986U1 (Android 13)
[server] ERROR: Attempt to get length of null array
java.lang.NullPointerException: Attempt to get length of null array
        at com.genymobile.scrcpy.LogUtils.buildCameraListMessage(LogUtils.java:121)
        at com.genymobile.scrcpy.Server.internalMain(Server.java:252)
        at com.genymobile.scrcpy.Server.main(Server.java:214)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:411)
parkerlreed commented 1 month ago

Realized this may be due to the 5th camera being a depth sensor that can't be grabbed like a normal device

[parker@rogally ~]$ scrcpy --video-source=camera --camera-id=4
scrcpy 2.4 <https://github.com/Genymobile/scrcpy>
INFO: Camera video source: control disabled
INFO: Camera video source: microphone audio source selected
INFO: ADB device found:
INFO:     -->   (usb)  R5CNB05JENH                     device  SM_G986U1
/usr/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 115.7 MB/s (69007 bytes in 0.001s)
[server] INFO: Device: [samsung] samsung SM-G986U1 (Android 13)
INFO: Renderer: opengl
INFO: OpenGL version: 4.6 (Compatibility Profile) Mesa 24.0.5-arch1.1
INFO: Trilinear filtering enabled
ERROR: Demuxer 'video': stream disabled due to connection error
ERROR: Demuxer 'audio': stream disabled due to connection error
ERROR: Demuxer error
[server] ERROR: Exception on thread Thread[video,5,main]
java.lang.NullPointerException: Attempt to get length of null array
        at java.util.Arrays.stream(Arrays.java:5473)
        at com.genymobile.scrcpy.FakeContext$$ExternalSyntheticApiModelOutline0.m(Unknown Source:0)
        at com.genymobile.scrcpy.CameraCapture.selectSize(CameraCapture.java:130)
        at com.genymobile.scrcpy.CameraCapture.init(CameraCapture.java:80)
        at com.genymobile.scrcpy.SurfaceEncoder.streamScreen(SurfaceEncoder.java:55)
        at com.genymobile.scrcpy.SurfaceEncoder.lambda$start$0$com-genymobile-scrcpy-SurfaceEncoder(SurfaceEncoder.java:253)
        at com.genymobile.scrcpy.SurfaceEncoder$$ExternalSyntheticLambda0.run(Unknown Source:4)
        at java.lang.Thread.run(Thread.java:1012)
rom1v commented 1 month ago

Thank you for your report.

Could you please retry with these changes:

diff --git a/server/src/main/java/com/genymobile/scrcpy/CameraCapture.java b/server/src/main/java/com/genymobile/scrcpy/CameraCapture.java
index a1003829f..df3cf7c4f 100644
--- a/server/src/main/java/com/genymobile/scrcpy/CameraCapture.java
+++ b/server/src/main/java/com/genymobile/scrcpy/CameraCapture.java
@@ -127,6 +127,10 @@ public class CameraCapture extends SurfaceCapture {

         StreamConfigurationMap configs = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
         android.util.Size[] sizes = highSpeed ? configs.getHighSpeedVideoSizes() : configs.getOutputSizes(MediaCodec.class);
+        if (sizes == null) {
+            return null;
+        }
+
         Stream<android.util.Size> stream = Arrays.stream(sizes);
         if (maxSize > 0) {
             stream = stream.filter(it -> it.getWidth() <= maxSize && it.getHeight() <= maxSize);
diff --git a/server/src/main/java/com/genymobile/scrcpy/LogUtils.java b/server/src/main/java/com/genymobile/scrcpy/LogUtils.java
index efa0672b7..1ffb19d3c 100644
--- a/server/src/main/java/com/genymobile/scrcpy/LogUtils.java
+++ b/server/src/main/java/com/genymobile/scrcpy/LogUtils.java
@@ -118,12 +118,16 @@ public final class LogUtils {
                         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());
+                        if (sizes == null || sizes.length == 0) {
+                            builder.append("\n        (none)");
+                        } else {
+                            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) {
+                        if (highSpeedSizes != null && highSpeedSizes.length > 0) {
                             builder.append("\n      High speed capture (--camera-high-speed):");
                             for (android.util.Size size : highSpeedSizes) {
                                 Range<Integer>[] highFpsRanges = configs.getHighSpeedVideoFpsRanges();

Here is a server binary including the changes (for scrcpy v2.4).

parkerlreed commented 1 month ago

That seems to have worked!

[parker@rogally ~]$ scrcpy --list-camera-sizes
scrcpy 2.4 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     -->   (usb)  R5CNB05JENH                     device  SM_G986U1
/usr/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 262.1 MB/s (163648 bytes in 0.001s)
[server] INFO: Device: [samsung] samsung SM-G986U1 (Android 13)
[server] INFO: List of cameras:
    --camera-id=0    (back, 4032x3024, fps=[15, 24, 30])
        - 4032x3024
        - 4032x2268
        - 4032x1816
        - 3024x3024
        - 1920x824
        - 3840x2160
        - 1920x1080
        - 2400x1080
        - 1920x864
        - 1920x1440
        - 1440x1080
        - 1088x1088
        - 1280x720
        - 960x720
        - 720x480
        - 640x480
        - 640x360
        - 352x288
        - 320x240
        - 256x144
        - 176x144
      High speed capture (--camera-high-speed):
        - 1280x720 (fps=[120, 240])
        - 1920x1080 (fps=[120, 240])
        - 1920x824 (fps=[120, 240])
    --camera-id=1    (front, 3648x2736, fps=[15, 24, 30])
        - 3648x2736
        - 3648x2048
        - 3648x1640
        - 2736x2736
        - 1920x824
        - 1920x1080
        - 2400x1080
        - 1920x864
        - 1920x1440
        - 1440x1080
        - 1088x1088
        - 1280x720
        - 960x720
        - 720x480
        - 640x480
        - 640x360
        - 352x288
        - 320x240
        - 256x144
        - 176x144
      High speed capture (--camera-high-speed):
        - 1280x720 (fps=[120])
        - 1920x1080 (fps=[120])
        - 1920x824 (fps=[120])
    --camera-id=2    (back, 4032x3024, fps=[15, 24, 30])
        - 4032x3024
        - 4032x2268
        - 4032x1816
        - 3024x3024
        - 1920x824
        - 3840x2160
        - 1920x1080
        - 2400x1080
        - 1920x864
        - 1920x1440
        - 1440x1080
        - 1088x1088
        - 1280x720
        - 960x720
        - 720x480
        - 640x480
        - 640x360
        - 352x288
        - 320x240
        - 256x144
        - 176x144
    --camera-id=3    (front, 3216x2208, fps=[15, 24, 30])
        - 3216x1808
        - 3216x1448
        - 2944x2208
        - 2944x1656
        - 2944x1320
        - 2208x2208
        - 1920x824
        - 1920x1080
        - 2400x1080
        - 1920x864
        - 1920x1440
        - 1440x1080
        - 1088x1088
        - 1280x720
        - 960x720
        - 720x480
        - 640x480
        - 640x360
        - 352x288
        - 320x240
        - 256x144
        - 176x144
      High speed capture (--camera-high-speed):
        - 1280x720 (fps=[120])
        - 1920x1080 (fps=[120])
        - 1920x824 (fps=[120])
    --camera-id=4    (back, 640x480, fps=[5, 10, 15, 20])
        (none)
parkerlreed commented 1 month ago

Side note: I can do 1080 60 for video recording but this seems to not list it?

Camera ID 0 says max of 30 and when I trying specifying ID 0 size 1080 and FPS 60 I get Camera capture failed.

image

rom1v commented 4 weeks ago

That seems to have worked!

Merged bcb8503b261969c1ec176c7b852f9e0a4924db7b into dev :rocket:

Side note: I can do 1080 60 for video recording but this seems to not list it?

Camera ID 0 says max of 30 and when I trying specifying ID 0 size 1080 and FPS 60 I get Camera capture failed.

Looks like #4675. Can you record at 1080p 60fps with another camera app (like OpenCamera)?