Skip to content

Commit 2348051

Browse files
authored
A2DPSink: Remove stubs, fix volume and connect callbacks (#2757)
* A2DPSink: Remove Stream implementation and onTransmit * A2DPSink: Fix onConnect and onVolume callbacks * A2DPSink: Remove transmit callback field
1 parent b4001bf commit 2348051

File tree

2 files changed

+9
-39
lines changed

2 files changed

+9
-39
lines changed

libraries/BluetoothAudio/src/A2DPSink.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,9 @@ void A2DPSink::avrcp_target_packet_handler(uint8_t packet_type, uint16_t channel
676676
volume_percentage = volume * 100 / 127;
677677
DEBUGV("AVRCP Target : Volume set to %d%% (%d)\n", volume_percentage, volume);
678678
_consumer->setVolume(volume);
679+
if (_volumeCB) {
680+
_volumeCB(_volumeData, volume);
681+
}
679682
break;
680683

681684
case AVRCP_SUBEVENT_OPERATION:
@@ -773,6 +776,11 @@ void A2DPSink::a2dp_sink_packet_handler(uint8_t packet_type, uint16_t channel, u
773776
DEBUGV("A2DP Sink : Streaming connection is established, address %s, cid 0x%02x, local seid %d\n",
774777
bd_addr_to_str(a2dp_conn->addr), a2dp_conn->a2dp_cid, a2dp_conn->a2dp_local_seid);
775778
memcpy(_sourceAddress, a2dp_conn->addr, sizeof(_sourceAddress));
779+
780+
_connected = true;
781+
if (_connectCB) {
782+
_connectCB(_connectData, true);
783+
}
776784
break;
777785

778786
case A2DP_SUBEVENT_STREAM_STARTED:
@@ -784,10 +792,6 @@ void A2DPSink::a2dp_sink_packet_handler(uint8_t packet_type, uint16_t channel, u
784792
// prepare media processing
785793
media_processing_init(&a2dp_conn->sbc_configuration);
786794
// audio stream is started when buffer reaches minimal level
787-
_connected = true;
788-
if (_connectCB) {
789-
_connectCB(_connectData, true);
790-
}
791795
break;
792796

793797
case A2DP_SUBEVENT_STREAM_SUSPENDED:

libraries/BluetoothAudio/src/A2DPSink.h

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,14 @@
3030
#include "btstack_resample.h"
3131
#include "btstack_ring_buffer.h"
3232

33-
class A2DPSink : public Stream {
33+
class A2DPSink {
3434
public:
3535
A2DPSink() {
3636
_title[0] = 0;
3737
_artist[0] = 0;
3838
_album[0] = 0;
3939
_genre[0] = 0;
4040
}
41-
virtual int available() override {
42-
return 0; // Unreadable, this is output only
43-
}
44-
45-
virtual int read() override {
46-
return 0;
47-
}
48-
49-
virtual int peek() override {
50-
return 0;
51-
}
52-
53-
virtual void flush() override {
54-
}
55-
virtual size_t write(const uint8_t *buffer, size_t size) override {
56-
(void) buffer;
57-
(void) size;
58-
return 0;
59-
}
60-
virtual int availableForWrite() override {
61-
return 0;
62-
}
63-
64-
virtual size_t write(uint8_t s) override {
65-
(void) s;
66-
return 0;
67-
}
6841

6942
bool setName(const char *name) {
7043
if (_running) {
@@ -75,11 +48,6 @@ class A2DPSink : public Stream {
7548
return true;
7649
}
7750

78-
void onTransmit(void (*cb)(void *), void *cbData = nullptr) {
79-
_transmitCB = cb;
80-
_transmitData = cbData;
81-
}
82-
8351
void onAVRCP(void (*cb)(void *, avrcp_operation_id_t, int), void *cbData = nullptr) {
8452
_avrcpCB = cb;
8553
_avrcpData = cbData;
@@ -237,8 +205,6 @@ class A2DPSink : public Stream {
237205
bool _connected = false;
238206

239207
// Callbacks
240-
void (*_transmitCB)(void *) = nullptr;
241-
void *_transmitData;
242208
void (*_avrcpCB)(void *, avrcp_operation_id_t, int) = nullptr;
243209
void *_avrcpData;
244210
void (*_batteryCB)(void *, avrcp_battery_status_t) = nullptr;

0 commit comments

Comments
 (0)