Shunkai Yao | ea24c1a | 2022-09-28 17:39:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <memory> |
| 20 | #include <string> |
| 21 | #include <unordered_map> |
| 22 | #include <vector> |
| 23 | |
Shunkai Yao | 1283685 | 2023-12-13 01:07:52 +0000 | [diff] [blame] | 24 | #include <aidl/Vintf.h> |
Shunkai Yao | ea24c1a | 2022-09-28 17:39:23 +0000 | [diff] [blame] | 25 | #include <android/binder_auto_utils.h> |
Shunkai Yao | 9f9fe92 | 2024-03-04 21:23:04 +0000 | [diff] [blame] | 26 | #include <system/audio_effects/aidl_effects_utils.h> |
Shunkai Yao | ea24c1a | 2022-09-28 17:39:23 +0000 | [diff] [blame] | 27 | |
Bart Van Assche | 5e7fcb4 | 2023-11-08 07:00:22 -0800 | [diff] [blame] | 28 | #include "AudioHalBinderServiceUtil.h" |
Shunkai Yao | ea24c1a | 2022-09-28 17:39:23 +0000 | [diff] [blame] | 29 | #include "TestUtils.h" |
| 30 | |
| 31 | using namespace android; |
| 32 | |
| 33 | using aidl::android::hardware::audio::effect::Descriptor; |
Shunkai Yao | ea24c1a | 2022-09-28 17:39:23 +0000 | [diff] [blame] | 34 | using aidl::android::hardware::audio::effect::IFactory; |
Shunkai Yao | ea24c1a | 2022-09-28 17:39:23 +0000 | [diff] [blame] | 35 | using aidl::android::media::audio::common::AudioUuid; |
| 36 | |
| 37 | class EffectFactoryHelper { |
| 38 | public: |
Shunkai Yao | cb0fc41 | 2022-12-15 20:34:32 +0000 | [diff] [blame] | 39 | static std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> getAllEffectDescriptors( |
| 40 | std::string serviceName, std::optional<AudioUuid> type = std::nullopt) { |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 41 | AudioHalBinderServiceUtil util; |
| 42 | auto names = android::getAidlHalInstanceNames(serviceName); |
Shunkai Yao | cb0fc41 | 2022-12-15 20:34:32 +0000 | [diff] [blame] | 43 | std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> result; |
Shunkai Yao | 08b687d | 2022-10-13 21:11:11 +0000 | [diff] [blame] | 44 | |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 45 | for (const auto& name : names) { |
| 46 | auto factory = IFactory::fromBinder(util.connectToService(name)); |
| 47 | if (factory) { |
Shunkai Yao | c12e082 | 2022-12-12 07:13:58 +0000 | [diff] [blame] | 48 | if (std::vector<Descriptor> descs; |
| 49 | factory->queryEffects(std::nullopt, std::nullopt, std::nullopt, &descs) |
| 50 | .isOk()) { |
| 51 | for (const auto& desc : descs) { |
Shunkai Yao | cb0fc41 | 2022-12-15 20:34:32 +0000 | [diff] [blame] | 52 | if (type.has_value() && desc.common.id.type != type.value()) { |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 53 | continue; |
| 54 | } |
Shunkai Yao | cb0fc41 | 2022-12-15 20:34:32 +0000 | [diff] [blame] | 55 | result.emplace_back(factory, desc); |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 56 | } |
| 57 | } |
Shunkai Yao | ea24c1a | 2022-09-28 17:39:23 +0000 | [diff] [blame] | 58 | } |
| 59 | } |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 60 | return result; |
Shunkai Yao | a4ab38c | 2022-10-14 01:07:47 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Shunkai Yao | 9f9fe92 | 2024-03-04 21:23:04 +0000 | [diff] [blame] | 63 | static int getHalVersion(const std::shared_ptr<IFactory>& factory) { |
| 64 | int version = 0; |
| 65 | return (factory && factory->getInterfaceVersion(&version).isOk()) ? version : 0; |
| 66 | } |
| 67 | |
| 68 | static bool isReopenSupported(const std::shared_ptr<IFactory>& factory) { |
| 69 | return EffectFactoryHelper::getHalVersion(factory) >= |
| 70 | aidl::android::hardware::audio::effect::kReopenSupportedVersion; |
| 71 | } |
Shunkai Yao | ea24c1a | 2022-09-28 17:39:23 +0000 | [diff] [blame] | 72 | }; |