1 /* 2 Copyright (c) 2011-2012, 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 union { 181 mm_camera_sp_buf_t sp; 182 mm_camera_mp_buf_t *mp; 183 }buf; 184 } mm_camera_buf_def_t; 185 186 typedef struct { 187 mm_camera_buf_def_t thumbnail; 188 mm_camera_buf_def_t main; 189 } mm_camera_buf_snapshot_t; 190 191 typedef struct { 192 mm_camera_buf_def_t video; 193 mm_camera_buf_def_t main; 194 } mm_camera_buf_video_t; 195 196 typedef struct { 197 mm_camera_channel_type_t ch_type; 198 union { 199 mm_camera_buf_def_t def; 200 mm_camera_buf_def_t preview; 201 mm_camera_buf_snapshot_t snapshot; 202 mm_camera_buf_video_t video; 203 }; 204 } mm_camera_reg_buf_t; 205 206 typedef enum { 207 MM_CAMERA_OPS_PREVIEW, // start/stop preview 208 MM_CAMERA_OPS_VIDEO, // start/stop video 209 MM_CAMERA_OPS_PREPARE_SNAPSHOT, // prepare capture in capture mode 210 MM_CAMERA_OPS_SNAPSHOT, // take snapshot (HDR,ZSL,live shot) 211 MM_CAMERA_OPS_RAW, // take raw streaming (raw snapshot, etc) 212 MM_CAMERA_OPS_ZSL, // start/stop zsl 213 // mm_camera_ops_parm_get_buffered_frame_t is used for MM_CAMERA_OPS_GET_BUFFERED_FRAME 214 MM_CAMERA_OPS_GET_BUFFERED_FRAME, // channel to dispatch buffered frame to app through call back 215 MM_CAMERA_OPS_FOCUS, // change focus,isp3a_af_mode_t* used in val 216 MM_CAMERA_OPS_MAX // max ops 217 }mm_camera_ops_type_t; 218 219 /* Temp: We are declaring it here so that we can still use the 220 legacy GET_CAPABILITIES call to config thread. A new design 221 to query capabilities based on V4L2 interface is being 222 discussed. */ 223 typedef enum { 224 CAMERA_OPS_LOCAL = -1, /*no need to query mm-camera*/ 225 CAMERA_OPS_STREAMING_PREVIEW = 0, 226 CAMERA_OPS_STREAMING_ZSL, 227 CAMERA_OPS_STREAMING_VIDEO, 228 CAMERA_OPS_CAPTURE, /*not supported*/ 229 CAMERA_OPS_FOCUS, 230 CAMERA_OPS_GET_PICTURE, /*5*/ 231 CAMERA_OPS_PREPARE_SNAPSHOT, 232 CAMERA_OPS_SNAPSHOT, 233 CAMERA_OPS_LIVESHOT, 234 CAMERA_OPS_RAW_SNAPSHOT, 235 CAMERA_OPS_VIDEO_RECORDING, /*10*/ 236 CAMERA_OPS_REGISTER_BUFFER, 237 CAMERA_OPS_UNREGISTER_BUFFER, 238 CAMERA_OPS_CAPTURE_AND_ENCODE, 239 CAMERA_OPS_RAW_CAPTURE, 240 CAMERA_OPS_ENCODE, /*15*/ 241 CAMERA_OPS_ZSL_STREAMING_CB, 242 /* add new above*/ 243 CAMERA_OPS_MAX 244 }mm_camera_legacy_ops_type_t; 245 246 typedef enum { 247 MM_CAMERA_CH_ATTR_RAW_STREAMING_TYPE, 248 MM_CAMERA_CH_ATTR_BUFFERING_FRAME, 249 MM_CAMERA_CH_ATTR_MAX 250 } mm_camera_channel_attr_type_t; 251 252 typedef struct { 253 /* how deep the circular frame queue */ 254 int water_mark; 255 int look_back; 256 int interval; /*skipping n-1 frames*/ 257 } mm_camera_channel_attr_buffering_frame_t; 258 259 typedef struct { 260 mm_camera_channel_attr_type_t type; 261 union { 262 /* add more if needed */ 263 mm_camera_raw_streaming_type_t raw_streaming_mode; 264 mm_camera_channel_attr_buffering_frame_t buffering_frame; 265 }; 266 } mm_camera_channel_attr_t; 267 268 typedef struct { 269 mm_camera_channel_type_t ch_type; 270 } mm_camera_ops_parm_get_buffered_frame_t; 271 272 typedef struct mm_camera mm_camera_t; 273 274 typedef struct { 275 /* if the parm is supported */ 276 uint8_t (*is_parm_supported)(mm_camera_t *camera, mm_camera_parm_type_t parm_type); 277 /* if the channel is supported */ 278 uint8_t (*is_ch_supported)(mm_camera_t *camera, mm_camera_channel_type_t ch_type); 279 /* set a parms current value */ 280 int32_t (*set_parm)(mm_camera_t *camera, mm_camera_parm_type_t parm_type, 281 void* p_value); 282 /* get a parms current value */ 283 int32_t (*get_parm)(mm_camera_t *camera, mm_camera_parm_type_t parm_type, 284 void* p_value); 285 int32_t (*request_buf) (mm_camera_t *camera, mm_camera_reg_buf_t *buf); 286 int32_t (*enqueue_buf) (mm_camera_t *camera, mm_camera_reg_buf_t *buf); 287 int32_t (*prepare_buf) (mm_camera_t *camera, mm_camera_reg_buf_t *buf); 288 int32_t (*unprepare_buf) (mm_camera_t *camera, mm_camera_channel_type_t ch_type); 289 } mm_camera_config_t; 290 291 typedef struct { 292 uint8_t (*is_op_supported)(mm_camera_t * camera, mm_camera_ops_type_t opcode); 293 /* val is reserved for some action such as MM_CAMERA_OPS_FOCUS */ 294 int32_t (*action)(mm_camera_t * camera, uint8_t start, 295 mm_camera_ops_type_t opcode, void *val); 296 int32_t (*open)(mm_camera_t * camera, mm_camera_op_mode_type_t op_mode); 297 void (*close)(mm_camera_t * camera); 298 void (*stop)(mm_camera_t * camera); 299 int32_t (*ch_acquire)(mm_camera_t * camera, mm_camera_channel_type_t ch_type); 300 void (*ch_release)(mm_camera_t * camera, mm_camera_channel_type_t ch_type); 301 int32_t (*ch_set_attr)(mm_camera_t * camera, mm_camera_channel_type_t ch_type, 302 mm_camera_channel_attr_t *attr); 303 int32_t (*sendmsg)(mm_camera_t * camera, void *msg, uint32_t buf_size, int sendfd); 304 } mm_camera_ops_t; 305 306 typedef struct { 307 int type; 308 uint32_t length; 309 void *value; 310 } mm_camera_stats_t; 311 312 typedef struct { 313 int idx; 314 struct msm_frame *frame; 315 } mm_camera_notify_frame_t; 316 317 typedef struct { 318 mm_camera_notify_frame_t video; 319 mm_camera_notify_frame_t main; 320 } mm_camera_notify_video_buf_t; 321 322 typedef struct { 323 mm_camera_notify_frame_t thumbnail; 324 mm_camera_notify_frame_t main; 325 } mm_camera_notify_snapshot_buf_t; 326 327 typedef struct { 328 mm_camera_channel_type_t type; 329 // union { 330 mm_camera_notify_snapshot_buf_t snapshot; 331 mm_camera_notify_video_buf_t video; 332 mm_camera_notify_frame_t def; 333 // }; 334 } mm_camera_ch_data_buf_t; 335 336 337 typedef enum { 338 MM_CAMERA_REG_BUF_CB_ONCE, 339 MM_CAMERA_REG_BUF_CB_COUNT, 340 MM_CAMERA_REG_BUF_CB_INFINITE 341 } mm_camera_register_buf_cb_type_t; 342 343 typedef void (*mm_camera_event_notify_t)(mm_camera_event_t *evt, 344 void *user_data); 345 346 typedef void (*mm_camera_buf_notify_t)(mm_camera_ch_data_buf_t *bufs, 347 void *user_data); 348 349 typedef struct { 350 uint8_t (*is_event_supported)(mm_camera_t * camera, 351 mm_camera_event_type_t evt_type); 352 int32_t (*register_event_notify)(mm_camera_t * camera, 353 mm_camera_event_notify_t evt_cb, 354 void * user_data, 355 mm_camera_event_type_t evt_type); 356 int32_t (*register_buf_notify)(mm_camera_t * camera, 357 mm_camera_channel_type_t ch_type, 358 mm_camera_buf_notify_t buf_cb, 359 mm_camera_register_buf_cb_type_t cb_type, 360 uint32_t cb_count, 361 void * user_data); 362 int32_t (*buf_done)(mm_camera_t * camera, mm_camera_ch_data_buf_t *bufs); 363 } mm_camera_notify_t; 364 365 typedef enum { 366 MM_CAMERA_JPEG_PARM_ROTATION, 367 MM_CAMERA_JPEG_PARM_MAINIMG_QUALITY, 368 MM_CAMERA_JPEG_PARM_THUMB_QUALITY, 369 MM_CAMERA_JPEG_PARM_MAX 370 } mm_camera_jpeg_parm_type_t; 371 372 typedef struct { 373 uint8_t* ptr; 374 uint32_t filled_size; 375 uint32_t size; 376 int32_t fd; 377 uint32_t offset; 378 }mm_camera_buffer_t; 379 380 typedef struct { 381 exif_tags_info_t* exif_data; 382 int exif_numEntries; 383 mm_camera_buffer_t* p_output_buffer; 384 uint8_t buffer_count; 385 uint32_t rotation; 386 uint32_t quality; 387 int y_offset; 388 int cbcr_offset; 389 /* bitmask for the images to be encoded. if capture_and_encode 390 * option is selected, all the images will be encoded irrespective 391 * of bitmask. 392 */ 393 uint8_t encodeBitMask; 394 uint32_t output_picture_width; 395 uint32_t output_picture_height; 396 int format3d; 397 }encode_params_t; 398 399 typedef struct { 400 void * src_img1_buf; // input main image buffer 401 uint32_t src_img1_size; // input main image size 402 void * src_img2_buf; // input thumbnail image buffer 403 uint32_t src_img2_size; // input thumbnail image size 404 void* out_jpeg1_buf; // out jpeg buffer 405 uint32_t out_jpeg1_size; // IN/OUT-result buf size/jpeg image size 406 void* out_jpeg2_buf; // out jpeg buffer 407 uint32_t out_jpeg2_size; // IN/OUT-result buf size/jpeg image size 408 mm_camera_status_type_t status; // result status place holder 409 } mm_camera_jpeg_encode_t; 410 411 typedef void (*mm_camera_jpeg_cb_t)(mm_camera_jpeg_encode_t *result, 412 void *user_data); 413 414 typedef struct { 415 uint8_t (*is_jpeg_supported)( mm_camera_t * camera); 416 int32_t (*set_parm)(mm_camera_t * camera, mm_camera_jpeg_parm_type_t parm_type, 417 void* p_value); 418 int32_t (*get_parm)(mm_camera_t * camera, mm_camera_jpeg_parm_type_t parm_type, 419 void* p_value); 420 int32_t (* register_event_cb)(mm_camera_t * camera, mm_camera_jpeg_cb_t * evt_cb, 421 void * user_data); 422 int32_t (*encode)(mm_camera_t * camera, uint8_t start, 423 mm_camera_jpeg_encode_t *data); 424 } mm_camera_jpeg_t; 425 426 struct mm_camera { 427 mm_camera_config_t *cfg; // config interface 428 mm_camera_ops_t *ops; // operation interface 429 mm_camera_notify_t *evt; // evt callback interface 430 mm_camera_jpeg_t *jpeg_ops; // jpeg config and encoding interface 431 qcamera_info_t camera_info; // postion, mount_angle, etc. 432 enum sensor_type_t sensor_type; // BAYER, YUV, JPEG_SOC, etc. 433 char video_dev_name[32]; // device node name, e.g. /dev/video1 434 }; 435 436 typedef enum { 437 MM_CAMERA_PAD_WORD, 438 MM_CAMERA_PAD_2K, 439 MM_CAMERA_PAD_MAX 440 } mm_camera_pad_type_t; 441 442 typedef struct 443 { 444 struct camera_size_type *sizes_tbl; 445 uint32_t tbl_size; 446 }default_sizes_tbl_t; 447 448 /*configure methods*/ 449 uint8_t cam_config_is_parm_supported( 450 int cam_id, 451 mm_camera_parm_type_t parm_type); 452 uint8_t cam_config_is_ch_supported( 453 int cam_id, 454 mm_camera_channel_type_t ch_type); 455 /* set a parms current value */ 456 int32_t cam_config_set_parm( 457 int cam_id, 458 mm_camera_parm_type_t parm_type, 459 void* p_value); 460 /* get a parms current value */ 461 int32_t cam_config_get_parm( 462 int cam_id, 463 mm_camera_parm_type_t parm_type, 464 void* p_value); 465 int32_t cam_config_request_buf(int cam_id, mm_camera_reg_buf_t *buf); 466 int32_t cam_config_enqueue_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