-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRkAiqManager.cpp
executable file
·915 lines (766 loc) · 26.6 KB
/
RkAiqManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
/*
* Copyright (c) 2019 Rockchip Corporation
*
* 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.
*
*/
#include "RkAiqManager.h"
#include "isp20/Isp20_module_dbg.h"
#include "isp20/CamHwIsp20.h"
#include "isp21/CamHwIsp21.h"
#include <fcntl.h>
#include <unistd.h>
using namespace XCam;
namespace RkCam {
#define RKAIQMNG_CHECK_RET(ret, format, ...) \
if (ret) { \
LOGE(format, ##__VA_ARGS__); \
return ret; \
}
bool
RkAiqMngCmdThread::loop ()
{
ENTER_XCORE_FUNCTION();
const static int32_t timeout = -1;
XCamReturn ret = XCAM_RETURN_NO_ERROR;
SmartPtr<msg_t> msg = mAiqCmdQueue.pop (timeout);
if (!msg.ptr()) {
XCAM_LOG_WARNING("RkAiqMngCmdThread got empty result, stop thread");
return false;
}
XCAM_ASSERT (mAiqMng);
switch (msg->cmd) {
case MSG_CMD_SW_WORKING_MODE:
if (msg->sync)
msg->mutex->lock();
mAiqMng->swWorkingModeDyn(msg->data.sw_wk_mode.mode);
mAiqMng->mWkSwitching = false;
if (msg->sync) {
msg->cond->broadcast ();
msg->mutex->unlock();
}
break;
default:
break;
}
// always true
return true;
}
bool
RkAiqRstApplyThread::loop ()
{
ENTER_XCORE_FUNCTION();
const static int32_t timeout = -1;
XCamReturn ret = XCAM_RETURN_NO_ERROR;
SmartPtr<RkAiqFullParamsProxy> results = mAiqRstQueue.pop (timeout);
XCAM_ASSERT (mAiqMng);
if (!results.ptr()) {
XCAM_LOG_WARNING("RkAiqRstApplyThread got empty result, stop thread");
return false;
}
#ifdef RUNTIME_MODULE_DEBUG
#ifndef RK_SIMULATOR_HW
if (g_apply_init_params_only)
goto out;
#endif
#endif
ret = mAiqMng->applyAnalyzerResult(results);
if (ret == XCAM_RETURN_NO_ERROR)
return true;
EXIT_XCORE_FUNCTION();
out:
// always true
return true;
}
RkAiqManager::RkAiqManager(const char* sns_ent_name,
rk_aiq_error_cb err_cb,
rk_aiq_metas_cb metas_cb)
: mCamHw(NULL)
, mRkAiqAnalyzer(NULL)
, mRkLumaAnalyzer(NULL)
, mAiqRstAppTh(new RkAiqRstApplyThread(this))
, mAiqMngCmdTh(new RkAiqMngCmdThread(this))
, mErrCb(err_cb)
, mMetasCb(metas_cb)
, mSnsEntName(sns_ent_name)
, mWorkingMode(RK_AIQ_WORKING_MODE_NORMAL)
, mOldWkModeForGray(RK_AIQ_WORKING_MODE_NORMAL)
, mWkSwitching(false)
, mCalibDb(NULL)
, _state(AIQ_STATE_INVALID)
, mCurMirror(false)
, mCurFlip(false)
{
ENTER_XCORE_FUNCTION();
EXIT_XCORE_FUNCTION();
}
RkAiqManager::~RkAiqManager()
{
ENTER_XCORE_FUNCTION();
EXIT_XCORE_FUNCTION();
}
void
RkAiqManager::setCamHw(SmartPtr<ICamHw>& camhw)
{
ENTER_XCORE_FUNCTION();
XCAM_ASSERT (!mCamHw.ptr());
mCamHw = camhw;
EXIT_XCORE_FUNCTION();
}
void
RkAiqManager::setAnalyzer(SmartPtr<RkAiqCore> analyzer)
{
ENTER_XCORE_FUNCTION();
XCAM_ASSERT (!mRkAiqAnalyzer.ptr());
mRkAiqAnalyzer = analyzer;
EXIT_XCORE_FUNCTION();
}
void
RkAiqManager::setLumaAnalyzer(SmartPtr<RkLumaCore> analyzer)
{
ENTER_XCORE_FUNCTION();
XCAM_ASSERT (!mRkLumaAnalyzer.ptr());
mRkLumaAnalyzer = analyzer;
EXIT_XCORE_FUNCTION();
}
void
RkAiqManager::setAiqCalibDb(const CamCalibDbContext_t* calibDb)
{
ENTER_XCORE_FUNCTION();
XCAM_ASSERT (!mCalibDb);
mCalibDb = calibDb;
EXIT_XCORE_FUNCTION();
}
XCamReturn
RkAiqManager::init()
{
ENTER_XCORE_FUNCTION();
XCamReturn ret = XCAM_RETURN_NO_ERROR;
XCAM_ASSERT (mSnsEntName);
XCAM_ASSERT (mRkAiqAnalyzer.ptr());
XCAM_ASSERT (mCamHw.ptr());
XCAM_ASSERT (mCalibDb);
mRkAiqAnalyzer->setAnalyzeResultCb(this);
// set hw infos
struct RkAiqHwInfo hw_info;
xcam_mem_clear(hw_info);
#ifndef RK_SIMULATOR_HW
rk_aiq_static_info_t* s_info = CamHwIsp20::getStaticCamHwInfo(mSnsEntName);
hw_info.fl_supported = s_info->has_fl;
hw_info.irc_supported = s_info->has_irc;
hw_info.lens_supported = s_info->has_lens_vcm;
hw_info.fl_strth_adj = s_info->fl_strth_adj_sup;
hw_info.fl_ir_strth_adj = s_info->fl_ir_strth_adj_sup;
mIspHwVer = s_info->isp_hw_ver;
#endif
mRkAiqAnalyzer->setHwInfos(hw_info);
ret = mRkAiqAnalyzer->init(mSnsEntName, mCalibDb);
RKAIQMNG_CHECK_RET(ret, "analyzer init error %d !", ret);
mRkLumaAnalyzer->setAnalyzeResultCb(this);
ret = mRkLumaAnalyzer->init(&mCalibDb->lumaDetect);
RKAIQMNG_CHECK_RET(ret, "luma analyzer init error %d !", ret);
mCamHw->setIspLumaListener(this);
mCamHw->setIspStatsListener(this);
mCamHw->setEvtsListener(this);
ret = mCamHw->init(mSnsEntName);
RKAIQMNG_CHECK_RET(ret, "camHw init error %d !", ret);
_state = AIQ_STATE_INITED;
isp_drv_share_mem_ops_t *mem_ops = NULL;
mCamHw->getShareMemOps(&mem_ops);
mRkAiqAnalyzer->setShareMemOps(mem_ops);
// set default mirror & flip
setDefMirrorFlip();
mAiqMngCmdTh->triger_start();
bool bret = mAiqMngCmdTh->start();
ret = bret ? XCAM_RETURN_NO_ERROR : XCAM_RETURN_ERROR_FAILED;
RKAIQMNG_CHECK_RET(ret, "cmd thread start error");
mDleayCpslParams = NULL;
EXIT_XCORE_FUNCTION();
return ret;
}
XCamReturn
RkAiqManager::prepare(uint32_t width, uint32_t height, rk_aiq_working_mode_t mode)
{
ENTER_XCORE_FUNCTION();
XCamReturn ret = XCAM_RETURN_NO_ERROR;
rk_aiq_exposure_sensor_descriptor sensor_des;
XCAM_ASSERT (mCalibDb);
#ifdef RUNTIME_MODULE_DEBUG
#ifndef RK_SIMULATOR_HW
get_dbg_force_disable_mods_env();
#endif
#endif
int working_mode_hw = RK_AIQ_WORKING_MODE_NORMAL;
if (mode == RK_AIQ_WORKING_MODE_NORMAL) {
working_mode_hw = mode;
} else {
if (mode == RK_AIQ_WORKING_MODE_ISP_HDR2)
working_mode_hw = RK_AIQ_ISP_HDR_MODE_2_FRAME_HDR;
else if (mode == RK_AIQ_WORKING_MODE_ISP_HDR3)
working_mode_hw = RK_AIQ_ISP_HDR_MODE_3_FRAME_HDR;
else
LOGE_ANALYZER("Not supported HDR mode !");
}
mCamHw->setCalib(mCalibDb);
if(mode != RK_AIQ_WORKING_MODE_NORMAL)
ret = mCamHw->prepare(width, height, working_mode_hw, mCalibDb->expset.CISExpUpdate.Hdr.time_update, mCalibDb->expset.CISExpUpdate.Hdr.gain_update);
else
ret = mCamHw->prepare(width, height, working_mode_hw, mCalibDb->expset.CISExpUpdate.Normal.time_update, mCalibDb->expset.CISExpUpdate.Normal.gain_update);
RKAIQMNG_CHECK_RET(ret, "camhw prepare error %d", ret);
xcam_mem_clear(sensor_des);
ret = mCamHw->getSensorModeData(mSnsEntName, sensor_des);
ret = mRkLumaAnalyzer->prepare(working_mode_hw);
RKAIQMNG_CHECK_RET(ret, "getSensorModeData error %d", ret);
ret = mRkAiqAnalyzer->prepare(&sensor_des, working_mode_hw);
RKAIQMNG_CHECK_RET(ret, "analyzer prepare error %d", ret);
SmartPtr<RkAiqFullParamsProxy> initParams = mRkAiqAnalyzer->getAiqFullParams();
ret = applyAnalyzerResult(initParams);
RKAIQMNG_CHECK_RET(ret, "set initial params error %d", ret);
mWorkingMode = mode;
mOldWkModeForGray = RK_AIQ_WORKING_MODE_NORMAL;
mWidth = width;
mHeight = height;
_state = AIQ_STATE_PREPARED;
EXIT_XCORE_FUNCTION();
return ret;
}
XCamReturn
RkAiqManager::start()
{
ENTER_XCORE_FUNCTION();
XCamReturn ret = XCAM_RETURN_NO_ERROR;
// restart
if (_state == AIQ_STATE_STOPED) {
SmartPtr<RkAiqFullParamsProxy> initParams = mRkAiqAnalyzer->getAiqFullParams();
if (initParams->data()->mIspParams.ptr()) {
initParams->data()->mIspParams->data()->frame_id = 0;
}
if (initParams->data()->mIsppParams.ptr()) {
initParams->data()->mIsppParams->data()->frame_id = 0;
}
applyAnalyzerResult(initParams);
}
mAiqRstAppTh->triger_start();
bool bret = mAiqRstAppTh->start();
ret = bret ? XCAM_RETURN_NO_ERROR : XCAM_RETURN_ERROR_FAILED;
RKAIQMNG_CHECK_RET(ret, "apply result thread start error");
ret = mRkAiqAnalyzer->start();
RKAIQMNG_CHECK_RET(ret, "analyzer start error %d", ret);
ret = mRkLumaAnalyzer->start();
RKAIQMNG_CHECK_RET(ret, "luma analyzer start error %d", ret);
ret = mCamHw->start();
RKAIQMNG_CHECK_RET(ret, "camhw start error %d", ret);
_state = AIQ_STATE_STARTED;
EXIT_XCORE_FUNCTION();
return ret;
}
XCamReturn
RkAiqManager::stop(bool keep_ext_hw_st)
{
ENTER_XCORE_FUNCTION();
XCamReturn ret = XCAM_RETURN_NO_ERROR;
if (_state == AIQ_STATE_STOPED) {
return ret;
}
mAiqRstAppTh->triger_stop();
bool bret = mAiqRstAppTh->stop();
ret = bret ? XCAM_RETURN_NO_ERROR : XCAM_RETURN_ERROR_FAILED;
RKAIQMNG_CHECK_RET(ret, "apply result thread stop error");
ret = mRkAiqAnalyzer->stop();
RKAIQMNG_CHECK_RET(ret, "analyzer stop error %d", ret);
ret = mRkLumaAnalyzer->stop();
RKAIQMNG_CHECK_RET(ret, "luma analyzer stop error %d", ret);
mCamHw->keepHwStAtStop(keep_ext_hw_st);
ret = mCamHw->stop();
RKAIQMNG_CHECK_RET(ret, "camhw stop error %d", ret);
mDleayCpslParams = NULL;
_state = AIQ_STATE_STOPED;
EXIT_XCORE_FUNCTION();
return ret;
}
XCamReturn
RkAiqManager::deInit()
{
ENTER_XCORE_FUNCTION();
XCamReturn ret = XCAM_RETURN_NO_ERROR;
mAiqMngCmdTh->triger_stop();
bool bret = mAiqMngCmdTh->stop();
ret = bret ? XCAM_RETURN_NO_ERROR : XCAM_RETURN_ERROR_FAILED;
RKAIQMNG_CHECK_RET(ret, "cmd thread stop error");
ret = mRkAiqAnalyzer->deInit();
RKAIQMNG_CHECK_RET(ret, "analyzer deinit error %d", ret);
ret = mRkLumaAnalyzer->deInit();
RKAIQMNG_CHECK_RET(ret, "luma analyzer deinit error %d", ret);
ret = mCamHw->deInit();
RKAIQMNG_CHECK_RET(ret, "camhw deinit error %d", ret);
_state = AIQ_STATE_INVALID;
EXIT_XCORE_FUNCTION();
return ret;
}
XCamReturn
RkAiqManager::isppStatsCb(SmartPtr<VideoBuffer>& isppStats)
{
ENTER_XCORE_FUNCTION();
return ispStatsCb(isppStats);
EXIT_XCORE_FUNCTION();
}
XCamReturn
RkAiqManager::ispLumaCb(SmartPtr<VideoBuffer>& ispLuma)
{
ENTER_XCORE_FUNCTION();
//TODO::create luma detection thread,analyze luma change,and decide
//number of frames should HDR to process.
XCamReturn ret = mRkLumaAnalyzer->pushStats(ispLuma);
EXIT_XCORE_FUNCTION();
return ret;
}
XCamReturn
RkAiqManager::ispStatsCb(SmartPtr<VideoBuffer>& ispStats)
{
ENTER_XCORE_FUNCTION();
XCamReturn ret = mRkAiqAnalyzer->pushStats(ispStats);
#ifndef RK_SIMULATOR_HW
if (get_rkaiq_runtime_dbg() > 0) {
if (ispStats->get_video_info().format == V4L2_META_FMT_RK_ISP1_STAT_3A) {
XCAM_STATIC_FPS_CALCULATION(ISP_STATS_FPS, 60);
} else {
XCAM_STATIC_FPS_CALCULATION(PP_STATS_FPS, 60);
}
}
#endif
EXIT_XCORE_FUNCTION();
return ret;
}
XCamReturn
RkAiqManager::ispEvtsCb(ispHwEvt_t* evt)
{
//TODO
XCamReturn ret = XCAM_RETURN_NO_ERROR;
if (mMetasCb) {
rk_aiq_metas_t metas;
metas.frame_id = evt->msg.frame_id;
return (*mMetasCb)(&metas);
}
return ret;
}
XCamReturn
RkAiqManager::applyAnalyzerResult(SmartPtr<RkAiqFullParamsProxy>& results)
{
ENTER_XCORE_FUNCTION();
XCamReturn ret = XCAM_RETURN_NO_ERROR;
RkAiqFullParams* aiqParams = NULL;
if (!results.ptr()) {
LOGW_ANALYZER("empty aiq params results!");
return ret;
}
// TODO: couldn't get dynamic debug env now
#if 0//def RUNTIME_MODULE_DEBUG
get_dbg_force_disable_mods_env();
#endif
aiqParams = results->data().ptr();
#ifndef RK_SIMULATOR_HW
if (mWorkingMode != RK_AIQ_WORKING_MODE_NORMAL && mIspHwVer == 4) {
SmartPtr<CamHwIsp20> mCamHwIsp20 = mCamHw.dynamic_cast_ptr<CamHwIsp20>();
rk_aiq_isp_params_v20_t* ispParams =
static_cast<rk_aiq_isp_params_v20_t*>(aiqParams->mIspParams->data().ptr());
bool isHdrGlobalTmo = ispParams->ahdr_proc_res.isHdrGlobalTmo;
mCamHwIsp20->setHdrGlobalTmoMode(ispParams->frame_id, isHdrGlobalTmo);
}
#endif
#ifdef RUNTIME_MODULE_DEBUG
#ifndef RK_SIMULATOR_HW
if (g_bypass_exp_params)
goto set_exp_end;
#endif
#endif
/* #define FLASH_CTL_DEBUG */
#ifdef FLASH_CTL_DEBUG
{
// for test
int fd = open("/tmp/flash_ctl", O_RDWR);
if (fd != -1) {
char c;
read(fd, &c, 1);
int enable = atoi(&c);
SmartPtr<rk_aiq_flash_setting_t> fl = new rk_aiq_flash_setting_t();
fl->flash_mode = enable ? RK_AIQ_FLASH_MODE_TORCH : RK_AIQ_FLASH_MODE_OFF;
fl->power[0] = 10000;
fl->strobe = enable ? true : false;
aiqParams->mFlParams = new SharedItemProxy<rk_aiq_flash_setting_t>(fl);;
ret = mCamHw->setFlParams(aiqParams->mFlParams);
if (ret)
LOGE_ANALYZER("setFlParams error %d", ret);
close(fd);
}
}
#else
#ifndef RK_SIMULATOR_HW
if (aiqParams->mCpslParams.ptr()) {
SmartPtr<CamHwIsp20> mCamHwIsp20 = mCamHw.dynamic_cast_ptr<CamHwIsp20>();
rk_aiq_isp_params_v2x_t* ispParams =
static_cast<rk_aiq_isp_params_v2x_t*>(aiqParams->mIspParams->data().ptr());
int gray_mode = ispParams->ie.base.mode;
bool cpsl_ir_en = aiqParams->mCpslParams->data()->update_ir &&
aiqParams->mCpslParams->data()->ir.irc_on;
bool cpsl_update = aiqParams->mCpslParams->data()->update_ir ||
aiqParams->mCpslParams->data()->update_fl;
if (cpsl_ir_en) {
mDelayCpslApplyFrmNum = 2;
mDleayCpslParams = aiqParams->mCpslParams;
LOGD_ANALYZER("gray mode on, cpsl ir on delay 2 frames");
} else if (cpsl_update) {
mDleayCpslParams.release();
mDelayCpslApplyFrmNum = 0;
ret = mCamHw->setCpslParams(aiqParams->mCpslParams);
if (ret)
LOGE_ANALYZER("setFlParams error %d", ret);
}
}
if (mDleayCpslParams.ptr() && --mDelayCpslApplyFrmNum == 0) {
LOGD_ANALYZER("set delyay cpsl ir on");
ret = mCamHw->setCpslParams(mDleayCpslParams);
if (ret)
LOGE_ANALYZER("setFlParams error %d", ret);
mDleayCpslParams.release();
}
#endif
#endif
if (aiqParams->mExposureParams.ptr()) {
//#define DEBUG_FIXED_EXPOSURE
#ifdef DEBUG_FIXED_EXPOSURE
/* test aec with fixed sensor exposure */
int cnt = aiqParams->mIspParams->data()->frame_id ;
if (aiqParams->mExposureParams->data()->algo_id == 0) {
aiqParams->mExposureParams->data()->exp_tbl_size = 1;
RKAiqAecExpInfo_t* exp_tbl = &aiqParams->mExposureParams->data()->exp_tbl[0];
if(cnt % 40 <= 19) {
exp_tbl->HdrExp[2].exp_sensor_params.coarse_integration_time = 984;
exp_tbl->HdrExp[2].exp_sensor_params.analog_gain_code_global = 48;
exp_tbl->HdrExp[1].exp_sensor_params.coarse_integration_time = 984;
exp_tbl->HdrExp[1].exp_sensor_params.analog_gain_code_global = 48;
exp_tbl->HdrExp[0].exp_sensor_params.coarse_integration_time = 246;
exp_tbl->HdrExp[0].exp_sensor_params.analog_gain_code_global = 16;
exp_tbl->HdrExp[2].exp_real_params.integration_time = 0.02;
exp_tbl->HdrExp[2].exp_real_params.analog_gain = 3;
exp_tbl->HdrExp[1].exp_real_params.integration_time = 0.02;
exp_tbl->HdrExp[1].exp_real_params.analog_gain = 3;
exp_tbl->HdrExp[0].exp_real_params.integration_time = 0.005;
exp_tbl->HdrExp[0].exp_real_params.analog_gain = 1;
} else {
exp_tbl->HdrExp[2].exp_sensor_params.coarse_integration_time = 1475;
exp_tbl->HdrExp[2].exp_sensor_params.analog_gain_code_global = 144;
exp_tbl->HdrExp[1].exp_sensor_params.coarse_integration_time = 1475;
exp_tbl->HdrExp[1].exp_sensor_params.analog_gain_code_global = 144;
exp_tbl->HdrExp[0].exp_sensor_params.coarse_integration_time = 492;
exp_tbl->HdrExp[0].exp_sensor_params.analog_gain_code_global = 48;
exp_tbl->HdrExp[2].exp_real_params.integration_time = 0.03;
exp_tbl->HdrExp[2].exp_real_params.analog_gain = 9;
exp_tbl->HdrExp[1].exp_real_params.integration_time = 0.03;
exp_tbl->HdrExp[1].exp_real_params.analog_gain = 9;
exp_tbl->HdrExp[0].exp_real_params.integration_time = 0.01;
exp_tbl->HdrExp[0].exp_real_params.analog_gain = 3;
}
}
ret = mCamHw->setExposureParams(aiqParams->mExposureParams);
if (ret)
LOGE_ANALYZER("setExposureParams error %d", ret);
#else
ret = mCamHw->setExposureParams(aiqParams->mExposureParams);
if (ret)
LOGE_ANALYZER("setExposureParams error %d", ret);
#endif
}
set_exp_end:
if (aiqParams->mIrisParams.ptr()) {
ret = mCamHw->setIrisParams(aiqParams->mIrisParams, aiqParams->mIrisParams->data()->IrisType);
if (ret)
LOGE_ANALYZER("setIrisParams error %d", ret);
}
#ifdef RUNTIME_MODULE_DEBUG
#ifndef RK_SIMULATOR_HW
if (g_bypass_isp_params)
goto set_isp_end;
#endif
#endif
if (aiqParams->mIspParams.ptr()) {
ret = mCamHw->setIspParams(aiqParams->mIspParams);
if (ret)
LOGE_ANALYZER("setIspParams error %d", ret);
}
set_isp_end:
#ifdef RUNTIME_MODULE_DEBUG
#ifndef RK_SIMULATOR_HW
if (g_bypass_ispp_params)
goto set_ispp_end;
#endif
#endif
#ifndef DISABLE_PP
if (aiqParams->mIsppParams.ptr()) {
ret = mCamHw->setIsppParams(aiqParams->mIsppParams);
if (ret)
LOGE_ANALYZER("setIsppParams error %d", ret);
}
#endif
set_ispp_end:
if (aiqParams->mFocusParams.ptr()) {
ret = mCamHw->setFocusParams(aiqParams->mFocusParams);
if (ret)
LOGE_ANALYZER("setFocusParams error %d", ret);
}
// disable this feature now, this require the hdr mode set to auto
#if 0
// switch working mode by gray_mode ?
if (aiqParams->mIspParams.ptr()) {
SmartPtr<rk_aiq_isp_params_t> isp_params = aiqParams->mIspParams->data();
LOGD_ANALYZER("ie mode %d, mWkSwitching %d, mWorkingMode %d, mOldWkModeForGray %d",
isp_params->ie.base.mode, mWkSwitching, mWorkingMode, mOldWkModeForGray);
if (isp_params->ie.base.mode == RK_AIQ_IE_EFFECT_BW &&
mWorkingMode != RK_AIQ_WORKING_MODE_NORMAL && !mWkSwitching) {
mOldWkModeForGray = mWorkingMode;
mWkSwitching = true;
LOGD_ANALYZER("switch to BW, old mode %d", mOldWkModeForGray);
SmartPtr<RkAiqMngCmdThread::msg_t> msg = new RkAiqMngCmdThread::msg_t();
msg->cmd = RkAiqMngCmdThread::MSG_CMD_SW_WORKING_MODE;
msg->sync = false;
msg->data.sw_wk_mode.mode = RK_AIQ_WORKING_MODE_NORMAL;
mAiqMngCmdTh->send_cmd(msg);
} else if (isp_params->ie.base.mode != RK_AIQ_IE_EFFECT_BW &&
mOldWkModeForGray != RK_AIQ_WORKING_MODE_NORMAL && !mWkSwitching) {
LOGD_ANALYZER("switch to color, old mode %d", mOldWkModeForGray);
mWkSwitching = true;
SmartPtr<RkAiqMngCmdThread::msg_t> msg = new RkAiqMngCmdThread::msg_t();
msg->cmd = RkAiqMngCmdThread::MSG_CMD_SW_WORKING_MODE;
msg->sync = false;
msg->data.sw_wk_mode.mode = mOldWkModeForGray;
mAiqMngCmdTh->send_cmd(msg);
mOldWkModeForGray = RK_AIQ_WORKING_MODE_NORMAL;
LOGD_ANALYZER("done switch to color, old mode %d", mOldWkModeForGray);
}
}
#endif
EXIT_XCORE_FUNCTION();
out:
return ret;
}
void
RkAiqManager::rkAiqCalcDone(SmartPtr<RkAiqFullParamsProxy> &results)
{
ENTER_XCORE_FUNCTION();
XCAM_ASSERT (mAiqRstAppTh.ptr());
mAiqRstAppTh->push_results(results);
EXIT_XCORE_FUNCTION();
}
void
RkAiqManager::rkAiqCalcFailed(const char* msg)
{
ENTER_XCORE_FUNCTION();
// TODO
EXIT_XCORE_FUNCTION();
return ;
}
void
RkAiqManager::rkLumaCalcDone(int frame_id, int count)
{
ENTER_XCORE_FUNCTION();
XCamReturn ret = XCAM_RETURN_NO_ERROR;
ret = mCamHw->setHdrProcessCount(frame_id, count);
EXIT_XCORE_FUNCTION();
}
void
RkAiqManager::rkLumaCalcFailed(const char* msg)
{
ENTER_XCORE_FUNCTION();
// TODO
EXIT_XCORE_FUNCTION();
return ;
}
XCamReturn
RkAiqManager::setModuleCtl(rk_aiq_module_id_t mId, bool mod_en)
{
ENTER_XCORE_FUNCTION();
XCamReturn ret = XCAM_RETURN_NO_ERROR;
ret = mCamHw->setModuleCtl(mId, mod_en);
EXIT_XCORE_FUNCTION();
return ret;
}
XCamReturn
RkAiqManager::getModuleCtl(rk_aiq_module_id_t mId, bool& mod_en)
{
ENTER_XCORE_FUNCTION();
XCamReturn ret = XCAM_RETURN_NO_ERROR;
ret = mCamHw->getModuleCtl(mId, mod_en);
EXIT_XCORE_FUNCTION();
return ret;
}
XCamReturn
RkAiqManager::enqueueBuffer(struct rk_aiq_vbuf *vbuf)
{
ENTER_XCORE_FUNCTION();
XCamReturn ret = XCAM_RETURN_NO_ERROR;
ret = mCamHw->enqueueBuffer(vbuf);
EXIT_XCORE_FUNCTION();
return ret;
}
XCamReturn RkAiqManager::offlineRdJobPrepare()
{
ENTER_XCORE_FUNCTION();
XCamReturn ret = XCAM_RETURN_NO_ERROR;
ret = mCamHw->offlineRdJobPrepare();
EXIT_XCORE_FUNCTION();
return ret;
}
XCamReturn RkAiqManager::offlineRdJobDone()
{
ENTER_XCORE_FUNCTION();
XCamReturn ret = XCAM_RETURN_NO_ERROR;
ret = mCamHw->offlineRdJobDone();
EXIT_XCORE_FUNCTION();
return ret;
}
XCamReturn RkAiqManager::setSharpFbcRotation(rk_aiq_rotation_t rot)
{
#ifndef RK_SIMULATOR_HW
SmartPtr<CamHwIsp20> camHwIsp20 = mCamHw.dynamic_cast_ptr<CamHwIsp20>();
if (camHwIsp20.ptr() && mIspHwVer == 4)
return camHwIsp20->setSharpFbcRotation(rot);
else
return XCAM_RETURN_ERROR_FAILED;
#else
return XCAM_RETURN_ERROR_FAILED;
#endif
}
XCamReturn RkAiqManager::setMirrorFlip(bool mirror, bool flip, int skip_frm_cnt)
{
XCamReturn ret = XCAM_RETURN_NO_ERROR;
ENTER_XCORE_FUNCTION();
if (_state == AIQ_STATE_INVALID) {
LOGE_ANALYZER("wrong aiq state !");
return XCAM_RETURN_ERROR_FAILED;
}
ret = mCamHw->setSensorFlip(mirror, flip, skip_frm_cnt);
if (ret == XCAM_RETURN_NO_ERROR) {
// notify aiq sensor flip is changed
mRkAiqAnalyzer->setSensorFlip(mirror, flip);
mCurMirror = mirror;
mCurFlip = flip;
} else {
LOGW_ANALYZER("set mirror %d, flip %d error", mirror, flip);
}
return ret;
EXIT_XCORE_FUNCTION();
}
XCamReturn RkAiqManager::getMirrorFlip(bool& mirror, bool& flip)
{
ENTER_XCORE_FUNCTION();
if (_state == AIQ_STATE_INVALID) {
LOGE_ANALYZER("wrong aiq state !");
return XCAM_RETURN_ERROR_FAILED;
}
mirror = mCurMirror;
flip = mCurFlip;
EXIT_XCORE_FUNCTION();
return XCAM_RETURN_NO_ERROR;
}
void RkAiqManager::setDefMirrorFlip()
{
/* set defalut mirror & flip from iq*/
bool def_mirr = mCalibDb->expset.CISFlip & 0x1 ? true : false;
bool def_flip = mCalibDb->expset.CISFlip & 0x2 ? true : false;
setMirrorFlip(def_mirr, def_flip, 0);
}
XCamReturn RkAiqManager::swWorkingModeDyn_msg(rk_aiq_working_mode_t mode) {
SmartPtr<RkAiqMngCmdThread::msg_t> msg = new RkAiqMngCmdThread::msg_t();
msg->cmd = RkAiqMngCmdThread::MSG_CMD_SW_WORKING_MODE;
msg->sync = true;
msg->data.sw_wk_mode.mode = mode;
mAiqMngCmdTh->send_cmd(msg);
return XCAM_RETURN_NO_ERROR;
}
XCamReturn RkAiqManager::swWorkingModeDyn(rk_aiq_working_mode_t mode)
{
ENTER_XCORE_FUNCTION();
SmartPtr<RkAiqFullParamsProxy> initParams;
XCamReturn ret = XCAM_RETURN_NO_ERROR;
if (mode == mWorkingMode)
return ret;
if (_state != AIQ_STATE_STARTED) {
LOGW_ANALYZER("should be called at STARTED state");
return ret;
}
// 1. stop analyzer, re-preapre with the new mode
// 2. stop luma analyzer, re-preapre with the new mode
LOGI_ANALYZER("stop analyzer ...");
mAiqRstAppTh->triger_stop();
bool bret = mAiqRstAppTh->stop();
ret = bret ? XCAM_RETURN_NO_ERROR : XCAM_RETURN_ERROR_FAILED;
RKAIQMNG_CHECK_RET(ret, "apply result thread stop error");
ret = mRkAiqAnalyzer->stop();
RKAIQMNG_CHECK_RET(ret, "analyzer stop error %d", ret);
ret = mRkLumaAnalyzer->stop();
RKAIQMNG_CHECK_RET(ret, "luma analyzer stop error %d", ret);
// 3. pause hwi
LOGI_ANALYZER("pause hwi ...");
ret = mCamHw->pause();
RKAIQMNG_CHECK_RET(ret, "pause hwi error %d", ret);
int working_mode_hw = RK_AIQ_WORKING_MODE_NORMAL;
if (mode == RK_AIQ_WORKING_MODE_ISP_HDR2)
working_mode_hw = RK_AIQ_ISP_HDR_MODE_2_FRAME_HDR;
else if (mode == RK_AIQ_WORKING_MODE_ISP_HDR3)
working_mode_hw = RK_AIQ_ISP_HDR_MODE_3_FRAME_HDR;
// 4. set new mode to hwi
ret = mCamHw->swWorkingModeDyn(working_mode_hw);
if (ret) {
LOGE_ANALYZER("hwi swWorkingModeDyn error ...");
goto restart;
}
// 5. re-prepare analyzer
LOGI_ANALYZER("reprepare analyzer ...");
rk_aiq_exposure_sensor_descriptor sensor_des;
ret = mCamHw->getSensorModeData(mSnsEntName, sensor_des);
ret = mRkAiqAnalyzer->prepare(&sensor_des, working_mode_hw);
RKAIQMNG_CHECK_RET(ret, "analyzer prepare error %d", ret);
initParams = mRkAiqAnalyzer->getAiqFullParams();
ret = applyAnalyzerResult(initParams);
RKAIQMNG_CHECK_RET(ret, "set initial params error %d", ret);
restart:
// 6. resume hwi
LOGI_ANALYZER("resume hwi");
ret = mCamHw->resume();
RKAIQMNG_CHECK_RET(ret, "pause hwi error %d", ret);
// 7. restart analyzer
LOGI_ANALYZER("restart analyzer");
mAiqRstAppTh->triger_start();
bret = mAiqRstAppTh->start();
ret = bret ? XCAM_RETURN_NO_ERROR : XCAM_RETURN_ERROR_FAILED;
RKAIQMNG_CHECK_RET(ret, "apply result thread start error");
ret = mRkAiqAnalyzer->start();
RKAIQMNG_CHECK_RET(ret, "analyzer start error %d", ret);
ret = mRkLumaAnalyzer->start();
RKAIQMNG_CHECK_RET(ret, "luma analyzer start error %d", ret);
/* // 7. resume hwi */
/* LOGI_ANALYZER("resume hwi"); */
/* ret = mCamHw->resume(); */
/* RKAIQMNG_CHECK_RET(ret, "pause hwi error %d", ret); */
mWorkingMode = mode;
EXIT_XCORE_FUNCTION();
return XCAM_RETURN_NO_ERROR;
}
void RkAiqManager::setMulCamConc(bool cc)
{
#ifndef RK_SIMULATOR_HW
SmartPtr<CamHwIsp20> camHwIsp20 = mCamHw.dynamic_cast_ptr<CamHwIsp20>();
if (camHwIsp20.ptr())
camHwIsp20->setMulCamConc(cc);
#endif
}
}; //namespace RkCam