Arduino A2DP
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BluetoothA2DPSinkQueued Class Reference

The BluetoothA2DPSinkQueued is using a separate Task with an additinal Queue to write the I2S data. application. More...

#include <BluetoothA2DPSinkQueued.h>

Inheritance diagram for BluetoothA2DPSinkQueued:
BluetoothA2DPSink BluetoothA2DPCommon

Public Member Functions

 BluetoothA2DPSinkQueued (AudioOutput &output)
 Output AudioOutput using AudioTools library.
 
 BluetoothA2DPSinkQueued (AudioStream &output)
 Output AudioStream using AudioTools library.
 
 BluetoothA2DPSinkQueued (Print &output)
 Output to Arduino Print.
 
void set_i2s_stack_size (int size)
 Defines the stack size of the i2s task (in bytes)
 
void set_i2s_ringbuffer_size (int size)
 Defines the ringbuffer size used by the i2s task (in bytes)
 
void set_i2s_ringbuffer_prefetch_percent (int percent)
 Audio starts to play when limit exeeded.
 
void set_i2s_task_priority (UBaseType_t prio)
 Defines the priority of the I2S task.
 
void set_i2s_write_size_upto (size_t size)
 
void set_i2s_ticks (int ticks)
 
void set_output (BluetoothA2DPOutput &output)
 Defines the output class: by default we use BluetoothA2DPOutputDefault.
 
void set_output (Print &output)
 Output to Arduino Print.
 
void set_output (AudioOutput &output)
 Output AudioOutput using AudioTools library.
 
void set_output (AudioStream &output)
 Output AudioStream using AudioTools library.
 
virtual void start (const char *name, bool auto_reconect)
 starts the I2S bluetooth sink with the inidicated name
 
virtual void start (const char *name)
 starts the I2S bluetooth sink with the inidicated name More...
 
virtual void end (bool release_memory=false)
 
virtual esp_a2d_mct_t get_audio_type ()
 Determine the actual audio type.
 
virtual void set_avrc_connection_state_callback (void(*callback)(bool))
 Define a callback method which provides connection state of AVRC service.
 
virtual void set_avrc_metadata_callback (void(*callback)(uint8_t, const uint8_t *))
 Define a callback method which provides the meta data.
 
virtual void set_avrc_rn_playstatus_callback (void(*callback)(esp_avrc_playback_stat_t playback))
 Define a callback method which provides esp_avrc_playback_stat_t playback status notifications.
 
virtual void set_avrc_rn_play_pos_callback (void(*callback)(uint32_t play_pos))
 Define a callback method which provides esp_avrc_rn_param_t play position notifications.
 
virtual void set_sample_rate_callback (void(*callback)(uint16_t rate))
 Defines the method which will be called with the sample rate is updated.
 
virtual void set_stream_reader (void(*callBack)(const uint8_t *, uint32_t), bool i2s_output=true)
 
virtual void set_raw_stream_reader (void(*callBack)(const uint8_t *, uint32_t))
 
virtual void set_on_data_received (void(*callBack)())
 Define callback which is called when we receive data.
 
virtual void set_address_validator (bool(*callBack)(esp_bd_addr_t remote_bda))
 Allows you to reject unauthorized addresses.
 
virtual bool is_avrc_connected ()
 returns true if the avrc service is connected
 
virtual void set_volume (uint8_t volume)
 Changes the volume.
 
virtual int get_volume ()
 Determines the volume.
 
virtual void set_on_volumechange (void(*callBack)(int))
 
virtual void set_avrc_rn_volumechange (void(*callBack)(int))
 Set the callback that is called when remote changes the volume.
 
virtual void set_avrc_rn_volumechange_completed (void(*callBack)(int))
 
virtual void play ()
 Starts to play music using AVRC.
 
virtual void pause ()
 AVRC pause.
 
virtual void stop ()
 AVRC stop.
 
virtual void next ()
 AVRC next.
 
