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
28namespace android {
29
30class MemoryDealer;
31
32class SoundTrigger : public BnSoundTriggerClient,
33                        public IBinder::DeathRecipient
34{
35public:
36
37    virtual ~SoundTrigger();
38
39    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
44    static  status_t setCaptureState(bool active);
45
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);
55
56            // BpSoundTriggerClient
57            virtual void onRecognitionEvent(const sp<IMemory>& eventMemory);
58            virtual void onSoundModelEvent(const sp<IMemory>& eventMemory);
59            virtual void onServiceStateChange(const sp<IMemory>& eventMemory);
60
61            //IBinder::DeathRecipient
62            virtual void binderDied(const wp<IBinder>& who);
63
64            static status_t stringToGuid(const char *str, sound_trigger_uuid_t *guid);
65            static status_t guidToString(const sound_trigger_uuid_t *guid,
66                                         char *str, size_t maxLen);
67
68private:
69            SoundTrigger(sound_trigger_module_handle_t module,
70                            const sp<SoundTriggerCallback>&);
71            static const sp<ISoundTriggerHwService> getSoundTriggerHwService();
72
73            Mutex                               mLock;
74            sp<ISoundTrigger>                   mISoundTrigger;
75            const sound_trigger_module_handle_t mModule;
76            sp<SoundTriggerCallback>            mCallback;
77};
78
79}; // namespace android
80
81#endif //ANDROID_HARDWARE_SOUNDTRIGGER_H
82