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

Demuxer 'audio': stream explicitly disabled by the device #4015

Closed
2 tasks done
blazeking101 opened this issue May 18, 2023 · 54 comments
Closed
2 tasks done

Demuxer 'audio': stream explicitly disabled by the device #4015

blazeking101 opened this issue May 18, 2023 · 54 comments

Comments

@blazeking101
Copy link

blazeking101 commented May 18, 2023

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

Environment

  • OS: [Window 10.]
  • scrcpy version: [2.0]
  • installation method: [Window 64-bit]
  • device model:Honor 70
  • Android version: [12]

Describe the bug
the audio forwarding doesn't work with my device I tried looking into solutions for this issue but I cannot find a solution to it

[server] INFO: Device: HONOR FNE-NX9 (Android 12)
[server] ERROR: Exception on thread Thread[Thread-4,5,main]
java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:220)
at android.media.AudioRecord.startRecording(AudioRecord.java:1326)
at com.genymobile.scrcpy.AudioCapture.start(AudioCapture.java:91)
at com.genymobile.scrcpy.AudioEncoder.encode(AudioEncoder.java:183)
at com.genymobile.scrcpy.AudioEncoder.lambda$start$0$com-genymobile-scrcpy-AudioEncoder(AudioEncoder.java:120)
at com.genymobile.scrcpy.AudioEncoder$$ExternalSyntheticLambda0.run(Unknown Source:2)
at java.lang.Thread.run(Thread.java:1012)
INFO: Renderer: direct3d
WARN: Demuxer 'audio': stream explicitly disabled by the device
INFO: Initial texture: 1080x2400

@rom1v
Copy link
Collaborator

rom1v commented May 18, 2023

Does #3862 work for you?

@rahaaatul
Copy link

I get this error too:

[server] INFO: Device: vivo V2043 (Android 11)
INFO: Renderer: direct3d
INFO: Initial texture: 720x1600
WARN: Demuxer 'audio': stream explicitly disabled by the device
[server] ERROR: Exception on thread Thread[Thread-4,5,main]
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
        at android.content.ContextWrapper.getPackageManager(ContextWrapper.java:102)
        at android.content.ContextWrapper.getPackageManager(ContextWrapper.java:102)
        at android.media.VivoAudioRecordImpl.getSignatures(VivoAudioRecordImpl.java:100)
        at android.media.VivoAudioRecordImpl.getSignInfo(VivoAudioRecordImpl.java:68)
        at android.media.VivoAudioRecordImpl.isSupportSubMixRecording(VivoAudioRecordImpl.java:133)
        at android.media.AudioRecord.<init>(AudioRecord.java:433)
        at android.media.AudioRecord$Builder.build(AudioRecord.java:798)
        at com.genymobile.scrcpy.AudioCapture.createAudioRecord(AudioCapture.java:58)
        at com.genymobile.scrcpy.AudioCapture.start(AudioCapture.java:90)
        at com.genymobile.scrcpy.AudioEncoder.encode(AudioEncoder.java:183)
        at com.genymobile.scrcpy.AudioEncoder.lambda$start$0$com-genymobile-scrcpy-AudioEncoder(AudioEncoder.java:120)
        at com.genymobile.scrcpy.AudioEncoder$$ExternalSyntheticLambda0.run(Unknown Source:2)
        at java.lang.Thread.run(Thread.java:923)

@blazeking101
Copy link
Author

blazeking101 commented Jun 8, 2023

sorry for the very late response, i couldn't really understand what was i supposed to do in the blog could you explain to me on what to do? (my honor phone is not andriod 13 and yet it doesn't work)

@rom1v
Copy link
Collaborator

rom1v commented Jun 8, 2023

@blazeking101 Please test this version and report if this works for you: #3862 (comment)

@TheTouYu
Copy link

@rom1v ,my phone is also honor 70, I have try #3862 version, and i get this:
scrcpy 2.0 https://github.com/Genymobile/scrcpy
C:\Users\Q520x\Downloads\scrcpy-win64-vivo...skipped. 60.8 MB/s (56403 bytes in 0.001s)
[server] INFO: Device: HONOR FNE-AN00 (Android 12)
[server] ERROR: Exception on thread Thread[Thread-4,5,main]
java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:220)
at android.media.AudioRecord.startRecording(AudioRecord.java:1326)
at com.genymobile.scrcpy.AudioCapture.startRecording(AudioCapture.java:110)
at com.genymobile.scrcpy.AudioCapture.start(AudioCapture.java:122)
at com.genymobile.scrcpy.AudioEncoder.encode(AudioEncoder.java:192)
at com.genymobile.scrcpy.AudioEncoder.lambda$start$0$com-genymobile-scrcpy-AudioEncoder(AudioEncoder.java:122)
at com.genymobile.scrcpy.AudioEncoder$$ExternalSyntheticLambda0.run(Unknown Source:4)
at java.lang.Thread.run(Thread.java:930)
INFO: Renderer: direct3d
WARN: Demuxer 'audio': stream explicitly disabled by the device
INFO: Texture: 1080x2400
WARN: Killing the server...

