blob: 2e2ff7ad16343336b3625896762d2c2baac44179 [file] [log] [blame]
Eric Laurentb7a11d82014-04-18 17:40:41 -07001/*
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 Laurentdf3dc7e2014-07-27 18:39:40 -070021#include <utils/threads.h>
Eric Laurentb7a11d82014-04-18 17:40:41 -070022#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
28namespace android {
29
30class MemoryDealer;
31
32class SoundTrigger : public BnSoundTriggerClient,
33 public IBinder::DeathRecipient
34{
35public:
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070036
37 virtual ~SoundTrigger();
38
Eric Laurentb7a11d82014-04-18 17:40:41 -070039 static status_t listModules(struct sound_trigger_module_descriptor *modules,
40 uint32_t *numModules);
41 static sp<SoundTrigger> attach(const sound_trigger_module_handle_t module,
42 const sp<SoundTriggerCallback>& callback);
43
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070044 static status_t setCaptureState(bool active);
Eric Laurentb7a11d82014-04-18 17:40:41 -070045
46 void detach();
47
48 status_t loadSoundModel(const sp<IMemory>& modelMemory,
49 sound_model_handle_t *handle);
50
51 status_t unloadSoundModel(sound_model_handle_t handle);
52
53 status_t startRecognition(sound_model_handle_t handle, const sp<IMemory>& dataMemory);
54 status_t stopRecognition(sound_model_handle_t handle);
mike dooley6e189b12018-11-07 15:44:37 +010055 status_t getModelState(sound_model_handle_t handle);
Eric Laurentb7a11d82014-04-18 17:40:41 -070056
57 // BpSoundTriggerClient
58 virtual void onRecognitionEvent(const sp<IMemory>& eventMemory);
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070059 virtual void onSoundModelEvent(const sp<IMemory>& eventMemory);
60 virtual void onServiceStateChange(const sp<IMemory>& eventMemory);
Eric Laurentb7a11d82014-04-18 17:40:41 -070061
62 //IBinder::DeathRecipient
63 virtual void binderDied(const wp<IBinder>& who);
64
65 static status_t stringToGuid(const char *str, sound_trigger_uuid_t *guid);
66 static status_t guidToString(const sound_trigger_uuid_t *guid,
67 char *str, size_t maxLen);
68
69private:
70 SoundTrigger(sound_trigger_module_handle_t module,
71 const sp<SoundTriggerCallback>&);
Eric Laurent37698712016-09-07 16:58:39 -070072 static const sp<ISoundTriggerHwService> getSoundTriggerHwService();
Eric Laurentb7a11d82014-04-18 17:40:41 -070073
74 Mutex mLock;
75 sp<ISoundTrigger> mISoundTrigger;
Eric Laurentb7a11d82014-04-18 17:40:41 -070076 sp<SoundTriggerCallback> mCallback;
77};
78
79}; // namespace android
80
81#endif //ANDROID_HARDWARE_SOUNDTRIGGER_H