Home | History | Annotate | Download | only in inc
      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_INTERFACE_H__
     31 #define __MM_CAMERA_INTERFACE_H__
     32 #include <linux/msm_ion.h>
     33 #include <camera.h>
     34 #include "QCamera_Intf.h"
     35 #include "cam_list.h"
     36 
     37 #define MM_CAMERA_MAX_NUM_FRAMES 16
     38 #define MM_CAMERA_MAX_2ND_SENSORS 4
     39 
     40 typedef enum {
     41     MM_CAMERA_OPS_LOCAL = -1,  /*no need to query mm-camera*/
     42     MM_CAMERA_OPS_STREAMING_PREVIEW = 0,
     43     MM_CAMERA_OPS_STREAMING_ZSL,
     44     MM_CAMERA_OPS_STREAMING_VIDEO,
     45     MM_CAMERA_OPS_CAPTURE, /*not supported*/
     46     MM_CAMERA_OPS_FOCUS,
     47     MM_CAMERA_OPS_GET_PICTURE, /*5*/
     48     MM_CAMERA_OPS_PREPARE_SNAPSHOT,
     49     MM_CAMERA_OPS_SNAPSHOT,
     50     MM_CAMERA_OPS_LIVESHOT,
     51     MM_CAMERA_OPS_RAW_SNAPSHOT,
     52     MM_CAMERA_OPS_VIDEO_RECORDING, /*10*/
     53     MM_CAMERA_OPS_REGISTER_BUFFER,
     54     MM_CAMERA_OPS_UNREGISTER_BUFFER,
     55     MM_CAMERA_OPS_CAPTURE_AND_ENCODE,
     56     MM_CAMERA_OPS_RAW_CAPTURE,
     57     MM_CAMERA_OPS_ENCODE, /*15*/
     58     MM_CAMERA_OPS_ZSL_STREAMING_CB,
     59     /* add new above*/
     60     MM_CAMERA_OPS_MAX
     61 }mm_camera_ops_type_t;
     62 
     63 typedef enum {
     64     MM_CAMERA_STREAM_OFFSET,
     65     MM_CAMERA_STREAM_CID,
     66     MM_CAMERA_STREAM_CROP
     67 }mm_camera_stream_parm_t;
     68 
     69 typedef struct {
     70    int32_t width;
     71    int32_t height;
     72 } mm_camera_dimension_t;
     73 
     74 typedef struct{
     75     uint32_t tbl_size;
     76     struct camera_size_type *sizes_tbl;
     77 }default_sizes_tbl_t;
     78 
     79 typedef struct  {
     80     int32_t left;
     81     int32_t top;
     82     int32_t width;
     83     int32_t height;
     84 } mm_camera_rect_t;
     85 
     86 /* TBD: meta header needs to move to msm_camear.h */
     87 typedef enum {
     88     /* no meta data header used */
     89     MM_CAMEAR_META_DATA_TYPE_DEF,
     90     /* has focus flag, exposure idx,
     91      * flash flag, etc. TBD */
     92     MM_CAMEAR_META_DATA_TYPE_BRACKETING,
     93     MM_CAMEAR_META_DATA_TYPE_MAX,
     94 } mm_camera_meta_header_t;
     95 
     96 typedef struct {
     97     cam_format_t fmt;
     98     mm_camera_meta_header_t meta_header;
     99     uint32_t width;
    100     uint32_t height;
    101     uint8_t rotation;
    102 } mm_camera_image_fmt_t;
    103 
    104 typedef struct {
    105     /* image format */
    106     mm_camera_image_fmt_t fmt;
    107 
    108     /* num of buffers needed */
    109     uint8_t num_of_bufs;
    110 
    111     /* flag to indicate if this stream need stream on */
    112     uint8_t need_stream_on;
    113 
    114     /* num of CB needs to be registered on other stream,
    115      * this field is valid only when need_stream_on is 0.
    116      * When need_stream_on = 1, num_stream_cb_times will be ignored. */
    117     uint8_t num_stream_cb_times;
    118 } mm_camera_stream_config_t;
    119 
    120 typedef struct {
    121     uint8_t name[32];
    122     int32_t min_value;
    123     int32_t max_value;
    124     int32_t step;
    125     int32_t default_value;
    126 } mm_camera_ctrl_cap_sharpness_t;
    127 
    128 typedef struct {
    129     int16_t *zoom_ratio_tbl;
    130     int32_t size;
    131 } mm_camera_zoom_tbl_t;
    132 
    133 typedef enum {
    134     /* ZSL use case: get burst of frames */
    135     MM_CAMERA_SUPER_BUF_NOTIFY_BURST = 0,
    136     /* get continuous frames: when the super buf is
    137      * ready dispatch it to HAL */
    138     MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS,
    139     MM_CAMERA_SUPER_BUF_NOTIFY_MAX
    140 } mm_camera_super_buf_notify_mode_t;
    141 
    142 typedef enum {
    143     /* save the frame. No matter focused or not */
    144     MM_CAMERA_SUPER_BUF_PRIORITY_NORMAL = 0,
    145     /* only queue the frame that is focused. Will enable
    146      * meta data header to carry focus info*/
    147     MM_CAMERA_SUPER_BUF_PRIORITY_FOCUS,
    148     /* after shutter, only queue matched exposure index */
    149     MM_CAMERA_SUPER_BUF_PRIORITY_EXPOSURE_BRACKETING,
    150     MM_CAMERA_SUPER_BUF_PRIORITY_MAX
    151 } mm_camera_super_buf_priority_t;
    152 
    153 typedef struct {
    154     mm_camera_super_buf_notify_mode_t notify_mode;
    155     /* queue depth. Only for burst mode */
    156     uint8_t water_mark;
    157     /* look back how many frames from last buf */
    158     uint8_t look_back;
    159     /* after send first frame to HAL, how many frames
    160      * needing to be skipped for next delivery? */
    161     uint8_t post_frame_skip;
    162     /* save matched priority frames only */
    163     mm_camera_super_buf_priority_t priority;
    164     /* in burst mode, how many super
    165      * bufs for each shutter press? */
    166     uint8_t burst_num;
    167 } mm_camera_bundle_attr_t;
    168 
    169 typedef struct {
    170     uint8_t camera_id;                   /* camera id */
    171     camera_info_t camera_info;           /* postion, mount_angle, etc. */
    172     enum sensor_type_t main_sensor_type; /* BAYER, YUV, JPEG_SOC, etc. */
    173     char *video_dev_name;                /* device node name, e.g. /dev/video1 */
    174 } mm_camera_info_t;
    175 
    176 typedef struct {
    177   uint8_t cid;
    178   uint8_t dt;
    179 }stream_cid_t;
    180 
    181 /* the stats struct will need rework after
    182  * defining the stats buf sharing logic */
    183 typedef struct {
    184     int type;
    185     uint32_t length;
    186     void *value;
    187 } mm_camera_stats_t;
    188 
    189 typedef struct {
    190     uint32_t stream_id; /* stream handler */
    191     int8_t buf_idx; /* buf idx within the stream bufs */
    192 
    193     struct timespec ts; /* time stamp, to be filled when DQBUF*/
    194     uint32_t frame_idx; /* frame sequence num, to be filled when DQBUF */
    195 
    196     int8_t num_planes; /* num of planes, to be filled during mem allocation */
    197     struct v4l2_plane planes[VIDEO_MAX_PLANES]; /* plane info, to be filled during mem allocation*/
    198     int fd; /* fd of the frame, to be filled during mem allocation */
    199     void *buffer; /* ptr to real frame buffer, to be filled during mem allocation */
    200     uint32_t frame_len; /* len of the whole frame, to be filled during mem allocation */
    201     void *mem_info; /* reserved for pointing to mem info */
    202     cam_exif_tags_t *p_mobicat_info; /*for mobicat info*/
    203 } mm_camera_buf_def_t;
    204 
    205 typedef struct {
    206     uint32_t camera_handle;
    207     uint32_t ch_id;
    208     uint8_t num_bufs;
    209     mm_camera_buf_def_t* bufs[MM_CAMEAR_MAX_STRAEM_BUNDLE];
    210 } mm_camera_super_buf_t;
    211 
    212 typedef void (*mm_camera_event_notify_t)(uint32_t camera_handle,
    213                                          mm_camera_event_t *evt,
    214                                          void *user_data);
    215 
    216 typedef void (*mm_camera_buf_notify_t) (mm_camera_super_buf_t *bufs,
    217                                         void *user_data);
    218 typedef cam_frame_len_offset_t mm_camera_frame_len_offset;
    219 
    220 typedef struct {
    221   void *user_data;
    222   int32_t (*get_buf) (uint32_t camera_handle,
    223                       uint32_t ch_id, uint32_t stream_id,
    224                       void *user_data,
    225                       mm_camera_frame_len_offset *frame_offset_info,
    226                       uint8_t num_bufs,
    227                       uint8_t *initial_reg_flag,
    228                       mm_camera_buf_def_t *bufs);
    229   int32_t (*put_buf) (uint32_t camera_handle,
    230                       uint32_t ch_id, uint32_t stream_id,
    231                       void *user_data, uint8_t num_bufs,
    232                       mm_camera_buf_def_t *bufs);
    233 } mm_camear_mem_vtbl_t;
    234 
    235 typedef struct {
    236     uint8_t num_2nd_sensors;
    237     uint8_t sensor_idxs[MM_CAMERA_MAX_2ND_SENSORS];
    238 } mm_camera_2nd_sensor_t;
    239 
    240 typedef enum {
    241     NATIVE_CMD_ID_SOCKET_MAP,
    242     NATIVE_CMD_ID_SOCKET_UNMAP,
    243     NATIVE_CMD_ID_IOCTL_CTRL,
    244     NATIVE_CMD_ID_MAX
    245 } mm_camera_native_cmd_id_t;
    246 
    247 typedef enum {
    248     MM_CAMERA_CMD_TYPE_PRIVATE,   /* OEM private ioctl */
    249     MM_CAMERA_CMD_TYPE_NATIVE     /* native ctrl cmd through ioctl */
    250 } mm_camera_cmd_type_t;
    251 
    252 typedef struct {
    253     mm_camera_buf_def_t *src_frame; /* src frame */
    254 } mm_camera_repro_data_t;
    255 
    256 typedef mm_camera_repro_cmd_config_t mm_camera_repro_isp_config_t;
    257 
    258 typedef struct {
    259     /* to sync the internal camera settings */
    260     int32_t (*sync) (uint32_t camera_handle);
    261     uint8_t (*is_event_supported) (uint32_t camera_handle,
    262                                  mm_camera_event_type_t evt_type);
    263     int32_t (*register_event_notify) (uint32_t camera_handle,
    264                                  mm_camera_event_notify_t evt_cb,
    265                                  void * user_data,
    266                                  mm_camera_event_type_t evt_type);
    267     int32_t (*qbuf) (uint32_t camera_handle, uint32_t ch_id,
    268                                  mm_camera_buf_def_t *buf);
    269     void (*camera_close) (uint32_t camera_handle);
    270     /* Only fo supporting advanced 2nd sensors. If no secondary sensor needed
    271      * HAL can ignore this function */
    272     mm_camera_2nd_sensor_t * (*query_2nd_sensor_info) (uint32_t camera_handle);
    273 
    274     /* if the operation is supported: TRUE - support, FALSE - not support */
    275     uint8_t (*is_op_supported)(uint32_t camera_handle, mm_camera_ops_type_t opcode);
    276 
    277     /* if the parm is supported: TRUE - support, FALSE - not support */
    278     int32_t (*is_parm_supported) (uint32_t camera_handle,
    279                                  mm_camera_parm_type_t parm_type,
    280                                  uint8_t *support_set_parm,
    281                                  uint8_t *support_get_parm);
    282     /* set a parm current value */
    283     int32_t (*set_parm) (uint32_t camera_handle,
    284                          mm_camera_parm_type_t parm_type,
    285                          void* p_value);
    286     /* get a parm current value */
    287     int32_t (*get_parm) (uint32_t camera_handle,
    288                          mm_camera_parm_type_t parm_type,
    289                          void* p_value);
    290     /* ch_id returned, zero is invalid ch_id */
    291     uint32_t (*ch_acquire) (uint32_t camera_handle);
    292     /* relaese channel */
    293     void (*ch_release) (uint32_t camera_handle, uint32_t ch_id);
    294     /* return stream_id. zero is invalid stream_id
    295      * default set to preview: ext_image_mode = 0
    296      * default set to primary sensor: sensor_idx = 0
    297      * value of ext_image_mode is defined in msm_camera.h
    298      */
    299     uint32_t (*add_stream) (uint32_t camera_handle, uint32_t ch_id,
    300                            mm_camera_buf_notify_t buf_cb, void *user_data,
    301                            uint32_t ext_image_mode, uint32_t sensor_idx);
    302     /* delete stream */
    303     int32_t (*del_stream) (uint32_t camera_handle, uint32_t ch_id,
    304                            uint32_t stream_id);
    305     /* set straem format This will trigger getting bufs from HAL */
    306     int32_t (*config_stream) (uint32_t camera_handle, uint32_t ch_id,
    307                               uint32_t stream_id,
    308                               mm_camera_stream_config_t *config);
    309     /* setup super buf bundle for ZSL(with burst mode) or other use cases */
    310     int32_t (*init_stream_bundle) (uint32_t camera_handle, uint32_t ch_id,
    311                                    mm_camera_buf_notify_t super_frame_notify_cb,
    312                                    void *user_data,  mm_camera_bundle_attr_t *attr,
    313                                    uint8_t num_streams, uint32_t *stream_ids);
    314     /* remove the super buf bundle */
    315     int32_t (*destroy_stream_bundle) (uint32_t camera_handle, uint32_t ch_id);
    316     /* start streaming */
    317     int32_t (*start_streams) (uint32_t camera_handle, uint32_t ch_id,
    318                               uint8_t num_streams, uint32_t *stream_ids);
    319     /* stop streaming */
    320     int32_t (*stop_streams) (uint32_t camera_handle, uint32_t ch_id,
    321                              uint8_t num_streams, uint32_t *stream_ids);
    322     /* tear down streams asyncly */
    323     int32_t (*async_teardown_streams) (uint32_t camera_handle, uint32_t ch_id,
    324                                        uint8_t num_streams, uint32_t *stream_ids);
    325     /* get super bufs. for burst mode only */
    326     int32_t (*request_super_buf) (uint32_t camera_handle,
    327                                   uint32_t ch_id,
    328                                   uint32_t num_buf_requested);
    329     /* abort the super buf dispatching. for burst mode only  */
    330     int32_t (*cancel_super_buf_request) (uint32_t camera_handle,
    331                                          uint32_t ch_id);
    332     /* start focus: by default sensor_idx=0 */
    333     int32_t (*start_focus) (uint32_t camera_handle,
    334                             uint32_t ch_id,
    335                             uint32_t sensor_idx,
    336                             uint32_t focus_mode);
    337     /* abort focus: by default sensor_idx=0 */
    338     int32_t (*abort_focus) (uint32_t camera_handle,
    339                             uint32_t ch_id,
    340                             uint32_t sensor_idx);
    341     /* prepare hardware will settle aec and flash.
    342      * by default sensor_idx=0 */
    343     int32_t (*prepare_snapshot) (uint32_t camera_handle,
    344                                  uint32_t ch_id,
    345                                  uint32_t sensor_idx);
    346     /* set a parm current value of a stream */
    347     int32_t (*set_stream_parm) (uint32_t camera_handle,
    348                                 uint32_t ch_id,
    349                                 uint32_t s_id,
    350                                 mm_camera_stream_parm_t parm_type,
    351                                 void *p_value);
    352     /* get a parm current value of a stream */
    353     int32_t (*get_stream_parm) (uint32_t camera_handle,
    354                                 uint32_t ch_id,
    355                                 uint32_t s_id,
    356                                 mm_camera_stream_parm_t parm_type,
    357                                 void *p_value);
    358     /* private communication tunnel */
    359     int32_t (*send_command) (uint32_t camera_handle,
    360                              mm_camera_cmd_type_t cmd_type,
    361                              uint32_t cmd_id,
    362                              uint32_t cmd_length,
    363                              void *cmd);
    364     /* open a re-process isp, return handler for repro isp (>0).
    365      * if failed, reutrn 0 */
    366     uint32_t (*open_repro_isp) (uint32_t camera_handle,
    367                                uint32_t ch_id,
    368                                mm_camera_repro_isp_type_t repro_isp_type);
    369     /* config the re-process isp */
    370     int32_t (*config_repro_isp) (uint32_t camera_handle,
    371                                  uint32_t ch_id,
    372                                  uint32_t repro_isp_handle,
    373                                  mm_camera_repro_isp_config_t *config);
    374     /* attach output stream to the re-process isp */
    375     int32_t (*attach_stream_to_repro_isp) (uint32_t camera_handle,
    376                                            uint32_t ch_id,
    377                                            uint32_t repro_isp_handle,
    378                                            uint32_t stream_id);
    379     /* start a re-process isp. */
    380     int32_t (*start_repro_isp) (uint32_t camera_handle,
    381                                 uint32_t ch_id,
    382                                 uint32_t repro_isp_handle,
    383                                 uint32_t stream_id);
    384     /* start a reprocess job for a src frame.
    385      * Only after repo_isp is started, reprocess API can be called */
    386     int32_t (*reprocess) (uint32_t camera_handle,
    387                           uint32_t ch_id,
    388                           uint32_t repro_isp_handle,
    389                           mm_camera_repro_data_t *repo_data);
    390     /* stop a re-process isp */
    391     int32_t (*stop_repro_isp) (uint32_t camera_handle,
    392                                uint32_t ch_id,
    393                                uint32_t repro_isp_handle,
    394                                uint32_t stream_id);
    395     /* detach an output stream from the re-process isp.
    396      * Can only be called after the re-process isp is stopped */
    397     int32_t (*detach_stream_from_repro_isp) (uint32_t camera_handle,
    398                                              uint32_t ch_id,
    399                                              uint32_t repro_isp_handle,
    400                                              uint32_t stream_id);
    401     /* close a re-process isp.
    402      * Can only close after all dest streams are detached from it */
    403     int32_t (*close_repro_isp) (uint32_t camera_handle,
    404                                 uint32_t ch_id,
    405                                 uint32_t repro_isp_handle);
    406 } mm_camera_ops_t;
    407 
    408 typedef struct {
    409     uint32_t camera_handle;        /* camera object handle */
    410     mm_camera_info_t *camera_info; /* reference pointer of camear info */
    411     mm_camera_ops_t *ops;          /* API call table */
    412 } mm_camera_vtbl_t;
    413 
    414 mm_camera_info_t * camera_query(uint8_t *num_cameras);
    415 mm_camera_vtbl_t * camera_open(uint8_t camera_idx,
    416                                mm_camear_mem_vtbl_t *mem_vtbl);
    417 
    418 //extern void mm_camera_util_profile(const char *str);
    419 
    420 typedef enum {
    421     MM_CAMERA_PREVIEW,
    422     MM_CAMERA_VIDEO,
    423     MM_CAMERA_SNAPSHOT_MAIN,
    424     MM_CAMERA_SNAPSHOT_THUMBNAIL,
    425     MM_CAMERA_SNAPSHOT_RAW,
    426     MM_CAMERA_RDI,
    427     MM_CAMERA_RDI1,
    428     MM_CAMERA_RDI2,
    429     MM_CAMERA_SAEC,
    430     MM_CAMERA_SAWB,
    431     MM_CAMERA_SAFC,
    432     MM_CAMERA_IHST,
    433     MM_CAMERA_CS,
    434     MM_CAMERA_RS,
    435     MM_CAMERA_CSTA,
    436     MM_CAMERA_ISP_PIX_OUTPUT1,
    437     MM_CAMERA_ISP_PIX_OUTPUT2,
    438     MM_CAMERA_IMG_MODE_MAX
    439 } mm_camera_img_mode;
    440 
    441 /* may remove later */
    442 typedef enum {
    443     MM_CAMERA_OP_MODE_NOTUSED,
    444     MM_CAMERA_OP_MODE_CAPTURE,
    445     MM_CAMERA_OP_MODE_VIDEO,
    446     MM_CAMERA_OP_MODE_ZSL,
    447     MM_CAMERA_OP_MODE_RAW,
    448     MM_CAMERA_OP_MODE_MAX
    449 } mm_camera_op_mode_type_t;
    450 
    451 #endif /*__MM_CAMERA_INTERFACE_H__*/
    452