blob: d2a94e4f75a7423ec940a2b6661380da44ed6527 [file] [log] [blame]
Shunkai Yao242521c2023-01-29 18:08:09 +00001/*
2 * Copyright (C) 2023 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 <cstdint>
18#include <cstring>
19#include <optional>
20#define LOG_TAG "AidlConversionSpatializer"
21//#define LOG_NDEBUG 0
22
23#include <error/expected_utils.h>
24#include <media/AidlConversionNdk.h>
25#include <media/AidlConversionEffect.h>
26#include <media/audiohal/AudioEffectUuid.h>
27#include <system/audio_effects/effect_spatializer.h>
28
29#include <utils/Log.h>
30
31#include "AidlConversionSpatializer.h"
32
33namespace android {
34namespace effect {
35
36using ::aidl::android::aidl_utils::statusTFromBinderStatus;
37using ::aidl::android::hardware::audio::effect::Parameter;
38using ::android::status_t;
39using utils::EffectParamReader;
40using utils::EffectParamWriter;
41
42status_t AidlConversionSpatializer::setParameter(EffectParamReader& param) {
Shunkai Yao04b073a2023-02-17 06:17:12 +000043 Parameter aidlParam = VALUE_OR_RETURN_STATUS(
44 ::aidl::android::legacy2aidl_EffectParameterReader_ParameterExtension(param));
Shunkai Yao242521c2023-01-29 18:08:09 +000045 return statusTFromBinderStatus(mEffect->setParameter(aidlParam));
46}
47
48status_t AidlConversionSpatializer::getParameter(EffectParamWriter& param) {
Shunkai Yao04b073a2023-02-17 06:17:12 +000049 Parameter aidlParam;
50 Parameter::Id id = UNION_MAKE(Parameter::Id, vendorEffectTag, 0 /* no tag */);
51 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam)));
52 const auto& extBytes = VALUE_OR_RETURN_STATUS(
53 ::aidl::android::aidl2legacy_ParameterExtension_vector_uint8(aidlParam));
54 if (param.getValueSize() < extBytes.size()) {
55 ALOGE("%s extension return data %zu exceed vsize %zu", __func__, extBytes.size(),
56 param.getValueSize());
Shunkai Yao242521c2023-01-29 18:08:09 +000057 param.setStatus(BAD_VALUE);
58 return BAD_VALUE;
59 }
Shunkai Yao04b073a2023-02-17 06:17:12 +000060 return param.writeToValue(extBytes.data(), extBytes.size());
Shunkai Yao242521c2023-01-29 18:08:09 +000061}
62
63} // namespace effect
64} // namespace android