Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Android audio system(audioplicy_service)

6,004 views

Published on

Android audio system(audioplicy_service)

  1. 1. 안드로이드의 모든것 분석과 포팅 정리Android Audio System(AudioPolicyService) 박철희 1
  2. 2. 1.Audiopolicyservice 위치 및 역활 안드로이드의 모든것 분석과 포팅 정리Application 역할:Framework 1.현재 입출력 디바이스의 연결 상태 파악 및 routing을 위한 조건 checkNativeFramework 2.중간 다리 역활HALKernel 2
  3. 3. 2.AudiopolicyService class 구조 안드로이드의 모든것 분석과 포팅 정리 IInterface IaudioPolicyService BnAudioPolicyService AudioPolicyClientInterface IBinder::DeathRecipient AudiopolicyService AudioPolicyInterface AudioPolicyManagerBase AudiopolicyManager 3
  4. 4. 3.AudioPolicyService의 초기화 안드로이드의 모든것 분석과 포팅 정리 Main_mediaserver.cpp int main(int argc, char** argv) { AudioFlinger::instantiate(); MediaPlayerService::instantiate(); CameraService::instantiate(); AudioPolicyService::instantiate(); ProcessState::self()->startThreadPool(); IPCThreadState::self()->joinThreadPool(); } bool AudioPolicyService:: AudioCommandThread::threadLoop() AudioPolicyService.cpp { void AudioPolicyService::instantiate() { case START_TONE, defaultServiceManager()->addService( case STOP_TONE: String16("media.audio_policy"), new AudioPolicyService());  mTonePlaybackThread 처리 } case SET_VOLUME: case SET_PARAMETERS: case SET_VOICE_VOLUME:AudioPolicyService::AudioPolicyService() case SET_FM_VOLUME: : BnAudioPolicyService() , mpPolicyManager(NULL)  mAudioCommandThread 처리{ // start tone playback thread(START_TONE,STOP_TONE) } mTonePlaybackThread = new AudioCommandThread(String8(""));// start audio commands thread(SET_VOLUME, SET_PARAMETERS, SET_VOICE_VOLUME, SET_FM_VOLUME)mAudioCommandThread = new AudioCommandThread(String8("ApmCommandThread"));mpPolicyManager = createAudioPolicyManager(this); 4
  5. 5. 3.AudioPolicyService의 초기화 안드로이드의 모든것 분석과 포팅 정리 Hardware/msm7k/libaudio-msm7x30/audiopolicymanager.cpp extern "C" AudioPolicyInterface* createAudioPolicyManager(AudioPolicyClientInterface *clientInterface) { return new AudioPolicyManager(clientInterface); } Android.mk(AudioFlinger) Hardware/msm7k/libaudio-msm7x30/Android.mk LOCAL_SRC_FILES := AudioPolicyManager.cpp libAudio libaudioPolicy LOCAL_SHARED_LIBRARIES := libcutils LOCAL_SHARED_LIBRARIES += libutils LOCAL_SHARED_LIBRARIES += libmedia LOCAL_MODULE := libaudiopolicyclass AudioPolicyManager: public AudioPolicyManagerBase{ AudioPolicyInterfacepublic: AudioPolicyManager(AudioPolicyClientInterface *clientInterface) : AudioPolicyManagerBase(clientInterface) { mLPADecodeOutput = -1; AudioPolicyManagerBase mLPAMuted = false; AudioPolicyService mLPAStreamType = AudioSystem::DEFAULT; } AudiopolicyManager… 5
  6. 6. 3.AudioPolicyService의 초기화 안드로이드의 모든것 분석과 포팅 정리Ex)Audiopolicyservice의 getoutput method를 호출할 경우audiopolicymanager.cpp에는 이 함수가 없다. 대신 상속받은 AudioPolicyManagerBase.cpp에 존재 함. AudioPolicyService.cpp audio_io_handle_t AudioPolicyService::getOutput { return mpPolicyManager->getOutput(stream, samplingRate, format, channels, flags); } AudioPolicyManagerBase.cpp audio_io_handle_t AudioPolicyManagerBase::getOutput(…) { … mpClientInterface->openOutput(&outputDesc->mDevice, &outputDesc->mSamplingRate, &outputDesc->mFormat, &outputDesc->mChannels, AudioPolicyService &outputDesc->mLatency, outputDesc->mFlags); } audio_io_handle_t AudioPolicyService::openOutput { af->openOutput(pDevices ,…); } Audioflinger 6
  7. 7. 3.AudioPolicyService의 초기화 안드로이드의 모든것 분석과 포팅 정리int AudioFlinger::openOutput{ AudioStreamOut *output = mAudioHardware->openOutputStream(*pDevices, (int *)&format, &channels, &samplingRate, &status); // notify client processes of the new output creation thread->audioConfigChanged_l(AudioSystem::OUTPUT_OPENED);}void AudioFlinger::PlaybackThread::audioConfigChanged_l{ mAudioFlinger->audioConfigChanged_l(event, param, NULL);} void AudioFlinger::audioConfigChanged_l { mNotificationClients.valueAt(i)->client()->ioConfigChanged(event, ioHandle, param2); } AudioSystem::AudioFlingerClient 아래와 같은 함수들에서 현재 output stream의 정보를 구할 때 gOutputs 가 사용된다. void AudioSystem::AudioFlingerClient::ioConfigChanged getOutputSamplingRate { getOutputFrameCount gOutputs.add(ioHandle, outputDesc); getOutputLatency } 7
  8. 8. 4.AudioPolicyManager의 초기화 안드로이드의 모든것 분석과 포팅 정리class AudioPolicyManager: public AudioPolicyManagerBase{public: AudioPolicyManager(AudioPolicyClientInterface *clientInterface) : AudioPolicyManagerBase(clientInterface) { mLPADecodeOutput = -1; mLPAMuted = false; mLPAStreamType = AudioSystem::DEFAULT; } AudioPolicyServiceAudioPolicyManagerBase::AudioPolicyManagerBase(AudioPolicyClientInterface *clientInterface){ //audiopolicyservice를 변수에 저장한다. mpClientInterface = clientInterface;uint32_t defaultDevice = (uint32_t) AudioSystem::DEVICE_OUT_SPEAKER;mHardwareOutput = mpClientInterface->openOutput(&outputDesc->mDevice, &outputDesc->mSamplingRate, &outputDesc->mFormat, &outputDesc->mChannels, &outputDesc->mLatency, outputDesc->mFlags);mHardwareOutput 는 playbackthread의 idsetOutputDevice(mHardwareOutput, defaultDevice, true);} 8
  9. 9. 4.AudioPolicyManager의 초기화 안드로이드의 모든것 분석과 포팅 정리void AudioPolicyManagerBase::setOutputDevice{ … // do the routing //mHardwareOutput:playbackthread의 id//device: AudioSystem::DEVICE_OUT_SPEAKER AudioParameter param = AudioParameter(); param.addInt(String8(AudioParameter::keyRouting), (int)device); mpClientInterface->setParameters(mHardwareOutput, param.toString(), delayMs);}void AudioPolicyService::setParameters{ mAudioCommandThread->parametersCommand((int)ioHandle, keyValuePairs, delayMs); // mAudioCommandThread 는 AudioPolicyService 생성자에서 생성된 thread} status_t AudioPolicyService::AudioCommandThread::parametersCommand { insertCommand_l(command, delayMs);  SET_PARAMETERS command를 mAudioCommands에 insert한다. } Threadloop으로 돌고 있는 AudioCommandThread 에서 처리한다. 9
  10. 10. 4.AudioPolicyManager의 초기화 안드로이드의 모든것 분석과 포팅 정리bool AudioPolicyService::AudioCommandThread::threadLoop(){ … case SET_PARAMETERS: command->mStatus = AudioSystem::setParameters(data->mIO, data->mKeyValuePairs);}AudioSystem.cppstatus_t AudioSystem::setParameters{ return af->setParameters(ioHandle, keyValuePairs);} AudioFlinger.cpp status_t AudioFlinger::setParameters { //현재 설정된 palybackthread의 parent class인 threadbase의 setParameters를 호출함. result = thread->setParameters(keyValuePairs); }status_t AudioFlinger::ThreadBase::setParameters{ mNewParameters.add(keyValuePairs);} bool AudioFlinger::MixerThread::threadLoop() { checkForNewParameters_l() } 10
  11. 11. 4.AudioPolicyManager의 초기화 안드로이드의 모든것 분석과 포팅 정리 bool AudioFlinger::MixerThread::checkForNewParameters_l() { sendConfigEvent_l(AudioSystem::OUTPUT_CONFIG_CHANGED); }void AudioFlinger::ThreadBase::sendConfigEvent_l(int event, int param){ mConfigEvents.add(configEvent);} bool AudioFlinger::MixerThread::threadLoop() { processConfigEvents(); } void AudioFlinger::ThreadBase::processConfigEvents() { audioConfigChanged_l(configEvent->mEvent, configEvent->mParam); } void AudioFlinger::audioConfigChanged_l { mNotificationClients.valueAt(i)->client()->ioConfigChanged(event, ioHandle, param2); } void AudioSystem::AudioFlingerClient::ioConfigChanged { case OUTPUT_CONFIG_CHANGED: gOutputs.replaceValueFor(ioHandle, outputDesc); } 11

×