component/bt: use macro "BTIF_AV_SRC_INCLUDED" to separate the A2DP source and SBC encoder module

This commit is contained in:
wangmengyang 2016-11-22 17:10:23 +08:00
parent d833293581
commit bb79b2d19b
2 changed files with 96 additions and 14 deletions

View file

@ -365,7 +365,7 @@ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data
btif_report_connection_state(state, &(btif_av_cb.peer_bda)); btif_report_connection_state(state, &(btif_av_cb.peer_bda));
/* change state to open/idle based on the status */ /* change state to open/idle based on the status */
btif_sm_change_state(btif_av_cb.sm_handle, av_state); btif_sm_change_state(btif_av_cb.sm_handle, av_state);
#if 0 #if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{ {
/* if queued PLAY command, send it now */ /* if queued PLAY command, send it now */
@ -379,7 +379,7 @@ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data
/* Bring up AVRCP connection too */ /* Bring up AVRCP connection too */
BTA_AvOpenRc(btif_av_cb.bta_handle); BTA_AvOpenRc(btif_av_cb.bta_handle);
} }
#endif /* #if 0*/ #endif
btif_queue_advance(); btif_queue_advance();
} break; } break;
@ -460,12 +460,14 @@ static BOOLEAN btif_av_state_closing_handler(btif_sm_event_t event, void *p_data
switch (event) switch (event)
{ {
case BTIF_SM_ENTER_EVT: case BTIF_SM_ENTER_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{ {
/* immediately stop transmission of frames */ /* immediately stop transmission of frames */
btif_a2dp_set_tx_flush(TRUE); btif_a2dp_set_tx_flush(TRUE);
/* wait for audioflinger to stop a2dp */ /* wait for audioflinger to stop a2dp */
} }
#endif /* (BTIF_AV_SRC_INCLUDED == TRUE) */
if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
{ {
btif_a2dp_set_rx_flush(TRUE); btif_a2dp_set_rx_flush(TRUE);
@ -474,11 +476,13 @@ static BOOLEAN btif_av_state_closing_handler(btif_sm_event_t event, void *p_data
case BTA_AV_STOP_EVT: case BTA_AV_STOP_EVT:
case BTIF_AV_STOP_STREAM_REQ_EVT: case BTIF_AV_STOP_STREAM_REQ_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{ {
/* immediately flush any pending tx frames while suspend is pending */ /* immediately flush any pending tx frames while suspend is pending */
btif_a2dp_set_tx_flush(TRUE); btif_a2dp_set_tx_flush(TRUE);
} }
#endif
if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
{ {
btif_a2dp_set_rx_flush(TRUE); btif_a2dp_set_rx_flush(TRUE);
@ -549,8 +553,10 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data)
break; break;
case BTIF_AV_START_STREAM_REQ_EVT: case BTIF_AV_START_STREAM_REQ_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep != AVDT_TSEP_SRC) if (btif_av_cb.peer_sep != AVDT_TSEP_SRC)
btif_a2dp_setup_codec(); btif_a2dp_setup_codec();
#endif
BTA_AvStart(); BTA_AvStart();
btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_START; btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_START;
break; break;
@ -563,6 +569,7 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data)
if ((p_av->start.status == BTA_SUCCESS) && (p_av->start.suspending == TRUE)) if ((p_av->start.status == BTA_SUCCESS) && (p_av->start.suspending == TRUE))
return TRUE; return TRUE;
#if (BTIF_AV_SRC_INCLUDED == TRUE)
/* if remote tries to start a2dp when DUT is a2dp source /* if remote tries to start a2dp when DUT is a2dp source
* then suspend. In case a2dp is sink and call is active * then suspend. In case a2dp is sink and call is active
* then disconnect the AVDTP channel * then disconnect the AVDTP channel
@ -586,7 +593,7 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data)
btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START; btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
} }
} }
#endif
/* remain in open state if status failed */ /* remain in open state if status failed */
if (p_av->start.status != BTA_AV_SUCCESS) if (p_av->start.status != BTA_AV_SUCCESS)
return FALSE; return FALSE;
@ -598,8 +605,10 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data)
/* change state to started, send acknowledgement if start is pending */ /* change state to started, send acknowledgement if start is pending */
if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) { if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) {
#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
btif_a2dp_on_started(NULL, TRUE); btif_a2dp_on_started(NULL, TRUE);
#endif
/* pending start flag will be cleared when exit current state */ /* pending start flag will be cleared when exit current state */
} }
btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_STARTED); btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_STARTED);
@ -707,9 +716,11 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data
break; break;
case BTIF_AV_START_STREAM_REQ_EVT: case BTIF_AV_START_STREAM_REQ_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE)
/* we were remotely started, just ack back the local request */ /* we were remotely started, just ack back the local request */
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
btif_a2dp_on_started(NULL, TRUE); btif_a2dp_on_started(NULL, TRUE);
#endif
break; break;
/* fixme -- use suspend = true always to work around issue with BTA AV */ /* fixme -- use suspend = true always to work around issue with BTA AV */
@ -723,13 +734,13 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data
/* if we were remotely suspended but suspend locally, local suspend /* if we were remotely suspended but suspend locally, local suspend
always overrides */ always overrides */
btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND; btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{ {
/* immediately stop transmission of frames while suspend is pending */ /* immediately stop transmission of frames while suspend is pending */
btif_a2dp_set_tx_flush(TRUE); btif_a2dp_set_tx_flush(TRUE);
} }
#endif
if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) { if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
btif_a2dp_set_rx_flush(TRUE); btif_a2dp_set_rx_flush(TRUE);
btif_a2dp_on_stopped(NULL); btif_a2dp_on_stopped(NULL);
@ -762,12 +773,13 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data
if (p_av->suspend.status != BTA_AV_SUCCESS) if (p_av->suspend.status != BTA_AV_SUCCESS)
{ {
btif_av_cb.flags &= ~BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING; btif_av_cb.flags &= ~BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{ {
/* suspend failed, reset back tx flush state */ /* suspend failed, reset back tx flush state */
btif_a2dp_set_tx_flush(FALSE); btif_a2dp_set_tx_flush(FALSE);
} }
#endif
return FALSE; return FALSE;
} }
@ -982,6 +994,7 @@ bt_status_t btif_av_init()
return BT_STATUS_SUCCESS; return BT_STATUS_SUCCESS;
} }
#if (BTIF_AV_SRC_INCLUDED == TRUE)
/******************************************************************************* /*******************************************************************************
** **
** Function init_src ** Function init_src
@ -1003,6 +1016,7 @@ static bt_status_t init_src(btav_callbacks_t* callbacks)
return status; return status;
} }
#endif
/******************************************************************************* /*******************************************************************************
** **
** Function init_sink ** Function init_sink
@ -1046,6 +1060,7 @@ static bt_status_t connect_int(bt_bdaddr_t *bd_addr, uint16_t uuid)
return BT_STATUS_SUCCESS; return BT_STATUS_SUCCESS;
} }
#if (BTIF_AV_SRC_INCLUDED == TRUE)
static bt_status_t src_connect_sink(bt_bdaddr_t *bd_addr) static bt_status_t src_connect_sink(bt_bdaddr_t *bd_addr)
{ {
BTIF_TRACE_EVENT("%s\n", __FUNCTION__); BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
@ -1053,6 +1068,7 @@ static bt_status_t src_connect_sink(bt_bdaddr_t *bd_addr)
return btif_queue_connect(UUID_SERVCLASS_AUDIO_SOURCE, bd_addr, connect_int); return btif_queue_connect(UUID_SERVCLASS_AUDIO_SOURCE, bd_addr, connect_int);
} }
#endif
static bt_status_t sink_connect_src(bt_bdaddr_t *bd_addr) static bt_status_t sink_connect_src(bt_bdaddr_t *bd_addr)
{ {
@ -1107,6 +1123,7 @@ static void cleanup(void)
btif_av_cb.sm_handle = NULL; btif_av_cb.sm_handle = NULL;
} }
#if (BTIF_AV_SRC_INCLUDED == TRUE)
static void cleanup_src(void) { static void cleanup_src(void) {
BTIF_TRACE_EVENT("%s\n", __FUNCTION__); BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
@ -1117,6 +1134,7 @@ static void cleanup_src(void) {
cleanup(); cleanup();
} }
} }
#endif
static void cleanup_sink(void) { static void cleanup_sink(void) {
BTIF_TRACE_EVENT("%s\n", __FUNCTION__); BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
@ -1129,6 +1147,7 @@ static void cleanup_sink(void) {
} }
} }
#if (BTIF_AV_SRC_INCLUDED == TRUE)
static const btav_interface_t bt_av_src_interface = { static const btav_interface_t bt_av_src_interface = {
sizeof(btav_interface_t), sizeof(btav_interface_t),
init_src, init_src,
@ -1136,6 +1155,7 @@ static const btav_interface_t bt_av_src_interface = {
disconnect, disconnect,
cleanup_src, cleanup_src,
}; };
#endif
static const btav_interface_t bt_av_sink_interface = { static const btav_interface_t bt_av_sink_interface = {
sizeof(btav_interface_t), sizeof(btav_interface_t),
@ -1282,6 +1302,7 @@ bt_status_t btif_av_sink_execute_service(BOOLEAN b_enable)
return BT_STATUS_SUCCESS; return BT_STATUS_SUCCESS;
} }
#if (BTIF_AV_SRC_INCLUDED == TRUE)
/******************************************************************************* /*******************************************************************************
** **
** Function btif_av_get_src_interface ** Function btif_av_get_src_interface
@ -1297,6 +1318,7 @@ const btav_interface_t *btif_av_get_src_interface(void)
return &bt_av_src_interface; return &bt_av_src_interface;
} }
#endif
/******************************************************************************* /*******************************************************************************
** **
** Function btif_av_get_sink_interface ** Function btif_av_get_sink_interface

View file

@ -234,10 +234,13 @@ typedef union
typedef struct typedef struct
{ {
#if (BTA_AV_INCLUDED == TRUE) #if (BTA_AV_INCLUDED == TRUE)
#if (BTIF_AV_INCLUDED == TRUE)
BUFFER_Q TxAaQ; BUFFER_Q TxAaQ;
#endif /* #if (BTIF_AV_INCLUDED == TRUE) */
BUFFER_Q RxSbcQ; BUFFER_Q RxSbcQ;
BOOLEAN is_tx_timer; BOOLEAN is_tx_timer;
BOOLEAN is_rx_timer; BOOLEAN is_rx_timer;
#if (BTIF_AV_INCLUDED == TRUE)
UINT16 TxAaMtuSize; UINT16 TxAaMtuSize;
UINT32 timestamp; UINT32 timestamp;
UINT8 TxTranscoding; UINT8 TxTranscoding;
@ -245,10 +248,13 @@ typedef struct
tBTIF_AV_MEDIA_FEEDINGS media_feeding; tBTIF_AV_MEDIA_FEEDINGS media_feeding;
tBTIF_AV_MEDIA_FEEDINGS_STATE media_feeding_state; tBTIF_AV_MEDIA_FEEDINGS_STATE media_feeding_state;
SBC_ENC_PARAMS encoder; SBC_ENC_PARAMS encoder;
#endif /* #if (BTIF_AV_INCLUDED == TRUE) */
UINT8 busy_level; UINT8 busy_level;
void* av_sm_hdl; void* av_sm_hdl;
UINT8 a2dp_cmd_pending; /* we can have max one command pending */ UINT8 a2dp_cmd_pending; /* we can have max one command pending */
#if (BTIF_AV_INCLUDED == TRUE)
BOOLEAN tx_flush; /* discards any outgoing data when true */ BOOLEAN tx_flush; /* discards any outgoing data when true */
#endif /* #if (BTIF_AV_INCLUDED == TRUE) */
BOOLEAN rx_flush; /* discards any incoming data when true */ BOOLEAN rx_flush; /* discards any incoming data when true */
UINT8 peer_sep; UINT8 peer_sep;
BOOLEAN data_channel_open; BOOLEAN data_channel_open;
@ -256,7 +262,9 @@ typedef struct
UINT32 sample_rate; UINT32 sample_rate;
UINT8 channel_count; UINT8 channel_count;
#if (BTIF_AV_INCLUDED == TRUE)
osi_alarm_t *media_alarm; osi_alarm_t *media_alarm;
#endif /* #if (BTIF_AV_INCLUDED == TRUE) */
osi_alarm_t *decode_alarm; osi_alarm_t *decode_alarm;
#endif #endif
@ -270,11 +278,17 @@ typedef struct {
long long ts_prev_us; long long ts_prev_us;
} t_stat; } t_stat;
#if (BTIF_AV_SRC_INCLUDED == TRUE)
static UINT64 last_frame_us = 0; static UINT64 last_frame_us = 0;
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
static void btif_a2dp_data_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event); static void btif_a2dp_data_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event);
static void btif_a2dp_ctrl_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event); static void btif_a2dp_ctrl_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event);
#if (BTIF_AV_SRC_INCLUDED == TRUE)
static void btif_a2dp_encoder_update(void); static void btif_a2dp_encoder_update(void);
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
#if (BTA_AV_SINK_INCLUDED == TRUE) #if (BTA_AV_SINK_INCLUDED == TRUE)
extern OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context, extern OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context,
const OI_BYTE **frameData, const OI_BYTE **frameData,
@ -303,6 +317,7 @@ static void btif_media_task_handle_inc_media(tBT_SBC_HDR*p_msg);
#endif #endif
#if (BTA_AV_INCLUDED == TRUE) #if (BTA_AV_INCLUDED == TRUE)
#if (BTIF_AV_SRC_INCLUDED == TRUE)
static void btif_media_send_aa_frame(void); static void btif_media_send_aa_frame(void);
static void btif_media_task_feeding_state_reset(void); static void btif_media_task_feeding_state_reset(void);
static void btif_media_task_aa_start_tx(void); static void btif_media_task_aa_start_tx(void);
@ -312,6 +327,7 @@ static void btif_media_task_enc_update(BT_HDR *p_msg);
static void btif_media_task_audio_feeding_init(BT_HDR *p_msg); static void btif_media_task_audio_feeding_init(BT_HDR *p_msg);
static void btif_media_task_aa_tx_flush(BT_HDR *p_msg); static void btif_media_task_aa_tx_flush(BT_HDR *p_msg);
static void btif_media_aa_prep_2_send(UINT8 nb_frame); static void btif_media_aa_prep_2_send(UINT8 nb_frame);
#endif /* (BTIF_AV_SRC_INCLUDED == TRUE) */
#if (BTA_AV_SINK_INCLUDED == TRUE) #if (BTA_AV_SINK_INCLUDED == TRUE)
static void btif_media_task_aa_handle_decoder_reset(BT_HDR *p_msg); static void btif_media_task_aa_handle_decoder_reset(BT_HDR *p_msg);
static void btif_media_task_aa_handle_clear_track(void); static void btif_media_task_aa_handle_clear_track(void);
@ -320,7 +336,9 @@ static void btif_media_task_aa_handle_start_decoding(void);
#endif #endif
BOOLEAN btif_media_task_clear_track(void); BOOLEAN btif_media_task_clear_track(void);
static void btif_media_task_handler(void *arg); static void btif_media_task_handler(void *arg);
#if (BTIF_AV_SRC_INCLUDED == TRUE)
static void btif_media_task_aa_handle_timer(UNUSED_ATTR void *context); static void btif_media_task_aa_handle_timer(UNUSED_ATTR void *context);
#endif
static void btif_media_task_avk_handle_timer(UNUSED_ATTR void *context); static void btif_media_task_avk_handle_timer(UNUSED_ATTR void *context);
static void btif_media_thread_init(UNUSED_ATTR void *context); static void btif_media_thread_init(UNUSED_ATTR void *context);
static void btif_media_thread_cleanup(UNUSED_ATTR void *context); static void btif_media_thread_cleanup(UNUSED_ATTR void *context);
@ -346,6 +364,7 @@ BOOLEAN btif_hf_is_call_idle(void)
** Misc helper functions ** Misc helper functions
*****************************************************************************/ *****************************************************************************/
#if (BTIF_AV_SRC_INCLUDED == TRUE)
static UINT64 time_now_us() static UINT64 time_now_us()
{ {
// TODO: implement this function // TODO: implement this function
@ -360,6 +379,7 @@ static void log_tstamps_us(char *comment)
GKI_queue_length(&btif_media_cb.TxAaQ)); GKI_queue_length(&btif_media_cb.TxAaQ));
prev_us = now_us; prev_us = now_us;
} }
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
UNUSED_ATTR static const char *dump_media_event(UINT16 event) UNUSED_ATTR static const char *dump_media_event(UINT16 event)
{ {
@ -610,6 +630,7 @@ static void btif_a2dp_data_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event)
UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_SET_READ_POLL_TMO, UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_SET_READ_POLL_TMO,
(void *)A2DP_DATA_READ_POLL_MS); (void *)A2DP_DATA_READ_POLL_MS);
#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_media_cb.peer_sep == AVDT_TSEP_SNK) { if (btif_media_cb.peer_sep == AVDT_TSEP_SNK) {
/* Start the media task to encode SBC */ /* Start the media task to encode SBC */
btif_media_task_start_aa_req(); btif_media_task_start_aa_req();
@ -617,6 +638,7 @@ static void btif_a2dp_data_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event)
/* make sure we update any changed sbc encoder params */ /* make sure we update any changed sbc encoder params */
btif_a2dp_encoder_update(); btif_a2dp_encoder_update();
} }
#endif /* BTIF_AV_SRC_INCLUDED == TRUE */
btif_media_cb.data_channel_open = TRUE; btif_media_cb.data_channel_open = TRUE;
/* ack back when media task is fully started */ /* ack back when media task is fully started */
@ -638,7 +660,7 @@ static void btif_a2dp_data_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event)
/***************************************************************************** /*****************************************************************************
** BTIF ADAPTATION ** BTIF ADAPTATION
*****************************************************************************/ *****************************************************************************/
#if (BTIF_AV_SRC_INCLUDED == TRUE)
static UINT16 btif_media_task_get_sbc_rate(void) static UINT16 btif_media_task_get_sbc_rate(void)
{ {
UINT16 rate = DEFAULT_SBC_BITRATE; UINT16 rate = DEFAULT_SBC_BITRATE;
@ -740,6 +762,7 @@ static void btif_a2dp_encoder_update(void)
btif_media_task_enc_update_req(&msg); btif_media_task_enc_update_req(&msg);
} }
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
static void btif_media_task_post(uint32_t sig) static void btif_media_task_post(uint32_t sig)
{ {
@ -766,8 +789,10 @@ static void btif_media_task_handler(void *arg)
case SIG_MEDIA_TASK_AVK_ALARM_TO: case SIG_MEDIA_TASK_AVK_ALARM_TO:
btif_media_task_avk_handle_timer(NULL); btif_media_task_avk_handle_timer(NULL);
break; break;
#if (BTIF_AV_SRC_INCLUDED == TRUE)
case SIG_MEDIA_TASK_AA_ALARM_TO: case SIG_MEDIA_TASK_AA_ALARM_TO:
btif_media_task_aa_handle_timer(NULL); btif_media_task_aa_handle_timer(NULL);
#endif
break; break;
case SIG_MEDIA_TASK_CMD_READY: case SIG_MEDIA_TASK_CMD_READY:
fixed_queue_process(btif_media_cmd_msg_queue); fixed_queue_process(btif_media_cmd_msg_queue);
@ -835,10 +860,12 @@ void btif_a2dp_stop_media_task(void)
{ {
APPL_TRACE_EVENT("## A2DP STOP MEDIA THREAD ##\n"); APPL_TRACE_EVENT("## A2DP STOP MEDIA THREAD ##\n");
#if (BTIF_AV_INCLUDED == TRUE)
// Stop timer // Stop timer
osi_alarm_free(btif_media_cb.media_alarm); osi_alarm_free(btif_media_cb.media_alarm);
btif_media_cb.media_alarm = NULL; btif_media_cb.media_alarm = NULL;
btif_media_cb.is_tx_timer = FALSE; btif_media_cb.is_tx_timer = FALSE;
#endif /* #if (BTIF_AV_INCLUDED == TRUE) */
// Exit thread // Exit thread
btif_media_task_post(SIG_MEDIA_TASK_CLEAN_UP); btif_media_task_post(SIG_MEDIA_TASK_CLEAN_UP);
@ -895,6 +922,8 @@ void btif_a2dp_setup_codec(void)
if (bta_av_co_audio_set_codec(&media_feeding, &status)) if (bta_av_co_audio_set_codec(&media_feeding, &status))
{ {
#if (BTIF_AV_SRC_INCLUDED == TRUE)
tBTIF_MEDIA_INIT_AUDIO_FEEDING mfeed; tBTIF_MEDIA_INIT_AUDIO_FEEDING mfeed;
/* Init the encoding task */ /* Init the encoding task */
@ -905,6 +934,7 @@ void btif_a2dp_setup_codec(void)
mfeed.feeding_mode = BTIF_AV_FEEDING_ASYNCHRONOUS; mfeed.feeding_mode = BTIF_AV_FEEDING_ASYNCHRONOUS;
/* Send message to Media task to configure transcoding */ /* Send message to Media task to configure transcoding */
btif_media_task_audio_feeding_init_req(&mfeed); btif_media_task_audio_feeding_init_req(&mfeed);
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
} }
GKI_enable(); GKI_enable();
@ -924,11 +954,13 @@ void btif_a2dp_setup_codec(void)
void btif_a2dp_on_idle(void) void btif_a2dp_on_idle(void)
{ {
APPL_TRACE_EVENT("## ON A2DP IDLE ##\n"); APPL_TRACE_EVENT("## ON A2DP IDLE ##\n");
#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_media_cb.peer_sep == AVDT_TSEP_SNK) if (btif_media_cb.peer_sep == AVDT_TSEP_SNK)
{ {
/* Make sure media task is stopped */ /* Make sure media task is stopped */
btif_media_task_stop_aa_req(); btif_media_task_stop_aa_req();
} }
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
bta_av_co_init(); bta_av_co_init();
#if (BTA_AV_SINK_INCLUDED == TRUE) #if (BTA_AV_SINK_INCLUDED == TRUE)
@ -1123,13 +1155,14 @@ void btif_a2dp_on_stopped(tBTA_AV_SUSPEND *p_av)
} }
} }
#if (BTIF_AV_SRC_INCLUDED == TRUE)
/* ensure tx frames are immediately suspended */ /* ensure tx frames are immediately suspended */
btif_media_cb.tx_flush = 1; btif_media_cb.tx_flush = 1;
/* request to stop media task */ /* request to stop media task */
btif_media_task_aa_tx_flush_req(); btif_media_task_aa_tx_flush_req();
btif_media_task_stop_aa_req(); btif_media_task_stop_aa_req();
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
/* once stream is fully stopped we will ack back */ /* once stream is fully stopped we will ack back */
} }
@ -1163,12 +1196,13 @@ void btif_a2dp_on_suspended(tBTA_AV_SUSPEND *p_av)
} }
/* once stream is fully stopped we will ack back */ /* once stream is fully stopped we will ack back */
#if (BTIF_AV_SRC_INCLUDED == TRUE)
/* ensure tx frames are immediately flushed */ /* ensure tx frames are immediately flushed */
btif_media_cb.tx_flush = 1; btif_media_cb.tx_flush = 1;
/* stop timer tick */ /* stop timer tick */
btif_media_task_stop_aa_req(); btif_media_task_stop_aa_req();
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
} }
/* when true media task discards any rx frames */ /* when true media task discards any rx frames */
@ -1178,13 +1212,14 @@ void btif_a2dp_set_rx_flush(BOOLEAN enable)
btif_media_cb.rx_flush = enable; btif_media_cb.rx_flush = enable;
} }
#if (BTIF_AV_SRC_INCLUDED == TRUE)
/* when true media task discards any tx frames */ /* when true media task discards any tx frames */
void btif_a2dp_set_tx_flush(BOOLEAN enable) void btif_a2dp_set_tx_flush(BOOLEAN enable)
{ {
APPL_TRACE_EVENT("## DROP TX %d ##\n", enable); APPL_TRACE_EVENT("## DROP TX %d ##\n", enable);
btif_media_cb.tx_flush = enable; btif_media_cb.tx_flush = enable;
} }
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
#if (BTA_AV_SINK_INCLUDED == TRUE) #if (BTA_AV_SINK_INCLUDED == TRUE)
static void btif_media_task_avk_handle_timer(UNUSED_ATTR void *context) static void btif_media_task_avk_handle_timer(UNUSED_ATTR void *context)
{ {
@ -1254,6 +1289,7 @@ static void btif_media_task_avk_handle_timer(UNUSED_ATTR void *context)
static void btif_media_task_avk_handle_timer(UNUSED_ATTR void *context) {} static void btif_media_task_avk_handle_timer(UNUSED_ATTR void *context) {}
#endif #endif
#if (BTIF_AV_SRC_INCLUDED == TRUE)
static void btif_media_task_aa_handle_timer(UNUSED_ATTR void *context) static void btif_media_task_aa_handle_timer(UNUSED_ATTR void *context)
{ {
log_tstamps_us("media task tx timer"); log_tstamps_us("media task tx timer");
@ -1269,8 +1305,10 @@ static void btif_media_task_aa_handle_timer(UNUSED_ATTR void *context)
} }
#endif #endif
} }
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
#if (BTA_AV_INCLUDED == TRUE) #if (BTA_AV_INCLUDED == TRUE)
#if (BTIF_AV_SRC_INCLUDED == TRUE)
static void btif_media_task_aa_handle_uipc_rx_rdy(void) static void btif_media_task_aa_handle_uipc_rx_rdy(void)
{ {
/* process all the UIPC data */ /* process all the UIPC data */
@ -1280,6 +1318,7 @@ static void btif_media_task_aa_handle_uipc_rx_rdy(void)
LOG_VERBOSE("btif_media_task_aa_handle_uipc_rx_rdy calls bta_av_ci_src_data_ready"); LOG_VERBOSE("btif_media_task_aa_handle_uipc_rx_rdy calls bta_av_ci_src_data_ready");
bta_av_ci_src_data_ready(BTA_AV_CHNL_AUDIO); bta_av_ci_src_data_ready(BTA_AV_CHNL_AUDIO);
} }
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
#endif #endif
static void btif_media_thread_init(UNUSED_ATTR void *context) { static void btif_media_thread_init(UNUSED_ATTR void *context) {
@ -1358,6 +1397,7 @@ static void btif_media_thread_handle_cmd(fixed_queue_t *queue)
switch (p_msg->event) switch (p_msg->event)
{ {
#if (BTA_AV_INCLUDED == TRUE) #if (BTA_AV_INCLUDED == TRUE)
#if (BTIF_AV_SRC_INCLUDED == TRUE)
case BTIF_MEDIA_START_AA_TX: case BTIF_MEDIA_START_AA_TX:
btif_media_task_aa_start_tx(); btif_media_task_aa_start_tx();
break; break;
@ -1379,6 +1419,7 @@ static void btif_media_thread_handle_cmd(fixed_queue_t *queue)
case BTIF_MEDIA_UIPC_RX_RDY: case BTIF_MEDIA_UIPC_RX_RDY:
btif_media_task_aa_handle_uipc_rx_rdy(); btif_media_task_aa_handle_uipc_rx_rdy();
break; break;
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
case BTIF_MEDIA_AUDIO_SINK_CFG_UPDATE: case BTIF_MEDIA_AUDIO_SINK_CFG_UPDATE:
#if (BTA_AV_SINK_INCLUDED == TRUE) #if (BTA_AV_SINK_INCLUDED == TRUE)
LOG_ERROR("SINK_CFG_UPDATE: xx\n"); LOG_ERROR("SINK_CFG_UPDATE: xx\n");
@ -1462,6 +1503,7 @@ static void btif_media_task_handle_inc_media(tBT_SBC_HDR*p_msg)
#endif #endif
#if (BTA_AV_INCLUDED == TRUE) #if (BTA_AV_INCLUDED == TRUE)
#if (BTIF_AV_SRC_INCLUDED == TRUE)
/******************************************************************************* /*******************************************************************************
** **
** Function btif_media_task_enc_init_req ** Function btif_media_task_enc_init_req
@ -1598,6 +1640,7 @@ BOOLEAN btif_media_task_stop_aa_req(void)
return TRUE; return TRUE;
} }
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
/******************************************************************************* /*******************************************************************************
** **
** Function btif_media_task_aa_rx_flush_req ** Function btif_media_task_aa_rx_flush_req
@ -1626,6 +1669,7 @@ BOOLEAN btif_media_task_aa_rx_flush_req(void)
return TRUE; return TRUE;
} }
#if (BTIF_AV_SRC_INCLUDED == TRUE)
/******************************************************************************* /*******************************************************************************
** **
** Function btif_media_task_aa_tx_flush_req ** Function btif_media_task_aa_tx_flush_req
@ -1661,6 +1705,8 @@ BOOLEAN btif_media_task_aa_tx_flush_req(void)
return TRUE; return TRUE;
} }
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
/******************************************************************************* /*******************************************************************************
** **
** Function btif_media_task_aa_rx_flush ** Function btif_media_task_aa_rx_flush
@ -1678,7 +1724,7 @@ static void btif_media_task_aa_rx_flush(void)
btif_media_flush_q(&(btif_media_cb.RxSbcQ)); btif_media_flush_q(&(btif_media_cb.RxSbcQ));
} }
#if (BTIF_AV_SRC_INCLUDED == TRUE)
/******************************************************************************* /*******************************************************************************
** **
** Function btif_media_task_aa_tx_flush ** Function btif_media_task_aa_tx_flush
@ -2009,6 +2055,7 @@ static void btif_media_task_audio_feeding_init(BT_HDR *p_msg)
} }
} }
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
int btif_a2dp_get_track_frequency(UINT8 frequency) { int btif_a2dp_get_track_frequency(UINT8 frequency) {
int freq = 48000; int freq = 48000;
switch (frequency) { switch (frequency) {
@ -2225,6 +2272,7 @@ static void btif_media_task_aa_handle_decoder_reset(BT_HDR *p_msg)
} }
#endif #endif
#if (BTIF_AV_SRC_INCLUDED == TRUE)
/******************************************************************************* /*******************************************************************************
** **
** Function btif_media_task_feeding_state_reset ** Function btif_media_task_feeding_state_reset
@ -2397,6 +2445,7 @@ static UINT8 btif_get_num_aa_frame(void)
return (UINT8)result; return (UINT8)result;
} }
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
/******************************************************************************* /*******************************************************************************
** **
@ -2444,6 +2493,7 @@ UINT8 btif_media_sink_enque_buf(BT_HDR *p_pkt)
return GKI_queue_length(&btif_media_cb.RxSbcQ); return GKI_queue_length(&btif_media_cb.RxSbcQ);
} }
/******************************************************************************* /*******************************************************************************
** **
** Function btif_media_aa_readbuf ** Function btif_media_aa_readbuf
@ -2453,11 +2503,19 @@ UINT8 btif_media_sink_enque_buf(BT_HDR *p_pkt)
** **
** Returns void ** Returns void
*******************************************************************************/ *******************************************************************************/
#if (BTIF_AV_SRC_INCLUDED == TRUE)
BT_HDR *btif_media_aa_readbuf(void) BT_HDR *btif_media_aa_readbuf(void)
{ {
return GKI_dequeue(&(btif_media_cb.TxAaQ)); return GKI_dequeue(&(btif_media_cb.TxAaQ));
} }
#else
BT_HDR *btif_media_aa_readbuf(void)
{
return NULL;
}
#endif /* BTIF_AV_SRC_INCLUDED */
#if (BTIF_AV_SRC_INCLUDED == TRUE)
/******************************************************************************* /*******************************************************************************
** **
** Function btif_media_aa_read_feeding ** Function btif_media_aa_read_feeding
@ -2766,7 +2824,9 @@ static void btif_media_aa_prep_2_send(UINT8 nb_frame)
break; break;
} }
} }
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
#if (BTIF_AV_SRC_INCLUDED == TRUE)
/******************************************************************************* /*******************************************************************************
** **
** Function btif_media_send_aa_frame ** Function btif_media_send_aa_frame
@ -2795,7 +2855,7 @@ static void btif_media_send_aa_frame(void)
} }
#endif /* BTA_AV_INCLUDED == TRUE */ #endif /* BTA_AV_INCLUDED == TRUE */
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
/******************************************************************************* /*******************************************************************************
** **
** Function dump_codec_info ** Function dump_codec_info