@rom1v
Copy link
Collaborator

rom1v commented Jun 11, 2023

@TheTouYu Could you please post your framework.jar?

adb pull /system/framework/framework.jar

@TheTouYu
Copy link

ok! thanks your reply!
framework.zip

@TheTouYu
Copy link

TheTouYu commented Jun 12, 2023 via email

@rom1v
Copy link
Collaborator

rom1v commented Jun 12, 2023

So on current AOSP master, the implementation of AudioRecord.startRecording() is:

    public void startRecording()
    throws IllegalStateException {
        if (mState != STATE_INITIALIZED) {
            throw new IllegalStateException("startRecording() called on an "
                    + "uninitialized AudioRecord.");
        }

        // start recording
        synchronized(mRecordingStateLock) {
            if (native_start(MediaSyncEvent.SYNC_EVENT_NONE, 0) == SUCCESS) {
                handleFullVolumeRec(true);
                mRecordingState = RECORDSTATE_RECORDING;
            }
        }
    }

On your device, the code has been modified by the vendor:

    public void startRecording() throws IllegalStateException {
        if (this.mRecordSource != 5) {
            try {
                Context context = ActivityThread.currentApplication();
                Objects.requireNonNull(context);
                String appName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.loadLabel(context.getPackageManager()).toString();
                String action = this.mRecordSource == 4 ? "开启通话录音" : "本地录音";
                HwFrameworkFactory.getHiLog().authPrintf(3, 218114827, TAG, appName, "android.audiorecord", ActivityThread.currentPackageName(), "AudioRecord.startRecording", action, new Object[0]);
            } catch (PackageManager.NameNotFoundException e) {
                Log.e(TAG, "appName not found");
            }
        }
        if (this.mState != 1) {
            throw new IllegalStateException("startRecording() called on an uninitialized AudioRecord.");
        }
        if (HwDeviceManager.disallowOp(30)) {
            HnMediaFactory.getHnAudioRecord().showDisableMicrophoneToast();
            throw new IllegalStateException("microphone has been disabled.");
        }
        synchronized (this.mRecordingStateLock) {
            if (native_start(0, 0) == 0) {
                handleFullVolumeRec(true);
                this.mRecordingState = 3;
                HwAudioServiceManager.checkRecordActive(this.mRecordSource);
                HwAudioServiceManager.sendRecordStateChangedIntent(this.mRecordingState);
            } else {
                HwAudioServiceManager.sendRecordStateChangedIntent(-1);
            }
        }
    }

It attempts to get information about the application package 😕 Scrcpy could not be run as an application (otherwise it would not get shell permissions), so it fails. For now, I don't see any solution to bypass this piece of code and make it work on your device.

@TheTouYu
Copy link

ok, I get! thanks for your work.

@yume-chan
Copy link
Contributor

yume-chan commented Jun 16, 2023

String action = this.mRecordSource == 4 ? "开启通话录音" : "本地录音";

Translates to

String action = this.mRecordSource == 4 ? "Turn on call recording" : "local recording";

Context context = ActivityThread.currentApplication();

I think enabling currentApplication patching will conflict with Nvidia Shield devices? #3801

context.getPackageManager()

ActivityThread.getSystemContext() returns a Context that getPackageManager can be invoked on. Use that Context for base of FakeContext should pass this line. (found when investigating #1887 (comment))

Usually the getSystemContext method is called like Context context = ActivityThread.systemMain().getSystemContext();, not sure if any ActivityThread (for example the one Scrcpy created) will work.

if (HwDeviceManager.disallowOp(30))
HwAudioServiceManager.checkRecordActive(this.mRecordSource);
HwAudioServiceManager.sendRecordStateChangedIntent(this.mRecordingState);

I'm more worried about these.

@rom1v
Copy link
Collaborator

rom1v commented Jun 16, 2023

I think that even if we manage to get a more or less valid context, context.getPackageManager().getPackageInfo(…) will return null or throw an exception anyway.

@yume-chan
Copy link
Contributor

I think it will work. ActivityThread.currentApplication().getPackageName() delegates to FakeContext.getPackageName() which returns "com.android.shell", and it's a real system app on Android.

I tried this minimal code:

Looper.prepareMainLooper();

@SuppressLint("PrivateApi") var activityThreadClass = Class.forName("android.app.ActivityThread");
@SuppressLint("DiscouragedPrivateApi") var systemMainMethod = activityThreadClass.getDeclaredMethod("systemMain");
var systemMain = systemMainMethod.invoke(null);
Objects.requireNonNull(systemMain);

var getSystemContextMethod = systemMain.getClass().getDeclaredMethod("getSystemContext");
var systemContext = (Context) getSystemContextMethod.invoke(systemMain);
Objects.requireNonNull(systemContext);

var packageManager = systemContext.getPackageManager();
var packageInfo = packageManager.getPackageInfo("com.android.shell", 0);
System.out.println(packageInfo.applicationInfo.loadLabel(packageManager));

It prints Shell.

@rom1v
Copy link
Collaborator

rom1v commented Jun 16, 2023

Oh, great :)

