• 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 
16 #ifndef ST_AUDIO_PNP_SERVER_H
17 #define ST_AUDIO_PNP_SERVER_H
18 
19 #include <functional>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 #include <thread>
24 
25 #include "hdf_types.h"
26 #include "audio_info.h"
27 #include "audio_pnp_param.h"
28 
29 namespace OHOS {
30 namespace AudioStandard {
31 using namespace std;
32 class MicrophoneBlocked;
33 
34 class AudioPnpServer {
35 public:
GetAudioPnpServer()36     static AudioPnpServer& GetAudioPnpServer()
37     {
38         static AudioPnpServer audioPnpServer;
39         return audioPnpServer;
40     }
41     ~AudioPnpServer();
42     bool init(void);
43     int32_t RegisterPnpStatusListener(std::shared_ptr<AudioPnpDeviceChangeCallback> callback);
44     int32_t UnRegisterPnpStatusListener();
45     void OnPnpDeviceStatusChanged(const std::string &info);
46     void StopPnpServer();
47     friend class MicrophoneBlocked;
48     void OnMicrophoneBlocked(const std::string &info, AudioPnpServer &audioPnpServer);
49 
50 private:
51     std::string eventInfo_;
52     std::mutex pnpMutex_;
53     std::shared_ptr<AudioPnpDeviceChangeCallback> pnpCallback_ = nullptr;
54     std::unique_ptr<std::thread> socketThread_ = nullptr;
55     std::unique_ptr<std::thread> inputThread_ = nullptr;
56     void OpenAndReadWithSocket();
57     void OpenAndReadInput();
58     void DetectAudioDevice();
59     void DetectAudioDpDevice();
60 };
61 
62 class MicrophoneBlocked {
63 public:
GetInstance()64     static MicrophoneBlocked &GetInstance()
65     {
66         static MicrophoneBlocked instance_;
67         return instance_;
68     }
MicrophoneBlocked()69     MicrophoneBlocked() {}
~MicrophoneBlocked()70     ~MicrophoneBlocked() {}
71     void OnMicrophoneBlocked(const std::string &info, AudioPnpServer &audioPnpServer);
72 };
73 
74 enum PnpEventType {
75     PNP_EVENT_DEVICE_ADD = 1,
76     PNP_EVENT_DEVICE_REMOVE = 2,
77     PNP_EVENT_LOAD_SUCCESS = 3,
78     PNP_EVENT_LOAD_FAILURE = 4,
79     PNP_EVENT_UNLOAD = 5,
80     PNP_EVENT_SERVICE_VALID = 7,
81     PNP_EVENT_SERVICE_INVALID  = 8,
82     PNP_EVENT_CAPTURE_THRESHOLD = 9,
83     PNP_EVENT_UNKNOWN = 10,
84     PNP_EVENT_MIC_BLOCKED = 11,
85     PNP_EVENT_MIC_UNBLOCKED = 12,
86 };
87 
88 enum PnpDeviceType {
89     PNP_DEVICE_LINEOUT = 1 << 0,
90     PNP_DEVICE_HEADPHONE = 1 << 1,
91     PNP_DEVICE_HEADSET = 1 << 2,
92     PNP_DEVICE_USB_HEADSET = 1 << 3,
93     PNP_DEVICE_USB_HEADPHONE = 1 << 4,
94     PNP_DEVICE_USBA_HEADSET = 1 << 5,
95     PNP_DEVICE_USBA_HEADPHONE = 1 << 6,
96     PNP_DEVICE_PRIMARY_DEVICE = 1 << 7,
97     PNP_DEVICE_USB_DEVICE = 1 << 8,
98     PNP_DEVICE_A2DP_DEVICE = 1 << 9,
99     PNP_DEVICE_HDMI_DEVICE = 1 << 10,
100     PNP_DEVICE_ADAPTER_DEVICE = 1 << 11,
101     PNP_DEVICE_DP_DEVICE = 1 << 12,
102     PNP_DEVICE_MIC = 1 << 13,
103     PNP_DEVICE_ACCESSORY = 1 << 14,
104     PNP_DEVICE_UNKNOWN,
105 };
106 
107 } // namespace AudioStandard
108 } // namespace OHOS
109 #endif // ST_AUDIO_PNP_SERVER_H