1 /* 2 * Copyright (c) 2024 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 AUDIO_MEMO_H 17 #define AUDIO_MEMO_H 18 19 #include <map> 20 #include <mutex> 21 #include "media_monitor_info.h" 22 #include "event_bean.h" 23 24 namespace OHOS { 25 namespace Media { 26 namespace MediaMonitor { 27 28 class AudioMemo { 29 public: GetAudioMemo()30 static AudioMemo& GetAudioMemo() 31 { 32 static AudioMemo audioMemo; 33 return audioMemo; 34 } 35 36 AudioMemo() = default; 37 ~AudioMemo() = default; 38 39 void UpdataRouteInfo(std::shared_ptr<EventBean> &bean); 40 int32_t GetAudioRouteMsg(std::map<PreferredType, std::shared_ptr<MonitorDeviceInfo>> &preferredDevices); 41 42 void WriteInfo(int32_t fd, std::string &dumpString); 43 44 int32_t ErasePreferredDeviceByType(const PreferredType &preferredType); 45 46 void UpdateExcludedDevice(std::shared_ptr<EventBean> &bean); 47 int32_t GetAudioExcludedDevicesMsg(std::map<AudioDeviceUsage, 48 std::vector<std::shared_ptr<MonitorDeviceInfo>>> &excludedDevices); 49 private: 50 PreferredType GetPreferredType(std::shared_ptr<EventBean> &bean); 51 PreferredType GetPreferredRenderType(int32_t streamUsage); 52 PreferredType GetPreferredCaptureType(int32_t AudioScene); 53 54 std::string GetPreferredNameFromType(const PreferredType &type); 55 56 void UpdateExcludedDeviceInner(AudioDeviceUsage audioDevUsage, std::shared_ptr<MonitorDeviceInfo> &deviceInfo, 57 int32_t exclusionStatus); 58 59 std::mutex preferredDeviceMutex_; 60 std::map<PreferredType, std::shared_ptr<MonitorDeviceInfo>> preferredDevices_; 61 62 std::mutex excludedDeviceMutex_; 63 std::map<AudioDeviceUsage, std::vector<std::shared_ptr<MonitorDeviceInfo>>> excludedDevices_; 64 }; 65 66 } // namespace MediaMonitor 67 } // namespace Media 68 } // namespace OHOS 69 #endif // AUDIO_MEMO_H