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