blob: fd393036d8c7d8788064ff66408ac3d89c538477 [file] [log] [blame]
Ytai Ben-Tsvia2cd51a2021-01-25 16:56:25 -08001/*
2 * Copyright 2021 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
17package android.hardware.soundtrigger@2.4;
18
19import @2.0::SoundModelHandle;
20import @2.1::ISoundTriggerHw.SoundModel;
21import @2.1::ISoundTriggerHw.PhraseSoundModel;
22import @2.3::ISoundTriggerHw;
23import @2.3::RecognitionConfig;
24import ISoundTriggerHwCallback;
25import ISoundTriggerHwGlobalCallback;
26
27/**
28 * SoundTrigger HAL interface. Used for hardware recognition of hotwords
29 * and other sounds.
30 *
31 * Important notes about the threading model:
32 * ==========================================
33 * Both this interface and the corresponding callback interface use a synchronized calling
34 * convention. This model comes with some advantages, but also with some risks of deadlocks if the
35 * implementation does not handle this correctly. Please consider the following:
36 * - After stopRecognition() returns no more recognition events for that model may be sent. This
37 * implies that any queues holding such events must be flushed before the call returns and that
38 * may imply that callback from the HAL to the client are done while stopRecognition() is blocked.
39 * This is OK, and supported by the framework.
40 * - Similarly, the same relationship applies between unloadModel() and subsequent callbacks to
41 * modelUnloaded().
42 * - Other than these two cases, calls into the HAL *MAY NOT* block on callbacks from the HAL, or
43 * else deadlock conditions may result, which may be handled by rebooting of the HAL process and
44 * cause service outages.
45 *
46 * Similarly, it is expected that a single call to startRecognition() generates at most one event
47 * (the model automatically becomes stopped when the event occurs, until explicitly started again)
48 * and that after a modelUnloaded() event no more events would be sent regarding the model.
49 * Note that a getModelState() call may generate a recognition event, but this event DOES NOT modify
50 * the model state - the model remains started.
51 *
52 * The HAL is expected to correctly handle a stopRecognition() call even after it sent an event
53 * indicating that recognition is stopped and an unloadModel() call even after it sent an event
54 * indicating that it has been unloaded. This is required in order to prevent race conditions
55 * between these calls. This also implies that model handles should generally not be reused until
56 * explicitly unloaded. To avoid the rare possibility of running out of handles, the framework will
57 * call unloadModel() on models that have been preemptively unloaded by the HAL.
58 *
59 * Due to the asynchronous nature of recognition events and preemptive model unloading, the HAL must
60 * correctly handle requests that would have been valid before an event has been delivered, but
61 * became moot as result of the event. Namely:
62 * - stopRecognition() may be called on a model that has already delivered an event and became
63 * inactive as a result. The HAL must return a successful return code in this case.
64 * - Furthermore, if a model is preemptively unloaded after it triggers (typically, this would
65 * happen when it is first aborted and immediately preemptively unloaded), stopRecognition() may
66 * be called on it. The HAL must return a successful return code in this case.
67 * - startRecognition() may be called on a model that has been preemptively unloaded. In this case,
68 * the HAL must return -EBUSY to indicate that the operation is temporarily unsuccessful.
69 * - unloadSoundModel() may be called on a model that has been preemptively unloaded. The HAL must
70 * return a successful return code in this case.
71 *
72 * Important notes about resource constraints and concurrency
73 * =========================================================
74 * Up until this version, the framework would enforce concurrency constraints expressed by the
75 * Properties presented by the soundtrigger instance. These include constraints on the maximum
76 * amount of models that can be loaded at the same time and on running recognition while capturing
77 * from the microphone.
78 * This version changes the approach for how these constraints are modeled, both offering the HAL
79 * implementation more flexibility and simplifying the framework's job in enforcing these
80 * limitations. Note that there is no change for how the framework behaves with earlier versions,
81 * everything described below only applies to this version and onward.
82 * The way this is achieved is as following:
83 * - The framework will no longer enforce constraints on concurrent loading of models, as expressed
84 * in the Properties.maxSoundModels field (this property is merely a hint at this point and may be
85 * deprecated in the future.
86 * - The framework will no longer enforce constraints on concurrency of audio recording and
87 * soundtrigger operation, as expressed in the Properties.concurrentCapture field (this property
88 * is merely a hint at this point and may be deprecated in the future).
89 * - The framework will no longer enforce constraints on concurrent loading of models, as expressed
90 * in the Properties (these properties are merely hints at this point and may be deprecated in the
91 * future.
92 * - The HAL implementation is free to reject starting of any model at any time by having the
93 * respective start*() method return -EBUSY.
94 * - The HAL implementation is free to reject loading of any model at any time by having the
95 * respective load*() method return -EBUSY.
96 * - The HAL implementation is free to preemptively stop a previously started model at its own
97 * discretion (for example, if a higher priority use-case which cannot coexist with detection
98 * has been requested). The HAL must notify the framework of the preemption by sending a
99 * recognition event with an `ABORT` status. The implementation must NOT attempt to restart the
100 * recognition automatically when conditions change.
101 * - The HAL implementation is free to preemptively unload a previously loaded model at its own
102 * discretion (for example, if a higher-priority model is being loaded and the two cannot
103 * coexist). When doing so, it must first abort the detection if active (as per above) and then
104 * notify the framework of the unload using the newly added modelUnloaded callback.
105 * - When conditions change, such that a model that couldn't previously load or start or that had
106 * previously been preemptively stopped or unloaded, the HAL must notify the framework via the
107 * newly added tryAgain() callback. This callback is not a guarantee that any operation would now
108 * succeed, but merely a hint that retrying something that had previously failed, now MAY succeed.
109 * Until this callback arrives, the framework may assume that any operation that had previously
110 * failed or aborted would still fail if retried, so the implementation should not forget to
111 * deliver it. There are no guarantees regarding how the framework may respond to this event and
112 * the order in which it may choose to reload/restart its models. Typically, as result of this
113 * event the framework will make a single attempt per model to bring this model to its desired
114 * state (loaded, started).
115 */
116interface ISoundTriggerHw extends @2.3::ISoundTriggerHw {
117 /**
118 * This will get called at most once per every attachment to the service.
119 *
120 * All events not tied to a specific model should go through this callback.
121 */
122 registerGlobalCallback(ISoundTriggerHwGlobalCallback callback);
123
124 /**
125 * Load a sound model. Once loaded, recognition of this model can be
126 * started and stopped.
127 * The implementation returns a unique handle used by other functions
128 * (unloadSoundModel(), startRecognition*(), etc...
129 *
130 * Must have the exact same semantics as loadSoundModel from ISoundTriggerHw@2.3 except that the
131 * return values have changed and that there is no cookie provided (the implementation may pass
132 * any value to the callback, as it is ignored).
133 *
134 * @param soundModel A SoundModel structure describing the sound model
135 * to load.
136 * @param callback The callback interface on which the soundModelCallback*()
137 * method must be called upon completion and modelUnloaded() upon preempted unload.
138 * @return retval Operation completion status: 0 in case of success,
139 * -EBUSY in case the operation is temporarily unavailable (but possible in general).
140 * @return modelHandle A unique handle assigned by the HAL for use by the
141 * framework when controlling activity for this sound model.
142 */
143 loadSoundModel_2_4(SoundModel soundModel, ISoundTriggerHwCallback callback)
144 generates (int32_t retval, SoundModelHandle modelHandle);
145
146 /**
147 * Load a key phrase sound model. Once loaded, recognition of this model can
148 * be started and stopped. Only one active recognition per model at a time.
149 * The SoundTrigger service must handle concurrent recognition requests by
150 * different users/applications on the same model.
151 * The implementation returns a unique handle used by other functions
152 * (unloadSoundModel(), startRecognition*(), etc...
153 *
154 * Must have the exact same semantics as loadPhraseSoundModel from ISoundTriggerHw@2.3 except
155 * that the return values have changed and that there is no cookie provided (the implementation
156 * may pass any value to the callback, as it is ignored).
157 *
158 * @param soundModel A PhraseSoundModel structure describing the sound model
159 * to load.
160 * @param callback The callback interface on which the soundModelCallback*()
161 * method must be called upon completion and modelUnloaded() upon preempted unload.
162 * @return retval Operation completion status: 0 in case of success,
163 * -EBUSY in case the operation is temporarily unavailable (but possible in general).
164 * @return modelHandle A unique handle assigned by the HAL for use by the
165 * framework when controlling activity for this sound model.
166 */
167 loadPhraseSoundModel_2_4(PhraseSoundModel soundModel, ISoundTriggerHwCallback callback)
168 generates (int32_t retval, SoundModelHandle modelHandle);
169
170 /**
171 * Start recognition on a given model. Only one recognition active
172 * at a time per model. Once recognition succeeds or fails, the callback
173 * associated with the model handle is called.
174 *
175 * Must have the exact same semantics as startRecognition from ISoundTriggerHw@2.3 except that
176 * there are different expectations of the return value and that there is no cookie provided
177 * (the implementation may pass any value to the callback, as it is ignored).
178 *
179 * @param modelHandle the handle of the sound model to use for recognition
180 * @param config A RecognitionConfig structure containing attributes of the
181 * recognition to perform
182 * @param callback The callback interface on which the recognitionCallback()
183 * method must be called upon recognition.
184 * @return retval Operation completion status: 0 in case of success,
185 * -EBUSY in case the operation is temporarily unavailable (but possible in general), or in
186 * case model has been preemtively unloaded.
187 */
188 startRecognition_2_4(SoundModelHandle modelHandle, RecognitionConfig config)
189 generates (int32_t retval);
190};