Arduino A2DP
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
BluetoothA2DPSource Class Reference

A2DP Bluetooth Source. More...

#include <BluetoothA2DPSource.h>

Inheritance diagram for BluetoothA2DPSource:
BluetoothA2DPCommon

Public Member Functions

 BluetoothA2DPSource ()
 Constructor.
 
 ~BluetoothA2DPSource ()
 Destructor.
 
virtual void clean_last_connection ()
 clean last connection (delete)
 
virtual bool connect_to (esp_bd_addr_t peer)
 Connnects to the indicated address.
 
virtual void debounce (void(*cb)(void), int ms)
 
void delay_ms (uint32_t millis)
 calls vTaskDelay to pause for the indicated number of milliseconds
 
virtual void disconnect ()
 Closes the connection.
 
void end (bool releaseMemory=false) override
 Ends the processing and releases the resources.
 
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 esp_bd_addr_tget_last_peer_address ()
 Provides the address of the last device.
 
unsigned long get_millis ()
 Provides the time in milliseconds since the last system boot.
 
virtual const char * get_name ()
 Provides the actual SSID name.
 
virtual int get_volume ()
 Determines the actual volume.
 
virtual bool is_connected ()
 Checks if A2DP is connected.
 
virtual bool is_discovery_active ()
 
void log_free_heap ()
 Logs the free heap.
 
virtual bool reconnect ()
 Reconnects to the last device.
 
virtual void set_auto_reconnect (bool active)
 
virtual void set_auto_reconnect (esp_bd_addr_t addr)
 automatically tries to reconnect to the indicated address
 
virtual void set_avrc_passthru_command_callback (void(*cb)(uint8_t key, bool isReleased))
 Define the handler fur button presses on the remote bluetooth speaker.
 
virtual void set_avrc_rn_events (std::vector< esp_avrc_rn_event_ids_t > events)
 
void set_bluedroid_config_t (esp_bluedroid_config_t cfg)
 Defines the esp_bluedroid_config_t: Available from IDF 5.2.1.
 
virtual void set_connectable (bool connectable)
 Bluetooth connectable.
 
virtual void set_connected (bool active)
 Calls disconnect or reconnect.
 
virtual void set_data_callback (int32_t(cb)(uint8_t *data, int32_t len))
 Defines the data callback.
 
virtual void set_data_callback_in_frames (int32_t(cb)(Frame *data, int32_t len))
 Defines the data callback.
 
virtual void set_data_source (Stream &data)
 Defines a single Arduino Stream (e.g. File) as audio source.
 
virtual void set_data_source_callback (Stream &(*next_stream)())
 Provide a callback which provides streams.
 
virtual void set_default_bt_mode (esp_bt_mode_t mode)
 
virtual void set_discoverability (esp_bt_discovery_mode_t d)
 Bluetooth discoverability. More...
 
virtual void set_discovery_mode_callback (void(*callback)(esp_bt_gap_discovery_state_t discoveryMode))
 Define callback to be notified about bt discovery mode state changes.
 
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 void set_local_name (const char *name)
 Defines the local name.
 
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 set_on_audio_state_changed_post (void(*callBack)(esp_a2d_audio_state_t state, void *), void *obj=nullptr)
 
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...
 
void set_pin_code (const char *pin_code, esp_bt_pin_type_t pin_type)
 Defines the pin code. If nothing is defined we use "1234".
 
virtual void set_reset_ble (bool doInit)
 Defines if the BLE should be reset on start.
 
virtual void set_ssid_callback (bool(*callback)(const char *ssid, esp_bd_addr_t address, int rrsi))
 Define callback to be notified about the found ssids.
 
virtual void set_ssp_enabled (bool active)
 activate Secure Simple Pairing
 
void set_task_core (BaseType_t core)
 
void set_task_priority (UBaseType_t priority)
 defines the task priority (the default value is configMAX_PRIORITIES - 10)
 
virtual void set_valid_cod_service (uint16_t filter)
 
virtual void set_volume (uint8_t volume)
 Sets the volume (range 0 - 127)
 
virtual void set_volume_control (A2DPVolumeControl *ptr)
 you can define a custom VolumeControl implementation
 
virtual void start ()
 
virtual void start (const char *name)
 Starts the A2DP source.
 
virtual void start (const char *name, music_data_frames_cb_t callback)
 Obsolete: use the start w/o callback and set the callback separately.
 
virtual void start (music_data_frames_cb_t callback)
 Obsolete: use the start w/o callback and set the callback separately.
 
virtual void start (std::vector< const char * > names)
 Starts the first available A2DP source.
 
