1 /* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are 5 * met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer in the documentation and/or other materials provided 11 * with the distribution. 12 * * Neither the name of The Linux Foundation nor the names of its 13 * contributors may be used to endorse or promote products derived 14 * from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 */ 29 30 #ifndef __MM_CAMERA_H__ 31 #define __MM_CAMERA_H__ 32 33 // System dependencies 34 #include <poll.h> 35 36 // Camera dependencies 37 #include "camera_common.h" 38 #include "cam_semaphore.h" 39 #include "mm_camera_interface.h" 40 41 /********************************************************************************** 42 * Data structure declarations 43 ***********************************************************************************/ 44 /* num of callbacks allowed for an event type */ 45 #define MM_CAMERA_EVT_ENTRY_MAX 4 46 /* num of data callbacks allowed in a stream obj */ 47 #define MM_CAMERA_STREAM_BUF_CB_MAX 4 48 /* num of data poll threads allowed in a channel obj */ 49 #define MM_CAMERA_CHANNEL_POLL_THREAD_MAX 1 50 51 #define MM_CAMERA_DEV_NAME_LEN 32 52 #define MM_CAMERA_DEV_OPEN_TRIES 20 53 #define MM_CAMERA_DEV_OPEN_RETRY_SLEEP 20 54 #define THREAD_NAME_SIZE 15 55 56 /* Future frame idx, large enough to make sure capture 57 * settings can be applied and small enough to still capture an image */ 58 #define MM_CAMERA_MAX_FUTURE_FRAME_WAIT 100 59 #define WAIT_TIMEOUT 5 60 61 #ifndef TRUE 62 #define TRUE 1 63 #endif 64 65 #ifndef FALSE 66 #define FALSE 0 67 #endif 68 69 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) 70 71 struct mm_channel; 72 struct mm_stream; 73 struct mm_camera_obj; 74 75 typedef int64_t nsecs_t; 76 77 typedef enum 78 { 79 MM_CAMERA_CMD_TYPE_DATA_CB, /* dataB CMD */ 80 MM_CAMERA_CMD_TYPE_EVT_CB, /* evtCB CMD */ 81 MM_CAMERA_CMD_TYPE_EXIT, /* EXIT */ 82 MM_CAMERA_CMD_TYPE_REQ_DATA_CB,/* request data */ 83 MM_CAMERA_CMD_TYPE_SUPER_BUF_DATA_CB, /* superbuf dataB CMD */ 84 MM_CAMERA_CMD_TYPE_CONFIG_NOTIFY, /* configure notify mode */ 85 MM_CAMERA_CMD_TYPE_START_ZSL, /* start zsl snapshot for channel */ 86 MM_CAMERA_CMD_TYPE_STOP_ZSL, /* stop zsl snapshot for channel */ 87 MM_CAMERA_CMD_TYPE_FLUSH_QUEUE, /* flush queue */ 88 MM_CAMERA_CMD_TYPE_GENERAL, /* general cmd */ 89 MM_CAMERA_CMD_TYPE_MAX 90 } mm_camera_cmdcb_type_t; 91 92 typedef struct { 93 uint32_t stream_id; 94 uint32_t frame_idx; 95 uint32_t flags; 96 mm_camera_buf_def_t *buf; /* ref to buf */ 97 } mm_camera_buf_info_t; 98 99 typedef enum { 100 MM_CAMERA_GENERIC_CMD_TYPE_AE_BRACKETING, 101 MM_CAMERA_GENERIC_CMD_TYPE_AF_BRACKETING, 102 MM_CAMERA_GENERIC_CMD_TYPE_FLASH_BRACKETING, 103 MM_CAMERA_GENERIC_CMD_TYPE_ZOOM_1X, 104 MM_CAMERA_GENERIC_CMD_TYPE_CAPTURE_SETTING, 105 } mm_camera_generic_cmd_type_t; 106 107 typedef struct { 108 mm_camera_generic_cmd_type_t type; 109 uint32_t payload[32]; 110 union { 111 cam_capture_frame_config_t frame_config; 112 }; 113 } mm_camera_generic_cmd_t; 114 115 typedef struct { 116 uint32_t frame_idx; 117 cam_stream_type_t stream_type; 118 } mm_camera_flush_cmd_t; 119 120 typedef struct { 121 mm_camera_cmdcb_type_t cmd_type; 122 union { 123 mm_camera_buf_info_t buf; /* frame buf if dataCB */ 124 mm_camera_event_t evt; /* evt if evtCB */ 125 mm_camera_super_buf_t superbuf; /* superbuf if superbuf dataCB*/ 126 mm_camera_req_buf_t req_buf; /* num of buf requested */ 127 mm_camera_flush_cmd_t flush_cmd; /* frame idx boundary for flush superbuf queue*/ 128 mm_camera_super_buf_notify_mode_t notify_mode; /* notification mode */ 129 mm_camera_generic_cmd_t gen_cmd; 130 } u; 131 } mm_camera_cmdcb_t; 132 133 typedef void (*mm_camera_cmd_cb_t)(mm_camera_cmdcb_t * cmd_cb, void* user_data); 134 135 typedef struct { 136 uint8_t is_active; /*indicates whether thread is active or not */ 137 cam_queue_t cmd_queue; /* cmd queue (queuing dataCB, asyncCB, or exitCMD) */ 138 pthread_t cmd_pid; /* cmd thread ID */ 139 cam_semaphore_t cmd_sem; /* semaphore for cmd thread */ 140 cam_semaphore_t sync_sem; /* semaphore for synchronization with cmd thread */ 141 mm_camera_cmd_cb_t cb; /* cb for cmd */ 142 void* user_data; /* user_data for cb */ 143 char threadName[THREAD_NAME_SIZE]; 144 } mm_camera_cmd_thread_t; 145 146 typedef enum { 147 MM_CAMERA_POLL_TYPE_EVT, 148 MM_CAMERA_POLL_TYPE_DATA, 149 MM_CAMERA_POLL_TYPE_MAX 150 } mm_camera_poll_thread_type_t; 151 152 /* function ptr defined for poll notify CB, 153 * registered at poll thread with poll fd */ 154 typedef void (*mm_camera_poll_notify_t)(void *user_data); 155 156 typedef struct { 157 int32_t fd; 158 mm_camera_poll_notify_t notify_cb; 159 uint32_t handler; 160 void* user_data; 161 } mm_camera_poll_entry_t; 162 163 typedef struct { 164 mm_camera_poll_thread_type_t poll_type; 165 /* array to store poll fd and cb info 166 * for MM_CAMERA_POLL_TYPE_EVT, only index 0 is valid; 167 * for MM_CAMERA_POLL_TYPE_DATA, depends on valid stream fd */ 168 mm_camera_poll_entry_t poll_entries[MAX_STREAM_NUM_IN_BUNDLE]; 169 int32_t pfds[2]; 170 pthread_t pid; 171 int32_t state; 172 int timeoutms; 173 uint32_t cmd; 174 struct pollfd poll_fds[MAX_STREAM_NUM_IN_BUNDLE + 1]; 175 uint8_t num_fds; 176 pthread_mutex_t mutex; 177 pthread_cond_t cond_v; 178 int32_t status; 179 char threadName[THREAD_NAME_SIZE]; 180 //void *my_obj; 181 } mm_camera_poll_thread_t; 182 183 /* mm_stream */ 184 typedef enum { 185 MM_STREAM_STATE_NOTUSED = 0, /* not used */ 186 MM_STREAM_STATE_INITED, /* inited */ 187 MM_STREAM_STATE_ACQUIRED, /* acquired, fd opened */ 188 MM_STREAM_STATE_CFG, /* fmt & dim configured */ 189 MM_STREAM_STATE_BUFFED, /* buf allocated */ 190 MM_STREAM_STATE_REG, /* buf regged, stream off */ 191 MM_STREAM_STATE_ACTIVE, /* active */ 192 MM_STREAM_STATE_MAX 193 } mm_stream_state_type_t; 194 195 typedef enum { 196 MM_STREAM_EVT_ACQUIRE, 197 MM_STREAM_EVT_RELEASE, 198 MM_STREAM_EVT_SET_FMT, 199 MM_STREAM_EVT_GET_BUF, 200 MM_STREAM_EVT_PUT_BUF, 201 MM_STREAM_EVT_REG_BUF, 202 MM_STREAM_EVT_UNREG_BUF, 203 MM_STREAM_EVT_START, 204 MM_STREAM_EVT_STOP, 205 MM_STREAM_EVT_QBUF, 206 MM_STREAM_EVT_SET_PARM, 207 MM_STREAM_EVT_GET_PARM, 208 MM_STREAM_EVT_DO_ACTION, 209 MM_STREAM_EVT_GET_QUEUED_BUF_COUNT, 210 MM_STREAM_EVT_MAX 211 } mm_stream_evt_type_t; 212 213 typedef struct { 214 mm_camera_buf_notify_t cb; 215 void *user_data; 216 /* cb_count = -1: infinite 217 * cb_count > 0: register only for required times */ 218 int8_t cb_count; 219 mm_camera_stream_cb_type cb_type; 220 } mm_stream_data_cb_t; 221 222 typedef struct { 223 /* buf reference count */ 224 uint8_t buf_refcnt; 225 226 /* This flag is to indicate if after allocation, 227 * the corresponding buf needs to qbuf into kernel 228 * (e.g. for preview usecase, display needs to hold two bufs, 229 * so no need to qbuf these two bufs initially) */ 230 uint8_t initial_reg_flag; 231 232 /* indicate if buf is in kernel(1) or client(0) */ 233 uint8_t in_kernel; 234 /*indicate if this buffer is mapped to daemon*/ 235 int8_t map_status; 236 } mm_stream_buf_status_t; 237 238 typedef struct mm_stream { 239 uint32_t my_hdl; /* local stream id */ 240 uint32_t server_stream_id; /* stream id from server */ 241 int32_t fd; 242 mm_stream_state_type_t state; 243 244 /* stream info*/ 245 cam_stream_info_t *stream_info; 246 247 /* padding info */ 248 cam_padding_info_t padding_info; 249 250 /* offset */ 251 cam_frame_len_offset_t frame_offset; 252 253 pthread_mutex_t cmd_lock; /* lock to protect cmd_thread */ 254 mm_camera_cmd_thread_t cmd_thread; 255 256 /* dataCB registered on this stream obj */ 257 pthread_mutex_t cb_lock; /* cb lock to protect buf_cb */ 258 mm_stream_data_cb_t buf_cb[MM_CAMERA_STREAM_BUF_CB_MAX]; 259 260 /* stream buffer management */ 261 pthread_mutex_t buf_lock; 262 uint8_t buf_num; /* num of buffers allocated */ 263 mm_camera_buf_def_t* buf; /* ptr to buf array */ 264 mm_stream_buf_status_t buf_status[CAM_MAX_NUM_BUFS_PER_STREAM]; /* ptr to buf status array */ 265 266 uint8_t plane_buf_num; /* num of plane buffers allocated Used only in Batch mode*/ 267 mm_camera_buf_def_t *plane_buf; /*Pointer to plane buffer array Used only in Batch mode */ 268 int32_t cur_buf_idx; /* Current container buffer active filling. Used only in Batch mode*/ 269 uint8_t cur_bufs_staged; /*Number of plane buf freed by HAL for this usr buf*/ 270 271 272 /* reference to parent channel_obj */ 273 struct mm_channel* ch_obj; 274 275 uint8_t is_bundled; /* flag if stream is bundled */ 276 277 /* reference to linked channel_obj */ 278 struct mm_channel* linked_obj; 279 struct mm_stream * linked_stream; /* original stream */ 280 uint8_t is_linked; /* flag if stream is linked */ 281 282 mm_camera_stream_mem_vtbl_t mem_vtbl; /* mem ops tbl */ 283 284 mm_camera_map_unmap_ops_tbl_t map_ops; 285 286 int8_t queued_buffer_count; 287 288 /*latest timestamp of this stream frame received & last frameID*/ 289 uint32_t prev_frameID; 290 nsecs_t prev_timestamp; 291 292 /* Need to wait for buffer mapping before stream-on*/ 293 pthread_cond_t buf_cond; 294 } mm_stream_t; 295 296 /* mm_channel */ 297 typedef enum { 298 MM_CHANNEL_STATE_NOTUSED = 0, /* not used */ 299 MM_CHANNEL_STATE_STOPPED, /* stopped */ 300 MM_CHANNEL_STATE_ACTIVE, /* active, at least one stream active */ 301 MM_CHANNEL_STATE_PAUSED, /* paused */ 302 MM_CHANNEL_STATE_MAX 303 } mm_channel_state_type_t; 304 305 typedef enum { 306 MM_CHANNEL_EVT_ADD_STREAM, 307 MM_CHANNEL_EVT_DEL_STREAM, 308 MM_CHANNEL_EVT_LINK_STREAM, 309 MM_CHANNEL_EVT_CONFIG_STREAM, 310 MM_CHANNEL_EVT_GET_BUNDLE_INFO, 311 MM_CHANNEL_EVT_START, 312 MM_CHANNEL_EVT_STOP, 313 MM_CHANNEL_EVT_PAUSE, 314 MM_CHANNEL_EVT_RESUME, 315 MM_CHANNEL_EVT_REQUEST_SUPER_BUF, 316 MM_CHANNEL_EVT_CANCEL_REQUEST_SUPER_BUF, 317 MM_CHANNEL_EVT_FLUSH_SUPER_BUF_QUEUE, 318 MM_CHANNEL_EVT_CONFIG_NOTIFY_MODE, 319 MM_CHANNEL_EVT_START_ZSL_SNAPSHOT, 320 MM_CHANNEL_EVT_STOP_ZSL_SNAPSHOT, 321 MM_CHANNEL_EVT_MAP_STREAM_BUF, 322 MM_CHANNEL_EVT_UNMAP_STREAM_BUF, 323 MM_CHANNEL_EVT_SET_STREAM_PARM, 324 MM_CHANNEL_EVT_GET_STREAM_PARM, 325 MM_CHANNEL_EVT_DO_STREAM_ACTION, 326 MM_CHANNEL_EVT_DELETE, 327 MM_CHANNEL_EVT_AF_BRACKETING, 328 MM_CHANNEL_EVT_AE_BRACKETING, 329 MM_CHANNEL_EVT_FLASH_BRACKETING, 330 MM_CHANNEL_EVT_ZOOM_1X, 331 MM_CAMERA_EVT_CAPTURE_SETTING, 332 MM_CHANNEL_EVT_GET_STREAM_QUEUED_BUF_COUNT, 333 MM_CHANNEL_EVT_MAP_STREAM_BUFS, 334 MM_CHANNEL_EVT_REG_STREAM_BUF_CB 335 } mm_channel_evt_type_t; 336 337 typedef struct { 338 uint32_t stream_id; 339 mm_camera_stream_config_t *config; 340 } mm_evt_paylod_config_stream_t; 341 342 typedef struct { 343 uint32_t stream_id; 344 cam_stream_parm_buffer_t *parms; 345 } mm_evt_paylod_set_get_stream_parms_t; 346 347 typedef struct { 348 uint32_t stream_id; 349 void *actions; 350 } mm_evt_paylod_do_stream_action_t; 351 352 typedef struct { 353 uint32_t stream_id; 354 mm_stream_data_cb_t buf_cb; 355 } mm_evt_paylod_reg_stream_buf_cb; 356 357 358 typedef struct { 359 uint8_t num_of_bufs; 360 mm_camera_buf_info_t super_buf[MAX_STREAM_NUM_IN_BUNDLE]; 361 uint8_t matched; 362 uint8_t expected; 363 uint32_t frame_idx; 364 } mm_channel_queue_node_t; 365 366 typedef struct { 367 cam_queue_t que; 368 uint8_t num_streams; 369 /* container for bundled stream handlers */ 370 uint32_t bundled_streams[MAX_STREAM_NUM_IN_BUNDLE]; 371 mm_camera_channel_attr_t attr; 372 uint32_t expected_frame_id; 373 uint32_t match_cnt; 374 uint32_t expected_frame_id_without_led; 375 uint32_t led_on_start_frame_id; 376 uint32_t led_off_start_frame_id; 377 uint32_t led_on_num_frames; 378 uint32_t once; 379 uint32_t frame_skip_count; 380 } mm_channel_queue_t; 381 382 typedef struct { 383 uint8_t is_active; /* flag to indicate if bundle is valid */ 384 /* queue to store bundled super buffers */ 385 mm_channel_queue_t superbuf_queue; 386 mm_camera_buf_notify_t super_buf_notify_cb; 387 void *user_data; 388 } mm_channel_bundle_t; 389 390 /* Nodes used for frame sync */ 391 typedef struct { 392 /* Frame idx */ 393 uint32_t frame_idx; 394 /* Frame present for corresponding channel*/ 395 uint32_t frame_valid[MAX_NUM_CAMERA_PER_BUNDLE]; 396 /* Frame present in all channels*/ 397 uint32_t matched; 398 } mm_channel_sync_node_t; 399 400 /* Frame sync information */ 401 typedef struct { 402 /* Number of camera channels that need to be synced*/ 403 uint8_t num_cam; 404 /* position of the next node to be updated */ 405 uint8_t pos; 406 /* circular node array used to store frame information */ 407 mm_channel_sync_node_t node[MM_CAMERA_FRAME_SYNC_NODES]; 408 /* Channel corresponding to each camera */ 409 struct mm_channel *ch_obj[MAX_NUM_CAMERA_PER_BUNDLE]; 410 /* Cb corresponding to each camera */ 411 mm_camera_buf_notify_t cb[MAX_NUM_CAMERA_PER_BUNDLE]; 412 } mm_channel_frame_sync_info_t; 413 414 /* Node information for multiple superbuf callbacks 415 * This can be used to batch nodes before sending to upper layer */ 416 typedef struct { 417 /* Number of nodes to be sent*/ 418 uint8_t num_nodes; 419 /* queue node information*/ 420 mm_channel_queue_node_t *node[MAX_NUM_CAMERA_PER_BUNDLE]; 421 /* channel information*/ 422 struct mm_channel *ch_obj[MAX_NUM_CAMERA_PER_BUNDLE]; 423 } mm_channel_node_info_t; 424 425 typedef enum { 426 MM_CHANNEL_BRACKETING_STATE_OFF, 427 MM_CHANNEL_BRACKETING_STATE_WAIT_GOOD_FRAME_IDX, 428 MM_CHANNEL_BRACKETING_STATE_ACTIVE, 429 } mm_channel_bracketing_state_t; 430 431 typedef struct mm_channel { 432 uint32_t my_hdl; 433 mm_channel_state_type_t state; 434 pthread_mutex_t ch_lock; /* channel lock */ 435 436 /* stream bundle info in the channel */ 437 mm_channel_bundle_t bundle; 438 439 /* num of pending suferbuffers */ 440 uint32_t pending_cnt; 441 uint32_t pending_retro_cnt; 442 mm_camera_req_buf_type_t req_type; 443 uint32_t bWaitForPrepSnapshotDone; 444 uint32_t unLockAEC; 445 /* num of pending suferbuffers */ 446 uint8_t stopZslSnapshot; 447 448 /* cmd thread for superbuffer dataCB and async stop*/ 449 mm_camera_cmd_thread_t cmd_thread; 450 451 /* cb thread for sending data cb */ 452 mm_camera_cmd_thread_t cb_thread; 453 454 /* data poll thread 455 * currently one data poll thread per channel 456 * could extended to support one data poll thread per stream in the channel */ 457 mm_camera_poll_thread_t poll_thread[MM_CAMERA_CHANNEL_POLL_THREAD_MAX]; 458 459 /* container for all streams in channel */ 460 mm_stream_t streams[MAX_STREAM_NUM_IN_BUNDLE]; 461 462 /* reference to parent cam_obj */ 463 struct mm_camera_obj* cam_obj; 464 465 /* manual zsl snapshot control */ 466 uint8_t manualZSLSnapshot; 467 468 /* control for zsl led */ 469 uint8_t startZSlSnapshotCalled; 470 uint8_t needLEDFlash; 471 mm_channel_bracketing_state_t bracketingState; 472 uint8_t isFlashBracketingEnabled; 473 uint8_t isZoom1xFrameRequested; 474 uint32_t burstSnapNum; 475 char threadName[THREAD_NAME_SIZE]; 476 477 /*Buffer diverted*/ 478 uint8_t diverted_frame_id; 479 uint32_t sessionid; 480 481 /*Frame capture configaration*/ 482 uint8_t isConfigCapture; 483 uint8_t cur_capture_idx; 484 uint32_t capture_frame_id[MAX_CAPTURE_BATCH_NUM]; 485 cam_capture_frame_config_t frameConfig; 486 uint8_t needLowLightZSL; 487 } mm_channel_t; 488 489 typedef struct { 490 mm_channel_t *ch; 491 uint32_t stream_id; 492 } mm_camera_stream_link_t; 493 494 /* struct to store information about pp cookie*/ 495 typedef struct { 496 uint32_t cam_hdl; 497 uint32_t ch_hdl; 498 uint32_t stream_hdl; 499 mm_channel_queue_node_t* super_buf; 500 } mm_channel_pp_info_t; 501 502 /* mm_camera */ 503 typedef struct { 504 mm_camera_event_notify_t evt_cb; 505 void *user_data; 506 } mm_camera_evt_entry_t; 507 508 typedef struct { 509 mm_camera_evt_entry_t evt[MM_CAMERA_EVT_ENTRY_MAX]; 510 /* reg_count <=0: infinite 511 * reg_count > 0: register only for required times */ 512 int reg_count; 513 } mm_camera_evt_obj_t; 514 515 typedef struct mm_camera_obj { 516 uint32_t my_hdl; 517 int ref_count; 518 int32_t ctrl_fd; 519 int32_t ds_fd; /* domain socket fd */ 520 pthread_mutex_t cam_lock; 521 pthread_mutex_t cb_lock; /* lock for evt cb */ 522 mm_channel_t ch[MM_CAMERA_CHANNEL_MAX]; 523 mm_camera_evt_obj_t evt; 524 mm_camera_poll_thread_t evt_poll_thread; /* evt poll thread */ 525 mm_camera_cmd_thread_t evt_thread; /* thread for evt CB */ 526 mm_camera_vtbl_t vtbl; 527 528 pthread_mutex_t evt_lock; 529 pthread_cond_t evt_cond; 530 mm_camera_event_t evt_rcvd; 531 532 pthread_mutex_t msg_lock; /* lock for sending msg through socket */ 533 uint32_t sessionid; /* Camera server session id */ 534 } mm_camera_obj_t; 535 536 typedef struct { 537 int8_t num_cam; 538 char video_dev_name[MM_CAMERA_MAX_NUM_SENSORS][MM_CAMERA_DEV_NAME_LEN]; 539 mm_camera_obj_t *cam_obj[MM_CAMERA_MAX_NUM_SENSORS]; 540 struct camera_info info[MM_CAMERA_MAX_NUM_SENSORS]; 541 cam_sync_type_t cam_type[MM_CAMERA_MAX_NUM_SENSORS]; 542 cam_sync_mode_t cam_mode[MM_CAMERA_MAX_NUM_SENSORS]; 543 uint8_t is_yuv[MM_CAMERA_MAX_NUM_SENSORS]; // 1=CAM_SENSOR_YUV, 0=CAM_SENSOR_RAW 544 } mm_camera_ctrl_t; 545 546 typedef enum { 547 mm_camera_async_call, 548 mm_camera_sync_call 549 } mm_camera_call_type_t; 550 551 /********************************************************************************** 552 * external function declare 553 ***********************************************************************************/ 554 /* utility functions */ 555 /* set int32_t value */ 556 extern int32_t mm_camera_util_s_ctrl(int32_t fd, 557 uint32_t id, 558 int32_t *value); 559 560 /* get int32_t value */ 561 extern int32_t mm_camera_util_g_ctrl(int32_t fd, 562 uint32_t id, 563 int32_t *value); 564 565 /* send msg throught domain socket for fd mapping */ 566 extern int32_t mm_camera_util_sendmsg(mm_camera_obj_t *my_obj, 567 void *msg, 568 size_t buf_size, 569 int sendfd); 570 571 /* send msg through domain socket for bundled fd mapping */ 572 extern int32_t mm_camera_util_bundled_sendmsg(mm_camera_obj_t *my_obj, 573 void *msg, 574 size_t buf_size, 575 int sendfds[CAM_MAX_NUM_BUFS_PER_STREAM], 576 int numfds); 577 578 /* Check if hardware target is A family */ 579 uint8_t mm_camera_util_chip_is_a_family(void); 580 581 /* mm-camera */ 582 extern int32_t mm_camera_open(mm_camera_obj_t *my_obj); 583 extern int32_t mm_camera_close(mm_camera_obj_t *my_obj); 584 extern int32_t mm_camera_register_event_notify(mm_camera_obj_t *my_obj, 585 mm_camera_event_notify_t evt_cb, 586 void * user_data); 587 extern int32_t mm_camera_qbuf(mm_camera_obj_t *my_obj, 588 uint32_t ch_id, 589 mm_camera_buf_def_t *buf); 590 extern int32_t mm_camera_get_queued_buf_count(mm_camera_obj_t *my_obj, 591 uint32_t ch_id, uint32_t stream_id); 592 extern int32_t mm_camera_query_capability(mm_camera_obj_t *my_obj); 593 extern int32_t mm_camera_set_parms(mm_camera_obj_t *my_obj, 594 parm_buffer_t *parms); 595 extern int32_t mm_camera_get_parms(mm_camera_obj_t *my_obj, 596 parm_buffer_t *parms); 597 extern int32_t mm_camera_map_buf(mm_camera_obj_t *my_obj, 598 uint8_t buf_type, 599 int fd, 600 size_t size); 601 extern int32_t mm_camera_map_bufs(mm_camera_obj_t *my_obj, 602 const cam_buf_map_type_list *buf_map_list); 603 extern int32_t mm_camera_unmap_buf(mm_camera_obj_t *my_obj, 604 uint8_t buf_type); 605 extern int32_t mm_camera_do_auto_focus(mm_camera_obj_t *my_obj); 606 extern int32_t mm_camera_cancel_auto_focus(mm_camera_obj_t *my_obj); 607 extern int32_t mm_camera_prepare_snapshot(mm_camera_obj_t *my_obj, 608 int32_t do_af_flag); 609 extern int32_t mm_camera_start_zsl_snapshot(mm_camera_obj_t *my_obj); 610 extern int32_t mm_camera_stop_zsl_snapshot(mm_camera_obj_t *my_obj); 611 extern int32_t mm_camera_flush(mm_camera_obj_t *my_obj); 612 extern int32_t mm_camera_start_zsl_snapshot_ch(mm_camera_obj_t *my_obj, 613 uint32_t ch_id); 614 extern int32_t mm_camera_stop_zsl_snapshot_ch(mm_camera_obj_t *my_obj, 615 uint32_t ch_id); 616 extern uint32_t mm_camera_add_channel(mm_camera_obj_t *my_obj, 617 mm_camera_channel_attr_t *attr, 618 mm_camera_buf_notify_t channel_cb, 619 void *userdata); 620 extern int32_t mm_camera_del_channel(mm_camera_obj_t *my_obj, 621 uint32_t ch_id); 622 extern int32_t mm_camera_get_bundle_info(mm_camera_obj_t *my_obj, 623 uint32_t ch_id, 624 cam_bundle_config_t *bundle_info); 625 extern uint32_t mm_camera_add_stream(mm_camera_obj_t *my_obj, 626 uint32_t ch_id); 627 extern int32_t mm_camera_del_stream(mm_camera_obj_t *my_obj, 628 uint32_t ch_id, 629 uint32_t stream_id); 630 extern uint32_t mm_camera_link_stream(mm_camera_obj_t *my_obj, 631 uint32_t ch_id, 632 uint32_t stream_id, 633 uint32_t linked_ch_id); 634 635 extern int32_t mm_camera_reg_stream_buf_cb(mm_camera_obj_t *my_obj, 636 uint32_t ch_id, uint32_t stream_id, mm_camera_buf_notify_t buf_cb, 637 mm_camera_stream_cb_type cb_type, void *userdata); 638 639 extern int32_t mm_camera_config_stream(mm_camera_obj_t *my_obj, 640 uint32_t ch_id, 641 uint32_t stream_id, 642 mm_camera_stream_config_t *config); 643 extern int32_t mm_camera_start_channel(mm_camera_obj_t *my_obj, 644 uint32_t ch_id); 645 extern int32_t mm_camera_stop_channel(mm_camera_obj_t *my_obj, 646 uint32_t ch_id); 647 extern int32_t mm_camera_request_super_buf(mm_camera_obj_t *my_obj, 648 uint32_t ch_id, mm_camera_req_buf_t *buf); 649 extern int32_t mm_camera_cancel_super_buf_request(mm_camera_obj_t *my_obj, 650 uint32_t ch_id); 651 extern int32_t mm_camera_flush_super_buf_queue(mm_camera_obj_t *my_obj, 652 uint32_t ch_id, 653 uint32_t frame_idx); 654 extern int32_t mm_camera_config_channel_notify(mm_camera_obj_t *my_obj, 655 uint32_t ch_id, 656 mm_camera_super_buf_notify_mode_t notify_mode); 657 extern int32_t mm_camera_set_stream_parms(mm_camera_obj_t *my_obj, 658 uint32_t ch_id, 659 uint32_t s_id, 660 cam_stream_parm_buffer_t *parms); 661 extern int32_t mm_camera_get_stream_parms(mm_camera_obj_t *my_obj, 662 uint32_t ch_id, 663 uint32_t s_id, 664 cam_stream_parm_buffer_t *parms); 665 extern int32_t mm_camera_register_event_notify_internal(mm_camera_obj_t *my_obj, 666 mm_camera_event_notify_t evt_cb, 667 void * user_data); 668 extern int32_t mm_camera_map_stream_buf(mm_camera_obj_t *my_obj, 669 uint32_t ch_id, 670 uint32_t stream_id, 671 uint8_t buf_type, 672 uint32_t buf_idx, 673 int32_t plane_idx, 674 int fd, 675 size_t size); 676 extern int32_t mm_camera_map_stream_bufs(mm_camera_obj_t *my_obj, 677 uint32_t ch_id, 678 const cam_buf_map_type_list *buf_map_list); 679 extern int32_t mm_camera_unmap_stream_buf(mm_camera_obj_t *my_obj, 680 uint32_t ch_id, 681 uint32_t stream_id, 682 uint8_t buf_type, 683 uint32_t buf_idx, 684 int32_t plane_idx); 685 extern int32_t mm_camera_do_stream_action(mm_camera_obj_t *my_obj, 686 uint32_t ch_id, 687 uint32_t stream_id, 688 void *actions); 689 extern int32_t mm_camera_get_session_id(mm_camera_obj_t *my_obj, 690 uint32_t* sessionid); 691 extern int32_t mm_camera_sync_related_sensors(mm_camera_obj_t *my_obj, 692 cam_sync_related_sensors_event_info_t *parms); 693 694 /* mm_channel */ 695 extern int32_t mm_channel_fsm_fn(mm_channel_t *my_obj, 696 mm_channel_evt_type_t evt, 697 void * in_val, 698 void * out_val); 699 extern int32_t mm_channel_init(mm_channel_t *my_obj, 700 mm_camera_channel_attr_t *attr, 701 mm_camera_buf_notify_t channel_cb, 702 void *userdata); 703 /* qbuf is a special case that not going through state machine. 704 * This is to avoid deadlock when trying to aquire ch_lock, 705 * from the context of dataCB, but async stop is holding ch_lock */ 706 extern int32_t mm_channel_qbuf(mm_channel_t *my_obj, 707 mm_camera_buf_def_t *buf); 708 /* mm_stream */ 709 extern int32_t mm_stream_fsm_fn(mm_stream_t *my_obj, 710 mm_stream_evt_type_t evt, 711 void * in_val, 712 void * out_val); 713 /* Function to register special callback for stream buffer*/ 714 extern int32_t mm_stream_reg_buf_cb(mm_stream_t *my_obj, 715 mm_stream_data_cb_t val); 716 extern int32_t mm_stream_map_buf(mm_stream_t *my_obj, 717 uint8_t buf_type, 718 uint32_t frame_idx, 719 int32_t plane_idx, 720 int fd, 721 size_t size); 722 extern int32_t mm_stream_map_bufs(mm_stream_t *my_obj, 723 const cam_buf_map_type_list *buf_map_list); 724 extern int32_t mm_stream_unmap_buf(mm_stream_t *my_obj, 725 uint8_t buf_type, 726 uint32_t frame_idx, 727 int32_t plane_idx); 728 729 730 /* utiltity fucntion declared in mm-camera-inteface2.c 731 * and need be used by mm-camera and below*/ 732 uint32_t mm_camera_util_generate_handler(uint8_t index); 733 const char * mm_camera_util_get_dev_name(uint32_t cam_handler); 734 uint8_t mm_camera_util_get_index_by_handler(uint32_t handler); 735 736 /* poll/cmd thread functions */ 737 extern int32_t mm_camera_poll_thread_launch( 738 mm_camera_poll_thread_t * poll_cb, 739 mm_camera_poll_thread_type_t poll_type); 740 extern int32_t mm_camera_poll_thread_release(mm_camera_poll_thread_t *poll_cb); 741 extern int32_t mm_camera_poll_thread_add_poll_fd( 742 mm_camera_poll_thread_t * poll_cb, 743 uint32_t handler, 744 int32_t fd, 745 mm_camera_poll_notify_t nofity_cb, 746 void *userdata, 747 mm_camera_call_type_t); 748 extern int32_t mm_camera_poll_thread_del_poll_fd( 749 mm_camera_poll_thread_t * poll_cb, 750 uint32_t handler, 751 mm_camera_call_type_t); 752 extern int32_t mm_camera_poll_thread_commit_updates( 753 mm_camera_poll_thread_t * poll_cb); 754 extern int32_t mm_camera_cmd_thread_launch( 755 mm_camera_cmd_thread_t * cmd_thread, 756 mm_camera_cmd_cb_t cb, 757 void* user_data); 758 extern int32_t mm_camera_cmd_thread_name(const char* name); 759 extern int32_t mm_camera_cmd_thread_release(mm_camera_cmd_thread_t * cmd_thread); 760 761 extern int32_t mm_camera_channel_advanced_capture(mm_camera_obj_t *my_obj, 762 uint32_t ch_id, mm_camera_advanced_capture_t type, 763 uint32_t trigger, void *in_value); 764 #endif /* __MM_CAMERA_H__ */ 765