Extract AudioCapture creation
This will allow to pass capture options without code duplication.
This commit is contained in:
parent
24999d0d32
commit
360f2fea1e
3 changed files with 10 additions and 8 deletions
|
@ -40,6 +40,7 @@ public final class AudioEncoder implements AsyncProcessor {
|
|||
private static final int READ_MS = 5; // milliseconds
|
||||
private static final int READ_SIZE = AudioCapture.millisToBytes(READ_MS);
|
||||
|
||||
private final AudioCapture capture;
|
||||
private final Streamer streamer;
|
||||
private final int bitRate;
|
||||
private final List<CodecOption> codecOptions;
|
||||
|
@ -58,7 +59,8 @@ public final class AudioEncoder implements AsyncProcessor {
|
|||
|
||||
private boolean ended;
|
||||
|
||||
public AudioEncoder(Streamer streamer, int bitRate, List<CodecOption> codecOptions, String encoderName) {
|
||||
public AudioEncoder(AudioCapture capture, Streamer streamer, int bitRate, List<CodecOption> codecOptions, String encoderName) {
|
||||
this.capture = capture;
|
||||
this.streamer = streamer;
|
||||
this.bitRate = bitRate;
|
||||
this.codecOptions = codecOptions;
|
||||
|
@ -175,7 +177,6 @@ public final class AudioEncoder implements AsyncProcessor {
|
|||
}
|
||||
|
||||
MediaCodec mediaCodec = null;
|
||||
AudioCapture capture = new AudioCapture();
|
||||
|
||||
boolean mediaCodecStarted = false;
|
||||
try {
|
||||
|
@ -192,10 +193,9 @@ public final class AudioEncoder implements AsyncProcessor {
|
|||
capture.start();
|
||||
|
||||
final MediaCodec mediaCodecRef = mediaCodec;
|
||||
final AudioCapture captureRef = capture;
|
||||
inputThread = new Thread(() -> {
|
||||
try {
|
||||
inputThread(mediaCodecRef, captureRef);
|
||||
inputThread(mediaCodecRef, capture);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
Ln.e("Audio capture error", e);
|
||||
} finally {
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.nio.ByteBuffer;
|
|||
|
||||
public final class AudioRawRecorder implements AsyncProcessor {
|
||||
|
||||
private final AudioCapture capture;
|
||||
private final Streamer streamer;
|
||||
|
||||
private Thread thread;
|
||||
|
@ -15,7 +16,8 @@ public final class AudioRawRecorder implements AsyncProcessor {
|
|||
private static final int READ_MS = 5; // milliseconds
|
||||
private static final int READ_SIZE = AudioCapture.millisToBytes(READ_MS);
|
||||
|
||||
public AudioRawRecorder(Streamer streamer) {
|
||||
public AudioRawRecorder(AudioCapture capture, Streamer streamer) {
|
||||
this.capture = capture;
|
||||
this.streamer = streamer;
|
||||
}
|
||||
|
||||
|
@ -29,7 +31,6 @@ public final class AudioRawRecorder implements AsyncProcessor {
|
|||
final ByteBuffer buffer = ByteBuffer.allocateDirect(READ_SIZE);
|
||||
final MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
||||
|
||||
AudioCapture capture = new AudioCapture();
|
||||
try {
|
||||
capture.start();
|
||||
|
||||
|
|
|
@ -136,13 +136,14 @@ public final class Server {
|
|||
|
||||
if (audio) {
|
||||
AudioCodec audioCodec = options.getAudioCodec();
|
||||
AudioCapture audioCapture = new AudioCapture();
|
||||
Streamer audioStreamer = new Streamer(connection.getAudioFd(), audioCodec, options.getSendCodecMeta(),
|
||||
options.getSendFrameMeta());
|
||||
AsyncProcessor audioRecorder;
|
||||
if (audioCodec == AudioCodec.RAW) {
|
||||
audioRecorder = new AudioRawRecorder(audioStreamer);
|
||||
audioRecorder = new AudioRawRecorder(audioCapture, audioStreamer);
|
||||
} else {
|
||||
audioRecorder = new AudioEncoder(audioStreamer, options.getAudioBitRate(), options.getAudioCodecOptions(),
|
||||
audioRecorder = new AudioEncoder(audioCapture, audioStreamer, options.getAudioBitRate(), options.getAudioCodecOptions(),
|
||||
options.getAudioEncoder());
|
||||
}
|
||||
asyncProcessors.add(audioRecorder);
|
||||
|
|
Loading…
Reference in a new issue