Skip to content

Commit b086847

Browse files
committed
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 <Genymobile/scrcpy#3757>
1 parent f065fee commit b086847

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

server/src/main/java/com/genymobile/scrcpy/AudioEncoder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import java.util.concurrent.ArrayBlockingQueue;
1515
import java.util.concurrent.BlockingQueue;
1616

17-
public final class AudioEncoder {
17+
public final class AudioEncoder implements AudioRecorder {
1818

1919
private static class InputTask {
2020
private final int index;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.genymobile.scrcpy;
2+
3+
/**
4+
* A component able to record audio asynchronously
5+
*
6+
* The implementation is responsible to send packets.
7+
*/
8+
public interface AudioRecorder {
9+
void start();
10+
void stop();
11+
void join() throws InterruptedException;
12+
}

server/src/main/java/com/genymobile/scrcpy/Server.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private static void scrcpy(Options options) throws IOException, ConfigurationExc
9292
}
9393

9494
Controller controller = null;
95-
AudioEncoder audioEncoder = null;
95+
AudioRecorder audioRecorder = null;
9696

9797
try (DesktopConnection connection = DesktopConnection.open(scid, tunnelForward, audio, control, sendDummyByte)) {
9898
if (options.getSendDeviceMeta()) {
@@ -111,8 +111,8 @@ private static void scrcpy(Options options) throws IOException, ConfigurationExc
111111
if (audio) {
112112
Streamer audioStreamer = new Streamer(connection.getAudioFd(), options.getAudioCodec(), options.getSendCodecId(),
113113
options.getSendFrameMeta());
114-
audioEncoder = new AudioEncoder(audioStreamer, options.getAudioBitRate(), options.getAudioCodecOptions(), options.getAudioEncoder());
115-
audioEncoder.start();
114+
audioRecorder = new AudioEncoder(audioStreamer, options.getAudioBitRate(), options.getAudioCodecOptions(), options.getAudioEncoder());
115+
audioRecorder.start();
116116
}
117117

118118
Streamer videoStreamer = new Streamer(connection.getVideoFd(), options.getVideoCodec(), options.getSendCodecId(),
@@ -131,17 +131,17 @@ private static void scrcpy(Options options) throws IOException, ConfigurationExc
131131
} finally {
132132
Ln.d("Screen streaming stopped");
133133
initThread.interrupt();
134-
if (audioEncoder != null) {
135-
audioEncoder.stop();
134+
if (audioRecorder != null) {
135+
audioRecorder.stop();
136136
}
137137
if (controller != null) {
138138
controller.stop();
139139
}
140140

141141
try {
142142
initThread.join();
143-
if (audioEncoder != null) {
144-
audioEncoder.join();
143+
if (audioRecorder != null) {
144+
audioRecorder.join();
145145
}
146146
if (controller != null) {
147147
controller.join();

0 commit comments

Comments
 (0)