From fc496a2fffd5e6a5bb49871ea08bb6f13a57103a Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Fri, 5 Aug 2016 12:13:45 -0700 Subject: [PATCH] sound trigger: initial implementation of TREBLE HAL Initial version of the sound trigger HAL for TREBLE model. Functionally equivalent to legacy HAL. Bug: 30222631 Test: build verified Change-Id: I3cc904f21e1d81458ef877352b21c25a798cd355 --- Android.bp | 1 + soundtrigger/2.0/Android.bp | 55 ++++ soundtrigger/2.0/Android.mk | 254 +++++++++++++++++++ soundtrigger/2.0/ISoundTriggerHw.hal | 215 ++++++++++++++++ soundtrigger/2.0/ISoundTriggerHwCallback.hal | 103 ++++++++ soundtrigger/2.0/types.hal | 75 ++++++ 6 files changed, 703 insertions(+) create mode 100644 soundtrigger/2.0/Android.bp create mode 100644 soundtrigger/2.0/Android.mk create mode 100644 soundtrigger/2.0/ISoundTriggerHw.hal create mode 100644 soundtrigger/2.0/ISoundTriggerHwCallback.hal create mode 100644 soundtrigger/2.0/types.hal diff --git a/Android.bp b/Android.bp index 65febd3ed5..b09da52d65 100644 --- a/Android.bp +++ b/Android.bp @@ -10,6 +10,7 @@ subdirs = [ "radio/1.0", "power/1.0", "power/1.0/default", + "soundtrigger/2.0", "tests/bar/1.0", "tests/baz/1.0", "tests/expression/1.0", diff --git a/soundtrigger/2.0/Android.bp b/soundtrigger/2.0/Android.bp new file mode 100644 index 0000000000..10a917b9bb --- /dev/null +++ b/soundtrigger/2.0/Android.bp @@ -0,0 +1,55 @@ +// This file is autogenerated by hidl-gen. Do not edit manually. + +genrule { + name: "android.hardware.soundtrigger@2.0_genc++", + tool: "hidl-gen", + cmd: "$tool -o $genDir -Lc++ -randroid.hardware:hardware/interfaces android.hardware.soundtrigger@2.0", + srcs: [ + "types.hal", + "ISoundTriggerHw.hal", + "ISoundTriggerHwCallback.hal", + ], + out: [ + "android/hardware/soundtrigger/2.0/types.cpp", + "android/hardware/soundtrigger/2.0/SoundTriggerHwAll.cpp", + "android/hardware/soundtrigger/2.0/SoundTriggerHwCallbackAll.cpp", + ], +} + +genrule { + name: "android.hardware.soundtrigger@2.0_genc++_headers", + tool: "hidl-gen", + cmd: "$tool -o $genDir -Lc++ -randroid.hardware:hardware/interfaces android.hardware.soundtrigger@2.0", + srcs: [ + "types.hal", + "ISoundTriggerHw.hal", + "ISoundTriggerHwCallback.hal", + ], + out: [ + "android/hardware/soundtrigger/2.0/types.h", + "android/hardware/soundtrigger/2.0/ISoundTriggerHw.h", + "android/hardware/soundtrigger/2.0/IHwSoundTriggerHw.h", + "android/hardware/soundtrigger/2.0/BnSoundTriggerHw.h", + "android/hardware/soundtrigger/2.0/BpSoundTriggerHw.h", + "android/hardware/soundtrigger/2.0/BsSoundTriggerHw.h", + "android/hardware/soundtrigger/2.0/ISoundTriggerHwCallback.h", + "android/hardware/soundtrigger/2.0/IHwSoundTriggerHwCallback.h", + "android/hardware/soundtrigger/2.0/BnSoundTriggerHwCallback.h", + "android/hardware/soundtrigger/2.0/BpSoundTriggerHwCallback.h", + "android/hardware/soundtrigger/2.0/BsSoundTriggerHwCallback.h", + ], +} + +cc_library_shared { + name: "android.hardware.soundtrigger@2.0", + generated_sources: ["android.hardware.soundtrigger@2.0_genc++"], + generated_headers: ["android.hardware.soundtrigger@2.0_genc++_headers"], + export_generated_headers: ["android.hardware.soundtrigger@2.0_genc++_headers"], + shared_libs: [ + "libhidl", + "libhwbinder", + "libutils", + "libcutils", + "android.hardware.audio.common@2.0", + ], +} diff --git a/soundtrigger/2.0/Android.mk b/soundtrigger/2.0/Android.mk new file mode 100644 index 0000000000..1e3f036bbe --- /dev/null +++ b/soundtrigger/2.0/Android.mk @@ -0,0 +1,254 @@ +# This file is autogenerated by hidl-gen. Do not edit manually. + +LOCAL_PATH := $(call my-dir) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := android.hardware.soundtrigger@2.0-java +LOCAL_MODULE_CLASS := JAVA_LIBRARIES + +intermediates := $(local-generated-sources-dir) + +HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX) + +LOCAL_JAVA_LIBRARIES := \ + android.hardware.audio.common@2.0-java \ + + +# +# Build types.hal (ConfidenceLevel) +# +GEN := $(intermediates)/android/hardware/soundtrigger/2.0/ConfidenceLevel.java +$(GEN): $(HIDL) +$(GEN): PRIVATE_HIDL := $(HIDL) +$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal +$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) +$(GEN): PRIVATE_CUSTOM_TOOL = \ + $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ + -Ljava -randroid.hardware:hardware/interfaces \ + android.hardware.soundtrigger@2.0::types.ConfidenceLevel + +$(GEN): $(LOCAL_PATH)/types.hal + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) + +# +# Build types.hal (PhraseRecognitionExtra) +# +GEN := $(intermediates)/android/hardware/soundtrigger/2.0/PhraseRecognitionExtra.java +$(GEN): $(HIDL) +$(GEN): PRIVATE_HIDL := $(HIDL) +$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal +$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) +$(GEN): PRIVATE_CUSTOM_TOOL = \ + $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ + -Ljava -randroid.hardware:hardware/interfaces \ + android.hardware.soundtrigger@2.0::types.PhraseRecognitionExtra + +$(GEN): $(LOCAL_PATH)/types.hal + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) + +# +# Build types.hal (RecognitionMode) +# +GEN := $(intermediates)/android/hardware/soundtrigger/2.0/RecognitionMode.java +$(GEN): $(HIDL) +$(GEN): PRIVATE_HIDL := $(HIDL) +$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal +$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) +$(GEN): PRIVATE_CUSTOM_TOOL = \ + $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ + -Ljava -randroid.hardware:hardware/interfaces \ + android.hardware.soundtrigger@2.0::types.RecognitionMode + +$(GEN): $(LOCAL_PATH)/types.hal + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) + +# +# Build types.hal (SoundModelType) +# +GEN := $(intermediates)/android/hardware/soundtrigger/2.0/SoundModelType.java +$(GEN): $(HIDL) +$(GEN): PRIVATE_HIDL := $(HIDL) +$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal +$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) +$(GEN): PRIVATE_CUSTOM_TOOL = \ + $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ + -Ljava -randroid.hardware:hardware/interfaces \ + android.hardware.soundtrigger@2.0::types.SoundModelType + +$(GEN): $(LOCAL_PATH)/types.hal + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) + +# +# Build ISoundTriggerHw.hal +# +GEN := $(intermediates)/android/hardware/soundtrigger/2.0/ISoundTriggerHw.java +$(GEN): $(HIDL) +$(GEN): PRIVATE_HIDL := $(HIDL) +$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/ISoundTriggerHw.hal +$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/ISoundTriggerHwCallback.hal +$(GEN): $(LOCAL_PATH)/ISoundTriggerHwCallback.hal +$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal +$(GEN): $(LOCAL_PATH)/types.hal +$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) +$(GEN): PRIVATE_CUSTOM_TOOL = \ + $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ + -Ljava -randroid.hardware:hardware/interfaces \ + android.hardware.soundtrigger@2.0::ISoundTriggerHw + +$(GEN): $(LOCAL_PATH)/ISoundTriggerHw.hal + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) + +# +# Build ISoundTriggerHwCallback.hal +# +GEN := $(intermediates)/android/hardware/soundtrigger/2.0/ISoundTriggerHwCallback.java +$(GEN): $(HIDL) +$(GEN): PRIVATE_HIDL := $(HIDL) +$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/ISoundTriggerHwCallback.hal +$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal +$(GEN): $(LOCAL_PATH)/types.hal +$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) +$(GEN): PRIVATE_CUSTOM_TOOL = \ + $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ + -Ljava -randroid.hardware:hardware/interfaces \ + android.hardware.soundtrigger@2.0::ISoundTriggerHwCallback + +$(GEN): $(LOCAL_PATH)/ISoundTriggerHwCallback.hal + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) +include $(BUILD_JAVA_LIBRARY) + + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := android.hardware.soundtrigger@2.0-java-static +LOCAL_MODULE_CLASS := JAVA_LIBRARIES + +intermediates := $(local-generated-sources-dir) + +HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX) + +LOCAL_STATIC_JAVA_LIBRARIES := \ + android.hardware.audio.common@2.0-java-static \ + + +# +# Build types.hal (ConfidenceLevel) +# +GEN := $(intermediates)/android/hardware/soundtrigger/2.0/ConfidenceLevel.java +$(GEN): $(HIDL) +$(GEN): PRIVATE_HIDL := $(HIDL) +$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal +$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) +$(GEN): PRIVATE_CUSTOM_TOOL = \ + $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ + -Ljava -randroid.hardware:hardware/interfaces \ + android.hardware.soundtrigger@2.0::types.ConfidenceLevel + +$(GEN): $(LOCAL_PATH)/types.hal + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) + +# +# Build types.hal (PhraseRecognitionExtra) +# +GEN := $(intermediates)/android/hardware/soundtrigger/2.0/PhraseRecognitionExtra.java +$(GEN): $(HIDL) +$(GEN): PRIVATE_HIDL := $(HIDL) +$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal +$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) +$(GEN): PRIVATE_CUSTOM_TOOL = \ + $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ + -Ljava -randroid.hardware:hardware/interfaces \ + android.hardware.soundtrigger@2.0::types.PhraseRecognitionExtra + +$(GEN): $(LOCAL_PATH)/types.hal + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) + +# +# Build types.hal (RecognitionMode) +# +GEN := $(intermediates)/android/hardware/soundtrigger/2.0/RecognitionMode.java +$(GEN): $(HIDL) +$(GEN): PRIVATE_HIDL := $(HIDL) +$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal +$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) +$(GEN): PRIVATE_CUSTOM_TOOL = \ + $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ + -Ljava -randroid.hardware:hardware/interfaces \ + android.hardware.soundtrigger@2.0::types.RecognitionMode + +$(GEN): $(LOCAL_PATH)/types.hal + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) + +# +# Build types.hal (SoundModelType) +# +GEN := $(intermediates)/android/hardware/soundtrigger/2.0/SoundModelType.java +$(GEN): $(HIDL) +$(GEN): PRIVATE_HIDL := $(HIDL) +$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal +$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) +$(GEN): PRIVATE_CUSTOM_TOOL = \ + $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ + -Ljava -randroid.hardware:hardware/interfaces \ + android.hardware.soundtrigger@2.0::types.SoundModelType + +$(GEN): $(LOCAL_PATH)/types.hal + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) + +# +# Build ISoundTriggerHw.hal +# +GEN := $(intermediates)/android/hardware/soundtrigger/2.0/ISoundTriggerHw.java +$(GEN): $(HIDL) +$(GEN): PRIVATE_HIDL := $(HIDL) +$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/ISoundTriggerHw.hal +$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/ISoundTriggerHwCallback.hal +$(GEN): $(LOCAL_PATH)/ISoundTriggerHwCallback.hal +$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal +$(GEN): $(LOCAL_PATH)/types.hal +$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) +$(GEN): PRIVATE_CUSTOM_TOOL = \ + $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ + -Ljava -randroid.hardware:hardware/interfaces \ + android.hardware.soundtrigger@2.0::ISoundTriggerHw + +$(GEN): $(LOCAL_PATH)/ISoundTriggerHw.hal + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) + +# +# Build ISoundTriggerHwCallback.hal +# +GEN := $(intermediates)/android/hardware/soundtrigger/2.0/ISoundTriggerHwCallback.java +$(GEN): $(HIDL) +$(GEN): PRIVATE_HIDL := $(HIDL) +$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/ISoundTriggerHwCallback.hal +$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal +$(GEN): $(LOCAL_PATH)/types.hal +$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) +$(GEN): PRIVATE_CUSTOM_TOOL = \ + $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ + -Ljava -randroid.hardware:hardware/interfaces \ + android.hardware.soundtrigger@2.0::ISoundTriggerHwCallback + +$(GEN): $(LOCAL_PATH)/ISoundTriggerHwCallback.hal + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) +include $(BUILD_STATIC_JAVA_LIBRARY) + + + +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/soundtrigger/2.0/ISoundTriggerHw.hal b/soundtrigger/2.0/ISoundTriggerHw.hal new file mode 100644 index 0000000000..a1be85d9b5 --- /dev/null +++ b/soundtrigger/2.0/ISoundTriggerHw.hal @@ -0,0 +1,215 @@ +/* + * Copyright 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. + */ + +package android.hardware.soundtrigger@2.0; + +import android.hardware.audio.common@2.0; + +import ISoundTriggerHwCallback; + +interface ISoundTriggerHw { + + /* + * Sound trigger implementation descriptor read by the framework via + * getProperties(). Used by SoundTrigger service to report to applications + * and manage concurrency and policy. + */ + struct Properties { + /* Implementor name */ + string implementor; + /* Implementation description */ + string description; + /* Implementation version */ + uint32_t version; + /* Unique implementation ID. The UUID must change with each version of + the engine implementation */ + Uuid uuid; + /* Maximum number of concurrent sound models loaded */ + uint32_t maxSoundModels; + /* Maximum number of key phrases */ + uint32_t maxKeyPhrases; + /* Maximum number of concurrent users detected */ + uint32_t maxUsers; + /* All supported modes. e.g RecognitionMode.VOICE_TRIGGER */ + uint32_t recognitionModes; + /* Supports seamless transition from detection to capture */ + bool captureTransition; + /* Maximum buffering capacity in ms if captureTransition is true */ + uint32_t maxBufferMs; + /* Supports capture by other use cases while detection is active */ + bool concurrentCapture; + /* Returns the trigger capture in event */ + bool triggerInEvent; + /* Rated power consumption when detection is active with TDB + * silence/sound/speech ratio */ + uint32_t powerConsumptionMw; + }; + + + /* + * Base sound model descriptor. This struct is the header of a larger block + * passed to loadSoundModel() and contains the binary data of the + * sound model. + */ + struct SoundModel { + /* Model type. e.g. SoundModelType.KEYPHRASE */ + SoundModelType type; + /* Unique sound model ID. */ + Uuid uuid; + /* Unique vendor ID. Identifies the engine the sound model + * was build for */ + Uuid vendorUuid; + /* Opaque data transparent to Android framework */ + vec data; + }; + + /* Key phrase descriptor */ + struct Phrase { + /* Unique keyphrase ID assigned at enrollment time */ + uint32_t id; + /* Recognition modes supported by this key phrase */ + uint32_t recognitionModes; + /* List of users IDs associated with this key phrase */ + vec users; + /* Locale - Java Locale style (e.g. en_US) */ + string locale; + /* Phrase text in UTF-8 format. */ + string text; + }; + + /* + * Specialized sound model for key phrase detection. + * Proprietary representation of key phrases in binary data must match + * information indicated by phrases field + */ + struct PhraseSoundModel { + /* Common part of sound model descriptor */ + SoundModel common; + /* List of descriptors for key phrases supported by this sound model */ + vec phrases; + }; + + /* + * Configuration for sound trigger capture session passed to + * startRecognition() method + */ + struct RecognitionConfig { + /* IO handle that will be used for capture. N/A if captureRequested + * is false */ + AudioIoHandle captureHandle; + /* Input device requested for detection capture */ + AudioDevice captureDevice; + /* Capture and buffer audio for this recognition instance */ + bool captureRequested; + /* Configuration for each key phrase */ + vec phrases; + /* Opaque capture configuration data transparent to the framework */ + vec data; + }; + + + /* + * Retrieve implementation properties. + * @return retval Operation completion status: 0 in case of success, + * -ENODEV in case of initialization error. + * @return properties A Properties structure containing implementation + * description and capabilities. + */ + getProperties() generates (int32_t retval, 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 must handle concurrent recognition requests by + * different users/applications on the same model. + * The implementation returns a unique handle used by other functions + * (unloadSoundModel(), startRecognition(), etc... + * @param soundModel A SoundModel structure describing the sound model to + * load. + * @param callback The callback interface on which the soundmodelCallback() + * method will be called upon completion. + * @param cookie The value of the cookie argument passed to the completion + * callback. This unique context information is assigned and + * used only by the framework. + * @return retval Operation completion status: 0 in case of success, + * -EINVAL in case of invalid sound model (e.g 0 data size), + * -ENOSYS in case of invalid operation (e.g max number of + * models exceeded), + * -ENOMEM in case of memory allocation failure, + * -ENODEV in case of initialization error. + * @return modelHandle A unique handle assigned by the HAL for use by the + * framework when controlling activity for this sound model. + */ + loadSoundModel(SoundModel soundModel, + ISoundTriggerHwCallback callback, + CallbackCookie cookie) + generates (int32_t retval, SoundModelHandle modelHandle); + + /* + * Unload a sound model. A sound model may be unloaded to make room for a + * new one to overcome implementation limitations. + * @param modelHandle the handle of the sound model to unload + * @return retval Operation completion status: 0 in case of success, + * -ENOSYS if the model is not loaded, + * -ENODEV in case of initialization error. + */ + unloadSoundModel(SoundModelHandle modelHandle) + generates (int32_t retval); + + /* + * Start recognition on a given model. Only one recognition active + * at a time per model. Once recognition succeeds of fails, the callback + * is called. + * @param modelHandle the handle of the sound model to use for recognition + * @param config A RecognitionConfig structure containing attributes of the + * recognition to perform + * @param callback The callback interface on which the recognitionCallback() + * method must be called upon recognition. + * @param cookie The value of the cookie argument passed to the recognition + * callback. This unique context information is assigned and + * used only by the framework. + * @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(SoundModelHandle modelHandle, + RecognitionConfig config, + ISoundTriggerHwCallback callback, + CallbackCookie cookie) + generates (int32_t retval); + + /* + * Stop recognition on a given model. + * The implementation must not call the recognition callback when stopped + * via this method. + * @param modelHandle The handle of the sound model to use for recognition + * @return retval Operation completion status: 0 in case of success, + * -ENOSYS in case of invalid model handle, + * -ENODEV in case of initialization error. + */ + stopRecognition(SoundModelHandle modelHandle) + generates (int32_t retval); + + /* + * Stop recognition on all models. + * @return retval Operation completion status: 0 in case of success, + * -ENODEV in case of initialization error. + */ + stopAllRecognitions() + generates (int32_t retval); +}; diff --git a/soundtrigger/2.0/ISoundTriggerHwCallback.hal b/soundtrigger/2.0/ISoundTriggerHwCallback.hal new file mode 100644 index 0000000000..294d45159d --- /dev/null +++ b/soundtrigger/2.0/ISoundTriggerHwCallback.hal @@ -0,0 +1,103 @@ +/* + * Copyright 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. + */ + +package android.hardware.soundtrigger@2.0; + +import android.hardware.audio.common@2.0; + +interface ISoundTriggerHwCallback { + enum RecognitionStatus : uint32_t { + SUCCESS = 0, + ABORT = 1, + FAILURE = 2, + }; + + enum SoundModelStatus : uint32_t { + UPDATED = 0, + }; + + /* + * Generic recognition event sent via recognition callback + */ + struct RecognitionEvent { + /* Recognition status e.g. SUCCESS */ + RecognitionStatus status; + /* Sound model type for this event. e.g SoundModelType.TYPE_KEYPHRASE */ + SoundModelType type; + /* Handle of loaded sound model which triggered the event */ + SoundModelHandle model; + /* It is possible to capture audio from this */ + /* utterance buffered by the implementation */ + bool captureAvailable; + /* Audio session ID. framework use */ + int32_t captureSession; + /* Delay in ms between end of model detection and start of audio + /* available for capture. A negative value is possible + * (e.g. if key phrase is also available for capture */ + int32_t captureDelayMs; + /* Duration in ms of audio captured before the start of the trigger. + * 0 if none. */ + int32_t capturePreambleMs; + /* The opaque data is the capture of the trigger sound */ + bool triggerInData; + /* Audio format of either the trigger in event data or to use for + * capture of the rest of the utterance */ + AudioConfig audioConfig; + /* Opaque event data */ + vec data; + }; + + /* + * Specialized recognition event for key phrase recognitions + */ + struct PhraseRecognitionEvent { + /* Common part of the recognition event */ + RecognitionEvent common; + /* List of descriptors for each recognized key phrase */ + vec phraseExtras; + }; + + /* + * Event sent via load sound model callback + */ + struct ModelEvent { + /* Sound model status e.g. SoundModelStatus.UPDATED */ + SoundModelStatus status; + /* Loaded sound model that triggered the event */ + SoundModelHandle model; + /* Opaque event data, passed transparently by the framework */ + vec data; + }; + + typedef int32_t CallbackCookie; + + /* + * Callback method called by the HAL when the sound recognition triggers + * @param event A RecognitionEvent structure containing detailed results + * of the recognition triggered + * @param cookie The cookie passed by the framework when recognition was + * started (see ISoundtriggerHw.startRecognition() + */ + recognitionCallback(RecognitionEvent event, CallbackCookie cookie); + /* + * Callback method called by the HAL when the sound model loading completes + * @param event A ModelEvent structure containing detailed results of the + * model loading operation + * @param cookie The cookie passed by the framework when loading was + * initiated (see ISoundtriggerHw.loadSoundModel() + */ + soundModelCallback(ModelEvent event, CallbackCookie cookie); +}; diff --git a/soundtrigger/2.0/types.hal b/soundtrigger/2.0/types.hal new file mode 100644 index 0000000000..059ab3266c --- /dev/null +++ b/soundtrigger/2.0/types.hal @@ -0,0 +1,75 @@ +/* + * Copyright 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. + */ + +package android.hardware.soundtrigger@2.0; + +/* + * Sound model types modes used in ISoundTriggerHw.SoundModel + */ +enum SoundModelType : int32_t { + /* use for unspecified sound model type */ + UNKNOWN = -1, + /* use for key phrase sound models */ + KEYPHRASE = 0, + /* use for all models other than keyphrase */ + GENERIC = 1, +}; + +typedef int32_t SoundModelHandle; + + +/* + * Recognition modes used in ISoundTriggerHw.RecognitionConfig, + * ISoundTriggerHw.Properties or PhraseRecognitionExtra + */ +enum RecognitionMode : uint32_t { + /* simple voice trigger */ + VOICE_TRIGGER = (1 << 0), + /* trigger only if one user in model identified */ + USER_IDENTIFICATION = (1 << 1), + /* trigger only if one user in mode authenticated */ + USER_AUTHENTICATION = (1 << 2), + /* generic sound trigger */ + GENERIC_TRIGGER = (1 << 3), +}; + +/* + * Confidence level for each user in structure PhraseRecognitionExtra + */ +struct ConfidenceLevel { + /* user ID */ + uint32_t userId; + /* confidence level in percent (0 - 100): */ + /* - min level for recognition configuration */ + /* - detected level for recognition event */ + uint32_t levelPercent; +}; + +/* + * Specialized recognition event for key phrase detection + */ +struct PhraseRecognitionExtra { + /* keyphrase ID */ + uint32_t id; + /* recognition modes used for this keyphrase */ + uint32_t recognitionModes; + /* confidence level for mode RecognitionMode.VOICE_TRIGGER */ + uint32_t confidenceLevel; + /* list of confidence levels per user for + * RecognitionMode.USER_IDENTIFICATION and + * RecognitionMode.USER_AUTHENTICATION */ + vec levels; +};