您的位置:首页 > 移动开发 > Android开发

Android Audio 02 - AudioTrack/AudioFlinger/AudioPolicyService 构架

2013-04-01 11:04 501 查看
Appre----------->   AT=audioTrack   

                             AF=audioFlinger 

                             APS=audioPolicyService

 

 

AudioTrack:

Java层的代码:1.getMinBufferSize   ---->native_get_min_buff_size

                            2.new AudioTrack    ----->constructor

                            3.play                         ------>native_start

                            4.write                        ------->native_write_byte

                            5.stop/release

java层会最终调用native层的代码,所以最后实现还是靠native。

 

native层:new AudioTrack   -->  native-setup ---->set()

set里面会做两件事情:1. audioSystem::getOutput

                                         2.audioFlinger->createTrack

AT要创建track,需要和Thread绑定,比如DirectOutput Thread,Mixer Thread,duplicating Thread等。getOutput就是找到这个track需要在哪类Thread上创建。因为这些个track都通过一个thread来混音,然后调用HAL出去播放。

AT的getOutput  ----> AudioSystem::getOutput  -> APS::getOutput -->APMB::getOutput

APMB::output---->1.getStrategy

                                2.getDeviceForStrategy

                                3.find the thread    ----->how?Thread 什么时候创建的了????

getoutput是能够找到合适的thread去创建track,但是这个thread是什么时候创建的?又是谁创建的了???

 

-------------------------

thread的创建

-----------------------

AF和APS都在main_mediaServer.cpp中有初始化instantiate

APS的构造-->APMB  constructor -->APS::openOutput -->AF::openOutput --> new Mixer Thread/DirectOutput/add into pool

好了,我们终于创建Thread的了

 

总结下:AT在native的set()中会通过getOutput找到合适的thread,然后AF会createTrack.

AF::createTrack会用相应的thread去创建track,跟thread绑定,track没法binder,new一个trackhandle

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: