1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef HEADSET_WAKEUP_WRAPPER_H
16 #define HEADSET_WAKEUP_WRAPPER_H
17 
18 #include <string>
19 #include <mutex>
20 
21 #include "i_headset_wakeup.h"
22 
23 namespace OHOS {
24 namespace IntellVoiceEngine {
25 using GetHeadsetWakeupInstFunc = IHeadsetWakeup *(*)();
26 
27 struct HeadsetWakeupManagerPriv {
28     void *handle { nullptr };
29     GetHeadsetWakeupInstFunc getHeadsetWakeupInst { nullptr };
30 };
31 
32 class HeadsetWakeupWrapper {
33 public:
34     HeadsetWakeupWrapper();
35     ~HeadsetWakeupWrapper();
36 
37     int32_t ReadHeadsetStream(std::vector<uint8_t> &audioStream, bool &hasAwakeWord);
38     int32_t NotifyVerifyResult(bool result);
39     int32_t StopReadingStream();
40     int32_t GetHeadsetAwakeState();
41 
42 private:
43     int32_t LoadHeadsetLib();
44     void UnloadHeadsetLib();
45 
46 private:
47     std::mutex mutex_ {};
48     HeadsetWakeupManagerPriv headsetWakeupPriv_;
49     IHeadsetWakeup *inst_ = nullptr;
50 };
51 }
52 }
53 #endif