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 "singleton.h" 25 #include "audio_group_handle.h" 26 #include "audio_manager_base.h" 27 #include "audio_module_info.h" 28 #include "audio_volume_config.h" 29 #include "audio_errors.h" 30 31 namespace OHOS { 32 namespace AudioStandard { 33 34 class AudioConnectedDevice { 35 public: GetInstance()36 static AudioConnectedDevice& GetInstance() 37 { 38 static AudioConnectedDevice instance; 39 return instance; 40 } 41 void UpdateConnectDevice(DeviceType deviceType, const std::string &macAddress, 42 const std::string &deviceName, const AudioStreamInfo &streamInfo); 43 bool IsConnectedOutputDevice(const std::shared_ptr<AudioDeviceDescriptor> &desc); 44 bool CheckDeviceConnected(std::string selectedDevice); 45 void SetDisplayName(const std::string &deviceName, bool isLocalDevice); 46 void SetDmDeviceType(const uint16_t dmDeviceType); 47 std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetDevicesInner(DeviceFlag deviceFlag); 48 std::shared_ptr<AudioDeviceDescriptor> GetConnectedDeviceByType(int32_t deviceType); 49 std::shared_ptr<AudioDeviceDescriptor> GetConnectedDeviceByType(std::string networkId, DeviceType deviceType); 50 std::shared_ptr<AudioDeviceDescriptor> GetConnectedDeviceByType(std::string networkId, DeviceType deviceType, 51 std::string macAddress); 52 void GetAllConnectedDeviceByType(std::string networkId, DeviceType deviceType, 53 std::string macAddress, DeviceRole deviceRole, std::vector<std::shared_ptr<AudioDeviceDescriptor>> &descForCb); 54 void DelConnectedDevice(std::string networkId, DeviceType deviceType); 55 void DelConnectedDevice(std::string networkId, DeviceType deviceType, std::string macAddress); 56 void DelConnectedDevice(std::string networkId, DeviceType deviceType, std::string macAddress, 57 DeviceRole deviceRole); 58 void AddConnectedDevice(std::shared_ptr<AudioDeviceDescriptor> remoteDeviceDescriptor); 59 DeviceType FindConnectedHeadset(); 60 void SetDisplayName(const std::string macAddress, const std::string deviceName); 61 std::shared_ptr<AudioDeviceDescriptor> CheckExistInputDevice(DeviceType activeDevice); 62 std::shared_ptr<AudioDeviceDescriptor> CheckExistOutputDevice(DeviceType activeDevice, std::string macAddress); 63 std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetCopy(); 64 std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetDevicesForGroup(GroupType type, int32_t groupId); 65 bool HasArm(const DeviceRole role); 66 bool HasHifi(const DeviceRole role); 67 bool IsArmDevice(const std::string &address, const DeviceRole role); 68 std::shared_ptr<AudioDeviceDescriptor> GetUsbDeviceDescriptor(const std::string &address, const DeviceRole role); 69 void UpdateSpatializationSupported(const std::string macAddress, const bool support); 70 private: AudioConnectedDevice()71 AudioConnectedDevice() {} ~AudioConnectedDevice()72 ~AudioConnectedDevice() {} 73 private: 74 std::vector<std::shared_ptr<AudioDeviceDescriptor>> connectedDevices_; 75 }; 76 } 77 } 78 #endif