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_API_SYSCTL_H 19 #define RK_AIQ_USER_API_SYSCTL_H 20 21 #include "rk_aiq.h" 22 #include "rk_aiq_algo_des.h" 23 24 RKAIQ_BEGIN_DECLARE 25 26 typedef struct rk_aiq_sys_ctx_s rk_aiq_sys_ctx_t; 27 28 /*! 29 * \brief pre-settings before init 30 * 31 * \param[in] sns_ent_name active sensor media entity name. This represents the unique camera module 32 * in system. And the whole active pipeline could be retrieved by this. 33 * \param[in] mode pipleline working mode, just used by \ref 34 * rk_aiq_uapi_sysctl_init to select iq file 35 * according to hdr mode. Unused if params \ref 36 * iq_file is specified. 37 * \param[in] iq_file optional, forcely used this iq file 38 * \note Optional API, should be called before\ref rk_aiq_uapi_sysctl_init. This 39 * API extends the functionality of \ref rk_aiq_uapi_sysctl_init. And just 40 * used to help select the satisfied iq file when multiple iq files 41 * exsist. 42 */ 43 XCamReturn 44 rk_aiq_uapi_sysctl_preInit(const char* sns_ent_name, 45 rk_aiq_working_mode_t mode, 46 const char* force_iq_file); 47 48 49 /** 50 * @brief set calibDB for init scene before init 51 * 52 * @param sns_ent_name sensor name 53 * @param main_scene main scene name 54 * @param sub_scene sub scenen name 55 * 56 * @return 0 if no error 57 */ 58 XCamReturn 59 rk_aiq_uapi_sysctl_preInit_scene(const char* sns_ent_name, const char *main_scene, 60 const char *sub_scene); 61 /** 62 * @brief set thunder boot info to aiq 63 * 64 * @param sns_ent_name sensor name 65 * @param is_pre_aiq is pre-customer aiq 66 * 67 * @return 0 if no error 68 */ 69 XCamReturn 70 rk_aiq_uapi_sysctl_preInit_tb_info(const char* sns_ent_name, 71 const rk_aiq_tb_info_t* info); 72 73 /*! 74 * \brief initialze aiq control system context 75 * Should call before any other APIs 76 * 77 * \param[in] sns_ent_name active sensor media entity name. This represents the unique camera module\n 78 * in system. And the whole active pipeline could be retrieved by this. 79 * \param[in] iq_file_dir define the search directory of the iq files. 80 * \param[in] err_cb not mandatory. it's used to return system errors to user. 81 * \param[in] metas_cb not mandatory. it's used to return the metas(sensor exposure settings,\n 82 * isp settings, etc.) for each frame 83 * \return return system context if success, or NULL if failure. 84 */ 85 rk_aiq_sys_ctx_t* 86 rk_aiq_uapi_sysctl_init(const char* sns_ent_name, 87 const char* iq_file_dir, 88 rk_aiq_error_cb err_cb, 89 rk_aiq_metas_cb metas_cb); 90 91 /*! 92 * \brief deinitialze aiq context 93 * Should not be called in started state 94 * 95 * \param[in] ctx the context returned by \ref rk_aiq_uapi_sysctl_init 96 */ 97 void 98 rk_aiq_uapi_sysctl_deinit( rk_aiq_sys_ctx_t* ctx); 99 100 /*! 101 * \brief prepare aiq control system before runninig 102 * prepare AIQ running enviroment, should be called before \ref rk_aiq_uapi_sysctl_start.\n 103 * And if re-prepared is required after \ref rk_aiq_uapi_sysctl_start is called,\n 104 * should call \ref rk_aiq_uapi_sysctl_stop firstly. 105 * 106 * \param[in] ctx the context returned by \ref rk_aiq_uapi_sysctl_init 107 * \param[in] width sensor active output width, just used to check internally 108 * \param[in] height sensor active output height, just used to check internally 109 * \param[in] mode pipleline working mode 110 * \return return 0 if success 111 */ 112 XCamReturn 113 rk_aiq_uapi_sysctl_prepare(const rk_aiq_sys_ctx_t* ctx, 114 uint32_t width, uint32_t height, 115 rk_aiq_working_mode_t mode); 116 117 /*! 118 * \brief start aiq control system 119 * should be called after \ref rk_aiq_uapi_sysctl_prepare. After this call, 120 * the aiq system repeats getting 3A statistics from ISP driver, running 121 * aiq algorimths(AE, AWB, AF, etc.), setting new parameters to drivers. 122 * 123 * \param[in] ctx the context returned by \ref rk_aiq_uapi_sysctl_init 124 * \return return 0 if success 125 */ 126 XCamReturn 127 rk_aiq_uapi_sysctl_start(const rk_aiq_sys_ctx_t* ctx); 128 129 /*! 130 * \brief stop aiq control system 131 * 132 * \param[in] ctx the context returned by \ref rk_aiq_uapi_sysctl_init 133 * \param[in] keep_ext_hw_st do not change external devices status, like ircut/cpsl 134 * \return return 0 if success 135 */ 136 XCamReturn 137 rk_aiq_uapi_sysctl_stop(const rk_aiq_sys_ctx_t* ctx, bool keep_ext_hw_st); 138 139 XCamReturn 140 rk_aiq_uapi_sysctl_getStaticMetas(const char* sns_ent_name, rk_aiq_static_info_t* static_info); 141 142 /*! 143 * \brief enum static camera infos 144 * 145 * \param[in] index which camera info will be enum 146 * \param[out] static_info returned camera infos 147 * \return return 0 if success 148 */ 149 XCamReturn 150 rk_aiq_uapi_sysctl_enumStaticMetas(int index, rk_aiq_static_info_t* static_info); 151 152 /*! 153 * \brief get sensor entity name from video node 154 * \param[in] vd pp stream video node full path 155 * \return return the binded sensor name 156 */ 157 const char* 158 rk_aiq_uapi_sysctl_getBindedSnsEntNmByVd(const char* vd); 159 160 XCamReturn 161 rk_aiq_uapi_sysctl_getMetaData(const rk_aiq_sys_ctx_t* ctx, uint32_t frame_id, rk_aiq_metas_t* metas); 162 163 #if 0 164 int32_t 165 rk_aiq_uapi_sysctl_getState(const rk_aiq_sys_ctx_t* ctx); 166 #endif 167 168 XCamReturn 169 rk_aiq_uapi_sysctl_setModuleCtl(const rk_aiq_sys_ctx_t* ctx, rk_aiq_module_id_t mId, bool mod_en); 170 171 int32_t 172 rk_aiq_uapi_sysctl_getModuleCtl(const rk_aiq_sys_ctx_t* ctx, rk_aiq_module_id_t mId, bool *mod_en); 173 174 /*! 175 * \brief register customized algo lib 176 * 177 * \param[in] ctx context 178 * \param[in,out] algo_lib_des allocate a new unique id value for algo_lib_des->id if success.\n 179 * this id could be used in \ref rk_aiq_uapi_sysctl_unRegLib 180 * or other lib APIs. The deference object by 181 * \ref algo_lib_des should be valid until \ref rk_aiq_uapi_sysctl_unRegLib 182 * \return return 0 if success 183 */ 184 XCamReturn 185 rk_aiq_uapi_sysctl_regLib(const rk_aiq_sys_ctx_t* ctx, 186 RkAiqAlgoDesComm* algo_lib_des); 187 188 /*! 189 * \brief unregister customized algo lib 190 * 191 * \param[in] ctx context 192 * \param[in] algo_type algo type defined by RkAiqAlgoDesComm.type 193 * \param[in] lib_id returned by call \ref rk_aiq_uapi_sysctl_regLib 194 * \return return 0 if success 195 */ 196 XCamReturn 197 rk_aiq_uapi_sysctl_unRegLib(const rk_aiq_sys_ctx_t* ctx, 198 const int algo_type, 199 const int lib_id); 200 201 /*! 202 * \brief enable or disable algo lib 203 * If the \ref lib_id is the same as the current running algo, this interface 204 * could be called in any state except for the context uninitialized. Otherwise, 205 * it could only be called in prepared or initialized state followed by 206 * call \ref rk_aiq_uapi_sysctl_prepare , and in this case, the old algo which type 207 * is \ref algo_type will be replaced by the new algo \ref lib_id. 208 * 209 * \param[in] ctx context 210 * \param[in] algo_type algo type defined by RkAiqAlgoDesComm.type 211 * \param[in] lib_id 0 for system integrated algos;\n 212 * returned by call \ref rk_aiq_uapi_sysctl_regLib for customer algos 213 * \param[in] enable enable or disable algos. enable means running the algo's processes\n 214 * defined in \ref RkAiqAlgoDesComm; disable means\n 215 * bypass the algo's prcosses. 216 * \return return 0 if success 217 */ 218 XCamReturn 219 rk_aiq_uapi_sysctl_enableAxlib(const rk_aiq_sys_ctx_t* ctx, 220 const int algo_type, 221 const int lib_id, 222 bool enable); 223 224 /*! 225 * \brief get algo lib enabled status 226 * 227 * \param[in] ctx context 228 * \param[in] algo_type algo type defined by RkAiqAlgoDesComm.type 229 * \param[in] lib_id 0 for system integrated algos;\n 230 * returned by call \ref rk_aiq_uapi_sysctl_regLib for customer algos 231 * \return return true if enabled , false if disabled or unregistered 232 */ 233 bool 234 rk_aiq_uapi_sysctl_getAxlibStatus(const rk_aiq_sys_ctx_t* ctx, 235 const int algo_type, 236 const int lib_id); 237 238 /*! 239 * \brief get enabled algo lib context 240 * The returned algo context will be used as the first param of algo private APIs. 241 * For those customer's algo lib, this interface should be called after 242 * \ref rk_aiq_uapi_sysctl_enableAxlib, or will return NULL. 243 * 244 * \param[in] ctx context 245 * \param[in] algo_type algo type defined by RkAiqAlgoDesComm.type 246 * \return return NULL if failed 247 */ 248 RkAiqAlgoContext* 249 rk_aiq_uapi_sysctl_getEnabledAxlibCtx(const rk_aiq_sys_ctx_t* ctx, const int algo_type); 250 251 /*! 252 * \brief get algo lib context 253 * The returned algo context will be used as the first param of algo private APIs. 254 * For those customer's algo lib, this interface should be called after 255 * \ref rk_aiq_uapi_sysctl_regLib, or will return NULL. 256 * 257 * \param[in] ctx context 258 * \param[in] algo_type algo type defined by RkAiqAlgoDesComm.type 259 * \param[in] lib_id 0 for system integrated algos;\n 260 * returned by call \ref rk_aiq_uapi_sysctl_regLib for customer algos 261 * \return return NULL if failed 262 */ 263 RkAiqAlgoContext* 264 rk_aiq_uapi_sysctl_getAxlibCtx(const rk_aiq_sys_ctx_t* ctx, const int algo_type, const int lib_id); 265 266 /*! 267 * \brief get 3a stats 268 * 269 * \param[in] ctx context 270 * \param[out] stats stats params 271 * \return return 0 if success 272 * \note non-blocked interface, and copy the result to stats. 273 */ 274 XCamReturn 275 rk_aiq_uapi_sysctl_get3AStats(const rk_aiq_sys_ctx_t* ctx, 276 rk_aiq_isp_stats_t *stats); 277 278 /*! 279 * \brief get 3a stats 280 * 281 * \param[in] ctx context 282 * \param[out] stats stats params ref 283 * \param[in] timeout_ms -1 means wait always until stats is available or 284 * stopped 285 * \return return 0 if success 286 * \note blocked interface, and return the stats ref, user should 287 * call \ref rk_aiq_uapi_sysctl_release3AStatsRef to release. 288 */ 289 XCamReturn 290 rk_aiq_uapi_sysctl_get3AStatsBlk(const rk_aiq_sys_ctx_t* ctx, 291 rk_aiq_isp_stats_t **stats, int timeout_ms); 292 293 /*! 294 * \brief release 3a stats result ref 295 * 296 * \param[in] ctx context 297 * \param[out] stats stats ref 298 * \return void 299 * \note called with \ref rk_aiq_uapi_sysctl_get3AStatsBlk 300 */ 301 void 302 rk_aiq_uapi_sysctl_release3AStatsRef(const rk_aiq_sys_ctx_t* ctx, 303 rk_aiq_isp_stats_t *stats); 304 /*! 305 * \brief set compensation light config 306 * 307 * \param[in] ctx context 308 * \param[out] cfg cpsl configs 309 * \return return 0 if success 310 */ 311 XCamReturn 312 rk_aiq_uapi_sysctl_setCpsLtCfg(const rk_aiq_sys_ctx_t* ctx, 313 rk_aiq_cpsl_cfg_t* cfg); 314 /*! 315 * \brief get compensation light info 316 * 317 * \param[in] ctx context 318 * \param[out] info current cpsl settings 319 * \return return 0 if success 320 */ 321 XCamReturn 322 rk_aiq_uapi_sysctl_getCpsLtInfo(const rk_aiq_sys_ctx_t* ctx, 323 rk_aiq_cpsl_info_t* info); 324 /*! 325 * \brief query compensation light capability 326 * 327 * \param[in] ctx context 328 * \param[out] cap cpsl cap info 329 * \return return 0 if success 330 */ 331 XCamReturn 332 rk_aiq_uapi_sysctl_queryCpsLtCap(const rk_aiq_sys_ctx_t* ctx, 333 rk_aiq_cpsl_cap_t* cap); 334 335 /*! 336 * \brief prepare RK-raw-format data process environment 337 * 338 * \param[in] ctx context 339 * \param[in] prop prepare params 340 * \return return 0 if success 341 */ 342 XCamReturn 343 rk_aiq_uapi_sysctl_prepareRkRaw(const rk_aiq_sys_ctx_t* ctx, rk_aiq_raw_prop_t prop); 344 345 /*! 346 * \brief queue RK-Raw-format buffer into aiq control system 347 * 348 * \param[in] ctx context 349 * \param[in] rawdata RK-Raw-format buffer 350 * \param[in] sync sync flag, true means sync mode,calling process will be blocked, 351 * until the queued frame is processed. false means async mode, calling 352 * process is not blocked, if you want to free rawdata or reuse it, callback 353 * should be registered,after frame is processed, callback function would be called. 354 * \return return 0 if success 355 */ 356 XCamReturn 357 rk_aiq_uapi_sysctl_enqueueRkRawBuf(const rk_aiq_sys_ctx_t* ctx, void *rawdata, bool sync); 358 359 /*! 360 * \brief queue RK-Raw-format file into aiq control system 361 * 362 * \param[in] ctx context 363 * \param[in] path RK-Raw-format file path 364 * calling process will be blocked until the queued frame is processed 365 * \return return 0 if success 366 */ 367 XCamReturn 368 rk_aiq_uapi_sysctl_enqueueRkRawFile(const rk_aiq_sys_ctx_t* ctx, const char *path); 369 370 /*! 371 * \brief regist RK-Raw-format buffer callback into aiq control system 372 * 373 * \param[in] ctx context 374 * \param[in] callback callback function pointer 375 * if callback function is registered, (when rk_aiq_uapi_sysctl_enqueueRkRawBuf used in sync mode) 376 * callback will be called in sync after the queued raw buffer is processed, raw buffer pointer 377 * which passed into aiq by rk_aiq_uapi_sysctl_enqueueRkRawBuf would be passed back into the callback 378 * function you registered. 379 * this function is not required. 380 * 381 * \return return 0 if success 382 */ 383 XCamReturn 384 rk_aiq_uapi_sysctl_registRkRawCb(const rk_aiq_sys_ctx_t* ctx, void (*callback)(void*)); 385 386 /*! 387 * \brief set the bypass stream rotation 388 * 389 * \param[in] ctx context 390 * \param[in] rot rotation val 391 * \return return 0 if success 392 */ 393 XCamReturn 394 rk_aiq_uapi_sysctl_setSharpFbcRotation(const rk_aiq_sys_ctx_t* ctx, rk_aiq_rotation_t rot); 395 396 /*! 397 * \brief get aiq version infos 398 * 399 * \param[in,out] vers version infos 400 * \return return 0 if success 401 */ 402 void rk_aiq_uapi_get_version_info(rk_aiq_ver_info_t* vers); 403 404 /*! 405 * \brief switch working mode dynamically 406 * this aims to switch the isp pipeline working mode fast, and can be called on 407 * streaming status. On non streaming status, should call rk_aiq_uapi_sysctl_prepare 408 * instead of this to set working mode. 409 */ 410 XCamReturn 411 rk_aiq_uapi_sysctl_swWorkingModeDyn(const rk_aiq_sys_ctx_t* ctx, rk_aiq_working_mode_t mode); 412 413 /*! 414 * \brief set multiple cameras working concurrently 415 * Notify this AIQ ctx will run with other sensor's AIQ ctx. 416 417 * \param[in] cc set cams concurrently used or not 418 * \note should be called before rk_aiq_uapi_sysctl_start 419 */ 420 void 421 rk_aiq_uapi_sysctl_setMulCamConc(const rk_aiq_sys_ctx_t* ctx, bool cc); 422 423 /*! 424 * \brief set crop window of isp input 425 * This API will affect the isp pipeline resolution. 426 * 427 * \param[in] rect set cams crop prop 428 * \note Optinal API, should be called before rk_aiq_uapi_sysctl_prepare 429 */ 430 XCamReturn 431 rk_aiq_uapi_sysctl_setCrop(const rk_aiq_sys_ctx_t* sys_ctx, rk_aiq_rect_t rect); 432 433 /*! 434 * \brief get crop window of isp input 435 * 436 * \param[in] rect get cams crop prop 437 */ 438 XCamReturn 439 rk_aiq_uapi_sysctl_getCrop(const rk_aiq_sys_ctx_t* sys_ctx, rk_aiq_rect_t *rect); 440 441 /*! 442 * \brief apply an new iq file when stream on 443 * 444 * \param[in] iqfile iqfile which will be applied 445 */ 446 XCamReturn 447 rk_aiq_uapi_sysctl_updateIq(rk_aiq_sys_ctx_t* sys_ctx, char* iqfile); 448 449 XCamReturn 450 rk_aiq_uapi_sysctl_tuning(const rk_aiq_sys_ctx_t* sys_ctx, char* param); 451 452 char* rk_aiq_uapi_sysctl_readiq(const rk_aiq_sys_ctx_t* sys_ctx, char* param); 453 454 /*! 455 * \brief register mems sensor handler interface 456 * 457 * \param[in] intf mems sensor interfaces 458 */ 459 XCamReturn 460 rk_aiq_uapi_sysctl_regMemsSensorIntf(const rk_aiq_sys_ctx_t* sys_ctx, 461 const rk_aiq_mems_sensor_intf_t* intf); 462 463 464 /** 465 * @brief switch calibDB for different scene 466 * 467 * @param sys_ctx 468 * @param main_scene main scene name 469 * @param sub_scene sub scenen name 470 * 471 * @return 0 if no error 472 */ 473 int rk_aiq_uapi_sysctl_switch_scene(const rk_aiq_sys_ctx_t* sys_ctx, 474 const char* main_scene, 475 const char* sub_scene); 476 477 /** 478 * @brief turn on/off socket server 479 * 480 * @param sys_ctx 481 * @param enable 482 * 483 * @return 0 if no error 484 */ 485 int rk_aiq_uapi_sysctl_tuning_enable(rk_aiq_sys_ctx_t* sys_ctx, bool enable); 486 487 RKAIQ_END_DECLARE 488 489 #endif 490