virtual void start (std::vector< const char * > names, music_data_frames_cb_t callback)
 Obsolete: use the start w/o callback and set the callback separately.
 
virtual void start_raw (const char *name, music_data_cb_t callback=nullptr)
 Obsolete: use the start w/o callback and set the callback separately.
 
virtual void start_raw (music_data_cb_t callback=nullptr)
 Obsolete: use the start w/o callback and set the callback separately.
 
virtual void start_raw (std::vector< const char * > names, music_data_cb_t callback=nullptr)
 Obsolete: use the start w/o callback and set the callback separately.
 
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_a2d_connection_state_t state)
 converts esp_a2d_connection_state_t to a string
 
const char * to_str (esp_avrc_playback_stat_t state)
 converts esp_avrc_playback_stat_t to a string More...
 
const char * to_str (esp_bd_addr_t bda)
 converts a esp_bd_addr_t to a string - the string is 18 characters long!
 

Protected Member Functions

virtual void a2d_app_heart_beat (void *arg)
 
void app_a2d_callback (esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param) override
 callback function for A2DP source
 
void app_gap_callback (esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) override
 
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
 
virtual void app_rc_tg_callback (esp_avrc_tg_cb_event_t event, esp_avrc_tg_cb_param_t *param) override
 
virtual bool app_send_msg (bt_app_msg_t *msg)
 
virtual void app_task_handler (void *arg)
 
virtual void app_task_shut_down ()
 
virtual void app_task_start_up ()
 
virtual void app_work_dispatched (bt_app_msg_t *msg)
 
virtual void av_hdl_avrc_tg_evt (uint16_t event, void *p_param) override
 
void av_hdl_stack_evt (uint16_t event, void *p_param) override
 
virtual esp_err_t bluedroid_init ()
 
virtual void bt_app_av_media_proc (uint16_t event, void *param)
 
virtual void bt_app_av_sm_hdlr (uint16_t event, void *param)
 A2DP application state machine.
 
virtual void bt_app_av_state_connected_hdlr (uint16_t event, void *param)
 
virtual void bt_app_av_state_connecting_hdlr (uint16_t event, void *param)
 
virtual void bt_app_av_state_disconnecting_hdlr (uint16_t event, void *param)
 
virtual void bt_app_av_state_unconnected_hdlr (uint16_t event, void *param)
 A2DP application state machine handler for each state.
 
virtual bool bt_app_work_dispatch (bt_app_cb_t p_cback, uint16_t event, void *p_params, int param_len, bt_app_copy_cb_t p_copy_cback)
 
virtual void bt_av_hdl_avrc_ct_evt (uint16_t event, void *p_param)
 avrc CT event handler
 
virtual void bt_av_notify_evt_handler (uint8_t event, esp_avrc_rn_param_t *param)
 
virtual void bt_av_volume_changed (void)
 
virtual bool bt_start ()
 Startup logic as implemented by Arduino. More...
 
esp_err_t esp_a2d_connect (esp_bd_addr_t peer) override
 
esp_err_t esp_a2d_disconnect (esp_bd_addr_t peer) override
 
virtual void filter_inquiry_scan_result (esp_bt_gap_cb_param_t *param)
 
virtual int32_t get_audio_data (uint8_t *data, int32_t len)
 provides the audio data to be sent
 
virtual int32_t get_audio_data_volume (uint8_t *data, int32_t len)
 provides the audio after applying the volume
 
virtual void get_last_connection ()
 
virtual bool get_name_from_eir (uint8_t *eir, uint8_t *bdname, uint8_t *bdname_len)
 
virtual bool has_last_connection ()
 
virtual void init_nvs ()
 
virtual bool is_valid_cod_service (uint32_t cod)
 
virtual bool isSource ()
 
virtual const char * last_bda_nvs_name ()
 
virtual void process_user_state_callbacks (uint16_t event, void *param)
 
virtual bool read_address (const char *name, esp_bd_addr_t &bda)
 
virtual void reset_last_connection ()
 resets the last connectioin so that we can reconnect
 
virtual void set_last_connection (esp_bd_addr_t bda)
 
virtual void set_scan_mode_connectable (bool connectable)
 Defines if the bluetooth is connectable.
 
void set_scan_mode_connectable_default () override
 
const char * to_state_str (int state)
 converts a APP_AV_STATE_ENUM to a string
 
virtual A2DPVolumeControlvolume_control ()
 provides access to the VolumeControl object
 
virtual bool write_address (const char *name, esp_bd_addr_t bda)
 

Protected Attributes

TaskHandle_t app_task_handle = nullptr
 
