blob: a9848fd018441b6210ba1a3f39914f6136af1eed [file] [log] [blame]
Shunkai Yaoc23916b2022-07-13 04:59:37 +00001/*
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
24using aidl::android::media::audio::common::AudioUuid;
25
26namespace aidl::android::hardware::audio::effect {
27
28Factory::Factory() {
29 // TODO: implement this with xml parser on audio_effect.xml, and filter with optional
30 // parameters.
31 Descriptor::Identity id;
Shunkai Yao121c6dd2022-09-21 23:42:08 +000032 id.type = EqualizerTypeUUID;
33 id.uuid = EqualizerSwImplUUID;
Shunkai Yaoc23916b2022-07-13 04:59:37 +000034 mIdentityList.push_back(id);
Shunkai Yaoc23916b2022-07-13 04:59:37 +000035}
36
37ndk::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 Yao45905172022-08-24 18:14:02 +000048ndk::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 Yao121c6dd2022-09-21 23:42:08 +000052 if (in_impl_uuid == EqualizerSwImplUUID) {
Shunkai Yao45905172022-08-24 18:14:02 +000053 *_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
62ndk::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 Yaoc23916b2022-07-13 04:59:37 +000072} // namespace aidl::android::hardware::audio::effect