blob: 39345a9683c95dcb45b21aec35a9d7d2767047b2 [file] [log] [blame]
Shunkai Yao6afc8552022-10-26 22:47:20 +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#include <cstddef>
18#define LOG_TAG "AHAL_DynamicsProcessingSw"
19#include <Utils.h>
20#include <algorithm>
21#include <unordered_set>
22
23#include <android-base/logging.h>
24#include <fmq/AidlMessageQueue.h>
25
26#include "DynamicsProcessingSw.h"
27
Shunkai Yaoc12e0822022-12-12 07:13:58 +000028using aidl::android::hardware::audio::effect::Descriptor;
Shunkai Yao6afc8552022-10-26 22:47:20 +000029using aidl::android::hardware::audio::effect::DynamicsProcessingSw;
Shunkai Yao6afc8552022-10-26 22:47:20 +000030using aidl::android::hardware::audio::effect::IEffect;
Shunkai Yao812d5b42022-11-16 18:08:50 +000031using aidl::android::hardware::audio::effect::kDynamicsProcessingSwImplUUID;
Shunkai Yao6afc8552022-10-26 22:47:20 +000032using aidl::android::hardware::audio::effect::State;
33using aidl::android::media::audio::common::AudioUuid;
34
35extern "C" binder_exception_t createEffect(const AudioUuid* in_impl_uuid,
36 std::shared_ptr<IEffect>* instanceSpp) {
Shunkai Yao812d5b42022-11-16 18:08:50 +000037 if (!in_impl_uuid || *in_impl_uuid != kDynamicsProcessingSwImplUUID) {
Shunkai Yao6afc8552022-10-26 22:47:20 +000038 LOG(ERROR) << __func__ << "uuid not supported";
39 return EX_ILLEGAL_ARGUMENT;
40 }
41 if (instanceSpp) {
42 *instanceSpp = ndk::SharedRefBase::make<DynamicsProcessingSw>();
43 LOG(DEBUG) << __func__ << " instance " << instanceSpp->get() << " created";
44 return EX_NONE;
45 } else {
46 LOG(ERROR) << __func__ << " invalid input parameter!";
47 return EX_ILLEGAL_ARGUMENT;
48 }
49}
50
Shunkai Yaoc12e0822022-12-12 07:13:58 +000051extern "C" binder_exception_t queryEffect(const AudioUuid* in_impl_uuid, Descriptor* _aidl_return) {
52 if (!in_impl_uuid || *in_impl_uuid != kDynamicsProcessingSwImplUUID) {
53 LOG(ERROR) << __func__ << "uuid not supported";
54 return EX_ILLEGAL_ARGUMENT;
Shunkai Yao6afc8552022-10-26 22:47:20 +000055 }
Shunkai Yaoc12e0822022-12-12 07:13:58 +000056 *_aidl_return = DynamicsProcessingSw::kDescriptor;
Shunkai Yao6afc8552022-10-26 22:47:20 +000057 return EX_NONE;
58}
59
60namespace aidl::android::hardware::audio::effect {
61
Shunkai Yaoc12e0822022-12-12 07:13:58 +000062const std::string DynamicsProcessingSw::kEffectName = "DynamicsProcessingSw";
63const DynamicsProcessing::Capability DynamicsProcessingSw::kCapability;
64const Descriptor DynamicsProcessingSw::kDescriptor = {
65 .common = {.id = {.type = kDynamicsProcessingTypeUUID,
66 .uuid = kDynamicsProcessingSwImplUUID,
67 .proxy = std::nullopt},
68 .flags = {.type = Flags::Type::INSERT,
69 .insert = Flags::Insert::FIRST,
70 .volume = Flags::Volume::CTRL},
71 .name = DynamicsProcessingSw::kEffectName,
72 .implementor = "The Android Open Source Project"},
73 .capability = Capability::make<Capability::dynamicsProcessing>(
74 DynamicsProcessingSw::kCapability)};
75
Shunkai Yao6afc8552022-10-26 22:47:20 +000076ndk::ScopedAStatus DynamicsProcessingSw::getDescriptor(Descriptor* _aidl_return) {
77 LOG(DEBUG) << __func__ << kDescriptor.toString();
78 *_aidl_return = kDescriptor;
79 return ndk::ScopedAStatus::ok();
80}
81
82ndk::ScopedAStatus DynamicsProcessingSw::setParameterSpecific(const Parameter::Specific& specific) {
83 RETURN_IF(Parameter::Specific::dynamicsProcessing != specific.getTag(), EX_ILLEGAL_ARGUMENT,
84 "EffectNotSupported");
Shunkai Yao6afc8552022-10-26 22:47:20 +000085
86 mSpecificParam = specific.get<Parameter::Specific::dynamicsProcessing>();
87 LOG(DEBUG) << __func__ << " success with: " << specific.toString();
88 return ndk::ScopedAStatus::ok();
89}
90
91ndk::ScopedAStatus DynamicsProcessingSw::getParameterSpecific(const Parameter::Id& id,
92 Parameter::Specific* specific) {
93 auto tag = id.getTag();
94 RETURN_IF(Parameter::Id::dynamicsProcessingTag != tag, EX_ILLEGAL_ARGUMENT, "wrongIdTag");
95 specific->set<Parameter::Specific::dynamicsProcessing>(mSpecificParam);
96 return ndk::ScopedAStatus::ok();
97}
98
99std::shared_ptr<EffectContext> DynamicsProcessingSw::createContext(
100 const Parameter::Common& common) {
101 if (mContext) {
102 LOG(DEBUG) << __func__ << " context already exist";
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530103 } else {
104 mContext = std::make_shared<DynamicsProcessingSwContext>(1 /* statusFmqDepth */, common);
Shunkai Yao6afc8552022-10-26 22:47:20 +0000105 }
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530106 return mContext;
107}
108
109std::shared_ptr<EffectContext> DynamicsProcessingSw::getContext() {
Shunkai Yao6afc8552022-10-26 22:47:20 +0000110 return mContext;
111}
112
113RetCode DynamicsProcessingSw::releaseContext() {
114 if (mContext) {
115 mContext.reset();
116 }
117 return RetCode::SUCCESS;
118}
119
120// Processing method running in EffectWorker thread.
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530121IEffect::Status DynamicsProcessingSw::effectProcessImpl(float* in, float* out, int samples) {
Shunkai Yao6afc8552022-10-26 22:47:20 +0000122 // TODO: get data buffer and process.
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530123 LOG(DEBUG) << __func__ << " in " << in << " out " << out << " samples " << samples;
124 for (int i = 0; i < samples; i++) {
Shunkai Yao6afc8552022-10-26 22:47:20 +0000125 *out++ = *in++;
126 }
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530127 return {STATUS_OK, samples, samples};
Shunkai Yao6afc8552022-10-26 22:47:20 +0000128}
129
130} // namespace aidl::android::hardware::audio::effect