• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
GetInstance()37     static HeadsetWakeupWrapper &GetInstance()
38     {
39         static HeadsetWakeupWrapper headsetWakeupWrapper;
40         return headsetWakeupWrapper;
41     }
42 
43     int32_t ReadHeadsetStream(std::vector<uint8_t> &audioStream, bool &hasAwakeWord);
44     int32_t NotifyVerifyResult(bool result);
45     int32_t StopReadingStream();
46     int32_t GetHeadsetAwakeState();
47     void NotifyHeadsetHdfDeath();
48 
49 private:
50     int32_t LoadHeadsetLib();
51     void UnloadHeadsetLib();
52 
53 private:
54     std::mutex mutex_ {};
55     HeadsetWakeupManagerPriv headsetWakeupPriv_;
56     IHeadsetWakeup *inst_ = nullptr;
57 };
58 }
59 }
60 #endif