Home | History | Annotate | Download | only in inc
      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_H__
     31 #define __MM_CAMERA_H__
     32 
     33 // System dependencies
     34 #include <poll.h>
     35 
     36 // Camera dependencies
     37 #include "camera_common.h"
     38 #include "cam_semaphore.h"
     39 #include "mm_camera_interface.h"
     40 #include "mm_camera_shim.h"
     41 
     42 /**********************************************************************************
     43 * Data structure declarations
     44 ***********************************************************************************/
     45 /* num of callbacks allowed for an event type */
     46 #define MM_CAMERA_EVT_ENTRY_MAX 4
     47 /* num of data callbacks allowed in a stream obj */
     48 #define MM_CAMERA_STREAM_BUF_CB_MAX 4
     49 /* num of data poll threads allowed in a channel obj */
     50 #define MM_CAMERA_CHANNEL_POLL_THREAD_MAX 1
     51 
     52 #define MM_CAMERA_DEV_NAME_LEN 32
     53 #define MM_CAMERA_DEV_OPEN_TRIES 20
     54 #define MM_CAMERA_DEV_OPEN_RETRY_SLEEP 20
     55 #define THREAD_NAME_SIZE 15
     56 
     57 /* Future frame idx, large enough to make sure capture
     58 * settings can be applied and small enough to still capture an image */
     59 #define MM_CAMERA_MAX_FUTURE_FRAME_WAIT 100
     60 #define WAIT_TIMEOUT 5
     61 
     62 #ifndef TRUE
     63 #define TRUE 1
     64 #endif
     65 
     66 #ifndef FALSE
     67 #define FALSE 0
     68 #endif
     69 
     70 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
     71 
     72 struct mm_channel;
     73 struct mm_stream;
     74 struct mm_camera_obj;
     75 
     76 typedef int64_t nsecs_t;
     77 
     78 typedef enum
     79 {
     80     MM_CAMERA_CMD_TYPE_DATA_CB,    /* dataB CMD */
     81     MM_CAMERA_CMD_TYPE_EVT_CB,     /* evtCB CMD */
     82     MM_CAMERA_CMD_TYPE_EXIT,       /* EXIT */
     83     MM_CAMERA_CMD_TYPE_REQ_DATA_CB,/* request data */
     84     MM_CAMERA_CMD_TYPE_SUPER_BUF_DATA_CB,    /* superbuf dataB CMD */
     85     MM_CAMERA_CMD_TYPE_CONFIG_NOTIFY, /* configure notify mode */
     86     MM_CAMERA_CMD_TYPE_START_ZSL, /* start zsl snapshot for channel */
     87     MM_CAMERA_CMD_TYPE_STOP_ZSL, /* stop zsl snapshot for channel */
     88     MM_CAMERA_CMD_TYPE_FLUSH_QUEUE, /* flush queue */
     89     MM_CAMERA_CMD_TYPE_GENERAL,  /* general cmd */
     90     MM_CAMERA_CMD_TYPE_MAX
     91 } mm_camera_cmdcb_type_t;
     92 
     93 typedef struct {
     94     uint32_t stream_id;
     95     uint32_t frame_idx;
     96     uint32_t flags;
     97     mm_camera_buf_def_t *buf; /* ref to buf */
     98 } mm_camera_buf_info_t;
     99 
    100 typedef enum {
    101     MM_CAMERA_GENERIC_CMD_TYPE_AE_BRACKETING,
    102     MM_CAMERA_GENERIC_CMD_TYPE_AF_BRACKETING,
    103     MM_CAMERA_GENERIC_CMD_TYPE_FLASH_BRACKETING,
    104     MM_CAMERA_GENERIC_CMD_TYPE_ZOOM_1X,
    105     MM_CAMERA_GENERIC_CMD_TYPE_CAPTURE_SETTING,
    106 } mm_camera_generic_cmd_type_t;
    107 
    108 typedef struct {
    109     mm_camera_generic_cmd_type_t type;
    110     uint32_t payload[32];
    111     union {
    112         cam_capture_frame_config_t frame_config;
    113     };
    114 } mm_camera_generic_cmd_t;
    115 
    116 typedef struct {
    117     uint32_t frame_idx;
    118     cam_stream_type_t stream_type;
    119 } mm_camera_flush_cmd_t;
    120 
    121 typedef struct {
    122     mm_camera_cmdcb_type_t cmd_type;
    123     union {
    124         mm_camera_buf_info_t buf;    /* frame buf if dataCB */
    125         mm_camera_event_t evt;       /* evt if evtCB */
    126         mm_camera_super_buf_t superbuf; /* superbuf if superbuf dataCB*/
    127         mm_camera_req_buf_t req_buf; /* num of buf requested */
    128         mm_camera_flush_cmd_t flush_cmd; /* frame idx boundary for flush superbuf queue*/
    129         mm_camera_super_buf_notify_mode_t notify_mode; /* notification mode */
    130         mm_camera_generic_cmd_t gen_cmd;
    131     } u;
    132 } mm_camera_cmdcb_t;
    133 
    134 typedef void (*mm_camera_cmd_cb_t)(mm_camera_cmdcb_t * cmd_cb, void* user_data);
    135 
    136 typedef struct {
    137     uint8_t is_active;     /*indicates whether thread is active or not */
    138     cam_queue_t cmd_queue; /* cmd queue (queuing dataCB, asyncCB, or exitCMD) */
    139     pthread_t cmd_pid;           /* cmd thread ID */
    140     cam_semaphore_t cmd_sem;     /* semaphore for cmd thread */
    141     cam_semaphore_t sync_sem;     /* semaphore for synchronization with cmd thread */
    142     mm_camera_cmd_cb_t cb;       /* cb for cmd */
    143     void* user_data;             /* user_data for cb */
    144     char threadName[THREAD_NAME_SIZE];
    145 } mm_camera_cmd_thread_t;
    146 
    147 typedef enum {
    148     MM_CAMERA_POLL_TYPE_EVT,
    149     MM_CAMERA_POLL_TYPE_DATA,
    150     MM_CAMERA_POLL_TYPE_MAX
    151 } mm_camera_poll_thread_type_t;
    152 
    153 /* function ptr defined for poll notify CB,
    154  * registered at poll thread with poll fd */
    155 typedef void (*mm_camera_poll_notify_t)(void *user_data);
    156 
    157 typedef struct {
    158     int32_t fd;
    159     mm_camera_poll_notify_t notify_cb;
    160     uint32_t handler;
    161     void* user_data;
    162 } mm_camera_poll_entry_t;
    163 
    164 typedef struct {
    165     mm_camera_poll_thread_type_t poll_type;
    166     /* array to store poll fd and cb info
    167      * for MM_CAMERA_POLL_TYPE_EVT, only index 0 is valid;
    168      * for MM_CAMERA_POLL_TYPE_DATA, depends on valid stream fd */
    169     mm_camera_poll_entry_t poll_entries[MAX_STREAM_NUM_IN_BUNDLE];
    170     int32_t pfds[2];
    171     pthread_t pid;
    172     int32_t state;
    173     int timeoutms;
    174     uint32_t cmd;
    175     struct pollfd poll_fds[MAX_STREAM_NUM_IN_BUNDLE + 1];
    176     uint8_t num_fds;
    177     pthread_mutex_t mutex;
    178     pthread_cond_t cond_v;
    179     int32_t status;
    180     char threadName[THREAD_NAME_SIZE];
    181     //void *my_obj;
    182 } mm_camera_poll_thread_t;
    183 
    184 /* mm_stream */
    185 typedef enum {
    186     MM_STREAM_STATE_NOTUSED = 0,      /* not used */
    187     MM_STREAM_STATE_INITED,           /* inited  */
    188     MM_STREAM_STATE_ACQUIRED,         /* acquired, fd opened  */
    189     MM_STREAM_STATE_CFG,              /* fmt & dim configured */
    190     MM_STREAM_STATE_BUFFED,           /* buf allocated */
    191     MM_STREAM_STATE_REG,              /* buf regged, stream off */
    192     MM_STREAM_STATE_ACTIVE,           /* active */
    193     MM_STREAM_STATE_MAX
    194 } mm_stream_state_type_t;
    195 
    196 typedef enum {
    197     MM_STREAM_EVT_ACQUIRE,
    198     MM_STREAM_EVT_RELEASE,
    199     MM_STREAM_EVT_SET_FMT,
    200     MM_STREAM_EVT_GET_BUF,
    201     MM_STREAM_EVT_PUT_BUF,
    202     MM_STREAM_EVT_REG_BUF,
    203     MM_STREAM_EVT_UNREG_BUF,
    204     MM_STREAM_EVT_START,
    205     MM_STREAM_EVT_STOP,
    206     MM_STREAM_EVT_QBUF,
    207     MM_STREAM_EVT_SET_PARM,
    208     MM_STREAM_EVT_GET_PARM,
    209     MM_STREAM_EVT_DO_ACTION,
    210     MM_STREAM_EVT_GET_QUEUED_BUF_COUNT,
    211     MM_STREAM_EVT_CANCEL_BUF,
    212     MM_STREAM_EVT_MAX
    213 } mm_stream_evt_type_t;
    214 
    215 typedef struct {
    216     mm_camera_buf_notify_t cb;
    217     void *user_data;
    218     /* cb_count = -1: infinite
    219      * cb_count > 0: register only for required times */
    220     int8_t cb_count;
    221     mm_camera_stream_cb_type cb_type;
    222 } mm_stream_data_cb_t;
    223 
    224 typedef struct {
    225     /* buf reference count */
    226     uint8_t buf_refcnt;
    227 
    228     /* This flag is to indicate if after allocation,
    229      * the corresponding buf needs to qbuf into kernel
    230      * (e.g. for preview usecase, display needs to hold two bufs,
    231      * so no need to qbuf these two bufs initially) */
    232     uint8_t initial_reg_flag;
    233 
    234     /* indicate if buf is in kernel(1) or client(0) */
    235     uint8_t in_kernel;
    236     /*indicate if this buffer is mapped to daemon*/
    237     int8_t map_status;
    238 } mm_stream_buf_status_t;
    239 
    240 typedef struct mm_stream {
    241     uint32_t my_hdl; /* local stream id */
    242     uint32_t server_stream_id; /* stream id from server */
    243     int32_t fd;
    244     mm_stream_state_type_t state;
    245 
    246     /* stream info*/
    247     cam_stream_info_t *stream_info;
    248 
    249     /* padding info */
    250     cam_padding_info_t padding_info;
    251 
    252     /* offset */
    253     cam_frame_len_offset_t frame_offset;
    254 
    255     pthread_mutex_t cmd_lock; /* lock to protect cmd_thread */
    256     mm_camera_cmd_thread_t cmd_thread;
    257 
    258     /* dataCB registered on this stream obj */
    259     pthread_mutex_t cb_lock; /* cb lock to protect buf_cb */
    260     mm_stream_data_cb_t buf_cb[MM_CAMERA_STREAM_BUF_CB_MAX];
    261 
    262     /* stream buffer management */
    263     pthread_mutex_t buf_lock;
    264     uint8_t buf_num; /* num of buffers allocated */
    265     mm_camera_buf_def_t* buf; /* ptr to buf array */
    266     mm_stream_buf_status_t buf_status[CAM_MAX_NUM_BUFS_PER_STREAM]; /* ptr to buf status array */
    267 
    268     uint8_t plane_buf_num; /* num of plane buffers allocated  Used only in Batch mode*/
    269     mm_camera_buf_def_t *plane_buf; /*Pointer to plane buffer array Used only in Batch mode */
    270     int32_t cur_buf_idx; /* Current container buffer active filling. Used only in Batch mode*/
    271     uint8_t cur_bufs_staged; /*Number of plane buf freed by HAL for this usr buf*/
    272 
    273 
    274     /* reference to parent channel_obj */
    275     struct mm_channel* ch_obj;
    276 
    277     uint8_t is_bundled; /* flag if stream is bundled */
    278 
    279     /* reference to linked channel_obj */
    280     struct mm_channel* linked_obj;
    281     struct mm_stream * linked_stream; /* original stream */
    282     uint8_t is_linked; /* flag if stream is linked */
    283 
    284     mm_camera_stream_mem_vtbl_t mem_vtbl; /* mem ops tbl */
    285 
    286     mm_camera_map_unmap_ops_tbl_t map_ops;
    287 
    288     int8_t queued_buffer_count;
    289 
    290     /*latest timestamp of this stream frame received & last frameID*/
    291     uint32_t prev_frameID;
    292     nsecs_t prev_timestamp;
    293 
    294     /* Need to wait for buffer mapping before stream-on*/
    295     pthread_cond_t buf_cond;
    296 } mm_stream_t;
    297 
    298 /* mm_channel */
    299 typedef enum {
    300     MM_CHANNEL_STATE_NOTUSED = 0,   /* not used */
    301     MM_CHANNEL_STATE_STOPPED,       /* stopped */
    302     MM_CHANNEL_STATE_ACTIVE,        /* active, at least one stream active */
    303     MM_CHANNEL_STATE_PAUSED,        /* paused */
    304     MM_CHANNEL_STATE_MAX
    305 } mm_channel_state_type_t;
    306 
    307 typedef enum {
    308     MM_CHANNEL_EVT_ADD_STREAM,
    309     MM_CHANNEL_EVT_DEL_STREAM,
    310     MM_CHANNEL_EVT_LINK_STREAM,
    311     MM_CHANNEL_EVT_CONFIG_STREAM,
    312     MM_CHANNEL_EVT_GET_BUNDLE_INFO,
    313     MM_CHANNEL_EVT_START,
    314     MM_CHANNEL_EVT_STOP,
    315     MM_CHANNEL_EVT_PAUSE,
    316     MM_CHANNEL_EVT_RESUME,
    317     MM_CHANNEL_EVT_REQUEST_SUPER_BUF,
    318     MM_CHANNEL_EVT_CANCEL_REQUEST_SUPER_BUF,
    319     MM_CHANNEL_EVT_FLUSH_SUPER_BUF_QUEUE,
    320     MM_CHANNEL_EVT_CONFIG_NOTIFY_MODE,
    321     MM_CHANNEL_EVT_START_ZSL_SNAPSHOT,
    322     MM_CHANNEL_EVT_STOP_ZSL_SNAPSHOT,
    323     MM_CHANNEL_EVT_MAP_STREAM_BUF,
    324     MM_CHANNEL_EVT_UNMAP_STREAM_BUF,
    325     MM_CHANNEL_EVT_SET_STREAM_PARM,
    326     MM_CHANNEL_EVT_GET_STREAM_PARM,
    327     MM_CHANNEL_EVT_DO_STREAM_ACTION,
    328     MM_CHANNEL_EVT_DELETE,
    329     MM_CHANNEL_EVT_AF_BRACKETING,
    330     MM_CHANNEL_EVT_AE_BRACKETING,
    331     MM_CHANNEL_EVT_FLASH_BRACKETING,
    332     MM_CHANNEL_EVT_ZOOM_1X,
    333     MM_CAMERA_EVT_CAPTURE_SETTING,
    334     MM_CHANNEL_EVT_GET_STREAM_QUEUED_BUF_COUNT,
    335     MM_CHANNEL_EVT_MAP_STREAM_BUFS,
    336     MM_CHANNEL_EVT_REG_STREAM_BUF_CB
    337 } mm_channel_evt_type_t;
    338 
    339 typedef struct {
    340     uint32_t stream_id;
    341     mm_camera_stream_config_t *config;
    342 } mm_evt_paylod_config_stream_t;
    343 
    344 typedef struct {
    345     uint32_t stream_id;
    346     cam_stream_parm_buffer_t *parms;
    347 } mm_evt_paylod_set_get_stream_parms_t;
    348 
    349 typedef struct {
    350     uint32_t stream_id;
    351     void *actions;
    352 } mm_evt_paylod_do_stream_action_t;
    353 
    354 typedef struct {
    355     uint32_t stream_id;
    356     mm_stream_data_cb_t buf_cb;
    357 } mm_evt_paylod_reg_stream_buf_cb;
    358 
    359 typedef struct {
    360     uint8_t num_of_bufs;
    361     mm_camera_buf_info_t super_buf[MAX_STREAM_NUM_IN_BUNDLE];
    362     uint8_t matched;
    363     uint8_t expected_frame;
    364     uint32_t frame_idx;
    365     /* unmatched meta idx needed in case of low priority queue */
    366     uint32_t unmatched_meta_idx;
    367 } mm_channel_queue_node_t;
    368 
    369 typedef struct {
    370     cam_queue_t que;
    371     uint8_t num_streams;
    372     /* container for bundled stream handlers */
    373     uint32_t bundled_streams[MAX_STREAM_NUM_IN_BUNDLE];
    374     mm_camera_channel_attr_t attr;
    375     uint32_t expected_frame_id;
    376     uint32_t match_cnt;
    377     uint32_t expected_frame_id_without_led;
    378     uint32_t led_on_start_frame_id;
    379     uint32_t led_off_start_frame_id;
    380     uint32_t led_on_num_frames;
    381     uint32_t once;
    382     uint32_t frame_skip_count;
    383     uint32_t good_frame_id;
    384 } mm_channel_queue_t;
    385 
    386 typedef struct {
    387     uint8_t is_active; /* flag to indicate if bundle is valid */
    388     /* queue to store bundled super buffers */
    389     mm_channel_queue_t superbuf_queue;
    390     mm_camera_buf_notify_t super_buf_notify_cb;
    391     void *user_data;
    392 } mm_channel_bundle_t;
    393 
    394 /* Nodes used for frame sync */
    395 typedef struct {
    396     /* Frame idx */
    397     uint32_t frame_idx;
    398     /* Frame present for corresponding channel*/
    399     uint32_t frame_valid[MAX_NUM_CAMERA_PER_BUNDLE];
    400     /* Frame present in all channels*/
    401     uint32_t matched;
    402 } mm_channel_sync_node_t;
    403 
    404 /* Frame sync information */
    405 typedef struct {
    406     /* Number of camera channels that need to be synced*/
    407     uint8_t num_cam;
    408     /* position of the next node to be updated */
    409     uint8_t pos;
    410     /* circular node array used to store frame information */
    411     mm_channel_sync_node_t node[MM_CAMERA_FRAME_SYNC_NODES];
    412     /* Channel corresponding to each camera */
    413     struct mm_channel *ch_obj[MAX_NUM_CAMERA_PER_BUNDLE];
    414     /* Cb corresponding to each camera */
    415     mm_camera_buf_notify_t cb[MAX_NUM_CAMERA_PER_BUNDLE];
    416 } mm_channel_frame_sync_info_t;
    417 
    418 /* Node information for multiple superbuf callbacks
    419 *  This can be used to batch nodes before sending to upper layer */
    420 typedef struct {
    421     /* Number of nodes to be sent*/
    422     uint8_t num_nodes;
    423     /* queue node information*/
    424     mm_channel_queue_node_t *node[MAX_NUM_CAMERA_PER_BUNDLE];
    425     /* channel information*/
    426     struct mm_channel *ch_obj[MAX_NUM_CAMERA_PER_BUNDLE];
    427 } mm_channel_node_info_t;
    428 
    429 typedef enum {
    430     MM_CHANNEL_BRACKETING_STATE_OFF,
    431     MM_CHANNEL_BRACKETING_STATE_WAIT_GOOD_FRAME_IDX,
    432     MM_CHANNEL_BRACKETING_STATE_ACTIVE,
    433 } mm_channel_bracketing_state_t;
    434 
    435 typedef struct mm_channel {
    436     uint32_t my_hdl;
    437     mm_channel_state_type_t state;
    438     pthread_mutex_t ch_lock; /* channel lock */
    439 
    440     /* stream bundle info in the channel */
    441     mm_channel_bundle_t bundle;
    442 
    443     /* num of pending suferbuffers */
    444     uint32_t pending_cnt;
    445     uint32_t pending_retro_cnt;
    446     mm_camera_req_buf_type_t req_type;
    447     uint32_t bWaitForPrepSnapshotDone;
    448     uint32_t unLockAEC;
    449     /* num of pending suferbuffers */
    450     uint8_t stopZslSnapshot;
    451 
    452     /* cmd thread for superbuffer dataCB and async stop*/
    453     mm_camera_cmd_thread_t cmd_thread;
    454 
    455     /* cb thread for sending data cb */
    456     mm_camera_cmd_thread_t cb_thread;
    457 
    458     /* data poll thread
    459     * currently one data poll thread per channel
    460     * could extended to support one data poll thread per stream in the channel */
    461     mm_camera_poll_thread_t poll_thread[MM_CAMERA_CHANNEL_POLL_THREAD_MAX];
    462 
    463     /* container for all streams in channel */
    464     mm_stream_t streams[MAX_STREAM_NUM_IN_BUNDLE];
    465 
    466     /* reference to parent cam_obj */
    467     struct mm_camera_obj* cam_obj;
    468 
    469     /* manual zsl snapshot control */
    470     uint8_t manualZSLSnapshot;
    471 
    472     /* control for zsl led */
    473     uint8_t startZSlSnapshotCalled;
    474     uint8_t needLEDFlash;
    475     mm_channel_bracketing_state_t bracketingState;
    476     uint8_t isFlashBracketingEnabled;
    477     uint8_t isZoom1xFrameRequested;
    478     uint32_t burstSnapNum;
    479     char threadName[THREAD_NAME_SIZE];
    480 
    481     /*Buffer diverted*/
    482     uint8_t diverted_frame_id;
    483     uint32_t sessionid;
    484 
    485     /*Frame capture configaration*/
    486     uint8_t isConfigCapture;
    487     uint8_t cur_capture_idx;
    488     uint32_t capture_frame_id[MAX_CAPTURE_BATCH_NUM];
    489     cam_capture_frame_config_t frameConfig;
    490     uint8_t needLowLightZSL;
    491 } mm_channel_t;
    492 
    493 typedef struct {
    494     mm_channel_t *ch;
    495     uint32_t stream_id;
    496 } mm_camera_stream_link_t;
    497 
    498 /* struct to store information about pp cookie*/
    499 typedef struct {
    500     uint32_t cam_hdl;
    501     uint32_t ch_hdl;
    502     uint32_t stream_hdl;
    503     mm_channel_queue_node_t* super_buf;
    504 } mm_channel_pp_info_t;
    505 
    506 /* mm_camera */
    507 typedef struct {
    508     mm_camera_event_notify_t evt_cb;
    509     void *user_data;
    510 } mm_camera_evt_entry_t;
    511 
    512 typedef struct {
    513     mm_camera_evt_entry_t evt[MM_CAMERA_EVT_ENTRY_MAX];
    514     /* reg_count <=0: infinite
    515      * reg_count > 0: register only for required times */
    516     int reg_count;
    517 } mm_camera_evt_obj_t;
    518 
    519 typedef struct mm_camera_obj {
    520     uint32_t my_hdl;
    521     int ref_count;
    522     int32_t ctrl_fd;
    523     int32_t ds_fd; /* domain socket fd */
    524     pthread_mutex_t cam_lock;
    525     pthread_mutex_t cb_lock; /* lock for evt cb */
    526     mm_channel_t ch[MM_CAMERA_CHANNEL_MAX];
    527     mm_camera_evt_obj_t evt;
    528     mm_camera_poll_thread_t evt_poll_thread; /* evt poll thread */
    529     mm_camera_cmd_thread_t evt_thread;       /* thread for evt CB */
    530     mm_camera_vtbl_t vtbl;
    531 
    532     pthread_mutex_t evt_lock;
    533     pthread_cond_t evt_cond;
    534     mm_camera_event_t evt_rcvd;
    535 
    536     pthread_mutex_t msg_lock; /* lock for sending msg through socket */
    537     uint32_t sessionid; /* Camera server session id */
    538 } mm_camera_obj_t;
    539 
    540 typedef struct {
    541     int8_t num_cam;
    542     mm_camera_shim_ops_t cam_shim_ops;
    543     char video_dev_name[MM_CAMERA_MAX_NUM_SENSORS][MM_CAMERA_DEV_NAME_LEN];
    544     mm_camera_obj_t *cam_obj[MM_CAMERA_MAX_NUM_SENSORS];
    545     struct camera_info info[MM_CAMERA_MAX_NUM_SENSORS];
    546     cam_sync_type_t cam_type[MM_CAMERA_MAX_NUM_SENSORS];
    547     cam_sync_mode_t cam_mode[MM_CAMERA_MAX_NUM_SENSORS];
    548     uint8_t is_yuv[MM_CAMERA_MAX_NUM_SENSORS]; // 1=CAM_SENSOR_YUV, 0=CAM_SENSOR_RAW
    549 } mm_camera_ctrl_t;
    550 
    551 typedef enum {
    552     mm_camera_async_call,
    553     mm_camera_sync_call
    554 } mm_camera_call_type_t;
    555 
    556 /**********************************************************************************
    557 * external function declare
    558 ***********************************************************************************/
    559 /* utility functions */
    560 /* set int32_t value */
    561 extern int32_t mm_camera_util_s_ctrl(mm_camera_obj_t *my_obj,
    562         int stream_id, int32_t fd, uint32_t id, int32_t *value);
    563 
    564 /* get int32_t value */
    565 extern int32_t mm_camera_util_g_ctrl(mm_camera_obj_t *my_obj,
    566         int stream_id, int32_t fd, uint32_t id, int32_t *value);
    567 
    568 /* send msg throught domain socket for fd mapping */
    569 extern int32_t mm_camera_util_sendmsg(mm_camera_obj_t *my_obj,
    570                                       void *msg,
    571                                       size_t buf_size,
    572                                       int sendfd);
    573 
    574 /* send msg through domain socket for bundled fd mapping */
    575 extern int32_t mm_camera_util_bundled_sendmsg(mm_camera_obj_t *my_obj,
    576                                               void *msg,
    577                                               size_t buf_size,
    578                                               int sendfds[CAM_MAX_NUM_BUFS_PER_STREAM],
    579                                               int numfds);
    580 
    581 /* Check if hardware target is A family */
    582 uint8_t mm_camera_util_chip_is_a_family(void);
    583 
    584 /* mm-camera */
    585 extern int32_t mm_camera_open(mm_camera_obj_t *my_obj);
    586 extern int32_t mm_camera_close(mm_camera_obj_t *my_obj);
    587 extern int32_t mm_camera_register_event_notify(mm_camera_obj_t *my_obj,
    588                                                mm_camera_event_notify_t evt_cb,
    589                                                void * user_data);
    590 extern int32_t mm_camera_qbuf(mm_camera_obj_t *my_obj,
    591                               uint32_t ch_id,
    592                               mm_camera_buf_def_t *buf);
    593 extern int32_t mm_camera_cancel_buf(mm_camera_obj_t *my_obj,
    594                        uint32_t ch_id,
    595                        uint32_t stream_id,
    596                        uint32_t buf_idx);
    597 extern int32_t mm_camera_get_queued_buf_count(mm_camera_obj_t *my_obj,
    598         uint32_t ch_id, uint32_t stream_id);
    599 extern int32_t mm_camera_query_capability(mm_camera_obj_t *my_obj);
    600 extern int32_t mm_camera_set_parms(mm_camera_obj_t *my_obj,
    601                                    parm_buffer_t *parms);
    602 extern int32_t mm_camera_get_parms(mm_camera_obj_t *my_obj,
    603                                    parm_buffer_t *parms);
    604 extern int32_t mm_camera_map_buf(mm_camera_obj_t *my_obj,
    605                                  uint8_t buf_type,
    606                                  int fd,
    607                                  size_t size,
    608                                  void *buffer);
    609 extern int32_t mm_camera_map_bufs(mm_camera_obj_t *my_obj,
    610                                   const cam_buf_map_type_list *buf_map_list);
    611 extern int32_t mm_camera_unmap_buf(mm_camera_obj_t *my_obj,
    612                                    uint8_t buf_type);
    613 extern int32_t mm_camera_do_auto_focus(mm_camera_obj_t *my_obj);
    614 extern int32_t mm_camera_cancel_auto_focus(mm_camera_obj_t *my_obj);
    615 extern int32_t mm_camera_prepare_snapshot(mm_camera_obj_t *my_obj,
    616                                           int32_t do_af_flag);
    617 extern int32_t mm_camera_start_zsl_snapshot(mm_camera_obj_t *my_obj);
    618 extern int32_t mm_camera_stop_zsl_snapshot(mm_camera_obj_t *my_obj);
    619 extern int32_t mm_camera_flush(mm_camera_obj_t *my_obj);
    620 extern int32_t mm_camera_start_zsl_snapshot_ch(mm_camera_obj_t *my_obj,
    621         uint32_t ch_id);
    622 extern int32_t mm_camera_stop_zsl_snapshot_ch(mm_camera_obj_t *my_obj,
    623         uint32_t ch_id);
    624 extern uint32_t mm_camera_add_channel(mm_camera_obj_t *my_obj,
    625                                       mm_camera_channel_attr_t *attr,
    626                                       mm_camera_buf_notify_t channel_cb,
    627                                       void *userdata);
    628 extern int32_t mm_camera_del_channel(mm_camera_obj_t *my_obj,
    629                                      uint32_t ch_id);
    630 extern int32_t mm_camera_get_bundle_info(mm_camera_obj_t *my_obj,
    631                                          uint32_t ch_id,
    632                                          cam_bundle_config_t *bundle_info);
    633 extern uint32_t mm_camera_add_stream(mm_camera_obj_t *my_obj,
    634                                      uint32_t ch_id);
    635 extern int32_t mm_camera_del_stream(mm_camera_obj_t *my_obj,
    636                                     uint32_t ch_id,
    637                                     uint32_t stream_id);
    638 extern uint32_t mm_camera_link_stream(mm_camera_obj_t *my_obj,
    639         uint32_t ch_id,
    640         uint32_t stream_id,
    641         uint32_t linked_ch_id);
    642 
    643 extern int32_t mm_camera_reg_stream_buf_cb(mm_camera_obj_t *my_obj,
    644         uint32_t ch_id, uint32_t stream_id, mm_camera_buf_notify_t buf_cb,
    645         mm_camera_stream_cb_type cb_type, void *userdata);
    646 
    647 extern int32_t mm_camera_config_stream(mm_camera_obj_t *my_obj,
    648                                        uint32_t ch_id,
    649                                        uint32_t stream_id,
    650                                        mm_camera_stream_config_t *config);
    651 extern int32_t mm_camera_start_channel(mm_camera_obj_t *my_obj,
    652                                        uint32_t ch_id);
    653 extern int32_t mm_camera_stop_channel(mm_camera_obj_t *my_obj,
    654                                       uint32_t ch_id);
    655 extern int32_t mm_camera_request_super_buf(mm_camera_obj_t *my_obj,
    656         uint32_t ch_id, mm_camera_req_buf_t *buf);
    657 extern int32_t mm_camera_cancel_super_buf_request(mm_camera_obj_t *my_obj,
    658                                                   uint32_t ch_id);
    659 extern int32_t mm_camera_flush_super_buf_queue(mm_camera_obj_t *my_obj,
    660                                                uint32_t ch_id,
    661                                                uint32_t frame_idx);
    662 extern int32_t mm_camera_config_channel_notify(mm_camera_obj_t *my_obj,
    663                                                uint32_t ch_id,
    664                                                mm_camera_super_buf_notify_mode_t notify_mode);
    665 extern int32_t mm_camera_set_stream_parms(mm_camera_obj_t *my_obj,
    666                                           uint32_t ch_id,
    667                                           uint32_t s_id,
    668                                           cam_stream_parm_buffer_t *parms);
    669 extern int32_t mm_camera_get_stream_parms(mm_camera_obj_t *my_obj,
    670                                           uint32_t ch_id,
    671                                           uint32_t s_id,
    672                                           cam_stream_parm_buffer_t *parms);
    673 extern int32_t mm_camera_register_event_notify_internal(mm_camera_obj_t *my_obj,
    674                                                         mm_camera_event_notify_t evt_cb,
    675                                                         void * user_data);
    676 extern int32_t mm_camera_map_stream_buf(mm_camera_obj_t *my_obj,
    677                                         uint32_t ch_id,
    678                                         uint32_t stream_id,
    679                                         uint8_t buf_type,
    680                                         uint32_t buf_idx,
    681                                         int32_t plane_idx,
    682                                         int fd,
    683                                         size_t size,
    684                                         void *buffer);
    685 extern int32_t mm_camera_map_stream_bufs(mm_camera_obj_t *my_obj,
    686                                          uint32_t ch_id,
    687                                          const cam_buf_map_type_list *buf_map_list);
    688 extern int32_t mm_camera_unmap_stream_buf(mm_camera_obj_t *my_obj,
    689                                           uint32_t ch_id,
    690                                           uint32_t stream_id,
    691                                           uint8_t buf_type,
    692                                           uint32_t buf_idx,
    693                                           int32_t plane_idx);
    694 extern int32_t mm_camera_do_stream_action(mm_camera_obj_t *my_obj,
    695                                           uint32_t ch_id,
    696                                           uint32_t stream_id,
    697                                           void *actions);
    698 extern int32_t mm_camera_get_session_id(mm_camera_obj_t *my_obj,
    699                                         uint32_t* sessionid);
    700 extern int32_t mm_camera_sync_related_sensors(mm_camera_obj_t *my_obj,
    701                                    cam_sync_related_sensors_event_info_t *parms);
    702 
    703 /* mm_channel */
    704 extern int32_t mm_channel_fsm_fn(mm_channel_t *my_obj,
    705                                  mm_channel_evt_type_t evt,
    706                                  void * in_val,
    707                                  void * out_val);
    708 extern int32_t mm_channel_init(mm_channel_t *my_obj,
    709                                mm_camera_channel_attr_t *attr,
    710                                mm_camera_buf_notify_t channel_cb,
    711                                void *userdata);
    712 /* qbuf is a special case that not going through state machine.
    713  * This is to avoid deadlock when trying to aquire ch_lock,
    714  * from the context of dataCB, but async stop is holding ch_lock */
    715 extern int32_t mm_channel_qbuf(mm_channel_t *my_obj,
    716                                mm_camera_buf_def_t *buf);
    717 extern int32_t mm_channel_cancel_buf(mm_channel_t *my_obj,
    718                         uint32_t stream_id, uint32_t buf_idx);
    719 /* mm_stream */
    720 extern int32_t mm_stream_fsm_fn(mm_stream_t *my_obj,
    721                                 mm_stream_evt_type_t evt,
    722                                 void * in_val,
    723                                 void * out_val);
    724 /* Function to register special callback for stream buffer*/
    725 extern int32_t mm_stream_reg_buf_cb(mm_stream_t *my_obj,
    726         mm_stream_data_cb_t val);
    727 extern int32_t mm_stream_map_buf(mm_stream_t *my_obj,
    728                                  uint8_t buf_type,
    729                                  uint32_t frame_idx,
    730                                  int32_t plane_idx,
    731                                  int fd,
    732                                  size_t size,
    733                                  void *buffer);
    734 extern int32_t mm_stream_map_bufs(mm_stream_t *my_obj,
    735                                   const cam_buf_map_type_list *buf_map_list);
    736 extern int32_t mm_stream_unmap_buf(mm_stream_t *my_obj,
    737                                    uint8_t buf_type,
    738                                    uint32_t frame_idx,
    739                                    int32_t plane_idx);
    740 
    741 /* utiltity fucntion declared in mm-camera-inteface2.c
    742  * and need be used by mm-camera and below*/
    743 uint32_t mm_camera_util_generate_handler(uint8_t index);
    744 const char * mm_camera_util_get_dev_name(uint32_t cam_handler);
    745 uint8_t mm_camera_util_get_index_by_handler(uint32_t handler);
    746 
    747 /* poll/cmd thread functions */
    748 extern int32_t mm_camera_poll_thread_launch(
    749                                 mm_camera_poll_thread_t * poll_cb,
    750                                 mm_camera_poll_thread_type_t poll_type);
    751 extern int32_t mm_camera_poll_thread_release(mm_camera_poll_thread_t *poll_cb);
    752 extern int32_t mm_camera_poll_thread_add_poll_fd(
    753                                 mm_camera_poll_thread_t * poll_cb,
    754                                 uint32_t handler,
    755                                 int32_t fd,
    756                                 mm_camera_poll_notify_t nofity_cb,
    757                                 void *userdata,
    758                                 mm_camera_call_type_t);
    759 extern int32_t mm_camera_poll_thread_del_poll_fd(
    760                                 mm_camera_poll_thread_t * poll_cb,
    761                                 uint32_t handler,
    762                                 mm_camera_call_type_t);
    763 extern int32_t mm_camera_poll_thread_commit_updates(
    764         mm_camera_poll_thread_t * poll_cb);
    765 extern int32_t mm_camera_cmd_thread_launch(
    766                                 mm_camera_cmd_thread_t * cmd_thread,
    767                                 mm_camera_cmd_cb_t cb,
    768                                 void* user_data);
    769 extern int32_t mm_camera_cmd_thread_name(const char* name);
    770 extern int32_t mm_camera_cmd_thread_release(mm_camera_cmd_thread_t * cmd_thread);
    771 
    772 extern int32_t mm_camera_channel_advanced_capture(mm_camera_obj_t *my_obj,
    773         uint32_t ch_id, mm_camera_advanced_capture_t type,
    774         uint32_t trigger, void *in_value);
    775 int32_t mm_camera_enqueue_evt(mm_camera_obj_t *my_obj,
    776                               mm_camera_event_t *event);
    777 int32_t mm_camera_load_shim_lib();
    778 cam_shim_packet_t *mm_camera_create_shim_cmd_packet(cam_shim_cmd_type type,
    779         uint32_t sessionID, void *data);
    780 int32_t mm_camera_destroy_shim_cmd_packet(cam_shim_packet_t *cmd);
    781 int32_t mm_camera_module_event_handler(
    782         uint32_t session_id, cam_event_t *event);
    783 cam_status_t mm_camera_module_open_session(int sessionid,
    784         int (*event_cb)(uint32_t sessionid, cam_event_t *event));
    785 int32_t mm_camera_module_close_session(int session);
    786 int32_t mm_camera_module_send_cmd(cam_shim_packet_t *event);
    787 
    788 #endif /* __MM_CAMERA_H__ */
    789