Skip to content

Commit f565df6

Browse files
committed
move buffer allocation outside loop and increase PipedInputStream size
1 parent ddef095 commit f565df6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,17 @@ public static void poc(PipedInputStream pis) throws Exception {
209209
audioTrack.play();
210210

211211
new Thread(() -> {
212+
byte[] audioBuffer = new byte[4096];
212213
while (true) {
213-
byte[] audioBuffer = new byte[8192];
214214
try {
215215
int bytesRead = pis.read(audioBuffer);
216+
if (bytesRead <= 0) {
217+
break;
218+
}
216219
audioTrack.write(audioBuffer, 0, bytesRead);
217220
} catch (Exception e) {
218221
Ln.e(e.toString());
222+
break;
219223
}
220224
}
221225
}, "client-audio-injector").start();
@@ -319,7 +323,8 @@ private static void scrcpy(Options options) throws IOException, ConfigurationExc
319323
InputStream is = s.getInputStream();
320324
BufferedInputStream bis = new BufferedInputStream(is);
321325
PipedOutputStream pos = new PipedOutputStream();
322-
PipedInputStream pis = new PipedInputStream(pos, 65535);
326+
//PipedInputStream pis = new PipedInputStream(pos, 65535);
327+
PipedInputStream pis = new PipedInputStream(pos, 500*1024);
323328
AudioDecoder decoder = new AudioDecoder();
324329
decoder.start(bis, pos);
325330
poc(pis);

0 commit comments

Comments
 (0)