@@ -82,19 +82,6 @@ int32_t a2dp_stream_source_sound_data(Frame* data, int32_t len) {
82
82
result_len = len;
83
83
}
84
84
85
-
86
- // Log result
87
- // if (AudioLogger::instance().level()==AudioLogger::Debug){
88
- // LOGD("a2dp_stream_source_sound_data %d -> %d", len, result_len);
89
- // } else {
90
- // if (result_len<len){
91
- // LOGW("a2dp_stream_source_sound_data underflow: %d -> %d ", len, result_len);
92
- // }
93
- // }
94
-
95
- // allow some other task
96
- // yield();
97
-
98
85
return result_len;
99
86
}
100
87
@@ -104,7 +91,7 @@ void a2dp_stream_sink_sound_data(const uint8_t* data, uint32_t len) {
104
91
uint32_t result_len = a2dp_buffer.writeArray (data, len);
105
92
LOGI (" a2dp_stream_sink_sound_data %d -> %d" , len, result_len);
106
93
// allow some other task
107
- yield ();
94
+ // yield();
108
95
}
109
96
}
110
97
@@ -152,6 +139,7 @@ class A2DPStream : public AudioStream {
152
139
void begin (RxTxMode mode, const char * name){
153
140
this ->mode = mode;
154
141
this ->name = name;
142
+ LOGI (" Connecting to %s" ,name);
155
143
156
144
157
145
switch (mode){
@@ -160,7 +148,7 @@ class A2DPStream : public AudioStream {
160
148
source (); // allocate object
161
149
a2dp_source->start ((char *)name, a2dp_stream_source_sound_data);
162
150
a2dp_source->set_on_connection_state_changed (a2dpStateCallback, this );
163
- while (!a2dp_source->isConnected ()){
151
+ while (!a2dp_source->is_connected ()){
164
152
delay (1000 );
165
153
}
166
154
LOGI (" a2dp_source is connected..." );
@@ -173,7 +161,7 @@ class A2DPStream : public AudioStream {
173
161
a2dp_sink->set_stream_reader (&a2dp_stream_sink_sound_data, false );
174
162
a2dp_sink->start ((char *)name);
175
163
a2dp_sink->set_on_connection_state_changed (a2dpStateCallback, this );
176
- while (!a2dp_sink->isConnected ()){
164
+ while (!a2dp_sink->is_connected ()){
177
165
delay (1000 );
178
166
}
179
167
LOGI (" a2dp_sink is connected..." );
@@ -185,8 +173,8 @@ class A2DPStream : public AudioStream {
185
173
// / checks if we are connected
186
174
bool isConnected () {
187
175
if (a2dp_source==nullptr && a2dp_sink==nullptr ) return false ;
188
- if (a2dp_source!=nullptr ) return a2dp_source->isConnected ();
189
- return a2dp_sink->isConnected ();
176
+ if (a2dp_source!=nullptr ) return a2dp_source->is_connected ();
177
+ return a2dp_sink->is_connected ();
190
178
}
191
179
192
180
// / is ready to process data
@@ -201,11 +189,16 @@ class A2DPStream : public AudioStream {
201
189
202
190
// / Writes the data into a temporary send buffer - where it can be picked up by the callback
203
191
virtual size_t write (const uint8_t * data, size_t len) {
192
+ LOGD (" %s: %zu" , LOG_METHOD, len);
193
+
204
194
size_t result = 0 ;
205
195
if (is_a2dp_active){
206
- LOGD (" write %d" , len);
207
- result = a2dp_buffer.writeArray (data,len);
208
- LOGI (" write %d -> %d" , len,result);
196
+ if (a2dp_buffer.availableToWrite ()>=len){
197
+ result = a2dp_buffer.writeArray (data, len);
198
+ LOGD (" write %d -> %d" , len, result);
199
+ } else {
200
+ LOGI (" write %d - buffer full (available sound: %d, free: %d)" , len, a2dp_buffer.available (), a2dp_buffer.availableToWrite () );
201
+ }
209
202
} else {
210
203
LOGW ( " write failed because !is_a2dp_active (yet)" );
211
204
delay (5000 );
@@ -274,9 +267,9 @@ class A2DPStream : public AudioStream {
274
267
static void a2dpStateCallback (esp_a2d_connection_state_t state, void *caller){
275
268
LOGD (LOG_METHOD);
276
269
A2DPStream *self = (A2DPStream*)caller;
277
- // if (state==ESP_A2D_CONNECTION_STATE_CONNECTED){
278
- // self-> is_a2dp_active = true;
279
- // }
270
+ if (state==ESP_A2D_CONNECTION_STATE_CONNECTED){
271
+ is_a2dp_active = true ;
272
+ }
280
273
LOGW (" ==> state: %s" , self->a2dp ->to_str (state));
281
274
}
282
275
0 commit comments