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/ion.h>
     33 #include <linux/videodev2.h>
     34 #include <QCamera_Intf.h>
     35 
     36 #define MM_CAMERA_MAX_NUM_FRAMES 16
     37 #define MM_CAMEAR_MAX_STRAEM_BUNDLE 4
     38 #define MM_CAMERA_MAX_2ND_SENSORS 4
     39 
     40 typedef enum {
     41     MM_CAMERA_WHITE_BALANCE_AUTO,
     42     MM_CAMERA_WHITE_BALANCE_OFF,
     43     MM_CAMERA_WHITE_BALANCE_DAYLIGHT,
     44     MM_CAMERA_WHITE_BALANCE_INCANDESCENT,
     45     MM_CAMERA_WHITE_BALANCE_FLUORESCENT,
     46     MM_CAMERA_WHITE_BALANCE_CLOUDY,
     47     MM_CAMERA_WHITE_BALANCE_MAX
     48 } mm_camera_white_balance_mode_type_t;
     49 
     50 typedef enum {
     51     MM_CAMERA_STREAM_OFFSET,
     52     MM_CAMERA_STREAM_CID,
     53     MM_CAMERA_STREAM_CROP
     54 }mm_camera_stream_parm_t;
     55 
     56 typedef struct {
     57    int32_t width;
     58    int32_t height;
     59 } mm_camera_dimension_t;
     60 
     61 typedef struct{
     62     uint32_t tbl_size;
     63     struct camera_size_type *sizes_tbl;
     64 }default_sizes_tbl_t;
     65 
     66 typedef struct  {
     67     int32_t left;
     68     int32_t top;
     69     int32_t width;
     70     int32_t height;
     71 } mm_camera_rect_t;
     72 
     73 /* TBD: meta header needs to move to msm_camear.h */
     74 typedef enum {
     75     /* no meta data header used */
     76     MM_CAMEAR_META_DATA_TYPE_DEF,
     77     /* has focus flag, exposure idx,
     78      * flash flag, etc. TBD */
     79     MM_CAMEAR_META_DATA_TYPE_BRACKETING,
     80     MM_CAMEAR_META_DATA_TYPE_MAX,
     81 } mm_camera_meta_header_t;
     82 
     83 typedef struct {
     84     cam_format_t fmt;
     85     mm_camera_meta_header_t meta_header;
     86     uint32_t width;
     87     uint32_t height;
     88     uint8_t rotation;
     89 } mm_camera_image_fmt_t;
     90 
     91 typedef struct {
     92     /* image format */
     93     mm_camera_image_fmt_t fmt;
     94 
     95     /* num of buffers needed */
     96     uint8_t num_of_bufs;
     97 
     98     /* flag to indicate if this stream need stream on */
     99     uint8_t need_stream_on;
    100 } mm_camera_stream_config_t;
    101 
    102 typedef struct {
    103     uint8_t name[32];
    104     int32_t min_value;
    105     int32_t max_value;
    106     int32_t step;
    107     int32_t default_value;
    108 } mm_camera_ctrl_cap_sharpness_t;
    109 
    110 typedef struct {
    111     int16_t *zoom_ratio_tbl;
    112     int32_t size;
    113 } mm_camera_zoom_tbl_t;
    114 
    115 typedef enum {
    116     /* ZSL use case: get burst of frames */
    117     MM_CAMERA_SUPER_BUF_NOTIFY_BURST = 0,
    118     /* get continuous frames: when the super buf is
    119      * ready dispatch it to HAL */
    120     MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS,
    121     MM_CAMERA_SUPER_BUF_NOTIFY_MAX
    122 }mm_camera_super_buf_notify_mode_t;
    123 
    124 typedef enum {
    125     /* save the frame. No matter focused or not */
    126     MM_CAMERA_SUPER_BUF_PRIORITY_NORMAL = 0,
    127     /* only queue the frame that is focused. Will enable
    128      * meta data header to carry focus info*/
    129     MM_CAMERA_SUPER_BUF_PRIORITY_FOCUS,
    130     /* after shutter, only queue matched exposure index */
    131     MM_CAMERA_SUPER_BUF_PRIORITY_EXPOSURE_BRACKETING,
    132     MM_CAMERA_SUPER_BUF_PRIORITY_MAX
    133 }mm_camera_super_buf_priority_t;
    134 
    135 typedef struct {
    136     mm_camera_super_buf_notify_mode_t notify_mode;
    137     /* queue depth. Only for burst mode */
    138     uint8_t water_mark;
    139     /* look back how many frames from last buf */
    140     uint8_t look_back;
    141     /* after send first frame to HAL, how many frames
    142      * needing to be skipped for next delivery? */
    143     uint8_t post_frame_skip;
    144     /* save matched priority frames only */
    145     mm_camera_super_buf_priority_t priority;
    146     /* in burst mode, how many super
    147      * bufs for each shutter press? */
    148     uint8_t burst_num;
    149 } mm_camera_bundle_attr_t;
    150 
    151 typedef struct {
    152     uint8_t camera_id;                   /* camera id */
    153     qcamera_info_t camera_info;           /* postion, mount_angle, etc. */
    154     enum sensor_type_t main_sensor_type; /* BAYER, YUV, JPEG_SOC, etc. */
    155     char *video_dev_name;                /* device node name, e.g. /dev/video1 */
    156 } mm_camera_info_t;
    157 
    158 typedef struct {
    159   uint8_t cid;
    160   uint8_t dt;
    161 }stream_cid_t;
    162 
    163 /* the stats struct will need rework after
    164  * defining the stats buf sharing logic */
    165 typedef struct {
    166     int type;
    167     uint32_t length;
    168     void *value;
    169 } mm_camera_stats_t;
    170 
    171 typedef struct {
    172     uint32_t stream_id; /* stream handler */
    173     int8_t buf_idx; /* buf idx within the stream bufs */
    174 
    175     struct timespec ts; /* time stamp, to be filled when DQBUF*/
    176     uint32_t frame_idx; /* frame sequence num, to be filled when DQBUF */
    177 
    178     int8_t num_planes; /* num of planes, to be filled during mem allocation */
    179     struct v4l2_plane planes[VIDEO_MAX_PLANES]; /* plane info, to be filled during mem allocation*/
    180     int fd; /* fd of the frame, to be filled during mem allocation */
    181     void* buffer; /* ptr to real frame buffer, to be filled during mem allocation */
    182     uint32_t frame_len; /* len of the whole frame, to be filled during mem allocation */
    183 } mm_camera_buf_def_t;
    184 
    185 typedef struct {
    186     uint32_t camera_handle;
    187     uint32_t ch_id;
    188     uint8_t num_bufs;
    189     mm_camera_buf_def_t* bufs[MM_CAMEAR_MAX_STRAEM_BUNDLE];
    190 } mm_camera_super_buf_t;
    191 
    192 typedef void (*mm_camera_event_notify_t)(uint32_t camera_handle,
    193                                          mm_camera_event_t *evt,
    194                                          void *user_data);
    195 
    196 typedef void (*mm_camera_buf_notify_t) (mm_camera_super_buf_t *bufs,
    197                                         void *user_data);
    198 typedef cam_frame_len_offset_t mm_camera_frame_len_offset;
    199 
    200 typedef struct {
    201   void *user_data;
    202   int32_t (*get_buf) (uint32_t camera_handle,
    203                       uint32_t ch_id, uint32_t stream_id,
    204                       void *user_data,
    205                       mm_camera_frame_len_offset *frame_offset_info,
    206                       uint8_t num_bufs,
    207                       uint8_t *initial_reg_flag,
    208                       mm_camera_buf_def_t *bufs);
    209   int32_t (*put_buf) (uint32_t camera_handle,
    210                       uint32_t ch_id, uint32_t stream_id,
    211                       void *user_data, uint8_t num_bufs,
    212                       mm_camera_buf_def_t *bufs);
    213 } mm_camear_mem_vtbl_t;
    214 
    215 typedef struct {
    216     uint8_t num_2nd_sensors;
    217     uint8_t sensor_idxs[MM_CAMERA_MAX_2ND_SENSORS];
    218 } mm_camera_2nd_sensor_t;
    219 
    220 typedef struct {
    221 	int32_t (*sync) (uint32_t camera_handle);
    222 	uint8_t (*is_event_supported) (uint32_t camera_handle,
    223                                  mm_camera_event_type_t evt_type);
    224     int32_t (*register_event_notify) (uint32_t camera_handle,
    225                                  mm_camera_event_notify_t evt_cb,
    226                                  void * user_data,
    227                                  mm_camera_event_type_t evt_type);
    228     int32_t (*qbuf) (uint32_t camera_handle, uint32_t ch_id,
    229                                  mm_camera_buf_def_t *buf);
    230     void (*camera_close) (uint32_t camera_handle);
    231     /* Only fo supporting advanced 2nd sensors. If no secondary sensor needed
    232      * HAL can ignore this function */
    233     mm_camera_2nd_sensor_t * (*query_2nd_sensor_info) (uint32_t camera_handle);
    234     /* if the parm is supported: TRUE - support, FALSE - not support */
    235     int32_t (*is_parm_supported) (uint32_t camera_handle,
    236                                  mm_camera_parm_type_t parm_type,
    237                                  uint8_t *support_set_parm,
    238                                  uint8_t *support_get_parm);
    239     /* set a parms current value */
    240     int32_t (*set_parm) (uint32_t camera_handle,
    241                          mm_camera_parm_type_t parm_type,
    242                          void* p_value);
    243     /* get a parms current value */
    244     int32_t (*get_parm) (uint32_t camera_handle,
    245                          mm_camera_parm_type_t parm_type,
    246                          void* p_value);
    247     /* ch_id returned, zero is invalid ch_id */
    248     uint32_t (*ch_acquire) (uint32_t camera_handle);
    249     /* relaese channel */
    250     void (*ch_release) (uint32_t camera_handle, uint32_t ch_id);
    251     /* return stream_id. zero is invalid stream_id
    252      * default set to preview: ext_image_mode = 0
    253      * default set to primary sensor: sensor_idx = 0
    254      * value of ext_image_mode is defined in msm_camera.h
    255      */
    256     uint32_t (*add_stream) (uint32_t camera_handle, uint32_t ch_id,
    257                            mm_camera_buf_notify_t buf_cb, void *user_data,
    258                            uint32_t ext_image_mode, uint32_t sensor_idx);
    259     /* delete stream */
    260     int32_t (*del_stream) (uint32_t camera_handle, uint32_t ch_id,
    261                            uint32_t stream_id);
    262     /* set straem format This will trigger getting bufs from HAL */
    263     int32_t (*config_stream) (uint32_t camera_handle, uint32_t ch_id,
    264                               uint32_t stream_id,
    265                               mm_camera_stream_config_t *config);
    266     /* setup super buf bundle for ZSL */
    267     int32_t (*init_stream_bundle) (uint32_t camera_handle, uint32_t ch_id,
    268                                    mm_camera_buf_notify_t super_frame_notify_cb,
    269                                    void *user_data,  mm_camera_bundle_attr_t *attr,
    270                                    uint8_t num_streams, uint32_t *stream_ids);
    271     /* remove the super buf bundle */
    272     int32_t (*destroy_stream_bundle) (uint32_t camera_handle, uint32_t ch_id);
    273     /* start streaming */
    274     int32_t (*start_streams) (uint32_t camera_handle, uint32_t ch_id,
    275                               uint8_t num_streams, uint32_t *stream_ids);
    276     /* stop streaming */
    277     int32_t (*stop_streams) (uint32_t camera_handle, uint32_t ch_id,
    278                              uint8_t num_streams, uint32_t *stream_ids);
    279     /* tear down streams asyncly */
    280     int32_t (*async_teardown_streams) (uint32_t camera_handle, uint32_t ch_id,
    281                                        uint8_t num_streams, uint32_t *stream_ids);
    282     /* get super bufs. for burst mode only */
    283     int32_t (*request_super_buf) (uint32_t camera_handle, uint32_t ch_id);
    284     /* abort the super buf dispatching. for burst mode only  */
    285     int32_t (*cancel_super_buf_request) (uint32_t camera_handle,
    286                                          uint32_t ch_id);
    287     /* start focus: by default sensor_idx=0 */
    288     int32_t (*start_focus) (uint32_t camera_handle,
    289                             uint32_t ch_id,
    290                             uint32_t sensor_idx,
    291                             uint32_t focus_mode);
    292     /* abort focus: by default sensor_idx=0 */
    293     int32_t (*abort_focus) (uint32_t camera_handle,
    294                             uint32_t ch_id,
    295                             uint32_t sensor_idx);
    296     /* prepare hardware will settle aec and flash.
    297      * by default sensor_idx=0 */
    298     int32_t (*prepare_snapshot) (uint32_t camera_handle,
    299                                  uint32_t ch_id,
    300                                  uint32_t sensor_idx);
    301     /* set a parms current value */
    302     int32_t (*set_stream_parm) (uint32_t camera_handle,
    303                                 uint32_t ch_id,
    304                                 uint32_t s_id,
    305                                 mm_camera_stream_parm_t parm_type,
    306                                 void* p_value);
    307     /* get a parms current value */
    308     int32_t (*get_stream_parm) (uint32_t camera_handle,
    309                                 uint32_t ch_id,
    310                                 uint32_t s_id,
    311                                 mm_camera_stream_parm_t parm_type,
    312                                 void* p_value);
    313 } mm_camera_ops_t;
    314 
    315 typedef struct {
    316     uint32_t camera_handle;        /* camera object handle */
    317     mm_camera_info_t *camera_info; /* reference pointer of camear info */
    318     mm_camera_ops_t *ops;          /* API call table */
    319 } mm_camera_vtbl_t;
    320 
    321 mm_camera_info_t * camera_query(uint8_t *num_cameras);
    322 mm_camera_vtbl_t * camera_open(uint8_t camera_idx,
    323                                mm_camear_mem_vtbl_t *mem_vtbl);
    324 
    325 typedef enum {
    326     MM_CAMERA_PREVIEW,
    327     MM_CAMERA_VIDEO,
    328     MM_CAMERA_SNAPSHOT_MAIN,
    329     MM_CAMERA_SNAPSHOT_THUMBNAIL,
    330     MM_CAMERA_SNAPSHOT_RAW,
    331     MM_CAMERA_RDI
    332 }mm_camera_img_mode;
    333 
    334 /* may remove later */
    335 typedef enum {
    336     MM_CAMERA_OP_MODE_NOTUSED,
    337     MM_CAMERA_OP_MODE_CAPTURE,
    338     MM_CAMERA_OP_MODE_VIDEO,
    339     MM_CAMERA_OP_MODE_ZSL,
    340     MM_CAMERA_OP_MODE_MAX
    341 } mm_camera_op_mode_type_t;
    342 #endif /*__MM_CAMERA_INTERFACE_H__*/
    343