Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 "EffectHalHidl" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include <media/EffectsFactoryApi.h> |
| 21 | #include <utils/Log.h> |
| 22 | |
Mikhail Naganov | 9f57e3c | 2016-12-05 12:54:36 -0800 | [diff] [blame] | 23 | #include "ConversionHelperHidl.h" |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 24 | #include "EffectHalHidl.h" |
| 25 | #include "HidlUtils.h" |
| 26 | |
| 27 | using ::android::hardware::audio::effect::V2_0::Result; |
| 28 | using ::android::hardware::hidl_vec; |
| 29 | using ::android::hardware::Return; |
| 30 | using ::android::hardware::Status; |
| 31 | |
| 32 | namespace android { |
| 33 | |
| 34 | EffectHalHidl::EffectHalHidl(const sp<IEffect>& effect, uint64_t effectId) |
| 35 | : mEffect(effect), mEffectId(effectId) { |
| 36 | } |
| 37 | |
| 38 | EffectHalHidl::~EffectHalHidl() { |
| 39 | } |
| 40 | |
| 41 | // static |
| 42 | void EffectHalHidl::effectDescriptorToHal( |
| 43 | const EffectDescriptor& descriptor, effect_descriptor_t* halDescriptor) { |
| 44 | HidlUtils::uuidToHal(descriptor.type, &halDescriptor->type); |
| 45 | HidlUtils::uuidToHal(descriptor.uuid, &halDescriptor->uuid); |
| 46 | halDescriptor->flags = static_cast<uint32_t>(descriptor.flags); |
| 47 | halDescriptor->cpuLoad = descriptor.cpuLoad; |
| 48 | halDescriptor->memoryUsage = descriptor.memoryUsage; |
| 49 | memcpy(halDescriptor->name, descriptor.name.data(), descriptor.name.size()); |
| 50 | memcpy(halDescriptor->implementor, |
| 51 | descriptor.implementor.data(), descriptor.implementor.size()); |
| 52 | } |
| 53 | |
| 54 | // static |
| 55 | status_t EffectHalHidl::analyzeResult(const Result& result) { |
| 56 | switch (result) { |
| 57 | case Result::OK: return OK; |
| 58 | case Result::INVALID_ARGUMENTS: return BAD_VALUE; |
| 59 | case Result::INVALID_STATE: return NOT_ENOUGH_DATA; |
| 60 | case Result::NOT_INITIALIZED: return NO_INIT; |
| 61 | case Result::NOT_SUPPORTED: return INVALID_OPERATION; |
| 62 | case Result::RESULT_TOO_BIG: return NO_MEMORY; |
| 63 | default: return NO_INIT; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | status_t EffectHalHidl::process(audio_buffer_t */*inBuffer*/, audio_buffer_t */*outBuffer*/) { |
| 68 | // Idea -- intercept set buffer config command, capture audio format, use it |
| 69 | // for determining frame size in bytes on input and output. |
| 70 | return OK; |
| 71 | } |
| 72 | |
| 73 | status_t EffectHalHidl::processReverse(audio_buffer_t */*inBuffer*/, audio_buffer_t */*outBuffer*/) { |
| 74 | return OK; |
| 75 | } |
| 76 | |
| 77 | status_t EffectHalHidl::command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData, |
| 78 | uint32_t *replySize, void *pReplyData) { |
| 79 | if (mEffect == 0) return NO_INIT; |
| 80 | hidl_vec<uint8_t> hidlData; |
| 81 | hidlData.setToExternal(reinterpret_cast<uint8_t*>(pCmdData), cmdSize); |
| 82 | status_t status; |
| 83 | Return<void> ret = mEffect->command(cmdCode, hidlData, *replySize, |
| 84 | [&](int32_t s, const hidl_vec<uint8_t>& result) { |
| 85 | status = s; |
| 86 | if (status == 0) { |
| 87 | if (*replySize > result.size()) *replySize = result.size(); |
| 88 | if (pReplyData && *replySize > 0) { |
| 89 | memcpy(pReplyData, &result[0], *replySize); |
| 90 | } |
| 91 | } |
| 92 | }); |
| 93 | return status; |
| 94 | } |
| 95 | |
| 96 | status_t EffectHalHidl::getDescriptor(effect_descriptor_t *pDescriptor) { |
| 97 | if (mEffect == 0) return NO_INIT; |
| 98 | Result retval = Result::NOT_INITIALIZED; |
| 99 | Return<void> ret = mEffect->getDescriptor( |
| 100 | [&](Result r, const EffectDescriptor& result) { |
| 101 | retval = r; |
| 102 | if (retval == Result::OK) { |
| 103 | effectDescriptorToHal(result, pDescriptor); |
| 104 | } |
| 105 | }); |
Steven Moreland | e83be8a | 2017-01-06 11:06:33 -0800 | [diff] [blame^] | 106 | return ret.isOk() ? analyzeResult(retval) : UNKNOWN_ERROR; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | } // namespace android |