Arduino A2DP

Loading...
Searching...
No Matches
BluetoothA2DPSink.h
1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4
5// http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12//
13// Copyright 2020 Phil Schatzmann
14// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
15
16#pragma once
17#include "BluetoothA2DPCommon.h"
18#if IS_VALID_PLATFORM
19
20#include "BluetoothA2DPOutput.h"
21#include "freertos/ringbuf.h"
22
23// Comment out next line to deactivate warnings
24#ifndef A2DP_I2S_AUDIOTOOLS
25#warning "AudioTools library is not included first or installed"
26#endif
27
28#define APP_SIG_WORK_DISPATCH (0x01)
29
30#ifndef BT_AV_TAG
31#define BT_AV_TAG "BT_AV"
32#endif
33
34#if (A2DP_SPP_SUPPORT && ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0))
35#include "esp_spp_api.h"
36#endif
37
38/* @brief event for handler "bt_av_hdl_stack_up */
39 enum {
40 BT_APP_EVT_STACK_UP = 0,
41};
42
43 extern "C" void ccall_i2s_task_handler(void *arg);
44 extern "C" void ccall_audio_data_callback(const uint8_t *data, uint32_t len);
45 extern "C" void ccall_av_hdl_a2d_evt(uint16_t event, void *p_param);
46 extern "C" void ccall_av_hdl_avrc_evt(uint16_t event, void *p_param);
47#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0)
48 extern "C" void ccall_audio_encoded_callback(esp_a2d_conn_hdl_t conn_hdl, esp_a2d_audio_buff_t *audio_buf);
49#endif
50
52 enum PinCodeRequest { Undefined, Confirm, Reply };
53
55 enum A2DPCodec { A2DP_CODEC_SBC, A2DP_CODEC_M12, A2DP_CODEC_AAC, A2DP_CODEC_ATRAC };
56
57// provide global ref for callbacks
58 class BluetoothA2DPSink;
59 extern BluetoothA2DPSink *actual_bluetooth_a2dp_sink;
60
71 class BluetoothA2DPSink : public BluetoothA2DPCommon {
73 friend void ccall_i2s_task_handler(void *arg);
75 friend void ccall_audio_data_callback(const uint8_t *data, uint32_t len);
77 friend void ccall_av_hdl_a2d_evt(uint16_t event, void *p_param);
79 friend void ccall_av_hdl_avrc_evt(uint16_t event, void *p_param);
80#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0)
81 friend void ccall_audio_encoded_callback(esp_a2d_conn_hdl_t conn_hdl, esp_a2d_audio_buff_t *audio_buf);
82#endif
83
84 public:
86 BluetoothA2DPSink();
87
89 BluetoothA2DPSink(BluetoothA2DPOutput &out) : BluetoothA2DPSink() {
90 set_output(out);
91 }
92
93#if A2DP_I2S_AUDIOTOOLS
95 BluetoothA2DPSink(audio_tools::AudioOutput &output) : BluetoothA2DPSink() {
96 set_output(output);
97 }
99 BluetoothA2DPSink(audio_tools::AudioStream &output) : BluetoothA2DPSink(){
100 set_output(output);
101 }
102#endif
103
104#ifdef ARDUINO
106 BluetoothA2DPSink(Print &output) : BluetoothA2DPSink() {
107 set_output(output);
108 }
109#endif
110
112 virtual ~BluetoothA2DPSink();
113
114#if A2DP_LEGACY_I2S_SUPPORT
116 virtual void set_pin_config(i2s_pin_config_t pin_config) {
117 out->set_pin_config(pin_config);
118 }
119
121 virtual void set_i2s_port(i2s_port_t i2s_num) { out->set_i2s_port(i2s_num); }
122
124 virtual void set_i2s_config(i2s_config_t i2s_config) {
125 out->set_i2s_config(i2s_config);
126 }
127
130 virtual void set_channels(i2s_channel_t channels) {
131 set_mono_downmix(channels == I2S_CHANNEL_MONO);
132 }
133
136 virtual void set_bits_per_sample(int bps) { out->set_bits_per_sample(bps); }
137
138#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 1)
139 virtual esp_err_t i2s_mclk_pin_select(const uint8_t pin) {
140 return out->i2s_mclk_pin_select(pin);
141 }
142#endif
143
144#endif
145
147 void set_output(BluetoothA2DPOutput &output) { out = &output; }
148
150 BluetoothA2DPOutput *get_output() { return out; }
151
152#ifdef ARDUINO
154 void set_output(Print &output) {
155 static BluetoothA2DPOutputPrint s_out;
156 out = &s_out;
157 out->set_output(output);
158 }
159#endif
160
161#if A2DP_I2S_AUDIOTOOLS
163 void set_output(audio_tools::AudioOutput &output) { out->set_output(output); }
165 void set_output(audio_tools::AudioStream &output) { out->set_output(output); }
166#endif
167
169 virtual void start(const char *name, bool auto_reconect);
170
172 virtual void start(const char *name);
173
176 virtual void end(bool release_memory = false);
177
179 virtual esp_a2d_mct_t get_audio_type();
180
181 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0)
185 bool set_codec(A2DPCodec codec, void (*encoded_cb)(const uint8_t *data, size_t len) = nullptr);
186 #endif
187
189 virtual void set_avrc_connection_state_callback(void (*callback)(bool)) {
190 this->avrc_connection_state_callback = callback;
191 }
192
194 virtual void set_avrc_metadata_callback(void (*callback)(uint8_t,
195 const uint8_t *)) {
196 this->avrc_metadata_callback = callback;
197 }
198
199#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
202 virtual void set_avrc_rn_playstatus_callback(
203 void (*callback)(esp_avrc_playback_stat_t playback)) {
204 this->avrc_rn_playstatus_callback = callback;
205 }
208 virtual void set_avrc_rn_play_pos_callback(
209 void (*callback)(uint32_t play_pos), uint32_t notif_interval = 10) {
210 this->avrc_rn_play_pos_callback = callback;
211 this->notif_interval_s = std::max(notif_interval, (uint32_t)1);
212 }
216 virtual void set_avrc_rn_track_change_callback(
217 void (*callback)(uint8_t *id)) {
218 this->avrc_rn_track_change_callback = callback;
219 }
220#endif
221
223 virtual void set_sample_rate_callback(void (*callback)(uint16_t rate)) {
224 this->sample_rate_callback = callback;
225 }
226
229 virtual void set_stream_reader(void (*callBack)(const uint8_t *, uint32_t),
230 bool i2s_output = true);
231
232
235 virtual void set_raw_stream_reader(void (*callBack)(const uint8_t *,
236 uint32_t));
237
239 virtual void set_on_data_received(void (*callBack)());
240
242 virtual void set_address_validator(
243 bool (*callBack)(esp_bd_addr_t remote_bda)) {
244 address_validator = callBack;
245 }
246
248 virtual bool is_avrc_connected();
249
251 virtual void set_volume(uint8_t volume);
252
254 virtual int get_volume();
255
258 virtual void set_on_volumechange(void (*callBack)(int));
259
261 virtual void set_avrc_rn_volumechange(void (*callBack)(int));
262
265 virtual void set_avrc_rn_volumechange_completed(void (*callBack)(int));
266
268 virtual void play();
270 virtual void pause();
272 virtual void stop();
274 virtual void next();
276 virtual void previous();
278 virtual void fast_forward();
280 virtual void rewind();
282 virtual void volume_up();
284 virtual void volume_down();
285
287 virtual void set_mono_downmix(bool enabled) {
288 volume_control()->set_mono_downmix(enabled);
289 }
290
292 virtual uint16_t sample_rate() { return m_sample_rate; }
293
295 virtual uint16_t channels() { return m_channels; }
296
298 virtual void activate_pin_code(bool active);
299
301 virtual void confirm_pin_code();
302
304 virtual void confirm_pin_code(int code);
305
307 virtual int pin_code() { return pin_code_int; }
308
313 virtual void set_avrc_metadata_attribute_mask(int flags) {
314 avrc_metadata_flags = flags;
315 }
316
318 virtual void set_swap_lr_channels(bool swap) { swap_left_right = swap; }
319
322 virtual void set_auto_reconnect(bool reconnect,
323 int count = AUTOCONNECT_TRY_NUM) {
324 reconnect_status = reconnect ? AutoReconnect : NoReconnect;
325 try_reconnect_max_count = count;
326 }
327
329 virtual esp_bd_addr_t *get_current_peer_address() { return &peer_bd_addr; }
330
332 void set_rssi_active(bool active) { rssi_active = active; }
333
335 bool update_rssi() {
336 if (!rssi_active) return false;
337 return esp_bt_gap_read_rssi_delta(*get_current_peer_address()) == ESP_OK;
338 }
339
341 esp_bt_gap_cb_param_t::read_rssi_delta_param get_last_rssi() {
342 return last_rssi_delta;
343 }
344
346 void set_rssi_callback(
347 void (*callback)(esp_bt_gap_cb_param_t::read_rssi_delta_param &rssi)) {
348 rssi_callback = callback;
349 }
350
352 void set_peer_name_callback(
353 void (*callback)(char *peer_name)) {
354 peer_name_callback = callback;
355 }
356
359 void set_reconnect_delay(int delay) { reconnect_delay = delay; }
360
362 void set_spp_active(bool flag) { spp_active = flag; }
363
364#if (A2DP_SPP_SUPPORT && ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0))
366 void set_spp_config(esp_spp_cfg_t cfg) {
367 spp_cfg = cfg;
368 }
369#endif
370
371
373 void set_output_active(bool flag) { is_i2s_active = flag; }
374
376 bool is_output_active() { return is_i2s_active; }
377
379 void set_max_write_size(int size) { max_write_size = size; }
380
382 void set_max_write_delay_ms(int delay) { max_write_delay_ms = delay; }
383
384#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
387 bool is_avrc_peer_rn_cap(esp_avrc_rn_event_ids_t cmd) {
388 return esp_avrc_rn_evt_bit_mask_operation(ESP_AVRC_BIT_MASK_OP_TEST,
389 &s_avrc_peer_rn_cap, cmd);
390 }
392 bool is_avrc_peer_rn_cap_available() { return s_avrc_peer_rn_cap.bits != 0; }
393
395 virtual const char *get_peer_name() { return get_connected_source_name(); }
396
397#endif
398
399 protected:
400 BluetoothA2DPOutputDefault out_default;
401 BluetoothA2DPOutput *out = &out_default;
402
403 volatile bool is_i2s_active = false;
404 // activate output via BluetoothA2DPOutput
405 bool is_output = true;
406 uint16_t m_sample_rate = 44100; // set default rate
407 // number of PCM channels negotiated (1=mono,2=stereo). Default 2.
408 uint8_t m_channels = 2;
409 uint32_t m_pkt_cnt = 0;
410 // esp_a2d_audio_state_t m_audio_state = ESP_A2D_AUDIO_STATE_STOPPED;
411 esp_a2d_mct_t audio_type;
412 char pin_code_str[20] = {0};
413 int connection_rety_count = 0;
414#if A2DP_SPP_SUPPORT
415 bool spp_active = false;
416# if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0))
417 esp_spp_mode_t esp_spp_mode = ESP_SPP_MODE_CB;
418# else
419 esp_spp_cfg_t spp_cfg = BT_SPP_DEFAULT_CONFIG();
420# endif
421#endif
422 _lock_t s_volume_lock;
423 uint8_t s_volume = 0;
424 bool s_volume_notify;
425 int pin_code_int = 0;
426 PinCodeRequest pin_code_request = Undefined;
427 bool is_pin_code_active = false;
428 bool avrc_connection_state = false;
429 int avrc_metadata_flags =
430 ESP_AVRC_MD_ATTR_TITLE | ESP_AVRC_MD_ATTR_ARTIST |
431 ESP_AVRC_MD_ATTR_ALBUM | ESP_AVRC_MD_ATTR_TRACK_NUM |
432 ESP_AVRC_MD_ATTR_NUM_TRACKS | ESP_AVRC_MD_ATTR_GENRE;
433 void (*bt_volumechange)(int) = nullptr;
434 void (*bt_dis_connected)() = nullptr;
435 void (*bt_connected)() = nullptr;
436 void (*data_received)() = nullptr;
437 void (*stream_reader)(const uint8_t *, uint32_t) = nullptr;
438 void (*encoded_stream_reader)(const uint8_t *, size_t) = nullptr;
439 void (*raw_stream_reader)(const uint8_t *, uint32_t) = nullptr;
440 void (*avrc_connection_state_callback)(bool connected) = nullptr;
441 void (*avrc_metadata_callback)(uint8_t, const uint8_t *) = nullptr;
442#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
443 void (*avrc_rn_playstatus_callback)(esp_avrc_playback_stat_t) = nullptr;
444 void (*avrc_rn_track_change_callback)(uint8_t *) = nullptr;
445 void (*avrc_rn_play_pos_callback)(uint32_t) = nullptr;
446 uint32_t notif_interval_s = 10;
447#endif
448 void (*avrc_rn_volchg_complete_callback)(int) = nullptr;
449 bool (*address_validator)(esp_bd_addr_t remote_bda) = nullptr;
450 void (*sample_rate_callback)(uint16_t rate) = nullptr;
451 bool swap_left_right = false;
452 int try_reconnect_max_count = AUTOCONNECT_TRY_NUM;
453
454 // RSSI support
455 esp_bt_gap_cb_param_t::read_rssi_delta_param last_rssi_delta;
456 bool rssi_active = false;
457 void (*rssi_callback)(esp_bt_gap_cb_param_t::read_rssi_delta_param &rssi) =
458 nullptr;
459 void (*peer_name_callback)(char *peer_name) =
460 nullptr;
461 int reconnect_delay = 1000;
462 int max_write_size = A2DP_I2S_MAX_WRITE_SIZE;
463 int max_write_delay_ms = A2DP_I2S_MAX_WRITE_DELAY_MS;
464
465#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
466 esp_avrc_rn_evt_cap_mask_t s_avrc_peer_rn_cap = {0};
467 char remote_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1];
468#endif
469#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0)
470 A2DPCodec desired_codec = A2DP_CODEC_SBC;
471 bool codec_sep_registered = false;
472#endif
473
474 void app_gap_callback(esp_bt_gap_cb_event_t event,
475 esp_bt_gap_cb_param_t *param) override;
476 void app_rc_ct_callback(esp_avrc_ct_cb_event_t event,
477 esp_avrc_ct_cb_param_t *param) override;
478 void app_a2d_callback(esp_a2d_cb_event_t event,
479 esp_a2d_cb_param_t *param) override;
480 void av_hdl_stack_evt(uint16_t event, void *p_param) override;
481
482 virtual int init_bluetooth();
483 virtual bool app_work_dispatch(app_callback_t p_cback, uint16_t event,
484 void *p_params, int param_len);
485 virtual void app_alloc_meta_buffer(esp_avrc_ct_cb_param_t *param);
486 virtual void av_new_track();
487 virtual void av_playback_changed();
488 virtual void av_play_pos_changed();
489 // execute AVRC command
490 virtual void execute_avrc_command(int cmd);
491
492 virtual const char *last_bda_nvs_name() { return "last_bda"; }
493
494 virtual bool is_reconnect(esp_a2d_disc_rsn_t type) {
495 bool result = is_autoreconnect_allowed &&
496 (reconnect_status == AutoReconnect ||
497 reconnect_status == IsReconnecting) &&
498 has_last_connection();
499 ESP_LOGI(BT_AV_TAG, "is_reconnect: %s", result ? "true" : "false");
500 return result;
501 }
502
506 // Callback for music stream
507 virtual void audio_data_callback(const uint8_t *data, uint32_t len);
508 // a2dp event handler
509 virtual void av_hdl_a2d_evt(uint16_t event, void *p_param);
510 // avrc event handler
511 virtual void av_hdl_avrc_evt(uint16_t event, void *p_param);
512
513 // split up long handlers
514 virtual void handle_connection_state(uint16_t event, void *p_param);
515 virtual void handle_audio_state(uint16_t event, void *p_param);
516 virtual void handle_audio_cfg(uint16_t event, void *p_param);
517 virtual void handle_avrc_connection_state(bool connected);
518
519#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
521 virtual const char *get_connected_source_name();
522 virtual void volume_set_by_local_host(uint8_t volume);
523 virtual void volume_set_by_controller(uint8_t volume);
524 virtual void av_notify_evt_handler(uint8_t event_id,
525 esp_avrc_rn_param_t *event_parameter);
526 virtual void app_rc_tg_callback(esp_avrc_tg_cb_event_t event,
527 esp_avrc_tg_cb_param_t *param) override;
528 virtual void av_hdl_avrc_tg_evt(uint16_t event, void *p_param) override;
529#else
530 virtual void av_notify_evt_handler(uint8_t event_id,
531 uint32_t event_parameter);
532#endif
533
534 virtual void init_i2s();
535
537 virtual size_t write_audio(const uint8_t *data, size_t size) {
538 return i2s_write_data(data, size);
539 }
540
542 size_t i2s_write_data(const uint8_t *data, size_t item_size);
543
545 virtual void i2s_task_handler(void *arg) {}
546 virtual void bt_i2s_task_start_up(void) {}
547 virtual void bt_i2s_task_shut_down(void) {}
548
549 esp_err_t esp_a2d_connect(esp_bd_addr_t peer) override {
550 return esp_a2d_sink_connect(peer);
551 }
552 esp_err_t esp_a2d_disconnect(esp_bd_addr_t remote_bda) override {
553 return esp_a2d_sink_disconnect(remote_bda);
554 }
555
556 void set_scan_mode_connectable_default() override {
557 set_scan_mode_connectable(true);
558 }
559
560 virtual void set_i2s_active(bool active);
561
562 virtual bool isSource() { return false; }
563
564};
565
566#endif // platform
BluetoothA2DPCommon.h
app_callback_t
void(* app_callback_t)(uint16_t event, void *param)
handler for the dispatched work
Definition BluetoothA2DPCommon.h:124
A2DPVolumeControl::set_mono_downmix
void set_mono_downmix(bool enabled)
Enables or disables mono downmix.
Definition A2DPVolumeControl.h:118
BluetoothA2DPCommon
Common Bluetooth A2DP functions.
Definition BluetoothA2DPCommon.h:173
BluetoothA2DPCommon::volume_control
virtual A2DPVolumeControl * volume_control()
provides access to the VolumeControl object
Definition BluetoothA2DPCommon.h:410
BluetoothA2DPCommon::reconnect
virtual bool reconnect()
Reconnects to the last device.
Definition BluetoothA2DPCommon.cpp:87
BluetoothA2DPCommon::set_scan_mode_connectable
virtual void set_scan_mode_connectable(bool connectable)
Defines if the bluetooth is connectable.
Definition BluetoothA2DPCommon.cpp:552
BluetoothA2DPOutputDefault
Default Output Class providing both the Legacy I2S and the AudioTools I2S functionality.
Definition BluetoothA2DPOutput.h:203
BluetoothA2DPOutput
Abstract Output Class.
Definition BluetoothA2DPOutput.h:22
BluetoothA2DPOutput::set_output
virtual void set_output(audio_tools::AudioOutput &output)
Not implemented.
Definition BluetoothA2DPOutput.h:32
BluetoothA2DPOutputPrint
Output Class using Print API:
Definition BluetoothA2DPOutput.h:126
BluetoothA2DPSink
A2DP Bluethooth Sink - We initialize and start the Bluetooth A2DP Sink. The example https://github....
Definition BluetoothA2DPSink.h:71
BluetoothA2DPSink::set_raw_stream_reader
virtual void set_raw_stream_reader(void(*callBack)(const uint8_t *, uint32_t))
Definition BluetoothA2DPSink.cpp:109
BluetoothA2DPSink::~BluetoothA2DPSink
virtual ~BluetoothA2DPSink()
Destructor - stops the playback and releases all resources.
Definition BluetoothA2DPSink.cpp:79
BluetoothA2DPSink::set_swap_lr_channels
virtual void set_swap_lr_channels(bool swap)
swaps the left and right channel
Definition BluetoothA2DPSink.h:318
BluetoothA2DPSink::set_output
void set_output(BluetoothA2DPOutput &output)
Defines the output class: by default we use BluetoothA2DPOutputDefault.
Definition BluetoothA2DPSink.h:147
BluetoothA2DPSink::activate_pin_code
virtual void activate_pin_code(bool active)
We need to confirm a new seesion by calling confirm_pin_code()
Definition BluetoothA2DPSink.cpp:1260
BluetoothA2DPSink::next
virtual void next()
AVRC next.
Definition BluetoothA2DPSink.cpp:1222
BluetoothA2DPSink::BluetoothA2DPSink
BluetoothA2DPSink()
Default Constructor: output via callback or Legacy I2S.
Definition BluetoothA2DPSink.cpp:69
BluetoothA2DPSink::audio_data_callback
virtual void audio_data_callback(const uint8_t *data, uint32_t len)
Definition BluetoothA2DPSink.cpp:1152
BluetoothA2DPSink::get_connected_source_name
virtual const char * get_connected_source_name()
Get the name of the connected source device (obsolete): use get_peer_name()
Definition BluetoothA2DPSink.cpp:296
BluetoothA2DPSink::ccall_av_hdl_avrc_evt
friend void ccall_av_hdl_avrc_evt(uint16_t event, void *p_param)
avrc event handler
Definition BluetoothA2DPSink.cpp:35
BluetoothA2DPSink::previous
virtual void previous()
AVRC previous.
Definition BluetoothA2DPSink.cpp:1225
BluetoothA2DPSink::pin_code
virtual int pin_code()
provides the requested pin code (0 = undefined)
Definition BluetoothA2DPSink.h:307
BluetoothA2DPSink::stop
virtual void stop()
AVRC stop.
Definition BluetoothA2DPSink.cpp:1220
BluetoothA2DPSink::update_rssi
bool update_rssi()
Requests an update of the rssi delta value.
Definition BluetoothA2DPSink.h:335
BluetoothA2DPSink::set_max_write_delay_ms
void set_max_write_delay_ms(int delay)
defines a small delay after each write: default is 0 ms
Definition BluetoothA2DPSink.h:382
BluetoothA2DPSink::volume_up
virtual void volume_up()
AVRC increase the volume.
Definition BluetoothA2DPSink.cpp:1235
BluetoothA2DPSink::fast_forward
virtual void fast_forward()
AVRC fast_forward.
Definition BluetoothA2DPSink.cpp:1228
BluetoothA2DPSink::set_rssi_active
void set_rssi_active(bool active)
Activates the rssi reporting.
Definition BluetoothA2DPSink.h:332
BluetoothA2DPSink::is_avrc_connected
virtual bool is_avrc_connected()
returns true if the avrc service is connected
Definition BluetoothA2DPSink.cpp:1192
BluetoothA2DPSink::set_stream_reader
virtual void set_stream_reader(void(*callBack)(const uint8_t *, uint32_t), bool i2s_output=true)
Definition BluetoothA2DPSink.cpp:102
BluetoothA2DPSink::set_volume
virtual void set_volume(uint8_t volume)
Changes the volume.
Definition BluetoothA2DPSink.cpp:1243
BluetoothA2DPSink::channels
virtual uint16_t channels()
Provides the actually set number of channels (1=mono,2=stereo)
Definition BluetoothA2DPSink.h:295
BluetoothA2DPSink::get_last_rssi
esp_bt_gap_cb_param_t::read_rssi_delta_param get_last_rssi()
provides the last rssi parameters
Definition BluetoothA2DPSink.h:341
BluetoothA2DPSink::end
virtual void end(bool release_memory=false)
Definition BluetoothA2DPSink.cpp:85
BluetoothA2DPSink::set_output
void set_output(audio_tools::AudioOutput &output)
Output AudioOutput using AudioTools library.
Definition BluetoothA2DPSink.h:163
BluetoothA2DPSink::confirm_pin_code
virtual void confirm_pin_code()
confirms the connection request by returning the receivedn pin code
Definition BluetoothA2DPSink.cpp:1264
BluetoothA2DPSink::set_avrc_rn_play_pos_callback
virtual void set_avrc_rn_play_pos_callback(void(*callback)(uint32_t play_pos), uint32_t notif_interval=10)
Definition BluetoothA2DPSink.h:208
BluetoothA2DPSink::set_avrc_rn_playstatus_callback
virtual void set_avrc_rn_playstatus_callback(void(*callback)(esp_avrc_playback_stat_t playback))
Definition BluetoothA2DPSink.h:202
BluetoothA2DPSink::set_mono_downmix
virtual void set_mono_downmix(bool enabled)
mix stereo into single mono signal
Definition BluetoothA2DPSink.h:287
BluetoothA2DPSink::BluetoothA2DPSink
BluetoothA2DPSink(audio_tools::AudioStream &output)
Output AudioStream using AudioTools library.
Definition BluetoothA2DPSink.h:99
BluetoothA2DPSink::set_output
void set_output(audio_tools::AudioStream &output)
Output AudioStream using AudioTools library.
Definition BluetoothA2DPSink.h:165
BluetoothA2DPSink::set_output_active
void set_output_active(bool flag)
Activate/Deactivate output e.g. to I2S.
Definition BluetoothA2DPSink.h:373
BluetoothA2DPSink::is_output_active
bool is_output_active()
Checks if output is active.
Definition BluetoothA2DPSink.h:376
BluetoothA2DPSink::get_peer_name
virtual const char * get_peer_name()
Get the name of the connected source device.
Definition BluetoothA2DPSink.h:395
BluetoothA2DPSink::get_audio_type
virtual esp_a2d_mct_t get_audio_type()
Determine the actual audio type.
Definition BluetoothA2DPSink.cpp:216
BluetoothA2DPSink::BluetoothA2DPSink
BluetoothA2DPSink(Print &output)
Output to Arduino Print.
Definition BluetoothA2DPSink.h:106
BluetoothA2DPSink::app_rc_ct_callback
void app_rc_ct_callback(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param) override
callback function for AVRCP controller
Definition BluetoothA2DPSink.cpp:483
BluetoothA2DPSink::is_avrc_peer_rn_cap_available
bool is_avrc_peer_rn_cap_available()
Returns true if the is_avrc_peer_rn_cap() method can be called.
Definition BluetoothA2DPSink.h:392
BluetoothA2DPSink::set_avrc_metadata_attribute_mask
virtual void set_avrc_metadata_attribute_mask(int flags)
Definition BluetoothA2DPSink.h:313
BluetoothA2DPSink::get_current_peer_address
virtual esp_bd_addr_t * get_current_peer_address()
Provides the address of the connected device.
Definition BluetoothA2DPSink.h:329
BluetoothA2DPSink::set_sample_rate_callback
virtual void set_sample_rate_callback(void(*callback)(uint16_t rate))
Defines the method which will be called with the sample rate is updated.
Definition BluetoothA2DPSink.h:223
BluetoothA2DPSink::set_max_write_size
void set_max_write_size(int size)
defines the max write size: default is A2DP_I2S_MAX_WRITE_SIZE
Definition BluetoothA2DPSink.h:379
BluetoothA2DPSink::sample_rate
virtual uint16_t sample_rate()
Provides the actually set data rate (in samples per second)
Definition BluetoothA2DPSink.h:292
BluetoothA2DPSink::set_reconnect_delay
void set_reconnect_delay(int delay)
Definition BluetoothA2DPSink.h:359
BluetoothA2DPSink::get_output
BluetoothA2DPOutput * get_output()
Provides access to the output class.
Definition BluetoothA2DPSink.h:150
BluetoothA2DPSink::set_rssi_callback
void set_rssi_callback(void(*callback)(esp_bt_gap_cb_param_t::read_rssi_delta_param &rssi))
Defines the callback that is called when we get an new rssi value.
Definition BluetoothA2DPSink.h:346
BluetoothA2DPSink::app_a2d_callback
void app_a2d_callback(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param) override
callback function for A2DP source
Definition BluetoothA2DPSink.cpp:1114
BluetoothA2DPSink::ccall_av_hdl_a2d_evt
friend void ccall_av_hdl_a2d_evt(uint16_t event, void *p_param)
a2dp event handler
Definition BluetoothA2DPSink.cpp:42
BluetoothA2DPSink::set_avrc_rn_volumechange_completed
virtual void set_avrc_rn_volumechange_completed(void(*callBack)(int))
Definition BluetoothA2DPSink.cpp:127
BluetoothA2DPSink::BluetoothA2DPSink
BluetoothA2DPSink(audio_tools::AudioOutput &output)
Output AudioOutput using AudioTools library.
Definition BluetoothA2DPSink.h:95
BluetoothA2DPSink::rewind
virtual void rewind()
AVRC rewind.
Definition BluetoothA2DPSink.cpp:1231
BluetoothA2DPSink::write_audio
virtual size_t write_audio(const uint8_t *data, size_t size)
output audio data e.g. to i2s or to queue
Definition BluetoothA2DPSink.h:537
BluetoothA2DPSink::pause
virtual void pause()
AVRC pause.
Definition BluetoothA2DPSink.cpp:1218
BluetoothA2DPSink::set_avrc_metadata_callback
virtual void set_avrc_metadata_callback(void(*callback)(uint8_t, const uint8_t *))
Define a callback method which provides the meta data.
Definition BluetoothA2DPSink.h:194
BluetoothA2DPSink::BluetoothA2DPSink
BluetoothA2DPSink(BluetoothA2DPOutput &out)
Define output scenario class.
Definition BluetoothA2DPSink.h:89
BluetoothA2DPSink::play
virtual void play()
Starts to play music using AVRC.
Definition BluetoothA2DPSink.cpp:1216
BluetoothA2DPSink::i2s_write_data
size_t i2s_write_data(const uint8_t *data, size_t item_size)
writes the data to i2s
Definition BluetoothA2DPSink.cpp:1293
BluetoothA2DPSink::set_spp_active
void set_spp_active(bool flag)
Activates SSP (Serial protocol)
Definition BluetoothA2DPSink.h:362
BluetoothA2DPSink::ccall_audio_data_callback
friend void ccall_audio_data_callback(const uint8_t *data, uint32_t len)
Callback for music stream.
Definition BluetoothA2DPSink.cpp:29
BluetoothA2DPSink::ccall_i2s_task_handler
friend void ccall_i2s_task_handler(void *arg)
task hander for i2s
Definition BluetoothA2DPSink.cpp:23
BluetoothA2DPSink::set_on_volumechange
virtual void set_on_volumechange(void(*callBack)(int))
Definition BluetoothA2DPSink.cpp:119
BluetoothA2DPSink::get_volume
virtual int get_volume()
Determines the volume.
Definition BluetoothA2DPSink.cpp:1255
BluetoothA2DPSink::set_avrc_rn_volumechange
virtual void set_avrc_rn_volumechange(void(*callBack)(int))
Set the callback that is called when remote changes the volume.
Definition BluetoothA2DPSink.cpp:123
BluetoothA2DPSink::set_address_validator
virtual void set_address_validator(bool(*callBack)(esp_bd_addr_t remote_bda))
Allows you to reject unauthorized addresses.
Definition BluetoothA2DPSink.h:242
BluetoothA2DPSink::set_avrc_rn_track_change_callback
virtual void set_avrc_rn_track_change_callback(void(*callback)(uint8_t *id))
Definition BluetoothA2DPSink.h:216
BluetoothA2DPSink::volume_down
virtual void volume_down()
AVRC decrease the volume.
Definition BluetoothA2DPSink.cpp:1239
BluetoothA2DPSink::set_peer_name_callback
void set_peer_name_callback(void(*callback)(char *peer_name))
Defines the callback that is called when we get the peer name.
Definition BluetoothA2DPSink.h:352
BluetoothA2DPSink::set_avrc_connection_state_callback
virtual void set_avrc_connection_state_callback(void(*callback)(bool))
Define a callback method which provides connection state of AVRC service.
Definition BluetoothA2DPSink.h:189
BluetoothA2DPSink::set_spp_config
void set_spp_config(esp_spp_cfg_t cfg)
Set SPP configuration (only before start)
Definition BluetoothA2DPSink.h:366
BluetoothA2DPSink::set_codec
bool set_codec(A2DPCodec codec, void(*encoded_cb)(const uint8_t *data, size_t len)=nullptr)
Definition BluetoothA2DPSink.cpp:220
BluetoothA2DPSink::is_avrc_peer_rn_cap
bool is_avrc_peer_rn_cap(esp_avrc_rn_event_ids_t cmd)
Definition BluetoothA2DPSink.h:387
BluetoothA2DPSink::set_on_data_received
virtual void set_on_data_received(void(*callBack)())
Define callback which is called when we receive data.
Definition BluetoothA2DPSink.cpp:114
BluetoothA2DPSink::set_auto_reconnect
virtual void set_auto_reconnect(bool reconnect, int count=AUTOCONNECT_TRY_NUM)
Definition BluetoothA2DPSink.h:322
BluetoothA2DPSink::start
virtual void start(const char *name, bool auto_reconect)
starts the I2S bluetooth sink with the inidicated name
Definition BluetoothA2DPSink.cpp:132
BluetoothA2DPSink::set_output
void set_output(Print &output)
Output to Arduino Print.
Definition BluetoothA2DPSink.h:154
BluetoothA2DPSink::i2s_task_handler
virtual void i2s_task_handler(void *arg)
dummy functions needed for BluetoothA2DPSinkQueued
Definition BluetoothA2DPSink.h:545
esp_avrc_rn_event_ids_t
esp_avrc_rn_event_ids_t
AVRC event notification ids.
Definition external_lists.h:50
esp_avrc_playback_stat_t
esp_avrc_playback_stat_t
AVRCP current status of playback.
Definition external_lists.h:72
esp_bd_addr_t
uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN]
Bluetooth address.
Definition external_lists.h:107