• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 WAKEUP_ENGINE_H
16 #define WAKEUP_ENGINE_H
17 
18 #include <string>
19 #include "base_macros.h"
20 #include "engine_base.h"
21 #include "wakeup_engine_impl.h"
22 #include "headset_wakeup_engine_impl.h"
23 
24 namespace OHOS {
25 namespace IntellVoiceEngine {
26 enum DetectDeviceType {
27     DETECT_TYPE_PHONE = 0,
28     DETECT_TYPE_HEADSET,
29     DETECT_TYPE_BUT
30 };
31 
32 class WakeupEngine : public EngineBase {
33 public:
34     WakeupEngine();
35     ~WakeupEngine();
36     bool Init(const std::string &param, bool reEnroll = false) override;
37     void SetCallback(sptr<IRemoteObject> object) override;
38     int32_t Attach(const IntellVoiceEngineInfo &info) override;
39     int32_t Detach(void) override;
40     int32_t Start(bool isLast) override;
41     int32_t SetParameter(const std::string &keyValueList) override;
42     std::string GetParameter(const std::string &key) override;
43     int32_t Stop() override;
44     int32_t GetWakeupPcm(std::vector<uint8_t> &data) override;
45 
46     void OnDetected(int32_t uuid) override;
47     bool ResetAdapter() override;
48     void ReleaseAdapter() override;
49 
50     int32_t StartCapturer(int32_t channels) override;
51     int32_t Read(std::vector<uint8_t> &data) override;
52     int32_t StopCapturer() override;
53     int32_t NotifyHeadsetWakeEvent() override;
54     int32_t NotifyHeadsetHostEvent(HeadsetHostEventType event) override;
55 
56 private:
57     static std::string GetEventValue(int32_t uuid);
58     int32_t HandleHeadsetOff();
59     int32_t HandleHeadsetOn();
60     int32_t HandleCapturerMsg(StateMsg &msg);
61     static void StartAbility(const std::string &event);
62     USE_ROLE(WakeupEngineImpl);
63 
64 private:
65     OHOS::IntellVoiceUtils::UniqueProductType<HeadsetWakeupEngineImpl> headsetImpl_ =
66         OHOS::IntellVoiceUtils::UniqueProductType<HeadsetWakeupEngineImpl>(nullptr, nullptr);
67     std::mutex headsetMutex_;
68     sptr<IIntelligentVoiceEngineCallback> callback_ = nullptr;
69     std::atomic<DetectDeviceType> detectDeviceType_ = DETECT_TYPE_PHONE;
70 };
71 }
72 }
73 #endif