blob: 5090f11cb223f5500198037feeebe2d35a3dde07 [file] [log] [blame]
Shunkai Yao51202502022-12-12 06:11:46 +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 "EffectHalAidl"
18//#define LOG_NDEBUG 0
19
Mikhail Naganov5e406ba2023-01-13 00:27:22 +000020#include <error/expected_utils.h>
Shunkai Yao51202502022-12-12 06:11:46 +000021#include <media/AidlConversionCppNdk.h>
Shunkai Yaoa03533e2023-01-25 06:38:10 +000022#include <media/AidlConversionEffect.h>
Mikhail Naganov5e406ba2023-01-13 00:27:22 +000023#include <media/AidlConversionUtil.h>
Shunkai Yao51202502022-12-12 06:11:46 +000024#include <media/EffectsFactoryApi.h>
25#include <mediautils/TimeCheck.h>
26#include <utils/Log.h>
27
Shunkai Yao284bb0d2023-01-10 00:42:36 +000028#include <system/audio_effects/effect_aec.h>
29#include <system/audio_effects/effect_downmix.h>
30#include <system/audio_effects/effect_dynamicsprocessing.h>
31#include <system/audio_effects/effect_hapticgenerator.h>
32#include <system/audio_effects/effect_ns.h>
33#include <system/audio_effects/effect_spatializer.h>
34#include <system/audio_effects/effect_visualizer.h>
35
Shunkai Yao51202502022-12-12 06:11:46 +000036#include "EffectHalAidl.h"
37
38#include <system/audio.h>
Shunkai Yao51202502022-12-12 06:11:46 +000039#include <aidl/android/hardware/audio/effect/IEffect.h>
40
Mikhail Naganov5e406ba2023-01-13 00:27:22 +000041using ::aidl::android::aidl_utils::statusTFromBinderStatus;
Shunkai Yao51202502022-12-12 06:11:46 +000042using ::aidl::android::hardware::audio::effect::CommandId;
43using ::aidl::android::hardware::audio::effect::Descriptor;
44using ::aidl::android::hardware::audio::effect::IEffect;
Shunkai Yao44bdbad2023-01-14 05:11:58 +000045using ::aidl::android::hardware::audio::effect::IFactory;
Shunkai Yao51202502022-12-12 06:11:46 +000046using ::aidl::android::hardware::audio::effect::Parameter;
47
48namespace android {
49namespace effect {
50
Shunkai Yao44bdbad2023-01-14 05:11:58 +000051EffectHalAidl::EffectHalAidl(
52 const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory>& factory,
53 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& effect,
54 uint64_t effectId, int32_t sessionId, int32_t ioId,
55 const ::aidl::android::hardware::audio::effect::Descriptor& desc)
56 : EffectConversionHelperAidl(effect, sessionId, ioId, desc),
57 mFactory(factory),
58 mEffect(effect),
Shunkai Yao284bb0d2023-01-10 00:42:36 +000059 mEffectId(effectId),
60 mSessionId(sessionId),
61 mIoId(ioId),
Shunkai Yao284bb0d2023-01-10 00:42:36 +000062 mDesc(desc) {}
Shunkai Yao51202502022-12-12 06:11:46 +000063
Shunkai Yao44bdbad2023-01-14 05:11:58 +000064EffectHalAidl::~EffectHalAidl() {
65 if (mFactory) {
66 mFactory->destroyEffect(mEffect);
67 }
68}
Shunkai Yao51202502022-12-12 06:11:46 +000069
70status_t EffectHalAidl::setInBuffer(const sp<EffectBufferHalInterface>& buffer) {
71 if (buffer == nullptr) {
72 return BAD_VALUE;
73 }
74 ALOGW("%s not implemented yet", __func__);
75 return OK;
76}
77
78status_t EffectHalAidl::setOutBuffer(const sp<EffectBufferHalInterface>& buffer) {
79 if (buffer == nullptr) {
80 return BAD_VALUE;
81 }
82 ALOGW("%s not implemented yet", __func__);
83 return OK;
84}
85
86status_t EffectHalAidl::process() {
87 ALOGW("%s not implemented yet", __func__);
Shunkai Yao284bb0d2023-01-10 00:42:36 +000088 // write to input FMQ here, and wait for statusMQ STATUS_OK
Shunkai Yao51202502022-12-12 06:11:46 +000089 return OK;
90}
91
92// TODO: no one using, maybe deprecate this interface
93status_t EffectHalAidl::processReverse() {
94 ALOGW("%s not implemented yet", __func__);
95 return OK;
96}
97
Shunkai Yao51202502022-12-12 06:11:46 +000098status_t EffectHalAidl::command(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData,
99 uint32_t* replySize, void* pReplyData) {
Shunkai Yao284bb0d2023-01-10 00:42:36 +0000100 return handleCommand(cmdCode, cmdSize, pCmdData, replySize, pReplyData);
Shunkai Yao51202502022-12-12 06:11:46 +0000101}
102
103status_t EffectHalAidl::getDescriptor(effect_descriptor_t* pDescriptor) {
104 ALOGW("%s %p", __func__, pDescriptor);
105 if (pDescriptor == nullptr) {
106 return BAD_VALUE;
107 }
108 Descriptor aidlDesc;
Mikhail Naganov5e406ba2023-01-13 00:27:22 +0000109 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getDescriptor(&aidlDesc)));
Shunkai Yao51202502022-12-12 06:11:46 +0000110
111 *pDescriptor = VALUE_OR_RETURN_STATUS(
112 ::aidl::android::aidl2legacy_Descriptor_effect_descriptor(aidlDesc));
113 return OK;
114}
115
116status_t EffectHalAidl::close() {
Shunkai Yao44bdbad2023-01-14 05:11:58 +0000117 return statusTFromBinderStatus(mEffect->close());
Shunkai Yao51202502022-12-12 06:11:46 +0000118}
119
120status_t EffectHalAidl::dump(int fd) {
121 ALOGW("%s not implemented yet, fd %d", __func__, fd);
122 return OK;
123}
124
125} // namespace effect
126} // namespace android