Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HFP AG example: outgoing callback not triggered (IDFGH-2931) #4967

Closed
pavestru opened this issue Mar 20, 2020 · 10 comments
Closed

HFP AG example: outgoing callback not triggered (IDFGH-2931) #4967

pavestru opened this issue Mar 20, 2020 · 10 comments

Comments

@pavestru
Copy link

Environment

  • Development Kit: ESP32-Wrover-Kit
  • Kit version v4
  • Module or chip used: ESP32-WROVER-B
  • IDF version: v4.2-dev-781-g47253a827
  • Build System: make
  • Compiler version: xtensa-esp32-elf-gcc (crosstool-NG esp-2019r2) 8.2.0
  • Operating System: macOS
  • Using an IDE?: No
  • Power Supply: USB

Problem Description

ESP32 connects to a BT headset, receives audio from BT headset (CVSD codec), however, it is not sending audio to the same BT headset. Callback bt_app_hf_outgoing_cb (see here) almost never gets called. If it ever does, it is followed by a crash exactly like described in #4794 .

Expected Behavior

Callback bt_app_hf_outgoing_cb is expected to get called to play the sine wave in the headphones.

Actual Behavior

Callback bt_app_hf_outgoing_cb is not run at all except very rarely and randomly, followed by crashes exactly like described in #4794 .

Steps to reproduce

  1. Open [HFP AG](https://github.com/espressif/esp-idf/tree/master/examples/bluetooth/bluedroid/classic_bt/hfp_ag example)
  2. put a ESP_LOGI("..."); statement to both bt_app_hf_outgoing_cb and bt_app_hf_incoming_cb
  3. Follow README in hfp_ag example
  4. Uncomment this line and put mac address of your BT headset there
  5. Set HCI data path in menuconfig
  6. leave Bluedroid Options --> Wide Band Speech off
  7. set BR/EDR Sync(SCO/eSCO) Max Connections to 1 or more (default is 0)
  8. make flash monitor (runs HFP AG example)
  9. hf con; (if not connected yet)
  10. hf cona;

Code to reproduce this issue

Example code for callbacks in bt_app_hf.c:

static uint32_t bt_app_hf_outgoing_cb(uint8_t *p_buf, uint32_t sz)
{
    ESP_LOGE(BT_HF_TAG, "bt_app_hf_outgoing_cb");
    
    int sine_phase = esp_random();

    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 bt_app_hf_incoming_cb(const uint8_t *buf, uint32_t sz)
{
    ESP_LOGE(BT_HF_TAG, "bt_app_hf_incoming_cb, buf size: %d", sz);
    // direct to i2s
    esp_hf_outgoing_data_ready();
}

Note

I am using Sony SBH20 and Sony WH-1000XM3 headsets, both have the same behaviour.

Thank you.

@github-actions github-actions bot changed the title HFP AG example: outgoing callback not triggered HFP AG example: outgoing callback not triggered (IDFGH-2931) Mar 20, 2020
@Alvin1Zhang
Copy link
Collaborator

@pavestru Thanks for reporting, we will look into.

@KollarRichard
Copy link

Hi, is there any news on this issue?

@ypiotrp
Copy link

ypiotrp commented Jun 16, 2020

Hi. I got the same issue on the newest master. What is the status here? Is it a work in progress?

@howroyd
Copy link
Contributor

howroyd commented Jul 3, 2020

Same issue here. The outgoing callback hasn't been called once, but the incoming is firing as expected.

@howroyd
Copy link
Contributor

howroyd commented Jul 24, 2020

Just tested on latest pull from release v4.2 and still got the issue.

My log is just being flooded with the following. Incoming audio (from HFP client) seems ok, but a little glitchy. Certainly nowhere near as stable as A2DP.

W (22802) BT_APPL: bta_ag_sco_read_cback: status(2)

From what I can see this is a warning that there is no data in the SCO layer? Not surprising since the callback isn't being called to retrieve the data.

@glennhuber
Copy link

Just tested on 4.3 and still not working. Is this issue being looked into at Espressif?

@ypiotrp
Copy link

ypiotrp commented Oct 12, 2020

Hi @Alvin1Zhang! Have made any progress on this issue?

@Alvin1Zhang
Copy link
Collaborator

Thanks for the updates, and sorry for slow turnaround, we are still debugging this issue, will share updates once available. Thanks.

@boblane1
Copy link
Collaborator

Hi, @pavestru and other users!
I offer a patch to fix this problem, you can have a try. Please let me know if it still has problems. By the way, it is not recommended to print too much information in the callback function.

0001-fix-ag-example-outgoing-callback-not-triggered.zip

@ypiotrp
Copy link

ypiotrp commented Oct 13, 2020

Hi @boblane1!
I applied the patch you shared to release v4.1 ESP-IDF and this is the result that I got - https://www.youtube.com/watch?v=peONupbGCGs. I don't know if this is what should be expected but it is definitely a step up.

Thank you very much!

For everyone else. To reproduce this effect checkout the ESP-IDF at v4.1, apply the patch from the @boblane1's post, change the SCO path to HCI, disable the Wide Band Speech and change the BR/EDR Sync(SCO/eSCO) Max Connections to 1. Compile, flash, voila!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants