blob: ab5add5d359d7f11b5d0d78aa3e7388c927f3312 [file] [log] [blame]
/*
* Copyright (C) 2015, Samsung Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "ExynosVpuKernelThreshold"
#include <cutils/log.h>
#include "ExynosVpuKernelThreshold.h"
#include "vpu_kernel_util.h"
#include "td-binary-threshold.h"
namespace android {
using namespace std;
static vx_uint16 td_binary[] =
TASK_test_binary_threshold_from_VDE_DS;
vx_status
ExynosVpuKernelThreshold::inputValidator(vx_node node, vx_uint32 index)
{
vx_status status = VX_ERROR_INVALID_PARAMETERS;
if (index == 0) {
vx_parameter param = vxGetParameterByIndex(node, index);
if (param) {
vx_image input = 0;
vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &input, sizeof(input));
if (input) {
vx_df_image format = 0;
vxQueryImage(input, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format));
if (format == VX_DF_IMAGE_U8) {
status = VX_SUCCESS;
} else {
status = VX_ERROR_INVALID_FORMAT;
}
vxReleaseImage(&input);
}
vxReleaseParameter(&param);
}
} else if (index == 1) {
vx_parameter param = vxGetParameterByIndex(node, index);
if (param) {
vx_threshold threshold = 0;
vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &threshold, sizeof(threshold));
if (threshold) {
vx_enum type = 0;
vxQueryThreshold(threshold, VX_THRESHOLD_ATTRIBUTE_TYPE, &type, sizeof(type));
if ((type == VX_THRESHOLD_TYPE_BINARY) ||
(type == VX_THRESHOLD_TYPE_RANGE)) {
status = VX_SUCCESS;
} else {
status = VX_ERROR_INVALID_TYPE;
}
vxReleaseThreshold(&threshold);
}
vxReleaseParameter(&param);
}
}
return status;
}
vx_status
ExynosVpuKernelThreshold::outputValidator(vx_node node, vx_uint32 index, vx_meta_format meta)
{
vx_status status = VX_ERROR_INVALID_PARAMETERS;
if (index == 2) {
vx_parameter src_param = vxGetParameterByIndex(node, 0);
if (src_param) {
vx_image src = 0;
vxQueryParameter(src_param, VX_PARAMETER_ATTRIBUTE_REF, &src, sizeof(src));
if (src) {
vx_uint32 width = 0, height = 0;
vxQueryImage(src, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(height));
vxQueryImage(src, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height));
/* fill in the meta data with the attributes so that the checker will pass */
vx_df_image meta_format = VX_DF_IMAGE_U8;
vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &meta_format, sizeof(meta_format));
vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width));
vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height));
status = VX_SUCCESS;
vxReleaseImage(&src);
}
vxReleaseParameter(&src_param);
}
}
return status;
}
ExynosVpuKernelThreshold::ExynosVpuKernelThreshold(vx_char *name, vx_uint32 param_num)
: ExynosVpuKernel(name, param_num)
{
strcpy(m_task_name, "threshold");
}
ExynosVpuKernelThreshold::~ExynosVpuKernelThreshold(void)
{
}
vx_status
ExynosVpuKernelThreshold::setupBaseVxInfo(const vx_reference parameters[])
{
vx_status status = VX_FAILURE;
vx_image input = (vx_image)parameters[0];
status = vxGetValidAncestorRegionImage(input, &m_valid_rect);
if (status != VX_SUCCESS) {
VXLOGE("getting valid region fails, err:%d", status);
}
return status;
}
vx_status
ExynosVpuKernelThreshold::initTask(vx_node node, const vx_reference *parameters)
{
vx_status status;
#if 1
status = initTaskFromBinary();
if (status != VX_SUCCESS) {
VXLOGE("init task from binary fails, %p, %p", node, parameters);
goto EXIT;
}
#else
status = initTaskFromApi();
if (status != VX_SUCCESS) {
VXLOGE("init task from api fails, %p, %p", node, parameters);
goto EXIT;
}
#endif
EXIT:
return status;
}
vx_status
ExynosVpuKernelThreshold::initTaskFromBinary(void)
{
vx_status status = VX_SUCCESS;
ExynosVpuTaskIf *task_if_0;
task_if_0 = initTask0FromBinary();
if (task_if_0 == NULL) {
VXLOGE("task0 isn't created");
status = VX_FAILURE;
goto EXIT;
}
EXIT:
return status;
}
ExynosVpuTaskIf*
ExynosVpuKernelThreshold::initTask0FromBinary(void)
{
vx_status status = VX_SUCCESS;
int ret = NO_ERROR;
ExynosVpuTaskIfWrapper *task_wr = new ExynosVpuTaskIfWrapper(this, 0);
status = setTaskIfWrapper(0, task_wr);
if (status != VX_SUCCESS) {
VXLOGE("adding taskif wrapper fails");
return NULL;
}
ExynosVpuTaskIf *task_if = task_wr->getTaskIf();
ret = task_if->importTaskStr((struct vpul_task*)td_binary);
if (ret != NO_ERROR) {
VXLOGE("creating task descriptor fails, ret:%d", ret);
status = VX_FAILURE;
}
/* connect pu to io */
task_if->setIoPu(VS4L_DIRECTION_IN, 0, (uint32_t)0);
task_if->setIoPu(VS4L_DIRECTION_OT, 0, (uint32_t)2);
if (status == VX_SUCCESS)
return task_if;
else
return NULL;
}
vx_status
ExynosVpuKernelThreshold::initTaskFromApi(void)
{
vx_status status = VX_SUCCESS;
ExynosVpuTaskIf *task_if_0;
task_if_0 = initTask0FromApi();
if (task_if_0 == NULL) {
VXLOGE("task0 isn't created");
status = VX_FAILURE;
goto EXIT;
}
status = createStrFromObjectOfTask();
if (status != VX_SUCCESS) {
VXLOGE("creating task str fails");
goto EXIT;
}
EXIT:
return status;
}
ExynosVpuTaskIf*
ExynosVpuKernelThreshold::initTask0FromApi(void)
{
vx_status status = VX_SUCCESS;
ExynosVpuPuFactory pu_factory;
ExynosVpuTaskIfWrapper *task_wr = new ExynosVpuTaskIfWrapper(this, 0);
status = setTaskIfWrapper(0, task_wr);
if (status != VX_SUCCESS) {
VXLOGE("adding taskif wrapper fails");
return NULL;
}
ExynosVpuTaskIf *task_if = task_wr->getTaskIf();
ExynosVpuTask *task = new ExynosVpuTask(task_if);
struct vpul_task *task_param = task->getTaskInfo();
task_param->priority = m_priority;
ExynosVpuVertex *start_vertex = new ExynosVpuVertex(task, VPUL_VERTEXT_START);
ExynosVpuProcess *salb_process = new ExynosVpuProcess(task);
ExynosVpuVertex *end_vertex = new ExynosVpuVertex(task, VPUL_VERTEXT_END);
ExynosVpuVertex::connect(start_vertex, salb_process);
ExynosVpuVertex::connect(salb_process, end_vertex);
ExynosVpuIoSizeInout *iosize = new ExynosVpuIoSizeInout(salb_process);
/* define subchain */
ExynosVpuSubchainHw *salb_subchain = new ExynosVpuSubchainHw(salb_process);
/* define pu */
ExynosVpuPu *dma_in = pu_factory.createPu(salb_subchain, VPU_PU_DMAIN0);
dma_in->setSize(iosize, iosize);
ExynosVpuPu *salb = pu_factory.createPu(salb_subchain, VPU_PU_SALB0);
salb->setSize(iosize, iosize);
ExynosVpuPu *dma_out = pu_factory.createPu(salb_subchain, VPU_PU_DMAOT0);
dma_out->setSize(iosize, iosize);
ExynosVpuPu::connect(dma_in, 0, salb, 0);
ExynosVpuPu::connect(salb, 0, dma_out, 0);
struct vpul_pu_dma *dma_in_param = (struct vpul_pu_dma*)dma_in->getParameter();
struct vpul_pu_salb *salb_param = (struct vpul_pu_salb*)salb->getParameter();
struct vpul_pu_dma *dma_out_param = (struct vpul_pu_dma*)dma_out->getParameter();
salb_param->input_enable = 1;
salb_param->operation_code = 16;
salb_param->salbregs_custom_trunc_bittage= 1;
/* connect pu to io */
ExynosVpuIoExternalMem *io_external_mem;
ExynosVpuMemmapExternal *memmap;
ExynosVpuIoFixedMapRoi *fixed_roi;
ExynosVpuIoTypesDesc *iotyps;
io_external_mem = new ExynosVpuIoExternalMem(task);
memmap = new ExynosVpuMemmapExternal(task, io_external_mem);
fixed_roi = new ExynosVpuIoFixedMapRoi(salb_process, memmap);
iotyps = new ExynosVpuIoTypesDesc(salb_process, fixed_roi);
dma_in->setIoTypesDesc(iotyps);
io_external_mem = new ExynosVpuIoExternalMem(task);
memmap = new ExynosVpuMemmapExternal(task, io_external_mem);
fixed_roi = new ExynosVpuIoFixedMapRoi(salb_process, memmap);
iotyps = new ExynosVpuIoTypesDesc(salb_process, fixed_roi);
dma_out->setIoTypesDesc(iotyps);
status_t ret = NO_ERROR;
ret |= task_if->setIoPu(VS4L_DIRECTION_IN, 0, dma_in);
ret |= task_if->setIoPu(VS4L_DIRECTION_OT, 0, dma_out);
if (ret != NO_ERROR) {
VXLOGE("connectting pu to io fails");
status = VX_FAILURE;
goto EXIT;
}
EXIT:
if (status == VX_SUCCESS)
return task_if;
else
return NULL;
}
vx_status
ExynosVpuKernelThreshold::updateTaskParamFromVX(vx_node node, const vx_reference *parameters)
{
vx_status status = VX_SUCCESS;
if (!node)
VXLOGE("invalid node, %p, %p", node, parameters);
/* update vpu param from vx param */
vx_threshold threshold = (vx_threshold)parameters[1];
vx_enum type;
status = vxQueryThreshold(threshold, VX_THRESHOLD_ATTRIBUTE_TYPE, &type, sizeof(type));
if (status != VX_SUCCESS) {
VXLOGE("querying threshold fails");
goto EXIT;
}
ExynosVpuPu *salb;
salb = getTask(0)->getPu(VPU_PU_SALB0, 1, 0);
if (salb == NULL) {
VXLOGE("getting pu fails");
status = VX_FAILURE;
goto EXIT;
}
struct vpul_pu_salb *salb_param;
salb_param = (struct vpul_pu_salb*)salb->getParameter();
switch (type) {
case VX_THRESHOLD_TYPE_BINARY:
vx_int32 threshold_value;
vxQueryThreshold(threshold, VX_THRESHOLD_ATTRIBUTE_THRESHOLD_VALUE, &threshold_value, sizeof(threshold_value));
salb_param->thresh_lo = salb_param->thresh_hi = threshold_value;
salb_param->val_hi = 255;
salb_param->val_lo = 0;
break;
case VX_THRESHOLD_TYPE_RANGE:
vx_int32 threshold_hi, threshold_lo;
vxQueryThreshold(threshold, VX_THRESHOLD_ATTRIBUTE_THRESHOLD_UPPER, &threshold_hi, sizeof(threshold_hi));
vxQueryThreshold(threshold, VX_THRESHOLD_ATTRIBUTE_THRESHOLD_LOWER, &threshold_lo, sizeof(threshold_lo));
salb_param->thresh_hi = threshold_hi;
salb_param->thresh_lo = threshold_lo;
salb_param->val_hi = 0;
salb_param->val_lo = 0;
salb_param->org_val_med = 0;
salb_param->val_med_filler = 255;
break;
default:
VXLOGE("un-supported type, 0x%x", type);
goto EXIT;
break;
}
EXIT:
return status;
}
vx_status
ExynosVpuKernelThreshold::initVxIo(const vx_reference *parameters)
{
vx_status status = VX_SUCCESS;
ExynosVpuTaskIfWrapper *task_wr_0 = m_task_wr_list[0];
/* connect vx param to io */
vx_param_info_t param_info;
memset(&param_info, 0x0, sizeof(param_info));
param_info.image.plane = 0;
status = task_wr_0->setIoVxParam(VS4L_DIRECTION_IN, 0, 0, param_info);
if (status != VX_SUCCESS) {
VXLOGE("assigning param fails, %p", parameters);
goto EXIT;
}
param_info.image.plane = 0;
status = task_wr_0->setIoVxParam(VS4L_DIRECTION_OT, 0, 2, param_info);
if (status != VX_SUCCESS) {
VXLOGE("assigning param fails, %p", parameters);
goto EXIT;
}
EXIT:
return status;
}
}; /* namespace android */