components/bt: Not post message to a2dp ctrl queue from btc queue, just call it.

This commit is contained in:
baohongde 2019-10-29 17:30:50 +08:00
parent 304f6a577a
commit e85804824e
3 changed files with 33 additions and 89 deletions

View File

@ -321,7 +321,7 @@ error_exit:;
int btc_init(void)
{
btc_thread = osi_thread_create("BTC_TASK", BTC_TASK_STACK_SIZE, BTC_TASK_PRIO, BTC_TASK_PINNED_TO_CORE, 3);
btc_thread = osi_thread_create("BTC_TASK", BTC_TASK_STACK_SIZE, BTC_TASK_PRIO, BTC_TASK_PINNED_TO_CORE, 2);
if (btc_thread == NULL) {
return BT_STATUS_NOMEM;
}

View File

@ -109,7 +109,6 @@ typedef struct {
typedef struct {
tBTC_A2DP_SINK_CB btc_aa_snk_cb;
future_t *btc_a2dp_sink_future;
osi_thread_t *btc_aa_snk_task_hdl;
OI_CODEC_SBC_DECODER_CONTEXT context;
OI_UINT32 contextData[CODEC_DATA_WORDS(2, SBC_CODEC_FAST_FILTER_BUFFERS)];
@ -128,8 +127,6 @@ static void btc_a2dp_sink_handle_decoder_reset(tBTC_MEDIA_SINK_CFG_UPDATE *p_msg
static void btc_a2dp_sink_handle_clear_track(void);
static BOOLEAN btc_a2dp_sink_clear_track(void);
static void btc_a2dp_sink_ctrl_handler(void *arg);
static void btc_a2dp_sink_data_ready(void *context);
static int btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_OFF;
@ -171,29 +168,9 @@ static inline void btc_a2d_cb_to_app(esp_a2d_cb_event_t event, esp_a2d_cb_param_
** BTC ADAPTATION
*****************************************************************************/
static bool btc_a2dp_sink_ctrl_post(uint32_t sig, void *param)
static bool btc_a2dp_sink_ctrl(uint32_t sig, void *param)
{
a2dp_sink_task_evt_t *evt = (a2dp_sink_task_evt_t *)osi_malloc(sizeof(a2dp_sink_task_evt_t));
if (evt == NULL) {
return false;
}
evt->sig = sig;
evt->param = param;
return osi_thread_post(a2dp_sink_local_param.btc_aa_snk_task_hdl, btc_a2dp_sink_ctrl_handler, evt, 1, OSI_THREAD_MAX_TIMEOUT);
}
static void btc_a2dp_sink_ctrl_handler(void *arg)
{
a2dp_sink_task_evt_t *e = (a2dp_sink_task_evt_t *)arg;
if (e == NULL) {
return;
}
switch (e->sig) {
switch (sig) {
case BTC_MEDIA_TASK_SINK_INIT:
btc_a2dp_sink_thread_init(NULL);
break;
@ -201,7 +178,7 @@ static void btc_a2dp_sink_ctrl_handler(void *arg)
btc_a2dp_sink_thread_cleanup(NULL);
break;
case BTC_MEDIA_AUDIO_SINK_CFG_UPDATE:
btc_a2dp_sink_handle_decoder_reset(e->param);
btc_a2dp_sink_handle_decoder_reset(param);
break;
case BTC_MEDIA_AUDIO_SINK_CLEAR_TRACK:
btc_a2dp_sink_handle_clear_track();
@ -210,14 +187,14 @@ static void btc_a2dp_sink_ctrl_handler(void *arg)
btc_a2dp_sink_rx_flush();
break;
default:
APPL_TRACE_WARNING("media task unhandled evt: 0x%x\n", e->sig);
APPL_TRACE_WARNING("media task unhandled evt: 0x%x\n", sig);
}
if (e->param != NULL) {
osi_free(e->param);
if (param != NULL) {
osi_free(param);
}
osi_free(e);
return true;
}
bool btc_a2dp_sink_startup(void)
@ -239,7 +216,7 @@ bool btc_a2dp_sink_startup(void)
a2dp_sink_local_param.btc_aa_snk_task_hdl = btc_thread;
if (btc_a2dp_sink_ctrl_post(BTC_MEDIA_TASK_SINK_INIT, NULL) == false) {
if (btc_a2dp_sink_ctrl(BTC_MEDIA_TASK_SINK_INIT, NULL) == false) {
goto error_exit;
}
@ -265,11 +242,8 @@ void btc_a2dp_sink_shutdown(void)
// Exit thread
btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_SHUTTING_DOWN;
a2dp_sink_local_param.btc_a2dp_sink_future = future_new();
assert(a2dp_sink_local_param.btc_a2dp_sink_future);
btc_a2dp_sink_ctrl_post(BTC_MEDIA_TASK_SINK_CLEAN_UP, NULL);
future_await(a2dp_sink_local_param.btc_a2dp_sink_future);
a2dp_sink_local_param.btc_a2dp_sink_future = NULL;
btc_a2dp_sink_ctrl(BTC_MEDIA_TASK_SINK_CLEAN_UP, NULL);
a2dp_sink_local_param.btc_aa_snk_task_hdl = NULL;
@ -322,7 +296,7 @@ void btc_a2dp_sink_on_suspended(tBTA_AV_SUSPEND *p_av)
static void btc_a2dp_sink_data_post(void)
{
osi_thread_post(a2dp_sink_local_param.btc_aa_snk_task_hdl, btc_a2dp_sink_data_ready, NULL, 2, OSI_THREAD_MAX_TIMEOUT);
osi_thread_post(a2dp_sink_local_param.btc_aa_snk_task_hdl, btc_a2dp_sink_data_ready, NULL, 1, OSI_THREAD_MAX_TIMEOUT);
}
/*******************************************************************************
@ -336,7 +310,7 @@ static void btc_a2dp_sink_data_post(void)
*******************************************************************************/
static BOOLEAN btc_a2dp_sink_clear_track(void)
{
return btc_a2dp_sink_ctrl_post(BTC_MEDIA_AUDIO_SINK_CLEAR_TRACK, NULL);
return btc_a2dp_sink_ctrl(BTC_MEDIA_AUDIO_SINK_CLEAR_TRACK, NULL);
}
/* when true media task discards any rx frames */
@ -370,7 +344,7 @@ void btc_a2dp_sink_reset_decoder(UINT8 *p_av)
}
memcpy(p_buf->codec_info, p_av, AVDT_CODEC_SIZE);
btc_a2dp_sink_ctrl_post(BTC_MEDIA_AUDIO_SINK_CFG_UPDATE, p_buf);
btc_a2dp_sink_ctrl(BTC_MEDIA_AUDIO_SINK_CFG_UPDATE, p_buf);
}
static void btc_a2dp_sink_data_ready(UNUSED_ATTR void *context)
@ -605,7 +579,7 @@ BOOLEAN btc_a2dp_sink_rx_flush_req(void)
return TRUE;
}
return btc_a2dp_sink_ctrl_post(BTC_MEDIA_FLUSH_AA_RX, NULL);
return btc_a2dp_sink_ctrl(BTC_MEDIA_FLUSH_AA_RX, NULL);
}
/*******************************************************************************
@ -748,8 +722,6 @@ static void btc_a2dp_sink_thread_cleanup(UNUSED_ATTR void *context)
fixed_queue_free(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ, osi_free_func);
a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ = NULL;
future_ready(a2dp_sink_local_param.btc_a2dp_sink_future, NULL);
}
#endif /* BTC_AV_SINK_INCLUDED */

View File

@ -166,7 +166,6 @@ typedef struct {
typedef struct {
tBTC_A2DP_SOURCE_CB btc_aa_src_cb;
future_t *btc_a2dp_source_future;
osi_thread_t *btc_aa_src_task_hdl;
UINT64 last_frame_us;
} a2dp_source_local_param_t;
@ -186,7 +185,6 @@ static void btc_a2dp_source_aa_tx_flush(void);
static void btc_a2dp_source_prep_2_send(UINT8 nb_frame);
static void btc_a2dp_source_handle_timer(UNUSED_ATTR void *context);
static void btc_a2dp_source_encoder_init(void);
static void btc_a2dp_source_ctrl_handler(void *arg);
static int btc_a2dp_source_state = BTC_A2DP_SOURCE_STATE_OFF;
static esp_a2d_source_data_cb_t btc_aa_src_data_cb = NULL;
@ -238,29 +236,9 @@ bool btc_a2dp_source_is_task_shutting_down(void)
return btc_a2dp_source_state == BTC_A2DP_SOURCE_STATE_SHUTTING_DOWN;
}
static bool btc_a2dp_source_ctrl_post(uint32_t sig, void *param)
static bool btc_a2dp_source_ctrl(uint32_t sig, void *param)
{
a2dp_src_task_evt_t *evt = (a2dp_src_task_evt_t *)osi_malloc(sizeof(a2dp_src_task_evt_t));
if (evt == NULL) {
return false;
}
evt->sig = sig;
evt->param = param;
return osi_thread_post(a2dp_source_local_param.btc_aa_src_task_hdl, btc_a2dp_source_ctrl_handler, evt, 1, OSI_THREAD_MAX_TIMEOUT);
}
static void btc_a2dp_source_ctrl_handler(void *arg)
{
a2dp_src_task_evt_t *e = (a2dp_src_task_evt_t *)arg;
if (e == NULL) {
return;
}
switch (e->sig) {
switch (sig) {
case BTC_MEDIA_TASK_INIT:
btc_a2dp_source_thread_init(NULL);
break;
@ -274,26 +252,26 @@ static void btc_a2dp_source_ctrl_handler(void *arg)
btc_a2dp_source_aa_stop_tx();
break;
case BTC_MEDIA_SBC_ENC_INIT:
btc_a2dp_source_enc_init(e->param);
btc_a2dp_source_enc_init(param);
break;
case BTC_MEDIA_SBC_ENC_UPDATE:
btc_a2dp_source_enc_update(e->param);
btc_a2dp_source_enc_update(param);
break;
case BTC_MEDIA_AUDIO_FEEDING_INIT:
btc_a2dp_source_audio_feeding_init(e->param);
btc_a2dp_source_audio_feeding_init(param);
break;
case BTC_MEDIA_FLUSH_AA_TX:
btc_a2dp_source_aa_tx_flush();
break;
default:
APPL_TRACE_WARNING("media task unhandled evt: 0x%x\n", e->sig);
APPL_TRACE_WARNING("media task unhandled evt: 0x%x\n", sig);
}
if (e->param != NULL) {
osi_free(e->param);
if (param != NULL) {
osi_free(param);
}
osi_free(e);
return true;
}
bool btc_a2dp_source_startup(void)
@ -315,7 +293,7 @@ bool btc_a2dp_source_startup(void)
a2dp_source_local_param.btc_aa_src_task_hdl = btc_thread;
if (btc_a2dp_source_ctrl_post(BTC_MEDIA_TASK_INIT, NULL) == false) {
if (btc_a2dp_source_ctrl(BTC_MEDIA_TASK_INIT, NULL) == false) {
goto error_exit;
}
@ -341,11 +319,7 @@ void btc_a2dp_source_shutdown(void)
// Exit thread
btc_a2dp_source_state = BTC_A2DP_SOURCE_STATE_SHUTTING_DOWN;
a2dp_source_local_param.btc_a2dp_source_future = future_new();
assert(a2dp_source_local_param.btc_a2dp_source_future);
btc_a2dp_source_ctrl_post(BTC_MEDIA_TASK_CLEAN_UP, NULL);
future_await(a2dp_source_local_param.btc_a2dp_source_future);
a2dp_source_local_param.btc_a2dp_source_future = NULL;
btc_a2dp_source_ctrl(BTC_MEDIA_TASK_CLEAN_UP, NULL);
a2dp_source_local_param.btc_aa_src_task_hdl = NULL;
@ -421,7 +395,7 @@ void btc_a2dp_source_on_suspended(tBTA_AV_SUSPEND *p_av)
static void btc_a2dp_source_data_post(void)
{
osi_thread_post(a2dp_source_local_param.btc_aa_src_task_hdl, btc_a2dp_source_handle_timer, NULL, 2, OSI_THREAD_MAX_TIMEOUT);
osi_thread_post(a2dp_source_local_param.btc_aa_src_task_hdl, btc_a2dp_source_handle_timer, NULL, 1, OSI_THREAD_MAX_TIMEOUT);
}
static UINT64 time_now_us()
@ -524,7 +498,7 @@ BT_HDR *btc_a2dp_source_audio_readbuf(void)
*******************************************************************************/
BOOLEAN btc_a2dp_source_start_audio_req(void)
{
btc_a2dp_source_ctrl_post(BTC_MEDIA_START_AA_TX, NULL);
btc_a2dp_source_ctrl(BTC_MEDIA_START_AA_TX, NULL);
return TRUE;
}
@ -552,7 +526,7 @@ BOOLEAN btc_a2dp_source_stop_audio_req(void)
#if 0
if (btc_aa_src_ctrl_queue != NULL) {
#endif
btc_a2dp_source_ctrl_post(BTC_MEDIA_STOP_AA_TX, NULL);
btc_a2dp_source_ctrl(BTC_MEDIA_STOP_AA_TX, NULL);
#if 0
}
#endif
@ -577,7 +551,7 @@ BOOLEAN btc_a2dp_source_enc_init_req(tBTC_MEDIA_INIT_AUDIO *p_msg)
memcpy(p_buf, p_msg, sizeof(tBTC_MEDIA_INIT_AUDIO));
btc_a2dp_source_ctrl_post(BTC_MEDIA_SBC_ENC_INIT, p_buf);
btc_a2dp_source_ctrl(BTC_MEDIA_SBC_ENC_INIT, p_buf);
return TRUE;
}
@ -599,7 +573,7 @@ BOOLEAN btc_a2dp_source_enc_update_req(tBTC_MEDIA_UPDATE_AUDIO *p_msg)
}
memcpy(p_buf, p_msg, sizeof(tBTC_MEDIA_UPDATE_AUDIO));
btc_a2dp_source_ctrl_post(BTC_MEDIA_SBC_ENC_UPDATE, p_buf);
btc_a2dp_source_ctrl(BTC_MEDIA_SBC_ENC_UPDATE, p_buf);
return TRUE;
}
@ -620,7 +594,7 @@ BOOLEAN btc_a2dp_source_audio_feeding_init_req(tBTC_MEDIA_INIT_AUDIO_FEEDING *p_
}
memcpy(p_buf, p_msg, sizeof(tBTC_MEDIA_INIT_AUDIO_FEEDING));
btc_a2dp_source_ctrl_post(BTC_MEDIA_AUDIO_FEEDING_INIT, p_buf);
btc_a2dp_source_ctrl(BTC_MEDIA_AUDIO_FEEDING_INIT, p_buf);
return TRUE;
}
@ -648,7 +622,7 @@ BOOLEAN btc_a2dp_source_tx_flush_req(void)
#if 0
if (btc_aa_src_ctrl_queue != NULL) {
#endif
btc_a2dp_source_ctrl_post(BTC_MEDIA_FLUSH_AA_TX, NULL);
btc_a2dp_source_ctrl(BTC_MEDIA_FLUSH_AA_TX, NULL);
#if 0
}
#endif
@ -1616,8 +1590,6 @@ static void btc_a2dp_source_thread_cleanup(UNUSED_ATTR void *context)
fixed_queue_free(a2dp_source_local_param.btc_aa_src_cb.TxAaQ, osi_free_func);
a2dp_source_local_param.btc_aa_src_cb.TxAaQ = NULL;
future_ready(a2dp_source_local_param.btc_a2dp_source_future, NULL);
}
#endif /* BTC_AV_INCLUDED */