Skip to content

Commit

Permalink
Move audio source value
Browse files Browse the repository at this point in the history
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 Genymobile#5102 <Genymobile#5102>
  • Loading branch information
rom1v authored and Gottox committed Sep 29, 2024
1 parent f54cc5e commit 8dff6cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
14 changes: 3 additions & 11 deletions server/src/main/java/com/genymobile/scrcpy/audio/AudioSource.java
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit 8dff6cc

Please sign in to comment.