1 /*
2 * rk_aiq_algo_aeis_itf.c
3 *
4 * Copyright (c) 2021 Rockchip Electronics Co., Ltd
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Cody Xie <cody.xie@rock-chips.com>
19 */
20
21 #include "aeis/rk_aiq_algo_aeis_itf.h"
22
23 #include <memory>
24 #include <fstream>
25
26 #include "aeis/rk_aiq_types_aeis_algo_prvt.h"
27 #include "drm_device.h"
28 #include "drm_buffer.h"
29 //#include "dma_buffer.h"
30 #include "dma_video_buffer.h"
31 #include "dvs_app.h"
32 #include "remap_backend.h"
33 #include "unistd.h"
34 #include "xcam_common.h"
35 #include "xcam_log.h"
36 #include "imu_service.h"
37 #include "video_buffer.h"
38 #include "image_processor.h"
39 #include "scaler_service.h"
40 #include "eis_algo_service.h"
41 #include "RkAiqCalibDbV2Helper.h"
42
43 using namespace RkCam;
44 using namespace XCam;
45
46 RKAIQ_BEGIN_DECLARE
47
create_context(RkAiqAlgoContext ** context,const AlgoCtxInstanceCfg * cfg)48 static XCamReturn create_context(RkAiqAlgoContext** context, const AlgoCtxInstanceCfg* cfg) {
49 RkAiqAlgoContext* ctx = new RkAiqAlgoContext();
50 if (ctx == nullptr) {
51 LOGE_AEIS("create aeis context fail!");
52 return XCAM_RETURN_ERROR_MEM;
53 }
54
55 auto adaptor = new EisAlgoAdaptor();
56 if (adaptor == nullptr) {
57 LOGE_AEIS("create aeis handle fail!");
58 delete ctx;
59 return XCAM_RETURN_ERROR_MEM;
60 }
61
62 CalibDbV2_Eis_t* calib_eis =
63 (CalibDbV2_Eis_t*)(CALIBDBV2_GET_MODULE_PTR(cfg->calibv2, eis_calib));
64 adaptor->Config(cfg, calib_eis);
65
66 ctx->handle = static_cast<void*>(adaptor);
67 *context = ctx;
68
69 return XCAM_RETURN_NO_ERROR;
70 }
71
destroy_context(RkAiqAlgoContext * context)72 static XCamReturn destroy_context(RkAiqAlgoContext* context) {
73 if (context) {
74 if (context->handle) {
75 EisAlgoAdaptor* adaptor = static_cast<EisAlgoAdaptor*>(context->handle);
76 delete adaptor;
77 context->handle = nullptr;
78 }
79 delete context;
80 }
81 return XCAM_RETURN_NO_ERROR;
82 }
83
prepare(RkAiqAlgoCom * params)84 static XCamReturn prepare(RkAiqAlgoCom* params) {
85 EisAlgoAdaptor* adaptor = static_cast<EisAlgoAdaptor*>(params->ctx->handle);
86 RkAiqAlgoConfigAeis* config = (RkAiqAlgoConfigAeis*)params;
87
88 return adaptor->Prepare(config->mems_sensor_intf, config->mem_ops);
89 }
90
pre_process(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)91 static XCamReturn pre_process(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams) {
92
93 return XCAM_RETURN_NO_ERROR;
94 }
95
processing(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)96 static XCamReturn processing(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams) {
97 RkAiqAlgoProcAeis* input = (RkAiqAlgoProcAeis*)(inparams);
98 RkAiqAlgoProcResAeis* output = (RkAiqAlgoProcResAeis*)outparams;
99 EisAlgoAdaptor* adaptor = static_cast<EisAlgoAdaptor*>(inparams->ctx->handle);
100
101 if (!adaptor->IsEnabled()) {
102 return XCAM_RETURN_NO_ERROR;
103 }
104
105 if (!adaptor->IsValid()) {
106 return XCAM_RETURN_BYPASS;
107 }
108
109 adaptor->Start();
110
111 output->fec_en = true;
112
113 adaptor->GetProcResult(output);
114
115 adaptor->OnFrameEvent(input);
116
117 return XCAM_RETURN_NO_ERROR;
118 }
119
post_process(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)120 static XCamReturn post_process(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams) {
121 return XCAM_RETURN_NO_ERROR;
122 }
123
124 RkAiqAlgoDescription g_RkIspAlgoDescAeis = {
125 .common =
126 {
127 .version = RKISP_ALGO_AEIS_VERSION,
128 .vendor = RKISP_ALGO_AEIS_VENDOR,
129 .description = RKISP_ALGO_AEIS_DESCRIPTION,
130 .type = RK_AIQ_ALGO_TYPE_AEIS,
131 .id = 0,
132 .create_context = create_context,
133 .destroy_context = destroy_context,
134 },
135 .prepare = prepare,
136 .pre_process = NULL,
137 .processing = processing,
138 .post_process = NULL,
139 };
140
141 RKAIQ_END_DECLARE
142