Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 79e28e4e authored by Michael Dooley's avatar Michael Dooley
Browse files

Revert "Revert "Adding getModelState API to sound trigger""

This reverts commit 6dd21efe.

Reason for revert: undoing rollback

Change-Id: I9ad0662f95a20af7a4142852159a87520b338573
parent 5a855fee
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ 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;

};

+1 −0
Original line number Diff line number Diff line
@@ -52,6 +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);

            // BpSoundTriggerClient
            virtual void onRecognitionEvent(const sp<IMemory>& eventMemory);
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ LOCAL_SHARED_LIBRARIES += \
    libaudiohal_deathhandler \
    android.hardware.soundtrigger@2.0 \
    android.hardware.soundtrigger@2.1 \
    android.hardware.soundtrigger@2.2 \
    android.hardware.audio.common@2.0 \
    android.hidl.allocator@1.0 \
    android.hidl.memory@1.0
+50 −0
Original line number Diff line number Diff line
@@ -356,6 +356,50 @@ int SoundTriggerHalHidl::stopAllRecognitions()
    return hidlReturn;
}

int SoundTriggerHalHidl::getModelState(sound_model_handle_t handle,
                                       struct sound_trigger_recognition_event** event)
{
    sp<ISoundTriggerHw> soundtrigger = getService();
    if (soundtrigger == 0) {
        return -ENODEV;
    }

    sp<V2_2_ISoundTriggerHw> soundtrigger_2_2 = toService2_2(soundtrigger);
    if (soundtrigger_2_2 == 0) {
        ALOGE("getModelState not supported");
        return -ENODEV;
    }

    sp<SoundModel> model = getModel(handle);
    if (model == 0) {
        ALOGE("getModelState model not found for handle %u", handle);
        return -EINVAL;
    }

    int ret = NO_ERROR;
    Return<void> hidlReturn;
    {
        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);
              }
            });
    }
    if (!hidlReturn.isOk()) {
        ALOGE("getModelState error %s", hidlReturn.description().c_str());
        free(*event);
        *event = nullptr;
        ret = FAILED_TRANSACTION;
    }
    return ret;
}

SoundTriggerHalHidl::SoundTriggerHalHidl(const char *moduleName)
    : mModuleName(moduleName), mNextUniqueId(1)
{
@@ -388,6 +432,12 @@ sp<V2_1_ISoundTriggerHw> SoundTriggerHalHidl::toService2_1(const sp<ISoundTrigge
    return castResult_2_1.isOk() ? static_cast<sp<V2_1_ISoundTriggerHw>>(castResult_2_1) : nullptr;
}

sp<V2_2_ISoundTriggerHw> SoundTriggerHalHidl::toService2_2(const sp<ISoundTriggerHw>& s)
{
    auto castResult_2_2 = V2_2_ISoundTriggerHw::castFrom(s);
    return castResult_2_2.isOk() ? static_cast<sp<V2_2_ISoundTriggerHw>>(castResult_2_2) : nullptr;
}

sp<SoundTriggerHalHidl::SoundModel> SoundTriggerHalHidl::getModel(sound_model_handle_t handle)
{
    AutoMutex lock(mLock);
+12 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include "SoundTriggerHalInterface.h"
#include <android/hardware/soundtrigger/2.0/types.h>
#include <android/hardware/soundtrigger/2.1/ISoundTriggerHw.h>
#include <android/hardware/soundtrigger/2.2/ISoundTriggerHw.h>
#include <android/hardware/soundtrigger/2.0/ISoundTriggerHwCallback.h>
#include <android/hardware/soundtrigger/2.1/ISoundTriggerHwCallback.h>

@@ -46,6 +47,8 @@ using V2_1_ISoundTriggerHw =
using V2_1_ISoundTriggerHwCallback =
        ::android::hardware::soundtrigger::V2_1::ISoundTriggerHwCallback;
using ::android::hidl::memory::V1_0::IMemory;
using V2_2_ISoundTriggerHw =
        ::android::hardware::soundtrigger::V2_2::ISoundTriggerHw;

class SoundTriggerHalHidl : public SoundTriggerHalInterface,
                            public virtual V2_1_ISoundTriggerHwCallback
@@ -92,6 +95,14 @@ 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.
         * 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);

        // ISoundTriggerHwCallback
        virtual ::android::hardware::Return<void> recognitionCallback(
                const V2_0_ISoundTriggerHwCallback::RecognitionEvent& event, CallbackCookie cookie);
@@ -182,6 +193,7 @@ private:
        uint32_t nextUniqueId();
        sp<ISoundTriggerHw> getService();
        sp<V2_1_ISoundTriggerHw> toService2_1(const sp<ISoundTriggerHw>& s);
        sp<V2_2_ISoundTriggerHw> toService2_2(const sp<ISoundTriggerHw>& s);
        sp<SoundModel> getModel(sound_model_handle_t handle);
        sp<SoundModel> removeModel(sound_model_handle_t handle);

Loading