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 | |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 23 | #include <aidl/android/hardware/audio/effect/DefaultExtension.h> |
| 24 | #include <aidl/android/hardware/audio/effect/VendorExtension.h> |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 25 | #include <error/expected_utils.h> |
| 26 | #include <media/AidlConversionNdk.h> |
| 27 | #include <media/AidlConversionEffect.h> |
| 28 | #include <media/audiohal/AudioEffectUuid.h> |
| 29 | #include <system/audio_effects/effect_spatializer.h> |
| 30 | |
| 31 | #include <utils/Log.h> |
| 32 | |
| 33 | #include "AidlConversionSpatializer.h" |
| 34 | |
| 35 | namespace android { |
| 36 | namespace effect { |
| 37 | |
| 38 | using ::aidl::android::aidl_utils::statusTFromBinderStatus; |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 39 | using ::aidl::android::hardware::audio::effect::DefaultExtension; |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 40 | using ::aidl::android::hardware::audio::effect::Parameter; |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 41 | using ::aidl::android::hardware::audio::effect::VendorExtension; |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 42 | using ::android::status_t; |
| 43 | using utils::EffectParamReader; |
| 44 | using utils::EffectParamWriter; |
| 45 | |
| 46 | status_t AidlConversionSpatializer::setParameter(EffectParamReader& param) { |
Shunkai Yao | 04b073a | 2023-02-17 06:17:12 +0000 | [diff] [blame] | 47 | Parameter aidlParam = VALUE_OR_RETURN_STATUS( |
| 48 | ::aidl::android::legacy2aidl_EffectParameterReader_ParameterExtension(param)); |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 49 | return statusTFromBinderStatus(mEffect->setParameter(aidlParam)); |
| 50 | } |
| 51 | |
| 52 | status_t AidlConversionSpatializer::getParameter(EffectParamWriter& param) { |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 53 | DefaultExtension defaultExt; |
| 54 | // read parameters into DefaultExtension vector<uint8_t> |
| 55 | if (OK != param.readFromParameter(defaultExt.bytes.data(), param.getParameterSize())) { |
| 56 | ALOGE("%s invalid param %s", __func__, param.toString().c_str()); |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 57 | param.setStatus(BAD_VALUE); |
| 58 | return BAD_VALUE; |
| 59 | } |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 60 | |
| 61 | VendorExtension idTag; |
| 62 | idTag.extension.setParcelable(defaultExt); |
| 63 | Parameter::Id id = UNION_MAKE(Parameter::Id, vendorEffectTag, idTag); |
| 64 | Parameter aidlParam; |
| 65 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam))); |
| 66 | // copy the AIDL extension data back to effect_param_t |
| 67 | return VALUE_OR_RETURN_STATUS( |
| 68 | ::aidl::android::aidl2legacy_ParameterExtension_EffectParameterWriter(aidlParam, |
| 69 | param)); |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | } // namespace effect |
| 73 | } // namespace android |