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 <https://github.com/Genymobile/scrcpy/pull/5102>
This commit is contained in:
Romain Vimont 2024-07-16 13:02:07 +02:00
parent cf09e78323
commit 5e605b9b8f
2 changed files with 9 additions and 0 deletions

View File

@ -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();

View File

@ -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);