@@ -41,21 +41,25 @@ enum A2DPNoData {A2DPSilence, A2DPWhoosh};
41
41
*/
42
42
class A2DPConfig {
43
43
public:
44
- // / Logic when the processing is activated
44
+ // / Logic when the processing is activated (default StartWhenBufferFull)
45
45
A2DPStartLogic startup_logic = StartWhenBufferFull;
46
- // / Action when a2dp is not active yet
46
+ // / Action when a2dp is not active yet (default A2DPSilence)
47
47
A2DPNoData startup_nodata = A2DPSilence;
48
+ // / Mode: TX_MODE or RX_MODE (default RX_MODE)
48
49
RxTxMode mode = RX_MODE;
49
- // / A2DP name
50
+ // / A2DP name (default A2DP)
50
51
const char * name = " A2DP" ;
52
+ // / automatically reconnect if connection is lost (default false)
51
53
bool auto_reconnect = false ;
52
54
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)
54
56
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)
56
58
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)
58
60
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 ;
59
63
};
60
64
61
65
@@ -127,11 +131,12 @@ class A2DPStream : public AudioStream, public VolumeSupport {
127
131
A2DPConfig cfg;
128
132
cfg.mode = mode;
129
133
cfg.name = name;
130
- return begin (cfg, wait_for_connection);
134
+ cfg.wait_for_connection = wait_for_connection;
135
+ return begin (cfg);
131
136
}
132
137
133
138
// / Starts the processing
134
- bool begin (A2DPConfig cfg, bool wait_for_connection= true ){
139
+ bool begin (A2DPConfig cfg){
135
140
this ->config = cfg;
136
141
bool result = false ;
137
142
LOGI (" Connecting to %s" ,cfg.name );
@@ -159,7 +164,7 @@ class A2DPStream : public AudioStream, public VolumeSupport {
159
164
}
160
165
a2dp_source->set_on_connection_state_changed (a2dp_state_callback, this );
161
166
a2dp_source->start_raw ((char *)cfg.name , a2dp_stream_source_sound_data);
162
- if (wait_for_connection){
167
+ if (cfg. wait_for_connection ){
163
168
while (!a2dp_source->is_connected ()){
164
169
LOGD (" waiting for connection" );
165
170
delay (1000 );
@@ -183,7 +188,7 @@ class A2DPStream : public AudioStream, public VolumeSupport {
183
188
a2dp_sink->set_on_connection_state_changed (a2dp_state_callback, this );
184
189
a2dp_sink->set_sample_rate_callback (sample_rate_callback);
185
190
a2dp_sink->start ((char *)cfg.name );
186
- if (wait_for_connection){
191
+ if (cfg. wait_for_connection ){
187
192
while (!a2dp_sink->is_connected ()){
188
193
LOGD (" waiting for connection" );
189
194
delay (1000 );
0 commit comments