blob: ccc61dcebaffe793bc3ff8d138947b8941cc2cb3 [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
jiabin68e0df72019-03-18 17:55:35 -070039 static status_t listModules(const String16& opPackageName,
40 struct sound_trigger_module_descriptor *modules,
Eric Laurentb7a11d82014-04-18 17:40:41 -070041 uint32_t *numModules);
jiabin68e0df72019-03-18 17:55:35 -070042 static sp<SoundTrigger> attach(const String16& opPackageName,
43 const sound_trigger_module_handle_t module,
44 const sp<SoundTriggerCallback>& callback);
Eric Laurentb7a11d82014-04-18 17:40:41 -070045
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070046 static status_t setCaptureState(bool active);
Eric Laurentb7a11d82014-04-18 17:40:41 -070047
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 dooley6e189b12018-11-07 15:44:37 +010057 status_t getModelState(sound_model_handle_t handle);
Eric Laurentb7a11d82014-04-18 17:40:41 -070058
59 // BpSoundTriggerClient
60 virtual void onRecognitionEvent(const sp<IMemory>& eventMemory);
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070061 virtual void onSoundModelEvent(const sp<IMemory>& eventMemory);
62 virtual void onServiceStateChange(const sp<IMemory>& eventMemory);
Eric Laurentb7a11d82014-04-18 17:40:41 -070063
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
71private:
72 SoundTrigger(sound_trigger_module_handle_t module,
73 const sp<SoundTriggerCallback>&);
Eric Laurent37698712016-09-07 16:58:39 -070074 static const sp<ISoundTriggerHwService> getSoundTriggerHwService();
Eric Laurentb7a11d82014-04-18 17:40:41 -070075
76 Mutex mLock;
77 sp<ISoundTrigger> mISoundTrigger;
Eric Laurentb7a11d82014-04-18 17:40:41 -070078 sp<SoundTriggerCallback> mCallback;
79};
80
81}; // namespace android
82
83#endif //ANDROID_HARDWARE_SOUNDTRIGGER_H