Loading services/audioflinger/AudioFlinger.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -425,6 +425,8 @@ public: bool btNrecIsOff() const { return mBtNrecIsOff.load(); } bool btNrecIsOff() const { return mBtNrecIsOff.load(); } void lock() ACQUIRE(mLock) { mLock.lock(); } void unlock() RELEASE(mLock) { mLock.unlock(); } private: private: Loading services/audioflinger/PatchPanel.cpp +8 −2 Original line number Original line Diff line number Diff line Loading @@ -135,6 +135,10 @@ status_t AudioFlinger::PatchPanel::getAudioPort(struct audio_port_v7 *port) status_t AudioFlinger::PatchPanel::createAudioPatch(const struct audio_patch *patch, status_t AudioFlinger::PatchPanel::createAudioPatch(const struct audio_patch *patch, audio_patch_handle_t *handle, audio_patch_handle_t *handle, bool endpointPatch) bool endpointPatch) //unlocks AudioFlinger::mLock when calling ThreadBase::sendCreateAudioPatchConfigEvent //to avoid deadlocks if the thread loop needs to acquire AudioFlinger::mLock //before processing the create patch request. NO_THREAD_SAFETY_ANALYSIS { { if (handle == NULL || patch == NULL) { if (handle == NULL || patch == NULL) { return BAD_VALUE; return BAD_VALUE; Loading Loading @@ -245,7 +249,6 @@ status_t AudioFlinger::PatchPanel::createAudioPatch(const struct audio_patch *pa status = INVALID_OPERATION; status = INVALID_OPERATION; goto exit; goto exit; } } sp<ThreadBase> thread = sp<ThreadBase> thread = mAudioFlinger.checkPlaybackThread_l(patch->sources[1].ext.mix.handle); mAudioFlinger.checkPlaybackThread_l(patch->sources[1].ext.mix.handle); if (thread == 0) { if (thread == 0) { Loading Loading @@ -356,11 +359,12 @@ status_t AudioFlinger::PatchPanel::createAudioPatch(const struct audio_patch *pa goto exit; goto exit; } } } } mAudioFlinger.unlock(); status = thread->sendCreateAudioPatchConfigEvent(patch, &halHandle); status = thread->sendCreateAudioPatchConfigEvent(patch, &halHandle); mAudioFlinger.lock(); if (status == NO_ERROR) { if (status == NO_ERROR) { newPatch.setThread(thread); newPatch.setThread(thread); } } // remove stale audio patch with same input as sink if any // remove stale audio patch with same input as sink if any for (auto& iter : mPatches) { for (auto& iter : mPatches) { if (iter.second.mAudioPatch.sinks[0].ext.mix.handle == thread->id()) { if (iter.second.mAudioPatch.sinks[0].ext.mix.handle == thread->id()) { Loading Loading @@ -422,7 +426,9 @@ status_t AudioFlinger::PatchPanel::createAudioPatch(const struct audio_patch *pa mAudioFlinger.updateOutDevicesForRecordThreads_l(devices); mAudioFlinger.updateOutDevicesForRecordThreads_l(devices); } } mAudioFlinger.unlock(); status = thread->sendCreateAudioPatchConfigEvent(patch, &halHandle); status = thread->sendCreateAudioPatchConfigEvent(patch, &halHandle); mAudioFlinger.lock(); if (status == NO_ERROR) { if (status == NO_ERROR) { newPatch.setThread(thread); newPatch.setThread(thread); } } Loading services/audioflinger/Threads.cpp +6 −6 Original line number Original line Diff line number Diff line Loading @@ -4976,7 +4976,7 @@ AudioFlinger::MixerThread::MixerThread(const sp<AudioFlinger>& audioFlinger, Aud const NBAIO_Format offersFast[1] = {format}; const NBAIO_Format offersFast[1] = {format}; size_t numCounterOffersFast = 0; size_t numCounterOffersFast = 0; #if !LOG_NDEBUG #if !LOG_NDEBUG ssize_t index = index = #else #else (void) (void) #endif #endif Loading Loading @@ -7874,15 +7874,15 @@ AudioFlinger::RecordThread::RecordThread(const sp<AudioFlinger>& audioFlinger, Pipe *pipe = new Pipe(pipeFramesP2, format, pipeBuffer); Pipe *pipe = new Pipe(pipeFramesP2, format, pipeBuffer); const NBAIO_Format offersFast[1] = {format}; const NBAIO_Format offersFast[1] = {format}; size_t numCounterOffersFast = 0; size_t numCounterOffersFast = 0; [[maybe_unused]] ssize_t index = pipe->negotiate(offersFast, std::size(offersFast), [[maybe_unused]] ssize_t index2 = pipe->negotiate(offersFast, std::size(offersFast), nullptr /* counterOffers */, numCounterOffersFast); nullptr /* counterOffers */, numCounterOffersFast); ALOG_ASSERT(index == 0); ALOG_ASSERT(index2 == 0); mPipeSink = pipe; mPipeSink = pipe; PipeReader *pipeReader = new PipeReader(*pipe); PipeReader *pipeReader = new PipeReader(*pipe); numCounterOffersFast = 0; numCounterOffersFast = 0; index = pipeReader->negotiate(offersFast, std::size(offersFast), index2 = pipeReader->negotiate(offersFast, std::size(offersFast), nullptr /* counterOffers */, numCounterOffersFast); nullptr /* counterOffers */, numCounterOffersFast); ALOG_ASSERT(index == 0); ALOG_ASSERT(index2 == 0); mPipeSource = pipeReader; mPipeSource = pipeReader; mPipeFramesP2 = pipeFramesP2; mPipeFramesP2 = pipeFramesP2; mPipeMemory = pipeMemory; mPipeMemory = pipeMemory; Loading Loading @@ -9297,7 +9297,7 @@ void AudioFlinger::RecordThread::ResamplerBufferProvider::releaseBuffer( if (stepCount == 0) { if (stepCount == 0) { return; return; } } ALOG_ASSERT(stepCount <= mRsmpInUnrel); ALOG_ASSERT(stepCount <= (int32_t)mRsmpInUnrel); mRsmpInUnrel -= stepCount; mRsmpInUnrel -= stepCount; mRsmpInFront = audio_utils::safe_add_overflow(mRsmpInFront, stepCount); mRsmpInFront = audio_utils::safe_add_overflow(mRsmpInFront, stepCount); buffer->raw = NULL; buffer->raw = NULL; Loading Loading
services/audioflinger/AudioFlinger.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -425,6 +425,8 @@ public: bool btNrecIsOff() const { return mBtNrecIsOff.load(); } bool btNrecIsOff() const { return mBtNrecIsOff.load(); } void lock() ACQUIRE(mLock) { mLock.lock(); } void unlock() RELEASE(mLock) { mLock.unlock(); } private: private: Loading
services/audioflinger/PatchPanel.cpp +8 −2 Original line number Original line Diff line number Diff line Loading @@ -135,6 +135,10 @@ status_t AudioFlinger::PatchPanel::getAudioPort(struct audio_port_v7 *port) status_t AudioFlinger::PatchPanel::createAudioPatch(const struct audio_patch *patch, status_t AudioFlinger::PatchPanel::createAudioPatch(const struct audio_patch *patch, audio_patch_handle_t *handle, audio_patch_handle_t *handle, bool endpointPatch) bool endpointPatch) //unlocks AudioFlinger::mLock when calling ThreadBase::sendCreateAudioPatchConfigEvent //to avoid deadlocks if the thread loop needs to acquire AudioFlinger::mLock //before processing the create patch request. NO_THREAD_SAFETY_ANALYSIS { { if (handle == NULL || patch == NULL) { if (handle == NULL || patch == NULL) { return BAD_VALUE; return BAD_VALUE; Loading Loading @@ -245,7 +249,6 @@ status_t AudioFlinger::PatchPanel::createAudioPatch(const struct audio_patch *pa status = INVALID_OPERATION; status = INVALID_OPERATION; goto exit; goto exit; } } sp<ThreadBase> thread = sp<ThreadBase> thread = mAudioFlinger.checkPlaybackThread_l(patch->sources[1].ext.mix.handle); mAudioFlinger.checkPlaybackThread_l(patch->sources[1].ext.mix.handle); if (thread == 0) { if (thread == 0) { Loading Loading @@ -356,11 +359,12 @@ status_t AudioFlinger::PatchPanel::createAudioPatch(const struct audio_patch *pa goto exit; goto exit; } } } } mAudioFlinger.unlock(); status = thread->sendCreateAudioPatchConfigEvent(patch, &halHandle); status = thread->sendCreateAudioPatchConfigEvent(patch, &halHandle); mAudioFlinger.lock(); if (status == NO_ERROR) { if (status == NO_ERROR) { newPatch.setThread(thread); newPatch.setThread(thread); } } // remove stale audio patch with same input as sink if any // remove stale audio patch with same input as sink if any for (auto& iter : mPatches) { for (auto& iter : mPatches) { if (iter.second.mAudioPatch.sinks[0].ext.mix.handle == thread->id()) { if (iter.second.mAudioPatch.sinks[0].ext.mix.handle == thread->id()) { Loading Loading @@ -422,7 +426,9 @@ status_t AudioFlinger::PatchPanel::createAudioPatch(const struct audio_patch *pa mAudioFlinger.updateOutDevicesForRecordThreads_l(devices); mAudioFlinger.updateOutDevicesForRecordThreads_l(devices); } } mAudioFlinger.unlock(); status = thread->sendCreateAudioPatchConfigEvent(patch, &halHandle); status = thread->sendCreateAudioPatchConfigEvent(patch, &halHandle); mAudioFlinger.lock(); if (status == NO_ERROR) { if (status == NO_ERROR) { newPatch.setThread(thread); newPatch.setThread(thread); } } Loading
services/audioflinger/Threads.cpp +6 −6 Original line number Original line Diff line number Diff line Loading @@ -4976,7 +4976,7 @@ AudioFlinger::MixerThread::MixerThread(const sp<AudioFlinger>& audioFlinger, Aud const NBAIO_Format offersFast[1] = {format}; const NBAIO_Format offersFast[1] = {format}; size_t numCounterOffersFast = 0; size_t numCounterOffersFast = 0; #if !LOG_NDEBUG #if !LOG_NDEBUG ssize_t index = index = #else #else (void) (void) #endif #endif Loading Loading @@ -7874,15 +7874,15 @@ AudioFlinger::RecordThread::RecordThread(const sp<AudioFlinger>& audioFlinger, Pipe *pipe = new Pipe(pipeFramesP2, format, pipeBuffer); Pipe *pipe = new Pipe(pipeFramesP2, format, pipeBuffer); const NBAIO_Format offersFast[1] = {format}; const NBAIO_Format offersFast[1] = {format}; size_t numCounterOffersFast = 0; size_t numCounterOffersFast = 0; [[maybe_unused]] ssize_t index = pipe->negotiate(offersFast, std::size(offersFast), [[maybe_unused]] ssize_t index2 = pipe->negotiate(offersFast, std::size(offersFast), nullptr /* counterOffers */, numCounterOffersFast); nullptr /* counterOffers */, numCounterOffersFast); ALOG_ASSERT(index == 0); ALOG_ASSERT(index2 == 0); mPipeSink = pipe; mPipeSink = pipe; PipeReader *pipeReader = new PipeReader(*pipe); PipeReader *pipeReader = new PipeReader(*pipe); numCounterOffersFast = 0; numCounterOffersFast = 0; index = pipeReader->negotiate(offersFast, std::size(offersFast), index2 = pipeReader->negotiate(offersFast, std::size(offersFast), nullptr /* counterOffers */, numCounterOffersFast); nullptr /* counterOffers */, numCounterOffersFast); ALOG_ASSERT(index == 0); ALOG_ASSERT(index2 == 0); mPipeSource = pipeReader; mPipeSource = pipeReader; mPipeFramesP2 = pipeFramesP2; mPipeFramesP2 = pipeFramesP2; mPipeMemory = pipeMemory; mPipeMemory = pipeMemory; Loading Loading @@ -9297,7 +9297,7 @@ void AudioFlinger::RecordThread::ResamplerBufferProvider::releaseBuffer( if (stepCount == 0) { if (stepCount == 0) { return; return; } } ALOG_ASSERT(stepCount <= mRsmpInUnrel); ALOG_ASSERT(stepCount <= (int32_t)mRsmpInUnrel); mRsmpInUnrel -= stepCount; mRsmpInUnrel -= stepCount; mRsmpInFront = audio_utils::safe_add_overflow(mRsmpInFront, stepCount); mRsmpInFront = audio_utils::safe_add_overflow(mRsmpInFront, stepCount); buffer->raw = NULL; buffer->raw = NULL; Loading