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

Failed to start audio capture / Demuxer 'audio': stream explicitly disabled by the device on Android 11 #4147

Closed
2 tasks done
PureIncompetence opened this issue Jul 7, 2023 · 5 comments

Comments

@PureIncompetence
Copy link

PureIncompetence commented Jul 7, 2023

  • I have read the FAQ.

  • I have searched in existing issues.

  • OS: Ubuntu

  • scrcpy version: 2.1

  • installation method: manual build

  • device model: ASUS

  • Android version: 11 (LOS-based Custom ROM)

Sound does not work by default. As I've read in several other issues regarding sound, you bring up the Shell Heap Dump report activity for a short period of time to make android (11) think that scrcpy - which has the same uid - would be running upfront. That does not work on my device (ofc. with the screen on).
If I, however, run adb shell "am start com.android.shell/.HeapDumpActivity" before I run scrcpy, it does work. (The Heap Dump report activity pops up, scrcpy starts, closes it and audio works as expected.) Below I will post the output of what scrcpy logs without the manually started activity:

scrcpy 2.1 <https://github.com/Genymobile/scrcpy>
scrcpy-server-v2.1: 1 file pushed. 1.4 MB/s (56955 bytes in 0.040s)
[server] INFO: Device: [asus] asus ASUS_[redacted] (Android 11)
INFO: Renderer: opengl
INFO: OpenGL version: 4.6 (Compatibility Profile) Mesa 23.1.3
INFO: Trilinear filtering enabled
INFO: Texture: 1080x2336
[server] ERROR: Failed to start audio capture
[server] ERROR: On Android 11, audio capture must be started in the foreground, make sure that the device is unlocked when starting scrcpy.
WARN: Demuxer 'audio': stream explicitly disabled by the device

When searching for similar Issues, I found #3796 which looked a lot like my issue. I therefore tried to apply the same fix which was successfull there: Setting SystemClock.sleep() to a higher value (I tried 500 ms). After that I recompiled the scrcpy-server according to https://github.com/Genymobile/scrcpy/blob/master/doc/build.md#option-1-build-everything-from-sources (which is a real PITA btw, thank you for delivering that one pre-build by default.) and didnt notice any difference. On the other hand I have no experience with java whatsoever so I might have done some mistakes when recompiling.

@rom1v
Copy link
Collaborator

rom1v commented Jul 7, 2023

On dev branch, try with:

diff --git a/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java b/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java
index 7b20cce4f..8b30d6f26 100644
--- a/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java
+++ b/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java
@@ -118,7 +118,7 @@ public final class AudioCapture {
         if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) {
             startWorkaroundAndroid11();
             try {
-                tryStartRecording(3, 100);
+                tryStartRecording(6, 100);
             } finally {
                 stopWorkaroundAndroid11();
             }

and run with scrcpy -Vdebug. What is the result?

@PureIncompetence
Copy link
Author

Thank you for your very fast response.
Turns out I was kind of stupid. I didnt notice any difference after my patch because I replaced the /usr/share/scrcpy/scrcpy-server binary with my self-compiled one. Thanks to the verbose output of scrcpy -Vdebug I noticed and replaced the correct one (/usr/local/share/scrcpy/scrcpy-server) which is actually used by scrcpy.
Now it does work - with my patch (replacing the Variable delayMs with plain 500) as well as with yours (increasing the attempts from 3 to 6). I tried it 5 times, it worked each time. The following output is logged by scrcpy -Vdebug with your patch applied:

scrcpy 2.1 <https://github.com/Genymobile/scrcpy>
DEBUG: ADB device found:
DEBUG:     --> (tcpip)  [redacted]             device  ASUS_[redacted]
DEBUG: Device serial: [redacted]
DEBUG: Using server: /usr/local/share/scrcpy/scrcpy-server
/usr/local/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 160.7 MB/s (56971 bytes in 0.000s)
[server] INFO: Device: [asus] asus ASUS_[redacted] (Android 11)
DEBUG: Server connected
DEBUG: Starting controller thread
DEBUG: Starting receiver thread
[server] DEBUG: Using video encoder: 'OMX.qcom.video.encoder.avc'
[server] DEBUG: Using audio encoder: 'c2.android.opus.encoder'
[server] DEBUG: Failed to start audio capture, retrying...
INFO: Renderer: opengl
INFO: OpenGL version: 4.6 (Compatibility Profile) Mesa 23.1.3
INFO: Trilinear filtering enabled
DEBUG: Using icon: /usr/local/share/icons/hicolor/256x256/apps/scrcpy.png
DEBUG: Demuxer 'video': starting thread
DEBUG: Demuxer 'audio': starting thread
INFO: Texture: 1080x2336
[server] DEBUG: Failed to start audio capture, retrying...
[server] DEBUG: Failed to start audio capture, retrying...
DEBUG: [Audio] Buffer underflow, inserting silence: 21 samples
DEBUG: [Audio] Buffer underflow, inserting silence: 240 samples
DEBUG: [Audio] Buffer underflow, inserting silence: 240 samples
DEBUG: [Audio] Buffer underflow, inserting silence: 7 samples

@rom1v
Copy link
Collaborator

rom1v commented Jul 7, 2023

OK, so I will change from 3 to 5 attempts (so the last one is after ~500ms). Thank you for your report.

@PureIncompetence
Copy link
Author

Happy if I can contribute. Thank you for colaborating and finding the cause / fix in no time.

rom1v added a commit that referenced this issue Jul 7, 2023
Making the shell app foreground (specific for Android 11) may take more
than 300ms on some devices, so increase the number of attempts from 3 to
5 (separated by 100ms).

Fixes #4147 <#4147>
Refs #3796 <#3796>
Refs 02f4ff7
@rom1v
Copy link
Collaborator

rom1v commented Jul 7, 2023

Merged into dev: 01d785d

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