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 int32_t (*ch_acquire)(mm_camera_t * camera, mm_camera_channel_type_t ch_type); 299 void (*ch_release)(mm_camera_t * camera, mm_camera_channel_type_t ch_type); 300 int32_t (*ch_set_attr)(mm_camera_t * camera, mm_camera_channel_type_t ch_type, 301 mm_camera_channel_attr_t *attr); 302 int32_t (*sendmsg)(mm_camera_t * camera, void *msg, uint32_t buf_size, int sendfd); 303 } mm_camera_ops_t; 304 305 typedef struct { 306 int type; 307 uint32_t length; 308 void *value; 309 } mm_camera_stats_t; 310 311 typedef struct { 312 int idx; 313 struct msm_frame *frame; 314 } mm_camera_notify_frame_t; 315 316 typedef struct { 317 mm_camera_notify_frame_t video; 318 mm_camera_notify_frame_t main; 319 } mm_camera_notify_video_buf_t; 320 321 typedef struct { 322 mm_camera_notify_frame_t thumbnail; 323 mm_camera_notify_frame_t main; 324 } mm_camera_notify_snapshot_buf_t; 325 326 typedef struct { 327 mm_camera_channel_type_t type; 328 // union { 329 mm_camera_notify_snapshot_buf_t snapshot; 330 mm_camera_notify_video_buf_t video; 331 mm_camera_notify_frame_t def; 332 // }; 333 } mm_camera_ch_data_buf_t; 334 335 336 typedef enum { 337 MM_CAMERA_REG_BUF_CB_ONCE, 338 MM_CAMERA_REG_BUF_CB_COUNT, 339 MM_CAMERA_REG_BUF_CB_INFINITE 340 } mm_camera_register_buf_cb_type_t; 341 342 typedef void (*mm_camera_event_notify_t)(mm_camera_event_t *evt, 343 void *user_data); 344 345 typedef void (*mm_camera_buf_notify_t)(mm_camera_ch_data_buf_t *bufs, 346 void *user_data); 347 348 typedef struct { 349 uint8_t (*is_event_supported)(mm_camera_t * camera, 350 mm_camera_event_type_t evt_type); 351 int32_t (*register_event_notify)(mm_camera_t * camera, 352 mm_camera_event_notify_t evt_cb, 353 void * user_data, 354 mm_camera_event_type_t evt_type); 355 int32_t (*register_buf_notify)(mm_camera_t * camera, 356 mm_camera_channel_type_t ch_type, 357 mm_camera_buf_notify_t buf_cb, 358 mm_camera_register_buf_cb_type_t cb_type, 359 uint32_t cb_count, 360 void * user_data); 361 int32_t (*buf_done)(mm_camera_t * camera, mm_camera_ch_data_buf_t *bufs); 362 } mm_camera_notify_t; 363 364 typedef enum { 365 MM_CAMERA_JPEG_PARM_ROTATION, 366 MM_CAMERA_JPEG_PARM_MAINIMG_QUALITY, 367 MM_CAMERA_JPEG_PARM_THUMB_QUALITY, 368 MM_CAMERA_JPEG_PARM_MAX 369 } mm_camera_jpeg_parm_type_t; 370 371 typedef struct { 372 uint8_t* ptr; 373 uint32_t filled_size; 374 uint32_t size; 375 int32_t fd; 376 uint32_t offset; 377 }mm_camera_buffer_t; 378 379 typedef struct { 380 exif_tags_info_t* exif_data; 381 int exif_numEntries; 382 mm_camera_buffer_t* p_output_buffer; 383 uint8_t buffer_count; 384 uint32_t rotation; 385 uint32_t quality; 386 int y_offset; 387 int cbcr_offset; 388 /* bitmask for the images to be encoded. if capture_and_encode 389 * option is selected, all the images will be encoded irrespective 390 * of bitmask. 391 */ 392 uint8_t encodeBitMask; 393 uint32_t output_picture_width; 394 uint32_t output_picture_height; 395 int format3d; 396 }encode_params_t; 397 398 typedef struct { 399 void * src_img1_buf; // input main image buffer 400 uint32_t src_img1_size; // input main image size 401 void * src_img2_buf; // input thumbnail image buffer 402 uint32_t src_img2_size; // input thumbnail image size 403 void* out_jpeg1_buf; // out jpeg buffer 404 uint32_t out_jpeg1_size; // IN/OUT-result buf size/jpeg image size 405 void* out_jpeg2_buf; // out jpeg buffer 406 uint32_t out_jpeg2_size; // IN/OUT-result buf size/jpeg image size 407 mm_camera_status_type_t status; // result status place holder 408 } mm_camera_jpeg_encode_t; 409 410 typedef void (*mm_camera_jpeg_cb_t)(mm_camera_jpeg_encode_t *result, 411 void *user_data); 412 413 typedef struct { 414 uint8_t (*is_jpeg_supported)( mm_camera_t * camera); 415 int32_t (*set_parm)(mm_camera_t * camera, mm_camera_jpeg_parm_type_t parm_type, 416 void* p_value); 417 int32_t (*get_parm)(mm_camera_t * camera, mm_camera_jpeg_parm_type_t parm_type, 418 void* p_value); 419 int32_t (* register_event_cb)(mm_camera_t * camera, mm_camera_jpeg_cb_t * evt_cb, 420 void * user_data); 421 int32_t (*encode)(mm_camera_t * camera, uint8_t start, 422 mm_camera_jpeg_encode_t *data); 423 } mm_camera_jpeg_t; 424 425 struct mm_camera { 426 mm_camera_config_t *cfg; // config interface 427 mm_camera_ops_t *ops; // operation interface 428 mm_camera_notify_t *evt; // evt callback interface 429 mm_camera_jpeg_t *jpeg_ops; // jpeg config and encoding interface 430 qcamera_info_t camera_info; // postion, mount_angle, etc. 431 enum sensor_type_t sensor_type; // BAYER, YUV, JPEG_SOC, etc. 432 char video_dev_name[32]; // device node name, e.g. /dev/video1 433 }; 434 435 typedef enum { 436 MM_CAMERA_PAD_WORD, 437 MM_CAMERA_PAD_2K, 438 MM_CAMERA_PAD_MAX 439 } mm_camera_pad_type_t; 440 441 typedef struct 442 { 443 struct camera_size_type *sizes_tbl; 444 uint32_t tbl_size; 445 }default_sizes_tbl_t; 446 447 /*configure methods*/ 448 uint8_t cam_config_is_parm_supported( 449 int cam_id, 450 mm_camera_parm_type_t parm_type); 451 uint8_t cam_config_is_ch_supported( 452 int cam_id, 453 mm_camera_channel_type_t ch_type); 454 /* set a parms current value */ 455 int32_t cam_config_set_parm( 456 int cam_id, 457 mm_camera_parm_type_t parm_type, 458 void* p_value); 459 /* get a parms current value */ 460 int32_t cam_config_get_parm( 461 int cam_id, 462 mm_camera_parm_type_t parm_type, 463 void* p_value); 464 int32_t cam_config_request_buf(int cam_id, mm_camera_reg_buf_t *buf); 465 int32_t cam_config_enqueue_buf(int cam_id, mm_camera_reg_buf_t *buf); 466 int32_t cam_config_prepare_buf(int cam_id, mm_camera_reg_buf_t *buf); 467 int32_t cam_config_unprepare_buf(int cam_id, mm_camera_channel_type_t ch_type); 468 469 /*operation methods*/ 470 uint8_t cam_ops_is_op_supported(int cam_id, mm_camera_ops_type_t opcode); 471 /* val is reserved for some action such as MM_CAMERA_OPS_FOCUS */ 472 int32_t cam_ops_action(int cam_id, uint8_t start, 473 mm_camera_ops_type_t opcode, void *val); 474 int32_t cam_ops_open(int cam_id, mm_camera_op_mode_type_t op_mode); 475 void cam_ops_close(int cam_id); 476 int32_t cam_ops_ch_acquire(int cam_id, mm_camera_channel_type_t ch_type); 477 void cam_ops_ch_release(int cam_id, mm_camera_channel_type_t ch_type); 478 int32_t cam_ops_ch_set_attr(int cam_id, mm_camera_channel_type_t ch_type, 479 mm_camera_channel_attr_t *attr); 480 int32_t cam_ops_sendmsg(int cam_id, void *msg, uint32_t buf_size, int sendfd); 481 482 /*call-back notify methods*/ 483 uint8_t cam_evt_is_event_supported(int cam_id, mm_camera_event_type_t evt_type); 484 int32_t cam_evt_register_event_notify(int cam_id, 485 mm_camera_event_notify_t evt_cb, 486 void * user_data, 487 mm_camera_event_type_t evt_type); 488 int32_t cam_evt_register_buf_notify(int cam_id, 489 mm_camera_channel_type_t ch_type, 490 mm_camera_buf_notify_t buf_cb, 491 mm_camera_register_buf_cb_type_t cb_type, 492 uint32_t cb_count, 493 void * user_data); 494 495 int32_t cam_evt_buf_done(int cam_id, mm_camera_ch_data_buf_t *bufs); 496 497 /*camera JPEG methods*/ 498 uint8_t cam_jpeg_is_jpeg_supported(int cam_id); 499 int32_t cam_jpeg_set_parm(int cam_id, mm_camera_jpeg_parm_type_t parm_type, 500 void* p_value); 501 int32_t cam_jpeg_get_parm(int cam_id, mm_camera_jpeg_parm_type_t parm_type, 502 void* p_value); 503 int32_t cam_jpeg_register_event_cb(int cam_id, mm_camera_jpeg_cb_t * evt_cb, 504 void * user_data); 505 int32_t cam_jpeg_encode(int cam_id, uint8_t start, 506 mm_camera_jpeg_encode_t *data); 507 508 extern mm_camera_t * mm_camera_query(uint8_t *num_cameras); 509 extern uint8_t *mm_camera_do_mmap(uint32_t size, int *pmemFd); 510 extern int mm_camera_do_munmap(int pmem_fd, void *addr, size_t size); 511 extern uint8_t *mm_camera_do_mmap_ion(int ion_fd, struct ion_allocation_data *alloc, 512 struct ion_fd_data *ion_info_fd, int *mapFd); 513 extern int mm_camera_do_munmap_ion (int ion_fd, struct ion_fd_data *ion_info_fd, 514 void *addr, size_t size); 515 extern int mm_camera_dump_image(void *addr, uint32_t size, char *filename); 516 extern uint32_t mm_camera_get_msm_frame_len(cam_format_t fmt_type, 517 camera_mode_t mode, 518 int width, 519 int height, 520 int image_type, 521 uint8_t *num_planes, 522 uint32_t planes[]); 523 uint8_t *mm_camera_do_mmap_ion(int ion_fd, struct ion_allocation_data *alloc, 524 struct ion_fd_data *ion_info_fd, int *mapFd); 525 int mm_camera_do_munmap_ion (int ion_fd, struct ion_fd_data *ion_info_fd, 526 void *addr, size_t size); 527 extern void mm_camera_util_profile(const char *str); 528 #endif /*__MM_CAMERA_INTERFACE2_H__*/ 529