From d8dd105c11c4c7f6673d8a9934bd8a56bb03767b Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 15 Jul 2024 10:54:43 +0200 Subject: [PATCH] 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. --- .../scrcpy/audio/AudioDirectCapture.java | 14 +++++++++++++- .../com/genymobile/scrcpy/audio/AudioSource.java | 14 +++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/audio/AudioDirectCapture.java b/server/src/main/java/com/genymobile/scrcpy/audio/AudioDirectCapture.java index c033146724..361c7baca1 100644 --- a/server/src/main/java/com/genymobile/scrcpy/audio/AudioDirectCapture.java +++ b/server/src/main/java/com/genymobile/scrcpy/audio/AudioDirectCapture.java @@ -11,6 +11,7 @@ import android.content.Intent; import android.media.AudioRecord; import android.media.MediaCodec; +import android.media.MediaRecorder; import android.os.Build; import android.os.SystemClock; @@ -30,7 +31,18 @@ public class AudioDirectCapture implements AudioCapture { private AudioRecordReader reader; 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) diff --git a/server/src/main/java/com/genymobile/scrcpy/audio/AudioSource.java b/server/src/main/java/com/genymobile/scrcpy/audio/AudioSource.java index 2324f1a479..7201dd39e4 100644 --- a/server/src/main/java/com/genymobile/scrcpy/audio/AudioSource.java +++ b/server/src/main/java/com/genymobile/scrcpy/audio/AudioSource.java @@ -1,21 +1,13 @@ package com.genymobile.scrcpy.audio; -import android.media.MediaRecorder; - public enum AudioSource { - OUTPUT("output", MediaRecorder.AudioSource.REMOTE_SUBMIX), - MIC("mic", MediaRecorder.AudioSource.MIC); + OUTPUT("output"), + MIC("mic"); private final String name; - private final int value; - AudioSource(String name, int value) { + AudioSource(String name) { this.name = name; - this.value = value; - } - - int value() { - return value; } public static AudioSource findByName(String name) {