Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
111.47k stars 10.68k forks source link

encoding error,exception on thread #4921

Closed 1bharath-yadav closed 5 months ago

1bharath-yadav commented 5 months ago

Environment Archlinux

Describe the bug scrcpy --video-source=camera --camera-facing=front \ --v4l2-sink=/dev/video0;

scrcpy 2.4 https://github.com/Genymobile/scrcpy INFO: Video orientation is locked for v4l2 sink. See --lock-video-orientation. INFO: Camera video source: control disabled INFO: Camera video source: microphone audio source selected INFO: ADB device found: INFO: --> (usb) Q8JR4DUCLJIRKVPZ device 2201117PI /usr/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 138.8 MB/s (69007 bytes in 0.000s) [server] INFO: Device: [Xiaomi] POCO 2201117PI (Android 13) [server] INFO: Using camera '1' INFO: Renderer: opengl INFO: OpenGL version: 4.6 (Compatibility Profile) Mesa 24.0.7-arch1.3 INFO: Trilinear filtering enabled INFO: v4l2 sink started to device: /dev/video0 INFO: Texture: 2320x1744 [server] ERROR: Encoding error: java.lang.IllegalArgumentException: null [server] ERROR: Exception on thread Thread[video,5,main] java.lang.IllegalArgumentException at android.media.MediaCodec.native_configure(Native Method) at android.media.MediaCodec.configure(MediaCodec.java:2214) at android.media.MediaCodec.configure(MediaCodec.java:2130) at com.genymobile.scrcpy.SurfaceEncoder.streamScreen(SurfaceEncoder.java:69) 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) WARN: Device disconnected

rom1v commented 5 months ago

The encoder failed. I'm surprised that it does not retry with a lower resolution. Does it only happen with camera capture?

Can you try with -m1024?

1bharath-yadav commented 5 months ago

Yea

1bharath-yadav commented 5 months ago

sorry I am an Idoit it works

scrcpy -m 1024 --video-source=camera --no-audio --camera-facing=front \
    --v4l2-sink=/dev/video0

scrcpy 2.4 <https://github.com/Genymobile/scrcpy>
INFO: Video orientation is locked for v4l2 sink. See --lock-video-orientation.
INFO: Camera video source: control disabled
INFO: ADB device found:
INFO:     -->   (usb)  Q8JR4DUCLJIRKVPZ                device  2201117PI
/usr/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 115.2 MB/s (69007 bytes in 0.001s)
[server] INFO: Device: [Xiaomi] POCO 2201117PI (Android 13)
INFO: Renderer: opengl
INFO: OpenGL version: 4.6 (Compatibility Profile) Mesa 24.0.7-arch1.3
INFO: Trilinear filtering enabled
[server] INFO: Using camera '1'
INFO: v4l2 sink started to device: /dev/video0
INFO: Texture: 960x720
WARN: Killing the server...
rom1v commented 5 months ago

scrcpy -m 1024 --video-source=camera --no-audio --camera-facing=front --v4l2-sink=/dev/video0

Does it work if you don't pass --no-audio? Does it work if you don't pass -m 1024?

It should have retried with a lower resolution automatically.

To investigate, could you please test with this server binary where I added some logs:

And reproduce the error:

export SCRCPY_SERVER_PATH=/path/to/this/scrcpy-server  # adapt the path
scrcpy --video-source=camera --camera-facing=front

Then post the console output.

Thank you

