Loading services/soundtrigger/SoundTriggerHwService.cpp +48 −25 Original line number Diff line number Diff line Loading @@ -497,6 +497,8 @@ void SoundTriggerHwService::Module::detach() { if (!captureHotwordAllowed()) { return; } Vector<audio_session_t> releasedSessions; { AutoMutex lock(mLock); for (size_t i = 0; i < mModels.size(); i++) { Loading @@ -506,9 +508,16 @@ void SoundTriggerHwService::Module::detach() { mHwDevice->stop_recognition(mHwDevice, model->mHandle); } mHwDevice->unload_sound_model(mHwDevice, model->mHandle); releasedSessions.add(model->mCaptureSession); } mModels.clear(); } for (size_t i = 0; i < releasedSessions.size(); i++) { // do not call AudioSystem methods with mLock held AudioSystem::releaseSoundTriggerSession(releasedSessions[i]); } if (mClient != 0) { mClient->asBinder()->unlinkToDeath(this); } Loading Loading @@ -550,6 +559,16 @@ status_t SoundTriggerHwService::Module::loadSoundModel(const sp<IMemory>& modelM return BAD_VALUE; } audio_session_t session; audio_io_handle_t ioHandle; audio_devices_t device; // do not call AudioSystem methods with mLock held status_t status = AudioSystem::acquireSoundTriggerSession(&session, &ioHandle, &device); if (status != NO_ERROR) { return status; } { AutoMutex lock(mLock); status_t status = mHwDevice->load_sound_model(mHwDevice, sound_model, Loading @@ -557,20 +576,18 @@ status_t SoundTriggerHwService::Module::loadSoundModel(const sp<IMemory>& modelM this, handle); if (status != NO_ERROR) { return status; } audio_session_t session; audio_io_handle_t ioHandle; audio_devices_t device; status = AudioSystem::acquireSoundTriggerSession(&session, &ioHandle, &device); if (status != NO_ERROR) { return status; goto exit; } sp<Model> model = new Model(*handle, session, ioHandle, device, sound_model->type); mModels.replaceValueFor(*handle, model); } exit: if (status != NO_ERROR) { // do not call AudioSystem methods with mLock held AudioSystem::releaseSoundTriggerSession(session); } return status; } Loading @@ -580,7 +597,10 @@ status_t SoundTriggerHwService::Module::unloadSoundModel(sound_model_handle_t ha if (!captureHotwordAllowed()) { return PERMISSION_DENIED; } status_t status; audio_session_t session; { AutoMutex lock(mLock); ssize_t index = mModels.indexOfKey(handle); if (index < 0) { Loading @@ -591,8 +611,11 @@ status_t SoundTriggerHwService::Module::unloadSoundModel(sound_model_handle_t ha if (model->mState == Model::STATE_ACTIVE) { mHwDevice->stop_recognition(mHwDevice, model->mHandle); } AudioSystem::releaseSoundTriggerSession(model->mCaptureSession); return mHwDevice->unload_sound_model(mHwDevice, handle); status = mHwDevice->unload_sound_model(mHwDevice, handle); session = model->mCaptureSession; } AudioSystem::releaseSoundTriggerSession(session); return status; } status_t SoundTriggerHwService::Module::startRecognition(sound_model_handle_t handle, Loading Loading
services/soundtrigger/SoundTriggerHwService.cpp +48 −25 Original line number Diff line number Diff line Loading @@ -497,6 +497,8 @@ void SoundTriggerHwService::Module::detach() { if (!captureHotwordAllowed()) { return; } Vector<audio_session_t> releasedSessions; { AutoMutex lock(mLock); for (size_t i = 0; i < mModels.size(); i++) { Loading @@ -506,9 +508,16 @@ void SoundTriggerHwService::Module::detach() { mHwDevice->stop_recognition(mHwDevice, model->mHandle); } mHwDevice->unload_sound_model(mHwDevice, model->mHandle); releasedSessions.add(model->mCaptureSession); } mModels.clear(); } for (size_t i = 0; i < releasedSessions.size(); i++) { // do not call AudioSystem methods with mLock held AudioSystem::releaseSoundTriggerSession(releasedSessions[i]); } if (mClient != 0) { mClient->asBinder()->unlinkToDeath(this); } Loading Loading @@ -550,6 +559,16 @@ status_t SoundTriggerHwService::Module::loadSoundModel(const sp<IMemory>& modelM return BAD_VALUE; } audio_session_t session; audio_io_handle_t ioHandle; audio_devices_t device; // do not call AudioSystem methods with mLock held status_t status = AudioSystem::acquireSoundTriggerSession(&session, &ioHandle, &device); if (status != NO_ERROR) { return status; } { AutoMutex lock(mLock); status_t status = mHwDevice->load_sound_model(mHwDevice, sound_model, Loading @@ -557,20 +576,18 @@ status_t SoundTriggerHwService::Module::loadSoundModel(const sp<IMemory>& modelM this, handle); if (status != NO_ERROR) { return status; } audio_session_t session; audio_io_handle_t ioHandle; audio_devices_t device; status = AudioSystem::acquireSoundTriggerSession(&session, &ioHandle, &device); if (status != NO_ERROR) { return status; goto exit; } sp<Model> model = new Model(*handle, session, ioHandle, device, sound_model->type); mModels.replaceValueFor(*handle, model); } exit: if (status != NO_ERROR) { // do not call AudioSystem methods with mLock held AudioSystem::releaseSoundTriggerSession(session); } return status; } Loading @@ -580,7 +597,10 @@ status_t SoundTriggerHwService::Module::unloadSoundModel(sound_model_handle_t ha if (!captureHotwordAllowed()) { return PERMISSION_DENIED; } status_t status; audio_session_t session; { AutoMutex lock(mLock); ssize_t index = mModels.indexOfKey(handle); if (index < 0) { Loading @@ -591,8 +611,11 @@ status_t SoundTriggerHwService::Module::unloadSoundModel(sound_model_handle_t ha if (model->mState == Model::STATE_ACTIVE) { mHwDevice->stop_recognition(mHwDevice, model->mHandle); } AudioSystem::releaseSoundTriggerSession(model->mCaptureSession); return mHwDevice->unload_sound_model(mHwDevice, handle); status = mHwDevice->unload_sound_model(mHwDevice, handle); session = model->mCaptureSession; } AudioSystem::releaseSoundTriggerSession(session); return status; } status_t SoundTriggerHwService::Module::startRecognition(sound_model_handle_t handle, Loading