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

Commit 09c8fa93 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I8f62a549,I8feb2eb8

* changes:
  Convert libsoundtriggerservice to Android.bp
  Remove USE_LEGACY_LOCAL_AUDIO_HAL in libsoundtriggerservice
parents 2c7c5c4b d1dbc788
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
// Copyright 2014 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

cc_library_shared {
    name: "libsoundtriggerservice",

    srcs: [
        "SoundTriggerHwService.cpp",
        "SoundTriggerHalHidl.cpp",
    ],

    shared_libs: [
        "liblog",
        "libutils",
        "libbinder",
        "libcutils",
        "libhardware",
        "libsoundtrigger",
        "libaudioclient",
        "libmediautils",

        "libhwbinder",
        "libhidlbase",
        "libhidlmemory",
        "libhidltransport",
        "libbase",
        "libaudiohal",
        "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",
    ],

    include_dirs: ["frameworks/av/services/audioflinger"],

    cflags: [
        "-Wall",
        "-Werror",
    ],
}

services/soundtrigger/Android.mk

deleted100644 → 0
+0 −74
Original line number Diff line number Diff line
# Copyright 2014 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

ifeq ($(SOUND_TRIGGER_USE_STUB_MODULE), 1)
    ifneq ($(USE_LEGACY_LOCAL_AUDIO_HAL), true)
        $(error Requires building with USE_LEGACY_LOCAL_AUDIO_HAL=true)
    endif
    LOCAL_CFLAGS += -DSOUND_TRIGGER_USE_STUB_MODULE
endif

LOCAL_SRC_FILES:=               \
    SoundTriggerHwService.cpp

LOCAL_SHARED_LIBRARIES:= \
    liblog \
    libutils \
    libbinder \
    libcutils \
    libhardware \
    libsoundtrigger \
    libaudioclient \
    libmediautils \

ifeq ($(USE_LEGACY_LOCAL_AUDIO_HAL),true)
# libhardware configuration
LOCAL_SRC_FILES +=               \
    SoundTriggerHalLegacy.cpp
else
# Treble configuration
LOCAL_SRC_FILES +=               \
    SoundTriggerHalHidl.cpp

LOCAL_SHARED_LIBRARIES += \
    libhwbinder \
    libhidlbase \
    libhidlmemory \
    libhidltransport \
    libbase \
    libaudiohal \
    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
endif


LOCAL_C_INCLUDES += \
    frameworks/av/services/audioflinger

LOCAL_MULTILIB := $(AUDIOSERVER_MULTILIB)

LOCAL_CFLAGS += -Wall -Werror

LOCAL_MODULE:= libsoundtriggerservice

include $(BUILD_SHARED_LIBRARY)
+0 −127
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <utils/Log.h>
#include "SoundTriggerHalLegacy.h"