diff ```diff diff --git a/server/src/main/java/com/genymobile/scrcpy/SurfaceEncoder.java b/server/src/main/java/com/genymobile/scrcpy/SurfaceEncoder.java index 28435c098..9d11e86c3 100644 --- a/server/src/main/java/com/genymobile/scrcpy/SurfaceEncoder.java +++ b/server/src/main/java/com/genymobile/scrcpy/SurfaceEncoder.java @@ -61,6 +61,7 @@ public class SurfaceEncoder implements AsyncProcessor { do { Size size = capture.getSize(); + Ln.i("==== " + size); format.setInteger(MediaFormat.KEY_WIDTH, size.getWidth()); format.setInteger(MediaFormat.KEY_HEIGHT, size.getHeight()); @@ -97,6 +98,9 @@ public class SurfaceEncoder implements AsyncProcessor { } private boolean prepareRetry(Size currentSize) { + Ln.i("==== firstFrameSend=" + firstFrameSent); + Ln.i("==== consecutiveErrors=" + consecutiveErrors); + Ln.i("==== downsizeOnError=" + downsizeOnError); if (firstFrameSent) { ++consecutiveErrors; if (consecutiveErrors >= MAX_CONSECUTIVE_ERRORS) { @@ -117,12 +121,14 @@ public class SurfaceEncoder implements AsyncProcessor { // Downsizing on error is only enabled if an encoding failure occurs before the first frame (downsizing later could be surprising) int newMaxSize = chooseMaxSizeFallback(currentSize); + Ln.i("maxSizeFallback index=" + newMaxSize); if (newMaxSize == 0) { // Must definitively fail return false; } boolean accepted = capture.setMaxSize(newMaxSize); + Ln.i("fallback accepted=" + accepted); if (!accepted) { return false; } ```
1bharath-yadav commented 5 months ago
 scrcpy -m 1024 --video-source=camera  --no-video-playback  --camera-facing=front \
    --v4l2-sink=/dev/video0

scrcpy 2.4 <https://github.com/Genymobile/scrcpy>
INFO: Video orientation is locked for v4l2 sink. See --lock-video-orientation.
INFO: Camera video source: control disabled
INFO: Camera video source: microphone audio source selected
INFO: ADB device found:
INFO:     -->   (usb)  Q8JR4DUCLJIRKVPZ                device  2201117PI
/usr/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 72.4 MB/s (69007 bytes in 0.001s)
[server] INFO: Device: [Xiaomi] POCO 2201117PI (Android 13)
[server] INFO: Using camera '1'
INFO: v4l2 sink started to device: /dev/video0
scrcpy --video-source=camera --camera-facing=front \
    --v4l2-sink=/dev/video0
scrcpy 2.4 <https://github.com/Genymobile/scrcpy>
INFO: Video orientation is locked for v4l2 sink. See --lock-video-orientation.
INFO: Camera video source: control disabled
INFO: Camera video source: microphone audio source selected
INFO: ADB device found:
INFO:     -->   (usb)  Q8JR4DUCLJIRKVPZ                device  2201117PI
/usr/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 63.4 MB/s (69007 bytes in 0.001s)
[server] INFO: Device: [Xiaomi] POCO 2201117PI (Android 13)
INFO: Renderer: opengl
INFO: OpenGL version: 4.6 (Compatibility Profile) Mesa 24.0.7-arch1.3
INFO: Trilinear filtering enabled
[server] INFO: Using camera '1'
INFO: v4l2 sink started to device: /dev/video0
INFO: Texture: 2320x1744
[server] ERROR: Encoding error: java.lang.IllegalArgumentException: null
WARN: Device disconnected
[server] ERROR: Exception on thread Thread[video,5,main]
java.lang.IllegalArgumentException
        at android.media.MediaCodec.native_configure(Native Method)
        at android.media.MediaCodec.configure(MediaCodec.java:2214)
        at android.media.MediaCodec.configure(MediaCodec.java:2130)
        at com.genymobile.scrcpy.SurfaceEncoder.streamScreen(SurfaceEncoder.java:69)
        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)

i dont know how to test server

rom1v commented 5 months ago

i dont know how to test server

Download the scrcpy-server binary I linked in https://github.com/Genymobile/scrcpy/issues/4921#issuecomment-2109401604.

Then set an environment variable to force scrcpy to use this specific one (adapt the path):

export SCRCPY_SERVER_PATH=/path/to/this/scrcpy-server

Just after, in the same terminal, execute:

scrcpy --video-source=camera --camera-facing=front
1bharath-yadav commented 5 months ago

Yes yes doing that

On Tue, 14 May, 2024, 12:24 pm Romain Vimont, @.***> wrote:

i dont know how to test server

Download the scrcpy-server binary I linked in #4921 (comment) https://github.com/Genymobile/scrcpy/issues/4921#issuecomment-2109401604 somewhere.

Then set an environment variable to force scrcpy using this specific one (adapt the path):

export SCRCPY_SERVER_PATH=/path/to/this/scrcpy-server

Just after, in the same terminal, execute:

scrcpy --video-source=camera --camera-facing=front

