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 "hardware/camera_common.h" 38 #include "cam_semaphore.h" 39 #include "mm_camera_interface.h" 40 #include "mm_camera_shim.h" 41 42 /********************************************************************************** 43 * Data structure declarations 44 ***********************************************************************************/ 45 /* num of callbacks allowed for an event type */ 46 #define MM_CAMERA_EVT_ENTRY_MAX 4 47 /* num of data callbacks allowed in a stream obj */ 48 #define MM_CAMERA_STREAM_BUF_CB_MAX 4 49 /* num of data poll threads allowed in a channel obj */ 50 #define MM_CAMERA_CHANNEL_POLL_THREAD_MAX 1 51 52 #define MM_CAMERA_DEV_NAME_LEN 32 53 #define MM_CAMERA_DEV_OPEN_TRIES 20 54 #define MM_CAMERA_DEV_OPEN_RETRY_SLEEP 20 55 #define THREAD_NAME_SIZE 15 56 57 /* Future frame idx, large enough to make sure capture 58 * settings can be applied and small enough to still capture an image */ 59 #define MM_CAMERA_MAX_FUTURE_FRAME_WAIT 100 60 #define WAIT_TIMEOUT 5 61 62 /*For frame sync */ 63 #define MAX_OBJS_FOR_FRAME_SYNC 4 64 65 /* num of supporting camera*/ 66 #define MM_CAMERA_MAX_AUX_CAMERA 1 67 68 #ifndef TRUE 69 #define TRUE 1 70 #endif 71 72 #ifndef FALSE 73 #define FALSE 0 74 #endif 75 76 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) 77 78 struct mm_channel; 79 struct mm_stream; 80 struct mm_camera_obj; 81 82 typedef int64_t nsecs_t; 83 84 typedef enum 85 { 86 MM_CAMERA_CMD_TYPE_DATA_CB, /* dataB CMD */ 87 MM_CAMERA_CMD_TYPE_EVT_CB, /* evtCB CMD */ 88 MM_CAMERA_CMD_TYPE_EXIT, /* EXIT */ 89 MM_CAMERA_CMD_TYPE_REQ_DATA_CB,/* request data */ 90 MM_CAMERA_CMD_TYPE_SUPER_BUF_DATA_CB, /* superbuf dataB CMD */ 91 MM_CAMERA_CMD_TYPE_CONFIG_NOTIFY, /* configure notify mode */ 92 MM_CAMERA_CMD_TYPE_START_ZSL, /* start zsl snapshot for channel */ 93 MM_CAMERA_CMD_TYPE_STOP_ZSL, /* stop zsl snapshot for channel */ 94 MM_CAMERA_CMD_TYPE_FLUSH_QUEUE, /* flush queue */ 95 MM_CAMERA_CMD_TYPE_GENERAL, /* general cmd */ 96 MM_CAMERA_CMD_TYPE_MAX 97 } mm_camera_cmdcb_type_t; 98 99 typedef struct { 100 uint32_t stream_id; 101 uint32_t frame_idx; 102 uint32_t flags; 103 mm_camera_buf_def_t *buf; /* ref to buf */ 104 } mm_camera_buf_info_t; 105 106 typedef enum { 107 MM_CAMERA_GENERIC_CMD_TYPE_AE_BRACKETING, 108 MM_CAMERA_GENERIC_CMD_TYPE_AF_BRACKETING, 109 MM_CAMERA_GENERIC_CMD_TYPE_FLASH_BRACKETING, 110 MM_CAMERA_GENERIC_CMD_TYPE_ZOOM_1X, 111 MM_CAMERA_GENERIC_CMD_TYPE_CAPTURE_SETTING, 112 } mm_camera_generic_cmd_type_t; 113 114 typedef struct { 115 mm_camera_generic_cmd_type_t type; 116 uint32_t payload[32]; 117 union { 118 cam_capture_frame_config_t frame_config; 119 }; 120 } mm_camera_generic_cmd_t; 121 122 typedef struct { 123 uint32_t frame_idx; 124 cam_stream_type_t stream_type; 125 } mm_camera_flush_cmd_t; 126 127 typedef struct { 128 mm_camera_cmdcb_type_t cmd_type; 129 union { 130 mm_camera_buf_info_t buf; /* frame buf if dataCB */ 131 mm_camera_event_t evt; /* evt if evtCB */ 132 mm_camera_super_buf_t superbuf; /* superbuf if superbuf dataCB*/ 133 mm_camera_req_buf_t req_buf; /* num of buf requested */ 134 mm_camera_flush_cmd_t flush_cmd; /* frame idx boundary for flush superbuf queue*/ 135 mm_camera_super_buf_notify_mode_t notify_mode; /* notification mode */ 136 mm_camera_generic_cmd_t gen_cmd; 137 } u; 138 } mm_camera_cmdcb_t; 139 140 typedef void (*mm_camera_cmd_cb_t)(mm_camera_cmdcb_t * cmd_cb, void* user_data); 141 142 typedef struct { 143 uint8_t is_active; /*indicates whether thread is active or not */ 144 cam_queue_t cmd_queue; /* cmd queue (queuing dataCB, asyncCB, or exitCMD) */ 145 pthread_t cmd_pid; /* cmd thread ID */ 146 cam_semaphore_t cmd_sem; /* semaphore for cmd thread */ 147 cam_semaphore_t sync_sem; /* semaphore for synchronization with cmd thread */ 148 mm_camera_cmd_cb_t cb; /* cb for cmd */ 149 void* user_data; /* user_data for cb */ 150 char threadName[THREAD_NAME_SIZE]; 151 } mm_camera_cmd_thread_t; 152 153 typedef enum { 154 MM_CAMERA_POLL_TYPE_EVT, 155 MM_CAMERA_POLL_TYPE_DATA, 156 MM_CAMERA_POLL_TYPE_MAX 157 } mm_camera_poll_thread_type_t; 158 159 /* function ptr defined for poll notify CB, 160 * registered at poll thread with poll fd */ 161 typedef void (*mm_camera_poll_notify_t)(void *user_data); 162 163 typedef struct { 164 int32_t fd; 165 mm_camera_poll_notify_t notify_cb; 166 uint32_t handler; 167 void* user_data; 168 } mm_camera_poll_entry_t; 169 170 typedef struct { 171 mm_camera_poll_thread_type_t poll_type; 172 /* array to store poll fd and cb info 173 * for MM_CAMERA_POLL_TYPE_EVT, only index 0 is valid; 174 * for MM_CAMERA_POLL_TYPE_DATA, depends on valid stream fd */ 175 mm_camera_poll_entry_t poll_entries[MAX_STREAM_NUM_IN_BUNDLE]; 176 int32_t pfds[2]; 177 pthread_t pid; 178 int32_t state; 179 int timeoutms; 180 uint32_t cmd; 181 struct pollfd poll_fds[MAX_STREAM_NUM_IN_BUNDLE + 1]; 182 uint8_t num_fds; 183 pthread_mutex_t mutex; 184 pthread_cond_t cond_v; 185 int32_t status; 186 char threadName[THREAD_NAME_SIZE]; 187 //void *my_obj; 188 } mm_camera_poll_thread_t; 189 190 /* mm_stream */ 191 typedef enum { 192 MM_STREAM_STATE_NOTUSED = 0, /* not used */ 193 MM_STREAM_STATE_INITED, /* inited */ 194 MM_STREAM_STATE_ACQUIRED, /* acquired, fd opened */ 195 MM_STREAM_STATE_CFG, /* fmt & dim configured */ 196 MM_STREAM_STATE_BUFFED, /* buf allocated */ 197 MM_STREAM_STATE_REG, /* buf regged, stream off */ 198 MM_STREAM_STATE_ACTIVE, /* active */ 199 MM_STREAM_STATE_MAX 200 } mm_stream_state_type_t; 201 202 typedef enum { 203 MM_STREAM_EVT_ACQUIRE, 204 MM_STREAM_EVT_RELEASE, 205 MM_STREAM_EVT_SET_FMT, 206 MM_STREAM_EVT_GET_BUF, 207 MM_STREAM_EVT_PUT_BUF, 208 MM_STREAM_EVT_REG_BUF, 209 MM_STREAM_EVT_UNREG_BUF, 210 MM_STREAM_EVT_START, 211 MM_STREAM_EVT_STOP, 212 MM_STREAM_EVT_QBUF, 213 MM_STREAM_EVT_SET_PARM, 214 MM_STREAM_EVT_GET_PARM, 215 MM_STREAM_EVT_DO_ACTION, 216 MM_STREAM_EVT_GET_QUEUED_BUF_COUNT, 217 MM_STREAM_EVT_REG_FRAME_SYNC, 218 MM_STREAM_EVT_TRIGGER_FRAME_SYNC, 219 MM_STREAM_EVT_SWITCH_STREAM_CB, 220 MM_STREAM_EVT_MAX 221 } mm_stream_evt_type_t; 222 223 typedef struct { 224 mm_camera_buf_notify_t cb; 225 void *user_data; 226 /* cb_count = -1: infinite 227 * cb_count > 0: register only for required times */ 228 int8_t cb_count; 229 mm_camera_stream_cb_type cb_type; 230 } mm_stream_data_cb_t; 231 232 typedef struct { 233 /* buf reference count */ 234 uint8_t buf_refcnt; 235 236 /* This flag is to indicate if after allocation, 237 * the corresponding buf needs to qbuf into kernel 238 * (e.g. for preview usecase, display needs to hold two bufs, 239 * so no need to qbuf these two bufs initially) */ 240 uint8_t initial_reg_flag; 241 242 /* indicate if buf is in kernel(1) or client(0) */ 243 uint8_t in_kernel; 244 /*indicate if this buffer is mapped to daemon*/ 245 int8_t map_status; 246 } mm_stream_buf_status_t; 247 248 /*Structure definition to carry frame sync queue details*/ 249 typedef struct { 250 /*Number of objects to be synced*/ 251 uint8_t num_objs; 252 /*Object handle to be synced*/ 253 uint32_t bundled_objs[MAX_OBJS_FOR_FRAME_SYNC]; 254 /*Queue*/ 255 cam_queue_t que; 256 257 /*queue attributed*/ 258 /*Number of frames to wait before process unmatched cb*/ 259 uint8_t max_unmatched_frames; 260 261 /*Expected frame for this queue*/ 262 uint32_t expected_frame_id; 263 264 /*Parameter to consider during frame sync*/ 265 mm_camera_super_buf_priority_t priority; 266 } mm_frame_sync_queue_t; 267 268 /*Structure definition to carry frame sync details*/ 269 typedef struct { 270 /* flag to indicate if frame sync is active*/ 271 uint8_t is_active; 272 273 /*Frame sync lock. Shared between child and parent stream*/ 274 pthread_mutex_t sync_lock; 275 276 /*Limited number of synced frame request*/ 277 uint32_t num_buf_requested; 278 279 /*Queue to hold super buffers*/ 280 mm_frame_sync_queue_t superbuf_queue; 281 282 /*Callback registered for synced frame*/ 283 mm_camera_buf_notify_t super_buf_notify_cb; 284 285 /*Client data*/ 286 void *user_data; 287 } mm_frame_sync_t; 288 289 struct mm_stream; 290 typedef struct mm_stream { 291 uint32_t my_hdl; /* local stream id */ 292 uint32_t server_stream_id; /* stream id from server */ 293 int32_t fd; 294 mm_stream_state_type_t state; 295 296 /* stream info*/ 297 cam_stream_info_t *stream_info; 298 299 /* padding info */ 300 cam_padding_info_t padding_info; 301 302 /* offset */ 303 cam_frame_len_offset_t frame_offset; 304 305 pthread_mutex_t cmd_lock; /* lock to protect cmd_thread */ 306 mm_camera_cmd_thread_t cmd_thread; 307 308 /* dataCB registered on this stream obj */ 309 uint8_t is_cb_active; 310 pthread_mutex_t cb_lock; /* cb lock to protect buf_cb */ 311 mm_stream_data_cb_t buf_cb[MM_CAMERA_STREAM_BUF_CB_MAX]; 312 313 /* stream buffer management */ 314 pthread_mutex_t buf_lock; 315 uint8_t total_buf_cnt; /*Total number of buffer including slave*/ 316 uint8_t buf_num; /* num of buffers for this stream */ 317 uint8_t buf_idx; /* starting buffer index */ 318 319 mm_camera_buf_def_t* buf; /* ptr to buf array */ 320 mm_stream_buf_status_t buf_status[CAM_MAX_NUM_BUFS_PER_STREAM]; /* ptr to buf status array */ 321 322 uint8_t plane_buf_num; /* num of plane buffers allocated Used only in Batch mode*/ 323 mm_camera_buf_def_t *plane_buf; /*Pointer to plane buffer array Used only in Batch mode */ 324 int32_t cur_buf_idx; /* Current container buffer active filling. Used only in Batch mode*/ 325 uint8_t cur_bufs_staged; /*Number of plane buf freed by HAL for this usr buf*/ 326 327 /* reference to parent channel_obj */ 328 struct mm_channel* ch_obj; 329 330 uint8_t is_bundled; /* flag if stream is bundled */ 331 332 /* reference to linked channel_obj */ 333 struct mm_channel* linked_obj; 334 struct mm_stream * linked_stream; /* original stream */ 335 uint8_t is_linked; /* flag if stream is linked */ 336 337 mm_camera_stream_mem_vtbl_t mem_vtbl; /* mem ops tbl */ 338 mm_camera_map_unmap_ops_tbl_t map_ops; 339 340 int8_t queued_buffer_count; 341 342 /*latest timestamp of this stream frame received & last frameID*/ 343 uint32_t prev_frameID; 344 nsecs_t prev_timestamp; 345 346 /* Need to wait for buffer mapping before stream-on*/ 347 pthread_cond_t buf_cond; 348 349 struct mm_stream *master_str_obj; /*Master stream of this stream*/ 350 uint8_t num_s_cnt; 351 struct mm_stream *aux_str_obj[MM_CAMERA_MAX_AUX_CAMERA]; /*aux stream of this stream*/ 352 mm_frame_sync_t frame_sync; 353 uint8_t is_res_shared; 354 } mm_stream_t; 355 356 /* mm_channel */ 357 typedef enum { 358 MM_CHANNEL_STATE_NOTUSED = 0, /* not used */ 359 MM_CHANNEL_STATE_STOPPED, /* stopped */ 360 MM_CHANNEL_STATE_ACTIVE, /* active, at least one stream active */ 361 MM_CHANNEL_STATE_PAUSED, /* paused */ 362 MM_CHANNEL_STATE_MAX 363 } mm_channel_state_type_t; 364 365 typedef enum { 366 MM_CHANNEL_EVT_ADD_STREAM, 367 MM_CHANNEL_EVT_DEL_STREAM, 368 MM_CHANNEL_EVT_LINK_STREAM, 369 MM_CHANNEL_EVT_CONFIG_STREAM, 370 MM_CHANNEL_EVT_GET_BUNDLE_INFO, 371 MM_CHANNEL_EVT_START, 372 MM_CHANNEL_EVT_STOP, 373 MM_CHANNEL_EVT_PAUSE, 374 MM_CHANNEL_EVT_RESUME, 375 MM_CHANNEL_EVT_REQUEST_SUPER_BUF, 376 MM_CHANNEL_EVT_CANCEL_REQUEST_SUPER_BUF, 377 MM_CHANNEL_EVT_FLUSH_SUPER_BUF_QUEUE, 378 MM_CHANNEL_EVT_CONFIG_NOTIFY_MODE, 379 MM_CHANNEL_EVT_START_ZSL_SNAPSHOT, 380 MM_CHANNEL_EVT_STOP_ZSL_SNAPSHOT, 381 MM_CHANNEL_EVT_MAP_STREAM_BUF, 382 MM_CHANNEL_EVT_UNMAP_STREAM_BUF, 383 MM_CHANNEL_EVT_SET_STREAM_PARM, 384 MM_CHANNEL_EVT_GET_STREAM_PARM, 385 MM_CHANNEL_EVT_DO_ACTION, 386 MM_CHANNEL_EVT_DELETE, 387 MM_CHANNEL_EVT_AF_BRACKETING, 388 MM_CHANNEL_EVT_AE_BRACKETING, 389 MM_CHANNEL_EVT_FLASH_BRACKETING, 390 MM_CHANNEL_EVT_ZOOM_1X, 391 MM_CAMERA_EVT_CAPTURE_SETTING, 392 MM_CHANNEL_EVT_GET_STREAM_QUEUED_BUF_COUNT, 393 MM_CHANNEL_EVT_MAP_STREAM_BUFS, 394 MM_CHANNEL_EVT_REG_STREAM_BUF_CB, 395 MM_CHANNEL_EVT_REG_FRAME_SYNC, 396 MM_CHANNEL_EVT_TRIGGER_FRAME_SYNC, 397 MM_CHANNEL_EVT_SWITCH_STREAM_CB, 398 } mm_channel_evt_type_t; 399 400 typedef struct { 401 uint32_t stream_id; 402 mm_camera_stream_config_t *config; 403 } mm_evt_paylod_config_stream_t; 404 405 typedef struct { 406 uint32_t stream_id; 407 cam_stream_parm_buffer_t *parms; 408 } mm_evt_paylod_set_get_stream_parms_t; 409 410 typedef struct { 411 uint32_t stream_id; 412 void *actions; 413 } mm_evt_paylod_do_stream_action_t; 414 415 typedef struct { 416 uint32_t stream_id; 417 mm_stream_data_cb_t buf_cb; 418 } mm_evt_paylod_reg_stream_buf_cb; 419 420 typedef struct { 421 uint8_t num_of_bufs; 422 mm_camera_buf_info_t super_buf[MAX_STREAM_NUM_IN_BUNDLE]; 423 uint8_t matched; 424 uint8_t expected_frame; 425 uint32_t frame_idx; 426 /* unmatched meta idx needed in case of low priority queue */ 427 uint32_t unmatched_meta_idx; 428 } mm_channel_queue_node_t; 429 430 typedef struct { 431 cam_queue_t que; 432 uint8_t num_streams; 433 /* container for bundled stream handlers */ 434 uint32_t bundled_streams[MAX_STREAM_NUM_IN_BUNDLE]; 435 mm_camera_channel_attr_t attr; 436 uint32_t expected_frame_id; 437 uint32_t match_cnt; 438 uint32_t expected_frame_id_without_led; 439 uint32_t led_on_start_frame_id; 440 uint32_t led_off_start_frame_id; 441 uint32_t led_on_num_frames; 442 uint32_t once; 443 uint32_t frame_skip_count; 444 uint32_t good_frame_id; 445 } mm_channel_queue_t; 446 447 typedef struct { 448 uint8_t is_active; /* flag to indicate if bundle is valid */ 449 /* queue to store bundled super buffers */ 450 uint8_t is_cb_active; 451 mm_channel_queue_t superbuf_queue; 452 mm_camera_buf_notify_t super_buf_notify_cb; 453 void *user_data; 454 } mm_channel_bundle_t; 455 456 /* Nodes used for frame sync */ 457 typedef struct { 458 /* Frame idx */ 459 uint32_t frame_idx; 460 /* Frame present for corresponding channel*/ 461 uint32_t frame_valid[MAX_NUM_CAMERA_PER_BUNDLE]; 462 /* Frame present in all channels*/ 463 uint32_t matched; 464 } mm_channel_sync_node_t; 465 466 /* Frame sync information */ 467 typedef struct { 468 /* Number of camera channels that need to be synced*/ 469 uint8_t num_cam; 470 /* position of the next node to be updated */ 471 uint8_t pos; 472 /* circular node array used to store frame information */ 473 mm_channel_sync_node_t node[MM_CAMERA_FRAME_SYNC_NODES]; 474 /* Channel corresponding to each camera */ 475 struct mm_channel *ch_obj[MAX_NUM_CAMERA_PER_BUNDLE]; 476 /* Cb corresponding to each camera */ 477 mm_camera_buf_notify_t cb[MAX_NUM_CAMERA_PER_BUNDLE]; 478 } mm_channel_frame_sync_info_t; 479 480 /* Node information for multiple superbuf callbacks 481 * This can be used to batch nodes before sending to upper layer */ 482 typedef struct { 483 /* Number of nodes to be sent*/ 484 uint8_t num_nodes; 485 /* queue node information*/ 486 mm_channel_queue_node_t *node[MAX_NUM_CAMERA_PER_BUNDLE]; 487 /* channel information*/ 488 struct mm_channel *ch_obj[MAX_NUM_CAMERA_PER_BUNDLE]; 489 } mm_channel_node_info_t; 490 491 typedef enum { 492 MM_CHANNEL_BRACKETING_STATE_OFF, 493 MM_CHANNEL_BRACKETING_STATE_WAIT_GOOD_FRAME_IDX, 494 MM_CHANNEL_BRACKETING_STATE_ACTIVE, 495 } mm_channel_bracketing_state_t; 496 497 struct mm_channel; 498 typedef struct mm_channel { 499 uint32_t my_hdl; 500 mm_channel_state_type_t state; 501 pthread_mutex_t ch_lock; /* channel lock */ 502 503 /* stream bundle info in the channel */ 504 mm_channel_bundle_t bundle; 505 506 /* num of pending suferbuffers */ 507 uint32_t pending_cnt; 508 uint32_t pending_retro_cnt; 509 mm_camera_req_buf_type_t req_type; 510 uint32_t bWaitForPrepSnapshotDone; 511 uint32_t unLockAEC; 512 /* num of pending suferbuffers */ 513 uint8_t stopZslSnapshot; 514 515 /* cmd thread for superbuffer dataCB and async stop*/ 516 mm_camera_cmd_thread_t cmd_thread; 517 518 /* cb thread for sending data cb */ 519 mm_camera_cmd_thread_t cb_thread; 520 521 /* data poll thread 522 * currently one data poll thread per channel 523 * could extended to support one data poll thread per stream in the channel */ 524 mm_camera_poll_thread_t poll_thread[MM_CAMERA_CHANNEL_POLL_THREAD_MAX]; 525 526 /* container for all streams in channel */ 527 mm_stream_t streams[MAX_STREAM_NUM_IN_BUNDLE]; 528 529 /* reference to parent cam_obj */ 530 struct mm_camera_obj* cam_obj; 531 532 /* manual zsl snapshot control */ 533 uint8_t manualZSLSnapshot; 534 535 /* control for zsl led */ 536 uint8_t startZSlSnapshotCalled; 537 uint8_t needLEDFlash; 538 mm_channel_bracketing_state_t bracketingState; 539 uint8_t isFlashBracketingEnabled; 540 uint8_t isZoom1xFrameRequested; 541 uint32_t burstSnapNum; 542 char threadName[THREAD_NAME_SIZE]; 543 544 /*Buffer diverted*/ 545 uint8_t diverted_frame_id; 546 uint32_t sessionid; 547 548 /*Frame capture configaration*/ 549 uint8_t isConfigCapture; 550 uint8_t cur_capture_idx; 551 uint32_t capture_frame_id[MAX_CAPTURE_BATCH_NUM]; 552 cam_capture_frame_config_t frameConfig; 553 uint8_t needLowLightZSL; 554 555 /*Capture based on index*/ 556 uint8_t cur_req_idx; 557 uint8_t frame_req_cnt; 558 uint32_t requested_frame_id[MAX_CAPTURE_BATCH_NUM]; 559 560 /*For channel frame sync*/ 561 mm_frame_sync_t frame_sync; 562 563 /*Multiple camera's*/ 564 struct mm_channel *master_ch_obj; /*Master channel of this channel*/ 565 uint8_t num_s_cnt; 566 struct mm_channel *aux_ch_obj[MM_CAMERA_MAX_AUX_CAMERA]; /*Slave channel of this channel*/ 567 } mm_channel_t; 568 569 typedef struct { 570 mm_channel_t *ch; 571 uint32_t stream_id; 572 } mm_camera_stream_link_t; 573 574 /* struct to store information about pp cookie*/ 575 typedef struct { 576 uint32_t cam_hdl; 577 uint32_t ch_hdl; 578 uint32_t stream_hdl; 579 mm_channel_queue_node_t* super_buf; 580 } mm_channel_pp_info_t; 581 582 /* mm_camera */ 583 typedef struct { 584 mm_camera_event_notify_t evt_cb; 585 void *user_data; 586 } mm_camera_evt_entry_t; 587 588 typedef struct { 589 mm_camera_evt_entry_t evt[MM_CAMERA_EVT_ENTRY_MAX]; 590 /* reg_count <=0: infinite 591 * reg_count > 0: register only for required times */ 592 int reg_count; 593 } mm_camera_evt_obj_t; 594 595 struct mm_camera_obj; 596 typedef struct mm_camera_obj { 597 uint32_t my_hdl; 598 int ref_count; 599 int32_t ctrl_fd; 600 int32_t ds_fd; /* domain socket fd */ 601 pthread_mutex_t cam_lock; 602 pthread_mutex_t cb_lock; /* lock for evt cb */ 603 mm_channel_t ch[MM_CAMERA_CHANNEL_MAX]; 604 mm_camera_evt_obj_t evt; 605 mm_camera_poll_thread_t evt_poll_thread; /* evt poll thread */ 606 mm_camera_cmd_thread_t evt_thread; /* thread for evt CB */ 607 mm_camera_vtbl_t vtbl; 608 609 pthread_mutex_t evt_lock; 610 pthread_cond_t evt_cond; 611 mm_camera_event_t evt_rcvd; 612 613 pthread_mutex_t msg_lock; /* lock for sending msg through socket */ 614 uint32_t sessionid; /* Camera server session id */ 615 616 uint8_t my_num; /*this camera position in multi mode*/ 617 pthread_mutex_t muxer_lock; 618 struct mm_camera_obj *master_cam_obj; /*Master Camera of this camera*/ 619 uint8_t num_s_cnt; 620 struct mm_camera_obj *aux_cam_obj[MM_CAMERA_MAX_AUX_CAMERA]; /*Slave Camera of this camera*/ 621 } mm_camera_obj_t; 622 623 typedef struct { 624 int8_t num_cam; 625 mm_camera_shim_ops_t cam_shim_ops; 626 char video_dev_name[MM_CAMERA_MAX_NUM_SENSORS][MM_CAMERA_DEV_NAME_LEN]; 627 mm_camera_obj_t *cam_obj[MM_CAMERA_MAX_NUM_SENSORS]; 628 struct camera_info info[MM_CAMERA_MAX_NUM_SENSORS]; 629 cam_sync_type_t cam_type[MM_CAMERA_MAX_NUM_SENSORS]; 630 cam_sync_mode_t cam_mode[MM_CAMERA_MAX_NUM_SENSORS]; 631 uint8_t is_yuv[MM_CAMERA_MAX_NUM_SENSORS]; // 1=CAM_SENSOR_YUV, 0=CAM_SENSOR_RAW 632 uint32_t cam_index[MM_CAMERA_MAX_NUM_SENSORS]; //Actual cam index are stored in bits 633 } mm_camera_ctrl_t; 634 635 typedef enum { 636 mm_camera_async_call, 637 mm_camera_sync_call 638 } mm_camera_call_type_t; 639 640 /*internal structure for registring frame sync*/ 641 typedef struct { 642 mm_camera_obj_t *a_cam_obj; 643 uint32_t a_ch_id; 644 uint32_t a_stream_id; 645 uint8_t max_unmatched_frames; 646 mm_camera_buf_notify_t buf_cb; 647 uint8_t is_res_shared; 648 mm_camera_super_buf_priority_t priority; 649 void *userdata; 650 } mm_camera_frame_sync_t; 651 652 /*Payload for reg frame sync event in MCI*/ 653 typedef struct { 654 uint32_t stream_id; 655 mm_channel_t *a_ch_obj; 656 mm_stream_t *a_str_obj; 657 mm_camera_frame_sync_t *sync_attr; 658 } mm_evt_paylod_reg_frame_sync; 659 660 /*Payload for strart/stop frame sync event in MCI*/ 661 typedef struct { 662 uint32_t stream_id; 663 uint8_t enable_frame_sync; 664 } mm_evt_paylod_trigger_frame_sync; 665 666 /********************************************************************************** 667 * external function declare 668 ***********************************************************************************/ 669 /* utility functions */ 670 /* set int32_t value */ 671 extern int32_t mm_camera_util_s_ctrl(mm_camera_obj_t *my_obj, 672 int stream_id, int32_t fd, uint32_t id, int32_t *value); 673 674 /* get int32_t value */ 675 extern int32_t mm_camera_util_g_ctrl(mm_camera_obj_t *my_obj, 676 int stream_id, int32_t fd, uint32_t id, int32_t *value); 677 678 /* send msg throught domain socket for fd mapping */ 679 extern int32_t mm_camera_util_sendmsg(mm_camera_obj_t *my_obj, 680 void *msg, 681 size_t buf_size, 682 int sendfd); 683 684 /* send msg through domain socket for bundled fd mapping */ 685 extern int32_t mm_camera_util_bundled_sendmsg(mm_camera_obj_t *my_obj, 686 void *msg, 687 size_t buf_size, 688 int sendfds[CAM_MAX_NUM_BUFS_PER_STREAM], 689 int numfds); 690 691 /* Check if hardware target is A family */ 692 uint8_t mm_camera_util_chip_is_a_family(void); 693 694 /* mm-camera */ 695 extern int32_t mm_camera_open(mm_camera_obj_t *my_obj); 696 extern int32_t mm_camera_close(mm_camera_obj_t *my_obj); 697 extern int32_t mm_camera_register_event_notify(mm_camera_obj_t *my_obj, 698 mm_camera_event_notify_t evt_cb, 699 void * user_data); 700 extern int32_t mm_camera_qbuf(mm_camera_obj_t *my_obj, 701 uint32_t ch_id, 702 mm_camera_buf_def_t *buf); 703 extern int32_t mm_camera_get_queued_buf_count(mm_camera_obj_t *my_obj, 704 uint32_t ch_id, uint32_t stream_id); 705 extern int32_t mm_camera_query_capability(mm_camera_obj_t *my_obj); 706 extern int32_t mm_camera_set_parms(mm_camera_obj_t *my_obj, 707 parm_buffer_t *parms); 708 extern int32_t mm_camera_get_parms(mm_camera_obj_t *my_obj, 709 parm_buffer_t *parms); 710 extern int32_t mm_camera_map_buf(mm_camera_obj_t *my_obj, 711 uint8_t buf_type, 712 int fd, 713 size_t size, 714 void *buffer); 715 extern int32_t mm_camera_map_bufs(mm_camera_obj_t *my_obj, 716 const cam_buf_map_type_list *buf_map_list); 717 extern int32_t mm_camera_unmap_buf(mm_camera_obj_t *my_obj, 718 uint8_t buf_type); 719 extern int32_t mm_camera_do_auto_focus(mm_camera_obj_t *my_obj); 720 extern int32_t mm_camera_cancel_auto_focus(mm_camera_obj_t *my_obj); 721 extern int32_t mm_camera_prepare_snapshot(mm_camera_obj_t *my_obj, 722 int32_t do_af_flag); 723 extern int32_t mm_camera_start_zsl_snapshot(mm_camera_obj_t *my_obj); 724 extern int32_t mm_camera_stop_zsl_snapshot(mm_camera_obj_t *my_obj); 725 extern int32_t mm_camera_flush(mm_camera_obj_t *my_obj); 726 extern int32_t mm_camera_start_zsl_snapshot_ch(mm_camera_obj_t *my_obj, 727 uint32_t ch_id); 728 extern int32_t mm_camera_stop_zsl_snapshot_ch(mm_camera_obj_t *my_obj, 729 uint32_t ch_id); 730 extern uint32_t mm_camera_add_channel(mm_camera_obj_t *my_obj, 731 mm_camera_channel_attr_t *attr, 732 mm_camera_buf_notify_t channel_cb, 733 void *userdata); 734 extern int32_t mm_camera_del_channel(mm_camera_obj_t *my_obj, 735 uint32_t ch_id); 736 extern int32_t mm_camera_get_bundle_info(mm_camera_obj_t *my_obj, 737 uint32_t ch_id, 738 cam_bundle_config_t *bundle_info); 739 extern uint32_t mm_camera_add_stream(mm_camera_obj_t *my_obj, 740 uint32_t ch_id); 741 extern int32_t mm_camera_del_stream(mm_camera_obj_t *my_obj, 742 uint32_t ch_id, 743 uint32_t stream_id); 744 extern uint32_t mm_camera_link_stream(mm_camera_obj_t *my_obj, 745 uint32_t ch_id, 746 uint32_t stream_id, 747 uint32_t linked_ch_id); 748 749 extern int32_t mm_camera_reg_stream_buf_cb(mm_camera_obj_t *my_obj, 750 uint32_t ch_id, uint32_t stream_id, mm_camera_buf_notify_t buf_cb, 751 mm_camera_stream_cb_type cb_type, void *userdata); 752 extern int32_t mm_camera_config_stream(mm_camera_obj_t *my_obj, 753 uint32_t ch_id, 754 uint32_t stream_id, 755 mm_camera_stream_config_t *config); 756 extern int32_t mm_camera_start_channel(mm_camera_obj_t *my_obj, 757 uint32_t ch_id); 758 extern int32_t mm_camera_stop_channel(mm_camera_obj_t *my_obj, 759 uint32_t ch_id); 760 extern int32_t mm_camera_request_super_buf(mm_camera_obj_t *my_obj, 761 uint32_t ch_id, mm_camera_req_buf_t *buf); 762 extern int32_t mm_camera_cancel_super_buf_request(mm_camera_obj_t *my_obj, 763 uint32_t ch_id); 764 extern int32_t mm_camera_flush_super_buf_queue(mm_camera_obj_t *my_obj, 765 uint32_t ch_id, 766 uint32_t frame_idx); 767 extern int32_t mm_camera_config_channel_notify(mm_camera_obj_t *my_obj, 768 uint32_t ch_id, 769 mm_camera_super_buf_notify_mode_t notify_mode); 770 extern int32_t mm_camera_set_stream_parms(mm_camera_obj_t *my_obj, 771 uint32_t ch_id, 772 uint32_t s_id, 773 cam_stream_parm_buffer_t *parms); 774 extern int32_t mm_camera_get_stream_parms(mm_camera_obj_t *my_obj, 775 uint32_t ch_id, 776 uint32_t s_id, 777 cam_stream_parm_buffer_t *parms); 778 extern int32_t mm_camera_register_event_notify_internal(mm_camera_obj_t *my_obj, 779 mm_camera_event_notify_t evt_cb, 780 void * user_data); 781 extern int32_t mm_camera_map_stream_buf(mm_camera_obj_t *my_obj, 782 uint32_t ch_id, 783 uint32_t stream_id, 784 uint8_t buf_type, 785 uint32_t buf_idx, 786 int32_t plane_idx, 787 int fd, 788 size_t size, 789 void *buffer); 790 extern int32_t mm_camera_map_stream_bufs(mm_camera_obj_t *my_obj, 791 uint32_t ch_id, 792 const cam_buf_map_type_list *buf_map_list); 793 extern int32_t mm_camera_unmap_stream_buf(mm_camera_obj_t *my_obj, 794 uint32_t ch_id, 795 uint32_t stream_id, 796 uint8_t buf_type, 797 uint32_t buf_idx, 798 int32_t plane_idx); 799 extern int32_t mm_camera_do_stream_action(mm_camera_obj_t *my_obj, 800 uint32_t ch_id, 801 uint32_t stream_id, 802 void *actions); 803 extern int32_t mm_camera_get_session_id(mm_camera_obj_t *my_obj, 804 uint32_t* sessionid); 805 extern int32_t mm_camera_sync_related_sensors(mm_camera_obj_t *my_obj, 806 cam_sync_related_sensors_event_info_t *parms); 807 extern int32_t mm_camera_reg_frame_sync(mm_camera_obj_t *my_obj, 808 uint32_t ch_id, uint32_t stream_id, 809 mm_camera_frame_sync_t *sync_attr); 810 extern int32_t mm_camera_start_frame_sync(mm_camera_obj_t *my_obj, 811 uint32_t ch_id, uint32_t stream_id); 812 extern int32_t mm_camera_stop_frame_sync(mm_camera_obj_t *my_obj, 813 uint32_t ch_id, uint32_t stream_id); 814 extern int32_t mm_camera_switch_stream_cb(mm_camera_obj_t *my_obj, 815 uint32_t ch_id, uint32_t stream_id); 816 817 818 /* mm_channel */ 819 extern int32_t mm_channel_fsm_fn(mm_channel_t *my_obj, 820 mm_channel_evt_type_t evt, 821 void * in_val, 822 void * out_val); 823 extern int32_t mm_channel_init(mm_channel_t *my_obj, 824 mm_camera_channel_attr_t *attr, 825 mm_camera_buf_notify_t channel_cb, 826 void *userdata); 827 /* qbuf is a special case that not going through state machine. 828 * This is to avoid deadlock when trying to aquire ch_lock, 829 * from the context of dataCB, but async stop is holding ch_lock */ 830 extern int32_t mm_channel_qbuf(mm_channel_t *my_obj, 831 mm_camera_buf_def_t *buf); 832 /* mm_stream */ 833 extern int32_t mm_stream_fsm_fn(mm_stream_t *my_obj, 834 mm_stream_evt_type_t evt, 835 void * in_val, 836 void * out_val); 837 /* Function to register special callback for stream buffer*/ 838 extern int32_t mm_stream_reg_buf_cb(mm_stream_t *my_obj, 839 mm_stream_data_cb_t val); 840 extern int32_t mm_stream_map_buf(mm_stream_t *my_obj, 841 uint8_t buf_type, 842 uint32_t frame_idx, 843 int32_t plane_idx, 844 int fd, 845 size_t size, 846 void *buffer); 847 extern int32_t mm_stream_map_bufs(mm_stream_t *my_obj, 848 const cam_buf_map_type_list *buf_map_list); 849 extern int32_t mm_stream_unmap_buf(mm_stream_t *my_obj, 850 uint8_t buf_type, 851 uint32_t frame_idx, 852 int32_t plane_idx); 853 854 /* utiltity fucntion declared in mm-camera-inteface2.c 855 * and need be used by mm-camera and below*/ 856 uint32_t mm_camera_util_generate_handler(uint8_t index); 857 const char *mm_camera_util_get_dev_name(uint32_t cam_handler); 858 uint8_t mm_camera_util_get_index_by_handler(uint32_t handler); 859 860 /* poll/cmd thread functions */ 861 extern int32_t mm_camera_poll_thread_launch( 862 mm_camera_poll_thread_t * poll_cb, 863 mm_camera_poll_thread_type_t poll_type); 864 extern int32_t mm_camera_poll_thread_release(mm_camera_poll_thread_t *poll_cb); 865 extern int32_t mm_camera_poll_thread_add_poll_fd( 866 mm_camera_poll_thread_t * poll_cb, uint8_t idx, uint32_t handler, 867 int32_t fd, mm_camera_poll_notify_t nofity_cb, 868 void *userdata, mm_camera_call_type_t); 869 extern int32_t mm_camera_poll_thread_del_poll_fd( 870 mm_camera_poll_thread_t * poll_cb, uint8_t idx, uint32_t handler, 871 mm_camera_call_type_t); 872 extern int32_t mm_camera_poll_thread_commit_updates( 873 mm_camera_poll_thread_t * poll_cb); 874 extern int32_t mm_camera_cmd_thread_launch( 875 mm_camera_cmd_thread_t * cmd_thread, 876 mm_camera_cmd_cb_t cb, 877 void* user_data); 878 extern int32_t mm_camera_cmd_thread_name(const char* name); 879 extern int32_t mm_camera_cmd_thread_release(mm_camera_cmd_thread_t * cmd_thread); 880 881 extern int32_t mm_camera_channel_advanced_capture(mm_camera_obj_t *my_obj, 882 uint32_t ch_id, mm_camera_advanced_capture_t type, 883 uint32_t trigger, void *in_value); 884 int32_t mm_camera_enqueue_evt(mm_camera_obj_t *my_obj, 885 mm_camera_event_t *event); 886 int32_t mm_camera_load_shim_lib(); 887 cam_shim_packet_t *mm_camera_create_shim_cmd_packet(cam_shim_cmd_type type, 888 uint32_t sessionID, void *data); 889 int32_t mm_camera_destroy_shim_cmd_packet(cam_shim_packet_t *cmd); 890 int32_t mm_camera_module_event_handler( 891 uint32_t session_id, cam_event_t *event); 892 cam_status_t mm_camera_module_open_session(int sessionid, 893 int (*event_cb)(uint32_t sessionid, cam_event_t *event)); 894 int32_t mm_camera_module_close_session(int session); 895 int32_t mm_camera_module_send_cmd(cam_shim_packet_t *event); 896 897 #endif /* __MM_CAMERA_H__ */ 898