namespace android {

/* static */
sp<SoundTriggerHalInterface> SoundTriggerHalInterface::connectModule(const char *moduleName)
{
    return new SoundTriggerHalLegacy(moduleName);
}

SoundTriggerHalLegacy::SoundTriggerHalLegacy(const char *moduleName)
    : mModuleName(moduleName), mHwDevice(NULL)
{
}

void SoundTriggerHalLegacy::onFirstRef()
{
    const hw_module_t *mod;
    int rc;

    if (mModuleName == NULL) {
        mModuleName = "primary";
    }

    rc = hw_get_module_by_class(SOUND_TRIGGER_HARDWARE_MODULE_ID, mModuleName, &mod);
    if (rc != 0) {
        ALOGE("couldn't load sound trigger module %s.%s (%s)",
              SOUND_TRIGGER_HARDWARE_MODULE_ID, mModuleName, strerror(-rc));
        return;
    }
    rc = sound_trigger_hw_device_open(mod, &mHwDevice);
    if (rc != 0) {
        ALOGE("couldn't open sound trigger hw device in %s.%s (%s)",
              SOUND_TRIGGER_HARDWARE_MODULE_ID, mModuleName, strerror(-rc));
        mHwDevice = NULL;
        return;
    }
    if (mHwDevice->common.version < SOUND_TRIGGER_DEVICE_API_VERSION_1_0 ||
            mHwDevice->common.version > SOUND_TRIGGER_DEVICE_API_VERSION_CURRENT) {
        ALOGE("wrong sound trigger hw device version %04x", mHwDevice->common.version);
        return;
    }
}

SoundTriggerHalLegacy::~SoundTriggerHalLegacy()
{
    if (mHwDevice != NULL) {
        sound_trigger_hw_device_close(mHwDevice);
    }
}

int SoundTriggerHalLegacy::getProperties(struct sound_trigger_properties *properties)
{
    if (mHwDevice == NULL) {
        return -ENODEV;
    }
    return mHwDevice->get_properties(mHwDevice, properties);
}

int SoundTriggerHalLegacy::loadSoundModel(struct sound_trigger_sound_model *sound_model,
                        sound_model_callback_t callback,
                        void *cookie,
                        sound_model_handle_t *handle)
{
    if (mHwDevice == NULL) {
        return -ENODEV;
    }
    return mHwDevice->load_sound_model(mHwDevice, sound_model, callback, cookie, handle);
}

int SoundTriggerHalLegacy::unloadSoundModel(sound_model_handle_t handle)
{
    if (mHwDevice == NULL) {
        return -ENODEV;
    }
    return mHwDevice->unload_sound_model(mHwDevice, handle);
}

int SoundTriggerHalLegacy::startRecognition(sound_model_handle_t handle,
                         const struct sound_trigger_recognition_config *config,
                         recognition_callback_t callback,
                         void *cookie)
{
    if (mHwDevice == NULL) {
        return -ENODEV;
    }
    return mHwDevice->start_recognition(mHwDevice, handle, config, callback, cookie);
}

int SoundTriggerHalLegacy::stopRecognition(sound_model_handle_t handle)
{
    if (mHwDevice == NULL) {
        return -ENODEV;
    }
    return mHwDevice->stop_recognition(mHwDevice, handle);
}

int SoundTriggerHalLegacy::stopAllRecognitions()
{
    if (mHwDevice == NULL) {
        return -ENODEV;
    }
    if (mHwDevice->common.version >= SOUND_TRIGGER_DEVICE_API_VERSION_1_1 &&
     mHwDevice->stop_all_recognitions) {
        return mHwDevice->stop_all_recognitions(mHwDevice);
    }
    return -ENOSYS;
}

} // namespace android
+0 −85
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_HARDWARE_SOUNDTRIGGER_HAL_LEGACY_H
#define ANDROID_HARDWARE_SOUNDTRIGGER_HAL_LEGACY_H

#include "SoundTriggerHalInterface.h"

namespace android {

class SoundTriggerHalLegacy : public SoundTriggerHalInterface

{
public:
        virtual             ~SoundTriggerHalLegacy();

        virtual int getProperties(struct sound_trigger_properties *properties);

        /*
         * Load a sound model. Once loaded, recognition of this model can be started and stopped.
         * Only one active recognition per model at a time. The SoundTrigger service will handle
         * concurrent recognition requests by different users/applications on the same model.
         * The implementation returns a unique handle used by other functions (unload_sound_model(),
         * start_recognition(), etc...
         */
        virtual int loadSoundModel(struct sound_trigger_sound_model *sound_model,
                                sound_model_callback_t callback,
                                void *cookie,
                                sound_model_handle_t *handle);

        /*
         * Unload a sound model. A sound model can be unloaded to make room for a new one to overcome
         * implementation limitations.
         */
        virtual int unloadSoundModel(sound_model_handle_t handle);

        /* Start recognition on a given model. Only one recognition active at a time per model.
         * Once recognition succeeds of fails, the callback is called.
         * TODO: group recognition configuration parameters into one struct and add key phrase options.
         */
        virtual int startRecognition(sound_model_handle_t handle,
                                 const struct sound_trigger_recognition_config *config,
                                 recognition_callback_t callback,
                                 void *cookie);

        /* Stop recognition on a given model.
         * The implementation does not have to call the callback when stopped via this method.
         */
        virtual int stopRecognition(sound_model_handle_t handle);

        /* Stop recognition on all models.
         * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_1 or above.
         * If no implementation is provided, stop_recognition will be called for each running model.
         */
        int stopAllRecognitions();

        // RefBase
        virtual     void        onFirstRef();

private:

        friend class SoundTriggerHalInterface;

        explicit SoundTriggerHalLegacy(const char *moduleName = NULL);

        const char *mModuleName;
        struct sound_trigger_hw_device*        mHwDevice;
};

} // namespace android

#endif // ANDROID_HARDWARE_SOUNDTRIGGER_HAL_LEGACY_H
+0 −4
Original line number Diff line number Diff line
@@ -36,11 +36,7 @@
#include <system/sound_trigger.h>
#include "SoundTriggerHwService.h"

#ifdef SOUND_TRIGGER_USE_STUB_MODULE
#define HW_MODULE_PREFIX "stub"
#else
#define HW_MODULE_PREFIX "primary"
#endif
namespace android {

SoundTriggerHwService::SoundTriggerHwService()