Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to list camera sizes on S20+ #4852

Closed
2 tasks done
parkerlreed opened this issue Apr 16, 2024 · 5 comments
Closed
2 tasks done

Unable to list camera sizes on S20+ #4852

parkerlreed opened this issue Apr 16, 2024 · 5 comments

Comments

@parkerlreed
Copy link

  • I have read the FAQ.
  • I have searched in existing issues.

Environment

  • OS: Arch Linux
  • scrcpy version: 2.4
  • installation method: Repo
  • device model: Samsung S20+
  • Android version: 13

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
Copy link
Author

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
Copy link
Collaborator

rom1v commented Apr 17, 2024

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).

  • scrcpy-server SHA-256: b92c92032f0afaf462a4df551eec9e880e716c7302c16119ee50c9c017b79a9

@parkerlreed
Copy link
Author

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
Copy link
Author

parkerlreed commented Apr 17, 2024

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 added a commit that referenced this issue Apr 19, 2024
The array of sizes may be null. Handle this case gracefully.

Fixes #4852 <#4852>
@rom1v
Copy link
Collaborator

rom1v commented Apr 19, 2024

That seems to have worked!

Merged bcb8503 into dev 🚀

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)?

FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this issue Aug 2, 2024
The array of sizes may be null. Handle this case gracefully.

Fixes Genymobile#4852 <Genymobile#4852>
Gottox pushed a commit to Gottox/scrcpy that referenced this issue Sep 29, 2024
The array of sizes may be null. Handle this case gracefully.

Fixes Genymobile#4852 <Genymobile#4852>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants