btif_report_connection_state(state, &(btif_av_cb.peer_bda));
/* change state to open/idle based on the status */
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 queued PLAY command, send it now */
/* Bring up AVRCP connection too */
BTA_AvOpenRc(btif_av_cb.bta_handle);
}
-#endif /* #if 0*/
+#endif
btif_queue_advance();
} break;
switch (event)
{
case BTIF_SM_ENTER_EVT:
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{
/* immediately stop transmission of frames */
btif_a2dp_set_tx_flush(TRUE);
/* wait for audioflinger to stop a2dp */
}
+#endif /* (BTIF_AV_SRC_INCLUDED == TRUE) */
if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
{
btif_a2dp_set_rx_flush(TRUE);
case BTA_AV_STOP_EVT:
case BTIF_AV_STOP_STREAM_REQ_EVT:
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{
/* immediately flush any pending tx frames while suspend is pending */
btif_a2dp_set_tx_flush(TRUE);
}
+#endif
if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
{
btif_a2dp_set_rx_flush(TRUE);
break;
case BTIF_AV_START_STREAM_REQ_EVT:
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep != AVDT_TSEP_SRC)
btif_a2dp_setup_codec();
+#endif
BTA_AvStart();
btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_START;
break;
if ((p_av->start.status == BTA_SUCCESS) && (p_av->start.suspending == TRUE))
return TRUE;
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
/* if remote tries to start a2dp when DUT is a2dp source
* then suspend. In case a2dp is sink and call is active
* then disconnect the AVDTP channel
btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
}
}
-
+#endif
/* remain in open state if status failed */
if (p_av->start.status != BTA_AV_SUCCESS)
return FALSE;
/* change state to started, send acknowledgement if start is pending */
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)
btif_a2dp_on_started(NULL, TRUE);
+#endif
/* pending start flag will be cleared when exit current state */
}
btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_STARTED);
break;
case BTIF_AV_START_STREAM_REQ_EVT:
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
/* we were remotely started, just ack back the local request */
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
btif_a2dp_on_started(NULL, TRUE);
+#endif
break;
/* fixme -- use suspend = true always to work around issue with BTA AV */
/* if we were remotely suspended but suspend locally, local suspend
always overrides */
btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
-
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{
/* immediately stop transmission of frames while suspend is pending */
btif_a2dp_set_tx_flush(TRUE);
}
-
+#endif
if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
btif_a2dp_set_rx_flush(TRUE);
btif_a2dp_on_stopped(NULL);
if (p_av->suspend.status != BTA_AV_SUCCESS)
{
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)
{
/* suspend failed, reset back tx flush state */
btif_a2dp_set_tx_flush(FALSE);
}
- return FALSE;
+#endif
+ return FALSE;
}
if (p_av->suspend.initiator != TRUE)
return BT_STATUS_SUCCESS;
}
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
/*******************************************************************************
**
** Function init_src
return status;
}
+#endif
/*******************************************************************************
**
** Function init_sink
return BT_STATUS_SUCCESS;
}
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
static bt_status_t src_connect_sink(bt_bdaddr_t *bd_addr)
{
BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
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)
{
btif_av_cb.sm_handle = NULL;
}
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
static void cleanup_src(void) {
BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
cleanup();
}
}
+#endif
static void cleanup_sink(void) {
BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
}
}
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
static const btav_interface_t bt_av_src_interface = {
sizeof(btav_interface_t),
init_src,
disconnect,
cleanup_src,
};
+#endif
static const btav_interface_t bt_av_sink_interface = {
sizeof(btav_interface_t),
return BT_STATUS_SUCCESS;
}
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
/*******************************************************************************
**
** Function btif_av_get_src_interface
return &bt_av_src_interface;
}
+#endif
/*******************************************************************************
**
** Function btif_av_get_sink_interface
typedef struct
{
#if (BTA_AV_INCLUDED == TRUE)
+#if (BTIF_AV_INCLUDED == TRUE)
BUFFER_Q TxAaQ;
+#endif /* #if (BTIF_AV_INCLUDED == TRUE) */
BUFFER_Q RxSbcQ;
BOOLEAN is_tx_timer;
BOOLEAN is_rx_timer;
+#if (BTIF_AV_INCLUDED == TRUE)
UINT16 TxAaMtuSize;
UINT32 timestamp;
UINT8 TxTranscoding;
tBTIF_AV_MEDIA_FEEDINGS media_feeding;
tBTIF_AV_MEDIA_FEEDINGS_STATE media_feeding_state;
SBC_ENC_PARAMS encoder;
+#endif /* #if (BTIF_AV_INCLUDED == TRUE) */
UINT8 busy_level;
void* av_sm_hdl;
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 */
+#endif /* #if (BTIF_AV_INCLUDED == TRUE) */
BOOLEAN rx_flush; /* discards any incoming data when true */
UINT8 peer_sep;
BOOLEAN data_channel_open;
UINT32 sample_rate;
UINT8 channel_count;
+#if (BTIF_AV_INCLUDED == TRUE)
osi_alarm_t *media_alarm;
+#endif /* #if (BTIF_AV_INCLUDED == TRUE) */
osi_alarm_t *decode_alarm;
#endif
long long ts_prev_us;
} t_stat;
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
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_ctrl_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event);
+
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
static void btif_a2dp_encoder_update(void);
+#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
+
#if (BTA_AV_SINK_INCLUDED == TRUE)
extern OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context,
const OI_BYTE **frameData,
#endif
#if (BTA_AV_INCLUDED == TRUE)
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
static void btif_media_send_aa_frame(void);
static void btif_media_task_feeding_state_reset(void);
static void btif_media_task_aa_start_tx(void);
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_aa_prep_2_send(UINT8 nb_frame);
+#endif /* (BTIF_AV_SRC_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_clear_track(void);
#endif
BOOLEAN btif_media_task_clear_track(void);
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);
+#endif
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_cleanup(UNUSED_ATTR void *context);
** Misc helper functions
*****************************************************************************/
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
static UINT64 time_now_us()
{
// TODO: implement this function
GKI_queue_length(&btif_media_cb.TxAaQ));
prev_us = now_us;
}
+#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
UNUSED_ATTR static const char *dump_media_event(UINT16 event)
{
UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_SET_READ_POLL_TMO,
(void *)A2DP_DATA_READ_POLL_MS);
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_media_cb.peer_sep == AVDT_TSEP_SNK) {
/* Start the media task to encode SBC */
btif_media_task_start_aa_req();
/* make sure we update any changed sbc encoder params */
btif_a2dp_encoder_update();
}
+#endif /* BTIF_AV_SRC_INCLUDED == TRUE */
btif_media_cb.data_channel_open = TRUE;
/* ack back when media task is fully started */
/*****************************************************************************
** BTIF ADAPTATION
*****************************************************************************/
-
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
static UINT16 btif_media_task_get_sbc_rate(void)
{
UINT16 rate = DEFAULT_SBC_BITRATE;
btif_media_task_enc_update_req(&msg);
}
+#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
static void btif_media_task_post(uint32_t sig)
{
case SIG_MEDIA_TASK_AVK_ALARM_TO:
btif_media_task_avk_handle_timer(NULL);
break;
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
case SIG_MEDIA_TASK_AA_ALARM_TO:
btif_media_task_aa_handle_timer(NULL);
+#endif
break;
case SIG_MEDIA_TASK_CMD_READY:
fixed_queue_process(btif_media_cmd_msg_queue);
{
APPL_TRACE_EVENT("## A2DP STOP MEDIA THREAD ##\n");
+#if (BTIF_AV_INCLUDED == TRUE)
// Stop timer
osi_alarm_free(btif_media_cb.media_alarm);
btif_media_cb.media_alarm = NULL;
btif_media_cb.is_tx_timer = FALSE;
+#endif /* #if (BTIF_AV_INCLUDED == TRUE) */
// Exit thread
btif_media_task_post(SIG_MEDIA_TASK_CLEAN_UP);
if (bta_av_co_audio_set_codec(&media_feeding, &status))
{
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
+
tBTIF_MEDIA_INIT_AUDIO_FEEDING mfeed;
/* Init the encoding task */
mfeed.feeding_mode = BTIF_AV_FEEDING_ASYNCHRONOUS;
/* Send message to Media task to configure transcoding */
btif_media_task_audio_feeding_init_req(&mfeed);
+#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
}
GKI_enable();
void btif_a2dp_on_idle(void)
{
APPL_TRACE_EVENT("## ON A2DP IDLE ##\n");
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_media_cb.peer_sep == AVDT_TSEP_SNK)
{
/* Make sure media task is stopped */
btif_media_task_stop_aa_req();
}
-
+#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
+
bta_av_co_init();
#if (BTA_AV_SINK_INCLUDED == TRUE)
if (btif_media_cb.peer_sep == AVDT_TSEP_SRC)
}
}
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
/* ensure tx frames are immediately suspended */
btif_media_cb.tx_flush = 1;
/* request to stop media task */
btif_media_task_aa_tx_flush_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 */
-
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
/* ensure tx frames are immediately flushed */
btif_media_cb.tx_flush = 1;
/* stop timer tick */
btif_media_task_stop_aa_req();
+#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
}
/* when true media task discards any rx frames */
btif_media_cb.rx_flush = enable;
}
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
/* when true media task discards any tx frames */
void btif_a2dp_set_tx_flush(BOOLEAN enable)
{
APPL_TRACE_EVENT("## DROP TX %d ##\n", enable);
btif_media_cb.tx_flush = enable;
}
-
+#endif /* #if (BTIF_AV_SRC_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) {}
#endif
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
static void btif_media_task_aa_handle_timer(UNUSED_ATTR void *context)
{
log_tstamps_us("media task tx timer");
}
#endif
}
+#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
#if (BTA_AV_INCLUDED == TRUE)
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
static void btif_media_task_aa_handle_uipc_rx_rdy(void)
{
/* process all the UIPC data */
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);
}
+#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
#endif
static void btif_media_thread_init(UNUSED_ATTR void *context) {
switch (p_msg->event)
{
#if (BTA_AV_INCLUDED == TRUE)
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
case BTIF_MEDIA_START_AA_TX:
btif_media_task_aa_start_tx();
break;
case BTIF_MEDIA_UIPC_RX_RDY:
btif_media_task_aa_handle_uipc_rx_rdy();
break;
+#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
case BTIF_MEDIA_AUDIO_SINK_CFG_UPDATE:
#if (BTA_AV_SINK_INCLUDED == TRUE)
LOG_ERROR("SINK_CFG_UPDATE: xx\n");
#endif
#if (BTA_AV_INCLUDED == TRUE)
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
/*******************************************************************************
**
** Function btif_media_task_enc_init_req
return TRUE;
}
+#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
/*******************************************************************************
**
** Function btif_media_task_aa_rx_flush_req
return TRUE;
}
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
/*******************************************************************************
**
** Function btif_media_task_aa_tx_flush_req
return TRUE;
}
+#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
+
/*******************************************************************************
**
** Function btif_media_task_aa_rx_flush
btif_media_flush_q(&(btif_media_cb.RxSbcQ));
}
-
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
/*******************************************************************************
**
** Function btif_media_task_aa_tx_flush
}
}
+#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
int btif_a2dp_get_track_frequency(UINT8 frequency) {
int freq = 48000;
switch (frequency) {
}
#endif
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
/*******************************************************************************
**
** Function btif_media_task_feeding_state_reset
return (UINT8)result;
}
+#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
/*******************************************************************************
**
return GKI_queue_length(&btif_media_cb.RxSbcQ);
}
+
/*******************************************************************************
**
** Function btif_media_aa_readbuf
**
** Returns void
*******************************************************************************/
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
BT_HDR *btif_media_aa_readbuf(void)
{
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
break;
}
}
+#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
+#if (BTIF_AV_SRC_INCLUDED == TRUE)
/*******************************************************************************
**
** Function btif_media_send_aa_frame
}
#endif /* BTA_AV_INCLUDED == TRUE */
-
+#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
/*******************************************************************************
**
** Function dump_codec_info