Is there a benefit in calling ActivityThread.systemMain() rather than just new ActivityThread() (like scrcpy does in fillActivityThread())

@yume-chan
Copy link
Contributor

I don't know. This code was copied from a StackOverflow answer. I guess the ActivityThread created by Scrcpy will also work, systemMain is the simplest method to get an ActivityThread.

@rom1v
Copy link
Collaborator

rom1v commented Jun 16, 2023

ActivityThread.getSystemContext() returns a Context that getPackageManager can be invoked on. Use that Context for base of FakeContext should pass this line. (found when investigating #1887 (comment))

Let's try:

quick & dirty diff
diff --git a/server/src/main/java/com/genymobile/scrcpy/FakeContext.java b/server/src/main/java/com/genymobile/scrcpy/FakeContext.java
index 738203ded..0b3fedbda 100644
--- a/server/src/main/java/com/genymobile/scrcpy/FakeContext.java
+++ b/server/src/main/java/com/genymobile/scrcpy/FakeContext.java
@@ -2,10 +2,14 @@ package com.genymobile.scrcpy;
 
 import android.annotation.TargetApi;
 import android.content.AttributionSource;
+import android.content.Context;
 import android.content.ContextWrapper;
 import android.os.Build;
 import android.os.Process;
 
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
 public final class FakeContext extends ContextWrapper {
 
     public static final String PACKAGE_NAME = "com.android.shell";
@@ -13,12 +17,27 @@ public final class FakeContext extends ContextWrapper {
 
     private static final FakeContext INSTANCE = new FakeContext();
 
+    private static Context retrieveSystemContext() {
+        try {
+            Class<?> activityThreadClass = Class.forName("android.app.ActivityThread");
+            Constructor<?> activityThreadConstructor = activityThreadClass.getDeclaredConstructor();
+            activityThreadConstructor.setAccessible(true);
+            Object activityThread = activityThreadConstructor.newInstance();
+
+            Method getSystemContextMethod = activityThread.getClass().getDeclaredMethod("getSystemContext");
+            return (Context) getSystemContextMethod.invoke(activityThread);
+        } catch (Exception e) {
+            Ln.e("Cannot retrieve system context", e);
+            return null;
+        }
+    }
+
     public static FakeContext get() {
         return INSTANCE;
     }
 
     private FakeContext() {
-        super(null);
+        super(retrieveSystemContext());
     }
 
     @Override

@TheTouYu Please replace this binary in your scrcpy v2.0 folder and test again:

  • scrcpy-server SHA-256: 70eb70c2256f54cf93657b1272974ee952a1b6aae91cffd68cd38b95d317bdb5

Please post any stacktrace (the error printed in the console).

@TheTouYu
Copy link

TheTouYu commented Jun 16, 2023

ok,

C:\Users\Q520x\Downloads\scrcpy-win64-v2.0\scrcpy-win64-v2.0>scrcpy.exe --tcpip=192.168.123.11
scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
INFO: Connecting to 192.168.123.11:5555...
INFO: Connected to 192.168.123.11:5555
C:\Users\Q520x\Downloads\scrcpy-win64-v2.0\scrcpy-win64-v2...1 file pushed, 0 skipped. 9.5 MB/s (95226 bytes in 0.010s)
[server] INFO: Device: HONOR FNE-AN00 (Android 12)
[server] ERROR: Exception on thread Thread[Thread-4,5,main]
java.lang.NullPointerException
        at java.util.Objects.requireNonNull(Objects.java:220)
        at android.media.AudioRecord.startRecording(AudioRecord.java:1326)
        at com.genymobile.scrcpy.AudioCapture.start(AudioCapture.java:91)
        at com.genymobile.scrcpy.AudioEncoder.encode(AudioEncoder.java:183)
        at com.genymobile.scrcpy.AudioEncoder.lambda$start$0$com-genymobile-scrcpy-AudioEncoder(AudioEncoder.java:120)
        at com.genymobile.scrcpy.AudioEncoder$$ExternalSyntheticLambda0.run(Unknown Source:2)
        at java.lang.Thread.run(Thread.java:930)
INFO: Renderer: direct3d
WARN: Demuxer 'audio': stream explicitly disabled by the device
INFO: Initial texture: 2400x1080

@rom1v
Copy link
Collaborator

rom1v commented Jun 16, 2023

Ah, of course, ActivityThread.currentApplication() still returns null.

Let's quick-fix that with this additional diff:

diff
diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java
index 5800487da..fc8fb088f 100644
--- a/server/src/main/java/com/genymobile/scrcpy/Server.java
+++ b/server/src/main/java/com/genymobile/scrcpy/Server.java
@@ -81,7 +81,7 @@ public final class Server {
         // But only apply when strictly necessary, since workarounds can cause other issues:
         //  - <https://github.com/Genymobile/scrcpy/issues/940>
         //  - <https://github.com/Genymobile/scrcpy/issues/994>
-        boolean mustFillAppInfo = Build.BRAND.equalsIgnoreCase("meizu");
+        boolean mustFillAppInfo = true;
 
         // Before Android 11, audio is not supported.
         // Since Android 12, we can properly set a context on the AudioRecord.

Here is a new binary:

  • scrcpy-server SHA-256: c5f182a63be88fc392165181546ec99495cc5ded5f631ab3df809cd153d31679

@TheTouYu
Copy link

amazing! it works now
image

@rom1v
Copy link
Collaborator

rom1v commented Jun 16, 2023

Oh, so let's try if it works with only that last change without the first one:

diff
diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java
index 5800487da..fc8fb088f 100644
--- a/server/src/main/java/com/genymobile/scrcpy/Server.java
+++ b/server/src/main/java/com/genymobile/scrcpy/Server.java
@@ -81,7 +81,7 @@ public final class Server {
         // But only apply when strictly necessary, since workarounds can cause other issues:
         //  - <https://github.com/Genymobile/scrcpy/issues/940>
         //  - <https://github.com/Genymobile/scrcpy/issues/994>
-        boolean mustFillAppInfo = Build.BRAND.equalsIgnoreCase("meizu");
+        boolean mustFillAppInfo = true;
 
         // Before Android 11, audio is not supported.
         // Since Android 12, we can properly set a context on the AudioRecord.

Please test this new binary:

  • scrcpy-server SHA-256: 4345ce30da5d12663281abeb93210a48039065eb948f6c1c375be551c85bd2a4

@TheTouYu
Copy link

TheTouYu commented Jun 16, 2023

Thanks very much! and This time it report this:

C:\Users\Q520x\Downloads\scrcpy-win64-v2.0\scrcpy-win64-v2.0>scrcpy.exe -e
scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
C:\Users\Q520x\Downloads\scrcpy-win64-v2.0\scrcpy-win64-v2...file pushed, 0 skipped. 129.6 MB/s (95226 bytes in 0.001s)
[server] INFO: Device: HONOR FNE-AN00 (Android 12)
[server] ERROR: Exception on thread Thread[Thread-4,5,main]
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
        at android.content.ContextWrapper.getPackageManager(ContextWrapper.java:105)
        at android.content.ContextWrapper.getPackageManager(ContextWrapper.java:105)
        at android.media.AudioRecord.startRecording(AudioRecord.java:1327)
        at com.genymobile.scrcpy.AudioCapture.start(AudioCapture.java:91)
        at com.genymobile.scrcpy.AudioEncoder.encode(AudioEncoder.java:183)
        at com.genymobile.scrcpy.AudioEncoder.lambda$start$0$com-genymobile-scrcpy-AudioEncoder(AudioEncoder.java:120)
        at com.genymobile.scrcpy.AudioEncoder$$ExternalSyntheticLambda0.run(Unknown Source:2)
        at java.lang.Thread.run(Thread.java:930)
INFO: Renderer: direct3d
WARN: Demuxer 'audio': stream explicitly disabled by the device
INFO: Initial texture: 2400x1080

@rom1v
Copy link
Collaborator

rom1v commented Jun 16, 2023

OK, the result is as expected 👍 Thank you for the test.

I'll work on a proper fix on dev branch (maybe this evening) and I'll provide a new binary to test before merging. It will be included in scrcpy v2.1.

@TheTouYu
Copy link

Aha, this is what i should do, and I'm very happy, It also made the process of my first bug report enjoyable. Dalao, I am extremly grateful for the effort you had done for a better sortware user experience! (my English is poor , sorry for that)

@rom1v
Copy link
Collaborator

rom1v commented Jun 16, 2023

Arf, passing the system context as base in FakeContext causes #994 on Xiaomi devices:

java.io.FileNotFoundException: /data/system/theme_config/theme_compatibility.xml: open failed: ENOENT (No such file or directory)
	at libcore.io.IoBridge.open(IoBridge.java:492)
	at java.io.FileInputStream.<init>(FileInputStream.java:160)
	at java.io.FileInputStream.<init>(FileInputStream.java:115)
	at java.io.FileReader.<init>(FileReader.java:58)
	at miui.content.res.ThemeCompatibilityLoader.getVersion(ThemeCompatibilityLoader.java:108)
	at miui.content.res.ThemeCompatibilityLoader.getConfigDocumentTree(ThemeCompatibilityLoader.java:126)
	at miui.content.res.ThemeCompatibilityLoader.loadConfig(ThemeCompatibilityLoader.java:59)
	at miui.content.res.ThemeCompatibility.<clinit>(ThemeCompatibility.java:31)
	at miui.content.res.ThemeCompatibility.isThemeEnabled(ThemeCompatibility.java:111)
	at android.content.res.MiuiResourcesImpl.<clinit>(MiuiResourcesImpl.java:41)
	at android.content.res.Resources.<init>(Resources.java:353)
	at android.content.res.MiuiResources.<init>(MiuiResources.java:49)
	at android.content.res.Resources.getSystem(Resources.java:233)
	at android.app.LoadedApk.<init>(LoadedApk.java:239)
	at android.app.ContextImpl.createSystemContext(ContextImpl.java:2625)
	at android.app.ActivityThread.getSystemContext(ActivityThread.java:2533)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.genymobile.scrcpy.FakeContext.retrieveSystemContext(FakeContext.java:27)
	at com.genymobile.scrcpy.FakeContext.<init>(FakeContext.java:39)
	at com.genymobile.scrcpy.FakeContext.<clinit>(FakeContext.java:19)
	at com.genymobile.scrcpy.FakeContext.get(FakeContext.java:35)
	at com.genymobile.scrcpy.Workarounds.fillAppContext(Workarounds.java:99)
	at com.genymobile.scrcpy.Server.scrcpy(Server.java:120)
	at com.genymobile.scrcpy.Server.main(Server.java:218)
	at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
	at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:407)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
	at libcore.io.Linux.open(Native Method)
	at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
	at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
	at libcore.io.IoBridge.open(IoBridge.java:478)
	... 25 more

(That's just a log in the system code, nothing is thrown.)

Maybe I should pass it only if the manufacturer is not Xiaomi 😕

@TheTouYu By the way, could you post the result of:

adb shell getprop ro.product.manufacturer
adb shell getprop ro.product.brand

rom1v added a commit that referenced this issue Jun 16, 2023
DONOTMERGE: it causes #994 on Xiaomi devices

This allows to make Context.getPackageManager() work.

Fixes #4015 <#4015>
Refs <#4015 (comment)>

Co-authored-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
rom1v added a commit that referenced this issue Jun 16, 2023
This makes audio work on those devices.

Fixes #4015 <#4015>
@TheTouYu
Copy link

TheTouYu commented Jun 17, 2023

Ok, the result:

[h@TouYu relang]$ adb shell getprop ro.product.manufacturer
HONOR
[h@TouYu relang]$ adb shell getprop ro.product.brand
HONOR

@rom1v
Copy link
Collaborator

rom1v commented Jun 17, 2023

@yume-chan Oh, providing a base context might also impact Vivo phones: #3757 (comment)

@rom1v
Copy link
Collaborator

rom1v commented Jun 18, 2023

So, I worked on a new patch which should fix this issue without breaking #3805: 86e5c90 (honor branch).

Please test this new binary:

@TheTouYu
Copy link

TheTouYu commented Jun 19, 2023

sorry, this version still no work (^)

C:\Users\Q520x\Downloads\scrcpy-win64-honor_5\scrcpy-win64-v2.0-94-g1c2d4b18b>scrcpy.exe -e
scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
C:\Users\Q520x\Downloads\scrcpy-win64-honor_5\scrcpy-win64...file pushed, 0 skipped. 196.8 MB/s (56927 bytes in 0.000s)
[server] INFO: Device: [HONOR] HONOR FNE-AN00 (Android 12)
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: start failed
[server] INFO: newMaxSize = 1920
[server] INFO: Retrying with -m1920...
[server] INFO: Retrying...
INFO: Renderer: direct3d
INFO: Texture: 2400x1080
[server] INFO: newMaxSize = 1600
[server] INFO: Retrying with -m1600...
[server] INFO: Retrying...
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: start failed
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: start failed
[server] INFO: newMaxSize = 1280
[server] INFO: Retrying with -m1280...
[server] INFO: Retrying...
[server] WARN: Could not get any audio timestamp
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: start failed
[server] INFO: newMaxSize = 1024
[server] INFO: Retrying with -m1024...
[server] INFO: Retrying...
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: start failed
[server] INFO: newMaxSize = 800
[server] INFO: Retrying with -m800...
[server] INFO: Retrying...
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: start failed
[server] INFO: newMaxSize = 0
[server] ERROR: Exception on thread Thread[video,5,main]
android.media.MediaCodec$CodecException: start failed
        at android.media.MediaCodec.native_start(Native Method)
        at android.media.MediaCodec.start(MediaCodec.java:2289)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:102)
        at com.genymobile.scrcpy.ScreenEncoder.lambda$start$0$com-genymobile-scrcpy-ScreenEncoder(ScreenEncoder.java:290)
        at com.genymobile.scrcpy.ScreenEncoder$$ExternalSyntheticLambda0.run(Unknown Source:4)
        at java.lang.Thread.run(Thread.java:930)

@rom1v
Copy link
Collaborator

rom1v commented Jun 19, 2023

Ok, I will need more time then (maybe this evening or tomorrow) :/

Could you just confirm that #4015 (comment) still works (if you replace the binary in your v2.0 release)?

@TheTouYu
Copy link

sure, I am using it and it still works.

rom1v added a commit that referenced this issue Jun 19, 2023
Audio did not work on Honor devices.

To make it work, a system context must be set as a base context of
FakeContext (so that a PackageManager is available), and a current
Application must be initialized.

These workarounds must not be applied for all devices, because they
might cause other issues.

Fixes #4015 <#4015>
Refs #3085 <#3805>

Co-authored-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
@rom1v
Copy link
Collaborator

rom1v commented Jun 19, 2023

Just an additional quick test with a single line change (just in case it is sufficient):

diff
diff --git a/server/src/main/java/com/genymobile/scrcpy/Workarounds.java b/server/src/main/java/com/genymobile/scrcpy/Workarounds.java
index e0b312749..8735ddfbb 100644
--- a/server/src/main/java/com/genymobile/scrcpy/Workarounds.java
+++ b/server/src/main/java/com/genymobile/scrcpy/Workarounds.java
@@ -52,6 +52,7 @@ public final class Workarounds {
             // The system context must not be set for all devices, because it would cause other problems:
             //  - <https://github.com/Genymobile/scrcpy/issues/4015#issuecomment-1595382142>
             //  - <https://github.com/Genymobile/scrcpy/issues/3805#issuecomment-1596148031>
+            mustFillAppInfo = true;
             mustFillBaseContext = true;
             mustFillAppContext = true;
         }

(9f9b852 branch honor.6)

@TheTouYu
Copy link

congratulations! it‘s ok! ( $ ^^ $ )

@rom1v
Copy link
Collaborator

rom1v commented Jun 19, 2023

So it works for Honor devices and also for Vivo devices (#3805 (comment)). Let's merge it: fb21bbf

@rom1v rom1v closed this as completed in fb21bbf Jun 21, 2023
@CrimsonFork
Copy link

Having the same issue with 2.1 on Huawei P Smart 2019 (Android 12, POT LX1).

@rom1v
Copy link
Collaborator

rom1v commented Jun 23, 2023

@CrimsonFork Please post the whole scrcpy output.

@CrimsonFork
Copy link

$ scrcpy
scrcpy 2.1 <https://github.com/Genymobile/scrcpy>
/usr/local/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 1.2 MB/s (56955 bytes in 0.044s)
[server] INFO: Device: [HUAWEI] HUAWEI POT-LX1 (Android 10)
[server] WARN: Audio disabled: it is not supported before Android 11
INFO: Renderer: opengl
INFO: OpenGL version: 4.6 (Compatibility Profile) Mesa 23.0.2
INFO: Trilinear filtering enabled
WARN: Demuxer 'audio': stream explicitly disabled by the device
INFO: Texture: 1080x2336
[server] INFO: newMaxSize = 1920
[server] INFO: Retrying with -m1920...
[server] INFO: Retrying...
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: Error 0xfffffc0e
INFO: Texture: 888x1920

Ah, whoops, turns out EMUI12 is Android 10. Obviously.

@optimus0701
Copy link

optimus0701 commented Jul 31, 2023

[server] INFO: Device: [Xiaomi] lge LG-US998 (Android 11)
INFO: Renderer: direct3d
WA[server] ERROR: Could not create default audio encoder for opus
List of audio encoders:
    --audio-codec=aac --audio-encoder='OMX.google.aac.encoder'
RN: Demuxer 'audio': stream explicitly disabled by the device
INFO: Texture: 1440x2880
[server] ERROR: Exception on thread Thread[audio-encoder,5,main]
java.lang.IllegalArgumentException: Failed to initialize audio/opus, error 0xfffffffe
        at android.media.MediaCodec.native_setup(Native Method)
        at android.media.MediaCodec.<init>(Unknown Source:121)
        at android.media.MediaCodec.createEncoderByType(Unknown Source:3)
        at com.genymobile.scrcpy.AudioEncoder.createMediaCodec(AudioEncoder.java:292)
        at com.genymobile.scrcpy.AudioEncoder.encode(AudioEncoder.java:184)
        at com.genymobile.scrcpy.AudioEncoder.lambda$start$0$com-genymobile-scrcpy-AudioEncoder(AudioEncoder.java:124)
        at com.genymobile.scrcpy.AudioEncoder$$ExternalSyntheticLambda0.run(Unknown Source:4)
        at java.lang.Thread.run(Thread.java:923)

framework.jar: https://www.mediafire.com/file/fd273euyhlib45m/framework.jar/file

@yume-chan
Copy link
Contributor

[server] ERROR: Could not create default audio encoder for opus
List of audio encoders:
--audio-codec=aac --audio-encoder='OMX.google.aac.encoder'

#4110

rom1v added a commit that referenced this issue Nov 3, 2023
FakeContext used ActivityThread.getSystemContext() as base context only
in some cases, because it caused problems on some devices:
 - warnings on Xiaomi devices [1], which are now fixed by
   b8c5853
 - issues related to Looper [2], which are solved by just calling
   Looper.prepare*()

Therefore, we can now always assign a base context, which simplifies and
helps to solve camera issues on some devices (#4392).

[1] <#4015 (comment)>
[2] <#3805 (comment)>

Fixes #4392 <#4392>
@jincy-p-janardhanan
Copy link

Hi, I have the same issue on my Realme phone. Here's the console output:

scrcpy 2.3.1 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     -->   (usb)              d56f859f            device  RMX2103
E:\Downloads\scrcpy-win64-v2.3.1\scrcpy-win64-v2.3.1\scrcp... file pushed, 0 skipped. 67.3 MB/s (66007 bytes in 0.001s)
[server] INFO: Device: [realme] realme RMX2103 (Android 11)
INFO: Renderer: direct3d
INFO: Texture: 720x1600
[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

@rom1v
Copy link
Collaborator

rom1v commented Jan 23, 2024

Check the error message:

On Android 11, audio capture must be started in the foreground, make sure that the device is unlocked when starting scrcpy.

See https://github.com/Genymobile/scrcpy/blob/master/doc/audio.md

@jincy-p-janardhanan
Copy link

Sorry for the trouble, audio works when I start scrcpy after unlocking my phone.

@ursrahuladhikari
Copy link

scrcpy 2.3.1 https://github.com/Genymobile/scrcpy
INFO: ADB device found:
INFO: --> (usb) 137742376400071 device I2017
C:\Users\rahul\Desktop\For YT content & Stream\Stream\scrc... file pushed, 0 skipped. 16.0 MB/s (66007 bytes in 0.004s)
[server] INFO: Device: [vivo] iQOO I2017 (Android 14)
INFO: Renderer: direct3d
INFO: Texture: 1080x2376
WA[server] ERROR: Failed to invoke AudioRecord..
java.lang.NoSuchMethodException: android.media.AudioRecord.native_setup [class java.lang.Object, class java.lang.Object, class [I, int, int, int, int, class [I, class android.os.Parcel, long, int]
at java.lang.Class.getMethod(Class.java:2937)
at java.lang.Class.getDeclaredMethod(Class.java:2914)
at com.genymobile.scrcpy.Workarounds.createAudioRecord(Workarounds.java:293)
at com.genymobile.scrcpy.AudioCapture.startRecording(AudioCapture.java:116)
at com.genymobile.scrcpy.AudioCapture.start(AudioCapture.java:130)
at com.genymobile.scrcpy.AudioEncoder.encode(AudioEncoder.java:190)
at com.genymobile.scrcpy.AudioEncoder.lambda$start$0$com-genymobile-scrcpy-AudioEncoder(AudioEncoder.java:121)
at com.genymobile.scrcpy.AudioEncoder$$ExternalSyntheticLambda1.run(Unknown Source:4)
at java.lang.Thread.run(Thread.java:1012)
RN: Demuxer 'audio': stream explicitly disabled by the device
[server] ERROR: Exception on thread Thread[audio-encoder,5,main]
java.lang.RuntimeException: Cannot create AudioRecord
at com.genymobile.scrcpy.Workarounds.createAudioRecord(Workarounds.java:324)
at com.genymobile.scrcpy.AudioCapture.startRecording(AudioCapture.java:116)
at com.genymobile.scrcpy.AudioCapture.start(AudioCapture.java:130)
at com.genymobile.scrcpy.AudioEncoder.encode(AudioEncoder.java:190)
at com.genymobile.scrcpy.AudioEncoder.lambda$start$0$com-genymobile-scrcpy-AudioEncoder(AudioEncoder.java:121)
at com.genymobile.scrcpy.AudioEncoder$$ExternalSyntheticLambda1.run(Unknown Source:4)
at java.lang.Thread.run(Thread.java:1012)

Problem with the audio, its not capturing audio via USB ? Help if any one knows , I am using vivo IQOO 9 ( Android 14 Stable )

@rom1v
Copy link
Collaborator

rom1v commented Feb 9, 2024

@ursrahuladhikari #4492? Probably already fixed on dev branch.

@ursrahuladhikari
Copy link

@rom1v Thanks for the help brother 🙏, Yes its fixed and it's working for me 😊

rom1v added a commit that referenced this issue Jul 30, 2024
Workarounds were disabled by default, and enabled only on some device or
in specific conditions.

But it seems they are needed for more and more devices, so enable them
by default. They could be disabled for specific devices if necessary.

--- Cases where workarounds caused issues:
 - <#940>:
   To be tested
 - <#3805 (comment)>:
   To be tested
 - <#4015 (comment)>:
   This is not a problem anymore since commit
   b8c5853.
rom1v added a commit that referenced this issue Jul 31, 2024
Workarounds were disabled by default, and enabled only on some device or
in specific conditions.

But it seems they are needed for more and more devices, so enable them
by default. They could be disabled for specific devices if necessary in
the future.

In the past, these workarounds caused a (harmless) exception to be
printed on some Xiaomi devices [1]. But this is not a problem anymore
since commit b8c5853.

They also caused problems for audio on Vivo devices [2], but it seems
this is not the case anymore [3].

They might also impact an old Nvidia Shield [4], but hopefully this is
fixed now.

[1]: <#4015 (comment)>
[2]: <#3805 (comment)>
[3]: <#3805 (comment)>
[4]: <#940>

PR #5154 <#5154>
rom1v added a commit that referenced this issue Aug 1, 2024
Workarounds were disabled by default, and only enabled for some devices
or under specific conditions.

But it seems they are needed for more and more devices, so enable them
by default. They could be disabled for specific devices if necessary in
the future.

In the past, these workarounds caused a (harmless) exception to be
printed on some Xiaomi devices [1]. But this is not a problem anymore
since commit b8c5853.

They also caused problems for audio on Vivo devices [2], but it seems
this is not the case anymore [3].

They might also impact an old Nvidia Shield [4], but hopefully this is
fixed now.

[1]: <#4015 (comment)>
[2]: <#3805 (comment)>
[3]: <#3805 (comment)>
[4]: <#940>

PR #5154 <#5154>
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this issue Aug 2, 2024
Workarounds were disabled by default, and only enabled for some devices
or under specific conditions.

But it seems they are needed for more and more devices, so enable them
by default. They could be disabled for specific devices if necessary in
the future.

In the past, these workarounds caused a (harmless) exception to be
printed on some Xiaomi devices [1]. But this is not a problem anymore
since commit b8c5853.

They also caused problems for audio on Vivo devices [2], but it seems
this is not the case anymore [3].

They might also impact an old Nvidia Shield [4], but hopefully this is
fixed now.

[1]: <Genymobile#4015 (comment)>
[2]: <Genymobile#3805 (comment)>
[3]: <Genymobile#3805 (comment)>
[4]: <Genymobile#940>

PR Genymobile#5154 <Genymobile#5154>
Gottox pushed a commit to Gottox/scrcpy that referenced this issue Sep 29, 2024
Workarounds were disabled by default, and only enabled for some devices
or under specific conditions.

But it seems they are needed for more and more devices, so enable them
by default. They could be disabled for specific devices if necessary in
the future.

In the past, these workarounds caused a (harmless) exception to be
printed on some Xiaomi devices [1]. But this is not a problem anymore
since commit b8c5853.

They also caused problems for audio on Vivo devices [2], but it seems
this is not the case anymore [3].

They might also impact an old Nvidia Shield [4], but hopefully this is
fixed now.

[1]: <Genymobile#4015 (comment)>
[2]: <Genymobile#3805 (comment)>
[3]: <Genymobile#3805 (comment)>
[4]: <Genymobile#940>

PR Genymobile#5154 <Genymobile#5154>
@Barryksch
Copy link

With me it was because my default usb connection was MTP mode. Once i set it to charge only mode the problem stopped immediatly

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

10 participants