读了
https://www.jianshu.com/p/9491cc1adf70
https://blog.csdn.net/bberdong/article/details/88370351
很有收获
btif_a2dp_sink_command_ready
->
case BTIF_MEDIA_SINK_DECODER_UPDATE:
btif_a2dp_sink_decoder_update_event(
(tBTIF_MEDIA_SINK_DECODER_UPDATE*)p_msg);
break;
创建基于 android native层audiotrack.cpp的播放器
---->
btif_a2dp_sink_cb.audio_track =
#ifndef OS_GENERIC
BtifAvrcpAudioTrackCreate(sample_rate, channel_type);
#else
NULL;
#endif
if (btif_a2dp_sink_cb.audio_track == NULL) {
APPL_TRACE_ERROR("%s: A2dpSink: Track creation failed", __func__);
return;
}
->如下创建audiotrack,使用AudioTrack.cpp这个文件中的native AudioTrack类进行播放的app,播放状态都不会被java层track(这里是追踪的意思)
system/bt/btif/src/btif_avrcp_audio_track.cc
audio sink角色接收到soure角色的数据后向下将数据解码并写到播放设备
btif_av_sink_execute_service->
bte_av_sink_media_callback->
btif_a2dp_sink_enqueue_buf->
btif_a2dp_sink_audio_handle_start_decoding->
20ms后执行btif_decode_alarm_cb->
btif_a2dp_sink_avk_handle_timer->
btif_a2dp_sink_handle_inc_media->
BtifAvrcpAudioTrackWriteData
如上打开,打开AudioTrack.cpp write的函数向speaker播放音频
打开DUMP_PCM_DATA宏可以追踪播放音乐时的断续问题
路径为:/data/misc/bluedroid/output_sample.pcm
来数据时
bta_av_sink_data_cback发送BTA_AV_SINK_MEDIA_DATA_EVT事件
bta_av_sink_data_cback在bta_av_api_register里注册
a2dp基于avdt协议如协议手册
void avdt_scb_init(void) {
memset(&avdt_cb.scb[0], 0, sizeof(tAVDT_SCB) * AVDT_NUM_SEPS);
avdt_cb.p_scb_act = (tAVDT_SCB_ACTION*)avdt_scb_action;
}
avdt_scb_hdl_pkt->avdt_scb_hdl_pkt_no_frag->下一层avdt层调用数据的callback从而将数据传到a2dp 层,这里为a2dp sink
播放日志,如日志,播放时bt stack打开,执行java层的callback函数,让上层去获取歌曲信息
btif_av_execute_service->
BTA_AvEnable(BTA_SEC_AUTHENTICATE,
(BTA_AV_FEAT_RCTG | BTA_AV_FEAT_NO_SCO_SSPD), bte_av_callback);
static void bte_av_callback(tBTA_AV_EVT event, tBTA_AV* p_data) {
btif_transfer_context(btif_av_handle_event, event, (char*)p_data,
sizeof(tBTA_AV), btif_av_event_deep_copy);
}
01-01 11:14:53.348 894 1113 W bt_btif : btif_av_state_opened_handler: BTA_AV_START_EVT status=0 suspending=0 initiator=0 flags=0x0
01-01 11:14:53.348 894 1113 I BluetoothA2dpSinkServiceJni: bta2dp_audio_state_callback
01-01 11:14:53.350 894 1205 D A2dpSinkStateMachine: Connected process message: 101
01-01 11:14:53.350 894 1205 D A2dpSinkStateMachine: processAudioStateEvent in state 2
01-01 11:14:53.351 894 1205 D A2dpSinkStreamHandler: process message: 0
01-01 11:14:53.352 894 1205 D A2dpSinkStreamHandler: audioFocus = 1
01-01 11:14:53.352 894 1205 D AvrcpControllerService: getAvrcpControllerService(): returning [email protected]bfd2
01-01 11:14:53.352 894 1205 D A2dpSinkStreamHandler: startAvrcpUpdates
01-01 11:14:53.358 894 1113 I BluetoothAvrcpControllerJni: btavrcp_track_changed_callback
01-01 11:14:53.360 894 1113 D AvrcpControllerService: onTrackChanged
01-01 11:14:53.360 894 1290 D AvrcpControllerSM: HandleMessage: 202
01-01 11:14:53.361 894 1290 D A2dpSinkService: getA2dpSinkService(): returning [email protected]
01-01 11:14:53.361 894 1290 D AvrcpPlayer: getPlayBackState state 3 time -1
01-01 11:14:53.361 894 1290 D AvrcpControllerSM: broadcastPlayBackStateChanged = PlaybackState {state=3, position=-1, buffered position=0, speed=1.0, updated=1513536, actions=0, custom actions=[], active item id=-1, error=null}
01-01 11:14:53.361 894 1113 D AvrcpControllerService: onTrackChanged Metadata [artist=罗大佑 trackTitle= 你的样子 albumTitle= 光阴的故事 电视原声带 genre= trackNum= -1 track_len : 209607 TotalTracks -1]
01-01 11:14:53.364 894 1113 I BluetoothAvrcpControllerJni: btavrcp_play_status_changed_callback
01-01 11:14:53.365 894 1113 D AvrcpControllerService: onPlayStatusChanged 1
01-01 11:14:53.365 894 1290 D AvrcpTrackInfo: TrackInfo Metadata [artist= trackTitle= albumTitle= genre= trackNum= -1 track_len : -1 TotalTracks -1]
01-01 11:14:53.366 894 1290 D AvrcpControllerSM: broadcastMetaDataChanged = null, null, null