Home | History | Annotate | Download | only in common
      1 /* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
      2  *
      3  * Redistribution and use in source and binary forms, with or without
      4  * modification, are permitted provided that the following conditions are
      5  * met:
      6  *     * Redistributions of source code must retain the above copyright
      7  *       notice, this list of conditions and the following disclaimer.
      8  *     * Redistributions in binary form must reproduce the above
      9  *       copyright notice, this list of conditions and the following
     10  *       disclaimer in the documentation and/or other materials provided
     11  *       with the distribution.
     12  *     * Neither the name of The Linux Foundation nor the names of its
     13  *       contributors may be used to endorse or promote products derived
     14  *       from this software without specific prior written permission.
     15  *
     16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
     17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  *
     28  */
     29 
     30 #ifndef __MM_CAMERA_INTERFACE_H__
     31 #define __MM_CAMERA_INTERFACE_H__
     32 
     33 // System dependencies
     34 #include <media/msmb_camera.h>
     35 
     36 // Camera dependencies
     37 #include "cam_intf.h"
     38 #include "cam_queue.h"
     39 
     40 #define MM_CAMERA_MAX_NUM_SENSORS MSM_MAX_CAMERA_SENSORS
     41 #define MM_CAMERA_MAX_NUM_FRAMES CAM_MAX_NUM_BUFS_PER_STREAM
     42 
     43 /* num of channels allowed in a camera obj */
     44 #define MM_CAMERA_CHANNEL_MAX 16
     45 
     46 #define PAD_TO_SIZE(size, padding) \
     47         ((size + (typeof(size))(padding - 1)) & \
     48         (typeof(size))(~(padding - 1)))
     49 
     50 #define CEIL_DIVISION(n, d) ((n+d-1)/d)
     51 
     52 /*Bit shift to reach next camera in camera handle*/
     53 #define MM_CAMERA_HANDLE_SHIFT_MASK       16
     54 #define MM_CAMERA_HANDLE_BIT_MASK         0x0000ffff
     55 
     56 typedef enum {
     57     MM_CAMERA_TYPE_MAIN       = CAM_TYPE_MAIN,
     58     MM_CAMERA_TYPE_AUX        = CAM_TYPE_AUX,
     59 } mm_camera_obj_type;
     60 
     61 #define MM_CAMERA_DUAL_CAM (MM_CAMERA_TYPE_MAIN | MM_CAMERA_TYPE_AUX)
     62 #define MM_CAMERA_MAX_CAM_CNT 2
     63 
     64 /** CAM_DUMP_TO_FILE:
     65  *  @filename: file name
     66  *  @name:filename
     67  *  @index: index of the file
     68  *  @extn: file extension
     69  *  @p_addr: address of the buffer
     70  *  @len: buffer length
     71  *
     72  *  dump the image to the file
     73  **/
     74 #define CAM_DUMP_TO_FILE(path, name, index, extn, p_addr, len) ({ \
     75   size_t rc = 0; \
     76   char filename[FILENAME_MAX]; \
     77   if (index >= 0) \
     78     snprintf(filename, FILENAME_MAX, "%s/%s%d.%s", path, name, index, extn); \
     79   else \
     80     snprintf(filename, FILENAME_MAX, "%s/%s.%s", path, name, extn); \
     81   FILE *fp = fopen(filename, "w+"); \
     82   if (fp) { \
     83     rc = fwrite(p_addr, 1, len, fp); \
     84     LOGE("written size %d", len); \
     85     fclose(fp); \
     86   } else { \
     87     LOGE("open %s failed", filename); \
     88   } \
     89 })
     90 
     91 /* Declaring Buffer structure */
     92 struct mm_camera_buf_def;
     93 
     94 /** mm_camera_plane_def_t : structure for frame plane info
     95 *    @num_planes : num of planes for the frame buffer, to be
     96 *               filled during mem allocation
     97 *    @planes : plane info for the frame buffer, to be filled
     98 *               during mem allocation
     99 **/
    100 typedef struct {
    101     int8_t num_planes;
    102     struct v4l2_plane planes[VIDEO_MAX_PLANES];
    103 } mm_camera_plane_buf_def_t;
    104 
    105 /** mm_camera_user_buf_def_t : structure for frame plane info
    106 *    @num_buffers : num of buffers in this user defined structure
    107 *    @bufs_used : actual number of buffer filled
    108 *    @buf_in_use : flag to notify buffer usage status.
    109 *    @plane_buf : Plane buffer array pointer.
    110 **/
    111 typedef struct {
    112     uint8_t num_buffers;
    113     uint8_t bufs_used;     /*Num of Buffer filled by Kernel*/
    114     uint8_t buf_in_use;  /* Container buffer is freed to fill*/
    115     int32_t buf_idx[MSM_CAMERA_MAX_USER_BUFF_CNT];
    116     struct mm_camera_buf_def *plane_buf;
    117 } mm_camera_user_buf_def_t;
    118 
    119 /** mm_camera_buf_def_t: structure for stream frame buf
    120 *    @stream_id : stream handler to uniquely identify a stream
    121 *               object
    122 *    @buf_idx : index of the buf within the stream bufs, to be
    123 *               filled during mem allocation
    124 *    @timespec_ts : time stamp, to be filled when DQBUF is
    125 *                 called
    126 *    @frame_idx : frame sequence num, to be filled when DQBUF
    127 *    @plane_buf  : Frame plane definition
    128 *    @fd : file descriptor of the frame buffer, to be filled
    129 *        during mem allocation
    130 *    @buffer : pointer to the frame buffer, to be filled during
    131 *            mem allocation
    132 *    @frame_len : length of the whole frame, to be filled during
    133 *               mem allocation
    134 *    @mem_info : user specific pointer to additional mem info
    135 *    @flags:  v4l2_buffer flags, used to report error in data buffers
    136 **/
    137 typedef struct mm_camera_buf_def {
    138     uint32_t stream_id;
    139     cam_stream_type_t stream_type;
    140     cam_stream_buf_type buf_type;
    141     uint32_t buf_idx;
    142     uint8_t is_uv_subsampled;
    143     struct timespec ts;
    144     uint32_t frame_idx;
    145     union {
    146         mm_camera_plane_buf_def_t planes_buf;
    147         mm_camera_user_buf_def_t user_buf;
    148     };
    149     int fd;
    150     void *buffer;
    151     size_t frame_len;
    152     void *mem_info;
    153     uint32_t flags;
    154 } mm_camera_buf_def_t;
    155 
    156 /** mm_camera_super_buf_t: super buf structure for bundled
    157 *   stream frames
    158 *    @camera_handle : camera handler to uniquely identify
    159 *              a camera object
    160 *    @ch_id : channel handler to uniquely ideentify a channel
    161 *           object
    162 *    @num_bufs : number of buffers in the super buf, should not
    163 *              exceeds MAX_STREAM_NUM_IN_BUNDLE
    164 *    @bufs : array of buffers in the bundle
    165 **/
    166 typedef struct {
    167     uint32_t camera_handle;
    168     uint32_t ch_id;
    169     uint32_t num_bufs;
    170     uint8_t bUnlockAEC;
    171     uint8_t bReadyForPrepareSnapshot;
    172     mm_camera_buf_def_t* bufs[MAX_STREAM_NUM_IN_BUNDLE];
    173 } mm_camera_super_buf_t;
    174 
    175 /** mm_camera_req_buf_type_t
    176 * Request type for super buf from channel
    177 **/
    178 typedef enum {
    179     MM_CAMERA_REQ_SUPER_BUF,
    180     MM_CAMERA_REQ_FRAME_SYNC_BUF
    181 } mm_camera_req_buf_type_t;
    182 
    183 /** mm_camera_req_buf_t: Attributes for super buf request
    184 *
    185 *    @type : type of super buf requested
    186 *    @num_buf_requested : num of super bufs requested
    187 *    @num_retro_buf_requested : number of retro bufs requested
    188 *    @primary_only : specifies if only primary camera frame for a dual
    189 *     camera is requested
    190 **/
    191 typedef struct {
    192     mm_camera_req_buf_type_t type;
    193     uint32_t num_buf_requested;
    194     uint32_t num_retro_buf_requested;
    195     uint8_t primary_only;
    196     uint32_t frame_idx; //Client can request frameId to pick from ZSL queue
    197 } mm_camera_req_buf_t;
    198 
    199 typedef cam_event_t mm_camera_event_t;
    200 
    201 /** mm_camera_event_notify_t: function definition for event
    202 *   notify handling
    203 *    @camera_handle : camera handler
    204 *    @evt : pointer to an event struct
    205 *    @user_data: user data pointer
    206 **/
    207 typedef void (*mm_camera_event_notify_t)(uint32_t camera_handle,
    208                                          mm_camera_event_t *evt,
    209                                          void *user_data);
    210 
    211 /** mm_camera_buf_notify_t: function definition for frame notify
    212 *   handling
    213 *    @mm_camera_super_buf_t : received frame buffers
    214 *    @user_data: user data pointer
    215 **/
    216 typedef void (*mm_camera_buf_notify_t) (mm_camera_super_buf_t *bufs,
    217                                         void *user_data);
    218 
    219 /** map_stream_buf_op_t: function definition for operation of
    220 *   mapping stream buffers via domain socket
    221 *    @frame_idx : buffer index within stream buffers
    222 *    @plane_idx    : plane index. If all planes share the same
    223 *                   fd, plane_idx = -1; otherwise, plean_idx is
    224 *                   the index to plane (0..num_of_planes)
    225 *    @fd : file descriptor of the stream buffer
    226 *    @size: size of the stream buffer
    227 *    @buffer: Pointer to buffer to register
    228 *    @userdata : user data pointer
    229 **/
    230 typedef int32_t (*map_stream_buf_op_t) (uint32_t frame_idx,
    231                                         int32_t plane_idx,
    232                                         int fd,
    233                                         size_t size,
    234                                         void *buffer,
    235                                         cam_mapping_buf_type type,
    236                                         void *userdata);
    237 
    238 typedef int32_t (*map_stream_bufs_op_t) (const cam_buf_map_type_list *buf_map_list,
    239                                          void *userdata);
    240 
    241 /** unmap_stream_buf_op_t: function definition for operation of
    242 *                          unmapping stream buffers via domain
    243 *                          socket
    244 *    @frame_idx : buffer index within stream buffers
    245 *    @plane_idx : plane index. If all planes share the same
    246 *                 fd, plane_idx = -1; otherwise, plean_idx is
    247 *                 the index to plane (0..num_of_planes)
    248 *    @userdata : user data pointer
    249 **/
    250 typedef int32_t (*unmap_stream_buf_op_t) (uint32_t frame_idx,
    251                                           int32_t plane_idx,
    252                                           cam_mapping_buf_type type,
    253                                           void *userdata);
    254 
    255 /** mm_camera_map_unmap_ops_tbl_t: virtual table
    256 *                      for mapping/unmapping stream buffers via
    257 *                      domain socket
    258 *    @map_ops : operation for mapping
    259 *    @unmap_ops : operation for unmapping
    260 *    @userdata: user data pointer
    261 **/
    262 typedef struct {
    263     map_stream_buf_op_t map_ops;
    264     map_stream_bufs_op_t bundled_map_ops;
    265     unmap_stream_buf_op_t unmap_ops;
    266     void *userdata;
    267 } mm_camera_map_unmap_ops_tbl_t;
    268 
    269 /** mm_camera_stream_mem_vtbl_t: virtual table for stream
    270 *                      memory allocation and deallocation
    271 *    @get_bufs : function definition for allocating
    272 *                stream buffers
    273 *    @put_bufs : function definition for deallocating
    274 *                stream buffers
    275 *    @user_data: user data pointer
    276 **/
    277 typedef struct {
    278   void *user_data;
    279   int32_t (*set_config_ops) (mm_camera_map_unmap_ops_tbl_t *ops_tbl,
    280           void *user_data);
    281   int32_t (*get_bufs) (cam_frame_len_offset_t *offset,
    282                        uint8_t *num_bufs,
    283                        uint8_t **initial_reg_flag,
    284                        mm_camera_buf_def_t **bufs,
    285                        mm_camera_map_unmap_ops_tbl_t *ops_tbl,
    286                        void *user_data);
    287   int32_t (*put_bufs) (mm_camera_map_unmap_ops_tbl_t *ops_tbl,
    288                        void *user_data);
    289   int32_t (*invalidate_buf)(uint32_t index, void *user_data);
    290   int32_t (*clean_invalidate_buf)(uint32_t index, void *user_data);
    291 } mm_camera_stream_mem_vtbl_t;
    292 
    293 /** mm_camera_stream_config_t: structure for stream
    294 *                              configuration
    295 *    @stream_info : pointer to a stream info structure
    296 *    @padding_info: padding info obtained from querycapability
    297 *    @mem_tbl : memory operation table for
    298 *              allocating/deallocating stream buffers
    299 *    @stream_cb_sync : SYNC callback handling stream frame notify
    300 *    @stream_cb : ASYNC callback handling stream frame notify
    301 *    @userdata : user data pointer
    302 **/
    303 typedef struct {
    304     cam_stream_info_t *stream_info;
    305     cam_padding_info_t padding_info;
    306     mm_camera_stream_mem_vtbl_t mem_vtbl;
    307     mm_camera_buf_notify_t stream_cb_sync;
    308     mm_camera_buf_notify_t stream_cb;
    309     void *userdata;
    310 } mm_camera_stream_config_t;
    311 
    312 /** mm_camera_super_buf_notify_mode_t: enum for super uffer
    313 *                                      notification mode
    314 *    @MM_CAMERA_SUPER_BUF_NOTIFY_BURST :
    315 *       ZSL use case: get burst of frames
    316 *    @MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS :
    317 *       get continuous frames: when the super buf is ready
    318 *       dispatch it to HAL
    319 **/
    320 typedef enum {
    321     MM_CAMERA_SUPER_BUF_NOTIFY_BURST = 0,
    322     MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS,
    323     MM_CAMERA_SUPER_BUF_NOTIFY_MAX
    324 } mm_camera_super_buf_notify_mode_t;
    325 
    326 /** mm_camera_super_buf_priority_t: enum for super buffer
    327 *                                   matching priority
    328 *    @MM_CAMERA_SUPER_BUF_PRIORITY_NORMAL :
    329 *       Save the frame no matter focused or not. Currently only
    330 *       this type is supported.
    331 *    @MM_CAMERA_SUPER_BUF_PRIORITY_FOCUS :
    332 *       only queue the frame that is focused. Will enable meta
    333 *       data header to carry focus info
    334 *    @MM_CAMERA_SUPER_BUF_PRIORITY_EXPOSURE_BRACKETING :
    335 *       after shutter, only queue matched exposure index
    336 **/
    337 typedef enum {
    338     MM_CAMERA_SUPER_BUF_PRIORITY_NORMAL = 0,
    339     MM_CAMERA_SUPER_BUF_PRIORITY_FOCUS,
    340     MM_CAMERA_SUPER_BUF_PRIORITY_EXPOSURE_BRACKETING,
    341     MM_CAMERA_SUPER_BUF_PRIORITY_LOW,/* Bundled metadata frame may not match*/
    342     MM_CAMERA_SUPER_BUF_PRIORITY_MAX
    343 } mm_camera_super_buf_priority_t;
    344 
    345 /** mm_camera_advanced_capture_t: enum for advanced capture type.
    346 *    @MM_CAMERA_AF_BRACKETING :
    347 *       to enable AF Bracketig.
    348 *    @MM_CAMERA_AE_BRACKETING :
    349 *       to enable AF Bracketing.
    350 *    @MM_CAMERA_FLASH_BRACKETING :
    351 *       to enable Flash Bracketing.
    352 *    @MM_CAMERA_ZOOM_1X :
    353 *       to enable zoom 1x capture request
    354 **/
    355 typedef enum {
    356    MM_CAMERA_AF_BRACKETING = 0,
    357    MM_CAMERA_AE_BRACKETING,
    358    MM_CAMERA_FLASH_BRACKETING,
    359    MM_CAMERA_ZOOM_1X,
    360    MM_CAMERA_FRAME_CAPTURE,
    361 } mm_camera_advanced_capture_t;
    362 
    363 /** mm_camera_stream_cb_type: enum for stream buffer callback type.
    364 *    @MM_CAMERA_STREAM_CB_TYPE_ASYNC :
    365 *       callback is async type. buffer process done in client thread context
    366 *    @MM_CAMERA_STREAM_CB_TYPE_SYNC :
    367 *       callback is sync type. buffer process done interface thread context
    368 **/
    369 typedef enum {
    370     MM_CAMERA_STREAM_CB_TYPE_ASYNC,
    371     MM_CAMERA_STREAM_CB_TYPE_SYNC,
    372 } mm_camera_stream_cb_type;
    373 
    374 
    375 /** mm_camera_channel_attr_t: structure for defining channel
    376 *                             attributes
    377 *    @notify_mode : notify mode: burst or continuous
    378 *    @water_mark : queue depth. Only valid for burst mode
    379 *    @look_back : look back how many frames from last buf.
    380 *                 Only valid for burst mode
    381 *    @post_frame_skip : after send first frame to HAL, how many
    382 *                     frames needing to be skipped for next
    383 *                     delivery. Only valid for burst mode
    384 *    @max_unmatched_frames : max number of unmatched frames in
    385 *                     queue
    386 *    @enable_frame_sync: Enables frame sync for dual camera
    387 *    @priority : save matched priority frames only
    388 *    @user_expected_frame_id : Number of frames, camera interface
    389 *                     will wait for getting the instant capture frame.
    390 **/
    391 typedef struct {
    392     mm_camera_super_buf_notify_mode_t notify_mode;
    393     uint8_t water_mark;
    394     uint8_t look_back;
    395     uint8_t post_frame_skip;
    396     uint8_t max_unmatched_frames;
    397     uint8_t enable_frame_sync;
    398     mm_camera_super_buf_priority_t priority;
    399     uint8_t user_expected_frame_id;
    400 } mm_camera_channel_attr_t;
    401 
    402 /** mm_camera_intf_frame_sync_t: structure to register frame sync
    403 *    @camera_handle  : camera handle to be syced
    404 *    @ch_id          : channel id to be synced
    405 *    @stream_id      : stream id to be synced
    406 *    @max_unmatched_frames : Frames to wait for before frame callback
    407 *    @buf_cb         : callback. can be NULL. NULL uses already registered stream/channel cb
    408 *    @userdata       : client objects.
    409 **/
    410 typedef struct {
    411     uint32_t camera_handle;
    412     uint32_t ch_id;
    413     uint32_t stream_id;
    414     uint8_t max_unmatched_frames;
    415     mm_camera_buf_notify_t buf_cb;
    416     void *userdata;
    417 } mm_camera_intf_frame_sync_t;
    418 
    419 typedef struct {
    420     /** query_capability: fucntion definition for querying static
    421      *                    camera capabilities
    422      *    @camera_handle : camer handler
    423      *  Return value: 0 -- success
    424      *                -1 -- failure
    425      *  Note: would assume cam_capability_t is already mapped
    426      **/
    427     int32_t (*query_capability) (uint32_t camera_handle);
    428 
    429     /** register_event_notify: fucntion definition for registering
    430      *                         for event notification
    431      *    @camera_handle : camer handler
    432      *    @evt_cb : callback for event notify
    433      *    @user_data : user data poiner
    434      *  Return value: 0 -- success
    435      *                -1 -- failure
    436      **/
    437     int32_t (*register_event_notify) (uint32_t camera_handle,
    438                                       mm_camera_event_notify_t evt_cb,
    439                                       void *user_data);
    440 
    441     /** close_camera: fucntion definition for closing a camera
    442      *    @camera_handle : camer handler
    443      *  Return value: 0 -- success
    444      *                -1 -- failure
    445      **/
    446     int32_t (*close_camera) (uint32_t camera_handle);
    447 
    448     /** map_buf: fucntion definition for mapping a camera buffer
    449      *           via domain socket
    450      *    @camera_handle : camer handler
    451      *    @buf_type : type of mapping buffers, can be value of
    452      *                CAM_MAPPING_BUF_TYPE_CAPABILITY
    453      *                CAM_MAPPING_BUF_TYPE_SETPARM_BUF
    454      *                CAM_MAPPING_BUF_TYPE_GETPARM_BUF
    455      *    @fd : file descriptor of the stream buffer
    456      *    @size :  size of the stream buffer
    457      *  Return value: 0 -- success
    458      *                -1 -- failure
    459      **/
    460     int32_t (*map_buf) (uint32_t camera_handle,
    461                         uint8_t buf_type,
    462                         int fd,
    463                         size_t size,
    464                         void *buffer);
    465 
    466     /** map_bufs: function definition for mapping multiple camera buffers
    467      *           via domain socket
    468      *    @camera_handle : camera handler
    469      *    @buf_map_list : list of buffers to map
    470      *  Return value: 0 -- success
    471      *                -1 -- failure
    472      **/
    473     int32_t (*map_bufs) (uint32_t camera_handle,
    474                          const cam_buf_map_type_list *buf_map_list);
    475 
    476     /** unmap_buf: fucntion definition for unmapping a camera buffer
    477      *           via domain socket
    478      *    @camera_handle : camer handler
    479      *    @buf_type : type of mapping buffers, can be value of
    480      *                CAM_MAPPING_BUF_TYPE_CAPABILITY
    481      *                CAM_MAPPING_BUF_TYPE_SETPARM_BUF
    482      *                CAM_MAPPING_BUF_TYPE_GETPARM_BUF
    483      *  Return value: 0 -- success
    484      *                -1 -- failure
    485      **/
    486     int32_t (*unmap_buf) (uint32_t camera_handle,
    487                           uint8_t buf_type);
    488 
    489     /** set_parms: fucntion definition for setting camera
    490      *             based parameters to server
    491      *    @camera_handle : camer handler
    492      *    @parms : batch for parameters to be set, stored in
    493      *               parm_buffer_t
    494      *  Return value: 0 -- success
    495      *                -1 -- failure
    496      *  Note: would assume parm_buffer_t is already mapped, and
    497      *       according parameter entries to be set are filled in the
    498      *       buf before this call
    499      **/
    500     int32_t (*set_parms) (uint32_t camera_handle,
    501                           parm_buffer_t *parms);
    502 
    503     /** get_parms: fucntion definition for querying camera
    504      *             based parameters from server
    505      *    @camera_handle : camer handler
    506      *    @parms : batch for parameters to be queried, stored in
    507      *               parm_buffer_t
    508      *  Return value: 0 -- success
    509      *                -1 -- failure
    510      *  Note: would assume parm_buffer_t is already mapped, and
    511      *       according parameter entries to be queried are filled in
    512      *       the buf before this call
    513      **/
    514     int32_t (*get_parms) (uint32_t camera_handle,
    515                           parm_buffer_t *parms);
    516 
    517     /** do_auto_focus: fucntion definition for performing auto focus
    518      *    @camera_handle : camer handler
    519      *  Return value: 0 -- success
    520      *                -1 -- failure
    521      *  Note: if this call success, we will always assume there will
    522      *        be an auto_focus event following up.
    523      **/
    524     int32_t (*do_auto_focus) (uint32_t camera_handle);
    525 
    526     /** cancel_auto_focus: fucntion definition for cancelling
    527      *                     previous auto focus request
    528      *    @camera_handle : camer handler
    529     *  Return value: 0 -- success
    530     *                -1 -- failure
    531      **/
    532     int32_t (*cancel_auto_focus) (uint32_t camera_handle);
    533 
    534     /** prepare_snapshot: fucntion definition for preparing hardware
    535      *                    for snapshot.
    536      *    @camera_handle : camer handler
    537      *    @do_af_flag    : flag indicating if AF needs to be done
    538      *                     0 -- no AF needed
    539      *                     1 -- AF needed
    540      *  Return value: 0 -- success
    541      *                -1 -- failure
    542      **/
    543     int32_t (*prepare_snapshot) (uint32_t camera_handle,
    544                                  int32_t do_af_flag);
    545 
    546     /** start_zsl_snapshot: function definition for starting
    547      *                    zsl snapshot.
    548      *    @camera_handle : camer handler
    549      *    @ch_id         : channel id
    550      *  Return value: 0 -- success
    551      *                -1 -- failure
    552      **/
    553     int32_t (*start_zsl_snapshot) (uint32_t camera_handle, uint32_t ch_id);
    554 
    555     /** stop_zsl_snapshot: function definition for stopping
    556      *                    zsl snapshot.
    557      *    @camera_handle : camer handler
    558      *    @ch_id         : channel id
    559      *  Return value: 0 -- success
    560      *                -1 -- failure
    561      **/
    562     int32_t (*stop_zsl_snapshot) (uint32_t camera_handle, uint32_t ch_id);
    563 
    564     /** add_channel: fucntion definition for adding a channel
    565      *    @camera_handle : camer handler
    566      *    @ch_id : channel handler
    567      *    @attr : pointer to channel attribute structure
    568      *    @channel_cb : callbak to handle bundled super buffer
    569      *    @userdata : user data pointer
    570      *  Return value: channel id, zero is invalid ch_id
    571      * Note: attr, channel_cb, and userdata can be NULL if no
    572      *       superbufCB is needed
    573      **/
    574     uint32_t (*add_channel) (uint32_t camera_handle,
    575                              mm_camera_channel_attr_t *attr,
    576                              mm_camera_buf_notify_t channel_cb,
    577                              void *userdata);
    578 
    579     /** delete_channel: fucntion definition for deleting a channel
    580      *    @camera_handle : camer handler
    581      *    @ch_id : channel handler
    582      *  Return value: 0 -- success
    583      *                -1 -- failure
    584      **/
    585     int32_t (*delete_channel) (uint32_t camera_handle,
    586                                uint32_t ch_id);
    587 
    588     /** get_bundle_info: function definition for querying bundle
    589      *  info of the channel
    590      *    @camera_handle : camera handler
    591      *    @ch_id         : channel handler
    592      *    @bundle_info   : bundle info to be filled in
    593      *  Return value: 0 -- success
    594      *                -1 -- failure
    595      **/
    596     int32_t (*get_bundle_info) (uint32_t camera_handle,
    597                                 uint32_t ch_id,
    598                                 cam_bundle_config_t *bundle_info);
    599 
    600     /** add_stream: fucntion definition for adding a stream
    601      *    @camera_handle : camer handler
    602      *    @ch_id : channel handler
    603      *  Return value: stream_id. zero is invalid stream_id
    604      **/
    605     uint32_t (*add_stream) (uint32_t camera_handle,
    606                             uint32_t ch_id);
    607 
    608     /** delete_stream: fucntion definition for deleting a stream
    609      *    @camera_handle : camer handler
    610      *    @ch_id : channel handler
    611      *    @stream_id : stream handler
    612      *  Return value: 0 -- success
    613      *                -1 -- failure
    614      **/
    615     int32_t (*delete_stream) (uint32_t camera_handle,
    616                               uint32_t ch_id,
    617                               uint32_t stream_id);
    618 
    619     /** link_stream: function definition for linking a stream
    620      *    @camera_handle : camera handle
    621      *    @ch_id : channel handle from which the stream originates
    622      *    @stream_id : stream handle
    623      *    @linked_ch_id: channel handle in which the stream will be linked
    624      *  Return value: 0 -- success
    625      *                -1 -- failure
    626      **/
    627     int32_t (*link_stream) (uint32_t camera_handle,
    628           uint32_t ch_id,
    629           uint32_t stream_id,
    630           uint32_t linked_ch_id);
    631 
    632     /** config_stream: fucntion definition for configuring a stream
    633      *    @camera_handle : camer handler
    634      *    @ch_id : channel handler
    635      *    @stream_id : stream handler
    636      *    @confid : pointer to a stream configuration structure
    637      *  Return value: 0 -- success
    638      *                -1 -- failure
    639      **/
    640     int32_t (*config_stream) (uint32_t camera_handle,
    641                               uint32_t ch_id,
    642                               uint32_t stream_id,
    643                               mm_camera_stream_config_t *config);
    644 
    645     /** map_stream_buf: fucntion definition for mapping
    646      *                 stream buffer via domain socket
    647      *    @camera_handle : camer handler
    648      *    @ch_id : channel handler
    649      *    @stream_id : stream handler
    650      *    @buf_type : type of mapping buffers, can be value of
    651      *             CAM_MAPPING_BUF_TYPE_STREAM_BUF
    652      *             CAM_MAPPING_BUF_TYPE_STREAM_INFO
    653      *             CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF
    654      *    @buf_idx : buffer index within the stream buffers
    655      *    @plane_idx : plane index. If all planes share the same fd,
    656      *               plane_idx = -1; otherwise, plean_idx is the
    657      *               index to plane (0..num_of_planes)
    658      *    @fd : file descriptor of the stream buffer
    659      *    @size :  size of the stream buffer
    660      *  Return value: 0 -- success
    661      *                -1 -- failure
    662      **/
    663     int32_t (*map_stream_buf) (uint32_t camera_handle,
    664                                uint32_t ch_id,
    665                                uint32_t stream_id,
    666                                uint8_t buf_type,
    667                                uint32_t buf_idx,
    668                                int32_t plane_idx,
    669                                int fd,
    670                                size_t size,
    671                                void *buffer);
    672 
    673     /** map_stream_bufs: function definition for mapping multiple
    674      *                 stream buffers via domain socket
    675      *    @camera_handle : camera handler
    676      *    @ch_id : channel handler
    677      *    @buf_map_list : list of buffers to map
    678      *  Return value: 0 -- success
    679      *                -1 -- failure
    680      **/
    681     int32_t (*map_stream_bufs) (uint32_t camera_handle,
    682                                 uint32_t ch_id,
    683                                 const cam_buf_map_type_list *buf_map_list);
    684 
    685     /** unmap_stream_buf: fucntion definition for unmapping
    686      *                 stream buffer via domain socket
    687      *    @camera_handle : camer handler
    688      *    @ch_id : channel handler
    689      *    @stream_id : stream handler
    690      *    @buf_type : type of mapping buffers, can be value of
    691      *             CAM_MAPPING_BUF_TYPE_STREAM_BUF
    692      *             CAM_MAPPING_BUF_TYPE_STREAM_INFO
    693      *             CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF
    694      *    @buf_idx : buffer index within the stream buffers
    695      *    @plane_idx : plane index. If all planes share the same fd,
    696      *               plane_idx = -1; otherwise, plean_idx is the
    697      *               index to plane (0..num_of_planes)
    698      *  Return value: 0 -- success
    699      *                -1 -- failure
    700      **/
    701     int32_t (*unmap_stream_buf) (uint32_t camera_handle,
    702                                  uint32_t ch_id,
    703                                  uint32_t stream_id,
    704                                  uint8_t buf_type,
    705                                  uint32_t buf_idx,
    706                                  int32_t plane_idx);
    707 
    708     /** set_stream_parms: fucntion definition for setting stream
    709      *                    specific parameters to server
    710      *    @camera_handle : camer handler
    711      *    @ch_id : channel handler
    712      *    @stream_id : stream handler
    713      *    @parms : batch for parameters to be set
    714      *  Return value: 0 -- success
    715      *                -1 -- failure
    716      *  Note: would assume parm buffer is already mapped, and
    717      *       according parameter entries to be set are filled in the
    718      *       buf before this call
    719      **/
    720     int32_t (*set_stream_parms) (uint32_t camera_handle,
    721                                  uint32_t ch_id,
    722                                  uint32_t s_id,
    723                                  cam_stream_parm_buffer_t *parms);
    724 
    725     /** get_stream_parms: fucntion definition for querying stream
    726      *                    specific parameters from server
    727      *    @camera_handle : camer handler
    728      *    @ch_id : channel handler
    729      *    @stream_id : stream handler
    730      *    @parms : batch for parameters to be queried
    731      *  Return value: 0 -- success
    732      *                -1 -- failure
    733      *  Note: would assume parm buffer is already mapped, and
    734      *       according parameter entries to be queried are filled in
    735      *       the buf before this call
    736      **/
    737     int32_t (*get_stream_parms) (uint32_t camera_handle,
    738                                  uint32_t ch_id,
    739                                  uint32_t s_id,
    740                                  cam_stream_parm_buffer_t *parms);
    741 
    742     /** start_channel: fucntion definition for starting a channel
    743      *    @camera_handle : camer handler
    744      *    @ch_id : channel handler
    745      *  Return value: 0 -- success
    746      *                -1 -- failure
    747      * This call will start all streams belongs to the channel
    748      **/
    749     int32_t (*start_channel) (uint32_t camera_handle,
    750                               uint32_t ch_id);
    751 
    752     /** stop_channel: fucntion definition for stopping a channel
    753      *    @camera_handle : camer handler
    754      *    @ch_id : channel handler
    755      *  Return value: 0 -- success
    756      *                -1 -- failure
    757      * This call will stop all streams belongs to the channel
    758      **/
    759     int32_t (*stop_channel) (uint32_t camera_handle,
    760                              uint32_t ch_id);
    761 
    762     /** qbuf: fucntion definition for queuing a frame buffer back to
    763      *        kernel for reuse
    764      *    @camera_handle : camer handler
    765      *    @ch_id : channel handler
    766      *    @buf : a frame buffer to be queued back to kernel
    767      *  Return value: 0 -- success
    768      *                -1 -- failure
    769      **/
    770     int32_t (*qbuf) (uint32_t camera_handle,
    771                      uint32_t ch_id,
    772                      mm_camera_buf_def_t *buf);
    773 
    774     /** get_queued_buf_count: fucntion definition for querying queued buf count
    775      *    @camera_handle : camer handler
    776      *    @ch_id : channel handler
    777      *    @stream_id : stream handler
    778      *  Return value: queued buf count
    779      **/
    780     int32_t (*get_queued_buf_count) (uint32_t camera_handle,
    781             uint32_t ch_id,
    782             uint32_t stream_id);
    783 
    784     /** request_super_buf: fucntion definition for requesting frames
    785      *                     from superbuf queue in burst mode
    786      *    @camera_handle : camer handler
    787      *    @ch_id : channel handler
    788      *    @buf : provides info related to the super buf request
    789      *  Return value: 0 -- success
    790      *                -1 -- failure
    791      **/
    792     int32_t (*request_super_buf) (uint32_t camera_handle,
    793                                   uint32_t ch_id,
    794                                   mm_camera_req_buf_t *buf);
    795 
    796     /** cancel_super_buf_request: fucntion definition for canceling
    797      *                     frames dispatched from superbuf queue in
    798      *                     burst mode
    799      *    @camera_handle : camer handler
    800      *    @ch_id : channel handler
    801      *  Return value: 0 -- success
    802      *                -1 -- failure
    803      **/
    804     int32_t (*cancel_super_buf_request) (uint32_t camera_handle,
    805                                          uint32_t ch_id);
    806 
    807     /** flush_super_buf_queue: function definition for flushing out
    808      *                     all frames in the superbuf queue up to frame_idx,
    809      *                     even if frames with frame_idx come in later than
    810      *                     this call.
    811      *    @camera_handle : camer handler
    812      *    @ch_id : channel handler
    813      *    @frame_idx : frame index up until which all superbufs are flushed
    814      *  Return value: 0 -- success
    815      *                -1 -- failure
    816      **/
    817     int32_t (*flush_super_buf_queue) (uint32_t camera_handle,
    818                                       uint32_t ch_id, uint32_t frame_idx);
    819 
    820     /** configure_notify_mode: function definition for configuring the
    821      *                         notification mode of channel
    822      *    @camera_handle : camera handler
    823      *    @ch_id : channel handler
    824      *    @notify_mode : notification mode
    825      *  Return value: 0 -- success
    826      *                -1 -- failure
    827      **/
    828     int32_t (*configure_notify_mode) (uint32_t camera_handle,
    829                                       uint32_t ch_id,
    830                                       mm_camera_super_buf_notify_mode_t notify_mode);
    831 
    832    /** process_advanced_capture: function definition for start/stop advanced capture
    833      *                    for snapshot.
    834      *    @camera_handle : camera handle
    835      *    @ch_id : channel handler
    836      *    @type :  advanced capture type.
    837      *    @trigger    : flag indicating if advanced capture needs to be done
    838      *                     0 -- stop advanced capture
    839      *                     1 -- start advanced capture
    840      *    @in_value: Input value. Configaration
    841      *  Return value: 0 -- success
    842      *                -1 -- failure
    843      **/
    844     int32_t (*process_advanced_capture) (uint32_t camera_handle,
    845              uint32_t ch_id, mm_camera_advanced_capture_t type,
    846              int8_t start_flag, void *in_value);
    847 
    848    /** get_session_id: gets the backend session id from the kernel
    849      *    @camera_handle : camera handle
    850      *    @sessionid : session id to be retrieved
    851      *     Return value: 0 -- success
    852      *                -1 -- failure
    853      *  Note: if this call succeeds, we will get a valid session id
    854      **/
    855     int32_t (*get_session_id) (uint32_t camera_handle,
    856             uint32_t* sessionid);
    857 
    858     /** sync_related_sensors: sends sync cmd
    859       *    @camera_handle : camera handle
    860       *    @related_cam_info : related cam info to be sent to server
    861       *     Return value: 0 -- success
    862       *                -1 -- failure
    863       *  Note: if this call succeeds, we will get linking established in back end
    864       **/
    865      int32_t (*sync_related_sensors) (uint32_t camera_handle,
    866             cam_sync_related_sensors_event_info_t*
    867             related_cam_info);
    868     /** flush: function definition for flush
    869      *  @camera_handle: camera handler
    870      *  Return value: 0 -- success
    871      *               -1 -- failure
    872      **/
    873     int32_t (*flush) (uint32_t camera_handle);
    874 
    875    /** register_stream_buf_cb: fucntion definition for registering special stream callbacks
    876      *    @camera_handle : camer handler
    877      *    @ch_id : channel handler
    878      *    @stream_id : stream handler
    879      *    @buf_cb : callback function pointer
    880      *    @cb_type : Callback type SYNC/ASYNC
    881      *    @userdata : user data pointer
    882      *    Return value: 0 -- success
    883      *                -       1 -- failure
    884      **/
    885     int32_t (*register_stream_buf_cb) (uint32_t camera_handle,
    886             uint32_t ch_id, uint32_t stream_id, mm_camera_buf_notify_t buf_cb,
    887             mm_camera_stream_cb_type cb_type, void *userdata);
    888 
    889    /** register_stream_frame_sync: fucntion definition for registering frame sync
    890      *    @camera_handle : camer handler
    891      *    @ch_id : channel handler
    892      *    @stream_id : stream handler. Can be 0 to config only channel callback sync
    893      *    @sync_attr : pointer to a stream sync configuration structure
    894      *  Return value: 0 -- success
    895      *                -1 -- failure
    896      **/
    897     int32_t (*register_frame_sync) (uint32_t camera_handle,
    898             uint32_t ch_id, uint32_t stream_id,
    899             mm_camera_intf_frame_sync_t *sync_attr);
    900 
    901    /** start_stream_frame_sync:  function definition to start frame buffer sync
    902      *    @camera_handle : camer handler
    903      *    @ch_id : channel handler
    904      *    @stream_id : stream handler
    905      *  Return value: 0 -- success
    906      *                -1 -- failure
    907      **/
    908     int32_t (*start_stream_frame_sync) (uint32_t camera_handle,
    909             uint32_t ch_id, uint32_t stream_id);
    910 
    911    /** stop_stream_frame_sync:  function definition to stop frame buffer sync
    912      *    @camera_handle : camer handler
    913      *    @ch_id : channel handler
    914      *    @stream_id : stream handler
    915      *  Return value: 0 -- success
    916      *                -1 -- failure
    917      **/
    918     int32_t (*stop_stream_frame_sync) (uint32_t camera_handle,
    919             uint32_t ch_id, uint32_t stream_id);
    920 
    921    /** switch_stream: function definition to switch stream frame
    922      *    @camera_handle : camer handler
    923      *    @ch_id : channel handler
    924      *    @stream_id : stream handler
    925      *  Return value: 0 -- success
    926      *                -1 -- failure
    927      **/
    928     int32_t (*switch_stream_callback) (uint32_t camera_handle,
    929             uint32_t ch_id, uint32_t stream_id);
    930 } mm_camera_ops_t;
    931 
    932 /** mm_camera_vtbl_t: virtual table for camera operations
    933 *    @camera_handle : camera handler which uniquely identifies a
    934 *                   camera object
    935 *    @ops : API call table
    936 **/
    937 typedef struct {
    938     uint32_t camera_handle;
    939     mm_camera_ops_t *ops;
    940 } mm_camera_vtbl_t;
    941 
    942 /* return number of cameras */
    943 uint8_t get_num_of_cameras();
    944 
    945 /* return reference pointer of camera vtbl */
    946 int32_t camera_open(uint8_t camera_idx, mm_camera_vtbl_t **camera_obj);
    947 
    948 /* helper functions */
    949 int32_t mm_stream_calc_offset_preview(cam_stream_info_t *stream_info,
    950         cam_dimension_t *dim,
    951         cam_padding_info_t *padding,
    952         cam_stream_buf_plane_info_t *buf_planes);
    953 
    954 int32_t mm_stream_calc_offset_post_view(cam_format_t fmt,
    955         cam_dimension_t *dim,
    956         cam_stream_buf_plane_info_t *buf_planes);
    957 
    958 int32_t mm_stream_calc_offset_snapshot(cam_format_t fmt,
    959         cam_dimension_t *dim,
    960         cam_padding_info_t *padding,
    961         cam_stream_buf_plane_info_t *buf_planes);
    962 
    963 int32_t mm_stream_calc_offset_raw(cam_format_t fmt,
    964         cam_dimension_t *dim,
    965         cam_padding_info_t *padding,
    966         cam_stream_buf_plane_info_t *buf_planes);
    967 
    968 int32_t mm_stream_calc_offset_video(cam_format_t fmt,
    969         cam_dimension_t *dim,
    970         cam_stream_buf_plane_info_t *buf_planes);
    971 
    972 int32_t mm_stream_calc_offset_metadata(cam_dimension_t *dim,
    973         cam_padding_info_t *padding,
    974         cam_stream_buf_plane_info_t *buf_planes);
    975 
    976 int32_t mm_stream_calc_offset_postproc(cam_stream_info_t *stream_info,
    977         cam_padding_info_t *padding,
    978         cam_stream_buf_plane_info_t *buf_planes);
    979 
    980 int32_t mm_stream_calc_offset_analysis(cam_format_t fmt,
    981         cam_dimension_t *dim,
    982         cam_padding_info_t *padding,
    983         cam_stream_buf_plane_info_t *buf_planes);
    984 
    985 uint32_t mm_stream_calc_lcm (int32_t num1, int32_t num2);
    986 struct camera_info *get_cam_info(uint32_t camera_id, cam_sync_type_t *pCamType);
    987 
    988 uint8_t is_yuv_sensor(uint32_t camera_id);
    989 
    990 /*Dual camera related utility functions*/
    991 
    992 /*Query if it is dual camera mode based on the camera index*/
    993 uint8_t is_dual_camera_by_idx(uint32_t camera_id);
    994 
    995 /*Query if it is dual camera mode based on the camera/channel/stream handles*/
    996 uint8_t is_dual_camera_by_handle(uint32_t handle);
    997 
    998 /*Get Primary camera handle for camera/channel/stream*/
    999 uint32_t get_main_camera_handle(uint32_t handle);
   1000 
   1001 /*Get Auxilary camera handle for camera/channel/stream*/
   1002 uint32_t get_aux_camera_handle(uint32_t handle);
   1003 
   1004 /*Validate 2 handle if it is belong to same instance of camera/channel/stream*/
   1005 uint8_t validate_handle(uint32_t src_handle, uint32_t handle);
   1006 #endif /*__MM_CAMERA_INTERFACE_H__*/
   1007