xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/uAPI2/rk_aiq_user_api2_custom_awb.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *  Copyright (c) 2021 Rockchip Corporation
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 
18 #include "rk_aiq_user_api2_custom_awb.h"
19 #include "RkAiqCalibDbV2Helper.h"
20 
21 #ifdef RK_SIMULATOR_HW
22 #define CHECK_USER_API_ENABLE
23 #endif
24 
25 #if RKAIQ_HAVE_AWB_V21
26 #include "rk_aiq_user_api2_custom_awb_v3x.cpp"
27 #elif RKAIQ_HAVE_AWB_V32
28 #include "rk_aiq_user_api2_custom_awb_v32.cpp"
29 #endif
30 
31 
32 RKAIQ_BEGIN_DECLARE
33 
34 #define RKISP_ALGO_AWB_DEMO_VERSION     "v0.0.1"
35 #define RKISP_ALGO_AWB_DEMO_VENDOR      "Rockchip"
36 #define RKISP_ALGO_AWB_DEMO_DESCRIPTION "Rockchip Custom Awb"
37 
38 
39 /* instance was created by AIQ framework when rk_aiq_uapi_sysctl_regLib called */
40 typedef struct _RkAiqAwbAlgoContext {
41     rk_aiq_customeAwb_cbs_t cbs; // set by register
42     union {
43         rk_aiq_sys_ctx_t* aiq_ctx;  // set by register
44         rk_aiq_camgroup_ctx_t* group_ctx;  // set by register
45     };
46     rk_aiq_rkAwb_config_t rkCfg; // awb config of AIQ framework
47     rk_aiq_customeAwb_results_t customRes; // result of pfn_awb_run
48     bool cutomAwbInit;
49     bool updateCalib;
50     uint8_t log_level;
51     uint8_t log_sub_modules;
52     int camIdArray[6];
53     int camIdArrayLen;
54     bool isGroupMode;
55 } RkAiqAwbAlgoContext;
56 
AwbDemoCreateCtx(RkAiqAlgoContext ** context,const AlgoCtxInstanceCfg * cfg)57 static XCamReturn AwbDemoCreateCtx(RkAiqAlgoContext **context, const AlgoCtxInstanceCfg* cfg)
58 {
59     LOGD_AWB_SUBM(0xff, "%s ENTER", __func__);
60 
61     RESULT ret = RK_AIQ_RET_SUCCESS;
62     RkAiqAwbAlgoContext *ctx = new RkAiqAwbAlgoContext();
63     if (ctx == NULL) {
64         printf( "%s: create awb context fail!\n", __FUNCTION__);
65         return XCAM_RETURN_ERROR_MEM;
66     }
67     memset(ctx, 0, sizeof(*ctx));
68     xcam_get_awb_log_level(&ctx->log_level, &ctx->log_sub_modules);
69     if (cfg->isGroupMode) {
70         AlgoCtxInstanceCfgCamGroup* grpCfg = (AlgoCtxInstanceCfgCamGroup*)cfg;
71         memcpy(ctx->camIdArray, grpCfg->camIdArray, sizeof(ctx->camIdArray));
72         ctx->camIdArrayLen = grpCfg->camIdArrayLen;
73         ctx->isGroupMode = true;
74     } else {
75         ctx->camIdArrayLen = 0;
76         ctx->isGroupMode = false;
77     }
78     *context = (RkAiqAlgoContext *)ctx;
79     LOGD_AWB_SUBM(0xff, "%s EXIT", __func__);
80 
81     return XCAM_RETURN_NO_ERROR;
82 }
83 
AwbDemoDestroyCtx(RkAiqAlgoContext * context)84 static XCamReturn AwbDemoDestroyCtx(RkAiqAlgoContext *context)
85 {
86     LOGD_AWB_SUBM(0xff, "%s ENTER", __func__);
87     RkAiqAwbAlgoContext* context2 = (RkAiqAwbAlgoContext*)context;
88     if(context2 == NULL)
89         return XCAM_RETURN_NO_ERROR;
90     if (context2->cbs.pfn_awb_exit) {
91         context2->cbs.pfn_awb_exit(context2->aiq_ctx);
92         context2->cutomAwbInit = false;
93     }
94     delete context2;
95     context2 = NULL;
96 
97     LOGD_AWB_SUBM(0xff, "%s EXIT", __func__);
98     return XCAM_RETURN_NO_ERROR;
99 }
100 
101 
AwbDemoPrepare(RkAiqAlgoCom * params)102 static XCamReturn AwbDemoPrepare(RkAiqAlgoCom* params)
103 {
104     LOGD_AWB_SUBM(0xff, "%s ENTER", __func__);
105     XCamReturn ret = XCAM_RETURN_NO_ERROR;
106 
107     RkAiqAwbAlgoContext* algo_ctx = (RkAiqAwbAlgoContext*)params->ctx;
108     if(1/*params->u.prepare.conf_type & RK_AIQ_ALGO_CONFTYPE_CHANGEMODE*/){
109         algo_ctx->rkCfg.Working_mode = params->u.prepare.working_mode;
110     }
111     if (!algo_ctx->cutomAwbInit) {
112         initAwbHwFullConfigGw(&algo_ctx->rkCfg.awbHwConfig);
113         algo_ctx->rkCfg.RawWidth = params->u.prepare.sns_op_width;
114         algo_ctx->rkCfg.RawHeight = params->u.prepare.sns_op_height;
115         awb_window_init(algo_ctx->aiq_ctx,&algo_ctx->rkCfg);
116         frame_choose_init(algo_ctx->aiq_ctx,&algo_ctx->rkCfg);
117         initCustomAwbRes(&algo_ctx->customRes, &algo_ctx->rkCfg);
118         algo_ctx->cbs.pfn_awb_init(algo_ctx->aiq_ctx);
119         algo_ctx->cutomAwbInit = true;
120     }
121 
122     if(params->u.prepare.conf_type & RK_AIQ_ALGO_CONFTYPE_CHANGERES){
123         algo_ctx->rkCfg.RawWidth = params->u.prepare.sns_op_width;
124         algo_ctx->rkCfg.RawHeight = params->u.prepare.sns_op_height;
125         //awb_window_init(algo_ctx->aiq_ctx,&algo_ctx->rkCfg);
126     }
127     if(0/*params->u.prepare.conf_type & RK_AIQ_ALGO_CONFTYPE_CHANGERES || params->u.prepare.conf_type & RK_AIQ_ALGO_CONFTYPE_CHANGEMODE */){
128         uint32_t cmdctrl=0;
129         int pValue=0;
130         if (algo_ctx->cbs.pfn_awb_ctrl){
131             algo_ctx->cbs.pfn_awb_ctrl(algo_ctx->aiq_ctx,  cmdctrl, (void*)(&pValue));
132         }
133     }
134     LOGD_AWB_SUBM(0xff, "%s EXIT", __func__);
135 
136     return ret;
137 }
138 
AwbDemoPreProcess(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)139 static XCamReturn AwbDemoPreProcess(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
140 {
141     XCamReturn ret = XCAM_RETURN_NO_ERROR;
142 
143     LOG1_AWB_SUBM(0xff, "%s ENTER", __func__);
144 
145     LOG1_AWB_SUBM(0xff, "%s EXIT", __func__);
146 
147     return ret;
148 }
149 
AwbDemoProcessing(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)150 static XCamReturn AwbDemoProcessing(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
151 {
152 
153     LOG1_AWB_SUBM(0xff, "%s ENTER", __func__);
154     XCamReturn ret = XCAM_RETURN_NO_ERROR;
155 
156     RkAiqAlgoProcAwb* AwbProcParams = (RkAiqAlgoProcAwb*)inparams;
157     RkAiqAlgoProcResAwb* AwbProcResParams = (RkAiqAlgoProcResAwb*)outparams;
158     RkAiqAwbAlgoContext* algo_ctx = (RkAiqAwbAlgoContext*)inparams->ctx;
159 
160     AwbProcResParams->awb_cfg_update = true;
161     AwbProcResParams->awb_gain_update= true;
162 
163     if (algo_ctx->isGroupMode) {
164         LOGE_AWB("wrong awb mode");
165         return ret;
166     }
167 
168     if(!inparams->u.proc.init) { // init=ture, stats=null
169         rk_aiq_customAwb_stats_t customStats;
170 #if RKAIQ_HAVE_AWB_V21
171     #if defined(ISP_HW_V30)
172         if (!AwbProcParams->awb_statsBuf_v3x) {
173             LOGE_AWB("awb stats is null");
174             return(XCAM_RETURN_BYPASS);
175         }
176     #else
177         if (!AwbProcParams->awb_statsBuf_v201) {
178             LOGE_AWB("awb stats is null");
179             return(XCAM_RETURN_BYPASS);
180         }
181     #endif
182 #elif RKAIQ_HAVE_AWB_V32
183         if (!AwbProcParams->awb_statsBuf_v32) {
184             LOGE_AWB("awb stats is null");
185             return(XCAM_RETURN_BYPASS);
186         }
187 #endif
188 #if RKAIQ_HAVE_AWB_V21
189         rk_aiq_isp_awb_stats_v3x_t* xAwbStats = AwbProcParams->awb_statsBuf_v3x;
190         _rkAwbStats2CustomAwbStats(&customStats, xAwbStats);
191         WriteMeasureResult(*xAwbStats,algo_ctx->log_level);
192 #elif RKAIQ_HAVE_AWB_V32
193         rk_aiq_isp_awb_stats_v32_t* xAwbStats = AwbProcParams->awb_statsBuf_v32;
194         _rkAwbStats2CustomAwbStats(&customStats, xAwbStats);
195         WriteMeasureResult(*xAwbStats,algo_ctx->log_level);
196 #endif
197         if (algo_ctx->cbs.pfn_awb_run)
198             algo_ctx->cbs.pfn_awb_run(algo_ctx->aiq_ctx,
199                                      &customStats,
200                                      &algo_ctx->customRes
201                                   );
202     }else{
203         if (algo_ctx->cbs.pfn_awb_run)
204              algo_ctx->cbs.pfn_awb_run(algo_ctx->aiq_ctx,
205                                       nullptr,
206                                       &algo_ctx->customRes
207                                    );
208 
209     }
210 
211 #if RKAIQ_HAVE_AWB_V21
212     //check para
213     awb_window_check(&algo_ctx->rkCfg,algo_ctx->customRes.awbHwConfig.windowSet);
214     _customAwbHw2rkAwbHwCfg(&algo_ctx->customRes, &algo_ctx->rkCfg.awbHwConfig);
215     // gen part of proc result which is from customRes
216     _customAwbRes2rkAwbRes(AwbProcResParams, &algo_ctx->customRes,algo_ctx->rkCfg.awbHwConfig);
217     WriteDataForThirdParty(*AwbProcResParams->awb_hw1_para,algo_ctx->log_level);
218 #elif RKAIQ_HAVE_AWB_V32
219 
220 #if (RKAIQ_HAVE_BLC_V32)
221        AblcProc_V32_t *ablc_res_v32 = AwbProcParams->ablcProcResV32;
222 #else
223        AblcProc_V32_t *ablc_res_v32 = nullptr;
224 #endif
225 
226     RKAiqAecExpInfo_t *curExp = AwbProcParams->com.u.proc.curExp;
227     float aec_iso =  50;
228     float hdrmge_gain0_1=  1.0;
229     int working_mode = algo_ctx->rkCfg.Working_mode;
230     if(curExp != NULL) {
231         if(working_mode == RK_AIQ_WORKING_MODE_NORMAL) {
232             if(curExp->LinearExp.exp_real_params.analog_gain < 1.0) {
233                 aec_iso= 1.0;
234                 LOGW_AWB("linear mode again is wrong, use 1.0 instead\n");
235             } else {
236                 aec_iso = curExp->LinearExp.exp_real_params.analog_gain;
237             }
238             if(curExp->LinearExp.exp_real_params.digital_gain < 1.0) {
239                 aec_iso *= 1.0;
240                 LOGW_AWB("linear mode dgain is wrong, use 1.0 instead\n");
241             } else {
242                 aec_iso *= curExp->LinearExp.exp_real_params.digital_gain;
243             }
244         } else {
245             int i=0;
246             if ((rk_aiq_working_mode_t)working_mode >= RK_AIQ_WORKING_MODE_ISP_HDR2
247                 && (rk_aiq_working_mode_t)working_mode < RK_AIQ_WORKING_MODE_ISP_HDR3) {
248                 i = 1;
249             }else if ((rk_aiq_working_mode_t)working_mode >= RK_AIQ_WORKING_MODE_ISP_HDR3) {
250                 i = 2;
251             }
252 
253             if(curExp->HdrExp[i].exp_real_params.analog_gain < 1.0) {
254                 aec_iso = 1.0;
255                 LOGW_AWB("hdr mode again is wrong, use 1.0 instead\n");
256             } else {
257                 aec_iso = curExp->HdrExp[i].exp_real_params.analog_gain;
258             }
259             if(curExp->HdrExp[i].exp_real_params.digital_gain < 1.0) {
260                 aec_iso  *= 1.0;
261             } else {
262                 LOGW_AWB("hdr mode dgain is wrong, use 1.0 instead\n");
263                 aec_iso *= curExp->HdrExp[i].exp_real_params.digital_gain;
264             }
265             float sExpo = curExp->HdrExp[0].exp_real_params.analog_gain *
266                 curExp->HdrExp[0].exp_real_params.digital_gain *
267                 curExp->HdrExp[0].exp_real_params.integration_time;
268 
269             float lExpo = curExp->HdrExp[i].exp_real_params.analog_gain *
270             curExp->HdrExp[i].exp_real_params.digital_gain *
271             curExp->HdrExp[i].exp_real_params.integration_time;
272             if(sExpo>DIVMIN){
273                 hdrmge_gain0_1 = lExpo/sExpo;
274             }
275         }
276         aec_iso *=  50;
277     }
278     LOGE_AWB("aec_iso = %f, hdrmge_gain0_1=%f,",aec_iso,hdrmge_gain0_1);
279     rk_aiq_isp_awb_meas_cfg_v32_t *awbHwConfigFull = &algo_ctx->rkCfg.awbHwConfig;
280     //check para
281     awb_window_check(&algo_ctx->rkCfg,awbHwConfigFull->windowSet);
282     _customAwbHw2rkAwbHwCfg(&algo_ctx->customRes, awbHwConfigFull);
283     //update by other para
284     AwbProcResParams->awb_gain_algo->applyPosition =
285         ((rk_aiq_working_mode_t)working_mode == RK_AIQ_WORKING_MODE_NORMAL) ? IN_AWBGAIN1 :IN_AWBGAIN0;
286     calcInputBitIs12Bit( &awbHwConfigFull->inputBitIs12Bit, awbHwConfigFull->frameChoose, working_mode,ablc_res_v32);
287     calcInputRightShift212Bit(&awbHwConfigFull->inputShiftEnable,awbHwConfigFull->frameChoose, working_mode,ablc_res_v32);
288     ConfigWbgainBaseOnBlc(ablc_res_v32,AwbProcResParams->awb_gain_algo->applyPosition,&algo_ctx->customRes.awb_gain_algo);
289     ret = ConfigPreWbgain2(awbHwConfigFull,algo_ctx->customRes.awb_gain_algo,AwbProcResParams->awb_gain_algo->applyPosition);
290     RETURN_RESULT_IF_DIFFERENT(ret, XCAM_RETURN_NO_ERROR);
291     ret = ConfigBlc2(ablc_res_v32,algo_ctx->customRes.awb_gain_algo,
292         AwbProcResParams->awb_gain_algo->applyPosition,working_mode,awbHwConfigFull);
293     RETURN_RESULT_IF_DIFFERENT(ret, XCAM_RETURN_NO_ERROR);
294     ConfigOverexposureValue(ablc_res_v32,hdrmge_gain0_1,working_mode, awbHwConfigFull);
295     if( awbHwConfigFull->frameChoose == CALIB_AWB_INPUT_DRC){
296         awbHwConfigFull->lscBypEnable = true;
297     }else{
298         awbHwConfigFull->lscBypEnable = false;
299     }
300     // gen part of proc result which is from customRes
301     _customAwbRes2rkAwbRes(AwbProcResParams, &algo_ctx->customRes,*awbHwConfigFull);
302     WriteDataForThirdParty(*AwbProcResParams->awb_hw32_para,algo_ctx->log_level);
303 #endif
304     LOG1_AWB_SUBM(0xff, "%s EXIT", __func__);
305     return XCAM_RETURN_NO_ERROR;
306 }
307 
AwbDemoGroupProcessing(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)308 static XCamReturn AwbDemoGroupProcessing(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
309 {
310 
311     LOGD_AWB_SUBM(0xff, "%s ENTER --------------------frame%d  ---------------------", __func__,inparams->frame_id);
312     XCamReturn ret = XCAM_RETURN_NO_ERROR;
313 #if RKAIQ_HAVE_AWB_V21
314     RkAiqAlgoCamGroupProcIn* AwbProcParams = (RkAiqAlgoCamGroupProcIn*)inparams;
315     RkAiqAlgoCamGroupProcOut* AwbProcResParams = (RkAiqAlgoCamGroupProcOut*)outparams;
316     RkAiqAwbAlgoContext* algo_ctx = (RkAiqAwbAlgoContext*)inparams->ctx;
317     if (!algo_ctx->isGroupMode) {
318         LOGE_AWB("wrong awb mode for group");
319         return ret;
320     }
321 
322     if(!inparams->u.proc.init) { // init=ture, stats=null
323         rk_aiq_customAwb_stats_t customStats;
324         memset(&customStats,0,sizeof(customStats));
325         ret = _rkAwbStats2CustomGroupAwbStats(AwbProcParams->camgroupParmasArray,AwbProcParams->arraySize, &customStats);
326         RETURN_RESULT_IF_DIFFERENT(ret, XCAM_RETURN_NO_ERROR);
327 
328         if (algo_ctx->cbs.pfn_awb_run)
329             algo_ctx->cbs.pfn_awb_run(algo_ctx->aiq_ctx,
330                                      &customStats,
331                                      &algo_ctx->customRes
332                                   );
333         customAwbStatsRelease(&customStats);
334 
335     }else{
336 
337         if (algo_ctx->cbs.pfn_awb_run)
338              algo_ctx->cbs.pfn_awb_run(algo_ctx->aiq_ctx,
339                                       nullptr,
340                                       &algo_ctx->customRes
341                                    );
342 
343     }
344     // gen part of proc result which is from customRes
345     _customGruopAwbRes2rkAwbRes(AwbProcResParams->camgroupParmasArray ,AwbProcResParams->arraySize,&algo_ctx->rkCfg, &algo_ctx->customRes);
346     RETURN_RESULT_IF_DIFFERENT(ret, XCAM_RETURN_NO_ERROR);
347 #endif
348 
349     LOG1_AWB_SUBM(0xff, "%s EXIT", __func__);
350     return XCAM_RETURN_NO_ERROR;
351 }
352 
AwbDemoPostProcess(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)353 static XCamReturn AwbDemoPostProcess(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
354 {
355     RESULT ret = RK_AIQ_RET_SUCCESS;
356     RkAiqAwbAlgoContext* algo_ctx = (RkAiqAwbAlgoContext*)inparams->ctx;
357 
358 
359     return XCAM_RETURN_NO_ERROR;
360 }
361 
362 static std::map<rk_aiq_sys_ctx_t*, RkAiqAlgoDescription*> g_customAwb_desc_map;
363 
364 XCamReturn
rk_aiq_uapi2_customAWB_register(const rk_aiq_sys_ctx_t * ctx,rk_aiq_customeAwb_cbs_t * cbs)365 rk_aiq_uapi2_customAWB_register(const rk_aiq_sys_ctx_t* ctx, rk_aiq_customeAwb_cbs_t* cbs)
366 {
367     LOGD_AWB_SUBM(0xff, "%s ENTER", __func__);
368     XCamReturn ret = XCAM_RETURN_NO_ERROR;
369     if (!cbs)
370         return XCAM_RETURN_ERROR_PARAM;
371     const rk_aiq_camgroup_ctx_t* group_ctx = NULL;
372 
373     if (ctx->cam_type == RK_AIQ_CAM_TYPE_GROUP) {
374        LOGI_AWB_SUBM(0xff, "group awb");
375        group_ctx = (const rk_aiq_camgroup_ctx_t*)ctx;
376 
377     } else {
378        LOGI_AWB_SUBM(0xff, "single awb");
379     }
380     RkAiqAlgoDescription* desc = NULL;
381     rk_aiq_sys_ctx_t* cast_ctx = const_cast<rk_aiq_sys_ctx_t*>(ctx);
382 
383     std::map<rk_aiq_sys_ctx_t*, RkAiqAlgoDescription*>::iterator it =
384         g_customAwb_desc_map.find(cast_ctx);
385 
386     if (it == g_customAwb_desc_map.end()) {
387         desc = new RkAiqAlgoDescription();
388         g_customAwb_desc_map[cast_ctx] = desc;
389     } else {
390         desc = it->second;
391     }
392 
393     desc->common.version = RKISP_ALGO_AWB_DEMO_VERSION;
394     desc->common.vendor  = RKISP_ALGO_AWB_DEMO_VENDOR;
395     desc->common.description = RKISP_ALGO_AWB_DEMO_DESCRIPTION;
396     desc->common.type    = RK_AIQ_ALGO_TYPE_AWB;
397     desc->common.id      = 0;
398     desc->common.create_context  = AwbDemoCreateCtx;
399     desc->common.destroy_context = AwbDemoDestroyCtx;
400     desc->prepare = AwbDemoPrepare;
401     desc->pre_process = AwbDemoPreProcess;
402     if (!group_ctx)
403         desc->processing = AwbDemoProcessing;
404     else
405         desc->processing = AwbDemoGroupProcessing;
406     desc->post_process = AwbDemoPostProcess;
407 
408     ret = rk_aiq_uapi_sysctl_regLib(ctx, &desc->common);
409     if (ret != XCAM_RETURN_NO_ERROR) {
410         LOGE_AWB_SUBM(0xff, "register %d failed !", desc->common.id);
411         return ret;
412     }
413 
414     RkAiqAwbAlgoContext* algoCtx = (RkAiqAwbAlgoContext*)
415         rk_aiq_uapi_sysctl_getAxlibCtx(ctx,
416                                        desc->common.type,
417                                        desc->common.id);
418     if (algoCtx == NULL) {
419         LOGE_AWB_SUBM(0xff, "can't get custom awb algo %d ctx!", desc->common.id);
420         return XCAM_RETURN_ERROR_FAILED;
421     }
422 
423     algoCtx->cbs = *cbs;
424     algoCtx->aiq_ctx = const_cast<rk_aiq_sys_ctx_t*>(ctx);
425 
426     LOGD_AWB_SUBM(0xff, "register custom awb algo sucess for sys_ctx %p, lib_id %d !",
427                   ctx,
428                   desc->common.id);
429     LOGD_AWB_SUBM(0xff, "%s EXIT", __func__);
430 
431     return ret;
432 }
433 
434 XCamReturn
rk_aiq_uapi2_customAWB_enable(const rk_aiq_sys_ctx_t * ctx,bool enable)435 rk_aiq_uapi2_customAWB_enable(const rk_aiq_sys_ctx_t* ctx, bool enable)
436 {
437 
438     LOGD_AWB_SUBM(0xff, "%s ENTER", __func__);
439     XCamReturn ret = XCAM_RETURN_NO_ERROR;
440 
441     RkAiqAlgoDescription* desc = NULL;
442     rk_aiq_sys_ctx_t* cast_ctx = const_cast<rk_aiq_sys_ctx_t*>(ctx);
443 
444     std::map<rk_aiq_sys_ctx_t*, RkAiqAlgoDescription*>::iterator it =
445         g_customAwb_desc_map.find(cast_ctx);
446 
447     if (it == g_customAwb_desc_map.end()) {
448         LOGE_AWB_SUBM(0xff, "can't find custom awb algo for sys_ctx %p !", ctx);
449         return XCAM_RETURN_ERROR_FAILED;
450     } else {
451         desc = it->second;
452     }
453 
454     ret = rk_aiq_uapi_sysctl_enableAxlib(ctx,
455                                          desc->common.type,
456                                          desc->common.id,
457                                          enable);
458     if (ret != XCAM_RETURN_NO_ERROR) {
459         LOGE_AWB_SUBM(0xff, "enable custom awb lib id %d failed !");
460         return ret;
461     }
462     // now rk and custom awb are running concurrently,
463     // because other algos will depend on results of rk awb
464 #if 0
465     //only run custom awb
466     if (enable)
467         ret = rk_aiq_uapi_sysctl_enableAxlib(ctx,
468                                              desc->common.type,
469                                              0,
470                                              !enable);
471 #endif
472 
473     LOGD_AWB_SUBM(0xff, "enable custom awb algo sucess for sys_ctx %p, lib_id %d !",
474                   ctx,
475                   desc->common.id);
476     LOGD_AWB_SUBM(0xff, "%s EXIT", __func__);
477     return XCAM_RETURN_NO_ERROR;
478 }
479 
480 XCamReturn
rk_aiq_uapi2_customAWB_unRegister(const rk_aiq_sys_ctx_t * ctx)481 rk_aiq_uapi2_customAWB_unRegister(const rk_aiq_sys_ctx_t* ctx)
482 {
483 
484     LOGD_AWB_SUBM(0xff, "%s ENTER", __func__);
485     RkAiqAlgoDescription* desc = NULL;
486     rk_aiq_sys_ctx_t* cast_ctx = const_cast<rk_aiq_sys_ctx_t*>(ctx);
487 
488     std::map<rk_aiq_sys_ctx_t*, RkAiqAlgoDescription*>::iterator it =
489         g_customAwb_desc_map.find(cast_ctx);
490 
491     if (it == g_customAwb_desc_map.end()) {
492         LOGE_AWB_SUBM(0xff, "can't find custom awb algo for sys_ctx %p !", ctx);
493         return XCAM_RETURN_ERROR_FAILED;
494     } else {
495         desc = it->second;
496     }
497 
498     rk_aiq_uapi_sysctl_unRegLib(ctx,
499                                 desc->common.type,
500                                 desc->common.id);
501 
502     LOGD_AWB_SUBM(0xff, "unregister custom awb algo sucess for sys_ctx %p, lib_id %d !",
503                   ctx,
504                   desc->common.id);
505 
506     delete it->second;
507     g_customAwb_desc_map.erase(it);
508 
509     LOGD_AWB_SUBM(0xff, "%s EXIT", __func__);
510     return XCAM_RETURN_NO_ERROR;
511 }
512 
513 
514 
515 RKAIQ_END_DECLARE
516