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_A2DP_SERVICE_H 16 #define ST_AUDIO_A2DP_SERVICE_H 17 18 #include <bitset> 19 #include <list> 20 #include <string> 21 #include <unordered_map> 22 #include <unordered_set> 23 #include <mutex> 24 #include "audio_module_info.h" 25 #include "audio_device_info.h" 26 27 namespace OHOS { 28 namespace AudioStandard { 29 class AudioA2dpDevice { 30 public: GetInstance()31 static AudioA2dpDevice& GetInstance() 32 { 33 static AudioA2dpDevice instance; 34 return instance; 35 } 36 bool GetA2dpDeviceInfo(const std::string& device, A2dpDeviceConfigInfo& info); 37 bool GetA2dpInDeviceInfo(const std::string& device, A2dpDeviceConfigInfo& info); 38 bool GetA2dpDeviceVolumeLevel(const std::string& device, int32_t& volumeLevel); 39 bool CheckA2dpDeviceExist(const std::string& device); 40 bool SetA2dpDeviceMute(const std::string& device, bool mute); 41 void SetA2dpDeviceStreamInfo(const std::string& device, const DeviceStreamInfo& streamInfo); 42 void AddA2dpDevice(const std::string& device, const A2dpDeviceConfigInfo& config); 43 bool SetA2dpDeviceAbsVolumeSupport(const std::string& device, const bool support, int32_t volume, bool mute); 44 bool SetA2dpDeviceVolumeLevel(const std::string& device, const int32_t volumeLevel); 45 size_t DelA2dpDevice(const std::string& device); 46 47 void AddA2dpInDevice(const std::string& device, const A2dpDeviceConfigInfo& config); 48 size_t DelA2dpInDevice(const std::string& device); 49 bool GetA2dpDeviceMute(const std::string& device, bool& isMute); 50 void AddHearingAidDevice(const std::string& device, const A2dpDeviceConfigInfo& config); 51 size_t DelHearingAidDevice(const std::string& device); 52 bool CheckHearingAidDeviceExist(const std::string& device); 53 private: AudioA2dpDevice()54 AudioA2dpDevice() {} ~AudioA2dpDevice()55 ~AudioA2dpDevice() {} 56 private: 57 mutable std::mutex a2dpDeviceMapMutex_; 58 std::unordered_map<std::string, A2dpDeviceConfigInfo> connectedA2dpDeviceMap_; 59 mutable std::mutex a2dpInDeviceMapMutex_; 60 std::unordered_map<std::string, A2dpDeviceConfigInfo> connectedA2dpInDeviceMap_; 61 mutable std::mutex hearingAidDeviceMapMutex_; 62 std::unordered_map<std::string, A2dpDeviceConfigInfo> connectedHearingAidDeviceMap_; 63 }; 64 } 65 } 66 67 #endif