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 9e943c3cef..5f987dbb32 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 @@ -393,11 +393,6 @@ void btc_a2dp_source_on_suspended(tBTA_AV_SUSPEND *p_av) btc_a2dp_source_stop_audio_req(); } -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, 1, OSI_THREAD_MAX_TIMEOUT); -} - static UINT64 time_now_us(void) { #if _POSIX_TIMERS @@ -1438,11 +1433,6 @@ static void btc_a2dp_source_handle_timer(UNUSED_ATTR void *context) #endif } -static void btc_a2dp_source_alarm_cb(UNUSED_ATTR void *context) -{ - btc_a2dp_source_data_post(); -} - /******************************************************************************* ** ** Function btc_a2dp_source_feeding_state_reset @@ -1469,40 +1459,6 @@ static void btc_a2dp_source_feeding_state_reset(void) } } -/******************************************************************************* - ** - ** Function btc_a2dp_source_aa_start_tx - ** - ** Description Start media task encoding - ** - ** Returns void - ** - *******************************************************************************/ -static void btc_a2dp_source_aa_start_tx(void) -{ - APPL_TRACE_DEBUG("btc_a2dp_source_aa_start_tx is timer %d, feeding mode %d", - a2dp_source_local_param.btc_aa_src_cb.is_tx_timer, a2dp_source_local_param.btc_aa_src_cb.feeding_mode); - - a2dp_source_local_param.btc_aa_src_cb.is_tx_timer = TRUE; - a2dp_source_local_param.last_frame_us = 0; - - /* Reset the media feeding state */ - btc_a2dp_source_feeding_state_reset(); - - APPL_TRACE_EVENT("starting timer %dms", BTC_MEDIA_TIME_TICK_MS); - - assert(a2dp_source_local_param.btc_aa_src_cb.media_alarm == NULL); - - a2dp_source_local_param.btc_aa_src_cb.media_alarm = osi_alarm_new("aaTx", btc_a2dp_source_alarm_cb, NULL, BTC_MEDIA_TIME_TICK_MS); - - if (!a2dp_source_local_param.btc_aa_src_cb.media_alarm) { - BTC_TRACE_ERROR("%s unable to allocate media alarm.", __func__); - return; - } - - osi_alarm_set_periodic(a2dp_source_local_param.btc_aa_src_cb.media_alarm, BTC_MEDIA_TIME_TICK_MS); -} - /******************************************************************************* ** ** Function btc_a2dp_source_aa_stop_tx @@ -1549,6 +1505,50 @@ static void btc_a2dp_source_aa_stop_tx(void) btc_a2dp_source_feeding_state_reset(); } +/******************************************************************************* + ** + ** Function btc_a2dp_source_aa_start_tx + ** + ** Description Start media task encoding + ** + ** Returns void + ** + *******************************************************************************/ +static void btc_a2dp_source_alarm_cb(UNUSED_ATTR void *context) +{ + if (a2dp_source_local_param.btc_aa_src_task_hdl) { + osi_thread_post(a2dp_source_local_param.btc_aa_src_task_hdl, btc_a2dp_source_handle_timer, NULL, 1, OSI_THREAD_MAX_TIMEOUT); + } else { + APPL_TRACE_DEBUG("[%s] A2DP ALREADY FREED", __func__); + btc_a2dp_source_aa_stop_tx(); + } +} + +static void btc_a2dp_source_aa_start_tx(void) +{ + APPL_TRACE_DEBUG("btc_a2dp_source_aa_start_tx is timer %d, feeding mode %d", + a2dp_source_local_param.btc_aa_src_cb.is_tx_timer, a2dp_source_local_param.btc_aa_src_cb.feeding_mode); + + a2dp_source_local_param.btc_aa_src_cb.is_tx_timer = TRUE; + a2dp_source_local_param.last_frame_us = 0; + + /* Reset the media feeding state */ + btc_a2dp_source_feeding_state_reset(); + + APPL_TRACE_EVENT("starting timer %dms", BTC_MEDIA_TIME_TICK_MS); + + assert(a2dp_source_local_param.btc_aa_src_cb.media_alarm == NULL); + + a2dp_source_local_param.btc_aa_src_cb.media_alarm = osi_alarm_new("aaTx", btc_a2dp_source_alarm_cb, NULL, BTC_MEDIA_TIME_TICK_MS); + + if (!a2dp_source_local_param.btc_aa_src_cb.media_alarm) { + BTC_TRACE_ERROR("%s unable to allocate media alarm.", __func__); + return; + } + + osi_alarm_set_periodic(a2dp_source_local_param.btc_aa_src_cb.media_alarm, BTC_MEDIA_TIME_TICK_MS); +} + /******************************************************************************* ** ** Function btc_a2dp_source_flush_q