@@ -75,7 +75,7 @@ class A2DPConfig {
75
75
*
76
76
* Because we support only one instance the class is implemented as singleton!
77
77
*/
78
- class A2DPStream : public AudioStream {
78
+ class A2DPStream : public AudioStream , public AudioBaseInfoSource {
79
79
80
80
public:
81
81
// Release the allocate a2dp_source or a2dp_sink
@@ -142,6 +142,7 @@ class A2DPStream : public AudioStream {
142
142
delay (1000 );
143
143
}
144
144
LOGI (" a2dp_source is connected..." );
145
+ notifyBaseInfo (44100 );
145
146
// is_a2dp_active = true;
146
147
break ;
147
148
@@ -151,6 +152,7 @@ class A2DPStream : public AudioStream {
151
152
a2dp_sink->set_stream_reader (&a2dp_stream_sink_sound_data, false );
152
153
a2dp_sink->start ((char *)cfg.name );
153
154
a2dp_sink->set_on_connection_state_changed (a2dpStateCallback, this );
155
+ a2dp_sink->set_sample_rate_callback (sample_rate_callback);
154
156
while (!a2dp_sink->is_connected ()){
155
157
LOGD (" waiting for connection" );
156
158
delay (1000 );
@@ -257,11 +259,17 @@ class A2DPStream : public AudioStream {
257
259
a2dp->set_volume (volume * 100 );
258
260
}
259
261
262
+ virtual void setNotifyAudioChange (AudioBaseInfoDependent &bi) {
263
+ audioBaseInfoDependent = &bi;
264
+ }
265
+
266
+
260
267
protected:
261
268
A2DPConfig config;
262
269
BluetoothA2DPSource *a2dp_source = nullptr ;
263
270
BluetoothA2DPSink *a2dp_sink = nullptr ;
264
271
BluetoothA2DPCommon *a2dp=nullptr ;
272
+ AudioBaseInfoDependent *audioBaseInfoDependent=nullptr ;
265
273
int volume;
266
274
// semaphore to synchronize acess to the buffer
267
275
SemaphoreHandle_t xSemaphore = NULL ;
@@ -343,7 +351,7 @@ class A2DPStream : public AudioStream {
343
351
return result_len;
344
352
}
345
353
346
- // callback used by A2DP to write the sound data
354
+ // / callback used by A2DP to write the sound data
347
355
static void a2dp_stream_sink_sound_data (const uint8_t * data, uint32_t len) {
348
356
if (is_a2dp_active && a2dp_buffer!=nullptr ){
349
357
uint32_t result_len = a2dp_buffer->writeArray (data, len);
@@ -353,6 +361,24 @@ class A2DPStream : public AudioStream {
353
361
}
354
362
}
355
363
364
+ // / notify subscriber with AudioBaseInfo
365
+ void notifyBaseInfo (int rate){
366
+ if (audioBaseInfoDependent!=nullptr ){
367
+ AudioBaseInfo info;
368
+ info.channels = 2 ;
369
+ info.bits_per_sample = 16 ;
370
+ info.sample_rate = rate;
371
+ audioBaseInfoDependent->setAudioInfo (info);
372
+ }
373
+ }
374
+
375
+ // / callback to update audio info with used a2dp sample rate
376
+ static void sample_rate_callback (uint16_t rate) {
377
+ if (A2DPStream_self->audioBaseInfoDependent !=nullptr ){
378
+ A2DPStream_self->notifyBaseInfo (rate);
379
+ }
380
+ }
381
+
356
382
};
357
383
358
384
0 commit comments