Skip to content

Commit ed99d5e

Browse files
committed
A2DPStream tx_write_timeout_ms
1 parent d60b198 commit ed99d5e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/AudioTools/AudioLibs/A2DPStream.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class A2DPConfig {
5454
int delay_ms = 1;
5555
/// when a2dp source is active but has no data we generate silence data
5656
bool silence_on_nodata = false;
57+
/// write timeout in ms: -1 is blocking write
58+
int tx_write_timeout_ms = -1; // no timeout
5759
};
5860

5961

@@ -229,10 +231,16 @@ class A2DPStream : public AudioStream, public VolumeSupport {
229231
}
230232

231233
// blocking write: if buffer is full we wait
234+
int timeout = config.tx_write_timeout_ms;
235+
int wait_time = 5;
232236
size_t free = a2dp_buffer.availableForWrite();
233237
while(len > free){
234238
LOGD("Waiting for buffer: writing %d > available %d", (int) len, (int) free);
235-
delay(5);
239+
if (timeout > 0) {
240+
timeout -= wait_time;
241+
if (timeout <= 0) return 0;
242+
}
243+
delay(wait_time);
236244
free = a2dp_buffer.availableForWrite();
237245
}
238246
}

0 commit comments

Comments
 (0)