Skip to content

Commit 68dbabc

Browse files
committed
class A2DPStream; wait_for_connection
1 parent 81f3a42 commit 68dbabc

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

arduino-espeak-ng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 89e8406fb94dc562cc427abc80b9a727d591358a

src/AudioTools/AudioLibs/A2DPStream.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,25 @@ enum A2DPNoData {A2DPSilence, A2DPWhoosh};
4141
*/
4242
class A2DPConfig {
4343
public:
44-
/// Logic when the processing is activated
44+
/// Logic when the processing is activated (default StartWhenBufferFull)
4545
A2DPStartLogic startup_logic = StartWhenBufferFull;
46-
/// Action when a2dp is not active yet
46+
/// Action when a2dp is not active yet (default A2DPSilence)
4747
A2DPNoData startup_nodata = A2DPSilence;
48+
/// Mode: TX_MODE or RX_MODE (default RX_MODE)
4849
RxTxMode mode = RX_MODE;
49-
/// A2DP name
50+
/// A2DP name (default A2DP)
5051
const char* name = "A2DP";
52+
/// automatically reconnect if connection is lost (default false)
5153
bool auto_reconnect = false;
5254
int buffer_size = A2DP_BUFFER_SIZE * A2DP_BUFFER_COUNT;
53-
/// Delay in ms which is added to each write
55+
/// Delay in ms which is added to each write (default 1)
5456
int delay_ms = 1;
55-
/// when a2dp source is active but has no data we generate silence data
57+
/// when a2dp source is active but has no data we generate silence data (default false)
5658
bool silence_on_nodata = false;
57-
/// write timeout in ms: -1 is blocking write
59+
/// write timeout in ms: -1 is blocking write (default -1)
5860
int tx_write_timeout_ms = -1; // no timeout
61+
/// begin should wait for connection to be established (default true)
62+
bool wait_for_connection=true;
5963
};
6064

6165

@@ -127,11 +131,12 @@ class A2DPStream : public AudioStream, public VolumeSupport {
127131
A2DPConfig cfg;
128132
cfg.mode = mode;
129133
cfg.name = name;
130-
return begin(cfg, wait_for_connection);
134+
cfg.wait_for_connection = wait_for_connection;
135+
return begin(cfg);
131136
}
132137

133138
/// Starts the processing
134-
bool begin(A2DPConfig cfg, bool wait_for_connection=true){
139+
bool begin(A2DPConfig cfg){
135140
this->config = cfg;
136141
bool result = false;
137142
LOGI("Connecting to %s",cfg.name);
@@ -159,7 +164,7 @@ class A2DPStream : public AudioStream, public VolumeSupport {
159164
}
160165
a2dp_source->set_on_connection_state_changed(a2dp_state_callback, this);
161166
a2dp_source->start_raw((char*)cfg.name, a2dp_stream_source_sound_data);
162-
if (wait_for_connection){
167+
if (cfg.wait_for_connection){
163168
while(!a2dp_source->is_connected()){
164169
LOGD("waiting for connection");
165170
delay(1000);
@@ -183,7 +188,7 @@ class A2DPStream : public AudioStream, public VolumeSupport {
183188
a2dp_sink->set_on_connection_state_changed(a2dp_state_callback, this);
184189
a2dp_sink->set_sample_rate_callback(sample_rate_callback);
185190
a2dp_sink->start((char*)cfg.name);
186-
if (wait_for_connection){
191+
if (cfg.wait_for_connection){
187192
while(!a2dp_sink->is_connected()){
188193
LOGD("waiting for connection");
189194
delay(1000);

0 commit comments

Comments
 (0)