blob: 1cd1997acf7771386e220291c2e536bb1c8345be [file] [log] [blame]
Mikhail Naganovf558e022016-11-14 17:45:17 -08001/*
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 Naganov9f57e3c2016-12-05 12:54:36 -080023#include "ConversionHelperHidl.h"
Mikhail Naganovf558e022016-11-14 17:45:17 -080024#include "EffectHalHidl.h"
25#include "HidlUtils.h"
26
27using ::android::hardware::audio::effect::V2_0::Result;
28using ::android::hardware::hidl_vec;
29using ::android::hardware::Return;
30using ::android::hardware::Status;
31
32namespace android {
33
34EffectHalHidl::EffectHalHidl(const sp<IEffect>& effect, uint64_t effectId)
35 : mEffect(effect), mEffectId(effectId) {
36}
37
38EffectHalHidl::~EffectHalHidl() {
39}
40
41// static
42void 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
55status_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
67status_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
73status_t EffectHalHidl::processReverse(audio_buffer_t */*inBuffer*/, audio_buffer_t */*outBuffer*/) {
74 return OK;
75}
76
77status_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
96status_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 });
Mikhail Naganov9f57e3c2016-12-05 12:54:36 -0800106 ConversionHelperHidl::crashIfHalIsDead(ret.getStatus());
Mikhail Naganovf558e022016-11-14 17:45:17 -0800107 return ret.getStatus().isOk() ? analyzeResult(retval) : ret.getStatus().transactionError();
108}
109
110} // namespace android