Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 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 | |
| 17 | #ifndef ANDROID_HARDWARE_SOUNDTRIGGER_H |
| 18 | #define ANDROID_HARDWARE_SOUNDTRIGGER_H |
| 19 | |
| 20 | #include <binder/IBinder.h> |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 21 | #include <utils/threads.h> |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 22 | #include <soundtrigger/SoundTriggerCallback.h> |
| 23 | #include <soundtrigger/ISoundTrigger.h> |
| 24 | #include <soundtrigger/ISoundTriggerHwService.h> |
| 25 | #include <soundtrigger/ISoundTriggerClient.h> |
| 26 | #include <system/sound_trigger.h> |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | class MemoryDealer; |
| 31 | |
| 32 | class SoundTrigger : public BnSoundTriggerClient, |
| 33 | public IBinder::DeathRecipient |
| 34 | { |
| 35 | public: |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 36 | |
| 37 | virtual ~SoundTrigger(); |
| 38 | |
jiabin | 68e0df7 | 2019-03-18 17:55:35 -0700 | [diff] [blame] | 39 | static status_t listModules(const String16& opPackageName, |
| 40 | struct sound_trigger_module_descriptor *modules, |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 41 | uint32_t *numModules); |
jiabin | 68e0df7 | 2019-03-18 17:55:35 -0700 | [diff] [blame] | 42 | static sp<SoundTrigger> attach(const String16& opPackageName, |
| 43 | const sound_trigger_module_handle_t module, |
| 44 | const sp<SoundTriggerCallback>& callback); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 45 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 46 | static status_t setCaptureState(bool active); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 47 | |
| 48 | void detach(); |
| 49 | |
| 50 | status_t loadSoundModel(const sp<IMemory>& modelMemory, |
| 51 | sound_model_handle_t *handle); |
| 52 | |
| 53 | status_t unloadSoundModel(sound_model_handle_t handle); |
| 54 | |
| 55 | status_t startRecognition(sound_model_handle_t handle, const sp<IMemory>& dataMemory); |
| 56 | status_t stopRecognition(sound_model_handle_t handle); |
mike dooley | 6e189b1 | 2018-11-07 15:44:37 +0100 | [diff] [blame] | 57 | status_t getModelState(sound_model_handle_t handle); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 58 | |
| 59 | // BpSoundTriggerClient |
| 60 | virtual void onRecognitionEvent(const sp<IMemory>& eventMemory); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 61 | virtual void onSoundModelEvent(const sp<IMemory>& eventMemory); |
| 62 | virtual void onServiceStateChange(const sp<IMemory>& eventMemory); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 63 | |
| 64 | //IBinder::DeathRecipient |
| 65 | virtual void binderDied(const wp<IBinder>& who); |
| 66 | |
| 67 | static status_t stringToGuid(const char *str, sound_trigger_uuid_t *guid); |
| 68 | static status_t guidToString(const sound_trigger_uuid_t *guid, |
| 69 | char *str, size_t maxLen); |
| 70 | |
| 71 | private: |
| 72 | SoundTrigger(sound_trigger_module_handle_t module, |
| 73 | const sp<SoundTriggerCallback>&); |
Eric Laurent | 3769871 | 2016-09-07 16:58:39 -0700 | [diff] [blame] | 74 | static const sp<ISoundTriggerHwService> getSoundTriggerHwService(); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 75 | |
| 76 | Mutex mLock; |
| 77 | sp<ISoundTrigger> mISoundTrigger; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 78 | sp<SoundTriggerCallback> mCallback; |
| 79 | }; |
| 80 | |
| 81 | }; // namespace android |
| 82 | |
| 83 | #endif //ANDROID_HARDWARE_SOUNDTRIGGER_H |