SoundTrigger.h revision b7a11d83f749ad0200778c4815e907d011d4b5d3
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 <soundtrigger/SoundTriggerCallback.h> 22#include <soundtrigger/ISoundTrigger.h> 23#include <soundtrigger/ISoundTriggerHwService.h> 24#include <soundtrigger/ISoundTriggerClient.h> 25#include <system/sound_trigger.h> 26 27namespace android { 28 29class MemoryDealer; 30 31class SoundTrigger : public BnSoundTriggerClient, 32 public IBinder::DeathRecipient 33{ 34public: 35 static status_t listModules(struct sound_trigger_module_descriptor *modules, 36 uint32_t *numModules); 37 static sp<SoundTrigger> attach(const sound_trigger_module_handle_t module, 38 const sp<SoundTriggerCallback>& callback); 39 40 virtual ~SoundTrigger(); 41 42 void detach(); 43 44 status_t loadSoundModel(const sp<IMemory>& modelMemory, 45 sound_model_handle_t *handle); 46 47 status_t unloadSoundModel(sound_model_handle_t handle); 48 49 status_t startRecognition(sound_model_handle_t handle, const sp<IMemory>& dataMemory); 50 status_t stopRecognition(sound_model_handle_t handle); 51 52 // BpSoundTriggerClient 53 virtual void onRecognitionEvent(const sp<IMemory>& eventMemory); 54 55 //IBinder::DeathRecipient 56 virtual void binderDied(const wp<IBinder>& who); 57 58 static status_t stringToGuid(const char *str, sound_trigger_uuid_t *guid); 59 static status_t guidToString(const sound_trigger_uuid_t *guid, 60 char *str, size_t maxLen); 61 62private: 63 SoundTrigger(sound_trigger_module_handle_t module, 64 const sp<SoundTriggerCallback>&); 65 static const sp<ISoundTriggerHwService>& getSoundTriggerHwService(); 66 67 Mutex mLock; 68 sp<ISoundTrigger> mISoundTrigger; 69 const sound_trigger_module_handle_t mModule; 70 sp<SoundTriggerCallback> mCallback; 71}; 72 73}; // namespace android 74 75#endif //ANDROID_HARDWARE_SOUNDTRIGGER_H 76