Home | History | Annotate | Download | only in common
      1 /* Copyright (c) 2012-2015, 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 #include <linux/msm_ion.h>
     33 #include <linux/videodev2.h>
     34 #include <media/msmb_camera.h>
     35 #include "cam_intf.h"
     36 #include "cam_queue.h"
     37 
     38 #define MM_CAMERA_MAX_NUM_SENSORS MSM_MAX_CAMERA_SENSORS
     39 #define MM_CAMERA_MAX_NUM_FRAMES CAM_MAX_NUM_BUFS_PER_STREAM
     40 /* num of channels allowed in a camera obj */
     41 #define MM_CAMERA_CHANNEL_MAX 16
     42 
     43 #define PAD_TO_SIZE(size, padding) \
     44         ((size + (typeof(size))(padding - 1)) & \
     45         (typeof(size))(~(padding - 1)))
     46 
     47 /** CAM_DUMP_TO_FILE:
     48  *  @filename: file name
     49  *  @name:filename
     50  *  @index: index of the file
     51  *  @extn: file extension
     52  *  @p_addr: address of the buffer
     53  *  @len: buffer length
     54  *
     55  *  dump the image to the file
     56  **/
     57 #define CAM_DUMP_TO_FILE(path, name, index, extn, p_addr, len) ({ \
     58   size_t rc = 0; \
     59   char filename[FILENAME_MAX]; \
     60   if (index >= 0) \
     61     snprintf(filename, FILENAME_MAX, "%s/%s%d.%s", path, name, index, extn); \
     62   else \
     63     snprintf(filename, FILENAME_MAX, "%s/%s.%s", path, name, extn); \
     64   FILE *fp = fopen(filename, "w+"); \
     65   if (fp) { \
     66     rc = fwrite(p_addr, 1, len, fp); \
     67     ALOGE("%s:%d] written size %d", __func__, __LINE__, len); \
     68     fclose(fp); \
     69   } else { \
     70     ALOGE("%s:%d] open %s failed", __func__, __LINE__, filename); \
     71   } \
     72 })
     73 
     74 /* Declaring Buffer structure */
     75 struct mm_camera_buf_def;
     76 
     77 /** mm_camera_plane_def_t : structure for frame plane info
     78 *    @num_planes : num of planes for the frame buffer, to be
     79 *               filled during mem allocation
     80 *    @planes : plane info for the frame buffer, to be filled
     81 *               during mem allocation
     82 **/
     83 typedef struct {
     84     int8_t num_planes;
     85     struct v4l2_plane planes[VIDEO_MAX_PLANES];
     86 } mm_camera_plane_buf_def_t;
     87 
     88 /** mm_camera_user_buf_def_t : structure for frame plane info
     89 *    @num_buffers : num of buffers in this user defined structure
     90 *    @bufs_used : actual number of buffer filled
     91 *    @buf_in_use : flag to notify buffer usage status.
     92 *    @plane_buf : Plane buffer array pointer.
     93 **/
     94 typedef struct {
     95     uint8_t num_buffers;
     96     uint8_t bufs_used;     /*Num of Buffer filled by Kernel*/
     97     uint8_t buf_in_use;  /* Container buffer is freed to fill*/
     98     int32_t buf_idx[MSM_CAMERA_MAX_USER_BUFF_CNT];
     99     struct mm_camera_buf_def *plane_buf;
    100 } mm_camera_user_buf_def_t;
    101 
    102 /** mm_camera_buf_def_t: structure for stream frame buf
    103 *    @stream_id : stream handler to uniquely identify a stream
    104 *               object
    105 *    @buf_idx : index of the buf within the stream bufs, to be
    106 *               filled during mem allocation
    107 *    @timespec_ts : time stamp, to be filled when DQBUF is
    108 *                 called
    109 *    @frame_idx : frame sequence num, to be filled when DQBUF
    110 *    @plane_buf  : Frame plane definition
    111 *    @fd : file descriptor of the frame buffer, to be filled
    112 *        during mem allocation
    113 *    @buffer : pointer to the frame buffer, to be filled during
    114 *            mem allocation
    115 *    @frame_len : length of the whole frame, to be filled during
    116 *               mem allocation
    117 *    @mem_info : user specific pointer to additional mem info
    118 **/
    119 typedef struct mm_camera_buf_def {
    120     uint32_t stream_id;
    121     cam_stream_type_t stream_type;
    122     cam_stream_buf_type buf_type;
    123     uint32_t buf_idx;
    124     uint8_t is_uv_subsampled;
    125     struct timespec ts;
    126     uint32_t frame_idx;
    127     union {
    128         mm_camera_plane_buf_def_t planes_buf;
    129         mm_camera_user_buf_def_t user_buf;
    130     };
    131     int fd;
    132     void *buffer;
    133     size_t frame_len;
    134     void *mem_info;
    135 } mm_camera_buf_def_t;
    136 
    137 /** mm_camera_super_buf_t: super buf structure for bundled
    138 *   stream frames
    139 *    @camera_handle : camera handler to uniquely identify
    140 *              a camera object
    141 *    @ch_id : channel handler to uniquely ideentify a channel
    142 *           object
    143 *    @num_bufs : number of buffers in the super buf, should not
    144 *              exceeds MAX_STREAM_NUM_IN_BUNDLE
    145 *    @bufs : array of buffers in the bundle
    146 **/
    147 typedef struct {
    148     uint32_t camera_handle;
    149     uint32_t ch_id;
    150     uint32_t num_bufs;
    151     uint8_t bUnlockAEC;
    152     uint8_t bReadyForPrepareSnapshot;
    153     mm_camera_buf_def_t* bufs[MAX_STREAM_NUM_IN_BUNDLE];
    154 } mm_camera_super_buf_t;
    155 
    156 /** mm_camera_event_t: structure for event
    157 *    @server_event_type : event type from serer
    158 *    @status : status of an event, value could be
    159 *              CAM_STATUS_SUCCESS
    160 *              CAM_STATUS_FAILED
    161 **/
    162 typedef struct {
    163     cam_event_type_t server_event_type;
    164     uint32_t status;
    165 } mm_camera_event_t;
    166 
    167 /** mm_camera_event_notify_t: function definition for event
    168 *   notify handling
    169 *    @camera_handle : camera handler
    170 *    @evt : pointer to an event struct
    171 *    @user_data: user data pointer
    172 **/
    173 typedef void (*mm_camera_event_notify_t)(uint32_t camera_handle,
    174                                          mm_camera_event_t *evt,
    175                                          void *user_data);
    176 
    177 /** mm_camera_buf_notify_t: function definition for frame notify
    178 *   handling
    179 *    @mm_camera_super_buf_t : received frame buffers
    180 *    @user_data: user data pointer
    181 **/
    182 typedef void (*mm_camera_buf_notify_t) (mm_camera_super_buf_t *bufs,
    183                                         void *user_data);
    184 
    185 /** map_stream_buf_op_t: function definition for operation of
    186 *   mapping stream buffers via domain socket
    187 *    @frame_idx : buffer index within stream buffers
    188 *    @plane_idx    : plane index. If all planes share the same
    189 *                   fd, plane_idx = -1; otherwise, plean_idx is
    190 *                   the index to plane (0..num_of_planes)
    191 *    @fd : file descriptor of the stream buffer
    192 *    @size: size of the stream buffer
    193 *    @userdata : user data pointer
    194 **/
    195 typedef int32_t (*map_stream_buf_op_t) (uint32_t frame_idx,
    196                                         int32_t plane_idx,
    197                                         int fd,
    198                                         size_t size,
    199                                         cam_mapping_buf_type type,
    200                                         void *userdata);
    201 
    202 /** unmap_stream_buf_op_t: function definition for operation of
    203 *                          unmapping stream buffers via domain
    204 *                          socket
    205 *    @frame_idx : buffer index within stream buffers
    206 *    @plane_idx : plane index. If all planes share the same
    207 *                 fd, plane_idx = -1; otherwise, plean_idx is
    208 *                 the index to plane (0..num_of_planes)
    209 *    @userdata : user data pointer
    210 **/
    211 typedef int32_t (*unmap_stream_buf_op_t) (uint32_t frame_idx,
    212                                           int32_t plane_idx,
    213                                           cam_mapping_buf_type type,
    214                                           void *userdata);
    215 
    216 /** mm_camera_map_unmap_ops_tbl_t: virtual table
    217 *                      for mapping/unmapping stream buffers via
    218 *                      domain socket
    219 *    @map_ops : operation for mapping
    220 *    @unmap_ops : operation for unmapping
    221 *    @userdata: user data pointer
    222 **/
    223 typedef struct {
    224     map_stream_buf_op_t map_ops;
    225     unmap_stream_buf_op_t unmap_ops;
    226     void *userdata;
    227 } mm_camera_map_unmap_ops_tbl_t;
    228 
    229 /** mm_camera_stream_mem_vtbl_t: virtual table for stream
    230 *                      memory allocation and deallocation
    231 *    @get_bufs : function definition for allocating
    232 *                stream buffers
    233 *    @put_bufs : function definition for deallocating
    234 *                stream buffers
    235 *    @user_data: user data pointer
    236 **/
    237 typedef struct {
    238   void *user_data;
    239   int32_t (*get_bufs) (cam_frame_len_offset_t *offset,
    240                        uint8_t *num_bufs,
    241                        uint8_t **initial_reg_flag,
    242                        mm_camera_buf_def_t **bufs,
    243                        mm_camera_map_unmap_ops_tbl_t *ops_tbl,
    244                        void *user_data);
    245   int32_t (*put_bufs) (mm_camera_map_unmap_ops_tbl_t *ops_tbl,
    246                        void *user_data);
    247   int32_t (*invalidate_buf)(uint32_t index, void *user_data);
    248   int32_t (*clean_invalidate_buf)(uint32_t index, void *user_data);
    249 } mm_camera_stream_mem_vtbl_t;
    250 
    251 /** mm_camera_stream_config_t: structure for stream
    252 *                              configuration
    253 *    @stream_info : pointer to a stream info structure
    254 *    @padding_info: padding info obtained from querycapability
    255 *    @mem_tbl : memory operation table for
    256 *              allocating/deallocating stream buffers
    257 *    @stream_cb : callback handling stream frame notify
    258 *    @userdata : user data pointer
    259 **/
    260 typedef struct {
    261     cam_stream_info_t *stream_info;
    262     cam_padding_info_t padding_info;
    263     mm_camera_stream_mem_vtbl_t mem_vtbl;
    264     mm_camera_buf_notify_t stream_cb;
    265     void *userdata;
    266 } mm_camera_stream_config_t;
    267 
    268 /** mm_camera_super_buf_notify_mode_t: enum for super uffer
    269 *                                      notification mode
    270 *    @MM_CAMERA_SUPER_BUF_NOTIFY_BURST :
    271 *       ZSL use case: get burst of frames
    272 *    @MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS :
    273 *       get continuous frames: when the super buf is ready
    274 *       dispatch it to HAL
    275 **/
    276 typedef enum {
    277     MM_CAMERA_SUPER_BUF_NOTIFY_BURST = 0,
    278     MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS,
    279     MM_CAMERA_SUPER_BUF_NOTIFY_MAX
    280 } mm_camera_super_buf_notify_mode_t;
    281 
    282 /** mm_camera_super_buf_priority_t: enum for super buffer
    283 *                                   matching priority
    284 *    @MM_CAMERA_SUPER_BUF_PRIORITY_NORMAL :
    285 *       Save the frame no matter focused or not. Currently only
    286 *       this type is supported.
    287 *    @MM_CAMERA_SUPER_BUF_PRIORITY_FOCUS :
    288 *       only queue the frame that is focused. Will enable meta
    289 *       data header to carry focus info
    290 *    @MM_CAMERA_SUPER_BUF_PRIORITY_EXPOSURE_BRACKETING :
    291 *       after shutter, only queue matched exposure index
    292 **/
    293 typedef enum {
    294     MM_CAMERA_SUPER_BUF_PRIORITY_NORMAL = 0,
    295     MM_CAMERA_SUPER_BUF_PRIORITY_FOCUS,
    296     MM_CAMERA_SUPER_BUF_PRIORITY_EXPOSURE_BRACKETING,
    297     MM_CAMERA_SUPER_BUF_PRIORITY_LOW,/* Bundled metadata frame may not match*/
    298     MM_CAMERA_SUPER_BUF_PRIORITY_MAX
    299 } mm_camera_super_buf_priority_t;
    300 
    301 /** mm_camera_advanced_capture_t: enum for advanced capture type.
    302 *    @MM_CAMERA_AF_BRACKETING :
    303 *       to enable AF Bracketig.
    304 *    @MM_CAMERA_AE_BRACKETING :
    305 *       to enable AF Bracketing.
    306 *    @MM_CAMERA_FLASH_BRACKETING :
    307 *       to enable Flash Bracketing.
    308 *    @MM_CAMERA_ZOOM_1X :
    309 *       to enable zoom 1x capture request
    310 **/
    311 typedef enum {
    312    MM_CAMERA_AF_BRACKETING = 0,
    313    MM_CAMERA_AE_BRACKETING,
    314    MM_CAMERA_FLASH_BRACKETING,
    315    MM_CAMERA_ZOOM_1X,
    316    MM_CAMERA_FRAME_CAPTURE,
    317 } mm_camera_advanced_capture_t;
    318 
    319 /** mm_camera_channel_attr_t: structure for defining channel
    320 *                             attributes
    321 *    @notify_mode : notify mode: burst or continuous
    322 *    @water_mark : queue depth. Only valid for burst mode
    323 *    @look_back : look back how many frames from last buf.
    324 *                 Only valid for burst mode
    325 *    @post_frame_skip : after send first frame to HAL, how many
    326 *                     frames needing to be skipped for next
    327 *                     delivery. Only valid for burst mode
    328 *    @max_unmatched_frames : max number of unmatched frames in
    329 *                     queue
    330 *    @priority : save matched priority frames only
    331 **/
    332 typedef struct {
    333     mm_camera_super_buf_notify_mode_t notify_mode;
    334     uint8_t water_mark;
    335     uint8_t look_back;
    336     uint8_t post_frame_skip;
    337     uint8_t max_unmatched_frames;
    338     mm_camera_super_buf_priority_t priority;
    339 } mm_camera_channel_attr_t;
    340 
    341 typedef struct {
    342     /** query_capability: fucntion definition for querying static
    343      *                    camera capabilities
    344      *    @camera_handle : camer handler
    345      *  Return value: 0 -- success
    346      *                -1 -- failure
    347      *  Note: would assume cam_capability_t is already mapped
    348      **/
    349     int32_t (*query_capability) (uint32_t camera_handle);
    350 
    351     /** register_event_notify: fucntion definition for registering
    352      *                         for event notification
    353      *    @camera_handle : camer handler
    354      *    @evt_cb : callback for event notify
    355      *    @user_data : user data poiner
    356      *  Return value: 0 -- success
    357      *                -1 -- failure
    358      **/
    359     int32_t (*register_event_notify) (uint32_t camera_handle,
    360                                       mm_camera_event_notify_t evt_cb,
    361                                       void *user_data);
    362 
    363     /** close_camera: fucntion definition for closing a camera
    364      *    @camera_handle : camer handler
    365      *  Return value: 0 -- success
    366      *                -1 -- failure
    367      **/
    368     int32_t (*close_camera) (uint32_t camera_handle);
    369 
    370     /** map_buf: fucntion definition for mapping a camera buffer
    371      *           via domain socket
    372      *    @camera_handle : camer handler
    373      *    @buf_type : type of mapping buffers, can be value of
    374      *                CAM_MAPPING_BUF_TYPE_CAPABILITY
    375      *                CAM_MAPPING_BUF_TYPE_SETPARM_BUF
    376      *                CAM_MAPPING_BUF_TYPE_GETPARM_BUF
    377      *    @fd : file descriptor of the stream buffer
    378      *    @size :  size of the stream buffer
    379      *  Return value: 0 -- success
    380      *                -1 -- failure
    381      **/
    382     int32_t (*map_buf) (uint32_t camera_handle,
    383                         uint8_t buf_type,
    384                         int fd,
    385                         size_t size);
    386 
    387     /** unmap_buf: fucntion definition for unmapping a camera buffer
    388      *           via domain socket
    389      *    @camera_handle : camer handler
    390      *    @buf_type : type of mapping buffers, can be value of
    391      *                CAM_MAPPING_BUF_TYPE_CAPABILITY
    392      *                CAM_MAPPING_BUF_TYPE_SETPARM_BUF
    393      *                CAM_MAPPING_BUF_TYPE_GETPARM_BUF
    394      *  Return value: 0 -- success
    395      *                -1 -- failure
    396      **/
    397     int32_t (*unmap_buf) (uint32_t camera_handle,
    398                           uint8_t buf_type);
    399 
    400     /** set_parms: fucntion definition for setting camera
    401      *             based parameters to server
    402      *    @camera_handle : camer handler
    403      *    @parms : batch for parameters to be set, stored in
    404      *               parm_buffer_t
    405      *  Return value: 0 -- success
    406      *                -1 -- failure
    407      *  Note: would assume parm_buffer_t is already mapped, and
    408      *       according parameter entries to be set are filled in the
    409      *       buf before this call
    410      **/
    411     int32_t (*set_parms) (uint32_t camera_handle,
    412                           parm_buffer_t *parms);
    413 
    414     /** get_parms: fucntion definition for querying camera
    415      *             based parameters from server
    416      *    @camera_handle : camer handler
    417      *    @parms : batch for parameters to be queried, stored in
    418      *               parm_buffer_t
    419      *  Return value: 0 -- success
    420      *                -1 -- failure
    421      *  Note: would assume parm_buffer_t is already mapped, and
    422      *       according parameter entries to be queried are filled in
    423      *       the buf before this call
    424      **/
    425     int32_t (*get_parms) (uint32_t camera_handle,
    426                           parm_buffer_t *parms);
    427 
    428     /** do_auto_focus: fucntion definition for performing auto focus
    429      *    @camera_handle : camer handler
    430      *  Return value: 0 -- success
    431      *                -1 -- failure
    432      *  Note: if this call success, we will always assume there will
    433      *        be an auto_focus event following up.
    434      **/
    435     int32_t (*do_auto_focus) (uint32_t camera_handle);
    436 
    437     /** cancel_auto_focus: fucntion definition for cancelling
    438      *                     previous auto focus request
    439      *    @camera_handle : camer handler
    440     *  Return value: 0 -- success
    441     *                -1 -- failure
    442      **/
    443     int32_t (*cancel_auto_focus) (uint32_t camera_handle);
    444 
    445     /** prepare_snapshot: fucntion definition for preparing hardware
    446      *                    for snapshot.
    447      *    @camera_handle : camer handler
    448      *    @do_af_flag    : flag indicating if AF needs to be done
    449      *                     0 -- no AF needed
    450      *                     1 -- AF needed
    451      *  Return value: 0 -- success
    452      *                -1 -- failure
    453      **/
    454     int32_t (*prepare_snapshot) (uint32_t camera_handle,
    455                                  int32_t do_af_flag);
    456 
    457     /** start_zsl_snapshot: function definition for starting
    458      *                    zsl snapshot.
    459      *    @camera_handle : camer handler
    460      *    @ch_id         : channel id
    461      *  Return value: 0 -- success
    462      *                -1 -- failure
    463      **/
    464     int32_t (*start_zsl_snapshot) (uint32_t camera_handle, uint32_t ch_id);
    465 
    466     /** stop_zsl_snapshot: function definition for stopping
    467      *                    zsl snapshot.
    468      *    @camera_handle : camer handler
    469      *    @ch_id         : channel id
    470      *  Return value: 0 -- success
    471      *                -1 -- failure
    472      **/
    473     int32_t (*stop_zsl_snapshot) (uint32_t camera_handle, uint32_t ch_id);
    474 
    475     /** add_channel: fucntion definition for adding a channel
    476      *    @camera_handle : camer handler
    477      *    @ch_id : channel handler
    478      *    @attr : pointer to channel attribute structure
    479      *    @channel_cb : callbak to handle bundled super buffer
    480      *    @userdata : user data pointer
    481      *  Return value: channel id, zero is invalid ch_id
    482      * Note: attr, channel_cb, and userdata can be NULL if no
    483      *       superbufCB is needed
    484      **/
    485     uint32_t (*add_channel) (uint32_t camera_handle,
    486                              mm_camera_channel_attr_t *attr,
    487                              mm_camera_buf_notify_t channel_cb,
    488                              void *userdata);
    489 
    490     /** delete_channel: fucntion definition for deleting a channel
    491      *    @camera_handle : camer handler
    492      *    @ch_id : channel handler
    493      *  Return value: 0 -- success
    494      *                -1 -- failure
    495      **/
    496     int32_t (*delete_channel) (uint32_t camera_handle,
    497                                uint32_t ch_id);
    498 
    499     /** get_bundle_info: function definition for querying bundle
    500      *  info of the channel
    501      *    @camera_handle : camera handler
    502      *    @ch_id         : channel handler
    503      *    @bundle_info   : bundle info to be filled in
    504      *  Return value: 0 -- success
    505      *                -1 -- failure
    506      **/
    507     int32_t (*get_bundle_info) (uint32_t camera_handle,
    508                                 uint32_t ch_id,
    509                                 cam_bundle_config_t *bundle_info);
    510 
    511     /** add_stream: fucntion definition for adding a stream
    512      *    @camera_handle : camer handler
    513      *    @ch_id : channel handler
    514      *  Return value: stream_id. zero is invalid stream_id
    515      **/
    516     uint32_t (*add_stream) (uint32_t camera_handle,
    517                             uint32_t ch_id);
    518 
    519     /** delete_stream: fucntion definition for deleting a stream
    520      *    @camera_handle : camer handler
    521      *    @ch_id : channel handler
    522      *    @stream_id : stream handler
    523      *  Return value: 0 -- success
    524      *                -1 -- failure
    525      **/
    526     int32_t (*delete_stream) (uint32_t camera_handle,
    527                               uint32_t ch_id,
    528                               uint32_t stream_id);
    529 
    530     /** link_stream: function definition for linking a stream
    531      *    @camera_handle : camera handle
    532      *    @ch_id : channel handle from which the stream originates
    533      *    @stream_id : stream handle
    534      *    @linked_ch_id: channel handle in which the stream will be linked
    535      *  Return value: 0 -- success
    536      *                -1 -- failure
    537      **/
    538     int32_t (*link_stream) (uint32_t camera_handle,
    539           uint32_t ch_id,
    540           uint32_t stream_id,
    541           uint32_t linked_ch_id);
    542 
    543     /** config_stream: fucntion definition for configuring a stream
    544      *    @camera_handle : camer handler
    545      *    @ch_id : channel handler
    546      *    @stream_id : stream handler
    547      *    @confid : pointer to a stream configuration structure
    548      *  Return value: 0 -- success
    549      *                -1 -- failure
    550      **/
    551     int32_t (*config_stream) (uint32_t camera_handle,
    552                               uint32_t ch_id,
    553                               uint32_t stream_id,
    554                               mm_camera_stream_config_t *config);
    555 
    556     /** map_stream_buf: fucntion definition for mapping
    557      *                 stream buffer via domain socket
    558      *    @camera_handle : camer handler
    559      *    @ch_id : channel handler
    560      *    @stream_id : stream handler
    561      *    @buf_type : type of mapping buffers, can be value of
    562      *             CAM_MAPPING_BUF_TYPE_STREAM_BUF
    563      *             CAM_MAPPING_BUF_TYPE_STREAM_INFO
    564      *             CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF
    565      *    @buf_idx : buffer index within the stream buffers
    566      *    @plane_idx : plane index. If all planes share the same fd,
    567      *               plane_idx = -1; otherwise, plean_idx is the
    568      *               index to plane (0..num_of_planes)
    569      *    @fd : file descriptor of the stream buffer
    570      *    @size :  size of the stream buffer
    571      *  Return value: 0 -- success
    572      *                -1 -- failure
    573      **/
    574     int32_t (*map_stream_buf) (uint32_t camera_handle,
    575                                uint32_t ch_id,
    576                                uint32_t stream_id,
    577                                uint8_t buf_type,
    578                                uint32_t buf_idx,
    579                                int32_t plane_idx,
    580                                int fd,
    581                                size_t size);
    582 
    583     /** unmap_stream_buf: fucntion definition for unmapping
    584      *                 stream buffer via domain socket
    585      *    @camera_handle : camer handler
    586      *    @ch_id : channel handler
    587      *    @stream_id : stream handler
    588      *    @buf_type : type of mapping buffers, can be value of
    589      *             CAM_MAPPING_BUF_TYPE_STREAM_BUF
    590      *             CAM_MAPPING_BUF_TYPE_STREAM_INFO
    591      *             CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF
    592      *    @buf_idx : buffer index within the stream buffers
    593      *    @plane_idx : plane index. If all planes share the same fd,
    594      *               plane_idx = -1; otherwise, plean_idx is the
    595      *               index to plane (0..num_of_planes)
    596      *  Return value: 0 -- success
    597      *                -1 -- failure
    598      **/
    599     int32_t (*unmap_stream_buf) (uint32_t camera_handle,
    600                                  uint32_t ch_id,
    601                                  uint32_t stream_id,
    602                                  uint8_t buf_type,
    603                                  uint32_t buf_idx,
    604                                  int32_t plane_idx);
    605 
    606     /** set_stream_parms: fucntion definition for setting stream
    607      *                    specific parameters to server
    608      *    @camera_handle : camer handler
    609      *    @ch_id : channel handler
    610      *    @stream_id : stream handler
    611      *    @parms : batch for parameters to be set
    612      *  Return value: 0 -- success
    613      *                -1 -- failure
    614      *  Note: would assume parm buffer is already mapped, and
    615      *       according parameter entries to be set are filled in the
    616      *       buf before this call
    617      **/
    618     int32_t (*set_stream_parms) (uint32_t camera_handle,
    619                                  uint32_t ch_id,
    620                                  uint32_t s_id,
    621                                  cam_stream_parm_buffer_t *parms);
    622 
    623     /** get_stream_parms: fucntion definition for querying stream
    624      *                    specific parameters from server
    625      *    @camera_handle : camer handler
    626      *    @ch_id : channel handler
    627      *    @stream_id : stream handler
    628      *    @parms : batch for parameters to be queried
    629      *  Return value: 0 -- success
    630      *                -1 -- failure
    631      *  Note: would assume parm buffer is already mapped, and
    632      *       according parameter entries to be queried are filled in
    633      *       the buf before this call
    634      **/
    635     int32_t (*get_stream_parms) (uint32_t camera_handle,
    636                                  uint32_t ch_id,
    637                                  uint32_t s_id,
    638                                  cam_stream_parm_buffer_t *parms);
    639 
    640     /** start_channel: fucntion definition for starting a channel
    641      *    @camera_handle : camer handler
    642      *    @ch_id : channel handler
    643      *  Return value: 0 -- success
    644      *                -1 -- failure
    645      * This call will start all streams belongs to the channel
    646      **/
    647     int32_t (*start_channel) (uint32_t camera_handle,
    648                               uint32_t ch_id);
    649 
    650     /** stop_channel: fucntion definition for stopping a channel
    651      *    @camera_handle : camer handler
    652      *    @ch_id : channel handler
    653      *  Return value: 0 -- success
    654      *                -1 -- failure
    655      * This call will stop all streams belongs to the channel
    656      **/
    657     int32_t (*stop_channel) (uint32_t camera_handle,
    658                              uint32_t ch_id);
    659 
    660     /** qbuf: fucntion definition for queuing a frame buffer back to
    661      *        kernel for reuse
    662      *    @camera_handle : camer handler
    663      *    @ch_id : channel handler
    664      *    @buf : a frame buffer to be queued back to kernel
    665      *  Return value: 0 -- success
    666      *                -1 -- failure
    667      **/
    668     int32_t (*qbuf) (uint32_t camera_handle,
    669                      uint32_t ch_id,
    670                      mm_camera_buf_def_t *buf);
    671 
    672     /** get_queued_buf_count: fucntion definition for querying queued buf count
    673      *    @camera_handle : camer handler
    674      *    @ch_id : channel handler
    675      *    @stream_id : stream handler
    676      *  Return value: queued buf count
    677      **/
    678     int32_t (*get_queued_buf_count) (uint32_t camera_handle,
    679             uint32_t ch_id,
    680             uint32_t stream_id);
    681 
    682     /** request_super_buf: fucntion definition for requesting frames
    683      *                     from superbuf queue in burst mode
    684      *    @camera_handle : camer handler
    685      *    @ch_id : channel handler
    686      *    @num_buf_requested : number of super buffers requested
    687      *    @num_retro_buf_requested : number of retro buffers requested
    688      *  Return value: 0 -- success
    689      *                -1 -- failure
    690      **/
    691     int32_t (*request_super_buf) (uint32_t camera_handle,
    692                                   uint32_t ch_id,
    693                                   uint32_t num_buf_requested,
    694                                   uint32_t num_retro_buf_requested);
    695 
    696     /** cancel_super_buf_request: fucntion definition for canceling
    697      *                     frames dispatched from superbuf queue in
    698      *                     burst mode
    699      *    @camera_handle : camer handler
    700      *    @ch_id : channel handler
    701      *  Return value: 0 -- success
    702      *                -1 -- failure
    703      **/
    704     int32_t (*cancel_super_buf_request) (uint32_t camera_handle,
    705                                          uint32_t ch_id);
    706 
    707     /** flush_super_buf_queue: function definition for flushing out
    708      *                     all frames in the superbuf queue up to frame_idx,
    709      *                     even if frames with frame_idx come in later than
    710      *                     this call.
    711      *    @camera_handle : camer handler
    712      *    @ch_id : channel handler
    713      *    @frame_idx : frame index up until which all superbufs are flushed
    714      *  Return value: 0 -- success
    715      *                -1 -- failure
    716      **/
    717     int32_t (*flush_super_buf_queue) (uint32_t camera_handle,
    718                                       uint32_t ch_id, uint32_t frame_idx);
    719 
    720     /** configure_notify_mode: function definition for configuring the
    721      *                         notification mode of channel
    722      *    @camera_handle : camera handler
    723      *    @ch_id : channel handler
    724      *    @notify_mode : notification mode
    725      *  Return value: 0 -- success
    726      *                -1 -- failure
    727      **/
    728     int32_t (*configure_notify_mode) (uint32_t camera_handle,
    729                                       uint32_t ch_id,
    730                                       mm_camera_super_buf_notify_mode_t notify_mode);
    731 
    732    /** process_advanced_capture: function definition for start/stop advanced capture
    733      *                    for snapshot.
    734      *    @camera_handle : camera handle
    735      *    @ch_id : channel handler
    736      *    @type :  advanced capture type.
    737      *    @trigger    : flag indicating if advanced capture needs to be done
    738      *                     0 -- stop advanced capture
    739      *                     1 -- start advanced capture
    740      *    @in_value: Input value. Configaration
    741      *  Return value: 0 -- success
    742      *                -1 -- failure
    743      **/
    744     int32_t (*process_advanced_capture) (uint32_t camera_handle,
    745              uint32_t ch_id, mm_camera_advanced_capture_t type,
    746              int8_t start_flag, void *in_value);
    747 } mm_camera_ops_t;
    748 
    749 /** mm_camera_vtbl_t: virtual table for camera operations
    750 *    @camera_handle : camera handler which uniquely identifies a
    751 *                   camera object
    752 *    @ops : API call table
    753 **/
    754 typedef struct {
    755     uint32_t camera_handle;
    756     mm_camera_ops_t *ops;
    757 } mm_camera_vtbl_t;
    758 
    759 /* return number of cameras */
    760 uint8_t get_num_of_cameras();
    761 
    762 /* return reference pointer of camera vtbl */
    763 mm_camera_vtbl_t * camera_open(uint8_t camera_idx);
    764 
    765 /* helper functions */
    766 int32_t mm_stream_calc_offset_preview(cam_format_t fmt,
    767         cam_dimension_t *dim,
    768         cam_stream_buf_plane_info_t *buf_planes);
    769 
    770 int32_t mm_stream_calc_offset_post_view(cam_format_t fmt,
    771         cam_dimension_t *dim,
    772         cam_stream_buf_plane_info_t *buf_planes);
    773 
    774 int32_t mm_stream_calc_offset_snapshot(cam_format_t fmt,
    775         cam_dimension_t *dim,
    776         cam_padding_info_t *padding,
    777         cam_stream_buf_plane_info_t *buf_planes);
    778 
    779 int32_t mm_stream_calc_offset_raw(cam_format_t fmt,
    780         cam_dimension_t *dim,
    781         cam_padding_info_t *padding,
    782         cam_stream_buf_plane_info_t *buf_planes);
    783 
    784 int32_t mm_stream_calc_offset_video(cam_dimension_t *dim,
    785         cam_stream_buf_plane_info_t *buf_planes);
    786 
    787 int32_t mm_stream_calc_offset_metadata(cam_dimension_t *dim,
    788         cam_padding_info_t *padding,
    789         cam_stream_buf_plane_info_t *buf_planes);
    790 
    791 int32_t mm_stream_calc_offset_postproc(cam_stream_info_t *stream_info,
    792         cam_padding_info_t *padding,
    793         cam_stream_buf_plane_info_t *buf_planes);
    794 
    795 int32_t mm_stream_calc_offset_analysis(cam_format_t fmt,
    796         cam_dimension_t *dim,
    797         cam_padding_info_t *padding,
    798         cam_stream_buf_plane_info_t *buf_planes);
    799 
    800 struct camera_info *get_cam_info(uint32_t camera_id);
    801 #endif /*__MM_CAMERA_INTERFACE_H__*/
    802