diff options
author | Eric Laurent <elaurent@google.com> | 2014-10-22 17:28:39 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-10-22 17:28:39 +0000 |
commit | 6efbadac3ff5c3ddc194faaba44f1fe63e452c7f (patch) | |
tree | b6f9e52c650b6668e1a9023a374c2994848c69f8 /services/audioflinger | |
parent | d858f734f9677b560dc31da9d929bab717e438e1 (diff) | |
parent | b6a895127095dceaed8fec2ea0d291aa1722d08c (diff) | |
download | frameworks_av-6efbadac3ff5c3ddc194faaba44f1fe63e452c7f.zip frameworks_av-6efbadac3ff5c3ddc194faaba44f1fe63e452c7f.tar.gz frameworks_av-6efbadac3ff5c3ddc194faaba44f1fe63e452c7f.tar.bz2 |
am b6a89512: am 9d0d5958: Merge "audioflinger: new HW A/V sync ID allocation flow" into lmp-mr1-dev
* commit 'b6a895127095dceaed8fec2ea0d291aa1722d08c':
audioflinger: new HW A/V sync ID allocation flow
Diffstat (limited to 'services/audioflinger')
-rw-r--r-- | services/audioflinger/AudioFlinger.cpp | 66 | ||||
-rw-r--r-- | services/audioflinger/AudioFlinger.h | 3 |
2 files changed, 60 insertions, 9 deletions
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index e48af20..b6c365e 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -650,6 +650,7 @@ sp<IAudioTrack> AudioFlinger::createTrack( } } + setAudioHwSyncForSession_l(thread, (audio_session_t)lSessionId); } if (lStatus != NO_ERROR) { @@ -1604,22 +1605,69 @@ status_t AudioFlinger::setLowRamDevice(bool isLowRamDevice) audio_hw_sync_t AudioFlinger::getAudioHwSyncForSession(audio_session_t sessionId) { Mutex::Autolock _l(mLock); + + ssize_t index = mHwAvSyncIds.indexOfKey(sessionId); + if (index >= 0) { + ALOGV("getAudioHwSyncForSession found ID %d for session %d", + mHwAvSyncIds.valueAt(index), sessionId); + return mHwAvSyncIds.valueAt(index); + } + + audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice(); + if (dev == NULL) { + return AUDIO_HW_SYNC_INVALID; + } + char *reply = dev->get_parameters(dev, AUDIO_PARAMETER_HW_AV_SYNC); + AudioParameter param = AudioParameter(String8(reply)); + free(reply); + + int value; + if (param.getInt(String8(AUDIO_PARAMETER_HW_AV_SYNC), value) != NO_ERROR) { + ALOGW("getAudioHwSyncForSession error getting sync for session %d", sessionId); + return AUDIO_HW_SYNC_INVALID; + } + + // allow only one session for a given HW A/V sync ID. + for (size_t i = 0; i < mHwAvSyncIds.size(); i++) { + if (mHwAvSyncIds.valueAt(i) == (audio_hw_sync_t)value) { + ALOGV("getAudioHwSyncForSession removing ID %d for session %d", + value, mHwAvSyncIds.keyAt(i)); + mHwAvSyncIds.removeItemsAt(i); + break; + } + } + + mHwAvSyncIds.add(sessionId, value); + for (size_t i = 0; i < mPlaybackThreads.size(); i++) { sp<PlaybackThread> thread = mPlaybackThreads.valueAt(i); - if ((thread->hasAudioSession(sessionId) & ThreadBase::TRACK_SESSION) != 0) { - // A session can only be on one thread, so exit after first match - String8 reply = thread->getParameters(String8(AUDIO_PARAMETER_STREAM_HW_AV_SYNC)); - AudioParameter param = AudioParameter(reply); - int value; - if (param.getInt(String8(AUDIO_PARAMETER_STREAM_HW_AV_SYNC), value) == NO_ERROR) { - return value; - } + uint32_t sessions = thread->hasAudioSession(sessionId); + if (sessions & PlaybackThread::TRACK_SESSION) { + AudioParameter param = AudioParameter(); + param.addInt(String8(AUDIO_PARAMETER_STREAM_HW_AV_SYNC), value); + thread->setParameters(param.toString()); break; } } - return AUDIO_HW_SYNC_INVALID; + + ALOGV("getAudioHwSyncForSession adding ID %d for session %d", value, sessionId); + return (audio_hw_sync_t)value; } +// setAudioHwSyncForSession_l() must be called with AudioFlinger::mLock held +void AudioFlinger::setAudioHwSyncForSession_l(PlaybackThread *thread, audio_session_t sessionId) +{ + ssize_t index = mHwAvSyncIds.indexOfKey(sessionId); + if (index >= 0) { + audio_hw_sync_t syncId = mHwAvSyncIds.valueAt(index); + ALOGV("setAudioHwSyncForSession_l found ID %d for session %d", syncId, sessionId); + AudioParameter param = AudioParameter(); + param.addInt(String8(AUDIO_PARAMETER_STREAM_HW_AV_SYNC), syncId); + thread->setParameters(param.toString()); + } +} + + // ---------------------------------------------------------------------------- diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h index 1003017..4fb372d 100644 --- a/services/audioflinger/AudioFlinger.h +++ b/services/audioflinger/AudioFlinger.h @@ -733,6 +733,8 @@ private: // Effect chains without a valid thread DefaultKeyedVector< audio_session_t , sp<EffectChain> > mOrphanEffectChains; + // list of sessions for which a valid HW A/V sync ID was retrieved from the HAL + DefaultKeyedVector< audio_session_t , audio_hw_sync_t >mHwAvSyncIds; private: sp<Client> registerPid(pid_t pid); // always returns non-0 @@ -741,6 +743,7 @@ private: void closeOutputInternal_l(sp<PlaybackThread> thread); status_t closeInput_nonvirtual(audio_io_handle_t input); void closeInputInternal_l(sp<RecordThread> thread); + void setAudioHwSyncForSession_l(PlaybackThread *thread, audio_session_t sessionId); #ifdef TEE_SINK // all record threads serially share a common tee sink, which is re-created on format change |