1 Get Android defined A2DP interface btav_interface_t from bt_interface_t get_bluetooth_interface().
12345678910
04-2501:56:30.530I/BluetoothA2dpServiceJni(2093):classInitNative:succeedspackages/apps/Bluetooth/jni/com_android_bluetooth_a2dp.cpp137staticvoidinitNative(JNIEnv*env,jobjectobject)GLOBALconstbtav_interface_t*sBluetoothA2dpInterface=(btav_interface_t*)btInf->get_profile_interface(BT_PROFILE_ADVANCED_AUDIO_ID);sBluetoothA2dpInterface->init(&sBluetoothA2dpCallbacks);external/bluetooth/bluedroid/btif/src/btif_av.c725staticbt_status_tinit(btav_callbacks_t*callbacks)686intbtif_a2dp_start_media_task(void)GKI_create_task((TASKPTR)btif_media_task,A2DP_MEDIA_TASK,btif_enable_service(BTA_A2DP_SERVICE_ID);//Upon BT enable, BTIF core shall invoke the BTA APIs to enable the profiles
2 Init A2DP service by btav_interface_t->init().
* Start a btif_media_task as main loop for A2DP service.
* Open a socket to listen on client's connect request from control channel.
123456789101112131415161718192021
external/bluetooth/bluedroid/btif/src/btif_media_task.c//Task for SBC encoder. This task receives an event when the waveIn interface has a pcm data buffer ready. On receiving the event, handle all ready pcm data buffers. If stream is started, run the SBC encoder on each chunk of pcm samples and build an output packet consisting of one or more encoded SBC frames.1066intbtif_media_task(void*p)1073btif_media_task_init();1044UIPC_Init(NULL);606UDRV_APIvoidUIPC_Init(void*p_data)569intuipc_start_main_server_thread(void)pthread_create(&uipc_main.tid,(constpthread_attr_t*)NULL,(void*)uipc_read_task,NULL)1047UIPC_Open(UIPC_CH_ID_AV_CTRL,btif_a2dp_ctrl_cb);uipc_setup_server_locked(ch_id,A2DP_CTRL_PATH,p_cback);//This is the control socket that listen on A2DP client.1079while(1)//A2DP event loop 1080{1085if(event&BTIF_MEDIA_TASK_CMD)1090btif_media_task_handle_cmd(p_msg);10931094if(event&BTIF_MEDIA_TASK_DATA)1099btif_media_task_handle_media(p_msg);11021103if(event&BTIF_MEDIA_AA_TASK_TIMER)1105/* advance audio timer expiration */1106btif_media_task_aa_handle_timer();