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

custom android 12 root not working #2988

Open
2 tasks done
Fitertom opened this issue Jan 29, 2022 · 8 comments
Open
2 tasks done

custom android 12 root not working #2988

Fitertom opened this issue Jan 29, 2022 · 8 comments

Comments

@Fitertom
Copy link

Fitertom commented Jan 29, 2022

  • I have read the FAQ.

  • I have searched in existing issues.

  • OS: Windows 11

  • scrcpy version: 1.22

  • installation method: Windows release

  • device model: Xiaomi redmi note 8 pro mediatek

  • Android version: 12

i use android 12 i really need a script on it but it doesn't work i looked at similar threads on this topic but didn't find anything

scrcpy 1.22 <https://github.com/Genymobile/scrcpy>
C:\Program Files\scrcpy\scrcpy-server: 1 file pushed, 0 skipped. 76.1 MB/s (40955 bytes in 0.001s)
[server] INFO: Device: Xiaomi Redmi Note 8 Pro (Android 12)
[server] ERROR: Exception on thread Thread[main,5,main]
android.media.MediaCodec$CodecException: start failed
        at android.media.MediaCodec.native_start(Native Method)
        at android.media.MediaCodec.start(MediaCodec.java:2284)
        at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:97)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:73)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:100)
        at com.genymobile.scrcpy.Server.main(Server.java:326)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:357)
INFO: Renderer: direct3d
INFO: Initial texture: 1080x2336
WARN: Device disconnected
WARN: Killing the server...
@rom1v
Copy link
Collaborator

rom1v commented Jan 29, 2022

Oh, I think I missed to catch some errors to retry in #2947.

Could you please replace this file in v1.22, and post the whole console output?

  • scrcpy-server sha256:2eef221b9ab37c6391a8a5324b5c8a9f9b7e45756b25f8b075ea9de21e0c7d52
diff
diff --git a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
index 4c23dd92..79efc17c 100644
--- a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
+++ b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
@@ -89,13 +89,15 @@ public class ScreenEncoder implements Device.RotationListener {
                 Rect unlockedVideoRect = screenInfo.getUnlockedVideoSize().toRect();
                 int videoRotation = screenInfo.getVideoRotation();
                 int layerStack = device.getLayerStack();
-
                 setSize(format, videoRect.width(), videoRect.height());
-                configure(codec, format);
-                Surface surface = codec.createInputSurface();
-                setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack);
-                codec.start();
+
+                Surface surface = null;
                 try {
+                    configure(codec, format);
+                    surface = codec.createInputSurface();
+                    setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack);
+                    codec.start();
+
                     alive = encode(codec, fd);
                     // do not call stop() on exception, it would trigger an IllegalStateException
                     codec.stop();
@@ -119,7 +121,9 @@ public class ScreenEncoder implements Device.RotationListener {
                 } finally {
                     destroyDisplay(display);
                     codec.release();
-                    surface.release();
+                    if (surface != null) {
+                        surface.release();
+                    }
                 }
             } while (alive);
         } finally {

Thank you

@Fitertom
Copy link
Author

Fitertom commented Jan 29, 2022

[server] INFO: Device: Xiaomi Redmi Note 8 Pro (Android 12)
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: start failed
[server] INFO: Retrying with -m1920...
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: start failed
[server] INFO: Retrying with -m1600...
INFO: Renderer: direct3d
INFO: Initial texture: 1080x2336
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: start failed
[server] INFO: Retrying with -m1280...
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: start failed
[server] INFO: Retrying with -m1024...
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: start failed
[server] INFO: Retrying with -m800...
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: start failed
WARN: Device disconnected
[server] ERROR: Exception on thread Thread[main,5,main]
android.media.MediaCodec$CodecException: start failed
        at android.media.MediaCodec.native_start(Native Method)
        at android.media.MediaCodec.start(MediaCodec.java:2284)
        at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:99)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:73)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:100)
        at com.genymobile.scrcpy.Server.main(Server.java:326)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:357)

@rom1v
Copy link
Collaborator

rom1v commented Jan 29, 2022

OK, great, the retry mechanism now works in your case. But it seems your device can't encode the screen at any definition.

You could try with a different encoder: https://github.com/Genymobile/scrcpy#encoder

Also, does screenrecord work?

adb shell screenrecord /sdcard/file.mp4
adb pull /sdcard/file.mp4

@Fitertom
Copy link
Author

OK, great, the retry mechanism now works in your case. But it seems your device can't encode the screen at any definition.

You could try with a different encoder: https://github.com/Genymobile/scrcpy#encoder

Also, does screenrecord work?

adb shell screenrecord /sdcard/file.mp4
adb pull /sdcard/file.mp4

