蓝牙打电话后播放音乐无声
文章目录
查看log,发现播放音乐的时候,频繁打印
bt_a2dp_hw: start_audio_datapath: Audiopath start failed - in call, move to suspended
跟踪start_audio_datapath代码,发现执行A2DP命令时还是call状态,看起来蓝牙挂断状态没清理干净。
static int start_audio_datapath(struct a2dp_stream_common* common) { INFO(“state %d”, common->state);
int oldstate = common->state; common->state = AUDIO_A2DP_STATE_STARTING;
int a2dp_status = a2dp_command(common, A2DP_CTRL_CMD_START); if (a2dp_status < 0) { ERROR(“Audiopath start failed (status %d)", a2dp_status); goto error; } else if (a2dp_status == A2DP_CTRL_ACK_INCALL_FAILURE) { ERROR(“Audiopath start failed - in call, move to suspended”); goto error; }
/* connect socket if not yet connected */ if (common->audio_fd == AUDIO_SKT_DISCONNECTED) { common->audio_fd = skt_connect(A2DP_DATA_PATH, common->buffer_sz); if (common->audio_fd < 0) { ERROR(“Audiopath start failed - error opening data socket”); goto error; } } common->state = (a2dp_state_t)AUDIO_A2DP_STATE_STARTED;
/* check to see if delay reporting is enabled */ enable_delay_reporting = delay_reporting_enabled();
return 0;
error: common->state = (a2dp_state_t)oldstate; return -1; }
搜索A2DP_CTRL_ACK_INCALL_FAILURE,发现是在btif_a2dp_audio_process_request里面设置上的
uint8_t btif_a2dp_audio_process_request(uint8_t cmd) { LOG_INFO(LOG_TAG, “%s: cmd: %s”, __func__, audio_a2dp_hw_dump_ctrl_event((tA2DP_CTRL_CMD)cmd)); a2dp_cmd_pending = cmd; uint8_t status; switch (cmd) { case A2DP_CTRL_CMD_START: /* * Don’t send START request to stack while we are in a call. * Some headsets such as “Sony MW600”, don’t allow AVDTP START * while in a call, and respond with BAD_STATE. */ if (!bluetooth::headset::IsCallIdle()) { APPL_TRACE_WARNING("%s: A2DP command %s failed as call state is busy”, __func__, audio_a2dp_hw_dump_ctrl_event((tA2DP_CTRL_CMD)cmd)); status = A2DP_CTRL_ACK_INCALL_FAILURE; break; } … …
继续看IsCallIdle(),发现num_active非零引起的
bool IsCallIdle() { if (!bt_hf_callbacks) return true;
for (int i = 0; i < btif_max_hf_clients; ++i) { if ((btif_hf_cb[i].call_setup_state != BTHF_CALL_STATE_IDLE) || ((btif_hf_cb[i].num_held + btif_hf_cb[i].num_active) > 0)) return false; }
return true; }
framework层维护着mNumActiveCalls,在收到BT_AG_CALL_EVENT_IDLE回调的时候,应该将activeCall清零
文章作者 carter2005
上次更新 2019-01-30