Shunkai Yao | c23916b | 2022-07-13 04:59:37 +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 | #define LOG_TAG "AHAL_EffectFactory" |
| 18 | #include <android-base/logging.h> |
| 19 | |
| 20 | #include "effectFactory-impl/EffectFactory.h" |
| 21 | #include "equalizer-impl/Equalizer.h" |
| 22 | #include "visualizer-impl/Visualizer.h" |
| 23 | |
| 24 | using aidl::android::media::audio::common::AudioUuid; |
| 25 | |
| 26 | namespace aidl::android::hardware::audio::effect { |
| 27 | |
| 28 | Factory::Factory() { |
| 29 | // TODO: implement this with xml parser on audio_effect.xml, and filter with optional |
| 30 | // parameters. |
| 31 | Descriptor::Identity id; |
Shunkai Yao | 121c6dd | 2022-09-21 23:42:08 +0000 | [diff] [blame^] | 32 | id.type = EqualizerTypeUUID; |
| 33 | id.uuid = EqualizerSwImplUUID; |
Shunkai Yao | c23916b | 2022-07-13 04:59:37 +0000 | [diff] [blame] | 34 | mIdentityList.push_back(id); |
Shunkai Yao | c23916b | 2022-07-13 04:59:37 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | ndk::ScopedAStatus Factory::queryEffects(const std::optional<AudioUuid>& in_type, |
| 38 | const std::optional<AudioUuid>& in_instance, |
| 39 | std::vector<Descriptor::Identity>* _aidl_return) { |
| 40 | std::copy_if(mIdentityList.begin(), mIdentityList.end(), std::back_inserter(*_aidl_return), |
| 41 | [&](auto& desc) { |
| 42 | return (!in_type.has_value() || in_type.value() == desc.type) && |
| 43 | (!in_instance.has_value() || in_instance.value() == desc.uuid); |
| 44 | }); |
| 45 | return ndk::ScopedAStatus::ok(); |
| 46 | } |
| 47 | |
Shunkai Yao | 4590517 | 2022-08-24 18:14:02 +0000 | [diff] [blame] | 48 | ndk::ScopedAStatus Factory::createEffect( |
| 49 | const AudioUuid& in_impl_uuid, |
| 50 | std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>* _aidl_return) { |
| 51 | LOG(DEBUG) << __func__ << ": UUID " << in_impl_uuid.toString(); |
Shunkai Yao | 121c6dd | 2022-09-21 23:42:08 +0000 | [diff] [blame^] | 52 | if (in_impl_uuid == EqualizerSwImplUUID) { |
Shunkai Yao | 4590517 | 2022-08-24 18:14:02 +0000 | [diff] [blame] | 53 | *_aidl_return = ndk::SharedRefBase::make<Equalizer>(); |
| 54 | } else { |
| 55 | LOG(ERROR) << __func__ << ": UUID " |
| 56 | << " not supported"; |
| 57 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 58 | } |
| 59 | return ndk::ScopedAStatus::ok(); |
| 60 | } |
| 61 | |
| 62 | ndk::ScopedAStatus Factory::destroyEffect( |
| 63 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& in_handle) { |
| 64 | if (in_handle) { |
| 65 | // TODO: b/245393900 need check the instance state with IEffect.getState before destroy. |
| 66 | return ndk::ScopedAStatus::ok(); |
| 67 | } else { |
| 68 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 69 | } |
| 70 | } |
| 71 | |
Shunkai Yao | c23916b | 2022-07-13 04:59:37 +0000 | [diff] [blame] | 72 | } // namespace aidl::android::hardware::audio::effect |