Suggest workaround for error 0xfffffc0e
When the hardware encoder is not able to encode at the given definition,
it fails with an error 0xfffffc0e.
It is documented in the FAQ:
<https://github.com/Genymobile/scrcpy/blob/master/FAQ.md#i-get-an-error-could-not-open-video-stream>
But it is better to directly suggest the workaround in the console.
package com.genymobile.scrcpy;
import android.graphics.Rect;
+import android.media.MediaCodec;
+import android.os.Build;
import java.io.File;
import java.io.IOException;
@@ -133,11 +135,25 @@ public final class Server {
}
}
+ private static void suggestFix(Throwable e) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ if (e instanceof MediaCodec.CodecException) {
+ MediaCodec.CodecException mce = (MediaCodec.CodecException) e;
+ if (mce.getErrorCode() == 0xfffffc0e) {
+ Ln.e("The hardware encoder is not able to encode at the given definition.");
+ Ln.e("Try with a lower definition:");
+ Ln.e(" scrcpy -m 1024");
+ }
+ }
+ }
+ }
+
public static void main(String... args) throws Exception {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
Ln.e("Exception on thread " + t, e);
+ suggestFix(e);
}
});