QueueHandle_t app_task_queue = nullptr
 
esp_a2d_audio_state_t audio_state = ESP_A2D_AUDIO_STATE_STOPPED
 
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 * audio_state_obj = nullptr
 
void * audio_state_obj_post = nullptr
 
std::vector< esp_avrc_rn_event_ids_tavrc_rn_events
 
esp_bluedroid_config_t bluedroid_config {.ssp_en = true}
 
esp_bt_mode_t bt_mode = ESP_BT_MODE_CLASSIC_BT
 
const char * bt_name = {0}
 
std::vector< const char * > bt_names
 
esp_a2d_connection_state_t connection_state
 
void(* connection_state_callback )(esp_a2d_connection_state_t state, void *obj) = nullptr
 
void * connection_state_obj = nullptr
 
uint32_t debounce_ms = 0
 
unsigned int default_reconnect_timout = 10000
 
A2DPDefaultVolumeControl default_volume_control
 
const char * dev_name = "ESP32_A2DP_SRC"
 
esp_bt_discovery_mode_t discoverability = ESP_BT_GENERAL_DISCOVERABLE
 
bool discovery_active = false
 
void(* discovery_mode_callback )(esp_bt_gap_discovery_state_t discoveryMode)
 
int event_queue_size = 20
 
int event_stack_size = 3072
 
int32_t(* get_data_cb )(uint8_t *data, int32_t len) = nullptr
 callback for data
 
int32_t(* get_data_in_frames_cb )(Frame *data, int32_t len) = nullptr
 
Stream &(* get_next_stream_cb )() = nullptr
 
bool is_autoreconnect_allowed = false
 
bool is_passthru_active = false
 
bool is_start_disabled = false
 
bool is_target_status_active = true
 
bool is_volume_used = false
 
esp_bd_addr_t last_connection = {0, 0, 0, 0, 0, 0}
 
const char * m_a2d_audio_state_str [4] = {"Suspended", "Started", "Suspended", "Suspended"}
 
const char * m_a2d_conn_state_str [4]
 
const char * m_avrc_playback_state_str [5]
 
Stream * p_stream = nullptr
 
void(* passthru_command_callback )(uint8_t, bool) = nullptr
 
esp_bd_addr_t peer_bd_addr
 
esp_bt_pin_code_t pin_code
 
uint32_t pin_code_len
 
esp_bt_pin_type_t pin_type
 
ReconnectStatus reconnect_status = NoReconnect
 
unsigned long reconnect_timout = 0
 
bool reset_ble = false
 
APP_AV_STATE s_a2d_last_state
 
APP_AV_STATE s_a2d_state = APP_AV_STATE_IDLE
 
esp_avrc_rn_evt_cap_mask_t s_avrc_peer_rn_cap
 
int s_connecting_heatbeat_count
 
int s_intv_cnt = 0
 
int s_media_state = 0
 
uint8_t s_peer_bdname [ESP_BT_GAP_MAX_BDNAME_LEN+1]
 
uint32_t s_pkt_cnt
 
TimerHandle_t s_tmr
 
bool(* ssid_callback )(const char *ssid, esp_bd_addr_t address, int rrsi) = nullptr
 
bool ssp_enabled = false
 
BaseType_t task_core = 1
 
UBaseType_t task_priority = configMAX_PRIORITIES - 10
 
uint16_t valid_cod_services
 
A2DPVolumeControlvolume_control_ptr = nullptr
 
uint8_t volume_value = 0
 

Friends

void ccall_a2d_app_heart_beat (TIMER_ARG_TYPE arg)
 
int32_t ccall_bt_app_a2d_data_cb (uint8_t *data, int32_t len)
 
void ccall_bt_app_av_sm_hdlr (uint16_t event, void *param)
 
void ccall_bt_av_hdl_avrc_ct_evt (uint16_t event, void *param)
 

Detailed Description

A2DP Bluetooth Source.

Author
Phil Schatzmann

Member Function Documentation

◆ bt_app_av_state_connecting_hdlr()

void BluetoothA2DPSource::bt_app_av_state_connecting_hdlr ( uint16_t  event,
void *  param 
)
protectedvirtual

Switch state to APP_AV_STATE_UNCONNECTED when connecting lasts more than 2 heart beat intervals.

◆ bt_start()

bool BluetoothA2DPCommon::bt_start ( )
protectedvirtualinherited

Startup logic as implemented by Arduino.

Returns
true
false

◆ debounce()

void BluetoothA2DPCommon::debounce ( void(*)(void)  cb,
int  ms 
)
virtualinherited

