blob: 99346ef7890cb8552e412e9024bc41adb3240447 [file] [log] [blame]
Eric Laurent46bbe8a2014-04-15 10:54:24 -07001/*
2 * Copyright (C) 2014 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#include <system/audio.h>
18#include <system/sound_trigger.h>
19#include <hardware/hardware.h>
20
21#ifndef ANDROID_SOUND_TRIGGER_HAL_H
22#define ANDROID_SOUND_TRIGGER_HAL_H
23
24
25__BEGIN_DECLS
26
27/**
28 * The id of this module
29 */
30#define SOUND_TRIGGER_HARDWARE_MODULE_ID "sound_trigger"
31
32/**
33 * Name of the audio devices to open
34 */
35#define SOUND_TRIGGER_HARDWARE_INTERFACE "sound_trigger_hw_if"
36
37#define SOUND_TRIGGER_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
38#define SOUND_TRIGGER_MODULE_API_VERSION_CURRENT SOUND_TRIGGER_MODULE_API_VERSION_1_0
39
40
41#define SOUND_TRIGGER_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
Chris Thornton0a965102016-03-30 11:25:11 -070042#define SOUND_TRIGGER_DEVICE_API_VERSION_1_1 HARDWARE_DEVICE_API_VERSION(1, 1)
Michael Dooleyc2704a52018-10-16 19:55:18 +000043#define SOUND_TRIGGER_DEVICE_API_VERSION_1_2 HARDWARE_DEVICE_API_VERSION(1, 2)
44#define SOUND_TRIGGER_DEVICE_API_VERSION_CURRENT SOUND_TRIGGER_DEVICE_API_VERSION_1_2
Eric Laurent46bbe8a2014-04-15 10:54:24 -070045
46/**
47 * List of known sound trigger HAL modules. This is the base name of the sound_trigger HAL
48 * library composed of the "sound_trigger." prefix, one of the base names below and
49 * a suffix specific to the device.
50 * e.g: sondtrigger.primary.goldfish.so or sound_trigger.primary.default.so
51 */
52
53#define SOUND_TRIGGER_HARDWARE_MODULE_ID_PRIMARY "primary"
54
55
56/**
57 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
58 * and the fields of this data structure must begin with hw_module_t
59 * followed by module specific information.
60 */
61struct sound_trigger_module {
62 struct hw_module_t common;
63};
64
65typedef void (*recognition_callback_t)(struct sound_trigger_recognition_event *event, void *cookie);
66typedef void (*sound_model_callback_t)(struct sound_trigger_model_event *event, void *cookie);
67
68struct sound_trigger_hw_device {
69 struct hw_device_t common;
70
71 /*
72 * Retrieve implementation properties.
73 */
74 int (*get_properties)(const struct sound_trigger_hw_device *dev,
75 struct sound_trigger_properties *properties);
76
77 /*
78 * Load a sound model. Once loaded, recognition of this model can be started and stopped.
79 * Only one active recognition per model at a time. The SoundTrigger service will handle
80 * concurrent recognition requests by different users/applications on the same model.
81 * The implementation returns a unique handle used by other functions (unload_sound_model(),
82 * start_recognition(), etc...
83 */
84 int (*load_sound_model)(const struct sound_trigger_hw_device *dev,
85 struct sound_trigger_sound_model *sound_model,
86 sound_model_callback_t callback,
87 void *cookie,
88 sound_model_handle_t *handle);
89
90 /*
91 * Unload a sound model. A sound model can be unloaded to make room for a new one to overcome
92 * implementation limitations.
93 */
94 int (*unload_sound_model)(const struct sound_trigger_hw_device *dev,
95 sound_model_handle_t handle);
96
97 /* Start recognition on a given model. Only one recognition active at a time per model.
98 * Once recognition succeeds of fails, the callback is called.
99 * TODO: group recognition configuration parameters into one struct and add key phrase options.
100 */
101 int (*start_recognition)(const struct sound_trigger_hw_device *dev,
102 sound_model_handle_t sound_model_handle,
Eric Laurent30f3e6d2014-07-06 16:08:45 -0700103 const struct sound_trigger_recognition_config *config,
Eric Laurent46bbe8a2014-04-15 10:54:24 -0700104 recognition_callback_t callback,
Eric Laurent30f3e6d2014-07-06 16:08:45 -0700105 void *cookie);
Eric Laurent46bbe8a2014-04-15 10:54:24 -0700106
107 /* Stop recognition on a given model.
108 * The implementation does not have to call the callback when stopped via this method.
109 */
110 int (*stop_recognition)(const struct sound_trigger_hw_device *dev,
Chris Thornton42a448d2016-03-27 17:12:30 -0700111 sound_model_handle_t sound_model_handle);
112
113 /* Stop recognition on all models.
Chris Thornton0a965102016-03-30 11:25:11 -0700114 * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_1 or above.
Chris Thornton42a448d2016-03-27 17:12:30 -0700115 * If no implementation is provided, stop_recognition will be called for each running model.
116 */
117 int (*stop_all_recognitions)(const struct sound_trigger_hw_device* dev);
Michael Dooleyc2704a52018-10-16 19:55:18 +0000118
119 /* Get the current state of a given model.
mike dooley737f4ce2018-11-07 15:53:25 +0100120 * The state will be returned as a recognition event, via the callback that was registered
121 * in the start_recognition method.
Michael Dooleyc2704a52018-10-16 19:55:18 +0000122 * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_2 or above.
123 */
mike dooley737f4ce2018-11-07 15:53:25 +0100124 int (*get_model_state)(const struct sound_trigger_hw_device *dev,
125 sound_model_handle_t sound_model_handle);
Eric Laurent46bbe8a2014-04-15 10:54:24 -0700126};
127
128typedef struct sound_trigger_hw_device sound_trigger_hw_device_t;
129
130/** convenience API for opening and closing a supported device */
131
132static inline int sound_trigger_hw_device_open(const struct hw_module_t* module,
133 struct sound_trigger_hw_device** device)
134{
135 return module->methods->open(module, SOUND_TRIGGER_HARDWARE_INTERFACE,
Colin Crosscc8d9f92016-10-06 16:44:23 -0700136 TO_HW_DEVICE_T_OPEN(device));
Eric Laurent46bbe8a2014-04-15 10:54:24 -0700137}
138
139static inline int sound_trigger_hw_device_close(struct sound_trigger_hw_device* device)
140{
141 return device->common.close(&device->common);
142}
143
144__END_DECLS
145
146#endif // ANDROID_SOUND_TRIGGER_HAL_H