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_MS = 5; // milliseconds
|
||||||
private static final int READ_SIZE = AudioCapture.millisToBytes(READ_MS);
|
private static final int READ_SIZE = AudioCapture.millisToBytes(READ_MS);
|
||||||
|
|
||||||
|
private final AudioCapture capture;
|
||||||
private final Streamer streamer;
|
private final Streamer streamer;
|
||||||
private final int bitRate;
|
private final int bitRate;
|
||||||
private final List<CodecOption> codecOptions;
|
private final List<CodecOption> codecOptions;
|
||||||
|
@ -58,7 +59,8 @@ public final class AudioEncoder implements AsyncProcessor {
|
||||||
|
|
||||||
private boolean ended;
|
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.streamer = streamer;
|
||||||
this.bitRate = bitRate;
|
this.bitRate = bitRate;
|
||||||
this.codecOptions = codecOptions;
|
this.codecOptions = codecOptions;
|
||||||
|
@ -175,7 +177,6 @@ public final class AudioEncoder implements AsyncProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaCodec mediaCodec = null;
|
MediaCodec mediaCodec = null;
|
||||||
AudioCapture capture = new AudioCapture();
|
|
||||||
|
|
||||||
boolean mediaCodecStarted = false;
|
boolean mediaCodecStarted = false;
|
||||||
try {
|
try {
|
||||||
|
@ -192,10 +193,9 @@ public final class AudioEncoder implements AsyncProcessor {
|
||||||
capture.start();
|
capture.start();
|
||||||
|
|
||||||
final MediaCodec mediaCodecRef = mediaCodec;
|
final MediaCodec mediaCodecRef = mediaCodec;
|
||||||
final AudioCapture captureRef = capture;
|
|
||||||
inputThread = new Thread(() -> {
|
inputThread = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
inputThread(mediaCodecRef, captureRef);
|
inputThread(mediaCodecRef, capture);
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
Ln.e("Audio capture error", e);
|
Ln.e("Audio capture error", e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public final class AudioRawRecorder implements AsyncProcessor {
|
public final class AudioRawRecorder implements AsyncProcessor {
|
||||||
|
|
||||||
|
private final AudioCapture capture;
|
||||||
private final Streamer streamer;
|
private final Streamer streamer;
|
||||||
|
|
||||||
private Thread thread;
|
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_MS = 5; // milliseconds
|
||||||
private static final int READ_SIZE = AudioCapture.millisToBytes(READ_MS);
|
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;
|
this.streamer = streamer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +31,6 @@ public final class AudioRawRecorder implements AsyncProcessor {
|
||||||
final ByteBuffer buffer = ByteBuffer.allocateDirect(READ_SIZE);
|
final ByteBuffer buffer = ByteBuffer.allocateDirect(READ_SIZE);
|
||||||
final MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
final MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
||||||
|
|
||||||
AudioCapture capture = new AudioCapture();
|
|
||||||
try {
|
try {
|
||||||
capture.start();
|
capture.start();
|
||||||
|
|
||||||
|
|
|
@ -136,13 +136,14 @@ public final class Server {
|
||||||
|
|
||||||
if (audio) {
|
if (audio) {
|
||||||
AudioCodec audioCodec = options.getAudioCodec();
|
AudioCodec audioCodec = options.getAudioCodec();
|
||||||
|
AudioCapture audioCapture = new AudioCapture();
|
||||||
Streamer audioStreamer = new Streamer(connection.getAudioFd(), audioCodec, options.getSendCodecMeta(),
|
Streamer audioStreamer = new Streamer(connection.getAudioFd(), audioCodec, options.getSendCodecMeta(),
|
||||||
options.getSendFrameMeta());
|
options.getSendFrameMeta());
|
||||||
AsyncProcessor audioRecorder;
|
AsyncProcessor audioRecorder;
|
||||||
if (audioCodec == AudioCodec.RAW) {
|
if (audioCodec == AudioCodec.RAW) {
|
||||||
audioRecorder = new AudioRawRecorder(audioStreamer);
|
audioRecorder = new AudioRawRecorder(audioCapture, audioStreamer);
|
||||||
} else {
|
} else {
|
||||||
audioRecorder = new AudioEncoder(audioStreamer, options.getAudioBitRate(), options.getAudioCodecOptions(),
|
audioRecorder = new AudioEncoder(audioCapture, audioStreamer, options.getAudioBitRate(), options.getAudioCodecOptions(),
|
||||||
options.getAudioEncoder());
|
options.getAudioEncoder());
|
||||||
}
|
}
|
||||||
asyncProcessors.add(audioRecorder);
|
asyncProcessors.add(audioRecorder);
|
||||||
|
|
Loading…
Reference in a new issue