Merge "Converting sound trigger v2.2 getModelState to be asynchronous"

gugelfrei
Michael Dooley 6 years ago committed by Android (Google) Code Review
commit ef4bd9c425

@ -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;
};

@ -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);

@ -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;

@ -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(

@ -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() {}

@ -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)

@ -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);

@ -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;

@ -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

Loading…
Cancel
Save