1 /* 2 * Copyright (c) 2023 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_DEVICE_MANAGER_IMPL_H 17 #define AUDIO_DEVICE_MANAGER_IMPL_H 18 19 #include <map> 20 #include <mutex> 21 22 #include "audio_info.h" 23 #include "i_audio_device_manager.h" 24 #include "i_audio_device_adapter.h" 25 26 namespace OHOS { 27 namespace AudioStandard { 28 struct DeviceAdapterInfo { 29 std::shared_ptr<IAudioDeviceAdapter> devAdp = nullptr; 30 sptr<IAudioAdapter> audioAdapter = nullptr; 31 }; 32 33 class AudioDeviceManagerImpl : public IAudioDeviceManager { 34 public: AudioDeviceManagerImpl(const AudioDeviceManagerType devMgrType,sptr<IAudioManager> audioMgr)35 AudioDeviceManagerImpl(const AudioDeviceManagerType devMgrType, sptr<IAudioManager> audioMgr) 36 : audioMgrType_(devMgrType), audioMgr_(audioMgr) {}; 37 ~AudioDeviceManagerImpl() = default; 38 39 int32_t GetAllAdapters() override; 40 struct AudioAdapterDescriptor *GetTargetAdapterDesc(const std::string &adapterName, bool isMmap) override; 41 std::shared_ptr<IAudioDeviceAdapter> LoadAdapters(const std::string &adapterName, bool isMmap) override; 42 int32_t UnloadAdapter(const std::string &adapterName) override; 43 int32_t Release() override; 44 45 private: 46 static constexpr int32_t INVALID_INDEX = -1; 47 48 AudioDeviceManagerType audioMgrType_; 49 sptr<IAudioManager> audioMgr_; 50 std::mutex mtx_; 51 std::map<std::string, DeviceAdapterInfo> enableAdapters_; 52 std::vector<AudioAdapterDescriptor> descriptors_; 53 }; 54 } // namespace AudioStandard 55 } // namespace OHOS 56 #endif // AUDIO_DEVICE_MANAGER_IMPL_H 57