From 29b009d6fd6ce66d561ffcab3303ea1760aa3d31 Mon Sep 17 00:00:00 2001 From: wangmengyang Date: Sun, 5 May 2019 11:42:27 +0800 Subject: [PATCH] component/bt: fix some performance issues in A2DP source data flow control 1. modify the limit of frames to send to avoid dropping packet on A2DP source due to TX data queue overflow 2. reduce the A2DP source data queue size in order to achieve faster control respnonse --- .../btc/profile/std/a2dp/btc_a2dp_source.c | 14 ++++++++++---- components/bt/bluedroid/osi/include/osi/thread.h | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c index a4697bc26..5afbd3722 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c +++ b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c @@ -1156,10 +1156,16 @@ static UINT8 btc_get_num_aa_frame(void) /* calculate nbr of frames pending for this media tick */ result = btc_aa_src_cb.media_feeding_state.pcm.counter / pcm_bytes_per_frame; - if (result > MAX_PCM_FRAME_NUM_PER_TICK) { - APPL_TRACE_WARNING("%s() - Limiting frames to be sent from %d to %d" - , __FUNCTION__, result, MAX_PCM_FRAME_NUM_PER_TICK); - result = MAX_PCM_FRAME_NUM_PER_TICK; + + /* limit the frames to be sent */ + UINT32 frm_nb_threshold = MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - fixed_queue_length(btc_aa_src_cb.TxAaQ); + if (frm_nb_threshold > MAX_PCM_FRAME_NUM_PER_TICK) { + frm_nb_threshold = MAX_PCM_FRAME_NUM_PER_TICK; + } + + if (result > frm_nb_threshold) { + APPL_TRACE_EVENT("Limit frms to send from %d to %d", result, frm_nb_threshold); + result = frm_nb_threshold; } btc_aa_src_cb.media_feeding_state.pcm.counter -= result * pcm_bytes_per_frame; diff --git a/components/bt/bluedroid/osi/include/osi/thread.h b/components/bt/bluedroid/osi/include/osi/thread.h index 1aa773c01..cd08e8f9c 100644 --- a/components/bt/bluedroid/osi/include/osi/thread.h +++ b/components/bt/bluedroid/osi/include/osi/thread.h @@ -95,7 +95,7 @@ typedef enum { #define BTC_A2DP_SOURCE_TASK_STACK_SIZE (CONFIG_A2DP_SOURCE_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) // by menuconfig #define BTC_A2DP_SOURCE_TASK_NAME "BtA2dSourceT" #define BTC_A2DP_SOURCE_TASK_PRIO (configMAX_PRIORITIES - 3) -#define BTC_A2DP_SOURCE_DATA_QUEUE_LEN (3) +#define BTC_A2DP_SOURCE_DATA_QUEUE_LEN (1) #define BTC_A2DP_SOURCE_CTRL_QUEUE_LEN (5) #define BTC_A2DP_SOURCE_TASK_QUEUE_SET_LEN (BTC_A2DP_SOURCE_DATA_QUEUE_LEN + BTC_A2DP_SOURCE_CTRL_QUEUE_LEN)