Arduino A2DP
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.
 
void set_ssp_enabled (bool active)
 activate Secure Simple Pairing
 
void set_auto_reconnect (bool active)
 activate / deactivate the automatic reconnection to the last address (per default this is on)
 
void set_auto_reconnect (esp_bd_addr_t addr)
 automatically tries to reconnect to the indicated address
 
virtual void set_local_name (const char *name)
 Defines the local name.
 
virtual void start (const char *name, music_data_channels_cb_t callback=NULL)
 starts the bluetooth source More...
 
virtual void start (std::vector< const char * > names, music_data_channels_cb_t callback=NULL)
 starts the bluetooth source. Supports multiple alternative names
 
virtual void start_raw (const char *name, music_data_cb_t callback=NULL)
 starts the bluetooth source More...
 
virtual void start_raw (std::vector< const char * > names, music_data_cb_t callback=NULL)
 start_raw which supports multiple alternative names
 
virtual void set_pin_code (const char *pin_code, esp_bt_pin_type_t pin_type=ESP_BT_PIN_TYPE_VARIABLE)
 Defines the pin code. If nothing is defined we use "1234".
 
virtual bool write_data (SoundData *data)
 write sound data: In some cases it is very difficult to use the callback function. As an alternative we provide this method where you can just send the data to a queue. It is your responsibility however that you handle the situation if the queue is full.
 
virtual bool is_connected ()
 Returns true if the bluetooth device is connected.
 
virtual bool has_sound_data ()
 Returns true if write_dataRaw has been called with any valid data.
 
virtual void set_nvs_init (bool doInit)
 Defines if the Flash NVS should be reset on start.
 
virtual void set_reset_ble (bool doInit)
 Defines if the BLE should be reset on start.
 
virtual void set_volume (uint8_t volume)
 Sets the volume (range 0 - 255)
 
virtual int get_volume ()
 Determines the actual volume.
 
virtual int32_t get_data_default (uint8_t *data, int32_t len)
 callback for data
 
virtual void disconnect ()
 Closes the connection.
 
virtual void end (bool releaseMemory=false)
 Closes the connection and stops A2DP.
 