— Reply to this email directly, view it on GitHub https://github.com/Genymobile/scrcpy/issues/4921#issuecomment-2109417823, or unsubscribe https://github.com/notifications/unsubscribe-auth/BBOPGZD27RBUDWVHZ33OCE3ZCGYIXAVCNFSM6AAAAABHVP4IRKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBZGQYTOOBSGM . You are receiving this because you modified the open/close state.Message ID: @.***>

1bharath-yadav commented 5 months ago
$ scrcpy --video-source=camera --camera-facing=front
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)  Q8JR4DUCLJIRKVPZ                device  2201117PI
/home/Archer/Desktop/scrcpy-server: 1 file pushed, 0 skipped. 135.3 MB/s (109486 bytes in 0.001s)
[server] INFO: Device: [Xiaomi] POCO 2201117PI (Android 13)
INFO: Renderer: opengl
INFO: OpenGL version: 4.6 (Compatibility Profile) Mesa 24.0.7-arch1.3
INFO: Trilinear filtering enabled
[server] INFO: Using camera '1'
[server] INFO: ==== Size{width=2320, height=1744}
INFO: Texture: 2320x1744
[server] ERROR: Encoding error: java.lang.IllegalArgumentException: null
[server] INFO: ==== firstFrameSend=false
[server] INFO: ==== consecutiveErrors=0
[server] INFO: ==== downsizeOnError=true
[server] INFO: maxSizeFallback index=1920
[server] INFO: fallback accepted=true
[server] INFO: Retrying with -m1920...
[server] INFO: Retrying...
[server] INFO: ==== Size{width=1920, height=1440}
INFO: Texture: 1920x1440
rom1v commented 5 months ago

Hmm, that's great, but now it retries :thinking:

[server] INFO: Retrying with -m1920...

The initial issue was that it did not retry, so I added logs to understand why :confused:

Could you reproduce your initial issue (somehow) with this new server binary?

1bharath-yadav commented 5 months ago
scrcpy --video-source=camera --no-audio --camera-facing=front \
    --v4l2-sink=/dev/video0

scrcpy 2.4 <https://github.com/Genymobile/scrcpy>
INFO: Video orientation is locked for v4l2 sink. See --lock-video-orientation.
INFO: Camera video source: control disabled
INFO: ADB device found:
INFO:     -->   (usb)  Q8JR4DUCLJIRKVPZ                device  2201117PI
/home/Archer/Desktop/scrcpy-server: 1 file pushed, 0 skipped. 162.4 MB/s (109486 bytes in 0.001s)
[server] INFO: Device: [Xiaomi] POCO 2201117PI (Android 13)
INFO: Renderer: opengl
INFO: OpenGL version: 4.6 (Compatibility Profile) Mesa 24.0.7-arch1.3
INFO: Trilinear filtering enabled
[server] INFO: Using camera '1'
[server] INFO: ==== Size{width=2320, height=1744}
INFO: v4l2 sink started to device: /dev/video0
INFO: Texture: 2320x1744
[server] ERROR: Encoding error: java.lang.IllegalArgumentException: null
[server] INFO: ==== firstFrameSend=false
[server] INFO: ==== consecutiveErrors=0
[server] INFO: ==== downsizeOnError=false
WARN: Device disconnected
[server] ERROR: Exception on thread Thread[video,5,main]
java.lang.IllegalArgumentException
        at android.media.MediaCodec.native_configure(Native Method)
        at android.media.MediaCodec.configure(MediaCodec.java:2214)
        at android.media.MediaCodec.configure(MediaCodec.java:2130)
        at com.genymobile.scrcpy.SurfaceEncoder.streamScreen(SurfaceEncoder.java:70)
        at com.genymobile.scrcpy.SurfaceEncoder.lambda$start$0$com-genymobile-scrcpy-SurfaceEncoder(SurfaceEncoder.java:259)
        at com.genymobile.scrcpy.SurfaceEncoder$$ExternalSyntheticLambda0.run(Unknown Source:4)
        at java.lang.Thread.run(Thread.java:1012)
rom1v commented 5 months ago

Oh, ok, thank you very much! I understand now.

When V4L2 sink is set, the "downsize on error" feature is disabled:

https://github.com/Genymobile/scrcpy/blob/206809a99affad9a7aa58fcf7593cea71f48954d/app/src/cli.c#L2571-L2574

1bharath-yadav commented 5 months ago

love your work