1 /* 2 Copyright (c) 2011-2012,2015, The Linux Foundation. All rights reserved. 3 4 Redistribution and use in source and binary forms, with or without 5 modification, are permitted provided that the following conditions are 6 met: 7 * Redistributions of source code must retain the above copyright 8 notice, this list of conditions and the following disclaimer. 9 * Redistributions in binary form must reproduce the above 10 copyright notice, this list of conditions and the following 11 disclaimer in the documentation and/or other materials provided 12 with the distribution. 13 * Neither the name of The Linux Foundation nor the names of its 14 contributors may be used to endorse or promote products derived 15 from this software without specific prior written permission. 16 17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #ifndef __MM_CAMERA_INTERFACE2_H__ 31 #define __MM_CAMERA_INTERFACE2_H__ 32 #include <linux/msm_ion.h> 33 #include <linux/videodev2.h> 34 #include <media/msm_camera.h> 35 #include "QCamera_Intf.h" 36 #include "mm_omx_jpeg_encoder.h" 37 38 #define MM_CAMERA_MAX_NUM_FRAMES 16 39 40 typedef struct { 41 int num; 42 uint32_t frame_len; 43 struct msm_frame frame[MM_CAMERA_MAX_NUM_FRAMES]; 44 } mm_cameara_stream_buf_t; 45 46 typedef struct { 47 int32_t width; 48 int32_t height; 49 }mm_camera_dimension_t; 50 51 typedef enum { 52 MM_CAMERA_OK, 53 MM_CAMERA_E_GENERAL, 54 MM_CAMERA_E_NO_MEMORY, 55 MM_CAMERA_E_NOT_SUPPORTED, 56 MM_CAMERA_E_INVALID_INPUT, 57 MM_CAMERA_E_INVALID_OPERATION, /* 5 */ 58 MM_CAMERA_E_ENCODE, 59 MM_CAMERA_E_BUFFER_REG, 60 MM_CAMERA_E_PMEM_ALLOC, 61 MM_CAMERA_E_CAPTURE_FAILED, 62 MM_CAMERA_E_CAPTURE_TIMEOUT, /* 10 */ 63 }mm_camera_status_type_t; 64 65 typedef enum { 66 MM_CAMERA_OP_MODE_NOTUSED, 67 MM_CAMERA_OP_MODE_CAPTURE, 68 MM_CAMERA_OP_MODE_VIDEO, 69 MM_CAMERA_OP_MODE_ZSL, 70 MM_CAMERA_OP_MODE_MAX 71 }mm_camera_op_mode_type_t; 72 73 #define MM_CAMERA_PARM_SUPPORT_SET 0x01 74 #define MM_CAMERA_PARM_SUPPORT_GET 0x02 75 #define MM_CAMERA_PARM_SUPPORT_BOTH 0x03 76 77 typedef struct { 78 int32_t left; 79 int32_t top; 80 int32_t width; 81 int32_t height; 82 } mm_camera_rect_t; 83 84 typedef enum { 85 WHITE_BALANCE_AUTO = 1, 86 WHITE_BALANCE_INCANDESCENT = 3, 87 WHITE_BALANCE_FLUORESCENT = 4, 88 WHITE_BALANCE_DAYLIGHT = 5, 89 WHITE_BALANCE_CLOUDY = 6, 90 WHITE_BALANCE_OFF = 9, 91 } White_Balance_modes; 92 93 typedef enum { 94 MM_CAMERA_CH_PREVIEW, 95 MM_CAMERA_CH_VIDEO, 96 MM_CAMERA_CH_SNAPSHOT, 97 MM_CAMERA_CH_RAW, 98 MM_CAMERA_CH_MAX 99 } mm_camera_channel_type_t; 100 101 typedef enum { 102 MM_CAMERA_WHITE_BALANCE_AUTO = 1, 103 MM_CAMERA_WHITE_BALANCE_OFF = 2, 104 MM_CAMERA_WHITE_BALANCE_DAYLIGHT = 3, 105 MM_CAMERA_WHITE_BALANCE_INCANDESCENT = 4, 106 MM_CAMERA_WHITE_BALANCE_FLUORESCENT = 5, 107 } mm_camera_white_balance_mode_type_t; 108 /* MM_CAMERA_PARM_RAW_IMAGE_FMT */ 109 typedef struct { 110 cam_format_t fmt; 111 mm_camera_dimension_t dim; 112 } mm_camera_image_fmt_t; 113 114 typedef struct { 115 mm_camera_image_fmt_t main; 116 mm_camera_image_fmt_t thumbnail; 117 } mm_camera_ch_image_fmt_snapshot_t; 118 119 typedef enum { 120 MM_CAMERA_RAW_STREAMING_CAPTURE_SINGLE, 121 MM_CAMERA_RAW_STREAMING_MAX 122 } mm_camera_raw_streaming_type_t; 123 124 typedef struct { 125 mm_camera_image_fmt_t main; 126 mm_camera_image_fmt_t video; 127 } mm_camera_ch_image_fmt_video_t; 128 129 typedef struct { 130 mm_camera_channel_type_t ch_type; 131 union { 132 mm_camera_image_fmt_t def; 133 mm_camera_ch_image_fmt_snapshot_t snapshot; 134 mm_camera_ch_image_fmt_video_t video; 135 }; 136 } mm_camera_ch_image_fmt_parm_t; 137 typedef struct { 138 mm_camera_rect_t main_crop; 139 mm_camera_rect_t thumbnail_crop; 140 } mm_camera_crop_snapshot_t; 141 142 typedef struct { 143 mm_camera_channel_type_t ch_type; 144 union { 145 mm_camera_rect_t crop; 146 mm_camera_crop_snapshot_t snapshot; 147 }; 148 } mm_camera_ch_crop_t; 149 150 typedef struct { 151 uint8_t name[32]; 152 int32_t min_value; 153 int32_t max_value; 154 int32_t step; 155 int32_t default_value; 156 } mm_camera_ctrl_cap_sharpness_t; 157 158 typedef struct { 159 int16_t *zoom_ratio_tbl; 160 int32_t size; 161 } mm_camera_zoom_tbl_t; 162 163 #define MM_CAMERA_MAX_FRAME_NUM 16 164 165 typedef struct { 166 uint32_t *frame_offset; 167 struct msm_frame *frame; 168 } mm_camera_sp_buf_t; 169 170 typedef struct { 171 int8_t num_planes; 172 struct v4l2_plane planes[VIDEO_MAX_PLANES]; 173 uint32_t frame_offset; 174 struct msm_frame frame; 175 int idx; /* index to stream frame */ 176 } mm_camera_mp_buf_t; 177 178 typedef struct { 179 int8_t num; 180 int8_t no_enqueue_flag[MM_CAMERA_MAX_NUM_FRAMES]; 181 union { 182 mm_camera_sp_buf_t sp; 183 mm_camera_mp_buf_t *mp; 184 }buf; 185 } mm_camera_buf_def_t; 186 187 typedef struct { 188 mm_camera_buf_def_t thumbnail; 189 mm_camera_buf_def_t main; 190 } mm_camera_buf_snapshot_t; 191 192 typedef struct { 193 mm_camera_buf_def_t video; 194 mm_camera_buf_def_t main; 195 } mm_camera_buf_video_t; 196 197 typedef struct { 198 mm_camera_channel_type_t ch_type; 199 union { 200 mm_camera_buf_def_t def; 201 mm_camera_buf_def_t preview; 202 mm_camera_buf_snapshot_t snapshot; 203 mm_camera_buf_video_t video; 204 }; 205 } mm_camera_reg_buf_t; 206 207 typedef enum { 208 MM_CAMERA_OPS_PREVIEW, // start/stop preview 209 MM_CAMERA_OPS_VIDEO, // start/stop video 210 MM_CAMERA_OPS_PREPARE_SNAPSHOT, // prepare capture in capture mode 211 MM_CAMERA_OPS_SNAPSHOT, // take snapshot (HDR,ZSL,live shot) 212 MM_CAMERA_OPS_RAW, // take raw streaming (raw snapshot, etc) 213 MM_CAMERA_OPS_ZSL, // start/stop zsl 214 // mm_camera_ops_parm_get_buffered_frame_t is used for MM_CAMERA_OPS_GET_BUFFERED_FRAME 215 MM_CAMERA_OPS_GET_BUFFERED_FRAME, // channel to dispatch buffered frame to app through call back 216 MM_CAMERA_OPS_FOCUS, // change focus,isp3a_af_mode_t* used in val 217 MM_CAMERA_OPS_MAX // max ops 218 }mm_camera_ops_type_t; 219 220 /* Temp: We are declaring it here so that we can still use the 221 legacy GET_CAPABILITIES call to config thread. A new design 222 to query capabilities based on V4L2 interface is being 223 discussed. */ 224 typedef enum { 225 CAMERA_OPS_LOCAL = -1, /*no need to query mm-camera*/ 226 CAMERA_OPS_STREAMING_PREVIEW = 0, 227 CAMERA_OPS_STREAMING_ZSL, 228 CAMERA_OPS_STREAMING_VIDEO, 229 CAMERA_OPS_CAPTURE, /*not supported*/ 230 CAMERA_OPS_FOCUS, 231 CAMERA_OPS_GET_PICTURE, /*5*/ 232 CAMERA_OPS_PREPARE_SNAPSHOT, 233 CAMERA_OPS_SNAPSHOT, 234 CAMERA_OPS_LIVESHOT, 235 CAMERA_OPS_RAW_SNAPSHOT, 236 CAMERA_OPS_VIDEO_RECORDING, /*10*/ 237 CAMERA_OPS_REGISTER_BUFFER, 238 CAMERA_OPS_UNREGISTER_BUFFER, 239 CAMERA_OPS_CAPTURE_AND_ENCODE, 240 CAMERA_OPS_RAW_CAPTURE, 241 CAMERA_OPS_ENCODE, /*15*/ 242 CAMERA_OPS_ZSL_STREAMING_CB, 243 /* add new above*/ 244 CAMERA_OPS_MAX 245 }mm_camera_legacy_ops_type_t; 246 247 typedef enum { 248 MM_CAMERA_CH_ATTR_RAW_STREAMING_TYPE, 249 MM_CAMERA_CH_ATTR_BUFFERING_FRAME, 250 MM_CAMERA_CH_ATTR_MAX 251 } mm_camera_channel_attr_type_t; 252 253 typedef struct { 254 /* how deep the circular frame queue */ 255 int water_mark; 256 int look_back; 257 int interval; /*skipping n-1 frames*/ 258 } mm_camera_channel_attr_buffering_frame_t; 259 260 typedef struct { 261 mm_camera_channel_attr_type_t type; 262 union { 263 /* add more if needed */ 264 mm_camera_raw_streaming_type_t raw_streaming_mode; 265 mm_camera_channel_attr_buffering_frame_t buffering_frame; 266 }; 267 } mm_camera_channel_attr_t; 268 269 typedef struct { 270 mm_camera_channel_type_t ch_type; 271 } mm_camera_ops_parm_get_buffered_frame_t; 272 273 typedef struct mm_camera mm_camera_t; 274 275 typedef struct { 276 /* if the parm is supported */ 277 uint8_t (*is_parm_supported)(mm_camera_t *camera, mm_camera_parm_type_t parm_type); 278 /* if the channel is supported */ 279 uint8_t (*is_ch_supported)(mm_camera_t *camera, mm_camera_channel_type_t ch_type); 280 /* set a parm�s current value */ 281 int32_t (*set_parm)(mm_camera_t *camera, mm_camera_parm_type_t parm_type, 282 void* p_value); 283 /* get a parm�s current value */ 284 int32_t (*get_parm)(mm_camera_t *camera, mm_camera_parm_type_t parm_type, 285 void* p_value); 286 int32_t (*request_buf) (mm_camera_t *camera, mm_camera_reg_buf_t *buf); 287 int32_t (*enqueue_buf) (mm_camera_t *camera, mm_camera_reg_buf_t *buf); 288 int32_t (*prepare_buf) (mm_camera_t *camera, mm_camera_reg_buf_t *buf); 289 int32_t (*unprepare_buf) (mm_camera_t *camera, mm_camera_channel_type_t ch_type); 290 } mm_camera_config_t; 291 292 typedef struct { 293 uint8_t (*is_op_supported)(mm_camera_t * camera, mm_camera_ops_type_t opcode); 294 /* val is reserved for some action such as MM_CAMERA_OPS_FOCUS */ 295 int32_t (*action)(mm_camera_t * camera, uint8_t start, 296 mm_camera_ops_type_t opcode, void *val); 297 int32_t (*open)(mm_camera_t * camera, mm_camera_op_mode_type_t op_mode); 298 void (*close)(mm_camera_t * camera); 299 void (*stop)(mm_camera_t * camera); 300 int32_t (*ch_acquire)(mm_camera_t * camera, mm_camera_channel_type_t ch_type); 301 void (*ch_release)(mm_camera_t * camera, mm_camera_channel_type_t ch_type); 302 int32_t (*ch_set_attr)(mm_camera_t * camera, mm_camera_channel_type_t ch_type, 303 mm_camera_channel_attr_t *attr); 304 int32_t (*sendmsg)(mm_camera_t * camera, void *msg, uint32_t buf_size, int sendfd); 305 } mm_camera_ops_t; 306 307 typedef struct { 308 int type; 309 uint32_t length; 310 void *value; 311 } mm_camera_stats_t; 312 313 typedef struct { 314 int idx; 315 struct msm_frame *frame; 316 } mm_camera_notify_frame_t; 317 318 typedef struct { 319 mm_camera_notify_frame_t video; 320 mm_camera_notify_frame_t main; 321 } mm_camera_notify_video_buf_t; 322 323 typedef struct { 324 mm_camera_notify_frame_t thumbnail; 325 mm_camera_notify_frame_t main; 326 } mm_camera_notify_snapshot_buf_t; 327 328 typedef struct { 329 mm_camera_channel_type_t type; 330 // union { 331 mm_camera_notify_snapshot_buf_t snapshot; 332 mm_camera_notify_video_buf_t video; 333 mm_camera_notify_frame_t def; 334 // }; 335 } mm_camera_ch_data_buf_t; 336 337 338 typedef enum { 339 MM_CAMERA_REG_BUF_CB_ONCE, 340 MM_CAMERA_REG_BUF_CB_COUNT, 341 MM_CAMERA_REG_BUF_CB_INFINITE 342 } mm_camera_register_buf_cb_type_t; 343 344 typedef void (*mm_camera_event_notify_t)(mm_camera_event_t *evt, 345 void *user_data); 346 347 typedef void (*mm_camera_buf_notify_t)(mm_camera_ch_data_buf_t *bufs, 348 void *user_data); 349 350 typedef struct { 351 uint8_t (*is_event_supported)(mm_camera_t * camera, 352 mm_camera_event_type_t evt_type); 353 int32_t (*register_event_notify)(mm_camera_t * camera, 354 mm_camera_event_notify_t evt_cb, 355 void * user_data, 356 mm_camera_event_type_t evt_type); 357 int32_t (*register_buf_notify)(mm_camera_t * camera, 358 mm_camera_channel_type_t ch_type, 359 mm_camera_buf_notify_t buf_cb, 360 mm_camera_register_buf_cb_type_t cb_type, 361 uint32_t cb_count, 362 void * user_data); 363 int32_t (*buf_done)(mm_camera_t * camera, mm_camera_ch_data_buf_t *bufs); 364 } mm_camera_notify_t; 365 366 typedef enum { 367 MM_CAMERA_JPEG_PARM_ROTATION, 368 MM_CAMERA_JPEG_PARM_MAINIMG_QUALITY, 369 MM_CAMERA_JPEG_PARM_THUMB_QUALITY, 370 MM_CAMERA_JPEG_PARM_MAX 371 } mm_camera_jpeg_parm_type_t; 372 373 typedef struct { 374 uint8_t* ptr; 375 uint32_t filled_size; 376 uint32_t size; 377 int32_t fd; 378 uint32_t offset; 379 }mm_camera_buffer_t; 380 381 typedef struct { 382 exif_tags_info_t* exif_data; 383 int exif_numEntries; 384 mm_camera_buffer_t* p_output_buffer; 385 uint8_t buffer_count; 386 uint32_t rotation; 387 uint32_t quality; 388 int y_offset; 389 int cbcr_offset; 390 /* bitmask for the images to be encoded. if capture_and_encode 391 * option is selected, all the images will be encoded irrespective 392 * of bitmask. 393 */ 394 uint8_t encodeBitMask; 395 uint32_t output_picture_width; 396 uint32_t output_picture_height; 397 int format3d; 398 }encode_params_t; 399 400 typedef struct { 401 void * src_img1_buf; // input main image buffer 402 uint32_t src_img1_size; // input main image size 403 void * src_img2_buf; // input thumbnail image buffer 404 uint32_t src_img2_size; // input thumbnail image size 405 void* out_jpeg1_buf; // out jpeg buffer 406 uint32_t out_jpeg1_size; // IN/OUT-result buf size/jpeg image size 407 void* out_jpeg2_buf; // out jpeg buffer 408 uint32_t out_jpeg2_size; // IN/OUT-result buf size/jpeg image size 409 mm_camera_status_type_t status; // result status place holder 410 } mm_camera_jpeg_encode_t; 411 412 typedef void (*mm_camera_jpeg_cb_t)(mm_camera_jpeg_encode_t *result, 413 void *user_data); 414 415 typedef struct { 416 uint8_t (*is_jpeg_supported)( mm_camera_t * camera); 417 int32_t (*set_parm)(mm_camera_t * camera, mm_camera_jpeg_parm_type_t parm_type, 418 void* p_value); 419 int32_t (*get_parm)(mm_camera_t * camera, mm_camera_jpeg_parm_type_t parm_type, 420 void* p_value); 421 int32_t (* register_event_cb)(mm_camera_t * camera, mm_camera_jpeg_cb_t * evt_cb, 422 void * user_data); 423 int32_t (*encode)(mm_camera_t * camera, uint8_t start, 424 mm_camera_jpeg_encode_t *data); 425 } mm_camera_jpeg_t; 426 427 struct mm_camera { 428 mm_camera_config_t *cfg; // config interface 429 mm_camera_ops_t *ops; // operation interface 430 mm_camera_notify_t *evt; // evt callback interface 431 mm_camera_jpeg_t *jpeg_ops; // jpeg config and encoding interface 432 qcamera_info_t camera_info; // postion, mount_angle, etc. 433 enum sensor_type_t sensor_type; // BAYER, YUV, JPEG_SOC, etc. 434 char video_dev_name[32]; // device node name, e.g. /dev/video1 435 }; 436 437 typedef enum { 438 MM_CAMERA_PAD_WORD, 439 MM_CAMERA_PAD_2K, 440 MM_CAMERA_PAD_MAX 441 } mm_camera_pad_type_t; 442 443 typedef struct 444 { 445 struct camera_size_type *sizes_tbl; 446 uint32_t tbl_size; 447 }default_sizes_tbl_t; 448 449 /*configure methods*/ 450 uint8_t cam_config_is_parm_supported( 451 int cam_id, 452 mm_camera_parm_type_t parm_type); 453 uint8_t cam_config_is_ch_supported( 454 int cam_id, 455 mm_camera_channel_type_t ch_type); 456 /* set a parm�s current value */ 457 int32_t cam_config_set_parm( 458 int cam_id, 459 mm_camera_parm_type_t parm_type, 460 void* p_value); 461 /* get a parm�s current value */ 462 int32_t cam_config_get_parm( 463 int cam_id, 464 mm_camera_parm_type_t parm_type, 465 void* p_value); 466 int32_t cam_config_request_buf(int cam_id, mm_camera_reg_buf_t *buf); 467 int32_t cam_config_prepare_buf(int cam_id, mm_camera_reg_buf_t *buf); 468 int32_t cam_config_unprepare_buf(int cam_id, mm_camera_channel_type_t ch_type); 469 470 /*operation methods*/ 471 uint8_t cam_ops_is_op_supported(int cam_id, mm_camera_ops_type_t opcode); 472 /* val is reserved for some action such as MM_CAMERA_OPS_FOCUS */ 473 int32_t cam_ops_action(int cam_id, uint8_t start, 474 mm_camera_ops_type_t opcode, void *val); 475 int32_t cam_ops_open(int cam_id, mm_camera_op_mode_type_t op_mode); 476 void cam_ops_close(int cam_id); 477 void cam_ops_stop(int cam_id); 478 int32_t cam_ops_ch_acquire(int cam_id, mm_camera_channel_type_t ch_type); 479 void cam_ops_ch_release(int cam_id, mm_camera_channel_type_t ch_type); 480 int32_t cam_ops_ch_set_attr(int cam_id, mm_camera_channel_type_t ch_type, 481 mm_camera_channel_attr_t *attr); 482 int32_t cam_ops_sendmsg(int cam_id, void *msg, uint32_t buf_size, int sendfd); 483 484 /*call-back notify methods*/ 485 uint8_t cam_evt_is_event_supported(int cam_id, mm_camera_event_type_t evt_type); 486 int32_t cam_evt_register_event_notify(int cam_id, 487 mm_camera_event_notify_t evt_cb, 488 void * user_data, 489 mm_camera_event_type_t evt_type); 490 int32_t cam_evt_register_buf_notify(int cam_id, 491 mm_camera_channel_type_t ch_type, 492 mm_camera_buf_notify_t buf_cb, 493 mm_camera_register_buf_cb_type_t cb_type, 494 uint32_t cb_count, 495 void * user_data); 496 497 int32_t cam_evt_buf_done(int cam_id, mm_camera_ch_data_buf_t *bufs); 498 499 /*camera JPEG methods*/ 500 uint8_t cam_jpeg_is_jpeg_supported(int cam_id); 501 int32_t cam_jpeg_set_parm(int cam_id, mm_camera_jpeg_parm_type_t parm_type, 502 void* p_value); 503 int32_t cam_jpeg_get_parm(int cam_id, mm_camera_jpeg_parm_type_t parm_type, 504 void* p_value); 505 int32_t cam_jpeg_register_event_cb(int cam_id, mm_camera_jpeg_cb_t * evt_cb, 506 void * user_data); 507 int32_t cam_jpeg_encode(int cam_id, uint8_t start, 508 mm_camera_jpeg_encode_t *data); 509 510 extern mm_camera_t * mm_camera_query(uint8_t *num_cameras); 511 extern uint8_t *mm_camera_do_mmap(uint32_t size, int *pmemFd); 512 extern int mm_camera_do_munmap(int pmem_fd, void *addr, size_t size); 513 extern uint8_t *mm_camera_do_mmap_ion(int ion_fd, struct ion_allocation_data *alloc, 514 struct ion_fd_data *ion_info_fd, int *mapFd); 515 extern int mm_camera_do_munmap_ion (int ion_fd, struct ion_fd_data *ion_info_fd, 516 void *addr, size_t size); 517 extern int mm_camera_dump_image(void *addr, uint32_t size, char *filename); 518 extern uint32_t mm_camera_get_msm_frame_len(cam_format_t fmt_type, 519 camera_mode_t mode, 520 int width, 521 int height, 522 int image_type, 523 uint8_t *num_planes, 524 uint32_t planes[]); 525 uint8_t *mm_camera_do_mmap_ion(int ion_fd, struct ion_allocation_data *alloc, 526 struct ion_fd_data *ion_info_fd, int *mapFd); 527 int mm_camera_do_munmap_ion (int ion_fd, struct ion_fd_data *ion_info_fd, 528 void *addr, size_t size); 529 extern void mm_camera_util_profile(const char *str); 530 #endif /*__MM_CAMERA_INTERFACE2_H__*/ 531