1 /* 2 * Copyright (c) 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 AUDIO_PIPE_SELECTOR_H 16 #define AUDIO_PIPE_SELECTOR_H 17 18 #include <vector> 19 #include "audio_pipe_manager.h" 20 #include "audio_stream_info.h" 21 #include "audio_policy_config_manager.h" 22 23 namespace OHOS { 24 namespace AudioStandard { 25 26 class AudioPipeSelector { 27 public: 28 AudioPipeSelector(); 29 ~AudioPipeSelector() = default; 30 31 static std::shared_ptr<AudioPipeSelector> GetPipeSelector(); 32 33 std::vector<std::shared_ptr<AudioPipeInfo>> FetchPipeAndExecute(std::shared_ptr<AudioStreamDescriptor> &streamDesc); 34 std::vector<std::shared_ptr<AudioPipeInfo>> FetchPipesAndExecute( 35 std::vector<std::shared_ptr<AudioStreamDescriptor>> &streamDescs); 36 37 private: 38 void UpdataDeviceStreamInfo(std::shared_ptr<AudioStreamDescriptor> &streamDesc, 39 std::shared_ptr<PipeStreamPropInfo> streamPropInfo); 40 void ScanPipeListForStreamDesc(std::vector<std::shared_ptr<AudioPipeInfo>> &pipeInfoList, 41 std::shared_ptr<AudioStreamDescriptor> streamDesc); 42 bool ProcessConcurrency(std::shared_ptr<AudioStreamDescriptor> stream, 43 std::shared_ptr<AudioStreamDescriptor> cmpStream); 44 void IncomingConcurrency(std::shared_ptr<AudioStreamDescriptor> stream, 45 std::shared_ptr<AudioStreamDescriptor> cmpStream); 46 uint32_t GetRouteFlagByStreamDesc(std::shared_ptr<AudioStreamDescriptor> streamDesc); 47 std::string GetAdapterNameByStreamDesc(std::shared_ptr<AudioStreamDescriptor> streamDesc); 48 void ConvertStreamDescToPipeInfo(std::shared_ptr<AudioStreamDescriptor> streamDesc, 49 std::shared_ptr<PipeStreamPropInfo> streamPropInfo, AudioPipeInfo &info); 50 AudioStreamAction JudgeStreamAction(std::shared_ptr<AudioPipeInfo> newPipe, std::shared_ptr<AudioPipeInfo> oldPipe); 51 void SortStreamDescsByStartTime(std::vector<std::shared_ptr<AudioStreamDescriptor>> &streamDescs); 52 AudioPipeType GetPipeType(uint32_t flag, AudioMode audioMode); 53 void HandlePipeNotExist(std::vector<std::shared_ptr<AudioPipeInfo>> &newPipeInfoList, 54 std::shared_ptr<AudioStreamDescriptor> &streamDesc); 55 bool IsSameAdapter(std::shared_ptr<AudioStreamDescriptor> streamDescA, 56 std::shared_ptr<AudioStreamDescriptor> streamDescB); 57 void DecideFinalRouteFlag(std::vector<std::shared_ptr<AudioStreamDescriptor>> &streamDescs); 58 void ProcessNewPipeList(std::vector<std::shared_ptr<AudioPipeInfo>> &newPipeInfoList, 59 std::vector<std::shared_ptr<AudioStreamDescriptor>> &streamDescs); 60 void DecidePipesAndStreamAction(std::vector<std::shared_ptr<AudioPipeInfo>> &newPipeInfoList, 61 std::map<uint32_t, std::shared_ptr<AudioPipeInfo>> streamDescToOldPipeInfo); 62 AudioPolicyConfigManager& configManager_; 63 }; 64 } // namespace AudioStandard 65 } // namespace OHOS 66 #endif // AUDIO_PIPE_SELECTOR_H 67