-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
Comments
Does #3862 work for you? |
I get this error too:
|
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) |
@blazeking101 Please test this version and report if this works for you: #3862 (comment) |
@rom1v ,my phone is also honor 70, I have try #3862 version, and i get this: |
@TheTouYu Could you please post your
|
ok! thanks your reply! |
thanks you,here ls:
https://github.com/Genymobile/scrcpy/files/11717450/framework.zip
|
So on current AOSP 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. |
ok, I get! thanks for your work. |
Translates to
I think enabling
Usually the
I'm more worried about these. |
I think that even if we manage to get a more or less valid context, |
I think it will work. 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 |
Oh, great :) Is there a benefit in calling |
I don't know. This code was copied from a StackOverflow answer. I guess the |
Let's try: quick & dirty diffdiff --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:
Please post any stacktrace (the error printed in the console). |
ok,
|
Ah, of course, Let's quick-fix that with this additional diff: diffdiff --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:
|
Oh, so let's try if it works with only that last change without the first one: diffdiff --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:
|
Thanks very much! and This time it report this:
|
OK, the result is as expected 👍 Thank you for the test. I'll work on a proper fix on |
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) |
Arf, passing the system context as base in
(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:
|
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>
Ok, the result: [h@TouYu relang]$ adb shell getprop ro.product.manufacturer
HONOR
[h@TouYu relang]$ adb shell getprop ro.product.brand
HONOR |
@yume-chan Oh, providing a base context might also impact Vivo phones: #3757 (comment) |
So, I worked on a new patch which should fix this issue without breaking #3805: 86e5c90 ( Please test this new binary:
|
sorry, this version still no work (
|
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)? |
sure, I am using it and it still works. |
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>
Just an additional quick test with a single line change (just in case it is sufficient): diffdiff --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
|
congratulations! it‘s ok! ( $ ^^ $ ) |
So it works for Honor devices and also for Vivo devices (#3805 (comment)). Let's merge it: fb21bbf |
Having the same issue with 2.1 on Huawei P Smart 2019 (Android 12, POT LX1). |
@CrimsonFork Please post the whole scrcpy output. |
|
framework.jar: https://www.mediafire.com/file/fd273euyhlib45m/framework.jar/file |
|
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>
Hi, I have the same issue on my Realme phone. Here's the console output:
|
Check the error message:
See https://github.com/Genymobile/scrcpy/blob/master/doc/audio.md |
Sorry for the trouble, audio works when I start scrcpy after unlocking my phone. |
scrcpy 2.3.1 https://github.com/Genymobile/scrcpy Problem with the audio, its not capturing audio via USB ? Help if any one knows , I am using vivo IQOO 9 ( Android 14 Stable ) |
@ursrahuladhikari #4492? Probably already fixed on |
@rom1v Thanks for the help brother 🙏, Yes its fixed and it's working for me 😊 |
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.
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>
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>
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>
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>
With me it was because my default usb connection was MTP mode. Once i set it to charge only mode the problem stopped immediatly |
Environment
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
The text was updated successfully, but these errors were encountered: