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