blob: e1fffff3878a58d336bd5898e6e8be80544e6525 [file] [log] [blame]
Eric Laurent7a544b42016-08-05 19:01:13 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_HARDWARE_SOUNDTRIGGER_HAL_INTERFACE_H
18#define ANDROID_HARDWARE_SOUNDTRIGGER_HAL_INTERFACE_H
19
20#include <utils/RefBase.h>
21#include <system/sound_trigger.h>
22#include <hardware/sound_trigger.h>
23
24namespace android {
25
26class SoundTriggerHalInterface : public virtual RefBase
27{
28public:
29 /* get a sound trigger HAL instance */
30 static sp<SoundTriggerHalInterface> connectModule(const char *moduleName);
31
32 virtual ~SoundTriggerHalInterface() {}
33
34 virtual int getProperties(struct sound_trigger_properties *properties) = 0;
35
36 /*
37 * Load a sound model. Once loaded, recognition of this model can be started and stopped.
38 * Only one active recognition per model at a time. The SoundTrigger service will handle
39 * concurrent recognition requests by different users/applications on the same model.
40 * The implementation returns a unique handle used by other functions (unload_sound_model(),
41 * start_recognition(), etc...
42 */
43 virtual int loadSoundModel(struct sound_trigger_sound_model *sound_model,
44 sound_model_callback_t callback,
45 void *cookie,
46 sound_model_handle_t *handle) = 0;
47
48 /*
49 * Unload a sound model. A sound model can be unloaded to make room for a new one to overcome
50 * implementation limitations.
51 */
52 virtual int unloadSoundModel(sound_model_handle_t handle) = 0;
53
54 /* Start recognition on a given model. Only one recognition active at a time per model.
55 * Once recognition succeeds of fails, the callback is called.
56 * TODO: group recognition configuration parameters into one struct and add key phrase options.
57 */
58 virtual int startRecognition(sound_model_handle_t handle,
59 const struct sound_trigger_recognition_config *config,
60 recognition_callback_t callback,
61 void *cookie) = 0;
62
63 /* Stop recognition on a given model.
64 * The implementation does not have to call the callback when stopped via this method.
65 */
66 virtual int stopRecognition(sound_model_handle_t handle) = 0;
67
68 /* Stop recognition on all models.
69 * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_1 or above.
70 * If no implementation is provided, stop_recognition will be called for each running model.
71 */
72 virtual int stopAllRecognitions() = 0;
73
Michael Dooley67e3d412018-10-16 19:51:16 +000074 /* Get the current state of a given model.
mike dooley6e189b12018-11-07 15:44:37 +010075 * Returns 0 or an error code. If successful the state will be returned asynchronously
76 * via a recognition event in the callback method that was registered in the
77 * startRecognition() method.
Michael Dooley67e3d412018-10-16 19:51:16 +000078 * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_2 or above.
79 */
mike dooley6e189b12018-11-07 15:44:37 +010080 virtual int getModelState(sound_model_handle_t handle) = 0;
Michael Dooley67e3d412018-10-16 19:51:16 +000081
Nicholas Ambur41947e22019-10-01 11:53:40 -070082 /* Set a model specific ModelParameter with the given value. This parameter
83 * will keep its value for the duration the model is loaded regardless of starting and stopping
84 * recognition. Once the model is unloaded, the value will be lost.
85 * Returns 0 or an error code.
86 * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_3 or above.
87 */
88 virtual int setParameter(sound_model_handle_t handle,
89 sound_trigger_model_parameter_t model_param, int32_t value) = 0;
90
91 /* Get a model specific ModelParameter. This parameter will keep its value
92 * for the duration the model is loaded regardless of starting and stopping recognition.
93 * Once the model is unloaded, the value will be lost. If the value is not set, a default
94 * value is returned. See sound_trigger_model_parameter_t for parameter default values.
95 * Returns 0 or an error code. On return 0, value pointer will be set.
96 * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_3 or above.
97 */
98 virtual int getParameter(sound_model_handle_t sound_model_handle,
99 sound_trigger_model_parameter_t model_param, int32_t* value) = 0;
100
101 /* Get supported parameter attributes with respect to the provided model
102 * handle. Along with determining the valid range, this API is also used
103 * to determine if a given parameter ID is supported at all by the
104 * modelHandle for use with getParameter and setParameter APIs.
105 */
106 virtual int queryParameter(sound_model_handle_t sound_model_handle,
107 sound_trigger_model_parameter_t model_param,
108 sound_trigger_model_parameter_range_t* param_range) = 0;
109
Eric Laurent7a544b42016-08-05 19:01:13 -0700110protected:
111 SoundTriggerHalInterface() {}
112};
113
114} // namespace android
115
116#endif // ANDROID_HARDWARE_SOUNDTRIGGER_HAL_INTERFACE_H