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 16 #ifndef ST_AUDIO_IOHANDLE_MAP_H 17 #define ST_AUDIO_IOHANDLE_MAP_H 18 19 #include <bitset> 20 #include <list> 21 #include <string> 22 #include <unordered_map> 23 #include <unordered_set> 24 #include <mutex> 25 #include "singleton.h" 26 #include "audio_group_handle.h" 27 #include "audio_manager_base.h" 28 #include "audio_module_info.h" 29 30 namespace OHOS { 31 namespace AudioStandard { 32 33 class AudioIOHandleMap { 34 public: GetInstance()35 static AudioIOHandleMap& GetInstance() 36 { 37 static AudioIOHandleMap instance; 38 return instance; 39 } 40 41 void DeInit(); 42 std::unordered_map<std::string, AudioIOHandle> GetCopy(); 43 bool GetModuleIdByKey(std::string moduleName, AudioIOHandle& moduleId); 44 void DelIOHandleInfo(std::string moduleName); 45 void AddIOHandleInfo(std::string moduleName, const AudioIOHandle& moduleId); 46 AudioIOHandle GetSinkIOHandle(DeviceType deviceType); 47 AudioIOHandle GetSourceIOHandle(DeviceType deviceType); 48 bool CheckIOHandleExist(std::string moduleName); 49 50 int32_t OpenPortAndInsertIOHandle(const std::string &moduleName, const AudioModuleInfo &moduleInfo); 51 int32_t ClosePortAndEraseIOHandle(const std::string &moduleName, bool isSync = false); 52 53 void NotifyUnmutePort(); 54 void MuteSinkPort(const std::string &portName, int32_t duration, bool isSync); 55 void SetMoveFinish(bool flag); 56 void MuteDefaultSinkPort(std::string networkID, std::string sinkName); 57 void UnmutePortAfterMuteDuration(int32_t muteDuration, const std::string &portName); 58 void DoUnmutePort(int32_t muteDuration, const std::string &portName); 59 60 private: AudioIOHandleMap()61 AudioIOHandleMap() {} ~AudioIOHandleMap()62 ~AudioIOHandleMap() {} 63 64 private: 65 std::mutex ioHandlesMutex_; 66 std::unordered_map<std::string, AudioIOHandle> IOHandles_ = {}; 67 68 std::mutex moveDeviceMutex_; 69 std::condition_variable moveDeviceCV_; 70 std::atomic<bool> moveDeviceFinished_ = false; 71 72 static std::map<std::string, std::string> sinkPortStrToClassStrMap_; 73 }; 74 } 75 } 76 77 #endif