Skip to content

Commit

Permalink
A2DPStream tx_write_timeout_ms
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Dec 9, 2024
1 parent d60b198 commit ed99d5e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/AudioTools/AudioLibs/A2DPStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class A2DPConfig {
int delay_ms = 1;
/// when a2dp source is active but has no data we generate silence data
bool silence_on_nodata = false;
/// write timeout in ms: -1 is blocking write
int tx_write_timeout_ms = -1; // no timeout
};


Expand Down Expand Up @@ -229,10 +231,16 @@ class A2DPStream : public AudioStream, public VolumeSupport {
}

// blocking write: if buffer is full we wait
int timeout = config.tx_write_timeout_ms;
int wait_time = 5;
size_t free = a2dp_buffer.availableForWrite();
while(len > free){
LOGD("Waiting for buffer: writing %d > available %d", (int) len, (int) free);
delay(5);
if (timeout > 0) {
timeout -= wait_time;
if (timeout <= 0) return 0;
}
delay(wait_time);
free = a2dp_buffer.availableForWrite();
}
}
Expand Down

0 comments on commit ed99d5e

Please sign in to comment.