Loading services/audioflinger/AudioFlinger.cpp +17 −28 Original line number Original line Diff line number Diff line Loading @@ -370,6 +370,18 @@ status_t AudioFlinger::dump(int fd, const Vector<String16>& args) return NO_ERROR; return NO_ERROR; } } sp<AudioFlinger::Client> AudioFlinger::registerPid_l(pid_t pid) { // If pid is already in the mClients wp<> map, then use that entry // (for which promote() is always != 0), otherwise create a new entry and Client. sp<Client> client = mClients.valueFor(pid).promote(); if (client == 0) { client = new Client(this, pid); mClients.add(pid, client); } return client; } // IAudioFlinger interface // IAudioFlinger interface Loading @@ -390,7 +402,6 @@ sp<IAudioTrack> AudioFlinger::createTrack( sp<PlaybackThread::Track> track; sp<PlaybackThread::Track> track; sp<TrackHandle> trackHandle; sp<TrackHandle> trackHandle; sp<Client> client; sp<Client> client; wp<Client> wclient; status_t lStatus; status_t lStatus; int lSessionId; int lSessionId; Loading @@ -412,14 +423,7 @@ sp<IAudioTrack> AudioFlinger::createTrack( goto Exit; goto Exit; } } wclient = mClients.valueFor(pid); client = registerPid_l(pid); if (wclient != NULL) { client = wclient.promote(); } else { client = new Client(this, pid); mClients.add(pid, client); } ALOGV("createTrack() sessionId: %d", (sessionId == NULL) ? -2 : *sessionId); ALOGV("createTrack() sessionId: %d", (sessionId == NULL) ? -2 : *sessionId); if (sessionId != NULL && *sessionId != AUDIO_SESSION_OUTPUT_MIX) { if (sessionId != NULL && *sessionId != AUDIO_SESSION_OUTPUT_MIX) { Loading Loading @@ -4131,7 +4135,6 @@ sp<IAudioRecord> AudioFlinger::openRecord( sp<RecordThread::RecordTrack> recordTrack; sp<RecordThread::RecordTrack> recordTrack; sp<RecordHandle> recordHandle; sp<RecordHandle> recordHandle; sp<Client> client; sp<Client> client; wp<Client> wclient; status_t lStatus; status_t lStatus; RecordThread *thread; RecordThread *thread; size_t inFrameCount; size_t inFrameCount; Loading @@ -4152,13 +4155,7 @@ sp<IAudioRecord> AudioFlinger::openRecord( goto Exit; goto Exit; } } wclient = mClients.valueFor(pid); client = registerPid_l(pid); if (wclient != NULL) { client = wclient.promote(); } else { client = new Client(this, pid); mClients.add(pid, client); } // If no audio session id is provided, create one here // If no audio session id is provided, create one here if (sessionId != NULL && *sessionId != AUDIO_SESSION_OUTPUT_MIX) { if (sessionId != NULL && *sessionId != AUDIO_SESSION_OUTPUT_MIX) { Loading Loading @@ -5405,10 +5402,8 @@ sp<IEffect> AudioFlinger::createEffect(pid_t pid, status_t lStatus = NO_ERROR; status_t lStatus = NO_ERROR; sp<EffectHandle> handle; sp<EffectHandle> handle; effect_descriptor_t desc; effect_descriptor_t desc; sp<Client> client; wp<Client> wclient; ALOGV("createEffect pid %d, client %p, priority %d, sessionId %d, io %d", ALOGV("createEffect pid %d, effectClient %p, priority %d, sessionId %d, io %d", pid, effectClient.get(), priority, sessionId, io); pid, effectClient.get(), priority, sessionId, io); if (pDesc == NULL) { if (pDesc == NULL) { Loading Loading @@ -5559,14 +5554,7 @@ sp<IEffect> AudioFlinger::createEffect(pid_t pid, } } } } wclient = mClients.valueFor(pid); sp<Client> client = registerPid_l(pid); if (wclient != NULL) { client = wclient.promote(); } else { client = new Client(this, pid); mClients.add(pid, client); } // create effect on selected output thread // create effect on selected output thread handle = thread->createEffect_l(client, effectClient, priority, sessionId, handle = thread->createEffect_l(client, effectClient, priority, sessionId, Loading Loading @@ -6923,6 +6911,7 @@ void AudioFlinger::EffectHandle::disconnect(bool unpiniflast) mCblk->~effect_param_cblk_t(); // destroy our shared-structure. mCblk->~effect_param_cblk_t(); // destroy our shared-structure. } } mCblkMemory.clear(); // free the shared memory before releasing the heap it belongs to mCblkMemory.clear(); // free the shared memory before releasing the heap it belongs to // Client destructor must run with AudioFlinger mutex locked Mutex::Autolock _l(mClient->audioFlinger()->mLock); Mutex::Autolock _l(mClient->audioFlinger()->mLock); mClient.clear(); mClient.clear(); } } Loading services/audioflinger/AudioFlinger.h +6 −2 Original line number Original line Diff line number Diff line Loading @@ -1231,7 +1231,7 @@ mutable Mutex mLock; // mutex for process, commands and handl sp<EffectModule> mEffect; // pointer to controlled EffectModule sp<EffectModule> mEffect; // pointer to controlled EffectModule sp<IEffectClient> mEffectClient; // callback interface for client notifications sp<IEffectClient> mEffectClient; // callback interface for client notifications sp<Client> mClient; // client for shared memory allocation /*const*/ sp<Client> mClient; // client for shared memory allocation, see disconnect() sp<IMemory> mCblkMemory; // shared memory for control block sp<IMemory> mCblkMemory; // shared memory for control block effect_param_cblk_t* mCblk; // control block for deferred parameter setting via shared memory effect_param_cblk_t* mCblk; // control block for deferred parameter setting via shared memory uint8_t* mBuffer; // pointer to parameter area in shared memory uint8_t* mBuffer; // pointer to parameter area in shared memory Loading Loading @@ -1403,7 +1403,7 @@ mutable Mutex mLock; // mutex for process, commands and handl mutable Mutex mLock; mutable Mutex mLock; DefaultKeyedVector< pid_t, wp<Client> > mClients; DefaultKeyedVector< pid_t, wp<Client> > mClients; // see ~Client() mutable Mutex mHardwareLock; mutable Mutex mHardwareLock; audio_hw_device_t* mPrimaryHardwareDev; audio_hw_device_t* mPrimaryHardwareDev; Loading @@ -1429,6 +1429,10 @@ mutable Mutex mLock; // mutex for process, commands and handl float masterVolume_l() const { return mMasterVolume; } float masterVolume_l() const { return mMasterVolume; } bool masterMute_l() const { return mMasterMute; } bool masterMute_l() const { return mMasterMute; } private: sp<Client> registerPid_l(pid_t pid); // always returns non-0 }; }; Loading Loading
services/audioflinger/AudioFlinger.cpp +17 −28 Original line number Original line Diff line number Diff line Loading @@ -370,6 +370,18 @@ status_t AudioFlinger::dump(int fd, const Vector<String16>& args) return NO_ERROR; return NO_ERROR; } } sp<AudioFlinger::Client> AudioFlinger::registerPid_l(pid_t pid) { // If pid is already in the mClients wp<> map, then use that entry // (for which promote() is always != 0), otherwise create a new entry and Client. sp<Client> client = mClients.valueFor(pid).promote(); if (client == 0) { client = new Client(this, pid); mClients.add(pid, client); } return client; } // IAudioFlinger interface // IAudioFlinger interface Loading @@ -390,7 +402,6 @@ sp<IAudioTrack> AudioFlinger::createTrack( sp<PlaybackThread::Track> track; sp<PlaybackThread::Track> track; sp<TrackHandle> trackHandle; sp<TrackHandle> trackHandle; sp<Client> client; sp<Client> client; wp<Client> wclient; status_t lStatus; status_t lStatus; int lSessionId; int lSessionId; Loading @@ -412,14 +423,7 @@ sp<IAudioTrack> AudioFlinger::createTrack( goto Exit; goto Exit; } } wclient = mClients.valueFor(pid); client = registerPid_l(pid); if (wclient != NULL) { client = wclient.promote(); } else { client = new Client(this, pid); mClients.add(pid, client); } ALOGV("createTrack() sessionId: %d", (sessionId == NULL) ? -2 : *sessionId); ALOGV("createTrack() sessionId: %d", (sessionId == NULL) ? -2 : *sessionId); if (sessionId != NULL && *sessionId != AUDIO_SESSION_OUTPUT_MIX) { if (sessionId != NULL && *sessionId != AUDIO_SESSION_OUTPUT_MIX) { Loading Loading @@ -4131,7 +4135,6 @@ sp<IAudioRecord> AudioFlinger::openRecord( sp<RecordThread::RecordTrack> recordTrack; sp<RecordThread::RecordTrack> recordTrack; sp<RecordHandle> recordHandle; sp<RecordHandle> recordHandle; sp<Client> client; sp<Client> client; wp<Client> wclient; status_t lStatus; status_t lStatus; RecordThread *thread; RecordThread *thread; size_t inFrameCount; size_t inFrameCount; Loading @@ -4152,13 +4155,7 @@ sp<IAudioRecord> AudioFlinger::openRecord( goto Exit; goto Exit; } } wclient = mClients.valueFor(pid); client = registerPid_l(pid); if (wclient != NULL) { client = wclient.promote(); } else { client = new Client(this, pid); mClients.add(pid, client); } // If no audio session id is provided, create one here // If no audio session id is provided, create one here if (sessionId != NULL && *sessionId != AUDIO_SESSION_OUTPUT_MIX) { if (sessionId != NULL && *sessionId != AUDIO_SESSION_OUTPUT_MIX) { Loading Loading @@ -5405,10 +5402,8 @@ sp<IEffect> AudioFlinger::createEffect(pid_t pid, status_t lStatus = NO_ERROR; status_t lStatus = NO_ERROR; sp<EffectHandle> handle; sp<EffectHandle> handle; effect_descriptor_t desc; effect_descriptor_t desc; sp<Client> client; wp<Client> wclient; ALOGV("createEffect pid %d, client %p, priority %d, sessionId %d, io %d", ALOGV("createEffect pid %d, effectClient %p, priority %d, sessionId %d, io %d", pid, effectClient.get(), priority, sessionId, io); pid, effectClient.get(), priority, sessionId, io); if (pDesc == NULL) { if (pDesc == NULL) { Loading Loading @@ -5559,14 +5554,7 @@ sp<IEffect> AudioFlinger::createEffect(pid_t pid, } } } } wclient = mClients.valueFor(pid); sp<Client> client = registerPid_l(pid); if (wclient != NULL) { client = wclient.promote(); } else { client = new Client(this, pid); mClients.add(pid, client); } // create effect on selected output thread // create effect on selected output thread handle = thread->createEffect_l(client, effectClient, priority, sessionId, handle = thread->createEffect_l(client, effectClient, priority, sessionId, Loading Loading @@ -6923,6 +6911,7 @@ void AudioFlinger::EffectHandle::disconnect(bool unpiniflast) mCblk->~effect_param_cblk_t(); // destroy our shared-structure. mCblk->~effect_param_cblk_t(); // destroy our shared-structure. } } mCblkMemory.clear(); // free the shared memory before releasing the heap it belongs to mCblkMemory.clear(); // free the shared memory before releasing the heap it belongs to // Client destructor must run with AudioFlinger mutex locked Mutex::Autolock _l(mClient->audioFlinger()->mLock); Mutex::Autolock _l(mClient->audioFlinger()->mLock); mClient.clear(); mClient.clear(); } } Loading
services/audioflinger/AudioFlinger.h +6 −2 Original line number Original line Diff line number Diff line Loading @@ -1231,7 +1231,7 @@ mutable Mutex mLock; // mutex for process, commands and handl sp<EffectModule> mEffect; // pointer to controlled EffectModule sp<EffectModule> mEffect; // pointer to controlled EffectModule sp<IEffectClient> mEffectClient; // callback interface for client notifications sp<IEffectClient> mEffectClient; // callback interface for client notifications sp<Client> mClient; // client for shared memory allocation /*const*/ sp<Client> mClient; // client for shared memory allocation, see disconnect() sp<IMemory> mCblkMemory; // shared memory for control block sp<IMemory> mCblkMemory; // shared memory for control block effect_param_cblk_t* mCblk; // control block for deferred parameter setting via shared memory effect_param_cblk_t* mCblk; // control block for deferred parameter setting via shared memory uint8_t* mBuffer; // pointer to parameter area in shared memory uint8_t* mBuffer; // pointer to parameter area in shared memory Loading Loading @@ -1403,7 +1403,7 @@ mutable Mutex mLock; // mutex for process, commands and handl mutable Mutex mLock; mutable Mutex mLock; DefaultKeyedVector< pid_t, wp<Client> > mClients; DefaultKeyedVector< pid_t, wp<Client> > mClients; // see ~Client() mutable Mutex mHardwareLock; mutable Mutex mHardwareLock; audio_hw_device_t* mPrimaryHardwareDev; audio_hw_device_t* mPrimaryHardwareDev; Loading @@ -1429,6 +1429,10 @@ mutable Mutex mLock; // mutex for process, commands and handl float masterVolume_l() const { return mMasterVolume; } float masterVolume_l() const { return mMasterVolume; } bool masterMute_l() const { return mMasterMute; } bool masterMute_l() const { return mMasterMute; } private: sp<Client> registerPid_l(pid_t pid); // always returns non-0 }; }; Loading