SoundTriggerHalInterface.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #ifndef ANDROID_HARDWARE_SOUNDTRIGGER_HAL_INTERFACE_H
  17. #define ANDROID_HARDWARE_SOUNDTRIGGER_HAL_INTERFACE_H
  18. #include <utils/RefBase.h>
  19. #include <system/sound_trigger.h>
  20. #include <hardware/sound_trigger.h>
  21. namespace android {
  22. class SoundTriggerHalInterface : public virtual RefBase
  23. {
  24. public:
  25. /* get a sound trigger HAL instance */
  26. static sp<SoundTriggerHalInterface> connectModule(const char *moduleName);
  27. virtual ~SoundTriggerHalInterface() {}
  28. virtual int getProperties(struct sound_trigger_properties *properties) = 0;
  29. /*
  30. * Load a sound model. Once loaded, recognition of this model can be started and stopped.
  31. * Only one active recognition per model at a time. The SoundTrigger service will handle
  32. * concurrent recognition requests by different users/applications on the same model.
  33. * The implementation returns a unique handle used by other functions (unload_sound_model(),
  34. * start_recognition(), etc...
  35. */
  36. virtual int loadSoundModel(struct sound_trigger_sound_model *sound_model,
  37. sound_model_callback_t callback,
  38. void *cookie,
  39. sound_model_handle_t *handle) = 0;
  40. /*
  41. * Unload a sound model. A sound model can be unloaded to make room for a new one to overcome
  42. * implementation limitations.
  43. */
  44. virtual int unloadSoundModel(sound_model_handle_t handle) = 0;
  45. /* Start recognition on a given model. Only one recognition active at a time per model.
  46. * Once recognition succeeds of fails, the callback is called.
  47. * TODO: group recognition configuration parameters into one struct and add key phrase options.
  48. */
  49. virtual int startRecognition(sound_model_handle_t handle,
  50. const struct sound_trigger_recognition_config *config,
  51. recognition_callback_t callback,
  52. void *cookie) = 0;
  53. /* Stop recognition on a given model.
  54. * The implementation does not have to call the callback when stopped via this method.
  55. */
  56. virtual int stopRecognition(sound_model_handle_t handle) = 0;
  57. /* Stop recognition on all models.
  58. * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_1 or above.
  59. * If no implementation is provided, stop_recognition will be called for each running model.
  60. */
  61. virtual int stopAllRecognitions() = 0;
  62. /* Get the current state of a given model.
  63. * Returns 0 or an error code. If successful the state will be returned asynchronously
  64. * via a recognition event in the callback method that was registered in the
  65. * startRecognition() method.
  66. * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_2 or above.
  67. */
  68. virtual int getModelState(sound_model_handle_t handle) = 0;
  69. protected:
  70. SoundTriggerHalInterface() {}
  71. };
  72. } // namespace android
  73. #endif // ANDROID_HARDWARE_SOUNDTRIGGER_HAL_INTERFACE_H