• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 ST_AUDIO_CONNECTED_DEVICE_H
16 #define ST_AUDIO_CONNECTED_DEVICE_H
17 
18 #include <bitset>
19 #include <list>
20 #include <string>
21 #include <unordered_map>
22 #include <unordered_set>
23 #include <mutex>
24 #include <shared_mutex>
25 #include "singleton.h"
26 #include "audio_group_handle.h"
27 #include "audio_manager_base.h"
28 #include "audio_module_info.h"
29 #include "audio_volume_config.h"
30 #include "audio_errors.h"
31 #include "audio_device_descriptor.h"
32 
33 namespace OHOS {
34 namespace AudioStandard {
35 
36 struct DmDevice {
37     std::string deviceName_;
38     std::string networkId_;
39     uint16_t dmDeviceType_{0};
40 };
41 
42 class AudioConnectedDevice {
43 public:
GetInstance()44     static AudioConnectedDevice& GetInstance()
45     {
46         static AudioConnectedDevice instance;
47         return instance;
48     }
49     void UpdateConnectDevice(DeviceType deviceType, const std::string &macAddress,
50         const std::string &deviceName, const AudioStreamInfo &streamInfo);
51     bool IsConnectedOutputDevice(const std::shared_ptr<AudioDeviceDescriptor> &desc);
52     bool CheckDeviceConnected(std::string selectedDevice);
53     void SetDisplayName(const std::string &deviceName, bool isLocalDevice);
54     void UpdateDmDeviceMap(DmDevice &&dmDevice, bool isConnect);
55     void UpdateDeviceDesc4DmDevice(AudioDeviceDescriptor &deviceDesc);
56     std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetDevicesInner(DeviceFlag deviceFlag);
57     std::shared_ptr<AudioDeviceDescriptor> GetConnectedDeviceByType(int32_t deviceType);
58     std::shared_ptr<AudioDeviceDescriptor> GetConnectedDeviceByType(std::string networkId, DeviceType deviceType);
59     std::shared_ptr<AudioDeviceDescriptor> GetConnectedDeviceByType(std::string networkId, DeviceType deviceType,
60         std::string macAddress);
61     void GetAllConnectedDeviceByType(std::string networkId, DeviceType deviceType,
62         std::string macAddress, DeviceRole deviceRole, std::vector<std::shared_ptr<AudioDeviceDescriptor>> &descForCb);
63     void DelConnectedDevice(std::string networkId, DeviceType deviceType);
64     void DelConnectedDevice(std::string networkId, DeviceType deviceType, std::string macAddress);
65     void DelConnectedDevice(std::string networkId, DeviceType deviceType, std::string macAddress,
66         DeviceRole deviceRole);
67     void AddConnectedDevice(std::shared_ptr<AudioDeviceDescriptor> remoteDeviceDescriptor);
68     DeviceType FindConnectedHeadset();
69     void SetDisplayName(const std::string macAddress, const std::string deviceName);
70     std::shared_ptr<AudioDeviceDescriptor> CheckExistInputDevice(DeviceType activeDevice);
71     std::shared_ptr<AudioDeviceDescriptor> CheckExistOutputDevice(DeviceType activeDevice, std::string macAddress);
72     std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetCopy();
73     std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetDevicesForGroup(GroupType type, int32_t groupId);
74     bool HasArm(const DeviceRole role);
75     bool HasHifi(const DeviceRole role);
76     bool IsArmDevice(const std::string &address, const DeviceRole role);
77     std::shared_ptr<AudioDeviceDescriptor> GetUsbDeviceDescriptor(const std::string &address, const DeviceRole role);
78     void UpdateSpatializationSupported(const std::string macAddress, const bool support);
79     void RegisterNameMonitorHelper();
80 private:
AudioConnectedDevice()81     AudioConnectedDevice() {}
~AudioConnectedDevice()82     ~AudioConnectedDevice() {}
83 private:
84     std::vector<std::shared_ptr<AudioDeviceDescriptor>> connectedDevices_;
85     std::mutex dmDeviceMtx_;
86     std::unordered_map<std::string, DmDevice> dmDeviceMap_;
87     std::shared_mutex mutex_;
88 };
89 }
90 }
91 #endif