blob: 6175b6b3464648569a3f4143a522c86b4fa2d726 [file] [log] [blame]
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -07001/*
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
Mikhail Naganova0c91332016-09-19 10:01:12 -070017#define LOG_TAG "EffectHalLocal"
Mikhail Naganove4f1f632016-08-31 11:35:10 -070018//#define LOG_NDEBUG 0
19
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -070020#include <utils/Log.h>
21
22#include "EffectHalLocal.h"
23
24namespace android {
25
26EffectHalLocal::EffectHalLocal(effect_handle_t handle)
27 : mHandle(handle) {
28}
29
30EffectHalLocal::~EffectHalLocal() {
31 int status = EffectRelease(mHandle);
Mikhail Naganove4f1f632016-08-31 11:35:10 -070032 ALOGW_IF(status, "Error releasing effect %p: %s", mHandle, strerror(-status));
33 mHandle = 0;
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -070034}
35
Mikhail Naganov022b9952017-01-04 16:36:51 -080036status_t EffectHalLocal::setInBuffer(const sp<EffectBufferHalInterface>& buffer) {
37 mInBuffer = buffer;
38 return OK;
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -070039}
40
Mikhail Naganov022b9952017-01-04 16:36:51 -080041status_t EffectHalLocal::setOutBuffer(const sp<EffectBufferHalInterface>& buffer) {
42 mOutBuffer = buffer;
43 return OK;
44}
45
46status_t EffectHalLocal::process() {
Mikhail Naganov2f607552017-01-11 16:09:03 -080047 if (mInBuffer == nullptr || mOutBuffer == nullptr) {
48 ALOGE_IF(mInBuffer == nullptr, "Input buffer not set");
49 ALOGE_IF(mOutBuffer == nullptr, "Output buffer not set");
50 return NO_INIT;
51 }
Mikhail Naganov022b9952017-01-04 16:36:51 -080052 return (*mHandle)->process(mHandle, mInBuffer->audioBuffer(), mOutBuffer->audioBuffer());
53}
54
55status_t EffectHalLocal::processReverse() {
56 if ((*mHandle)->process_reverse != NULL) {
Mikhail Naganov2f607552017-01-11 16:09:03 -080057 if (mInBuffer == nullptr || mOutBuffer == nullptr) {
58 ALOGE_IF(mInBuffer == nullptr, "Input buffer not set");
59 ALOGE_IF(mOutBuffer == nullptr, "Output buffer not set");
60 return NO_INIT;
61 }
Mikhail Naganov022b9952017-01-04 16:36:51 -080062 return (*mHandle)->process_reverse(
63 mHandle, mInBuffer->audioBuffer(), mOutBuffer->audioBuffer());
64 } else {
65 return INVALID_OPERATION;
66 }
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -070067}
68
69status_t EffectHalLocal::command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData,
70 uint32_t *replySize, void *pReplyData) {
71 return (*mHandle)->command(mHandle, cmdCode, cmdSize, pCmdData, replySize, pReplyData);
72}
73
74status_t EffectHalLocal::getDescriptor(effect_descriptor_t *pDescriptor) {
75 return (*mHandle)->get_descriptor(mHandle, pDescriptor);
76}
77
Mikhail Naganov022b9952017-01-04 16:36:51 -080078status_t EffectHalLocal::close() {
79 return OK;
80}
81
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -070082} // namespace android