• Like
  • Save
Android audio system(오디오 플링거 서비스 초기화)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Android audio system(오디오 플링거 서비스 초기화)

  • 2,620 views
Published

 

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • Good
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
2,620
On SlideShare
0
From Embeds
0
Number of Embeds
6

Actions

Shares
Downloads
0
Comments
1
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. 안드로이드 아나토미 정리 Android Audio System(오디오 플링거 서비스 초기화) 박철희 1
  • 2. 1.오디오 시스템의 역활 안드로이드 아나토미 정리사운드 데이터 사운드 데이터PCM 데이터 PCM 데이터(decode된 data) (encoding될 data) 2
  • 3. 2.PCM(Pulse code modulation) DATA 안드로이드 아나토미 정리 3
  • 4. 3.오디오 시스템 아키텍쳐 안드로이드 아나토미 정리 ApplicationNative proxy Native system
  • 5. 4.오디오 플링거 서비스 초기화 안드로이드 아나토미 정리 1)오디오 HAL 결정 AudioFlinger.cpp AudioFlinger::AudioFlinger(){ mAudioHardware = AudioHardwareInterface::create(); } AudioHardwareInterface.cpp AudioHardwareInterface* AudioHardwareInterface::create() { #ifdef GENERIC_AUDIO hw = new AudioHardwareGeneric(); #else hw = createAudioHardware(); } #endif if (hw->initCheck() != NO_ERROR) { LOGW("Using stubbed audio hardware. No sound will be produced."); delete hw; hw = new AudioHardwareStub(); } }
  • 6. 4.오디오 플링거 서비스 초기화 안드로이드 아나토미 정리 2)출력 스트림 생성 AudioFlinger.cpp AudioPolicyService::AudioPolicyService() { mpPolicyManager = createAudioPolicyManager(this); } AudioPolicyManager.cpp extern "C" AudioPolicyInterface* createAudioPolicyManager(AudioPolicyClientInterface *clientInterface) { return new AudioPolicyManager(clientInterface); } AudioPolicyManager의 부모 class인 AudioPolicyManagerBase에서 openOutput호출 AudioPolicyManagerBase.cpp AudioPolicyManagerBase::AudioPolicyManagerBase(AudioPolicyClientInterface *clientInterface){ mHardwareOutput = mpClientInterface->openOutput(&outputDesc->mDevice, &outputDesc->mSamplingRate, &outputDesc->mFormat, &outputDesc->mChannels, &outputDesc->mLatency, outputDesc->mFlags); }
  • 7. 4.오디오 플링거 서비스 초기화 안드로이드 아나토미 정리 AudioPolicyService.cpp audio_io_handle_t AudioPolicyService::openOutput(){ return af->openOutput(pDevices, pSamplingRate, (uint32_t *)pFormat, pChannels, pLatencyMs, flags); } AudioFlinger.cpp AudioFlinger::openOutput(){ AudioStreamOut *output = mAudioHardware->openOutputStream(*pDevices, (int *)&format, &channels, &samplingRate, &status); AudioHardware.cpp AudioStreamOut* AudioHardware::openOutputStream{ AudioStreamOutMSM72xx* out = new AudioStreamOutMSM72xx(); status_t lStatus = out->set(this, devices, format, channels, sampleRate); } status_t AudioHardware::AudioStreamOutMSM72xx::set{ if (pFormat) *pFormat = lFormat; if (pChannels) *pChannels = lChannels; if (pRate) *pRate = lRate; }
  • 8. 4.오디오 플링거 서비스 초기화 안드로이드 아나토미 정리 3)Playback thread(Mixer thread) 생성 AudioFlinger.cpp DirectOutputThread AudioFlinger::openOutput(){ -Linear PCM이 아닌 PCM Data를 출력하고 자 할 경우 사용 (Linear PCM: PCM 포맷이 8 ,16,24로 고정된 PCM) if ((flags & AudioSystem::OUTPUT_FLAG_DIRECT) || { thread = new DirectOutputThread(this, output, id, *pDevices); } else { thread = new MixerThread(this, output, id, *pDevices); } Refbase Pthread_create 3 4 1 Thread Run() _threadLoop() Threadbase 2 5 1회호출 6 반복호출 playbackthread onFirstRef() ReadyToRun() MixerThread ThreadLoop()
  • 9. 4.오디오 플링거 서비스 초기화 안드로이드 아나토미 정리RefBase.cpp int Thread::_threadLoop(void* user)void RefBase::incStrong(const void* id) const{ { do {const_cast<RefBase*>(this)->onFirstRef(); bool result;} if (first) { 1 first = false; self->mStatus = self->readyToRun(); 5AudioFlinger..cpp }void AudioFlinger::PlaybackThread::onFirstRef(){ else{ 4 result = self->threadLoop(); 6run(buffer, ANDROID_PRIORITY_URGENT_AUDIO); }} } } 2 status_t AudioFlinger::PlaybackThread::readyToRun()Threads.cpp {status_t Thread::run(const char* name, int32_t priority, size_t stack){ if (mSampleRate == 0) { return NO_INIT;res = androidCreateRawThreadEtc } (_threadLoop,this, name, priority, stack, &mThread); return NO_ERROR;} } 3 bool AudioFlinger::MixerThread::threadLoop() int androidCreateRawThreadEtc(){ { while (!exitPending()) int result = pthread_create(&thread, &attr, { (android_pthread_entry)entryFunction, userData); … } } }
  • 10. 4.오디오 플링거 서비스 초기화 안드로이드 아나토미 정리AudioFlinger::MixerThread::MixerThread : PlaybackThread(audioFlinger, output, id, device), mAudioMixer(0){ mAudioMixer = new AudioMixer(mFrameCount, mSampleRate);} track track trackAudioFlinger::PlaybackThread::PlaybackThread{ … . readOutputParameters();} void AudioFlinger::PlaybackThread::readOutputParameters() { mFrameSize = (uint16_t)mOutput->frameSize(); mFrameCount = mOutput->bufferSize() / mFrameSize; Mixer mMixBuffer = new int16_t[mFrameCount * 2]; buffer memset(mMixBuffer, 0, mFrameCount * 2 * sizeof(int16_t)); } frame 1)frame: pcm data를 읽고 쓰는 단위 Framecount: 2)framesize: pcm format x 채널 수 Buffersize/frame ex) 16 bit x 2 (strero)= 4 bytes size Audio HAL
  • 11. 4.오디오 플링거 서비스 초기화 안드로이드 아나토미 정리AudioFlinger::MixerThread::MixerThread : PlaybackThread(audioFlinger, output, id, device), mAudioMixer(0){ mAudioMixer = new AudioMixer(mFrameCount, mSampleRate);}AudioMixer::AudioMixer(size_t frameCount, uint32_t sampleRate){ mState.enabledTracks= 0; track_t* t = mState.tracks; for (int i=0 ; i<32 ; i++) { t->bufferProvider = 0; Track[0] track track Track[31] t->mainBuffer = NULL; …} .} AudioMixer State_t [0] [31] mState tracks Buffer Mixer provider buffer Enable tracks MainBuffer hook hook