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

Commit 66203be3 authored by Nicholas Ambur's avatar Nicholas Ambur Committed by Android (Google) Code Review
Browse files

Merge "add audioCapabilities to SoundTrigger properties"

parents 0b214dc4 539cbb72
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -671,5 +671,5 @@ b27ab0cd40b0b078cdcd024bfe1061c4c4c065f3519eeb9347fa359a3268a5ae android.hardwar
##
# END Radio HAL Merge Conflict Avoidance Buffer - STOPSHIP if present
##
b46d358537168c478762c3d34d5fe1555a3fcd89cd1f43621350ada395e6f795 android.hardware.soundtrigger@2.3::types
15924fbf38b3c282299a37e48c72405c97e322f844f815081db6acbca22d4165 android.hardware.soundtrigger@2.3::ISoundTriggerHw
51d1c8d285e0456da2a3fdfbf4700c6277165d5e83219894d651c8ea0e39aa8b android.hardware.soundtrigger@2.3::types
12d7533ff0754f45bf59ab300799074570a99a676545652c2c23abc73cb4515d android.hardware.soundtrigger@2.3::ISoundTriggerHw
+23 −0
Original line number Diff line number Diff line
@@ -17,7 +17,9 @@
package android.hardware.soundtrigger@2.3;

import @2.0::SoundModelHandle;
import @2.0::ISoundTriggerHwCallback.CallbackCookie;
import @2.2::ISoundTriggerHw;
import @2.1::ISoundTriggerHwCallback;

