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