From d338750b86fd7bb5d818ee384fa584766dcce590 Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Thu, 23 Dec 2021 20:45:09 +0800 Subject: [PATCH 1/4] Fixed a2dp source audio data packet congestion causing choppy audio in a2dp sink --- .../btc/profile/std/a2dp/btc_a2dp_control.c | 22 +++++-------------- .../bluedroid/btc/profile/std/a2dp/btc_av.c | 21 +++++++----------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c index 732ab503f8..13f0bf79f5 100644 --- a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c +++ b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c @@ -1,16 +1,8 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /***************************************************************************** * @@ -146,10 +138,8 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl) break; case ESP_A2D_MEDIA_CTRL_START: if (btc_av_stream_ready() == TRUE ) { - /* post start event and wait for audio path to open */ + /* post start event */ btc_dispatch_sm_event(BTC_AV_START_STREAM_REQ_EVT, NULL, 0); - - btc_a2dp_dispatch_datapath_evt(BTC_AV_DATAPATH_OPEN_EVT); #if (BTC_AV_SINK_INCLUDED == TRUE) if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) { btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); diff --git a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c index 52003751a2..a0ade8130f 100644 --- a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c +++ b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c @@ -1,16 +1,8 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /***************************************************************************** * @@ -681,6 +673,9 @@ static BOOLEAN btc_av_state_opened_handler(btc_sm_event_t event, void *p_data) /* pending start flag will be cleared when exit current state */ } #endif /* BTC_AV_SRC_INCLUDED */ + /* wait for audio path to open */ + btc_a2dp_control_datapath_ctrl(BTC_AV_DATAPATH_OPEN_EVT); + btc_sm_change_state(btc_av_cb.sm_handle, BTC_AV_STATE_STARTED); } break; From e4277d520298371ba806a4836913b6668a042383 Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Thu, 23 Dec 2021 21:54:10 +0800 Subject: [PATCH 2/4] Fixed the crash caused by calling esp_a2d_media_ctrl(ESP_A2D_MEDIA_CTRL_START) after stream started --- .../bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c | 1 - 1 file changed, 1 deletion(-) diff --git a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c index 13f0bf79f5..eb422287a1 100644 --- a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c +++ b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c @@ -146,7 +146,6 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl) } #endif } else if (btc_av_stream_started_ready()) { - btc_a2dp_dispatch_datapath_evt(BTC_AV_DATAPATH_OPEN_EVT); btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); } else { btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); From 49f496e5397e6e7d7308d92def2456b92d7de8b8 Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Fri, 24 Dec 2021 11:29:27 +0800 Subject: [PATCH 3/4] remove btc_a2dp_dispatch_datapath_evt and event --- .../btc/profile/std/a2dp/btc_a2dp_control.c | 16 -------------- .../bluedroid/btc/profile/std/a2dp/btc_av.c | 4 ---- .../btc/profile/std/include/btc_av.h | 21 +++++-------------- 3 files changed, 5 insertions(+), 36 deletions(-) diff --git a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c index eb422287a1..458f9d39dd 100644 --- a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c +++ b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c @@ -88,22 +88,6 @@ void btc_a2dp_control_set_datachnl_stat(BOOLEAN open) btc_aa_ctrl_cb.data_channel_open = open; } -static void btc_a2dp_dispatch_datapath_evt(uint32_t dp_evt) -{ - btc_msg_t msg; - msg.sig = BTC_SIG_API_CALL; - msg.pid = BTC_PID_A2DP; - msg.act = BTC_AV_DATAPATH_CTRL_EVT; - - btc_av_args_t arg; - memset(&arg, 0, sizeof(btc_av_args_t)); - arg.dp_evt = dp_evt; - - /* Switch to BTC context */ - APPL_TRACE_DEBUG("%s sig %u act %u, dp_evt %u\n", __func__, msg.sig, msg.act, arg.dp_evt); - btc_transfer_context(&msg, &arg, sizeof(btc_av_args_t), NULL); -} - void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl) { APPL_TRACE_DEBUG("BTC MEDIA (A2DP-DATA) EVENT %u", ctrl); diff --git a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c index a0ade8130f..f198294d50 100644 --- a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c +++ b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c @@ -1504,10 +1504,6 @@ void btc_a2dp_call_handler(btc_msg_t *msg) btc_a2dp_control_media_ctrl(arg->ctrl); break; } - case BTC_AV_DATAPATH_CTRL_EVT: { - btc_a2dp_control_datapath_ctrl(arg->dp_evt); - break; - } case BTC_AV_CONNECT_REQ_EVT: btc_sm_dispatch(btc_av_cb.sm_handle, msg->act, (char *)msg->arg); break; diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_av.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_av.h index 553f0ddec7..c4fd1ac16b 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_av.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_av.h @@ -1,16 +1,8 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /******************************************************************************* @@ -79,7 +71,6 @@ typedef enum { BTC_AV_SRC_API_REG_DATA_CB_EVT, #endif /* BTC_AV_SRC_INCLUDED */ BTC_AV_API_MEDIA_CTRL_EVT, - BTC_AV_DATAPATH_CTRL_EVT, } btc_av_act_t; /* btc_av_args_t */ @@ -104,8 +95,6 @@ typedef union { #endif /* BTC_AV_SRC_INCLUDED */ // BTC_AV_API_MEDIA_CTRL_EVT esp_a2d_media_ctrl_t ctrl; - // BTC_AV_DATAPATH_CTRL_EVT - uint32_t dp_evt; } btc_av_args_t; /******************************************************************************* From 7485b4d4b2880a93dbbda96fb003f965120a519a Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Thu, 6 Jan 2022 14:10:18 +0800 Subject: [PATCH 4/4] btc_a2dp_control_set_datachnl_stat is only used by a2dp sink --- .../btc/profile/std/a2dp/btc_a2dp_control.c | 4 +++- .../btc/profile/std/a2dp/btc_a2dp_source.c | 19 +++++-------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c index 458f9d39dd..814b408c9f 100644 --- a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c +++ b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c @@ -25,7 +25,7 @@ #if BTC_AV_INCLUDED typedef struct { - BOOLEAN data_channel_open; + BOOLEAN data_channel_open; /* used only by A2DP sink */ UINT8 a2dp_cmd_pending; /* we can have max one command pending */ } tBTC_AA_CTRL_CB; @@ -75,7 +75,9 @@ static void btc_a2dp_datapath_open(void) btc_a2dp_source_encoder_update(); } #endif +#if (BTC_AV_SINK_INCLUDED == TRUE) btc_aa_ctrl_cb.data_channel_open = TRUE; +#endif } BOOLEAN btc_a2dp_control_get_datachnl_stat(void) diff --git a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c index 8accd9b550..b35ac83fa5 100644 --- a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c +++ b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c @@ -1,16 +1,8 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /****************************************************************************** ** @@ -1579,7 +1571,6 @@ static void btc_a2dp_source_thread_init(UNUSED_ATTR void *context) static void btc_a2dp_source_thread_cleanup(UNUSED_ATTR void *context) { - btc_a2dp_control_set_datachnl_stat(FALSE); /* Clear media task flag */ btc_a2dp_source_state = BTC_A2DP_SOURCE_STATE_OFF;