Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
105.54k stars 10.24k forks source link

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

Closed blazeking101 closed 1 year ago

blazeking101 commented 1 year ago

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

rom1v commented 1 year ago

Does #3862 work for you?

rahaaatul commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@blazeking101 Please test this version and report if this works for you: https://github.com/Genymobile/scrcpy/pull/3862#issuecomment-1561871804

TheTouYu commented 1 year ago

@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 commented 1 year ago

@TheTouYu Could you please post your framework.jar?

adb pull /system/framework/framework.jar
TheTouYu commented 1 year ago

ok! thanks your reply! framework.zip

TheTouYu commented 1 year ago

thanks you,here ls: https://github.com/Genymobile/scrcpy/files/11717450/framework.zip

rom1v commented 1 year ago

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 :confused: 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 commented 1 year ago

ok, I get! thanks for your work.

yume-chan commented 1 year ago

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 https://github.com/Genymobile/scrcpy/issues/1887#issuecomment-1564633226)

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Oh, great :)

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

yume-chan commented 1 year ago

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 commented 1 year ago

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 https://github.com/Genymobile/scrcpy/issues/1887#issuecomment-1564633226)

Let's try:

quick & dirty diff ```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:

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

TheTouYu commented 1 year ago

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 commented 1 year ago

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

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

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: // - // - - 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:

TheTouYu commented 1 year ago

amazing! it works now

image
rom1v commented 1 year ago

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

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: // - // - - 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:

TheTouYu commented 1 year ago

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 commented 1 year ago

OK, the result is as expected :+1: 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 commented 1 year ago

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 commented 1 year ago

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 :confused:

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

adb shell getprop ro.product.manufacturer
adb shell getprop ro.product.brand
TheTouYu commented 1 year ago

Ok, the result:

[h@TouYu relang]$ adb shell getprop ro.product.manufacturer
HONOR
[h@TouYu relang]$ adb shell getprop ro.product.brand
HONOR
rom1v commented 1 year ago

@yume-chan Oh, providing a base context might also impact Vivo phones: https://github.com/Genymobile/scrcpy/pull/3757#issuecomment-1454684588

rom1v commented 1 year ago

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

Please test this new binary:

blazeking101 commented 1 year ago

oh it works now thank you for all of your hard work i really appreciate it much love <333

rom1v commented 1 year ago

Awesome.

I refactored and simplified the workaround. I removed the call to fillAppInfo(), I think it is not necessary), but I'm not entirely sure, so it might break.

Could you please test this new version with an Honor device? (e91954de82d7c196797e66d38dc4c906a817897e honor.3 branch)

TheTouYu commented 1 year ago

sorry for late response, here is result:

C:\Users\Q520x\Downloads\scrcpy-win64-honor_3\scrcpy-win64-v2.0-93-ge91954de8>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-honor_3\scrcpy-win64... file pushed, 0 skipped. 76.3 MB/s (56871 bytes in 0.001s)
[server] INFO: Device: [HONOR] HONOR FNE-AN00 (Android 12)
[server] ERROR: Exception on thread Thread[audio-encoder,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:114)
        at com.genymobile.scrcpy.AudioCapture.start(AudioCapture.java:126)
        at com.genymobile.scrcpy.AudioEncoder.encode(AudioEncoder.java:193)
        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:930)
INFO: Renderer: direct3d
WARN: Demuxer 'audio': stream explicitly disabled by the device
INFO: Texture: 1080x2400
rom1v commented 1 year ago

@TheTouYu OK, thank you :+1:

So this one should work (feb247f78266ce68c4d6d81da6b20653d679dba4 branch honor.4):

Could you confirm?

TheTouYu commented 1 year ago

I get this:

image
rom1v commented 1 year ago

Thank you for your quick test. I'm surprised that it does not work.

Does https://github.com/Genymobile/scrcpy/issues/4015#issuecomment-1596192278 work for you?

TheTouYu commented 1 year ago

let me try, wait a moment

TheTouYu commented 1 year ago

oh no,

C:\Users\Q520x\Downloads\scrcpy-win64-issue4015\scrcpy-win64-v2.0-93-g86e5c90ed>scrcpy.exe -e
scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
C:\Users\Q520x\Downloads\scrcpy-win64-issue4015\scrcpy-win... file pushed, 0 skipped. 58.1 MB/s (56923 bytes in 0.001s)
[server] INFO: Device: [HONOR] HONOR FNE-AN00 (Android 12)
[server] ERROR: Exception on thread Thread[audio-encoder,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:114)
        at com.genymobile.scrcpy.AudioCapture.start(AudioCapture.java:126)
        at com.genymobile.scrcpy.AudioEncoder.encode(AudioEncoder.java:193)
        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:930)
[server] INFO: newMaxSize = 1920
[server] INFO: Retrying with -m1920...
[server] INFO: Retrying...
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: start failed
INFO: Renderer: direct3d
WARN: Demuxer 'audio': stream explicitly disabled by the device
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] 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 commented 1 year ago

OK, there was some confusion because the first patches were applied on master while the latest were applied on dev, and there were changes regarding workarounds between both branches.

So, maybe this one will work (1c2d4b18b2ab8490a0da18c37b987223279106f8 branch honor.5)

TheTouYu commented 1 year ago

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 commented 1 year ago

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

Could you just confirm that https://github.com/Genymobile/scrcpy/issues/4015#issuecomment-1594432451 still works (if you replace the binary in your v2.0 release)?

TheTouYu commented 1 year ago

sure, I am using it and it still works.

rom1v commented 1 year ago

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

diff ```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: // - // - + mustFillAppInfo = true; mustFillBaseContext = true; mustFillAppContext = true; } ```

(9f9b852ae7deaae9dc4c4baa445424d9620f3824 branch honor.6)

TheTouYu commented 1 year ago

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

rom1v commented 1 year ago

So it works for Honor devices and also for Vivo devices (https://github.com/Genymobile/scrcpy/issues/3805#issuecomment-1597249985). Let's merge it: fb21bbf763691407bc069d84b8e6248667a80e6f

CrimsonFork commented 1 year ago

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

rom1v commented 1 year ago

@CrimsonFork Please post the whole scrcpy output.

CrimsonFork commented 1 year ago
$ scrcpy ``` scrcpy 2.1 /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 commented 11 months ago
[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 commented 11 months ago

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

4110

jincy-p-janardhanan commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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