Skip to content

Commit

Permalink
set_valid_cod_service
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Oct 18, 2024
1 parent ed23c43 commit 374cde3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/BluetoothA2DPSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,9 @@ bool BluetoothA2DPSource::get_name_from_eir(uint8_t *eir, uint8_t *bdname,
return false;
}

bool BluetoothA2DPSource::isValidAudioService(uint32_t cod){
bool BluetoothA2DPSource::is_valid_cod_service(uint32_t cod){
uint32_t srvc = esp_bt_gap_get_cod_srvc(cod);
return srvc & ESP_BT_COD_SRVC_RENDERING
|| srvc & ESP_BT_COD_SRVC_AUDIO
|| srvc & ESP_BT_COD_SRVC_TELEPHONY;
return srvc & valid_cod_services;
}

void BluetoothA2DPSource::filter_inquiry_scan_result(
Expand Down Expand Up @@ -415,7 +413,7 @@ void BluetoothA2DPSource::filter_inquiry_scan_result(
}
/* search for device with MAJOR service class as "rendering" in COD */
if (!esp_bt_gap_is_valid_cod(cod) ||
!isValidAudioService(cod)) {
!is_valid_cod_service(cod)) {
ESP_LOGI(BT_AV_TAG, "--Compatiblity: Incompatible");
return;
}
Expand Down
8 changes: 7 additions & 1 deletion src/BluetoothA2DPSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ class BluetoothA2DPSource : public BluetoothA2DPCommon {
return discovery_active;
}

/// Defines the valid enumesp_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)
virtual void set_valid_cod_service(uint16_t filter){
this->valid_cod_services = filter;
}

protected:
music_data_channels_cb_t data_stream_channels_callback;
const char *dev_name = "ESP32_A2DP_SRC";
Expand Down Expand Up @@ -227,6 +232,7 @@ class BluetoothA2DPSource : public BluetoothA2DPCommon {
bool reset_ble = false;
music_data_cb_t data_stream_callback;
bool discovery_active = false;
uint16_t valid_cod_services = ESP_BT_COD_SRVC_RENDERING | ESP_BT_COD_SRVC_AUDIO | ESP_BT_COD_SRVC_TELEPHONY;

bool(*ssid_callback)(const char*ssid, esp_bd_addr_t address, int rrsi) = nullptr;
void(*discovery_mode_callback)(esp_bt_gap_discovery_state_t discoveryMode) = nullptr;
Expand Down Expand Up @@ -279,7 +285,7 @@ class BluetoothA2DPSource : public BluetoothA2DPCommon {
/// resets the last connectioin so that we can reconnect
virtual void reset_last_connection();
/// returns true for ESP_BT_COD_SRVC_RENDERING,ESP_BT_COD_SRVC_AUDIO,ESP_BT_COD_SRVC_TELEPHONY
virtual bool isValidAudioService(uint32_t cod);
virtual bool is_valid_cod_service(uint32_t cod);

virtual esp_err_t esp_a2d_connect(esp_bd_addr_t peer) {
ESP_LOGI(BT_AV_TAG, "a2dp connecting to: %s", to_str(peer));
Expand Down

0 comments on commit 374cde3

Please sign in to comment.