Prevents that the same method is executed multiple times within the indicated time limit

◆ is_discovery_active()

virtual bool BluetoothA2DPSource::is_discovery_active ( )
inlinevirtual

Provides the current discovery state: returns true when the discovery is in progress

◆ is_valid_cod_service()

bool BluetoothA2DPSource::is_valid_cod_service ( uint32_t  cod)
protectedvirtual

returns true for ESP_BT_COD_SRVC_RENDERING,ESP_BT_COD_SRVC_AUDIO,ESP_BT_COD_SRVC_TELEPHONY

◆ set_auto_reconnect()

virtual void BluetoothA2DPSource::set_auto_reconnect ( bool  active)
inlinevirtual

activate / deactivate the automatic reconnection to the last address (per default this is on)

◆ set_avrc_rn_events()

virtual void BluetoothA2DPCommon::set_avrc_rn_events ( std::vector< esp_avrc_rn_event_ids_t events)
inlinevirtualinherited

Define the vector of esp_avrc_rn_event_ids_t with e.g. ESP_AVRC_RN_PLAY_STATUS_CHANGE | ESP_AVRC_RN_TRACK_CHANGE | ESP_AVRC_RN_TRACK_REACHED_END | ESP_AVRC_RN_TRACK_REACHED_START | ESP_AVRC_RN_PLAY_POS_CHANGED | ESP_AVRC_RN_BATTERY_STATUS_CHANGE | ESP_AVRC_RN_SYSTEM_STATUS_CHANGE | ESP_AVRC_RN_APP_SETTING_CHANGE | ESP_AVRC_RN_NOW_PLAYING_CHANGE | ESP_AVRC_RN_AVAILABLE_PLAYERS_CHANGE | ESP_AVRC_RN_ADDRESSED_PLAYER_CHANGE | ESP_AVRC_RN_UIDS_CHANGE|ESP_AVRC_RN_VOLUME_CHANGE

◆ set_default_bt_mode()

virtual void BluetoothA2DPCommon::set_default_bt_mode ( esp_bt_mode_t  mode)
inlinevirtualinherited

Defines the default bt mode. The default is ESP_BT_MODE_CLASSIC_BT: use this e.g. to set to ESP_BT_MODE_BTDM

◆ 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_task_core()

void BluetoothA2DPCommon::set_task_core ( BaseType_t  core)
inlineinherited

Defines the core which is used to start the tasks (to process the events and audio queue)

◆ set_valid_cod_service()

virtual void BluetoothA2DPSource::set_valid_cod_service ( uint16_t  filter)
inlinevirtual

Defines the valid esp_bt_cod_srvc_t values that are used to identify an audio service. e.g (ESP_BT_COD_SRVC_RENDERING | ESP_BT_COD_SRVC_AUDIO | ESP_BT_COD_SRVC_TELEPHONY)

◆ start()

virtual void BluetoothA2DPSource::start ( )
inlinevirtual

Starts the A2DP source w/o indicating any names: use the ssid callback to select the device

◆ 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_rn_events

std::vector<esp_avrc_rn_event_ids_t> BluetoothA2DPCommon::avrc_rn_events
protectedinherited
Initial value:
= {
ESP_AVRC_RN_VOLUME_CHANGE}

◆ connection_state

esp_a2d_connection_state_t BluetoothA2DPCommon::connection_state
protectedinherited
Initial value:
=
@ ESP_A2D_CONNECTION_STATE_DISCONNECTED
Definition: external_lists.h:17

◆ discovery_mode_callback

void(* BluetoothA2DPSource::discovery_mode_callback) (esp_bt_gap_discovery_state_t discoveryMode)
protected
Initial value:
=
nullptr

◆ m_a2d_conn_state_str

const char* BluetoothA2DPCommon::m_a2d_conn_state_str[4]
protectedinherited
Initial value:
= {"Disconnected", "Connecting",
"Connected", "Disconnecting"}

◆ m_avrc_playback_state_str

const char* BluetoothA2DPCommon::m_avrc_playback_state_str[5]
protectedinherited
Initial value:
= {"stopped", "playing", "paused",
"forward seek", "reverse seek"}

◆ s_a2d_last_state

APP_AV_STATE BluetoothA2DPSource::s_a2d_last_state
protected
Initial value:
=
APP_AV_STATE_IDLE

◆ valid_cod_services

uint16_t BluetoothA2DPSource::valid_cod_services
protected
Initial value:
= ESP_BT_COD_SRVC_RENDERING |
ESP_BT_COD_SRVC_AUDIO |
ESP_BT_COD_SRVC_TELEPHONY

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