From 4635a78574577beffe2348612f1e6e55b31b2b3e Mon Sep 17 00:00:00 2001 From: Branden Archer Date: Sat, 26 Dec 2015 17:51:16 -0500 Subject: [PATCH] Set the TCP send buffer size to avoid buffering audio If the send buffer size is large and the receiver is unable to keep up, then audio samples will collect on the monitor and lag will accumulate. As only the most recent sample is important, reduce the send buffer size to the minimum AudioRecord buffer size. --- src/protect/babymonitor/MonitorActivity.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/protect/babymonitor/MonitorActivity.java b/src/protect/babymonitor/MonitorActivity.java index 2babbef..699ccdf 100644 --- a/src/protect/babymonitor/MonitorActivity.java +++ b/src/protect/babymonitor/MonitorActivity.java @@ -71,6 +71,9 @@ public class MonitorActivity extends Activity OutputStream out = socket.getOutputStream(); + socket.setSendBufferSize(bufferSize); + Log.d(TAG, "Socket send buffer size: " + socket.getSendBufferSize()); + while (socket.isConnected() && Thread.currentThread().isInterrupted() == false) { int read = audioRecord.read(buffer, 0, bufferSize);