HFP AG Callback function not working properly [BT-776]

searock35
Posts: 3
Joined: Tue Dec 10, 2019 3:56 pm

HFP AG Callback function not working properly [BT-776]

Postby searock35 » Mon Apr 20, 2020 11:10 pm

Hi friends,

I am trying to use ESP32's HFP_AG profile to send and receive audio from Bluetooth headphones/speakers. I am planning on doing some signal processing on the microphone input and sending a custom output to the client, and as far as I can tell that means I need to configure the audio path to communicate using HCI instead of PCM. So, I register the incoming and outcoming data callbacks, connect to the target device, and initiate an audio connection with the device. However, I get consistent errors when I start connecting to the device. Here is a short taste:

E (7130) BT_BTM: btm_sco_connected, handle 181
I (7130) HFP: Audio state connected
W (7160) BT_APPL: bta_ag_sco_read_cback: status(2)
W (7160) BT_APPL: bta_ag_sco_read_cback: status(2)
W (7170) BT_APPL: bta_ag_sco_read_cback: status(2)
W (7180) BT_APPL: bta_ag_sco_read_cback: status(2)
W (7190) BT_APPL: bta_ag_sco_read_cback: status(2)
W (7190) BT_APPL: bta_ag_sco_read_cback: status(2)
W (7200) BT_APPL: bta_ag_sco_read_cback: status(2)
W (7210) BT_APPL: bta_ag_sco_read_cback: status(2)

Occasionally, I get a few of these sco read status updates that have a 1. I looked a little deeper and found that a 2 status means that it detected no data from the callback, while a 1 means there was a parity error. These are my callback functions:

Code: Select all

static const int16_t sine_int16[] = {
     0,    2057,    4107,    6140,    8149,   10126,   12062,   13952,   15786,   17557,
 19260,   20886,   22431,   23886,   25247,   26509,   27666,   28714,   29648,   30466,
 31163,   31738,   32187,   32509,   32702,   32767,   32702,   32509,   32187,   31738,
 31163,   30466,   29648,   28714,   27666,   26509,   25247,   23886,   22431,   20886,
 19260,   17557,   15786,   13952,   12062,   10126,    8149,    6140,    4107,    2057,
     0,   -2057,   -4107,   -6140,   -8149,  -10126,  -12062,  -13952,  -15786,  -17557,
-19260,  -20886,  -22431,  -23886,  -25247,  -26509,  -27666,  -28714,  -29648,  -30466,
-31163,  -31738,  -32187,  -32509,  -32702,  -32767,  -32702,  -32509,  -32187,  -31738,
-31163,  -30466,  -29648,  -28714,  -27666,  -26509,  -25247,  -23886,  -22431,  -20886,
-19260,  -17557,  -15786,  -13952,  -12062,  -10126,   -8149,   -6140,   -4107,   -2057,
};

#define TABLE_SIZE_CVSD   100
static uint32_t outgoing_cb(uint8_t *p_buf, uint32_t sz)
{
    int sine_phase = esp_random();
    ESP_LOGI(HFP_TAG, "MADE IT");

    for (int i = 0; i < TABLE_SIZE_CVSD; i++) {
        p_buf[i * 2]     = sine_int16[sine_phase];
        p_buf[i * 2 + 1] = sine_int16[sine_phase];
        ++sine_phase;
        if (sine_phase >= TABLE_SIZE_CVSD) {
            sine_phase -= TABLE_SIZE_CVSD;
        }
    }
    return sz;
}
static void incoming_cb(const uint8_t *buf, uint32_t len) {
	//ESP_LOGI(HFP_TAG, "Data in: address: %x Length: %d", (int) buf, len);
	esp_hf_outgoing_data_ready();

}

I understand that there are many issues on this forum, and time is not a free resource. I was hoping for either some feedback on what I might be doing wrong, or an update on whether or not this issue can be fixed. I've seen at least 1 other person with the same issue a few years ago. Maybe things have changed since then?

Thanks,
Searock

ESP_Alvin
Posts: 211
Joined: Thu May 17, 2018 2:26 am

Re: HFP AG Callback function not working properly [BT-776]

Postby ESP_Alvin » Tue Apr 21, 2020 2:11 am

Moderator's note: edit the topic title for issue tracking, thanks.

KBFEDE
Posts: 8
Joined: Sun Apr 26, 2020 8:56 am

Re: HFP AG Callback function not working properly [BT-776]

Postby KBFEDE » Sun Apr 26, 2020 9:07 am

Hi, this is an already known issue on Github.
We are doing optimization of Bluedroid and maybe we shall fix this on the newer IDF version like release/v4.2.
Sorry for wasting your time, thanks.

KBFEDE
Posts: 8
Joined: Sun Apr 26, 2020 8:56 am

Re: HFP AG Callback function not working properly [BT-776]

Postby KBFEDE » Mon Apr 27, 2020 2:22 am

Here is the link to the same issue on Github.

https://github.com/espressif/esp-idf/issues/4967

Please follow this issue and we will update this on Github.

ypiotr
Posts: 3
Joined: Tue May 26, 2020 8:04 am

Re: HFP AG Callback function not working properly [BT-776]

Postby ypiotr » Fri Oct 09, 2020 11:07 am

Hi!
Have you done any progress since April? I'm having the same problem. I want to send some audio messages through using HFP and when I try using the "hf cona;" command from the HFP AG example the ESP get stuck in codec negotiations I think. I can post the console output if you want.

Regards,
Piotr

Who is online

Users browsing this forum: Baidu [Spider], VinayDand and 115 guests