virtual void set_volume_control (VolumeControl *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.
 
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.
 
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!
 
void set_task_priority (UBaseType_t priority)
 defines the task priority (the default value is configMAX_PRIORITIES - 3)
 

Protected Member Functions

virtual void process_user_state_callbacks (uint16_t event, void *param)
 
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_app_task_start_up (void)
 
virtual void bt_app_task_shut_down (void)
 
virtual void bt_app_av_media_proc (uint16_t event, void *param)
 
virtual void bt_app_av_state_unconnected (uint16_t event, void *param)
 
virtual void bt_app_av_state_connecting (uint16_t event, void *param)
 
virtual void bt_app_av_state_connected (uint16_t event, void *param)
 
virtual void bt_app_av_state_disconnecting (uint16_t event, void *param)
 
virtual bool bt_app_send_msg (app_msg_t *msg)
 
virtual void bt_app_work_dispatched (app_msg_t *msg)
 
virtual bool get_name_from_eir (uint8_t *eir, uint8_t *bdname, uint8_t *bdname_len)
 
virtual void filter_inquiry_scan_result (esp_bt_gap_cb_param_t *param)
 
virtual const char * last_bda_nvs_name ()
 
virtual void bt_av_hdl_stack_evt (uint16_t event, void *p_param)
 
virtual void bt_app_task_handler (void *arg)
 
virtual void bt_app_gap_callback (esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
 
virtual void bt_app_rc_ct_cb (esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param)
 callback function for AVRCP controller
 
virtual void a2d_app_heart_beat (void *arg)
 
virtual void bt_app_a2d_cb (esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
 callback function for A2DP source
 
virtual void bt_app_av_sm_hdlr (uint16_t event, void *param)
 A2DP application state machine.
 
virtual void bt_av_hdl_avrc_ct_evt (uint16_t event, void *p_param)
 avrc CT event handler
 
virtual void reset_last_connection ()
 resets the last connectioin so that we can reconnect
 
virtual void get_last_connection ()
 
virtual void set_last_connection (esp_bd_addr_t bda)
 
virtual void clean_last_connection ()
 
virtual void connect_to_last_device ()
 
virtual bool has_last_connection ()
 
virtual void set_scan_mode_connectable (bool connectable)
 
virtual VolumeControlvolume_control ()
 provides access to the VolumeControl object
 

Protected Attributes

music_data_channels_cb_t data_stream_channels_callback
 
const char * dev_name = "ESP32_A2DP_SRC"
 
bool ssp_enabled =false
 
const char * bt_name
 
std::vector< const char * > bt_names
 
esp_bt_pin_type_t pin_type
 
esp_bt_pin_code_t pin_code
 
uint32_t pin_code_len
 
esp_bd_addr_t s_peer_bda
 
uint8_t s_peer_bdname [ESP_BT_GAP_MAX_BDNAME_LEN+1]
 
int s_a2d_state
 
int s_media_state
 
int s_intv_cnt =0
 
int s_connecting_intv
 
uint32_t s_pkt_cnt
 
TimerHandle_t s_tmr
 
xQueueHandle s_bt_app_task_queue
 
xTaskHandle s_bt_app_task_handle
 
SoundDatasound_data
 
int32_t sound_data_current_pos
 
bool hasSoundData
 
bool nvs_init = true
 
bool reset_ble = true
 
music_data_cb_t data_stream_callback
 
uint8_t volume_value = 0
 
bool is_volume_used = false
 
bool auto_reconnect =true
 
uint32_t debounce_ms = 0
 
DefaultVolumeControl default_volume_control
 
VolumeControlvolume_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 * connection_state_obj = nullptr
 
void * audio_state_obj = nullptr
 
const char * m_a2d_conn_state_str [4] = {"Disconnected", "Connecting", "Connected", "Disconnecting"}
 
const char * m_a2d_audio_state_str [3] = {"Suspended", "Stopped", "Started"}
 
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 - 3
 

Friends

void ccall_bt_av_hdl_stack_evt (uint16_t event, void *p_param)
 
void ccall_bt_app_task_handler (void *arg)
 
void ccall_bt_app_gap_callback (esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
 
void ccall_bt_app_rc_ct_cb (esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param)
 
void ccall_a2d_app_heart_beat (void *arg)
 
void ccall_bt_app_a2d_cb (esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
 
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)
 
int32_t ccall_bt_app_a2d_data_cb (uint8_t *data, int32_t len)
 
int32_t ccall_get_channel_data_wrapper (uint8_t *data, int32_t len)
 
int32_t ccall_get_data_default (uint8_t *data, int32_t len)
 

Detailed Description

A2DP Bluetooth Source.

Author
Phil Schatzmann

Member Function Documentation

◆ bt_av_hdl_stack_evt()

void BluetoothA2DPSource::bt_av_hdl_stack_evt ( uint16_t  event,
void *  p_param 
)
protectedvirtual

The following mthods are called by the framework. They are public so that they can be executed from a extern "C" function.

◆ start()

void BluetoothA2DPSource::start ( const char *  name,
music_data_channels_cb_t  callback = NULL 
)
virtual

starts the bluetooth source

Parameters
nameBluetooth name of the device to connect to
callbackfunction that provides the audio stream as array of Frame
is_ssp_enabledFlag to activate Secure Simple Pairing

◆ start_raw()

void BluetoothA2DPSource::start_raw ( const char *  name,
music_data_cb_t  callback = NULL 
)
virtual

starts the bluetooth source

Parameters
nameBluetooth name of the device to connect to
callbackfunction that provides the audio stream - The supported audio codec in ESP32 A2DP is SBC. SBC audio stream is encoded from PCM data normally formatted as 44.1kHz sampling rate, two-channel 16-bit sample data
is_ssp_enabledFlag to activate Secure Simple Pairing

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