C:\Users\Fitertomus\Downloads\Новая папка (2)>adb shell screenrecord /sdcard/file.mp4
ERROR: unable to start codec (err=-12)
WARNING: failed at 1080x2340, retrying at 720x1280
ERROR: unable to start codec (err=-12)
adb shell screenrecord /sdcard/file.mp4 - DONT WORK

C:\Users\Fitertomus\Downloads\Новая папка (2)>adb pull /sdcard/file.mp4
adb: error: failed to stat remote object '/sdcard/file.mp4': No such file or directory
adb pull /sdcard/file.mp4 - DONT WORK

C:\Users\Fitertomus\Downloads\Новая папка (2)>scrcpy --encoder 'OMX.google.h264.encoder'
scrcpy 1.22 https://github.com/Genymobile/scrcpy
C:\Users\Fitertomus\Downloads\Новая папка (2)\sc...file pushed, 0 skipped. 143.5 MB/s (96899 bytes in 0.001s)
[server] INFO: Device: Xiaomi Redmi Note 8 Pro (Android 12)
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: start failed
[server] INFO: Retrying with -m1920...
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
[server] INFO: Retrying with -m1600...
INFO: Renderer: direct3d
INFO: Initial texture: 1080x2336
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
[server] INFO: Retrying with -m1280...
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
[server] INFO: Retrying with -m1024...
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
[server] INFO: Retrying with -m800...
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
WARN: Device disconnected
[server] ERROR: Exception on thread Thread[main,5,main]
java.lang.IllegalStateException
at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3535)
at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:151)
at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:101)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:73)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:100)
at com.genymobile.scrcpy.Server.main(Server.java:326)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:357)
WARN: Killing the server...

C:\Users\Fitertomus\Downloads\Новая папка (2)>scrcpy --encoder 'OMX.MTK.VIDEO.ENCODER.AVC'
scrcpy 1.22 https://github.com/Genymobile/scrcpy
C:\Users\Fitertomus\Downloads\Новая папка (2)\sc...file pushed, 0 skipped. 146.1 MB/s (96899 bytes in 0.001s)
[server] INFO: Device: Xiaomi Redmi Note 8 Pro (Android 12)
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: start failed
[server] INFO: Retrying with -m1920...
INFO: Renderer: direct3d
INFO: Initial texture: 1080x2336
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
[server] INFO: Retrying with -m1600...
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
[server] INFO: Retrying with -m1280...
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
[server] INFO: Retrying with -m1024...
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
[server] INFO: Retrying with -m800...
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
WARN: Device disconnected
[server] ERROR: Exception on thread Thread[main,5,main]
java.lang.IllegalStateException
at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3535)
at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:151)
at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:101)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:73)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:100)
at com.genymobile.scrcpy.Server.main(Server.java:326)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:357)
WARN: Killing the server...

@Fitertom
Copy link
Author

if anything on the official firmware miui 12.5 scrcpy worked without problems

@rom1v
Copy link
Collaborator

rom1v commented Jan 29, 2022

OK, if screenrecord does not work, then there's definitely a bug in the ROM.

@Fitertom
Copy link
Author

OK, if screenrecord does not work, then there's definitely a bug in the ROM.

I have a built-in screen recording on my phone and from the very beginning it doesn’t work, maybe it’s somehow related, but third-party recording applications asked for access to broadcast / screen recording, it’s possible and it’s somehow connected with this, maybe the protection of android 12 does not allow third-party programs to record screen without permission and these applications simply do not request it

rom1v added a commit that referenced this issue Jan 30, 2022
The new retry mechanism with a lower definition only worked if the error
occurred during encode(). For example:

    java.lang.IllegalStateException
        at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
        at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3452)
        at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:114)
        at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:95)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:61)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:80)
        at com.genymobile.scrcpy.Server.main(Server.java:255)

However, MediaCodec may also fail before encoding, during configure() or
start(). For example:

ERROR: Exception on thread Thread[main,5,main]
    android.media.MediaCodec$CodecException: Error 0xfffffc0e
        at android.media.MediaCodec.native_configure(Native Method)
        at android.media.MediaCodec.configure(MediaCodec.java:1956)
        at android.media.MediaCodec.configure(MediaCodec.java:1885)
        at com.genymobile.scrcpy.ScreenEncoder.configure(ScreenEncoder.java:158)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:68)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:28)
        at com.genymobile.scrcpy.Server.main(Server.java:110)

Also downscale and retry in these cases.

Refs #2947 <#2947>
Refs #2988 <#2988>
rom1v added a commit that referenced this issue Jan 30, 2022
The new retry mechanism with a lower definition only worked if the error
occurred during encode(). For example:

    java.lang.IllegalStateException
        at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
        at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3452)
        at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:114)
        at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:95)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:61)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:80)
        at com.genymobile.scrcpy.Server.main(Server.java:255)