/**
 * SoundTrigger HAL interface. Used for hardware recognition of hotwords
@@ -37,6 +39,27 @@ interface ISoundTriggerHw extends @2.2::ISoundTriggerHw {
     */
    getProperties_2_3() generates (int32_t retval, Properties properties);

    /**
     * Start recognition on a given model. Only one recognition active
     * at a time per model. Once recognition succeeds or fails, the callback
     * associated with the model handle is called.
     *
     * Must have the exact same semantics as startRecognition from
     * ISoundTriggerHw@2.1 except that the RecognitionConfig includes audio
     * capabilities applied when the recognition is active.
     *
     * @param modelHandle the handle of the sound model to use for recognition
     * @param config A RecognitionConfig structure containing attributes of the
     *     recognition to perform
     * @return retval Operation completion status: 0 in case of success,
     *     -EINVAL in case of invalid recognition attributes,
     *     -ENOSYS in case of invalid model handle,
     *     -ENOMEM in case of memory allocation failure,
     *     -ENODEV in case of initialization error.
     */
    startRecognition_2_3(SoundModelHandle modelHandle, RecognitionConfig config)
            generates (int32_t retval);

    /**
     * Set a model specific parameter with the given value. This parameter
     * will keep its value for the duration the model is loaded regardless of starting and stopping
+84 −1
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "SoundTriggerHw"

#include "SoundTriggerHw.h"
@@ -357,6 +356,7 @@ void SoundTriggerHw::convertPropertiesFromHal(
                (const struct sound_trigger_properties_extended_1_3*)header;
        convertPropertiesFromHal(&properties->base, &halProperties->base);
        properties->supportedModelArch = halProperties->supported_model_arch;
        properties->audioCapabilities = halProperties->audio_capabilities;
    }
}

@@ -460,6 +460,54 @@ struct sound_trigger_recognition_config* SoundTriggerHw::convertRecognitionConfi
    return halConfig;
}

struct sound_trigger_recognition_config_header* SoundTriggerHw::convertRecognitionConfigToHalHeader(
        const V2_3::RecognitionConfig* config) {
    sp<IMemory> memory;
    const V2_1::ISoundTriggerHw::RecognitionConfig* config_2_1 = &config->base;
    const V2_0::ISoundTriggerHw::RecognitionConfig* config_2_0 = &config_2_1->header;

    size_t allocSize =
            sizeof(struct sound_trigger_recognition_config_extended_1_3) + config_2_1->data.size();
    struct sound_trigger_recognition_config_extended_1_3* halConfigExtended =
            static_cast<struct sound_trigger_recognition_config_extended_1_3*>(malloc(allocSize));
    LOG_ALWAYS_FATAL_IF(halConfigExtended == nullptr,
                        "malloc failed for size %zu in convertRecognitionConfigToHalHeader",
                        allocSize);
    halConfigExtended->header.version = SOUND_TRIGGER_DEVICE_API_VERSION_1_3;
    halConfigExtended->header.size = allocSize;

    struct sound_trigger_recognition_config* halConfigBase = &halConfigExtended->base;

    halConfigBase->capture_handle = (audio_io_handle_t)config_2_0->captureHandle;
    halConfigBase->capture_device = (audio_devices_t)config_2_0->captureDevice;
    halConfigBase->capture_requested = config_2_0->captureRequested;

    unsigned int i;
    for (i = 0; i < config_2_0->phrases.size() && i < SOUND_TRIGGER_MAX_PHRASES; i++) {
        convertPhraseRecognitionExtraToHal(&halConfigBase->phrases[i], &config_2_0->phrases[i]);
    }
    halConfigBase->num_phrases = i;

    halConfigBase->data_offset = sizeof(struct sound_trigger_recognition_config_extended_1_3);
    halConfigBase->data_size = config_2_1->data.size();
    if (config_2_1->data.size() != 0) {
        memory = mapMemory(config_2_1->data);
        LOG_ALWAYS_FATAL_IF(memory == nullptr,
                            "failed to map config memory in convertRecognitionConfigToHalHeader");
        memory->read();

        uint8_t* dst = reinterpret_cast<uint8_t*>(halConfigExtended) + halConfigBase->data_offset;
        const uint8_t* src = static_cast<const uint8_t*>(static_cast<void*>(memory->getPointer()));
        memcpy(dst, src, config_2_1->data.size());

        memory->commit();
    }

    halConfigExtended->audio_capabilities = config->audioCapabilities;

    return &halConfigExtended->header;
}

// static
void SoundTriggerHw::convertSoundModelEventFromHal(
        V2_0::ISoundTriggerHwCallback::ModelEvent* event,
@@ -741,6 +789,41 @@ exit:
    return Void();
}

Return<int32_t> SoundTriggerHw::startRecognition_2_3(int32_t modelHandle,
                                                     const V2_3::RecognitionConfig& config) {
    int32_t ret;
    sp<SoundTriggerHw::SoundModelClient> client;
    struct sound_trigger_recognition_config_header* header;

    if (mHwDevice == NULL) {
        ret = -ENODEV;
        goto exit;
    }

    {
        AutoMutex lock(mLock);
        client = mClients.valueFor(modelHandle);
        if (client == 0) {
            ret = -ENOSYS;
            goto exit;
        }
    }

    header = convertRecognitionConfigToHalHeader(&config);

    if (header == nullptr) {
        ret = -EINVAL;
        goto exit;
    }
    ret = mHwDevice->start_recognition_extended(mHwDevice, client->getHalHandle(), header,
                                                recognitionCallback_, client.get());

    free(header);

exit:
    return ret;
}

Return<int32_t> SoundTriggerHw::setParameter(V2_0::SoundModelHandle modelHandle,
                                             ModelParameter modelParam, int32_t value) {
    sp<SoundModelClient> client;
+4 −0
Original line number Diff line number Diff line
@@ -86,6 +86,8 @@ struct SoundTriggerHw : public ISoundTriggerHw {

    // Methods from V2_3::ISoundTriggerHw follow.
    Return<void> getProperties_2_3(getProperties_2_3_cb _hidl_cb) override;
    Return<int32_t> startRecognition_2_3(int32_t modelHandle,
                                         const V2_3::RecognitionConfig& config) override;
    Return<int32_t> setParameter(V2_0::SoundModelHandle modelHandle, ModelParameter modelParam,
                                 int32_t value) override;
    Return<void> getParameter(V2_0::SoundModelHandle modelHandle, ModelParameter modelParam,
@@ -170,6 +172,8 @@ struct SoundTriggerHw : public ISoundTriggerHw {
    // returned recognition config must be freed by caller
    struct sound_trigger_recognition_config* convertRecognitionConfigToHal(
            const V2_0::ISoundTriggerHw::RecognitionConfig* config);
    struct sound_trigger_recognition_config_header* convertRecognitionConfigToHalHeader(
            const V2_3::RecognitionConfig* config);

    static void convertPhraseRecognitionExtraFromHal(
            V2_0::PhraseRecognitionExtra* extra,
+36 −0
Original line number Diff line number Diff line
@@ -18,6 +18,22 @@ package android.hardware.soundtrigger@2.3;

import android.hidl.safe_union@1.0::Monostate;
import @2.0::ISoundTriggerHw.Properties;
import @2.1::ISoundTriggerHw.RecognitionConfig;

/**
 * AudioCapabilities supported by the implemented HAL
 * driver.
 */
enum AudioCapabilities : uint32_t {
    /**
     * If set the underlying module supports AEC.
     */
    ECHO_CANCELLATION = 1 << 0,
    /**
     * If set, the underlying module supports noise suppression.
     */
    NOISE_SUPPRESSION = 1 << 1,
};

/**
 * Extended implementation properties providing verbose implementation
@@ -31,6 +47,26 @@ struct Properties {
     * (eg. DSP architecture)
     */
    string supportedModelArch;

    /**
     * Bit field encoding of the AudioCapabilities
     * supported by the firmware.
     */
    bitfield<AudioCapabilities> audioCapabilities;
};

/**
 * Configuration for sound trigger capture session passed to
 * startRecognition_2_1() method.
 */
struct RecognitionConfig {
    @2.1::ISoundTriggerHw.RecognitionConfig base;

    /**
     * Bit field encoding of the AudioCapabilities
     * supported by the firmware.
     */
    uint32_t audioCapabilities;
};

/**
Loading