Extract audio recorder interface

In order to support both encoded and raw audio stream, extract a
interface (very minimal, but sufficient to just start and stop).

PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
This commit is contained in:
Romain Vimont 2023-03-03 18:49:05 +01:00
commit b08684709a
3 changed files with 20 additions and 8 deletions

View file

@ -14,7 +14,7 @@ import java.util.List;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
public final class AudioEncoder { public final class AudioEncoder implements AudioRecorder {
private static class InputTask { private static class InputTask {
private final int index; private final int index;

View file

@ -0,0 +1,12 @@
package com.genymobile.scrcpy;
/**
* A component able to record audio asynchronously
*
* The implementation is responsible to send packets.
*/
public interface AudioRecorder {
void start();
void stop();
void join() throws InterruptedException;
}

View file

@ -92,7 +92,7 @@ public final class Server {
} }
Controller controller = null; Controller controller = null;
AudioEncoder audioEncoder = null; AudioRecorder audioRecorder = null;
try (DesktopConnection connection = DesktopConnection.open(scid, tunnelForward, audio, control, sendDummyByte)) { try (DesktopConnection connection = DesktopConnection.open(scid, tunnelForward, audio, control, sendDummyByte)) {
if (options.getSendDeviceMeta()) { if (options.getSendDeviceMeta()) {
@ -111,8 +111,8 @@ public final class Server {
if (audio) { if (audio) {
Streamer audioStreamer = new Streamer(connection.getAudioFd(), options.getAudioCodec(), options.getSendCodecId(), Streamer audioStreamer = new Streamer(connection.getAudioFd(), options.getAudioCodec(), options.getSendCodecId(),
options.getSendFrameMeta()); options.getSendFrameMeta());
audioEncoder = new AudioEncoder(audioStreamer, options.getAudioBitRate(), options.getAudioCodecOptions(), options.getAudioEncoder()); audioRecorder = new AudioEncoder(audioStreamer, options.getAudioBitRate(), options.getAudioCodecOptions(), options.getAudioEncoder());
audioEncoder.start(); audioRecorder.start();
} }
Streamer videoStreamer = new Streamer(connection.getVideoFd(), options.getVideoCodec(), options.getSendCodecId(), Streamer videoStreamer = new Streamer(connection.getVideoFd(), options.getVideoCodec(), options.getSendCodecId(),
@ -131,8 +131,8 @@ public final class Server {
} finally { } finally {
Ln.d("Screen streaming stopped"); Ln.d("Screen streaming stopped");
initThread.interrupt(); initThread.interrupt();
if (audioEncoder != null) { if (audioRecorder != null) {
audioEncoder.stop(); audioRecorder.stop();
} }
if (controller != null) { if (controller != null) {
controller.stop(); controller.stop();
@ -140,8 +140,8 @@ public final class Server {
try { try {
initThread.join(); initThread.join();
if (audioEncoder != null) { if (audioRecorder != null) {
audioEncoder.join(); audioRecorder.join();
} }
if (controller != null) { if (controller != null) {
controller.join(); controller.join();