From 5e605b9b8f8a31b53a41695a831696edad29327e Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Tue, 16 Jul 2024 13:02:07 +0200 Subject: [PATCH] Move audio compatibility check The compatibility depends on the capture constraints, not the encoding. This will allow to add a new capture implementation with different constraints. PR #5102 --- .../java/com/genymobile/scrcpy/audio/AudioCapture.java | 7 +++++++ .../java/com/genymobile/scrcpy/audio/AudioEncoder.java | 2 ++ 2 files changed, 9 insertions(+) diff --git a/server/src/main/java/com/genymobile/scrcpy/audio/AudioCapture.java b/server/src/main/java/com/genymobile/scrcpy/audio/AudioCapture.java index 609ea4c2..27ea1ec1 100644 --- a/server/src/main/java/com/genymobile/scrcpy/audio/AudioCapture.java +++ b/server/src/main/java/com/genymobile/scrcpy/audio/AudioCapture.java @@ -121,6 +121,13 @@ public final class AudioCapture { recorder.startRecording(); } + public void checkCompatibility() throws AudioCaptureException { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + Ln.w("Audio disabled: it is not supported before Android 11"); + throw new AudioCaptureException(); + } + } + public void start() throws AudioCaptureException { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) { startWorkaroundAndroid11(); diff --git a/server/src/main/java/com/genymobile/scrcpy/audio/AudioEncoder.java b/server/src/main/java/com/genymobile/scrcpy/audio/AudioEncoder.java index 219e2c0c..3eadf51a 100644 --- a/server/src/main/java/com/genymobile/scrcpy/audio/AudioEncoder.java +++ b/server/src/main/java/com/genymobile/scrcpy/audio/AudioEncoder.java @@ -187,6 +187,8 @@ public final class AudioEncoder implements AsyncProcessor { boolean mediaCodecStarted = false; try { + capture.checkCompatibility(); // throws an AudioCaptureException on error + Codec codec = streamer.getCodec(); mediaCodec = createMediaCodec(codec, encoderName);