SoundTrigger.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  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. #ifndef ANDROID_HARDWARE_SOUNDTRIGGER_H
  17. #define ANDROID_HARDWARE_SOUNDTRIGGER_H
  18. #include <binder/IBinder.h>
  19. #include <utils/threads.h>
  20. #include <soundtrigger/SoundTriggerCallback.h>
  21. #include <soundtrigger/ISoundTrigger.h>
  22. #include <soundtrigger/ISoundTriggerHwService.h>
  23. #include <soundtrigger/ISoundTriggerClient.h>
  24. #include <system/sound_trigger.h>
  25. namespace android {
  26. class MemoryDealer;
  27. class SoundTrigger : public BnSoundTriggerClient,
  28. public IBinder::DeathRecipient
  29. {
  30. public:
  31. virtual ~SoundTrigger();
  32. static status_t listModules(const String16& opPackageName,
  33. struct sound_trigger_module_descriptor *modules,
  34. uint32_t *numModules);
  35. static sp<SoundTrigger> attach(const String16& opPackageName,
  36. const sound_trigger_module_handle_t module,
  37. const sp<SoundTriggerCallback>& callback);
  38. static status_t setCaptureState(bool active);
  39. void detach();
  40. status_t loadSoundModel(const sp<IMemory>& modelMemory,
  41. sound_model_handle_t *handle);
  42. status_t unloadSoundModel(sound_model_handle_t handle);
  43. status_t startRecognition(sound_model_handle_t handle, const sp<IMemory>& dataMemory);
  44. status_t stopRecognition(sound_model_handle_t handle);
  45. status_t getModelState(sound_model_handle_t handle);
  46. // BpSoundTriggerClient
  47. virtual void onRecognitionEvent(const sp<IMemory>& eventMemory);
  48. virtual void onSoundModelEvent(const sp<IMemory>& eventMemory);
  49. virtual void onServiceStateChange(const sp<IMemory>& eventMemory);
  50. //IBinder::DeathRecipient
  51. virtual void binderDied(const wp<IBinder>& who);
  52. static status_t stringToGuid(const char *str, sound_trigger_uuid_t *guid);
  53. static status_t guidToString(const sound_trigger_uuid_t *guid,
  54. char *str, size_t maxLen);
  55. private:
  56. SoundTrigger(sound_trigger_module_handle_t module,
  57. const sp<SoundTriggerCallback>&);
  58. static const sp<ISoundTriggerHwService> getSoundTriggerHwService();
  59. Mutex mLock;
  60. sp<ISoundTrigger> mISoundTrigger;
  61. sp<SoundTriggerCallback> mCallback;
  62. };
  63. }; // namespace android
  64. #endif //ANDROID_HARDWARE_SOUNDTRIGGER_H