1 /*
2 * rk_aiq_user_api2_camgroup.cpp
3 *
4 * Copyright (c) 2021 Rockchip Corporation
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 */
19
20 #include "rk_aiq_user_api2_sysctl.h"
21 #include "rk_aiq_user_api2_camgroup.h"
22 #include "RkAiqCamGroupManager.h"
23 #include "common/panorama_stitchingApp.h"
24
25 using namespace RkCam;
26 using namespace XCam;
27
28 static XCamReturn
_cam_group_bind(rk_aiq_camgroup_ctx_t * camgroup_ctx,rk_aiq_sys_ctx_t * aiq_ctx)29 _cam_group_bind(rk_aiq_camgroup_ctx_t* camgroup_ctx, rk_aiq_sys_ctx_t* aiq_ctx)
30 {
31 #ifdef RKAIQ_ENABLE_CAMGROUP
32 ENTER_XCORE_FUNCTION();
33
34 XCamReturn ret = XCAM_RETURN_NO_ERROR;
35
36 // bind aiq to group
37 ret = camgroup_ctx->cam_group_manager->bind(aiq_ctx->_rkAiqManager.ptr());
38 if (ret) {
39 LOGE("bind sensor %s aiq ctx %p failed !", aiq_ctx->_sensor_entity_name, aiq_ctx);
40 return ret;
41 }
42
43 camgroup_ctx->cam_group_manager->setContainerCtx(camgroup_ctx);
44
45 // bind group to aiq
46 aiq_ctx->_camGroupManager = camgroup_ctx->cam_group_manager.ptr();
47 aiq_ctx->_analyzer->setCamGroupManager(aiq_ctx->_camGroupManager);
48
49 #if 0
50 // set first one as main cam
51 aiq_ctx->_rkAiqManager->setCamGroupManager(aiq_ctx->_camGroupManager,
52 camgroup_ctx->cam_ctxs_num == 0 ? true : false);
53 #else
54 if (aiq_ctx->_is_1608_sensor) {
55 // 1608 sensor.
56 aiq_ctx->_rkAiqManager->setCamGroupManager(aiq_ctx->_camGroupManager, false);
57 camgroup_ctx->cam_1608_num++;
58 LOGD(" >>>>====<<<< sensor name: %s, 1608-sensor(%d), sync mode(isMain): %d. \n", aiq_ctx->_sensor_entity_name,
59 aiq_ctx->_is_1608_sensor,
60 false);
61 } else {
62 // normal sensor.
63 aiq_ctx->_rkAiqManager->setCamGroupManager(aiq_ctx->_camGroupManager,
64 camgroup_ctx->cam_ctxs_num == camgroup_ctx->cam_1608_num ? true : false);
65 LOGD(" >>>>====<<<< sensor name: %s, 1608-sensor(%d), sync mode(isMain): %d. \n", aiq_ctx->_sensor_entity_name,
66 aiq_ctx->_is_1608_sensor,
67 camgroup_ctx->cam_ctxs_num == \
68 camgroup_ctx->cam_1608_num ? true : false);
69 }
70 #endif
71
72 camgroup_ctx->cam_ctxs_num++;
73 camgroup_ctx->cam_ctxs_array[aiq_ctx->_camPhyId] = aiq_ctx;
74
75 LOGD("%s: bind sensor %s aiq ctx success !", aiq_ctx->_sensor_entity_name, aiq_ctx);
76
77 EXIT_XCORE_FUNCTION();
78 #endif
79
80 return XCAM_RETURN_NO_ERROR;
81 }
82
83 static XCamReturn
_cam_group_unbind(rk_aiq_camgroup_ctx_t * camgroup_ctx,rk_aiq_sys_ctx_t * aiq_ctx)84 _cam_group_unbind(rk_aiq_camgroup_ctx_t* camgroup_ctx, rk_aiq_sys_ctx_t* aiq_ctx)
85 {
86 #ifdef RKAIQ_ENABLE_CAMGROUP
87 ENTER_XCORE_FUNCTION();
88
89 XCamReturn ret = XCAM_RETURN_NO_ERROR;
90
91 ret = camgroup_ctx->cam_group_manager->unbind(aiq_ctx->_camPhyId);
92 if (ret) {
93 LOGE("unbind sensor %s aiq ctx 0x%x failed !", aiq_ctx->_sensor_entity_name, aiq_ctx);
94 return ret;
95 }
96 aiq_ctx->_camGroupManager = NULL;
97 aiq_ctx->_analyzer->setCamGroupManager(NULL);
98 aiq_ctx->_rkAiqManager->setCamGroupManager(NULL, false);
99 camgroup_ctx->cam_ctxs_array[aiq_ctx->_camPhyId] = NULL;
100 camgroup_ctx->cam_ctxs_num--;
101
102 LOGD("%s: unbind sensor %s aiq ctx success !", aiq_ctx->_sensor_entity_name, aiq_ctx);
103
104 EXIT_XCORE_FUNCTION();
105 #endif
106
107 return XCAM_RETURN_NO_ERROR;
108 }
109
110 rk_aiq_camgroup_ctx_t*
rk_aiq_uapi2_camgroup_create(rk_aiq_camgroup_instance_cfg_t * cfg)111 rk_aiq_uapi2_camgroup_create(rk_aiq_camgroup_instance_cfg_t* cfg)
112 {
113 #ifdef RKAIQ_ENABLE_CAMGROUP
114 ENTER_XCORE_FUNCTION();
115
116 XCamReturn ret = XCAM_RETURN_NO_ERROR;
117
118 rk_aiq_camgroup_ctx_t* camgroup_ctx = NULL;
119 rk_aiq_sys_ctx_t* aiq_ctx = NULL;
120 std::string single_iq_file;
121 std::string camgroup_iq_file;
122 std::string overlap_map_file;
123
124 camgroup_ctx = new rk_aiq_camgroup_ctx_t();
125
126 if (!camgroup_ctx)
127 goto error;
128
129 camgroup_ctx->cam_group_manager = new RkAiqCamGroupManager();
130 if (!camgroup_ctx->cam_group_manager.ptr())
131 goto error;
132
133 camgroup_ctx->_apiMutex = new Mutex();
134 //RKAIQ_API_SMART_LOCK(camgroup_ctx);
135
136 if (cfg->sns_num > RK_AIQ_CAM_GROUP_MAX_CAMS) {
137 LOGE("nums %s is over the max cams %d !", cfg->sns_num, RK_AIQ_CAM_GROUP_MAX_CAMS);
138 return NULL;
139 }
140
141 camgroup_ctx->cam_type = RK_AIQ_CAM_TYPE_GROUP;
142 camgroup_ctx->cam_ctxs_num = 0;
143 camgroup_ctx->cam_1608_num = 0;
144 memset(camgroup_ctx->cam_ctxs_array, 0, sizeof(camgroup_ctx->cam_ctxs_array));
145 camgroup_ctx->_srcOverlapMap_s = NULL;
146 camgroup_ctx->_camgroup_calib = NULL;
147
148 if (cfg->config_file_dir) {
149 if (cfg->single_iq_file) {
150 //single_iq_file += cfg->config_file_dir;
151 //single_iq_file += "/";
152 single_iq_file += cfg->single_iq_file;
153 }
154 if (cfg->group_iq_file) {
155 camgroup_iq_file += cfg->config_file_dir;
156 camgroup_iq_file += "/";
157 camgroup_iq_file += cfg->group_iq_file;
158 }
159 if (cfg->overlap_map_file) {
160 overlap_map_file += cfg->config_file_dir;
161 overlap_map_file += "/";
162 overlap_map_file += cfg->overlap_map_file;
163 }
164 }
165
166 if (overlap_map_file.length()) {
167 camgroup_ctx->_srcOverlapMap_s = new RK_PS_SrcOverlapMap();
168 ret = rk_aiq_uapi2_camgroup_getOverlapMap_from_file(overlap_map_file.c_str(),
169 &camgroup_ctx->_srcOverlapMap_s);
170 if (ret) {
171 delete camgroup_ctx->_srcOverlapMap_s;
172 camgroup_ctx->_srcOverlapMap_s = NULL;
173 }
174 }
175
176 for (int i = 0; i < cfg->sns_num; i++) {
177 // TODO: fix 1608 psy-sensor, "m0x_b_RK1608-dphy RK1608-dphy0"
178 if (strstr(cfg->sns_ent_nm_array[i], "1608")) {
179 // LOGE(" >>>>====<<<< sensor_name: %s.", cfg->sns_ent_nm_array[i]);
180 continue;
181 }
182
183 if (single_iq_file.length())
184 rk_aiq_uapi_sysctl_preInit(cfg->sns_ent_nm_array[i],
185 RK_AIQ_WORKING_MODE_NORMAL, /* nonsense */
186 single_iq_file.c_str());
187
188 if (cfg->pHwEvt_cb)
189 rk_aiq_uapi2_sysctl_regHwEvtCb(cfg->sns_ent_nm_array[i],
190 cfg->pHwEvt_cb,
191 cfg->pHwEvtCbCtx);
192
193 aiq_ctx = rk_aiq_uapi_sysctl_init(cfg->sns_ent_nm_array[i],
194 cfg->config_file_dir, NULL, NULL);
195 if (!aiq_ctx) {
196 LOGE("init aiq ctx %d for %s failed !", i, cfg->sns_ent_nm_array[i]);
197 goto error;
198 }
199 // notify single cam work as multiple mode
200 rk_aiq_uapi_sysctl_setMulCamConc(aiq_ctx, true);
201
202 if (camgroup_ctx->_srcOverlapMap_s) {
203 aiq_ctx->_hw_info.module_rotation =
204 camgroup_ctx->_srcOverlapMap_s->srcOverlapPositon[i];
205
206 // update module rotation info
207 aiq_ctx->_analyzer->setHwInfos(aiq_ctx->_hw_info);
208 }
209
210 ret = _cam_group_bind(camgroup_ctx, aiq_ctx);
211 if (ret) {
212 LOGE("%s: bind sensor %s aiq ctx 0x%x failed !",
213 __func__, aiq_ctx->_sensor_entity_name, aiq_ctx);
214 goto error;
215 }
216 }
217 if (camgroup_ctx->cam_1608_num == camgroup_ctx->cam_ctxs_num) {
218 LOGE("%s: >>>>====<<<< ERROR, Only slave(master-slave)-sensor work is not supported in group mode!", __func__);
219 goto error;
220 }
221
222 if (camgroup_iq_file.length())
223 camgroup_ctx->_camgroup_calib = RkAiqCalibDbV2::createCalibDbCamgroup(camgroup_iq_file.c_str());
224
225 ret = camgroup_ctx->cam_group_manager->setCamgroupCalib(camgroup_ctx->_camgroup_calib);
226 if (ret) {
227 LOGE("%s: set camgroup calib failed !", __func__);
228 goto error;
229 }
230 ret = camgroup_ctx->cam_group_manager->init();
231 if (ret) {
232 LOGE("%s: init failed !", __func__);
233 goto error;
234 }
235
236 LOGD("%s: create camgroup 0x%x success !", __func__, camgroup_ctx);
237
238 EXIT_XCORE_FUNCTION();
239
240 return camgroup_ctx;
241
242 error:
243 LOGE("%s failed", __func__);
244 if (camgroup_ctx)
245 rk_aiq_uapi2_camgroup_destroy(camgroup_ctx);
246 #endif
247 return NULL;
248 }
249
250 struct RK_PS_SrcOverlapMap*
rk_aiq_uapi2_camgroup_getOverlapMap(rk_aiq_camgroup_ctx_t * camgroup_ctx)251 rk_aiq_uapi2_camgroup_getOverlapMap(rk_aiq_camgroup_ctx_t* camgroup_ctx)
252 {
253 #ifdef RKAIQ_ENABLE_CAMGROUP
254 if (camgroup_ctx->_srcOverlapMap_s)
255 return camgroup_ctx->_srcOverlapMap_s;
256 else
257 return NULL;
258 #else
259 return NULL;
260 #endif
261 }
262
263 XCamReturn
rk_aiq_uapi2_camgroup_getOverlapMap_from_file(const char * map_file,struct RK_PS_SrcOverlapMap ** overlapMap)264 rk_aiq_uapi2_camgroup_getOverlapMap_from_file(const char* map_file, struct RK_PS_SrcOverlapMap** overlapMap)
265 {
266 #ifdef RKAIQ_ENABLE_CAMGROUP
267 FILE *fp2 = fopen(map_file, "rb");
268
269 if (fp2) {
270 fread(*overlapMap, sizeof(RK_PS_SrcOverlapMap), 1, fp2);
271 fclose(fp2);
272 return XCAM_RETURN_NO_ERROR;
273 } else {
274 LOGE("get overlap data from %s error!", map_file);
275 return XCAM_RETURN_ERROR_FAILED;
276 }
277 #else
278 return XCAM_RETURN_ERROR_FAILED;
279 #endif
280 }
281
282 rk_aiq_sys_ctx_t*
rk_aiq_uapi2_camgroup_getAiqCtxBySnsNm(rk_aiq_camgroup_ctx_t * camgroup_ctx,const char * sns_entity_name)283 rk_aiq_uapi2_camgroup_getAiqCtxBySnsNm(rk_aiq_camgroup_ctx_t* camgroup_ctx, const char* sns_entity_name)
284 {
285 #ifdef RKAIQ_ENABLE_CAMGROUP
286 ENTER_XCORE_FUNCTION();
287
288 RKAIQ_API_SMART_LOCK(camgroup_ctx);
289
290 for (int i = 0; i < RK_AIQ_CAM_GROUP_MAX_CAMS; i++) {
291 if (camgroup_ctx->cam_ctxs_array[i]) {
292 if (strcmp(camgroup_ctx->cam_ctxs_array[i]->_sensor_entity_name, sns_entity_name) == 0) {
293 LOGD("%s: get sensor %s aiq ctx 0x%x success !",
294 __func__, sns_entity_name, camgroup_ctx->cam_ctxs_array[i]);
295 return camgroup_ctx->cam_ctxs_array[i];
296 }
297 }
298 }
299
300 LOGD("%s: get sensor %s aiq ctx failed !", __func__, sns_entity_name);
301
302 EXIT_XCORE_FUNCTION();
303 #endif
304
305 return NULL;
306
307 }
308
309 XCamReturn
rk_aiq_uapi2_camgroup_bind(rk_aiq_camgroup_ctx_t * camgroup_ctx,rk_aiq_sys_ctx_t ** ctx,int num)310 rk_aiq_uapi2_camgroup_bind(rk_aiq_camgroup_ctx_t* camgroup_ctx, rk_aiq_sys_ctx_t** ctx, int num)
311 {
312 #ifdef RKAIQ_ENABLE_CAMGROUP
313 ENTER_XCORE_FUNCTION();
314
315 XCamReturn ret = XCAM_RETURN_NO_ERROR;
316
317 RKAIQ_API_SMART_LOCK(camgroup_ctx);
318
319 if (camgroup_ctx->cam_ctxs_num + num > RK_AIQ_CAM_GROUP_MAX_CAMS) {
320 LOGE("binded num %d + num %d > max %d !", camgroup_ctx->cam_ctxs_num, num, RK_AIQ_CAM_GROUP_MAX_CAMS);
321 return XCAM_RETURN_ERROR_OUTOFRANGE;
322 }
323
324 for (int j = 0; j < num; j++) {
325 // query bind status firstly
326 bool need_bind = true;
327 for (int i = 0; i < RK_AIQ_CAM_GROUP_MAX_CAMS; i++) {
328 if (camgroup_ctx->cam_ctxs_array[i] == ctx[j]) {
329 LOGI("already binded for ctx 0x%x", ctx[j]);
330 need_bind = false;
331 break;
332 }
333 }
334 // find a empty slot
335 if (need_bind) {
336 for (int i = 0; i < RK_AIQ_CAM_GROUP_MAX_CAMS; i++) {
337 if (camgroup_ctx->cam_ctxs_array[i] == NULL) {
338 ret = _cam_group_bind(camgroup_ctx, ctx[j]);
339 if (ret) {
340 LOGE("%s: bind sensor %s aiq ctx 0x%x failed !",
341 __func__, ctx[j]->_sensor_entity_name, ctx[j]);
342 break;
343 }
344 }
345 }
346 }
347 }
348
349 LOGD("%s: bind sensor aiq ctxs success !", __func__);
350
351 EXIT_XCORE_FUNCTION();
352 #endif
353
354 return XCAM_RETURN_NO_ERROR;
355 }
356
357 XCamReturn
rk_aiq_uapi2_camgroup_unbind(rk_aiq_camgroup_ctx_t * camgroup_ctx,rk_aiq_sys_ctx_t ** ctx,int num)358 rk_aiq_uapi2_camgroup_unbind(rk_aiq_camgroup_ctx_t* camgroup_ctx, rk_aiq_sys_ctx_t** ctx, int num)
359 {
360 #ifdef RKAIQ_ENABLE_CAMGROUP
361 ENTER_XCORE_FUNCTION();
362
363 RKAIQ_API_SMART_LOCK(camgroup_ctx);
364
365 for (int j = 0; j < num; j++) {
366 for (int i = 0; i < RK_AIQ_CAM_GROUP_MAX_CAMS; i++) {
367 if (camgroup_ctx->cam_ctxs_array[i] == ctx[j]) {
368 if (_cam_group_unbind(camgroup_ctx, ctx[j])) {
369 LOGE("%s: unbind sensor %s aiq ctx 0x%x failed !",
370 __func__, ctx[j]->_sensor_entity_name, ctx[j]);
371 break;
372 }
373 }
374 }
375 }
376
377 LOGD("%s: unbind sensor aiq ctxs success !", __func__);
378
379 EXIT_XCORE_FUNCTION();
380 #endif
381
382 return XCAM_RETURN_NO_ERROR;
383 }
384
385 XCamReturn
rk_aiq_uapi2_camgroup_prepare(rk_aiq_camgroup_ctx_t * camgroup_ctx,rk_aiq_working_mode_t mode)386 rk_aiq_uapi2_camgroup_prepare(rk_aiq_camgroup_ctx_t* camgroup_ctx, rk_aiq_working_mode_t mode)
387 {
388 #ifdef RKAIQ_ENABLE_CAMGROUP
389 ENTER_XCORE_FUNCTION();
390
391 XCamReturn ret = XCAM_RETURN_NO_ERROR;
392
393 RKAIQ_API_SMART_LOCK(camgroup_ctx);
394
395 for (int i = 0; i < RK_AIQ_CAM_GROUP_MAX_CAMS; i++) {
396 rk_aiq_sys_ctx_t* aiq_ctx = camgroup_ctx->cam_ctxs_array[i];
397 if (aiq_ctx) {
398 ret = rk_aiq_uapi_sysctl_prepare(aiq_ctx, 0, 0, mode);
399 if (ret) {
400 LOGE("%s: prepare failed for aiq ctx 0x%x !", __func__, aiq_ctx);
401 continue;
402 }
403 }
404 }
405
406 ret = camgroup_ctx->cam_group_manager->prepare();
407 if (ret) {
408 LOGE("%s: prepare failed !", __func__);
409 return ret;
410 }
411
412 LOGD("%s: prepare camgroup success !", __func__);
413
414 EXIT_XCORE_FUNCTION();
415 #endif
416
417 return XCAM_RETURN_NO_ERROR;
418 }
419
420 XCamReturn
rk_aiq_uapi2_camgroup_start(rk_aiq_camgroup_ctx_t * camgroup_ctx)421 rk_aiq_uapi2_camgroup_start(rk_aiq_camgroup_ctx_t* camgroup_ctx)
422 {
423 #ifdef RKAIQ_ENABLE_CAMGROUP
424 ENTER_XCORE_FUNCTION();
425
426 XCamReturn ret = XCAM_RETURN_NO_ERROR;
427
428 RKAIQ_API_SMART_LOCK(camgroup_ctx);
429
430 ret = camgroup_ctx->cam_group_manager->start();
431 if (ret) {
432 LOGE("%s: start failed !", __func__);
433 return ret;
434 }
435
436 for (int i = 0; i < RK_AIQ_CAM_GROUP_MAX_CAMS; i++) {
437 rk_aiq_sys_ctx_t* aiq_ctx = camgroup_ctx->cam_ctxs_array[i];
438 if (aiq_ctx) {
439 ret = rk_aiq_uapi_sysctl_start(aiq_ctx);
440 if (ret) {
441 LOGE("%s: start failed for aiq ctx 0x%x !", __func__, aiq_ctx);
442 continue;
443 }
444 }
445 }
446
447 LOGD("%s: start camgroup success !", __func__);
448
449 EXIT_XCORE_FUNCTION();
450 #endif
451
452 return XCAM_RETURN_NO_ERROR;
453 }
454
455 XCamReturn
rk_aiq_uapi2_camgroup_stop(rk_aiq_camgroup_ctx_t * camgroup_ctx)456 rk_aiq_uapi2_camgroup_stop(rk_aiq_camgroup_ctx_t* camgroup_ctx)
457 {
458 #ifdef RKAIQ_ENABLE_CAMGROUP
459 ENTER_XCORE_FUNCTION();
460
461 XCamReturn ret = XCAM_RETURN_NO_ERROR;
462
463 RKAIQ_API_SMART_LOCK(camgroup_ctx);
464
465 ret = camgroup_ctx->cam_group_manager->stop();
466 if (ret) {
467 LOGE("%s: stop failed !", __func__);
468 return ret;
469 }
470
471 for (int i = 0; i < RK_AIQ_CAM_GROUP_MAX_CAMS; i++) {
472 rk_aiq_sys_ctx_t* aiq_ctx = camgroup_ctx->cam_ctxs_array[i];
473 if (aiq_ctx) {
474 ret = rk_aiq_uapi_sysctl_stop(aiq_ctx, false);
475 if (ret) {
476 LOGE("%s: stop failed for aiq ctx 0x%x !", __func__, aiq_ctx);
477 continue;
478 }
479 }
480 }
481
482 LOGD("%s: stop camgroup success !", __func__);
483
484 EXIT_XCORE_FUNCTION();
485 #endif
486
487 return XCAM_RETURN_NO_ERROR;
488
489 }
490
491 XCamReturn
rk_aiq_uapi2_camgroup_destroy(rk_aiq_camgroup_ctx_t * camgroup_ctx)492 rk_aiq_uapi2_camgroup_destroy(rk_aiq_camgroup_ctx_t* camgroup_ctx)
493 {
494 #ifdef RKAIQ_ENABLE_CAMGROUP
495 ENTER_XCORE_FUNCTION();
496
497 XCamReturn ret = XCAM_RETURN_NO_ERROR;
498 {
499 RKAIQ_API_SMART_LOCK(camgroup_ctx);
500 for (int i = 0; i < RK_AIQ_CAM_GROUP_MAX_CAMS; i++) {
501 rk_aiq_sys_ctx_t* aiq_ctx = camgroup_ctx->cam_ctxs_array[i];
502 if (aiq_ctx) {
503 ret = _cam_group_unbind(camgroup_ctx, aiq_ctx);
504 if (ret) {
505 LOGE("%s: unbind sensor %s aiq ctx 0x%x failed !",
506 __func__, aiq_ctx->_sensor_entity_name, aiq_ctx);
507 continue;
508 }
509 rk_aiq_uapi_sysctl_deinit(aiq_ctx);
510 }
511 }
512
513 if (camgroup_ctx->cam_ctxs_num > 0) {
514 LOGE("impossible case, some aiq ctx may not deinit !");
515 }
516 ret = camgroup_ctx->cam_group_manager->deInit();
517 if (ret) {
518 LOGE("%s: deinit failed !", __func__);
519 return ret;
520 }
521 camgroup_ctx->cam_group_manager.release();
522 }
523 if (camgroup_ctx->_camgroup_calib) {
524 RkAiqCalibDbV2::CamCalibDbCamgroupFree(camgroup_ctx->_camgroup_calib);
525 }
526 if (camgroup_ctx->_srcOverlapMap_s)
527 delete camgroup_ctx->_srcOverlapMap_s;
528 camgroup_ctx->_apiMutex.release();
529 delete camgroup_ctx;
530
531 LOGD("%s: destroy camgroup success !", __func__);
532
533 EXIT_XCORE_FUNCTION();
534 #endif
535
536 return XCAM_RETURN_NO_ERROR;
537 }
538
539 XCamReturn
rk_aiq_uapi2_camgroup_getCamInfos(rk_aiq_camgroup_ctx_t * camgroup_ctx,rk_aiq_camgroup_camInfos_t * camInfos)540 rk_aiq_uapi2_camgroup_getCamInfos(rk_aiq_camgroup_ctx_t* camgroup_ctx, rk_aiq_camgroup_camInfos_t* camInfos)
541 {
542 #ifdef RKAIQ_ENABLE_CAMGROUP
543 ENTER_XCORE_FUNCTION();
544
545 XCamReturn ret = XCAM_RETURN_NO_ERROR;
546 {
547 RKAIQ_API_SMART_LOCK(camgroup_ctx);
548 if (!camInfos) {
549 LOGE("null params !");
550 return XCAM_RETURN_ERROR_PARAM;
551 }
552
553 camInfos->valid_sns_num = camgroup_ctx->cam_ctxs_num;
554
555 for (int i = 0, j = 0; i < RK_AIQ_CAM_GROUP_MAX_CAMS; i++) {
556 rk_aiq_sys_ctx_t* aiq_ctx = camgroup_ctx->cam_ctxs_array[i];
557
558 if (aiq_ctx) {
559 camInfos->sns_ent_nm[j] = aiq_ctx->_sensor_entity_name;
560 camInfos->sns_camPhyId[j] = aiq_ctx->_camPhyId;
561 j++;
562 }
563 }
564 }
565 EXIT_XCORE_FUNCTION();
566 #endif
567
568 return XCAM_RETURN_NO_ERROR;
569 }
570
571 XCamReturn
rk_aiq_uapi2_camgroup_resetCam(rk_aiq_camgroup_ctx_t * camgroup_ctx,int camId)572 rk_aiq_uapi2_camgroup_resetCam(rk_aiq_camgroup_ctx_t* camgroup_ctx, int camId)
573 {
574 #ifdef RKAIQ_ENABLE_CAMGROUP
575 ENTER_XCORE_FUNCTION();
576 XCamReturn ret = XCAM_RETURN_NO_ERROR;
577
578 if (!camgroup_ctx)
579 return XCAM_RETURN_ERROR_PARAM;
580
581 for (auto camCtx : camgroup_ctx->cam_ctxs_array) {
582 if (!camCtx)
583 continue;
584
585 if (camCtx->_camPhyId == camId) {
586 LOGD("cam: %d, reset...", camId);
587 ret = camCtx->_camHw->reset_hardware();
588 if (ret) {
589 LOGE("failed to reset hardware\n");
590 return XCAM_RETURN_ERROR_IOCTL;
591 }
592 }
593 }
594
595 EXIT_XCORE_FUNCTION();
596 #endif
597
598 return XCAM_RETURN_NO_ERROR;
599 }
600
601