Move audio source value

The MediaRecorder constant should not belong to the AudioSource enum.

This will allow to add a new AudioSource which has no meaningful
MediaRecorder audio source value.

PR #5102 <https://github.com/Genymobile/scrcpy/pull/5102>
This commit is contained in:
Romain Vimont 2024-07-15 10:54:43 +02:00
parent 0f076083e8
commit 53c6eb66ea
2 changed files with 16 additions and 12 deletions

View File

@ -11,6 +11,7 @@ import android.content.ComponentName;
import android.content.Intent; import android.content.Intent;
import android.media.AudioRecord; import android.media.AudioRecord;
import android.media.MediaCodec; import android.media.MediaCodec;
import android.media.MediaRecorder;
import android.os.Build; import android.os.Build;
import android.os.SystemClock; import android.os.SystemClock;
@ -30,7 +31,18 @@ public class AudioDirectCapture implements AudioCapture {
private AudioRecordReader reader; private AudioRecordReader reader;
public AudioDirectCapture(AudioSource audioSource) { public AudioDirectCapture(AudioSource audioSource) {
this.audioSource = audioSource.value(); this.audioSource = getAudioSourceValue(audioSource);
}
private static int getAudioSourceValue(AudioSource audioSource) {
switch (audioSource) {
case OUTPUT:
return MediaRecorder.AudioSource.REMOTE_SUBMIX;
case MIC:
return MediaRecorder.AudioSource.MIC;
default:
throw new IllegalArgumentException("Unsupported audio source: " + audioSource);
}
} }
@TargetApi(Build.VERSION_CODES.M) @TargetApi(Build.VERSION_CODES.M)

View File

@ -1,21 +1,13 @@
package com.genymobile.scrcpy.audio; package com.genymobile.scrcpy.audio;
import android.media.MediaRecorder;
public enum AudioSource { public enum AudioSource {
OUTPUT("output", MediaRecorder.AudioSource.REMOTE_SUBMIX), OUTPUT("output"),
MIC("mic", MediaRecorder.AudioSource.MIC); MIC("mic");
private final String name; private final String name;
private final int value;
AudioSource(String name, int value) { AudioSource(String name) {
this.name = name; this.name = name;
this.value = value;
}
int value() {
return value;
} }
public static AudioSource findByName(String name) { public static AudioSource findByName(String name) {