• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
24 namespace android {
25 
26 class SoundTriggerHalInterface : public virtual RefBase
27 {
28 public:
29         /* get a sound trigger HAL instance */
30         static sp<SoundTriggerHalInterface> connectModule(const char *moduleName);
31 
~SoundTriggerHalInterface()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 
74         /* Get the current state of a given model.
75          * 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.
78          * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_2 or above.
79          */
80         virtual int getModelState(sound_model_handle_t handle) = 0;
81 
82 protected:
SoundTriggerHalInterface()83         SoundTriggerHalInterface() {}
84 };
85 
86 } // namespace android
87 
88 #endif // ANDROID_HARDWARE_SOUNDTRIGGER_HAL_INTERFACE_H
89