virtual void previous ()
 AVRC previous.
 
virtual void fast_forward ()
 AVRC fast_forward.
 
virtual void rewind ()
 AVRC rewind.
 
virtual void set_mono_downmix (bool enabled)
 mix stereo into single mono signal
 
virtual uint16_t sample_rate ()
 Provides the actually set data rate (in samples per second)
 
virtual void activate_pin_code (bool active)
 We need to confirm a new seesion by calling confirm_pin_code()
 
virtual void confirm_pin_code ()
 confirms the connection request by returning the receivedn pin code
 
virtual void confirm_pin_code (int code)
 confirms the connection request by returning the indicated pin code
 
virtual int pin_code ()
 provides the requested pin code (0 = undefined)
 
virtual void set_avrc_metadata_attribute_mask (int flags)
 
virtual void set_swap_lr_channels (bool swap)
 swaps the left and right channel
 
virtual void set_auto_reconnect (bool reconnect, int count=AUTOCONNECT_TRY_NUM)
 
void set_auto_reconnect (bool active)
 activate / deactivate the automatic reconnection to the last address (per default this is on)
 
virtual esp_bd_addr_t * get_current_peer_address ()
 Provides the address of the connected device.
 
void set_rssi_active (bool active)
 Activates the rssi reporting.
 
bool update_rssi ()
 Requests an update of the rssi delta value.
 
esp_bt_gap_cb_param_t::read_rssi_delta_param get_last_rssi ()
 provides the last rssi parameters
 
