mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-03 22:58:51 +00:00
Refactor audio sources
Store the target audio source integer (one of the constants in android.media.MediaRecorder.AudioSource) in the AudioSource enum (or -1 if not relevant). This will simplify adding new audio sources.
This commit is contained in:
parent
671025cb68
commit
9fb7446b88
2 changed files with 13 additions and 17 deletions
|
@ -12,7 +12,6 @@ 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;
|
||||||
|
|
||||||
|
@ -32,18 +31,7 @@ public class AudioDirectCapture implements AudioCapture {
|
||||||
private AudioRecordReader reader;
|
private AudioRecordReader reader;
|
||||||
|
|
||||||
public AudioDirectCapture(AudioSource audioSource) {
|
public AudioDirectCapture(AudioSource audioSource) {
|
||||||
this.audioSource = getAudioSourceValue(audioSource);
|
this.audioSource = audioSource.getDirectAudioSource();
|
||||||
}
|
|
||||||
|
|
||||||
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(AndroidVersions.API_23_ANDROID_6_0)
|
@TargetApi(AndroidVersions.API_23_ANDROID_6_0)
|
||||||
|
|
|
@ -1,20 +1,28 @@
|
||||||
package com.genymobile.scrcpy.audio;
|
package com.genymobile.scrcpy.audio;
|
||||||
|
|
||||||
|
import android.media.MediaRecorder;
|
||||||
|
|
||||||
public enum AudioSource {
|
public enum AudioSource {
|
||||||
OUTPUT("output"),
|
OUTPUT("output", MediaRecorder.AudioSource.REMOTE_SUBMIX),
|
||||||
MIC("mic"),
|
MIC("mic", MediaRecorder.AudioSource.MIC),
|
||||||
PLAYBACK("playback");
|
PLAYBACK("playback", -1);
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
private final int directAudioSource;
|
||||||
|
|
||||||
AudioSource(String name) {
|
AudioSource(String name, int directAudioSource) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.directAudioSource = directAudioSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDirect() {
|
public boolean isDirect() {
|
||||||
return this != PLAYBACK;
|
return this != PLAYBACK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDirectAudioSource() {
|
||||||
|
return directAudioSource;
|
||||||
|
}
|
||||||
|
|
||||||
public static AudioSource findByName(String name) {
|
public static AudioSource findByName(String name) {
|
||||||
for (AudioSource audioSource : AudioSource.values()) {
|
for (AudioSource audioSource : AudioSource.values()) {
|
||||||
if (name.equals(audioSource.name)) {
|
if (name.equals(audioSource.name)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue