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 #include "audio_engine_manager.h" 16 #include "none_mix_engine.h" 17 18 namespace OHOS { 19 namespace AudioStandard { GetInstance()20AudioEngineManager AudioEngineManager::GetInstance() 21 { 22 static AudioEngineManager enginManager; 23 return enginManager; 24 } 25 AddRenderer(std::shared_ptr<IRendererStream> stream,DeviceInfo device)26void AudioEngineManager::AddRenderer(std::shared_ptr<IRendererStream> stream, DeviceInfo device) 27 { 28 AudioProcessConfig config = stream->GetAudioProcessConfig(); 29 bool isDirect = true; 30 PlaybackType playbackType_ = PlaybackType::DIRECT; 31 if (config.streamType != STREAM_MUSIC) { 32 playbackType_ = PlaybackType::VOIP; 33 isDirect = false; 34 } 35 auto iter = renderEngines_.find(playbackType_); 36 if (iter == renderEngines_.end()) { 37 std::shared_ptr<AudioPlaybackEngine> playbackEngine = std::make_shared<NoneMixEngine>(); 38 playbackEngine->Init(device, !isDirect); 39 playbackEngine->AddRenderer(stream); 40 renderEngines_.emplace(playbackType_, playbackEngine); 41 } 42 } RemoveRenderer(std::shared_ptr<IRendererStream> stream)43void AudioEngineManager::RemoveRenderer(std::shared_ptr<IRendererStream> stream) 44 { 45 AudioProcessConfig config = stream->GetAudioProcessConfig(); 46 PlaybackType playbackType_ = PlaybackType::DIRECT; 47 if (config.streamType != STREAM_MUSIC) { 48 playbackType_ = PlaybackType::VOIP; 49 } 50 auto iter = renderEngines_.find(playbackType_); 51 if (iter != renderEngines_.end()) { 52 renderEngines_.erase(iter); 53 } 54 } 55 } // namespace AudioStandard 56 } // namespace OHOS 57