void set_rssi_calldoxback (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.
 
void set_reconnect_delay (int delay)
 
void set_spp_active (bool flag)
 Activates SSP (Serial protocol)
 
virtual const char * get_connected_source_name ()
 Get the name of the connected source device (obsolete)
 
bool is_avrc_peer_rn_cap (esp_avrc_rn_event_ids_t cmd)
 
bool is_avrc_peer_rn_cap_available ()
 Returns true if the is_avrc_peer_rn_cap() method can be called.
 
virtual const char * get_peer_name ()
 Get the name of the connected source device.
 
virtual void disconnect ()
 Closes the connection.
 
virtual bool reconnect ()
 Reconnects to the last device.
 
virtual bool connect_to (esp_bd_addr_t peer)
 Connnects to the indicated address.
 
virtual void set_connected (bool active)
 Calls disconnect or reconnect.
 
virtual bool is_connected ()
 Checks if A2DP is connected.
 
virtual void set_volume_control (A2DPVolumeControl *ptr)
 you can define a custom VolumeControl implementation
 
virtual esp_a2d_audio_state_t get_audio_state ()
 Determine the actual audio state.
 
virtual esp_a2d_connection_state_t get_connection_state ()
 Determine the connection state.
 
virtual void set_on_connection_state_changed (void(*callBack)(esp_a2d_connection_state_t state, void *), void *obj=nullptr)
 Set the callback that is called when the connection state is changed. More...
 
virtual void set_on_audio_state_changed_post (void(*callBack)(esp_a2d_audio_state_t state, void *), void *obj=nullptr)
 
virtual void set_on_audio_state_changed (void(*callBack)(esp_a2d_audio_state_t state, void *), void *obj=nullptr)
 Set the callback that is called when the audio state is changed. More...
 
virtual void debounce (void(*cb)(void), int ms)
 Prevents that the same method is executed multiple times within the indicated time limit.
 
void log_free_heap ()
 Logs the free heap.
 
const char * to_str (esp_a2d_connection_state_t state)
 converts esp_a2d_connection_state_t to a string
 
const char * to_str (esp_a2d_audio_state_t state)
 converts a esp_a2d_audio_state_t to a string
 
const char * to_str (esp_bd_addr_t bda)
 converts a esp_bd_addr_t to a string - the string is 18 characters long!
 
const char * to_str (esp_avrc_playback_stat_t state)
 converts esp_avrc_playback_stat_t to a string More...
 
void set_task_priority (UBaseType_t priority)
 defines the task priority (the default value is configMAX_PRIORITIES - 10)
 
void set_task_core (BaseType_t core)
 Defines the core which is used to start the tasks (to process the events and audio queue)
 
void set_event_queue_size (int size)
 Defines the queue size of the event task.
 
void set_event_stack_size (int size)
 Defines the stack size of the event task (in bytes)
 
virtual esp_bd_addr_t * get_last_peer_address ()
 Provides the address of the last device.
 
virtual void set_discoverability (esp_bt_discovery_mode_t d)
 Bluetooth discoverability. More...
 
virtual void set_connectable (bool connectable)
 Bluetooth connectable.
 
virtual const char * get_name ()
 Provides the actual SSID name.
 
virtual void clean_last_connection ()
 clean last connection (delete)
 
virtual void set_default_bt_mode (esp_bt_mode_t mode)
 Defines the default bt mode. The default is ESP_BT_MODE_CLASSIC_BT: use this e.g. to set to ESP_BT_MODE_BTDM.
 

Protected Member Functions

void bt_i2s_task_start_up (void) override
 
void bt_i2s_task_shut_down (void) override
 
void i2s_task_handler (void *arg) override
 dummy functions needed for BluetoothA2DPSinkQueued More...
 
size_t write_audio (const uint8_t *data, size_t size) override
 output audio data e.g. to i2s or to queue
 
void set_i2s_active (bool active) override
 
int i2s_ringbuffer_prefetch_size ()
 
virtual int init_bluetooth ()
 
virtual void app_task_start_up (void)
 
virtual void app_task_shut_down (void)
 
virtual bool app_send_msg (bt_app_msg_t *msg)
 
virtual bool app_work_dispatch (app_callback_t p_cback, uint16_t event, void *p_params, int param_len)
 
virtual void app_work_dispatched (bt_app_msg_t *msg)
 
virtual void app_alloc_meta_buffer (esp_avrc_ct_cb_param_t *param)
 
virtual void av_new_track ()
 
virtual void av_playback_changed ()
 
virtual void av_play_pos_changed ()
 
virtual void init_nvs ()
 
virtual void execute_avrc_command (int cmd)
 
virtual const char * last_bda_nvs_name ()
 
virtual bool is_reconnect (esp_a2d_disc_rsn_t type)
 
virtual void app_task_handler (void *arg)
 
virtual void app_a2d_callback (esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
 
virtual void app_gap_callback (esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
 
virtual void app_rc_ct_callback (esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param)
 
virtual void audio_data_callback (const uint8_t *data, uint32_t len)
 
virtual void av_hdl_stack_evt (uint16_t event, void *p_param)
 
virtual void av_hdl_a2d_evt (uint16_t event, void *p_param)
 
virtual void av_hdl_avrc_evt (uint16_t event, void *p_param)
 
virtual void handle_connection_state (uint16_t event, void *p_param)
 
virtual void handle_audio_state (uint16_t event, void *p_param)
 
virtual void handle_audio_cfg (uint16_t event, void *p_param)
 
virtual void handle_avrc_connection_state (bool connected)
 
virtual void volume_set_by_local_host (uint8_t volume)
 
virtual void volume_set_by_controller (uint8_t volume)
 
virtual void av_notify_evt_handler (uint8_t event_id, esp_avrc_rn_param_t *event_parameter)
 
virtual void app_rc_tg_callback (esp_avrc_tg_cb_event_t event, esp_avrc_tg_cb_param_t *param)
 
virtual void av_hdl_avrc_tg_evt (uint16_t event, void *p_param)
 
virtual void init_i2s ()
 
size_t i2s_write_data (const uint8_t *data, size_t item_size)
 writes the data to i2s
 
virtual esp_err_t esp_a2d_connect (esp_bd_addr_t peer)
 
void set_scan_mode_connectable_default () override
 
virtual void get_last_connection ()
 
virtual void set_last_connection (esp_bd_addr_t bda)
 
virtual bool has_last_connection ()
 
virtual void set_scan_mode_connectable (bool connectable)
 Defines if the bluetooth is connectable.
 
virtual A2DPVolumeControlvolume_control ()
 provides access to the VolumeControl object
 

Protected Attributes

xTaskHandle s_bt_i2s_task_handle = nullptr
 
RingbufHandle_t s_ringbuf_i2s = nullptr
 
SemaphoreHandle_t s_i2s_write_semaphore = nullptr
 
int i2s_stack_size = 2048
 
int i2s_ringbuffer_size = RINGBUF_HIGHEST_WATER_LEVEL
 
UBaseType_t i2s_task_priority = configMAX_PRIORITIES - 3
 
volatile A2DPRingBufferMode ringbuffer_mode = RINGBUFFER_MODE_PROCESSING
 
volatile bool is_starting = true
 
size_t i2s_write_size_upto = 240 * 6
 
int i2s_ticks = 20
 
int ringbuffer_prefetch_percent = RINGBUF_PREFETCH_PERCENT
 
BluetoothA2DPOutputDefault out_default
 
BluetoothA2DPOutputout = &out_default
 
xQueueHandle app_task_queue = nullptr
 
xTaskHandle app_task_handle = nullptr
 
volatile bool is_i2s_active = false
 
bool is_output = true
 
uint16_t m_sample_rate = 0
 
uint32_t m_pkt_cnt = 0
 
esp_a2d_mct_t audio_type
 
char pin_code_str [20] = {0}
 
bool player_init = false
 
int connection_rety_count = 0
 
bool spp_active = false
 
esp_spp_mode_t esp_spp_mode = ESP_SPP_MODE_CB
 
_lock_t s_volume_lock
 
uint8_t s_volume = 0
 
bool s_volume_notify
 
int pin_code_int = 0
 
PinCodeRequest pin_code_request = Undefined
 
bool is_pin_code_active = false
 
bool avrc_connection_state = false
 
int avrc_metadata_flags
 
void(* bt_volumechange )(int) = nullptr
 
void(* bt_dis_connected )() = nullptr
 
void(* bt_connected )() = nullptr
 
void(* data_received )() = nullptr
 
void(* stream_reader )(const uint8_t *, uint32_t) = nullptr
 
void(* raw_stream_reader )(const uint8_t *, uint32_t) = nullptr
 
void(* avrc_connection_state_callback )(bool connected) = nullptr
 
void(* avrc_metadata_callback )(uint8_t, const uint8_t *) = nullptr
 
void(* avrc_rn_playstatus_callback )(esp_avrc_playback_stat_t) = nullptr
 
void(* avrc_rn_play_pos_callback )(uint32_t) = nullptr
 
void(* avrc_rn_volchg_complete_callback )(int) = nullptr
 
bool(* address_validator )(esp_bd_addr_t remote_bda) = nullptr
 
void(* sample_rate_callback )(uint16_t rate) = nullptr
 
bool swap_left_right = false
 
int try_reconnect_max_count = AUTOCONNECT_TRY_NUM
 
esp_bt_gap_cb_param_t::read_rssi_delta_param last_rssi_delta
 
bool rssi_active = false
 
void(* rssi_callbak )(esp_bt_gap_cb_param_t::read_rssi_delta_param &rssi)
 
int reconnect_delay = 1000
 
esp_avrc_rn_evt_cap_mask_t s_avrc_peer_rn_cap = {0}
 
esp_avrc_rn_evt_cap_mask_t s_avrc_peer_rn_cap_set = {0}
 
char remote_name [ESP_BT_GAP_MAX_BDNAME_LEN+1]
 
const char * bt_name = {0}
 
esp_bd_addr_t peer_bd_addr
 
ReconnectStatus reconnect_status = NoReconnect
 
unsigned long reconnect_timout =0
 
unsigned int default_reconnect_timout =10000
 
bool is_autoreconnect_allowed = false
 
uint32_t debounce_ms = 0
 
A2DPDefaultVolumeControl default_volume_control
 
A2DPVolumeControlvolume_control_ptr = nullptr
 
esp_bd_addr_t last_connection = {0,0,0,0,0,0}
 
bool is_start_disabled = false
 
void(* connection_state_callback )(esp_a2d_connection_state_t state, void *obj) = nullptr
 
void(* audio_state_callback )(esp_a2d_audio_state_t state, void *obj) = nullptr
 
void(* audio_state_callback_post )(esp_a2d_audio_state_t state, void *obj) = nullptr
 
void * connection_state_obj = nullptr
 
void * audio_state_obj = nullptr
 
void * audio_state_obj_post = nullptr
 
const char * m_a2d_conn_state_str [4] = {"Disconnected", "Connecting", "Connected", "Disconnecting"}
 
const char * m_a2d_audio_state_str [3] = {"Suspended", "Stopped", "Started"}
 
const char * m_avrc_playback_state_str [5] = {"stopped", "playing", "paused", "forward seek", "reverse seek"}
 
esp_a2d_audio_state_t audio_state = ESP_A2D_AUDIO_STATE_STOPPED
 
esp_a2d_connection_state_t connection_state = ESP_A2D_CONNECTION_STATE_DISCONNECTED
 
UBaseType_t task_priority = configMAX_PRIORITIES - 10
 
uint8_t volume_value = 0
 
bool is_volume_used = false
 
BaseType_t task_core = 1
 
int event_queue_size = 20
 
int event_stack_size = 3072
 
esp_bt_mode_t bt_mode = ESP_BT_MODE_CLASSIC_BT
 
esp_bt_discovery_mode_t discoverability = ESP_BT_GENERAL_DISCOVERABLE
 

Detailed Description

The BluetoothA2DPSinkQueued is using a separate Task with an additinal Queue to write the I2S data. application.

Author
Phil Schatzmann

Member Function Documentation

◆ app_task_handler()

void BluetoothA2DPSink::app_task_handler ( void *  arg)
protectedvirtualinherited

Wrappbed methods called from callbacks

◆ end()

void BluetoothA2DPSink::end ( bool  release_memory = false)
virtualinherited

ends the I2S bluetooth sink with the indicated name - if you release the memory a future start is not possible

Reimplemented from BluetoothA2DPCommon.

◆ i2s_task_handler()

void BluetoothA2DPSinkQueued::i2s_task_handler ( void *  arg)
overrideprotectedvirtual

dummy functions needed for BluetoothA2DPSinkQueued

The total length of DMA buffer of I2S is: dma_frame_num * dma_desc_num * i2s_channel_num * i2s_data_bit_width / 8. Transmit dma_frame_num * dma_desc_num bytes to DMA is trade-off.

Reimplemented from BluetoothA2DPSink.

◆ is_avrc_peer_rn_cap()

bool BluetoothA2DPSink::is_avrc_peer_rn_cap ( esp_avrc_rn_event_ids_t  cmd)
inlineinherited

Provides the result of the last result for the esp_avrc_tg_get_rn_evt_cap() callback (Available from ESP_IDF_4)

◆ set_auto_reconnect()

virtual void BluetoothA2DPSink::set_auto_reconnect ( bool  reconnect,
int  count = AUTOCONNECT_TRY_NUM 
)
inlinevirtualinherited

Defines the number of times that the system tries to automatically reconnect to the last system

◆ set_avrc_metadata_attribute_mask()

virtual void BluetoothA2DPSink::set_avrc_metadata_attribute_mask ( int  flags)
inlinevirtualinherited

defines the requested metadata: eg. ESP_AVRC_MD_ATTR_TITLE | ESP_AVRC_MD_ATTR_ARTIST | ESP_AVRC_MD_ATTR_ALBUM | ESP_AVRC_MD_ATTR_TRACK_NUM | ESP_AVRC_MD_ATTR_NUM_TRACKS | ESP_AVRC_MD_ATTR_GENRE | ESP_AVRC_MD_ATTR_PLAYING_TIME

◆ set_avrc_rn_volumechange_completed()

void BluetoothA2DPSink::set_avrc_rn_volumechange_completed ( void(*)(int)  callBack)
virtualinherited

set the callback that the local volume change is notification is received and complete

◆ set_discoverability()

void BluetoothA2DPCommon::set_discoverability ( esp_bt_discovery_mode_t  d)
virtualinherited

Bluetooth discoverability.

Defines if the bluetooth is discoverable.

◆ set_on_audio_state_changed()

void BluetoothA2DPCommon::set_on_audio_state_changed ( void(*)(esp_a2d_audio_state_t state, void *)  callBack,
void *  obj = nullptr 
)
virtualinherited

Set the callback that is called when the audio state is changed.

Set the callback that is called when the audio state is changed This callback is called before the I2S bus is changed.

◆ set_on_audio_state_changed_post()

void BluetoothA2DPCommon::set_on_audio_state_changed_post ( void(*)(esp_a2d_audio_state_t state, void *)  callBack,
void *  obj = nullptr 
)
virtualinherited

Set the callback that is called after the audio state has changed. This callback is called after the I2S bus has changed.

◆ set_on_connection_state_changed()

void BluetoothA2DPCommon::set_on_connection_state_changed ( void(*)(esp_a2d_connection_state_t state, void *)  callBack,
void *  obj = nullptr 
)
virtualinherited

Set the callback that is called when the connection state is changed.

Set the callback that is called when the connection state is changed This callback is called before the I2S bus is changed.

◆ set_on_volumechange()

void BluetoothA2DPSink::set_on_volumechange ( void(*)(int)  callBack)
virtualinherited

Set the callback that is called when they change the volume (kept for compatibility)

◆ set_raw_stream_reader()

void BluetoothA2DPSink::set_raw_stream_reader ( void(*)(const uint8_t *, uint32_t)  callBack)
virtualinherited

Define a callback that is called before the volume changes: this callback provides access to the data

◆ set_reconnect_delay()

void BluetoothA2DPSink::set_reconnect_delay ( int  delay)
inlineinherited

Defines the delay that is added to delay the startup when we automatically reconnect

◆ set_stream_reader()

void BluetoothA2DPSink::set_stream_reader ( void(*)(const uint8_t *, uint32_t)  callBack,
bool  i2s_output = true 
)
virtualinherited

Define callback which is called when we receive data: This callback provides access to the data

◆ start()

void BluetoothA2DPSink::start ( const char *  name)
virtualinherited

starts the I2S bluetooth sink with the inidicated name

Main function to start the Bluetooth Processing

◆ to_str()

const char * BluetoothA2DPCommon::to_str ( esp_avrc_playback_stat_t  state)
inherited

converts esp_avrc_playback_stat_t to a string

converts a esp_a2d_audio_state_t to a string

Member Data Documentation

◆ avrc_metadata_flags

int BluetoothA2DPSink::avrc_metadata_flags
protectedinherited
Initial value:
=
ESP_AVRC_MD_ATTR_TITLE | ESP_AVRC_MD_ATTR_ARTIST |
ESP_AVRC_MD_ATTR_ALBUM | ESP_AVRC_MD_ATTR_TRACK_NUM |
ESP_AVRC_MD_ATTR_NUM_TRACKS | ESP_AVRC_MD_ATTR_GENRE

◆ rssi_callbak

void(* BluetoothA2DPSink::rssi_callbak) (esp_bt_gap_cb_param_t::read_rssi_delta_param &rssi)
protectedinherited
Initial value:
=
nullptr

The documentation for this class was generated from the following files: