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 "EffectHalLocal" 18//#define LOG_NDEBUG 0 19 20#include <media/EffectsFactoryApi.h> 21#include <utils/Log.h> 22 23#include "EffectHalLocal.h" 24 25namespace android { 26 27EffectHalLocal::EffectHalLocal(effect_handle_t handle) 28 : mHandle(handle) { 29} 30 31EffectHalLocal::~EffectHalLocal() { 32 int status = EffectRelease(mHandle); 33 ALOGW_IF(status, "Error releasing effect %p: %s", mHandle, strerror(-status)); 34 mHandle = 0; 35} 36 37status_t EffectHalLocal::setInBuffer(const sp<EffectBufferHalInterface>& buffer) { 38 mInBuffer = buffer; 39 return OK; 40} 41 42status_t EffectHalLocal::setOutBuffer(const sp<EffectBufferHalInterface>& buffer) { 43 mOutBuffer = buffer; 44 return OK; 45} 46 47status_t EffectHalLocal::process() { 48 if (mInBuffer == nullptr || mOutBuffer == nullptr) { 49 ALOGE_IF(mInBuffer == nullptr, "Input buffer not set"); 50 ALOGE_IF(mOutBuffer == nullptr, "Output buffer not set"); 51 return NO_INIT; 52 } 53 return (*mHandle)->process(mHandle, mInBuffer->audioBuffer(), mOutBuffer->audioBuffer()); 54} 55 56status_t EffectHalLocal::processReverse() { 57 if ((*mHandle)->process_reverse != NULL) { 58 if (mInBuffer == nullptr || mOutBuffer == nullptr) { 59 ALOGE_IF(mInBuffer == nullptr, "Input buffer not set"); 60 ALOGE_IF(mOutBuffer == nullptr, "Output buffer not set"); 61 return NO_INIT; 62 } 63 return (*mHandle)->process_reverse( 64 mHandle, mInBuffer->audioBuffer(), mOutBuffer->audioBuffer()); 65 } else { 66 return INVALID_OPERATION; 67 } 68} 69 70status_t EffectHalLocal::command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData, 71 uint32_t *replySize, void *pReplyData) { 72 return (*mHandle)->command(mHandle, cmdCode, cmdSize, pCmdData, replySize, pReplyData); 73} 74 75status_t EffectHalLocal::getDescriptor(effect_descriptor_t *pDescriptor) { 76 return (*mHandle)->get_descriptor(mHandle, pDescriptor); 77} 78 79status_t EffectHalLocal::close() { 80 return OK; 81} 82 83} // namespace android 84