diff options
author | mike dooley <mdooley@google.com> | 2018-11-07 15:44:37 +0100 |
---|---|---|
committer | mike dooley <mdooley@google.com> | 2018-11-09 20:05:44 +0100 |
commit | 6e189b19bbcdb21692924b90d6b33181e490b3fa (patch) | |
tree | 19c789d8d68b7a3f87d54525ff50173fa14fedd3 | |
parent | fd1c998237da395af546e0e3143a4133f966559b (diff) | |
download | frameworks_av-6e189b19bbcdb21692924b90d6b33181e490b3fa.tar.gz frameworks_av-6e189b19bbcdb21692924b90d6b33181e490b3fa.tar.bz2 frameworks_av-6e189b19bbcdb21692924b90d6b33181e490b3fa.zip |
Converting sound trigger v2.2 getModelState to be asynchronous
Test: built android with checkbuild flag
Change-Id: Ic12dbfe46aae08666ab02a1a8ee0dbb5c2d9381f
Bug-Id: 70206501
-rw-r--r-- | include/soundtrigger/ISoundTrigger.h | 3 | ||||
-rw-r--r-- | include/soundtrigger/SoundTrigger.h | 2 | ||||
-rw-r--r-- | services/soundtrigger/SoundTriggerHalHidl.cpp | 18 | ||||
-rw-r--r-- | services/soundtrigger/SoundTriggerHalHidl.h | 8 | ||||
-rw-r--r-- | services/soundtrigger/SoundTriggerHalInterface.h | 8 | ||||
-rw-r--r-- | services/soundtrigger/SoundTriggerHwService.cpp | 29 | ||||
-rw-r--r-- | services/soundtrigger/SoundTriggerHwService.h | 6 | ||||
-rw-r--r-- | soundtrigger/ISoundTrigger.cpp | 15 | ||||
-rw-r--r-- | soundtrigger/SoundTrigger.cpp | 5 |
9 files changed, 27 insertions, 67 deletions
diff --git a/include/soundtrigger/ISoundTrigger.h b/include/soundtrigger/ISoundTrigger.h index ea1aea6fd2..c357caafa3 100644 --- a/include/soundtrigger/ISoundTrigger.h +++ b/include/soundtrigger/ISoundTrigger.h @@ -40,8 +40,7 @@ public: virtual status_t startRecognition(sound_model_handle_t handle, const sp<IMemory>& dataMemory) = 0; virtual status_t stopRecognition(sound_model_handle_t handle) = 0; - virtual status_t getModelState(sound_model_handle_t handle, - sp<IMemory>& eventMemory) = 0; + virtual status_t getModelState(sound_model_handle_t handle) = 0; }; diff --git a/include/soundtrigger/SoundTrigger.h b/include/soundtrigger/SoundTrigger.h index dcf9ce8c11..2e2ff7ad16 100644 --- a/include/soundtrigger/SoundTrigger.h +++ b/include/soundtrigger/SoundTrigger.h @@ -52,7 +52,7 @@ public: status_t startRecognition(sound_model_handle_t handle, const sp<IMemory>& dataMemory); status_t stopRecognition(sound_model_handle_t handle); - status_t getModelState(sound_model_handle_t handle, sp<IMemory>& eventMemory); + status_t getModelState(sound_model_handle_t handle); // BpSoundTriggerClient virtual void onRecognitionEvent(const sp<IMemory>& eventMemory); diff --git a/services/soundtrigger/SoundTriggerHalHidl.cpp b/services/soundtrigger/SoundTriggerHalHidl.cpp index 0f9aa1589f..1d37a8ef44 100644 --- a/services/soundtrigger/SoundTriggerHalHidl.cpp +++ b/services/soundtrigger/SoundTriggerHalHidl.cpp @@ -356,8 +356,7 @@ int SoundTriggerHalHidl::stopAllRecognitions() return hidlReturn; } -int SoundTriggerHalHidl::getModelState(sound_model_handle_t handle, - struct sound_trigger_recognition_event** event) +int SoundTriggerHalHidl::getModelState(sound_model_handle_t handle) { sp<ISoundTriggerHw> soundtrigger = getService(); if (soundtrigger == 0) { @@ -377,24 +376,13 @@ int SoundTriggerHalHidl::getModelState(sound_model_handle_t handle, } int ret = NO_ERROR; - Return<void> hidlReturn; + Return<int32_t> hidlReturn(0); { AutoMutex lock(mHalLock); - hidlReturn = soundtrigger_2_2->getModelState( - model->mHalHandle, - [&](int r, const V2_0_ISoundTriggerHwCallback::RecognitionEvent& halEvent) { - ret = r; - if (ret != 0) { - ALOGE("getModelState returned error code %d", ret); - } else { - *event = convertRecognitionEventFromHal(&halEvent); - } - }); + hidlReturn = soundtrigger_2_2->getModelState(model->mHalHandle); } if (!hidlReturn.isOk()) { ALOGE("getModelState error %s", hidlReturn.description().c_str()); - free(*event); - *event = nullptr; ret = FAILED_TRANSACTION; } return ret; diff --git a/services/soundtrigger/SoundTriggerHalHidl.h b/services/soundtrigger/SoundTriggerHalHidl.h index 3f4bec3ccf..fb9e39e65f 100644 --- a/services/soundtrigger/SoundTriggerHalHidl.h +++ b/services/soundtrigger/SoundTriggerHalHidl.h @@ -96,12 +96,12 @@ public: virtual int stopAllRecognitions(); /* Get the current state of a given model. - * Returns 0 or an error code. If successful it also sets indicated the event pointer - * and expectes that the caller will free the memory. + * Returns 0 or an error code. If successful the state will be returned asynchronously + * via a recognition event in the callback method that was registered in the + * startRecognition() method. * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_2 or above. */ - virtual int getModelState(sound_model_handle_t handle, - struct sound_trigger_recognition_event** event); + virtual int getModelState(sound_model_handle_t handle); // ISoundTriggerHwCallback virtual ::android::hardware::Return<void> recognitionCallback( diff --git a/services/soundtrigger/SoundTriggerHalInterface.h b/services/soundtrigger/SoundTriggerHalInterface.h index 076ca2375f..0183ecef12 100644 --- a/services/soundtrigger/SoundTriggerHalInterface.h +++ b/services/soundtrigger/SoundTriggerHalInterface.h @@ -72,12 +72,12 @@ public: virtual int stopAllRecognitions() = 0; /* Get the current state of a given model. - * Returns 0 or an error code. If successful it also sets indicated the event pointer - * and expectes that the caller will free the memory. + * Returns 0 or an error code. If successful the state will be returned asynchronously + * via a recognition event in the callback method that was registered in the + * startRecognition() method. * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_2 or above. */ - virtual int getModelState(sound_model_handle_t handle, - struct sound_trigger_recognition_event** event) = 0; + virtual int getModelState(sound_model_handle_t handle) = 0; protected: SoundTriggerHalInterface() {} diff --git a/services/soundtrigger/SoundTriggerHwService.cpp b/services/soundtrigger/SoundTriggerHwService.cpp index 79e9e88d87..79150683a6 100644 --- a/services/soundtrigger/SoundTriggerHwService.cpp +++ b/services/soundtrigger/SoundTriggerHwService.cpp @@ -717,8 +717,7 @@ status_t SoundTriggerHwService::Module::stopRecognition(sound_model_handle_t han return NO_ERROR; } -status_t SoundTriggerHwService::Module::getModelState(sound_model_handle_t handle, - sp<IMemory>& eventMemory) +status_t SoundTriggerHwService::Module::getModelState(sound_model_handle_t handle) { ALOGV("getModelState() model handle %d", handle); if (mHalInterface == 0) { @@ -734,21 +733,7 @@ status_t SoundTriggerHwService::Module::getModelState(sound_model_handle_t handl return INVALID_OPERATION; } - if (model->mType != SOUND_MODEL_TYPE_GENERIC) { - return BAD_VALUE; - } - - struct sound_trigger_recognition_event* event = nullptr; - status_t status = mHalInterface->getModelState(handle, &event); - if (status == NO_ERROR) { - sp<SoundTriggerHwService> service; - service = mService.promote(); - if (service != 0) { - eventMemory = service->prepareRecognitionEvent(event); - } - free(event); - } - return status; + return mHalInterface->getModelState(handle); } void SoundTriggerHwService::Module::onCallbackEvent(const sp<CallbackEvent>& event) @@ -784,7 +769,10 @@ void SoundTriggerHwService::Module::onCallbackEvent(const sp<CallbackEvent>& eve } recognitionEvent->capture_session = model->mCaptureSession; - model->mState = Model::STATE_IDLE; + // Don't reset the model state if this recognition event is a get-state response + if (recognitionEvent->status != RECOGNITION_STATUS_GET_STATE_RESPONSE) { + model->mState = Model::STATE_IDLE; + } clients.add(model->mModuleClient); } } break; @@ -1052,8 +1040,7 @@ status_t SoundTriggerHwService::ModuleClient::stopRecognition(sound_model_handle return module->stopRecognition(handle); } -status_t SoundTriggerHwService::ModuleClient::getModelState(sound_model_handle_t handle, - sp<IMemory>& eventMemory) +status_t SoundTriggerHwService::ModuleClient::getModelState(sound_model_handle_t handle) { ALOGV("getModelState() model handle %d", handle); if (!captureHotwordAllowed(IPCThreadState::self()->getCallingPid(), @@ -1065,7 +1052,7 @@ status_t SoundTriggerHwService::ModuleClient::getModelState(sound_model_handle_t if (module == 0) { return NO_INIT; } - return module->getModelState(handle, eventMemory); + return module->getModelState(handle); } void SoundTriggerHwService::ModuleClient::setCaptureState_l(bool active) diff --git a/services/soundtrigger/SoundTriggerHwService.h b/services/soundtrigger/SoundTriggerHwService.h index c222cd9afe..4258ec0467 100644 --- a/services/soundtrigger/SoundTriggerHwService.h +++ b/services/soundtrigger/SoundTriggerHwService.h @@ -122,8 +122,7 @@ public: virtual status_t startRecognition(sound_model_handle_t handle, const sp<IMemory>& dataMemory); virtual status_t stopRecognition(sound_model_handle_t handle); - virtual status_t getModelState(sound_model_handle_t handle, - sp<IMemory>& eventMemory); + virtual status_t getModelState(sound_model_handle_t handle); sp<SoundTriggerHalInterface> halInterface() const { return mHalInterface; } struct sound_trigger_module_descriptor descriptor() { return mDescriptor; } @@ -171,8 +170,7 @@ public: virtual status_t startRecognition(sound_model_handle_t handle, const sp<IMemory>& dataMemory); virtual status_t stopRecognition(sound_model_handle_t handle); - virtual status_t getModelState(sound_model_handle_t handle, - sp<IMemory>& eventMemory); + virtual status_t getModelState(sound_model_handle_t handle); virtual status_t dump(int fd, const Vector<String16>& args); diff --git a/soundtrigger/ISoundTrigger.cpp b/soundtrigger/ISoundTrigger.cpp index 32882f1ef2..f5b4b5950c 100644 --- a/soundtrigger/ISoundTrigger.cpp +++ b/soundtrigger/ISoundTrigger.cpp @@ -114,8 +114,7 @@ public: return status; } - virtual status_t getModelState(sound_model_handle_t handle, - sp<IMemory>& eventMemory) + virtual status_t getModelState(sound_model_handle_t handle) { Parcel data, reply; data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor()); @@ -123,9 +122,6 @@ public: status_t status = remote()->transact(GET_MODEL_STATE, data, &reply); if (status == NO_ERROR) { status = (status_t)reply.readInt32(); - if (status == NO_ERROR) { - eventMemory = interface_cast<IMemory>(reply.readStrongBinder()); - } } return status; } @@ -192,14 +188,7 @@ status_t BnSoundTrigger::onTransact( status_t status = UNKNOWN_ERROR; status_t ret = data.read(&handle, sizeof(sound_model_handle_t)); if (ret == NO_ERROR) { - sp<IMemory> eventMemory; - status = getModelState(handle, eventMemory); - if (eventMemory != NULL) { - ret = reply->writeStrongBinder( - IInterface::asBinder(eventMemory)); - } else { - ret = NO_MEMORY; - } + status = getModelState(handle); } reply->writeInt32(status); return ret; diff --git a/soundtrigger/SoundTrigger.cpp b/soundtrigger/SoundTrigger.cpp index bb0650f3a0..d1eb367763 100644 --- a/soundtrigger/SoundTrigger.cpp +++ b/soundtrigger/SoundTrigger.cpp @@ -188,14 +188,13 @@ status_t SoundTrigger::stopRecognition(sound_model_handle_t handle) return mISoundTrigger->stopRecognition(handle); } -status_t SoundTrigger::getModelState(sound_model_handle_t handle, - sp<IMemory>& eventMemory) +status_t SoundTrigger::getModelState(sound_model_handle_t handle) { Mutex::Autolock _l(mLock); if (mISoundTrigger == 0) { return NO_INIT; } - return mISoundTrigger->getModelState(handle, eventMemory); + return mISoundTrigger->getModelState(handle); } // BpSoundTriggerClient |