1 /* 2 * Copyright (c) 2019 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 #ifndef RK_AIQ_USER_API2_SYSCTL_H 19 #define RK_AIQ_USER_API2_SYSCTL_H 20 21 #include "rk_aiq.h" 22 #include "rk_aiq_algo_des.h" 23 #include "rk_aiq_offline_raw.h" 24 // #include "rk_aiq_user_api_sysctl.h" 25 26 RKAIQ_BEGIN_DECLARE 27 28 #ifndef RK_AIQ_SYS_CTX_T 29 #define RK_AIQ_SYS_CTX_T 30 typedef struct rk_aiq_sys_ctx_s rk_aiq_sys_ctx_t; 31 #endif 32 33 /********************below are verified api********************/ 34 35 /*! 36 * \brief pre-settings before init 37 * 38 * \param[in] sns_ent_name active sensor media entity name. This represents the unique camera module 39 * in system. And the whole active pipeline could be retrieved by this. 40 * \param[in] mode pipleline working mode, just used by \ref 41 * rk_aiq_uapi_sysctl_init to select iq file 42 * according to hdr mode. Unused if params \ref 43 * iq_file is specified. 44 * \param[in] force_iq_file optional, forcely used this iq file. Must be xml. 45 * Such as -> force_iq_file = "ov5695_TongJu_CHT842-MD.xml"; 46 * Meanwhile, there must has "ov5695_TongJu_CHT842-MD.json" in the same path with xml. 47 * \note Optional API, should be called before\ref rk_aiq_uapi_sysctl_init. This 48 * API extends the functionality of \ref rk_aiq_uapi_sysctl_init. And just 49 * used to help select the satisfied iq file when multiple iq files 50 * exsist. 51 */ 52 XCamReturn 53 rk_aiq_uapi2_sysctl_preInit(const char* sns_ent_name, 54 rk_aiq_working_mode_t mode, 55 const char* force_iq_file); 56 57 XCamReturn 58 rk_aiq_uapi2_sysctl_regHwEvtCb(const char* sns_ent_name, 59 rk_aiq_hwevt_cb hwevt_cb, 60 void* cb_ctx); 61 62 /*! 63 * \brief initialze aiq control system context 64 * Should call before any other APIs 65 * 66 * \param[in] sns_ent_name active sensor media entity name. This represents the unique camera module\n 67 * in system. And the whole active pipeline could be retrieved by this. 68 * \param[in] iq_file_dir define the search directory of the iq files. 69 * \param[in] err_cb not mandatory. it's used to return system errors to user. 70 * \param[in] metas_cb not mandatory. it's used to return the metas(sensor exposure settings,\n 71 * isp settings, etc.) for each frame 72 * \return return system context if success, or NULL if failure. 73 */ 74 rk_aiq_sys_ctx_t* 75 rk_aiq_uapi2_sysctl_init(const char* sns_ent_name, 76 const char* iq_file_dir, 77 rk_aiq_error_cb err_cb, 78 rk_aiq_metas_cb metas_cb); 79 80 /*! 81 * \brief deinitialze aiq context 82 * Should not be called in started state 83 * 84 * \param[in] ctx the context returned by \ref rk_aiq_uapi2_sysctl_init 85 */ 86 void 87 rk_aiq_uapi2_sysctl_deinit( rk_aiq_sys_ctx_t* ctx); 88 89 /*! 90 * \brief prepare aiq control system before runninig 91 * prepare AIQ running enviroment, should be called before \ref rk_aiq_uapi2_sysctl_start.\n 92 * And if re-prepared is required after \ref rk_aiq_uapi2_sysctl_start is called,\n 93 * should call \ref rk_aiq_uapi2_sysctl_stop firstly. 94 * 95 * \param[in] ctx the context returned by \ref rk_aiq_uapi2_sysctl_init 96 * \param[in] width sensor active output width, just used to check internally 97 * \param[in] height sensor active output height, just used to check internally 98 * \param[in] mode pipleline working mode 99 * \return return 0 if success 100 */ 101 XCamReturn 102 rk_aiq_uapi2_sysctl_prepare(const rk_aiq_sys_ctx_t* ctx, 103 uint32_t width, uint32_t height, 104 rk_aiq_working_mode_t mode); 105 106 /*! 107 * \brief start aiq control system 108 * should be called after \ref rk_aiq_uapi2_sysctl_prepare. After this call, 109 * the aiq system repeats getting 3A statistics from ISP driver, running 110 * aiq algorimths(AE, AWB, AF, etc.), setting new parameters to drivers. 111 * 112 * \param[in] ctx the context returned by \ref rk_aiq_uapi2_sysctl_init 113 * \return return 0 if success 114 */ 115 XCamReturn 116 rk_aiq_uapi2_sysctl_start(const rk_aiq_sys_ctx_t* ctx); 117 118 /*! 119 * \brief stop aiq control system 120 * 121 * \param[in] ctx the context returned by \ref rk_aiq_uapi2_sysctl_init 122 * \param[in] keep_ext_hw_st do not change external devices status, like ircut/cpsl 123 * \return return 0 if success 124 */ 125 XCamReturn 126 rk_aiq_uapi2_sysctl_stop(const rk_aiq_sys_ctx_t* ctx, bool keep_ext_hw_st); 127 128 /*! 129 * \brief get aiq version infos 130 * 131 * \param[in,out] vers version infos 132 * \return return 0 if success 133 */ 134 void rk_aiq_uapi2_get_version_info(rk_aiq_ver_info_t* vers); 135 136 /*! 137 * \brief apply an new iq file when stream on 138 * 139 * \param[in] iqfile iqfile which will be applied 140 */ 141 XCamReturn 142 rk_aiq_uapi2_sysctl_updateIq(rk_aiq_sys_ctx_t* sys_ctx, char* iqfile); 143 144 145 int32_t 146 rk_aiq_uapi2_sysctl_getModuleCtl(const rk_aiq_sys_ctx_t* ctx, 147 rk_aiq_module_id_t mId, bool *mod_en); 148 149 XCamReturn 150 rk_aiq_uapi2_sysctl_setModuleCtl(const rk_aiq_sys_ctx_t* ctx, rk_aiq_module_id_t mId, bool mod_en); 151 152 153 /*! 154 * \brief get algo lib enabled status 155 * 156 * \param[in] ctx context 157 * \param[in] algo_type algo type defined by RkAiqAlgoDesComm.type 158 * \param[in] lib_id 0 for system integrated algos;\n 159 * returned by call \ref rk_aiq_uapi2_sysctl_regLib for customer algos 160 * \return return true if enabled , false if disabled or unregistered 161 */ 162 bool 163 rk_aiq_uapi2_sysctl_getAxlibStatus(const rk_aiq_sys_ctx_t* ctx, 164 const int algo_type, 165 const int lib_id); 166 167 /*! 168 * \brief enable or disable algo lib 169 * If the \ref lib_id is the same as the current running algo, this interface 170 * could be called in any state except for the context uninitialized. Otherwise, 171 * it could only be called in prepared or initialized state followed by 172 * call \ref rk_aiq_uapi2_sysctl_prepare , and in this case, the old algo which type 173 * is \ref algo_type will be replaced by the new algo \ref lib_id. 174 * 175 * \param[in] ctx context 176 * \param[in] algo_type algo type defined by RkAiqAlgoDesComm.type 177 * \param[in] lib_id 0 for system integrated algos;\n 178 * returned by call \ref rk_aiq_uapi2_sysctl_regLib for customer algos 179 * \param[in] enable enable or disable algos. enable means running the algo's processes\n 180 * defined in \ref RkAiqAlgoDesComm; disable means\n 181 * bypass the algo's prcosses. 182 * \return return 0 if success 183 */ 184 XCamReturn 185 rk_aiq_uapi2_sysctl_enableAxlib(const rk_aiq_sys_ctx_t* ctx, 186 const int algo_type, 187 const int lib_id, 188 bool enable); 189 190 /*! 191 * \brief get enabled algo lib context 192 * The returned algo context will be used as the first param of algo private APIs. 193 * For those customer's algo lib, this interface should be called after 194 * \ref rk_aiq_uapi_sysctl_enableAxlib, or will return NULL. 195 * 196 * \param[in] ctx context 197 * \param[in] algo_type algo type defined by RkAiqAlgoDesComm.type 198 * \return return 0 if success 199 */ 200 const RkAiqAlgoContext* 201 rk_aiq_uapi2_sysctl_getEnabledAxlibCtx(const rk_aiq_sys_ctx_t* ctx, const int algo_type); 202 203 /********************below api continue to use api of CamHwIsp20********************/ 204 205 XCamReturn 206 rk_aiq_uapi2_sysctl_getStaticMetas(const char* sns_ent_name, rk_aiq_static_info_t* static_info); 207 208 XCamReturn 209 rk_aiq_uapi2_sysctl_enumStaticMetasByPhyId(int index, rk_aiq_static_info_t* static_info); 210 /*! 211 * \brief enum static camera infos 212 * 213 * \param[in] index which camera info will be enum 214 * \param[out] static_info returned camera infos 215 * \return return 0 if success 216 */ 217 XCamReturn 218 rk_aiq_uapi2_sysctl_enumStaticMetas(int index, rk_aiq_static_info_t* static_info); 219 220 /*! 221 * \brief get sensor entity name from video node 222 * \param[in] vd pp stream video node full path 223 * \return return the binded sensor name 224 */ 225 const char* 226 rk_aiq_uapi2_sysctl_getBindedSnsEntNmByVd(const char* vd); 227 228 /*! 229 * \brief get crop window of isp input 230 * 231 * \param[in] rect get cams crop prop 232 */ 233 XCamReturn 234 rk_aiq_uapi2_sysctl_getCrop(const rk_aiq_sys_ctx_t* sys_ctx, rk_aiq_rect_t *rect); 235 236 237 /*! 238 * \brief set compensation light config 239 * 240 * \param[in] ctx context 241 * \param[out] cfg cpsl configs 242 * \return return 0 if success 243 */ 244 XCamReturn 245 rk_aiq_uapi2_sysctl_setCpsLtCfg(const rk_aiq_sys_ctx_t* ctx, 246 rk_aiq_cpsl_cfg_t* cfg); 247 /*! 248 * \brief get compensation light info 249 * 250 * \param[in] ctx context 251 * \param[out] info current cpsl settings 252 * \return return 0 if success 253 */ 254 XCamReturn 255 rk_aiq_uapi2_sysctl_getCpsLtInfo(const rk_aiq_sys_ctx_t* ctx, 256 rk_aiq_cpsl_info_t* info); 257 /*! 258 * \brief query compensation light capability 259 * 260 * \param[in] ctx context 261 * \param[out] cap cpsl cap info 262 * \return return 0 if success 263 */ 264 XCamReturn 265 rk_aiq_uapi2_sysctl_queryCpsLtCap(const rk_aiq_sys_ctx_t* ctx, 266 rk_aiq_cpsl_cap_t* cap); 267 268 /*! 269 * \brief set the bypass stream rotation 270 * 271 * \param[in] ctx context 272 * \param[in] rot rotation val 273 * \return return 0 if success 274 */ 275 XCamReturn 276 rk_aiq_uapi2_sysctl_setSharpFbcRotation(const rk_aiq_sys_ctx_t* ctx, rk_aiq_rotation_t rot); 277 278 /*! 279 * \brief set multiple cameras working concurrently 280 * Notify this AIQ ctx will run with other sensor's AIQ ctx. 281 282 * \param[in] cc set cams concurrently used or not 283 * \note should be called before rk_aiq_uapi_sysctl_start 284 */ 285 void 286 rk_aiq_uapi2_sysctl_setMulCamConc(const rk_aiq_sys_ctx_t* ctx, bool cc); 287 288 /*! 289 * \brief register mems sensor handler interface 290 * 291 * \param[in] intf mems sensor interfaces 292 */ 293 XCamReturn 294 rk_aiq_uapi2_sysctl_regMemsSensorIntf(const rk_aiq_sys_ctx_t* sys_ctx, 295 const rk_aiq_mems_sensor_intf_t* intf); 296 297 /** 298 * @brief switch calibDB for different scene 299 * 300 * @param sys_ctx 301 * @param main_scene main scene name 302 * @param sub_scene sub scenen name 303 * 304 * @return 0 if no error 305 */ 306 int 307 rk_aiq_uapi2_sysctl_switch_scene(const rk_aiq_sys_ctx_t* sys_ctx, 308 const char* main_scene, 309 const char* sub_scene); 310 311 XCamReturn 312 rk_aiq_uapi2_sysctl_tuning(const rk_aiq_sys_ctx_t* sys_ctx, char* param); 313 314 char* rk_aiq_uapi2_sysctl_readiq(const rk_aiq_sys_ctx_t* sys_ctx, char* param); 315 316 XCamReturn 317 rk_aiq_uapi2_sysctl_preInit_scene(const char* sns_ent_name, const char *main_scene, 318 const char *sub_scene); 319 /** 320 * @brief set thunder boot info to aiq 321 * 322 * @param sns_ent_name sensor name 323 * @param is_pre_aiq is pre-customer aiq 324 * 325 * @return 0 if no error 326 */ 327 XCamReturn 328 rk_aiq_uapi2_sysctl_preInit_tb_info(const char* sns_ent_name, 329 const rk_aiq_tb_info_t* info); 330 331 /** 332 * @brief preInit the addr of IQ 333 * 334 * @param sns_ent_name 335 * @param addr 336 * @param len 337 * 338 * @return 0 if no error 339 */ 340 XCamReturn 341 rk_aiq_uapi2_sysctl_preInit_iq_addr(const char* sns_ent_name, void *addr, size_t len); 342 343 /** 344 * @brief preInit the addr of IQ 345 * 346 * @param sns_ent_name 347 * @param addr 348 * @param len 349 * 350 * @return 0 if no error 351 */ 352 XCamReturn 353 rk_aiq_uapi2_sysctl_preInit_iq_addr(const char* sns_ent_name, void *addr, size_t len); 354 355 typedef struct rk_aiq_ctx_camInfo_s { 356 const char* sns_ent_nm; 357 int sns_camPhyId; 358 } rk_aiq_ctx_camInfo_t; 359 360 /** 361 * @brief preInit the addr of CamCalibProj 362 * 363 * @param sns_ent_name 364 * @param addr 365 * 366 * @return 0 if no error 367 */ 368 XCamReturn 369 rk_aiq_uapi2_sysctl_preInit_calibproj(const char* sns_ent_name, void *addr); 370 371 372 /** 373 * @brief set device buffer count, currently only for raw tx/rx device 374 * 375 * @param sns_ent_name: Sensor entity name, can get from #rk_aiq_uapi2_sysctl_getBindedSnsEntNmByVd 376 * @param dev_ent: Device entity string, if equals "rkraw_tx" or "rkraw_rx", will set for all tx/rx devices 377 * @param buf_cnt: V4l2 buffer count for video device of entity #dev_ent 378 * 379 * @return XCAM_RETURN_NO_ERROR if no error, otherwise return values < 0 380 */ 381 XCamReturn 382 rk_aiq_uapi2_sysctl_preInit_devBufCnt(const char* sns_ent_name, const char* dev_ent, 383 int buf_cnt); 384 385 XCamReturn 386 rk_aiq_uapi2_sysctl_getCamInfos(const rk_aiq_sys_ctx_t* sys_ctx, rk_aiq_ctx_camInfo_t* camInfo); 387 388 /*! 389 * \brief get 3a stats 390 * 391 * \param[in] ctx context 392 * \param[out] stats stats params 393 * \return return 0 if success 394 * \note non-blocked interface, and copy the result to stats. 395 */ 396 XCamReturn 397 rk_aiq_uapi2_sysctl_get3AStats(const rk_aiq_sys_ctx_t* ctx, 398 rk_aiq_isp_stats_t *stats); 399 400 /*! 401 * \brief get 3a stats 402 * 403 * \param[in] ctx context 404 * \param[out] stats stats params ref 405 * \param[in] timeout_ms -1 means wait always until stats is available or 406 * stopped 407 * \return return 0 if success 408 * \note blocked interface, and return the stats ref, user should 409 * call \ref rk_aiq_uapi_sysctl_release3AStatsRef to release. 410 */ 411 XCamReturn 412 rk_aiq_uapi2_sysctl_get3AStatsBlk(const rk_aiq_sys_ctx_t* ctx, 413 rk_aiq_isp_stats_t **stats, int timeout_ms); 414 415 /*! 416 * \brief release 3a stats result ref 417 * 418 * \param[in] ctx context 419 * \param[out] stats stats ref 420 * \return void 421 * \note called with \ref rk_aiq_uapi_sysctl_get3AStatsBlk 422 */ 423 void 424 rk_aiq_uapi2_sysctl_release3AStatsRef(const rk_aiq_sys_ctx_t* ctx, 425 rk_aiq_isp_stats_t *stats); 426 427 /*! 428 * \brief prepare RK-raw-format data process environment 429 * 430 * \param[in] ctx context 431 * \param[in] prop prepare params 432 * \return return 0 if success 433 */ 434 XCamReturn 435 rk_aiq_uapi2_sysctl_prepareRkRaw(const rk_aiq_sys_ctx_t* ctx, rk_aiq_raw_prop_t prop); 436 437 /*! 438 * \brief queue RK-Raw-format buffer into aiq control system 439 * 440 * \param[in] ctx context 441 * \param[in] rawdata RK-Raw-format buffer 442 * \param[in] sync sync flag, true means sync mode,calling process will be blocked, 443 * until the queued frame is processed. false means async mode, calling 444 * process is not blocked, if you want to free rawdata or reuse it, callback 445 * should be registered,after frame is processed, callback function would be called. 446 * \return return 0 if success 447 */ 448 XCamReturn 449 rk_aiq_uapi2_sysctl_enqueueRkRawBuf(const rk_aiq_sys_ctx_t* ctx, void *rawdata, bool sync); 450 451 /*! 452 * \brief queue RK-Raw-format file into aiq control system 453 * 454 * \param[in] ctx context 455 * \param[in] path RK-Raw-format file path 456 * calling process will be blocked until the queued frame is processed 457 * \return return 0 if success 458 */ 459 XCamReturn 460 rk_aiq_uapi2_sysctl_enqueueRkRawFile(const rk_aiq_sys_ctx_t* ctx, const char *path); 461 462 /*! 463 * \brief regist RK-Raw-format buffer callback into aiq control system 464 * 465 * \param[in] ctx context 466 * \param[in] callback callback function pointer 467 * if callback function is registered, (when rk_aiq_uapi_sysctl_enqueueRkRawBuf used in sync mode) 468 * callback will be called in sync after the queued raw buffer is processed, raw buffer pointer 469 * which passed into aiq by rk_aiq_uapi_sysctl_enqueueRkRawBuf would be passed back into the callback 470 * function you registered. 471 * this function is not required. 472 * 473 * \return return 0 if success 474 */ 475 476 XCamReturn 477 rk_aiq_uapi2_sysctl_registRkRawCb(const rk_aiq_sys_ctx_t* ctx, void (*callback)(void*)); 478 479 /*! 480 * \brief get working mode 481 * 482 * \param[in] ctx context 483 * \param[out] working_mode rk_aiq_working_mode_t 484 */ 485 XCamReturn 486 rk_aiq_uapi2_sysctl_getWorkingMode(const rk_aiq_sys_ctx_t* ctx, rk_aiq_working_mode_t *mode); 487 488 /** 489 * @brief turn on/off socket server 490 * 491 * @param sys_ctx 492 * @param enable 493 * 494 * @return 0 if no error 495 */ 496 int rk_aiq_uapi2_sysctl_tuning_enable(rk_aiq_sys_ctx_t* sys_ctx, bool enable); 497 498 XCamReturn 499 rk_aiq_uapi2_sysctl_resetCam(const rk_aiq_sys_ctx_t* sys_ctx, int camId); 500 501 /** 502 * @brief generated isp params for offline raw 503 * 504 * @param sys_ctx 505 * @param sequence frame number 506 * @param next_frm_info next frame exp info, if mode=0, set null 507 * @param mode mode=1 working mode is all offline, mode=0 working mode is semi-offline 508 */ 509 void rk_aiq_uapi2_sysctl_rawReproc_genIspParams (rk_aiq_sys_ctx_t* sys_ctx, 510 uint32_t sequence, 511 rk_aiq_frame_info_t *next_frm_info, 512 int mode); 513 514 /** 515 * @brief set isp driver work mode to all offline 516 * 517 * @param isp_driver isp driver module name(such as rkisp0-vir0) 518 * use media-clt to print rkisp driver media info and get isp driver module name from the info printed 519 * @param offline_sns_name new sensor name 520 * @param two_frm_exp_info[2] an array which include first frame and seond frame exp info 521 * @return sns_ent_name 522 */ 523 const char* 524 rk_aiq_uapi2_sysctl_rawReproc_preInit(const char* isp_driver, 525 const char* offline_sns_name, 526 rk_aiq_frame_info_t two_frm_exp_info[2]); 527 /** 528 * @brief set user delay counts of params related to stats 529 * 530 * \param[in] sys_ctx the context returned by \ref rk_aiq_uapi2_sysctl_init 531 * \param[in] delay_cnts params calculated from stats n will be applyed to frame n+delay_cnts. 532 * Can set INT8_MAX to restore the old delay counts. 533 */ 534 535 void rk_aiq_uapi2_sysctl_setIspParamsDelayCnts(const rk_aiq_sys_ctx_t* sys_ctx, int8_t delay_cnts); 536 537 /** 538 * @brief set different format form sensor output. 539 * 540 * \param[in] sys_ctx the context returned by \ref rk_aiq_uapi2_sysctl_init 541 * \param[in] width input raw width. 542 * \param[in] height input raw height. 543 * \param[in] code input raw v4l2 format code. 544 */ 545 void rk_aiq_uapi2_sysctl_setUserSensorFormat(rk_aiq_sys_ctx_t* sys_ctx, uint16_t width, uint16_t height, 546 uint16_t code); 547 RKAIQ_END_DECLARE 548 549 #endif 550