blob: ea9d470e9c5dc174e4e9b625bdf55ca201022cb2 [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;
32 id.type = {static_cast<int32_t>(0x0bed4300),
33 0xddd6,
34 0x11db,
35 0x8f34,
36 {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}};
37 id.uuid = EqualizerUUID;
38 mIdentityList.push_back(id);
Shunkai Yao45905172022-08-24 18:14:02 +000039 // TODO: Add visualizer with default implementation later
40#if 0
Shunkai Yaoc23916b2022-07-13 04:59:37 +000041 id.type = {static_cast<int32_t>(0xd3467faa),
42 0xacc7,
43 0x4d34,
44 0xacaf,
45 {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}};
46 id.uuid = VisualizerUUID;
47 mIdentityList.push_back(id);
Shunkai Yao45905172022-08-24 18:14:02 +000048#endif
Shunkai Yaoc23916b2022-07-13 04:59:37 +000049}
50
51ndk::ScopedAStatus Factory::queryEffects(const std::optional<AudioUuid>& in_type,
52 const std::optional<AudioUuid>& in_instance,
53 std::vector<Descriptor::Identity>* _aidl_return) {
54 std::copy_if(mIdentityList.begin(), mIdentityList.end(), std::back_inserter(*_aidl_return),
55 [&](auto& desc) {
56 return (!in_type.has_value() || in_type.value() == desc.type) &&
57 (!in_instance.has_value() || in_instance.value() == desc.uuid);
58 });
59 return ndk::ScopedAStatus::ok();
60}
61
Shunkai Yao45905172022-08-24 18:14:02 +000062ndk::ScopedAStatus Factory::createEffect(
63 const AudioUuid& in_impl_uuid,
64 std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>* _aidl_return) {
65 LOG(DEBUG) << __func__ << ": UUID " << in_impl_uuid.toString();
66 if (in_impl_uuid == EqualizerUUID) {
67 *_aidl_return = ndk::SharedRefBase::make<Equalizer>();
68 } else {
69 LOG(ERROR) << __func__ << ": UUID "
70 << " not supported";
71 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
72 }
73 return ndk::ScopedAStatus::ok();
74}
75
76ndk::ScopedAStatus Factory::destroyEffect(
77 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& in_handle) {
78 if (in_handle) {
79 // TODO: b/245393900 need check the instance state with IEffect.getState before destroy.
80 return ndk::ScopedAStatus::ok();
81 } else {
82 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
83 }
84}
85
Shunkai Yaoc23916b2022-07-13 04:59:37 +000086} // namespace aidl::android::hardware::audio::effect