Skip to content

Commit

Permalink
Move audio compatibility check
Browse files Browse the repository at this point in the history
The compatibility depends on the capture constraints, not the encoding.

This will allow to add a new capture implementation with different
constraints.

PR Genymobile#5102 <Genymobile#5102>
  • Loading branch information
rom1v authored and Gottox committed Sep 29, 2024
1 parent 7bad34d commit d7631d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ private void startRecording() throws AudioCaptureException {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ private void encode() throws IOException, ConfigurationException, AudioCaptureEx

boolean mediaCodecStarted = false;
try {
capture.checkCompatibility(); // throws an AudioCaptureException on error

Codec codec = streamer.getCodec();
mediaCodec = createMediaCodec(codec, encoderName);

Expand Down

0 comments on commit d7631d3

Please sign in to comment.