Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 33 | namespace android { |
| 34 | namespace effect { |
| 35 | |
| 36 | using ::aidl::android::aidl_utils::statusTFromBinderStatus; |
| 37 | using ::aidl::android::hardware::audio::effect::Parameter; |
| 38 | using ::android::status_t; |
| 39 | using utils::EffectParamReader; |
| 40 | using utils::EffectParamWriter; |
| 41 | |
| 42 | status_t AidlConversionSpatializer::setParameter(EffectParamReader& param) { |
Shunkai Yao | 04b073a | 2023-02-17 06:17:12 +0000 | [diff] [blame^] | 43 | Parameter aidlParam = VALUE_OR_RETURN_STATUS( |
| 44 | ::aidl::android::legacy2aidl_EffectParameterReader_ParameterExtension(param)); |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 45 | return statusTFromBinderStatus(mEffect->setParameter(aidlParam)); |
| 46 | } |
| 47 | |
| 48 | status_t AidlConversionSpatializer::getParameter(EffectParamWriter& param) { |
Shunkai Yao | 04b073a | 2023-02-17 06:17:12 +0000 | [diff] [blame^] | 49 | 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 Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 57 | param.setStatus(BAD_VALUE); |
| 58 | return BAD_VALUE; |
| 59 | } |
Shunkai Yao | 04b073a | 2023-02-17 06:17:12 +0000 | [diff] [blame^] | 60 | return param.writeToValue(extBytes.data(), extBytes.size()); |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | } // namespace effect |
| 64 | } // namespace android |