post_proc: Add support for non-tunnel DSP audio effects
Add hw accelerator module to send PCM data to DSP and get
back the effects processed data.
Expose a wrapper library for AudioFlinger to be able use the new
module to apply the DSP audio effects.
Change-Id: I6ee30c11f04a97b35f12201fb61b8cd901921e68
Signed-off-by: Alexy Joseph <alexyj@codeaurora.org>
diff --git a/post_proc/bundle.c b/post_proc/bundle.c
index a0a6765..871b087 100644
--- a/post_proc/bundle.c
+++ b/post_proc/bundle.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
* Not a Contribution.
*
* Copyright (C) 2013 The Android Open Source Project
@@ -36,7 +36,7 @@
*/
#define LOG_TAG "offload_effect_bundle"
-#define LOG_NDEBUG 0
+//#define LOG_NDEBUG 0
#include <cutils/list.h>
#include <cutils/log.h>
@@ -45,6 +45,7 @@
#include <hardware/audio_effect.h>
#include "bundle.h"
+#include "hw_accelerator.h"
#include "equalizer.h"
#include "bass_boost.h"
#include "virtualizer.h"
@@ -68,6 +69,7 @@
&ins_env_reverb_descriptor,
&aux_preset_reverb_descriptor,
&ins_preset_reverb_descriptor,
+ &hw_accelerator_descriptor,
NULL,
};
@@ -243,6 +245,7 @@
if (!out_ctxt->mixer) {
ALOGE("Failed to open mixer");
out_ctxt->ctl = NULL;
+ out_ctxt->ref_ctl = NULL;
ret = -EINVAL;
free(out_ctxt);
goto exit;
@@ -256,6 +259,7 @@
free(out_ctxt);
goto exit;
}
+ out_ctxt->ref_ctl = out_ctxt->ctl;
}
list_init(&out_ctxt->effects_list);
@@ -322,7 +326,6 @@
return ret;
}
-
/*
* Effect operations
*/
@@ -381,6 +384,7 @@
context->ops.set_parameter = equalizer_set_parameter;
context->ops.get_parameter = equalizer_get_parameter;
context->ops.set_device = equalizer_set_device;
+ context->ops.set_hw_acc_mode = equalizer_set_mode;
context->ops.enable = equalizer_enable;
context->ops.disable = equalizer_disable;
context->ops.start = equalizer_start;
@@ -401,6 +405,7 @@
context->ops.set_parameter = bassboost_set_parameter;
context->ops.get_parameter = bassboost_get_parameter;
context->ops.set_device = bassboost_set_device;
+ context->ops.set_hw_acc_mode = bassboost_set_mode;
context->ops.enable = bassboost_enable;
context->ops.disable = bassboost_disable;
context->ops.start = bassboost_start;
@@ -421,6 +426,7 @@
context->ops.set_parameter = virtualizer_set_parameter;
context->ops.get_parameter = virtualizer_get_parameter;
context->ops.set_device = virtualizer_set_device;
+ context->ops.set_hw_acc_mode = virtualizer_set_mode;
context->ops.enable = virtualizer_enable;
context->ops.disable = virtualizer_disable;
context->ops.start = virtualizer_start;
@@ -447,6 +453,7 @@
context->ops.set_parameter = reverb_set_parameter;
context->ops.get_parameter = reverb_get_parameter;
context->ops.set_device = reverb_set_device;
+ context->ops.set_hw_acc_mode = reverb_set_mode;
context->ops.enable = reverb_enable;
context->ops.disable = reverb_disable;
context->ops.start = reverb_start;
@@ -459,7 +466,7 @@
} else if (memcmp(uuid, &ins_env_reverb_descriptor.uuid,
sizeof(effect_uuid_t)) == 0) {
context->desc = &ins_env_reverb_descriptor;
- reverb_preset_init(reverb_ctxt);
+ reverb_insert_init(reverb_ctxt);
} else if (memcmp(uuid, &aux_preset_reverb_descriptor.uuid,
sizeof(effect_uuid_t)) == 0) {
context->desc = &aux_preset_reverb_descriptor;
@@ -470,6 +477,27 @@
reverb_preset_init(reverb_ctxt);
}
reverb_ctxt->ctl = NULL;
+ } else if (memcmp(uuid, &hw_accelerator_descriptor.uuid,
+ sizeof(effect_uuid_t)) == 0) {
+ hw_accelerator_context_t *hw_acc_ctxt = (hw_accelerator_context_t *)
+ calloc(1, sizeof(hw_accelerator_context_t));
+ if (hw_acc_ctxt == NULL) {
+ ALOGE("h/w acc context allocation failed");
+ return -ENOMEM;
+ }
+ context = (effect_context_t *)hw_acc_ctxt;
+ context->ops.init = hw_accelerator_init;
+ context->ops.reset = hw_accelerator_reset;
+ context->ops.set_parameter = hw_accelerator_set_parameter;
+ context->ops.get_parameter = hw_accelerator_get_parameter;
+ context->ops.set_device = hw_accelerator_set_device;
+ context->ops.set_hw_acc_mode = hw_accelerator_set_mode;
+ context->ops.enable = hw_accelerator_enable;
+ context->ops.disable = hw_accelerator_disable;
+ context->ops.release = hw_accelerator_release;
+ context->ops.process = hw_accelerator_process;
+
+ context->desc = &hw_accelerator_descriptor;
} else {
return -EINVAL;
}
@@ -557,6 +585,7 @@
*/
/* Stub function for effect interface: never called for offloaded effects */
+/* called for hw accelerated effects */
int effect_process(effect_handle_t self,
audio_buffer_t *inBuffer,
audio_buffer_t *outBuffer)
@@ -564,7 +593,7 @@
effect_context_t * context = (effect_context_t *)self;
int status = 0;
- ALOGW("%s: ctxt %p, Called ?????", __func__, context);
+ ALOGV("%s", __func__);
pthread_mutex_lock(&lock);
if (!effect_exists(context)) {
@@ -577,6 +606,8 @@
goto exit;
}
+ if (context->ops.process)
+ status = context->ops.process(context, inBuffer, outBuffer);
exit:
pthread_mutex_unlock(&lock);
return status;
@@ -628,7 +659,7 @@
status = -EINVAL;
goto exit;
}
- if (!context->offload_enabled) {
+ if (!context->offload_enabled && !context->hw_acc_enabled) {
status = -EINVAL;
goto exit;
}
@@ -678,7 +709,7 @@
cmdSize, *replySize);
goto exit;
}
- if (!context->offload_enabled) {
+ if (!context->offload_enabled && !context->hw_acc_enabled) {
status = -EINVAL;
goto exit;
}
@@ -753,7 +784,20 @@
} break;
+ case EFFECT_CMD_HW_ACC: {
+ ALOGV("EFFECT_CMD_HW_ACC cmdSize %d pCmdData %p, *replySize %d, pReplyData %p",
+ cmdSize, pCmdData, *replySize, pReplyData);
+ if (cmdSize != sizeof(uint32_t) || pCmdData == NULL
+ || pReplyData == NULL || *replySize != sizeof(int)) {
+ return -EINVAL;
+ }
+ uint32_t value = *(uint32_t *)pCmdData;
+ if (context->ops.set_hw_acc_mode)
+ context->ops.set_hw_acc_mode(context, value);
+ context->hw_acc_enabled = (value > 0) ? true : false;
+ break;
+ }
default:
if (cmdCode >= EFFECT_CMD_FIRST_PROPRIETARY && context->ops.command)
status = context->ops.command(context, cmdCode, cmdSize,