Merge branch 'bugfix/a2dp_source_congest_v4.4' into 'release/v4.4'

component_bt: Fixed a2dp source audio data packet congestion causing choppy audio in a2dp sink (v4.4)

See merge request espressif/esp-idf!16733
This commit is contained in:
Jiang Jiang Jian 2022-02-09 08:16:01 +00:00
commit c8075df214
4 changed files with 27 additions and 81 deletions

View File

@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// 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.
/***************************************************************************** /*****************************************************************************
* *
@ -33,7 +25,7 @@
#if BTC_AV_INCLUDED #if BTC_AV_INCLUDED
typedef struct { 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 */ UINT8 a2dp_cmd_pending; /* we can have max one command pending */
} tBTC_AA_CTRL_CB; } tBTC_AA_CTRL_CB;
@ -83,7 +75,9 @@ static void btc_a2dp_datapath_open(void)
btc_a2dp_source_encoder_update(); btc_a2dp_source_encoder_update();
} }
#endif #endif
#if (BTC_AV_SINK_INCLUDED == TRUE)
btc_aa_ctrl_cb.data_channel_open = TRUE; btc_aa_ctrl_cb.data_channel_open = TRUE;
#endif
} }
BOOLEAN btc_a2dp_control_get_datachnl_stat(void) BOOLEAN btc_a2dp_control_get_datachnl_stat(void)
@ -96,22 +90,6 @@ void btc_a2dp_control_set_datachnl_stat(BOOLEAN open)
btc_aa_ctrl_cb.data_channel_open = 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) void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl)
{ {
APPL_TRACE_DEBUG("BTC MEDIA (A2DP-DATA) EVENT %u", ctrl); APPL_TRACE_DEBUG("BTC MEDIA (A2DP-DATA) EVENT %u", ctrl);
@ -146,17 +124,14 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl)
break; break;
case ESP_A2D_MEDIA_CTRL_START: case ESP_A2D_MEDIA_CTRL_START:
if (btc_av_stream_ready() == TRUE ) { 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_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_SINK_INCLUDED == TRUE)
if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) { 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); btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS);
} }
#endif #endif
} else if (btc_av_stream_started_ready()) { } 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); btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS);
} else { } else {
btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE);

View File

@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// 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.
/****************************************************************************** /******************************************************************************
** **
@ -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) static void btc_a2dp_source_thread_cleanup(UNUSED_ATTR void *context)
{ {
btc_a2dp_control_set_datachnl_stat(FALSE);
/* Clear media task flag */ /* Clear media task flag */
btc_a2dp_source_state = BTC_A2DP_SOURCE_STATE_OFF; btc_a2dp_source_state = BTC_A2DP_SOURCE_STATE_OFF;

View File

@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// 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.
/***************************************************************************** /*****************************************************************************
* *
@ -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 */ /* pending start flag will be cleared when exit current state */
} }
#endif /* BTC_AV_SRC_INCLUDED */ #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); btc_sm_change_state(btc_av_cb.sm_handle, BTC_AV_STATE_STARTED);
} break; } break;
@ -1509,10 +1504,6 @@ void btc_a2dp_call_handler(btc_msg_t *msg)
btc_a2dp_control_media_ctrl(arg->ctrl); btc_a2dp_control_media_ctrl(arg->ctrl);
break; break;
} }
case BTC_AV_DATAPATH_CTRL_EVT: {
btc_a2dp_control_datapath_ctrl(arg->dp_evt);
break;
}
case BTC_AV_CONNECT_REQ_EVT: case BTC_AV_CONNECT_REQ_EVT:
btc_sm_dispatch(btc_av_cb.sm_handle, msg->act, (char *)msg->arg); btc_sm_dispatch(btc_av_cb.sm_handle, msg->act, (char *)msg->arg);
break; break;

View File

@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// 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.
/******************************************************************************* /*******************************************************************************
@ -79,7 +71,6 @@ typedef enum {
BTC_AV_SRC_API_REG_DATA_CB_EVT, BTC_AV_SRC_API_REG_DATA_CB_EVT,
#endif /* BTC_AV_SRC_INCLUDED */ #endif /* BTC_AV_SRC_INCLUDED */
BTC_AV_API_MEDIA_CTRL_EVT, BTC_AV_API_MEDIA_CTRL_EVT,
BTC_AV_DATAPATH_CTRL_EVT,
} btc_av_act_t; } btc_av_act_t;
/* btc_av_args_t */ /* btc_av_args_t */
@ -104,8 +95,6 @@ typedef union {
#endif /* BTC_AV_SRC_INCLUDED */ #endif /* BTC_AV_SRC_INCLUDED */
// BTC_AV_API_MEDIA_CTRL_EVT // BTC_AV_API_MEDIA_CTRL_EVT
esp_a2d_media_ctrl_t ctrl; esp_a2d_media_ctrl_t ctrl;
// BTC_AV_DATAPATH_CTRL_EVT
uint32_t dp_evt;
} btc_av_args_t; } btc_av_args_t;
/******************************************************************************* /*******************************************************************************