However, MediaCodec may also fail before encoding, during configure() or
start(). For example:

    android.media.MediaCodec$CodecException: Error 0xfffffc0e
        at android.media.MediaCodec.native_configure(Native Method)
        at android.media.MediaCodec.configure(MediaCodec.java:1956)
        at android.media.MediaCodec.configure(MediaCodec.java:1885)
        at com.genymobile.scrcpy.ScreenEncoder.configure(ScreenEncoder.java:158)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:68)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:28)
        at com.genymobile.scrcpy.Server.main(Server.java:110)

Also downscale and retry in these cases.

Refs #2947 <#2947>
Refs #2988 <#2988>
rom1v added a commit that referenced this issue Jan 30, 2022
The new retry mechanism with a lower definition only worked if the error
occurred during encode(). For example:

    java.lang.IllegalStateException
        at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
        at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3452)
        at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:114)
        at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:95)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:61)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:80)
        at com.genymobile.scrcpy.Server.main(Server.java:255)

However, MediaCodec may also fail before encoding, during configure() or
start(). For example:

    android.media.MediaCodec$CodecException: Error 0xfffffc0e
        at android.media.MediaCodec.native_configure(Native Method)
        at android.media.MediaCodec.configure(MediaCodec.java:1956)
        at android.media.MediaCodec.configure(MediaCodec.java:1885)
        at com.genymobile.scrcpy.ScreenEncoder.configure(ScreenEncoder.java:158)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:68)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:28)
        at com.genymobile.scrcpy.Server.main(Server.java:110)

Also downscale and retry in these cases.

Refs #2947 <#2947>
Refs #2988 <#2988>
rom1v added a commit that referenced this issue Jan 30, 2022
The new retry mechanism with a lower definition only worked if the error
occurred during encode(). For example:

    java.lang.IllegalStateException
        at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
        at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3452)
        at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:114)
        at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:95)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:61)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:80)
        at com.genymobile.scrcpy.Server.main(Server.java:255)

However, MediaCodec may also fail before encoding, during configure() or
start(). For example:

    android.media.MediaCodec$CodecException: Error 0xfffffc0e
        at android.media.MediaCodec.native_configure(Native Method)
        at android.media.MediaCodec.configure(MediaCodec.java:1956)
        at android.media.MediaCodec.configure(MediaCodec.java:1885)
        at com.genymobile.scrcpy.ScreenEncoder.configure(ScreenEncoder.java:158)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:68)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:28)
        at com.genymobile.scrcpy.Server.main(Server.java:110)

Also downscale and retry in these cases.

Refs #2947 <#2947>
Refs #2988 <#2988>
PR #2990 <#2990>
rom1v added a commit that referenced this issue Jan 30, 2022
The new retry mechanism with a lower definition only worked if the error
occurred during encode(). For example:

    java.lang.IllegalStateException
        at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
        at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3452)
        at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:114)
        at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:95)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:61)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:80)
        at com.genymobile.scrcpy.Server.main(Server.java:255)

However, MediaCodec may also fail before encoding, during configure() or
start(). For example:

    android.media.MediaCodec$CodecException: Error 0xfffffc0e
        at android.media.MediaCodec.native_configure(Native Method)
        at android.media.MediaCodec.configure(MediaCodec.java:1956)
        at android.media.MediaCodec.configure(MediaCodec.java:1885)
        at com.genymobile.scrcpy.ScreenEncoder.configure(ScreenEncoder.java:158)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:68)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:28)
        at com.genymobile.scrcpy.Server.main(Server.java:110)

Also downscale and retry in these cases.

Refs #2947 <#2947>
Refs #2988 <#2988>
PR #2990 <#2990>
rom1v added a commit that referenced this issue Feb 2, 2022
The new retry mechanism with a lower definition only worked if the error
occurred during encode(). For example:

    java.lang.IllegalStateException
        at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
        at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3452)
        at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:114)
        at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:95)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:61)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:80)
        at com.genymobile.scrcpy.Server.main(Server.java:255)

However, MediaCodec may also fail before encoding, during configure() or
start(). For example:

    android.media.MediaCodec$CodecException: Error 0xfffffc0e
        at android.media.MediaCodec.native_configure(Native Method)
        at android.media.MediaCodec.configure(MediaCodec.java:1956)
        at android.media.MediaCodec.configure(MediaCodec.java:1885)
        at com.genymobile.scrcpy.ScreenEncoder.configure(ScreenEncoder.java:158)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:68)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:28)
        at com.genymobile.scrcpy.Server.main(Server.java:110)

Also downscale and retry in these cases.

Refs #2947 <#2947>
Refs #2988 <#2988>
PR #2990 <#2990>
@aa755
Copy link

aa755 commented Jun 21, 2023

I was getting the same error. once I started screen recording on android just once and stopped, scrcpy also started working.

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

3 participants