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_INTERFACE_H__ 31 #define __MM_CAMERA_INTERFACE_H__ 32 33 // System dependencies 34 #include <media/msmb_camera.h> 35 36 // Camera dependencies 37 #include "cam_intf.h" 38 #include "cam_queue.h" 39 40 #define MM_CAMERA_MAX_NUM_SENSORS MSM_MAX_CAMERA_SENSORS 41 #define MM_CAMERA_MAX_NUM_FRAMES CAM_MAX_NUM_BUFS_PER_STREAM 42 43 /* num of channels allowed in a camera obj */ 44 #define MM_CAMERA_CHANNEL_MAX 16 45 46 #define PAD_TO_SIZE(size, padding) \ 47 ((size + (typeof(size))(padding - 1)) & \ 48 (typeof(size))(~(padding - 1))) 49 50 #define CEIL_DIVISION(n, d) ((n+d-1)/d) 51 52 /*Bit shift to reach next camera in camera handle*/ 53 #define MM_CAMERA_HANDLE_SHIFT_MASK 16 54 #define MM_CAMERA_HANDLE_BIT_MASK 0x0000ffff 55 56 typedef enum { 57 MM_CAMERA_TYPE_MAIN = CAM_TYPE_MAIN, 58 MM_CAMERA_TYPE_AUX = CAM_TYPE_AUX, 59 } mm_camera_obj_type; 60 61 #define MM_CAMERA_DUAL_CAM (MM_CAMERA_TYPE_MAIN | MM_CAMERA_TYPE_AUX) 62 #define MM_CAMERA_MAX_CAM_CNT 2 63 64 /** CAM_DUMP_TO_FILE: 65 * @filename: file name 66 * @name:filename 67 * @index: index of the file 68 * @extn: file extension 69 * @p_addr: address of the buffer 70 * @len: buffer length 71 * 72 * dump the image to the file 73 **/ 74 #define CAM_DUMP_TO_FILE(path, name, index, extn, p_addr, len) ({ \ 75 size_t rc = 0; \ 76 char filename[FILENAME_MAX]; \ 77 if (index >= 0) \ 78 snprintf(filename, FILENAME_MAX, "%s/%s%d.%s", path, name, index, extn); \ 79 else \ 80 snprintf(filename, FILENAME_MAX, "%s/%s.%s", path, name, extn); \ 81 FILE *fp = fopen(filename, "w+"); \ 82 if (fp) { \ 83 rc = fwrite(p_addr, 1, len, fp); \ 84 LOGE("written size %d", len); \ 85 fclose(fp); \ 86 } else { \ 87 LOGE("open %s failed", filename); \ 88 } \ 89 }) 90 91 /* Declaring Buffer structure */ 92 struct mm_camera_buf_def; 93 94 /** mm_camera_plane_def_t : structure for frame plane info 95 * @num_planes : num of planes for the frame buffer, to be 96 * filled during mem allocation 97 * @planes : plane info for the frame buffer, to be filled 98 * during mem allocation 99 **/ 100 typedef struct { 101 int8_t num_planes; 102 struct v4l2_plane planes[VIDEO_MAX_PLANES]; 103 } mm_camera_plane_buf_def_t; 104 105 /** mm_camera_user_buf_def_t : structure for frame plane info 106 * @num_buffers : num of buffers in this user defined structure 107 * @bufs_used : actual number of buffer filled 108 * @buf_in_use : flag to notify buffer usage status. 109 * @plane_buf : Plane buffer array pointer. 110 **/ 111 typedef struct { 112 uint8_t num_buffers; 113 uint8_t bufs_used; /*Num of Buffer filled by Kernel*/ 114 uint8_t buf_in_use; /* Container buffer is freed to fill*/ 115 int32_t buf_idx[MSM_CAMERA_MAX_USER_BUFF_CNT]; 116 struct mm_camera_buf_def *plane_buf; 117 } mm_camera_user_buf_def_t; 118 119 /** mm_camera_buf_def_t: structure for stream frame buf 120 * @stream_id : stream handler to uniquely identify a stream 121 * object 122 * @buf_idx : index of the buf within the stream bufs, to be 123 * filled during mem allocation 124 * @timespec_ts : time stamp, to be filled when DQBUF is 125 * called 126 * @frame_idx : frame sequence num, to be filled when DQBUF 127 * @plane_buf : Frame plane definition 128 * @fd : file descriptor of the frame buffer, to be filled 129 * during mem allocation 130 * @buffer : pointer to the frame buffer, to be filled during 131 * mem allocation 132 * @frame_len : length of the whole frame, to be filled during 133 * mem allocation 134 * @mem_info : user specific pointer to additional mem info 135 * @flags: v4l2_buffer flags, used to report error in data buffers 136 * @cache_flags: Stores cache related read/write flags 137 **/ 138 typedef struct mm_camera_buf_def { 139 uint32_t stream_id; 140 cam_stream_type_t stream_type; 141 cam_stream_buf_type buf_type; 142 uint32_t buf_idx; 143 uint8_t is_uv_subsampled; 144 struct timespec ts; 145 uint32_t frame_idx; 146 union { 147 mm_camera_plane_buf_def_t planes_buf; 148 mm_camera_user_buf_def_t user_buf; 149 }; 150 int fd; 151 void *buffer; 152 size_t frame_len; 153 void *mem_info; 154 uint32_t flags; 155 uint32_t cache_flags; 156 } mm_camera_buf_def_t; 157 158 /** mm_camera_super_buf_t: super buf structure for bundled 159 * stream frames 160 * @camera_handle : camera handler to uniquely identify 161 * a camera object 162 * @ch_id : channel handler to uniquely ideentify a channel 163 * object 164 * @num_bufs : number of buffers in the super buf, should not 165 * exceeds MAX_STREAM_NUM_IN_BUNDLE 166 * @bufs : array of buffers in the bundle 167 **/ 168 typedef struct { 169 uint32_t camera_handle; 170 uint32_t ch_id; 171 uint32_t num_bufs; 172 uint8_t bUnlockAEC; 173 uint8_t bReadyForPrepareSnapshot; 174 mm_camera_buf_def_t* bufs[MAX_STREAM_NUM_IN_BUNDLE]; 175 } mm_camera_super_buf_t; 176 177 /** mm_camera_req_buf_type_t 178 * Request type for super buf from channel 179 **/ 180 typedef enum { 181 MM_CAMERA_REQ_SUPER_BUF, 182 MM_CAMERA_REQ_FRAME_SYNC_BUF 183 } mm_camera_req_buf_type_t; 184 185 /** mm_camera_req_buf_t: Attributes for super buf request 186 * 187 * @type : type of super buf requested 188 * @num_buf_requested : num of super bufs requested 189 * @num_retro_buf_requested : number of retro bufs requested 190 * @primary_only : specifies if only primary camera frame for a dual 191 * camera is requested 192 **/ 193 typedef struct { 194 mm_camera_req_buf_type_t type; 195 uint32_t num_buf_requested; 196 uint32_t num_retro_buf_requested; 197 uint8_t cam_num; //Frame from which camera 198 uint32_t frame_idx; //Client can request frameId to pick from ZSL queue 199 } mm_camera_req_buf_t; 200 201 typedef cam_event_t mm_camera_event_t; 202 203 /** mm_camera_event_notify_t: function definition for event 204 * notify handling 205 * @camera_handle : camera handler 206 * @evt : pointer to an event struct 207 * @user_data: user data pointer 208 **/ 209 typedef void (*mm_camera_event_notify_t)(uint32_t camera_handle, 210 mm_camera_event_t *evt, 211 void *user_data); 212 213 /** mm_camera_buf_notify_t: function definition for frame notify 214 * handling 215 * @mm_camera_super_buf_t : received frame buffers 216 * @user_data: user data pointer 217 **/ 218 typedef void (*mm_camera_buf_notify_t) (mm_camera_super_buf_t *bufs, 219 void *user_data); 220 221 /** map_stream_buf_op_t: function definition for operation of 222 * mapping stream buffers via domain socket 223 * @frame_idx : buffer index within stream buffers 224 * @plane_idx : plane index. If all planes share the same 225 * fd, plane_idx = -1; otherwise, plean_idx is 226 * the index to plane (0..num_of_planes) 227 * @fd : file descriptor of the stream buffer 228 * @size: size of the stream buffer 229 * @buffer: Pointer to buffer to register 230 * @userdata : user data pointer 231 **/ 232 typedef int32_t (*map_stream_buf_op_t) (uint32_t frame_idx, 233 int32_t plane_idx, 234 int fd, 235 size_t size, 236 void *buffer, 237 cam_mapping_buf_type type, 238 void *userdata); 239 240 typedef int32_t (*map_stream_bufs_op_t) (const cam_buf_map_type_list *buf_map_list, 241 void *userdata); 242 243 /** unmap_stream_buf_op_t: function definition for operation of 244 * unmapping stream buffers via domain 245 * socket 246 * @frame_idx : buffer index within stream buffers 247 * @plane_idx : plane index. If all planes share the same 248 * fd, plane_idx = -1; otherwise, plean_idx is 249 * the index to plane (0..num_of_planes) 250 * @userdata : user data pointer 251 **/ 252 typedef int32_t (*unmap_stream_buf_op_t) (uint32_t frame_idx, 253 int32_t plane_idx, 254 cam_mapping_buf_type type, 255 void *userdata); 256 257 /** mm_camera_map_unmap_ops_tbl_t: virtual table 258 * for mapping/unmapping stream buffers via 259 * domain socket 260 * @map_ops : operation for mapping 261 * @unmap_ops : operation for unmapping 262 * @userdata: user data pointer 263 **/ 264 typedef struct { 265 map_stream_buf_op_t map_ops; 266 map_stream_bufs_op_t bundled_map_ops; 267 unmap_stream_buf_op_t unmap_ops; 268 void *userdata; 269 } mm_camera_map_unmap_ops_tbl_t; 270 271 /** mm_camera_stream_mem_vtbl_t: virtual table for stream 272 * memory allocation and deallocation 273 * @get_bufs : function definition for allocating 274 * stream buffers 275 * @put_bufs : function definition for deallocating 276 * stream buffers 277 * @user_data: user data pointer 278 **/ 279 typedef struct { 280 void *user_data; 281 int32_t (*set_config_ops) (mm_camera_map_unmap_ops_tbl_t *ops_tbl, 282 void *user_data); 283 int32_t (*get_bufs) (cam_frame_len_offset_t *offset, 284 uint8_t *num_bufs, 285 uint8_t **initial_reg_flag, 286 mm_camera_buf_def_t **bufs, 287 mm_camera_map_unmap_ops_tbl_t *ops_tbl, 288 void *user_data); 289 int32_t (*put_bufs) (mm_camera_map_unmap_ops_tbl_t *ops_tbl, 290 void *user_data); 291 int32_t (*invalidate_buf)(uint32_t index, void *user_data); 292 int32_t (*clean_invalidate_buf)(uint32_t index, void *user_data); 293 int32_t (*clean_buf)(uint32_t index, void *user_data); 294 } mm_camera_stream_mem_vtbl_t; 295 296 /** mm_camera_stream_config_t: structure for stream 297 * configuration 298 * @stream_info : pointer to a stream info structure 299 * @padding_info: padding info obtained from querycapability 300 * @mem_tbl : memory operation table for 301 * allocating/deallocating stream buffers 302 * @stream_cb_sync : SYNC callback handling stream frame notify 303 * @stream_cb : ASYNC callback handling stream frame notify 304 * @userdata : user data pointer 305 **/ 306 typedef struct { 307 cam_stream_info_t *stream_info; 308 cam_padding_info_t padding_info; 309 mm_camera_stream_mem_vtbl_t mem_vtbl; 310 mm_camera_buf_notify_t stream_cb_sync; 311 mm_camera_buf_notify_t stream_cb; 312 void *userdata; 313 } mm_camera_stream_config_t; 314 315 /** mm_camera_super_buf_notify_mode_t: enum for super uffer 316 * notification mode 317 * @MM_CAMERA_SUPER_BUF_NOTIFY_BURST : 318 * ZSL use case: get burst of frames 319 * @MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS : 320 * get continuous frames: when the super buf is ready 321 * dispatch it to HAL 322 **/ 323 typedef enum { 324 MM_CAMERA_SUPER_BUF_NOTIFY_BURST = 0, 325 MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS, 326 MM_CAMERA_SUPER_BUF_NOTIFY_MAX 327 } mm_camera_super_buf_notify_mode_t; 328 329 /** mm_camera_super_buf_priority_t: enum for super buffer 330 * matching priority 331 * @MM_CAMERA_SUPER_BUF_PRIORITY_NORMAL : 332 * Save the frame no matter focused or not. Currently only 333 * this type is supported. 334 * @MM_CAMERA_SUPER_BUF_PRIORITY_FOCUS : 335 * only queue the frame that is focused. Will enable meta 336 * data header to carry focus info 337 * @MM_CAMERA_SUPER_BUF_PRIORITY_EXPOSURE_BRACKETING : 338 * after shutter, only queue matched exposure index 339 **/ 340 typedef enum { 341 MM_CAMERA_SUPER_BUF_PRIORITY_NORMAL = 0, 342 MM_CAMERA_SUPER_BUF_PRIORITY_FOCUS, 343 MM_CAMERA_SUPER_BUF_PRIORITY_EXPOSURE_BRACKETING, 344 MM_CAMERA_SUPER_BUF_PRIORITY_LOW,/* Bundled metadata frame may not match*/ 345 MM_CAMERA_SUPER_BUF_PRIORITY_MAX 346 } mm_camera_super_buf_priority_t; 347 348 /** mm_camera_advanced_capture_t: enum for advanced capture type. 349 * @MM_CAMERA_AF_BRACKETING : 350 * to enable AF Bracketig. 351 * @MM_CAMERA_AE_BRACKETING : 352 * to enable AF Bracketing. 353 * @MM_CAMERA_FLASH_BRACKETING : 354 * to enable Flash Bracketing. 355 * @MM_CAMERA_ZOOM_1X : 356 * to enable zoom 1x capture request 357 **/ 358 typedef enum { 359 MM_CAMERA_AF_BRACKETING = 0, 360 MM_CAMERA_AE_BRACKETING, 361 MM_CAMERA_FLASH_BRACKETING, 362 MM_CAMERA_ZOOM_1X, 363 MM_CAMERA_FRAME_CAPTURE, 364 } mm_camera_advanced_capture_t; 365 366 /** mm_camera_stream_cb_type: enum for stream buffer callback type. 367 * @MM_CAMERA_STREAM_CB_TYPE_ASYNC : 368 * callback is async type. buffer process done in client thread context 369 * @MM_CAMERA_STREAM_CB_TYPE_SYNC : 370 * callback is sync type. buffer process done interface thread context 371 **/ 372 typedef enum { 373 MM_CAMERA_STREAM_CB_TYPE_ASYNC, 374 MM_CAMERA_STREAM_CB_TYPE_SYNC, 375 } mm_camera_stream_cb_type; 376 377 378 /** mm_camera_channel_attr_t: structure for defining channel 379 * attributes 380 * @notify_mode : notify mode: burst or continuous 381 * @water_mark : queue depth. Only valid for burst mode 382 * @look_back : look back how many frames from last buf. 383 * Only valid for burst mode 384 * @post_frame_skip : after send first frame to HAL, how many 385 * frames needing to be skipped for next 386 * delivery. Only valid for burst mode 387 * @max_unmatched_frames : max number of unmatched frames in 388 * queue 389 * @enable_frame_sync: Enables frame sync for dual camera 390 * @priority : save matched priority frames only 391 * @user_expected_frame_id : Number of frames, camera interface 392 * will wait for getting the instant capture frame. 393 **/ 394 typedef struct { 395 mm_camera_super_buf_notify_mode_t notify_mode; 396 uint8_t water_mark; 397 uint8_t look_back; 398 uint8_t post_frame_skip; 399 uint8_t max_unmatched_frames; 400 uint8_t enable_frame_sync; 401 mm_camera_super_buf_priority_t priority; 402 uint8_t user_expected_frame_id; 403 } mm_camera_channel_attr_t; 404 405 /** mm_camera_cb_req_type: Callback request type**/ 406 typedef enum { 407 MM_CAMERA_CB_REQ_TYPE_DEFAULT, 408 MM_CAMERA_CB_REQ_TYPE_SWITCH, 409 MM_CAMERA_CB_REQ_TYPE_FRAME_SYNC, 410 MM_CAMERA_CB_REQ_TYPE_ALL_CB, 411 } mm_camera_cb_req_type; 412 413 /** mm_camera_intf_cb_req_type: structure to request different mode of stream callback 414 * @camera_handle : camera handle to be syced 415 * @ch_id : channel id to be synced 416 * @stream_id : stream id to be synced 417 * @max_unmatched_frames : Frames to wait for before frame callback 418 * @buf_cb : callback. can be NULL. NULL uses already registered stream/channel cb 419 * @userdata : client objects. 420 **/ 421 typedef struct { 422 uint32_t camera_handle; 423 uint32_t ch_id; 424 uint32_t stream_id; 425 mm_camera_channel_attr_t attr; 426 mm_camera_buf_notify_t buf_cb; 427 void *userdata; 428 } mm_camera_intf_frame_sync_t; 429 430 typedef struct { 431 /** query_capability: fucntion definition for querying static 432 * camera capabilities 433 * @camera_handle : camer handler 434 * Return value: 0 -- success 435 * -1 -- failure 436 * Note: would assume cam_capability_t is already mapped 437 **/ 438 int32_t (*query_capability) (uint32_t camera_handle); 439 440 /** register_event_notify: fucntion definition for registering 441 * for event notification 442 * @camera_handle : camer handler 443 * @evt_cb : callback for event notify 444 * @user_data : user data poiner 445 * Return value: 0 -- success 446 * -1 -- failure 447 **/ 448 int32_t (*register_event_notify) (uint32_t camera_handle, 449 mm_camera_event_notify_t evt_cb, 450 void *user_data); 451 452 /** close_camera: fucntion definition for closing a camera 453 * @camera_handle : camer handler 454 * Return value: 0 -- success 455 * -1 -- failure 456 **/ 457 int32_t (*close_camera) (uint32_t camera_handle); 458 459 /** map_buf: fucntion definition for mapping a camera buffer 460 * via domain socket 461 * @camera_handle : camer handler 462 * @buf_type : type of mapping buffers, can be value of 463 * CAM_MAPPING_BUF_TYPE_CAPABILITY 464 * CAM_MAPPING_BUF_TYPE_SETPARM_BUF 465 * CAM_MAPPING_BUF_TYPE_GETPARM_BUF 466 * @fd : file descriptor of the stream buffer 467 * @size : size of the stream buffer 468 * Return value: 0 -- success 469 * -1 -- failure 470 **/ 471 int32_t (*map_buf) (uint32_t camera_handle, 472 uint8_t buf_type, 473 int fd, 474 size_t size, 475 void *buffer); 476 477 /** map_bufs: function definition for mapping multiple camera buffers 478 * via domain socket 479 * @camera_handle : camera handler 480 * @buf_map_list : list of buffers to map 481 * Return value: 0 -- success 482 * -1 -- failure 483 **/ 484 int32_t (*map_bufs) (uint32_t camera_handle, 485 const cam_buf_map_type_list *buf_map_list); 486 487 /** unmap_buf: fucntion definition for unmapping a camera buffer 488 * via domain socket 489 * @camera_handle : camer handler 490 * @buf_type : type of mapping buffers, can be value of 491 * CAM_MAPPING_BUF_TYPE_CAPABILITY 492 * CAM_MAPPING_BUF_TYPE_SETPARM_BUF 493 * CAM_MAPPING_BUF_TYPE_GETPARM_BUF 494 * Return value: 0 -- success 495 * -1 -- failure 496 **/ 497 int32_t (*unmap_buf) (uint32_t camera_handle, 498 uint8_t buf_type); 499 500 /** set_parms: fucntion definition for setting camera 501 * based parameters to server 502 * @camera_handle : camer handler 503 * @parms : batch for parameters to be set, stored in 504 * parm_buffer_t 505 * Return value: 0 -- success 506 * -1 -- failure 507 * Note: would assume parm_buffer_t is already mapped, and 508 * according parameter entries to be set are filled in the 509 * buf before this call 510 **/ 511 int32_t (*set_parms) (uint32_t camera_handle, 512 parm_buffer_t *parms); 513 514 /** get_parms: fucntion definition for querying camera 515 * based parameters from server 516 * @camera_handle : camer handler 517 * @parms : batch for parameters to be queried, stored in 518 * parm_buffer_t 519 * Return value: 0 -- success 520 * -1 -- failure 521 * Note: would assume parm_buffer_t is already mapped, and 522 * according parameter entries to be queried are filled in 523 * the buf before this call 524 **/ 525 int32_t (*get_parms) (uint32_t camera_handle, 526 parm_buffer_t *parms); 527 528 /** do_auto_focus: fucntion definition for performing auto focus 529 * @camera_handle : camer handler 530 * Return value: 0 -- success 531 * -1 -- failure 532 * Note: if this call success, we will always assume there will 533 * be an auto_focus event following up. 534 **/ 535 int32_t (*do_auto_focus) (uint32_t camera_handle); 536 537 /** cancel_auto_focus: fucntion definition for cancelling 538 * previous auto focus request 539 * @camera_handle : camer handler 540 * Return value: 0 -- success 541 * -1 -- failure 542 **/ 543 int32_t (*cancel_auto_focus) (uint32_t camera_handle); 544 545 /** prepare_snapshot: fucntion definition for preparing hardware 546 * for snapshot. 547 * @camera_handle : camer handler 548 * @do_af_flag : flag indicating if AF needs to be done 549 * 0 -- no AF needed 550 * 1 -- AF needed 551 * Return value: 0 -- success 552 * -1 -- failure 553 **/ 554 int32_t (*prepare_snapshot) (uint32_t camera_handle, 555 int32_t do_af_flag); 556 557 /** start_zsl_snapshot: function definition for starting 558 * zsl snapshot. 559 * @camera_handle : camer handler 560 * @ch_id : channel id 561 * Return value: 0 -- success 562 * -1 -- failure 563 **/ 564 int32_t (*start_zsl_snapshot) (uint32_t camera_handle, uint32_t ch_id); 565 566 /** stop_zsl_snapshot: function definition for stopping 567 * zsl snapshot. 568 * @camera_handle : camer handler 569 * @ch_id : channel id 570 * Return value: 0 -- success 571 * -1 -- failure 572 **/ 573 int32_t (*stop_zsl_snapshot) (uint32_t camera_handle, uint32_t ch_id); 574 575 /** add_channel: fucntion definition for adding a channel 576 * @camera_handle : camer handler 577 * @ch_id : channel handler 578 * @attr : pointer to channel attribute structure 579 * @channel_cb : callbak to handle bundled super buffer 580 * @userdata : user data pointer 581 * Return value: channel id, zero is invalid ch_id 582 * Note: attr, channel_cb, and userdata can be NULL if no 583 * superbufCB is needed 584 **/ 585 uint32_t (*add_channel) (uint32_t camera_handle, 586 mm_camera_channel_attr_t *attr, 587 mm_camera_buf_notify_t channel_cb, 588 void *userdata); 589 590 /** delete_channel: fucntion definition for deleting a channel 591 * @camera_handle : camer handler 592 * @ch_id : channel handler 593 * Return value: 0 -- success 594 * -1 -- failure 595 **/ 596 int32_t (*delete_channel) (uint32_t camera_handle, 597 uint32_t ch_id); 598 599 /** get_bundle_info: function definition for querying bundle 600 * info of the channel 601 * @camera_handle : camera handler 602 * @ch_id : channel handler 603 * @bundle_info : bundle info to be filled in 604 * Return value: 0 -- success 605 * -1 -- failure 606 **/ 607 int32_t (*get_bundle_info) (uint32_t camera_handle, 608 uint32_t ch_id, 609 cam_bundle_config_t *bundle_info); 610 611 /** add_stream: fucntion definition for adding a stream 612 * @camera_handle : camer handler 613 * @ch_id : channel handler 614 * Return value: stream_id. zero is invalid stream_id 615 **/ 616 uint32_t (*add_stream) (uint32_t camera_handle, 617 uint32_t ch_id); 618 619 /** delete_stream: fucntion definition for deleting a stream 620 * @camera_handle : camer handler 621 * @ch_id : channel handler 622 * @stream_id : stream handler 623 * Return value: 0 -- success 624 * -1 -- failure 625 **/ 626 int32_t (*delete_stream) (uint32_t camera_handle, 627 uint32_t ch_id, 628 uint32_t stream_id); 629 630 /** link_stream: function definition for linking a stream 631 * @camera_handle : camera handle 632 * @ch_id : channel handle from which the stream originates 633 * @stream_id : stream handle 634 * @linked_ch_id: channel handle in which the stream will be linked 635 * Return value: 0 -- success 636 * -1 -- failure 637 **/ 638 int32_t (*link_stream) (uint32_t camera_handle, 639 uint32_t ch_id, 640 uint32_t stream_id, 641 uint32_t linked_ch_id); 642 643 /** config_stream: fucntion definition for configuring a stream 644 * @camera_handle : camer handler 645 * @ch_id : channel handler 646 * @stream_id : stream handler 647 * @confid : pointer to a stream configuration structure 648 * Return value: 0 -- success 649 * -1 -- failure 650 **/ 651 int32_t (*config_stream) (uint32_t camera_handle, 652 uint32_t ch_id, 653 uint32_t stream_id, 654 mm_camera_stream_config_t *config); 655 656 /** map_stream_buf: fucntion definition for mapping 657 * stream buffer via domain socket 658 * @camera_handle : camer handler 659 * @ch_id : channel handler 660 * @stream_id : stream handler 661 * @buf_type : type of mapping buffers, can be value of 662 * CAM_MAPPING_BUF_TYPE_STREAM_BUF 663 * CAM_MAPPING_BUF_TYPE_STREAM_INFO 664 * CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF 665 * @buf_idx : buffer index within the stream buffers 666 * @plane_idx : plane index. If all planes share the same fd, 667 * plane_idx = -1; otherwise, plean_idx is the 668 * index to plane (0..num_of_planes) 669 * @fd : file descriptor of the stream buffer 670 * @size : size of the stream buffer 671 * Return value: 0 -- success 672 * -1 -- failure 673 **/ 674 int32_t (*map_stream_buf) (uint32_t camera_handle, 675 uint32_t ch_id, 676 uint32_t stream_id, 677 uint8_t buf_type, 678 uint32_t buf_idx, 679 int32_t plane_idx, 680 int fd, 681 size_t size, 682 void *buffer); 683 684 /** map_stream_bufs: function definition for mapping multiple 685 * stream buffers via domain socket 686 * @camera_handle : camera handler 687 * @ch_id : channel handler 688 * @buf_map_list : list of buffers to map 689 * Return value: 0 -- success 690 * -1 -- failure 691 **/ 692 int32_t (*map_stream_bufs) (uint32_t camera_handle, 693 uint32_t ch_id, 694 const cam_buf_map_type_list *buf_map_list); 695 696 /** unmap_stream_buf: fucntion definition for unmapping 697 * stream buffer via domain socket 698 * @camera_handle : camer handler 699 * @ch_id : channel handler 700 * @stream_id : stream handler 701 * @buf_type : type of mapping buffers, can be value of 702 * CAM_MAPPING_BUF_TYPE_STREAM_BUF 703 * CAM_MAPPING_BUF_TYPE_STREAM_INFO 704 * CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF 705 * @buf_idx : buffer index within the stream buffers 706 * @plane_idx : plane index. If all planes share the same fd, 707 * plane_idx = -1; otherwise, plean_idx is the 708 * index to plane (0..num_of_planes) 709 * Return value: 0 -- success 710 * -1 -- failure 711 **/ 712 int32_t (*unmap_stream_buf) (uint32_t camera_handle, 713 uint32_t ch_id, 714 uint32_t stream_id, 715 uint8_t buf_type, 716 uint32_t buf_idx, 717 int32_t plane_idx); 718 719 /** set_stream_parms: fucntion definition for setting stream 720 * specific parameters to server 721 * @camera_handle : camer handler 722 * @ch_id : channel handler 723 * @stream_id : stream handler 724 * @parms : batch for parameters to be set 725 * Return value: 0 -- success 726 * -1 -- failure 727 * Note: would assume parm buffer is already mapped, and 728 * according parameter entries to be set are filled in the 729 * buf before this call 730 **/ 731 int32_t (*set_stream_parms) (uint32_t camera_handle, 732 uint32_t ch_id, 733 uint32_t s_id, 734 cam_stream_parm_buffer_t *parms); 735 736 /** get_stream_parms: fucntion definition for querying stream 737 * specific parameters from server 738 * @camera_handle : camer handler 739 * @ch_id : channel handler 740 * @stream_id : stream handler 741 * @parms : batch for parameters to be queried 742 * Return value: 0 -- success 743 * -1 -- failure 744 * Note: would assume parm buffer is already mapped, and 745 * according parameter entries to be queried are filled in 746 * the buf before this call 747 **/ 748 int32_t (*get_stream_parms) (uint32_t camera_handle, 749 uint32_t ch_id, 750 uint32_t s_id, 751 cam_stream_parm_buffer_t *parms); 752 753 /** start_channel: fucntion definition for starting a channel 754 * @camera_handle : camer handler 755 * @ch_id : channel handler 756 * Return value: 0 -- success 757 * -1 -- failure 758 * This call will start all streams belongs to the channel 759 **/ 760 int32_t (*start_channel) (uint32_t camera_handle, 761 uint32_t ch_id); 762 763 /** stop_channel: fucntion definition for stopping a channel 764 * @camera_handle : camer handler 765 * @ch_id : channel handler 766 * Return value: 0 -- success 767 * -1 -- failure 768 * This call will stop all streams belongs to the channel 769 **/ 770 int32_t (*stop_channel) (uint32_t camera_handle, 771 uint32_t ch_id); 772 773 /** qbuf: fucntion definition for queuing a frame buffer back to 774 * kernel for reuse 775 * @camera_handle : camer handler 776 * @ch_id : channel handler 777 * @buf : a frame buffer to be queued back to kernel 778 * Return value: 0 -- success 779 * -1 -- failure 780 **/ 781 int32_t (*qbuf) (uint32_t camera_handle, 782 uint32_t ch_id, 783 mm_camera_buf_def_t *buf); 784 785 /** cancel_buffer: fucntion definition for recalling a frame 786 * buffer from the kernel this is most likely when h/w 787 * failed to use this buffer and dropped the frame we use 788 * this API to recall the buffer and return it to the 789 * framework 790 * @camera_handle : camer handler 791 * @ch_id : channel handler 792 * @stream_id : stream handle 793 * @buf : a frame buffer to be queued back to kernel 794 * Return value: 0 -- success 795 * -1 -- failure 796 **/ 797 int32_t (*cancel_buffer) (uint32_t camera_handle, 798 uint32_t ch_id, 799 uint32_t stream_id, 800 uint32_t buf_idx); 801 802 803 /** get_queued_buf_count: fucntion definition for querying queued buf count 804 * @camera_handle : camer handler 805 * @ch_id : channel handler 806 * @stream_id : stream handler 807 * Return value: queued buf count 808 **/ 809 int32_t (*get_queued_buf_count) (uint32_t camera_handle, 810 uint32_t ch_id, 811 uint32_t stream_id); 812 813 /** request_super_buf: fucntion definition for requesting frames 814 * from superbuf queue in burst mode 815 * @camera_handle : camer handler 816 * @ch_id : channel handler 817 * @buf : provides info related to the super buf request 818 * Return value: 0 -- success 819 * -1 -- failure 820 **/ 821 int32_t (*request_super_buf) (uint32_t camera_handle, 822 uint32_t ch_id, 823 mm_camera_req_buf_t *buf); 824 825 /** cancel_super_buf_request: fucntion definition for canceling 826 * frames dispatched from superbuf queue in 827 * burst mode 828 * @camera_handle : camer handler 829 * @ch_id : channel handler 830 * Return value: 0 -- success 831 * -1 -- failure 832 **/ 833 int32_t (*cancel_super_buf_request) (uint32_t camera_handle, 834 uint32_t ch_id); 835 836 /** flush_super_buf_queue: function definition for flushing out 837 * all frames in the superbuf queue up to frame_idx, 838 * even if frames with frame_idx come in later than 839 * this call. 840 * @camera_handle : camer handler 841 * @ch_id : channel handler 842 * @frame_idx : frame index up until which all superbufs are flushed 843 * Return value: 0 -- success 844 * -1 -- failure 845 **/ 846 int32_t (*flush_super_buf_queue) (uint32_t camera_handle, 847 uint32_t ch_id, uint32_t frame_idx); 848 849 /** configure_notify_mode: function definition for configuring the 850 * notification mode of channel 851 * @camera_handle : camera handler 852 * @ch_id : channel handler 853 * @notify_mode : notification mode 854 * Return value: 0 -- success 855 * -1 -- failure 856 **/ 857 int32_t (*configure_notify_mode) (uint32_t camera_handle, 858 uint32_t ch_id, 859 mm_camera_super_buf_notify_mode_t notify_mode); 860 861 /** process_advanced_capture: function definition for start/stop advanced capture 862 * for snapshot. 863 * @camera_handle : camera handle 864 * @ch_id : channel handler 865 * @type : advanced capture type. 866 * @trigger : flag indicating if advanced capture needs to be done 867 * 0 -- stop advanced capture 868 * 1 -- start advanced capture 869 * @in_value: Input value. Configaration 870 * Return value: 0 -- success 871 * -1 -- failure 872 **/ 873 int32_t (*process_advanced_capture) (uint32_t camera_handle, 874 uint32_t ch_id, mm_camera_advanced_capture_t type, 875 int8_t start_flag, void *in_value); 876 877 /** get_session_id: gets the backend session id from the kernel 878 * @camera_handle : camera handle 879 * @sessionid : session id to be retrieved 880 * Return value: 0 -- success 881 * -1 -- failure 882 * Note: if this call succeeds, we will get a valid session id 883 **/ 884 int32_t (*get_session_id) (uint32_t camera_handle, 885 uint32_t* sessionid); 886 887 /** set_dual_cam_cmd: sends sync cmd 888 * @camera_handle : camera handle 889 * Return value: 0 -- success 890 * -1 -- failure 891 * Note: if this call succeeds, we will get linking established in back end 892 **/ 893 int32_t (*set_dual_cam_cmd)(uint32_t camera_handle); 894 /** flush: function definition for flush 895 * @camera_handle: camera handler 896 * Return value: 0 -- success 897 * -1 -- failure 898 **/ 899 int32_t (*flush) (uint32_t camera_handle); 900 901 /** register_stream_buf_cb: fucntion definition for registering special stream callbacks 902 * @camera_handle : camer handler 903 * @ch_id : channel handler 904 * @stream_id : stream handler 905 * @buf_cb : callback function pointer 906 * @cb_type : Callback type SYNC/ASYNC 907 * @userdata : user data pointer 908 * Return value: 0 -- success 909 * - 1 -- failure 910 **/ 911 int32_t (*register_stream_buf_cb) (uint32_t camera_handle, 912 uint32_t ch_id, uint32_t stream_id, mm_camera_buf_notify_t buf_cb, 913 mm_camera_stream_cb_type cb_type, void *userdata); 914 915 /** register_stream_frame_sync: fucntion definition for registering frame sync 916 * @camera_handle : camer handler 917 * @ch_id : channel handler 918 * @stream_id : stream handler. Can be 0 to config only channel callback sync 919 * @sync_attr : pointer to a stream sync configuration structure 920 * Return value: 0 -- success 921 * -1 -- failure 922 **/ 923 int32_t (*register_frame_sync) (uint32_t camera_handle, 924 uint32_t ch_id, uint32_t stream_id, 925 mm_camera_intf_frame_sync_t *sync_attr); 926 927 /** handle_frame_sync_cb: function to handle frame sync 928 * @camera_handle : camer handler 929 * @ch_id : channel handler 930 * @stream_id : stream handler 931 * @req_type : Frame sync request type 932 * Return value: 0 -- success 933 * -1 -- failure 934 **/ 935 int32_t (*handle_frame_sync_cb) (uint32_t camera_handle, 936 uint32_t ch_id, uint32_t stream_id, 937 mm_camera_cb_req_type req_type); 938 } mm_camera_ops_t; 939 940 /** mm_camera_vtbl_t: virtual table for camera operations 941 * @camera_handle : camera handler which uniquely identifies a 942 * camera object 943 * @ops : API call table 944 **/ 945 typedef struct { 946 uint32_t camera_handle; 947 mm_camera_ops_t *ops; 948 } mm_camera_vtbl_t; 949 950 /* return number of cameras */ 951 uint8_t get_num_of_cameras(); 952 953 /* return reference pointer of camera vtbl */ 954 int32_t camera_open(uint8_t camera_idx, mm_camera_vtbl_t **camera_obj); 955 956 /* helper functions */ 957 int32_t mm_stream_calc_offset_preview(cam_stream_info_t *stream_info, 958 cam_dimension_t *dim, 959 cam_padding_info_t *padding, 960 cam_stream_buf_plane_info_t *buf_planes); 961 962 int32_t mm_stream_calc_offset_post_view(cam_stream_info_t *stream_info, 963 cam_dimension_t *dim, 964 cam_padding_info_t *padding, 965 cam_stream_buf_plane_info_t *buf_planes); 966 967 int32_t mm_stream_calc_offset_snapshot(cam_format_t fmt, 968 cam_dimension_t *dim, 969 cam_padding_info_t *padding, 970 cam_stream_buf_plane_info_t *buf_planes); 971 972 int32_t mm_stream_calc_offset_raw(cam_format_t fmt, 973 cam_dimension_t *dim, 974 cam_padding_info_t *padding, 975 cam_stream_buf_plane_info_t *buf_planes); 976 977 int32_t mm_stream_calc_offset_video(cam_format_t fmt, 978 cam_dimension_t *dim, 979 cam_stream_buf_plane_info_t *buf_planes); 980 981 int32_t mm_stream_calc_offset_metadata(cam_dimension_t *dim, 982 cam_padding_info_t *padding, 983 cam_stream_buf_plane_info_t *buf_planes); 984 985 int32_t mm_stream_calc_offset_postproc(cam_stream_info_t *stream_info, 986 cam_padding_info_t *padding, 987 cam_stream_buf_plane_info_t *buf_planes); 988 989 int32_t mm_stream_calc_offset_analysis(cam_format_t fmt, 990 cam_dimension_t *dim, 991 cam_padding_info_t *padding, 992 cam_stream_buf_plane_info_t *buf_planes); 993 994 uint32_t mm_stream_calc_lcm (int32_t num1, int32_t num2); 995 struct camera_info *get_cam_info(uint32_t camera_id, cam_sync_type_t *pCamType); 996 997 uint8_t is_yuv_sensor(uint32_t camera_id); 998 999 /*Dual camera related utility functions*/ 1000 1001 /*Query if it is dual camera mode based on the camera index*/ 1002 uint8_t is_dual_camera_by_idx(uint32_t camera_id); 1003 1004 /*Query if it is dual camera mode based on the camera/channel/stream handles*/ 1005 uint8_t is_dual_camera_by_handle(uint32_t handle); 1006 1007 /*Get Primary camera handle for camera/channel/stream*/ 1008 uint32_t get_main_camera_handle(uint32_t handle); 1009 1010 /*Get Auxilary camera handle for camera/channel/stream*/ 1011 uint32_t get_aux_camera_handle(uint32_t handle); 1012 1013 /*Validate 2 handle if it is belong to same instance of camera/channel/stream*/ 1014 uint8_t validate_handle(uint32_t src_handle, uint32_t handle); 1015 #endif /*__MM_CAMERA_INTERFACE_H__*/ 1016