@@ -75,7 +75,7 @@ class A2DPConfig {
7575 *
7676 * Because we support only one instance the class is implemented as singleton!
7777 */
78- class A2DPStream : public AudioStream {
78+ class A2DPStream : public AudioStream , public AudioBaseInfoSource {
7979
8080 public:
8181 // Release the allocate a2dp_source or a2dp_sink
@@ -142,6 +142,7 @@ class A2DPStream : public AudioStream {
142142 delay (1000 );
143143 }
144144 LOGI (" a2dp_source is connected..." );
145+ notifyBaseInfo (44100 );
145146 // is_a2dp_active = true;
146147 break ;
147148
@@ -151,6 +152,7 @@ class A2DPStream : public AudioStream {
151152 a2dp_sink->set_stream_reader (&a2dp_stream_sink_sound_data, false );
152153 a2dp_sink->start ((char *)cfg.name );
153154 a2dp_sink->set_on_connection_state_changed (a2dpStateCallback, this );
155+ a2dp_sink->set_sample_rate_callback (sample_rate_callback);
154156 while (!a2dp_sink->is_connected ()){
155157 LOGD (" waiting for connection" );
156158 delay (1000 );
@@ -257,11 +259,17 @@ class A2DPStream : public AudioStream {
257259 a2dp->set_volume (volume * 100 );
258260 }
259261
262+ virtual void setNotifyAudioChange (AudioBaseInfoDependent &bi) {
263+ audioBaseInfoDependent = &bi;
264+ }
265+
266+
260267 protected:
261268 A2DPConfig config;
262269 BluetoothA2DPSource *a2dp_source = nullptr ;
263270 BluetoothA2DPSink *a2dp_sink = nullptr ;
264271 BluetoothA2DPCommon *a2dp=nullptr ;
272+ AudioBaseInfoDependent *audioBaseInfoDependent=nullptr ;
265273 int volume;
266274 // semaphore to synchronize acess to the buffer
267275 SemaphoreHandle_t xSemaphore = NULL ;
@@ -343,7 +351,7 @@ class A2DPStream : public AudioStream {
343351 return result_len;
344352 }
345353
346- // callback used by A2DP to write the sound data
354+ // / callback used by A2DP to write the sound data
347355 static void a2dp_stream_sink_sound_data (const uint8_t * data, uint32_t len) {
348356 if (is_a2dp_active && a2dp_buffer!=nullptr ){
349357 uint32_t result_len = a2dp_buffer->writeArray (data, len);
@@ -353,6 +361,24 @@ class A2DPStream : public AudioStream {
353361 }
354362 }
355363
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+
356382};
357383
358384
0 commit comments