• 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 
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 #include "audio_pipe_info.h"
30 
31 namespace OHOS {
32 namespace AudioStandard {
33 
34 class AudioIOHandleMap {
35 public:
GetInstance()36     static AudioIOHandleMap& GetInstance()
37     {
38         static AudioIOHandleMap instance;
39         return instance;
40     }
41 
42     void DeInit();
43     std::unordered_map<std::string, AudioIOHandle> GetCopy();
44     bool GetModuleIdByKey(std::string moduleName, AudioIOHandle& moduleId);
45     void DelIOHandleInfo(std::string moduleName);
46     void AddIOHandleInfo(std::string moduleName, const AudioIOHandle& moduleId);
47     AudioIOHandle GetSinkIOHandle(DeviceType deviceType);
48     AudioIOHandle GetSourceIOHandle(DeviceType deviceType);
49     bool CheckIOHandleExist(std::string moduleName);
50 
51     int32_t OpenPortAndInsertIOHandle(const std::string &moduleName, const AudioModuleInfo &moduleInfo);
52     int32_t ClosePortAndEraseIOHandle(const std::string &moduleName);
53     int32_t ReloadPortAndUpdateIOHandle(std::shared_ptr<AudioPipeInfo> &pipeInfo, const AudioModuleInfo &moduleInfo);
54 
55     void NotifyUnmutePort();
56     void MuteSinkPort(const std::string &portName, int32_t duration, bool isSync, bool isSleepEnabled = true);
57     void SetMoveFinish(bool flag);
58     void MuteDefaultSinkPort(std::string networkID, std::string sinkName);
59     void UnmutePortAfterMuteDuration(int32_t muteDuration, const std::string &portName);
60     void DoUnmutePort(int32_t muteDuration, const std::string &portName);
61 
62 private:
AudioIOHandleMap()63     AudioIOHandleMap() {}
~AudioIOHandleMap()64     ~AudioIOHandleMap() {}
65 
66 private:
67     std::mutex ioHandlesMutex_;
68     std::unordered_map<std::string, AudioIOHandle> IOHandles_ = {};
69 
70     std::mutex moveDeviceMutex_;
71     std::condition_variable moveDeviceCV_;
72     std::atomic<bool> moveDeviceFinished_ = false;
73 
74     static std::map<std::string, std::string> sinkPortStrToClassStrMap_;
75 };
76 }
77 }
78 
79 #endif