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> 21 #include <utils/threads.h> 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: 36 37 virtual ~SoundTrigger(); 38 39 static status_t listModules(const String16& opPackageName, 40 struct sound_trigger_module_descriptor *modules, 41 uint32_t *numModules); 42 static sp<SoundTrigger> attach(const String16& opPackageName, 43 const sound_trigger_module_handle_t module, 44 const sp<SoundTriggerCallback>& callback); 45 46 static status_t setCaptureState(bool active); 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); 57 status_t getModelState(sound_model_handle_t handle); 58 59 // BpSoundTriggerClient 60 virtual void onRecognitionEvent(const sp<IMemory>& eventMemory); 61 virtual void onSoundModelEvent(const sp<IMemory>& eventMemory); 62 virtual void onServiceStateChange(const sp<IMemory>& eventMemory); 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>&); 74 static const sp<ISoundTriggerHwService> getSoundTriggerHwService(); 75 76 Mutex mLock; 77 sp<ISoundTrigger> mISoundTrigger; 78 sp<SoundTriggerCallback> mCallback; 79 }; 80 81 }; // namespace android 82 83 #endif //ANDROID_HARDWARE_SOUNDTRIGGER_H 84