diff options
author | Eric Laurent <elaurent@google.com> | 2015-05-01 19:10:25 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-01 19:10:26 +0000 |
commit | cc85abcf4ac398dca240db356b8b4db052b415a4 (patch) | |
tree | 65f9eccab6b0d9b9f3dcee48e2c44326b0edbef4 /services/audioflinger | |
parent | 0bbf8b213ad96051357e3ad6d6d2808bfa31a59a (diff) | |
parent | 73e26b661af50be2c0a4ff6c9ac85f7347a8b235 (diff) | |
download | frameworks_av-cc85abcf4ac398dca240db356b8b4db052b415a4.zip frameworks_av-cc85abcf4ac398dca240db356b8b4db052b415a4.tar.gz frameworks_av-cc85abcf4ac398dca240db356b8b4db052b415a4.tar.bz2 |
Merge "AudioSystem: refactor audio config cache and callbacks" into mnc-dev
Diffstat (limited to 'services/audioflinger')
-rw-r--r-- | services/audioflinger/AudioFlinger.cpp | 25 | ||||
-rw-r--r-- | services/audioflinger/AudioFlinger.h | 3 | ||||
-rw-r--r-- | services/audioflinger/Threads.cpp | 72 | ||||
-rw-r--r-- | services/audioflinger/Threads.h | 23 |
4 files changed, 61 insertions, 62 deletions
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index 64e9fea..bd6889d 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -1268,11 +1268,11 @@ void AudioFlinger::registerClient(const sp<IAudioFlingerClient>& client) // the config change is always sent from playback or record threads to avoid deadlock // with AudioSystem::gLock for (size_t i = 0; i < mPlaybackThreads.size(); i++) { - mPlaybackThreads.valueAt(i)->sendIoConfigEvent(AudioSystem::OUTPUT_OPENED); + mPlaybackThreads.valueAt(i)->sendIoConfigEvent(AUDIO_OUTPUT_OPENED); } for (size_t i = 0; i < mRecordThreads.size(); i++) { - mRecordThreads.valueAt(i)->sendIoConfigEvent(AudioSystem::INPUT_OPENED); + mRecordThreads.valueAt(i)->sendIoConfigEvent(AUDIO_INPUT_OPENED); } } } @@ -1306,14 +1306,13 @@ void AudioFlinger::removeNotificationClient(pid_t pid) } } -void AudioFlinger::audioConfigChanged(int event, audio_io_handle_t ioHandle, const void *param2) +void AudioFlinger::ioConfigChanged(audio_io_config_event event, + const sp<AudioIoDescriptor>& ioDesc) { Mutex::Autolock _l(mClientLock); size_t size = mNotificationClients.size(); for (size_t i = 0; i < size; i++) { - mNotificationClients.valueAt(i)->audioFlingerClient()->ioConfigChanged(event, - ioHandle, - param2); + mNotificationClients.valueAt(i)->audioFlingerClient()->ioConfigChanged(event, ioDesc); } } @@ -1832,7 +1831,7 @@ status_t AudioFlinger::openOutput(audio_module_handle_t module, *latencyMs = thread->latency(); // notify client processes of the new output creation - thread->audioConfigChanged(AudioSystem::OUTPUT_OPENED); + thread->ioConfigChanged(AUDIO_OUTPUT_OPENED); // the first primary output opened designates the primary hw device if ((mPrimaryHardwareDev == NULL) && (flags & AUDIO_OUTPUT_FLAG_PRIMARY)) { @@ -1870,7 +1869,7 @@ audio_io_handle_t AudioFlinger::openDuplicateOutput(audio_io_handle_t output1, thread->addOutputTrack(thread2); mPlaybackThreads.add(id, thread); // notify client processes of the new output creation - thread->audioConfigChanged(AudioSystem::OUTPUT_OPENED); + thread->ioConfigChanged(AUDIO_OUTPUT_OPENED); return id; } @@ -1920,7 +1919,9 @@ status_t AudioFlinger::closeOutput_nonvirtual(audio_io_handle_t output) } } } - audioConfigChanged(AudioSystem::OUTPUT_CLOSED, output, NULL); + const sp<AudioIoDescriptor> ioDesc = new AudioIoDescriptor(); + ioDesc->mIoHandle = output; + ioConfigChanged(AUDIO_OUTPUT_CLOSED, ioDesc); } thread->exit(); // The thread entity (active unit of execution) is no longer running here, @@ -1998,7 +1999,7 @@ status_t AudioFlinger::openInput(audio_module_handle_t module, if (thread != 0) { // notify client processes of the new input creation - thread->audioConfigChanged(AudioSystem::INPUT_OPENED); + thread->ioConfigChanged(AUDIO_INPUT_OPENED); return NO_ERROR; } return NO_INIT; @@ -2181,7 +2182,9 @@ status_t AudioFlinger::closeInput_nonvirtual(audio_io_handle_t input) putOrphanEffectChain_l(chain); } } - audioConfigChanged(AudioSystem::INPUT_CLOSED, input, NULL); + const sp<AudioIoDescriptor> ioDesc = new AudioIoDescriptor(); + ioDesc->mIoHandle = input; + ioConfigChanged(AUDIO_INPUT_CLOSED, ioDesc); mRecordThreads.removeItem(input); } // FIXME: calling thread->exit() without mLock held should not be needed anymore now that diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h index 34ec2b1..8085ec2 100644 --- a/services/audioflinger/AudioFlinger.h +++ b/services/audioflinger/AudioFlinger.h @@ -545,7 +545,8 @@ private: // no range check, doesn't check per-thread stream volume, AudioFlinger::mLock held float streamVolume_l(audio_stream_type_t stream) const { return mStreamTypes[stream].volume; } - void audioConfigChanged(int event, audio_io_handle_t ioHandle, const void *param2); + void ioConfigChanged(audio_io_config_event event, + const sp<AudioIoDescriptor>& ioDesc); // Allocate an audio_io_handle_t, session ID, effect ID, or audio_module_handle_t. // They all share the same ID space, but the namespaces are actually independent diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp index 234e45f..fa00b47 100644 --- a/services/audioflinger/Threads.cpp +++ b/services/audioflinger/Threads.cpp @@ -584,16 +584,16 @@ status_t AudioFlinger::ThreadBase::sendConfigEvent_l(sp<ConfigEvent>& event) return status; } -void AudioFlinger::ThreadBase::sendIoConfigEvent(int event, int param) +void AudioFlinger::ThreadBase::sendIoConfigEvent(audio_io_config_event event) { Mutex::Autolock _l(mLock); - sendIoConfigEvent_l(event, param); + sendIoConfigEvent_l(event); } // sendIoConfigEvent_l() must be called with ThreadBase::mLock held -void AudioFlinger::ThreadBase::sendIoConfigEvent_l(int event, int param) +void AudioFlinger::ThreadBase::sendIoConfigEvent_l(audio_io_config_event event) { - sp<ConfigEvent> configEvent = (ConfigEvent *)new IoConfigEvent(event, param); + sp<ConfigEvent> configEvent = (ConfigEvent *)new IoConfigEvent(event); sendConfigEvent_l(configEvent); } @@ -657,7 +657,7 @@ void AudioFlinger::ThreadBase::processConfigEvents_l() } break; case CFG_EVENT_IO: { IoConfigEventData *data = (IoConfigEventData *)event->mData.get(); - audioConfigChanged(data->mEvent, data->mParam); + ioConfigChanged(data->mEvent); } break; case CFG_EVENT_SET_PARAMETER: { SetParameterConfigEventData *data = (SetParameterConfigEventData *)event->mData.get(); @@ -1921,32 +1921,28 @@ String8 AudioFlinger::PlaybackThread::getParameters(const String8& keys) return out_s8; } -void AudioFlinger::PlaybackThread::audioConfigChanged(int event, int param) { - AudioSystem::OutputDescriptor desc; - void *param2 = NULL; +void AudioFlinger::PlaybackThread::ioConfigChanged(audio_io_config_event event) { + sp<AudioIoDescriptor> desc = new AudioIoDescriptor(); + ALOGV("PlaybackThread::ioConfigChanged, thread %p, event %d", this, event); - ALOGV("PlaybackThread::audioConfigChanged, thread %p, event %d, param %d", this, event, - param); + desc->mIoHandle = mId; switch (event) { - case AudioSystem::OUTPUT_OPENED: - case AudioSystem::OUTPUT_CONFIG_CHANGED: - desc.channelMask = mChannelMask; - desc.samplingRate = mSampleRate; - desc.format = mFormat; - desc.frameCount = mNormalFrameCount; // FIXME see + case AUDIO_OUTPUT_OPENED: + case AUDIO_OUTPUT_CONFIG_CHANGED: + desc->mChannelMask = mChannelMask; + desc->mSamplingRate = mSampleRate; + desc->mFormat = mFormat; + desc->mFrameCount = mNormalFrameCount; // FIXME see // AudioFlinger::frameCount(audio_io_handle_t) - desc.latency = latency_l(); - param2 = &desc; + desc->mLatency = latency_l(); break; - case AudioSystem::STREAM_CONFIG_CHANGED: - param2 = ¶m; - case AudioSystem::OUTPUT_CLOSED: + case AUDIO_OUTPUT_CLOSED: default: break; } - mAudioFlinger->audioConfigChanged(event, mId, param2); + mAudioFlinger->ioConfigChanged(event, desc); } void AudioFlinger::PlaybackThread::writeCallback() @@ -4203,7 +4199,7 @@ bool AudioFlinger::MixerThread::checkForNewParameter_l(const String8& keyValuePa } mTracks[i]->mName = name; } - sendIoConfigEvent_l(AudioSystem::OUTPUT_CONFIG_CHANGED); + sendIoConfigEvent_l(AUDIO_OUTPUT_CONFIG_CHANGED); } } @@ -4655,7 +4651,7 @@ bool AudioFlinger::DirectOutputThread::checkForNewParameter_l(const String8& key } if (status == NO_ERROR && reconfig) { readOutputParameters_l(); - sendIoConfigEvent_l(AudioSystem::OUTPUT_CONFIG_CHANGED); + sendIoConfigEvent_l(AUDIO_OUTPUT_CONFIG_CHANGED); } } @@ -6701,7 +6697,7 @@ bool AudioFlinger::RecordThread::checkForNewParameter_l(const String8& keyValueP } if (status == NO_ERROR) { readInputParameters_l(); - sendIoConfigEvent_l(AudioSystem::INPUT_CONFIG_CHANGED); + sendIoConfigEvent_l(AUDIO_INPUT_CONFIG_CHANGED); } } } @@ -6722,26 +6718,26 @@ String8 AudioFlinger::RecordThread::getParameters(const String8& keys) return out_s8; } -void AudioFlinger::RecordThread::audioConfigChanged(int event, int param __unused) { - AudioSystem::OutputDescriptor desc; - const void *param2 = NULL; +void AudioFlinger::RecordThread::ioConfigChanged(audio_io_config_event event) { + sp<AudioIoDescriptor> desc = new AudioIoDescriptor(); + + desc->mIoHandle = mId; switch (event) { - case AudioSystem::INPUT_OPENED: - case AudioSystem::INPUT_CONFIG_CHANGED: - desc.channelMask = mChannelMask; - desc.samplingRate = mSampleRate; - desc.format = mFormat; - desc.frameCount = mFrameCount; - desc.latency = 0; - param2 = &desc; + case AUDIO_INPUT_OPENED: + case AUDIO_INPUT_CONFIG_CHANGED: + desc->mChannelMask = mChannelMask; + desc->mSamplingRate = mSampleRate; + desc->mFormat = mFormat; + desc->mFrameCount = mFrameCount; + desc->mLatency = 0; break; - case AudioSystem::INPUT_CLOSED: + case AUDIO_INPUT_CLOSED: default: break; } - mAudioFlinger->audioConfigChanged(event, mId, param2); + mAudioFlinger->ioConfigChanged(event, desc); } void AudioFlinger::RecordThread::readInputParameters_l() diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h index 2c514f8..066090b 100644 --- a/services/audioflinger/Threads.h +++ b/services/audioflinger/Threads.h @@ -100,22 +100,21 @@ public: class IoConfigEventData : public ConfigEventData { public: - IoConfigEventData(int event, int param) : - mEvent(event), mParam(param) {} + IoConfigEventData(audio_io_config_event event) : + mEvent(event) {} virtual void dump(char *buffer, size_t size) { - snprintf(buffer, size, "IO event: event %d, param %d\n", mEvent, mParam); + snprintf(buffer, size, "IO event: event %d\n", mEvent); } - const int mEvent; - const int mParam; + const audio_io_config_event mEvent; }; class IoConfigEvent : public ConfigEvent { public: - IoConfigEvent(int event, int param) : + IoConfigEvent(audio_io_config_event event) : ConfigEvent(CFG_EVENT_IO) { - mData = new IoConfigEventData(event, param); + mData = new IoConfigEventData(event); } virtual ~IoConfigEvent() {} }; @@ -250,13 +249,13 @@ public: status_t& status) = 0; virtual status_t setParameters(const String8& keyValuePairs); virtual String8 getParameters(const String8& keys) = 0; - virtual void audioConfigChanged(int event, int param = 0) = 0; + virtual void ioConfigChanged(audio_io_config_event event) = 0; // sendConfigEvent_l() must be called with ThreadBase::mLock held // Can temporarily release the lock if waiting for a reply from // processConfigEvents_l(). status_t sendConfigEvent_l(sp<ConfigEvent>& event); - void sendIoConfigEvent(int event, int param = 0); - void sendIoConfigEvent_l(int event, int param = 0); + void sendIoConfigEvent(audio_io_config_event event); + void sendIoConfigEvent_l(audio_io_config_event event); void sendPrioConfigEvent_l(pid_t pid, pid_t tid, int32_t prio); status_t sendSetParameterConfigEvent_l(const String8& keyValuePair); status_t sendCreateAudioPatchConfigEvent(const struct audio_patch *patch, @@ -560,7 +559,7 @@ public: { return android_atomic_acquire_load(&mSuspended) > 0; } virtual String8 getParameters(const String8& keys); - virtual void audioConfigChanged(int event, int param = 0); + virtual void ioConfigChanged(audio_io_config_event event); status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames); // FIXME rename mixBuffer() to sinkBuffer() and remove int16_t* dependency. // Consider also removing and passing an explicit mMainBuffer initialization @@ -1230,7 +1229,7 @@ public: status_t& status); virtual void cacheParameters_l() {} virtual String8 getParameters(const String8& keys); - virtual void audioConfigChanged(int event, int param = 0); + virtual void ioConfigChanged(audio_io_config_event event); virtual status_t createAudioPatch_l(const struct audio_patch *patch, audio_patch_handle_t *handle); virtual status_t releaseAudioPatch_l(const audio_patch_handle_t handle); |