1 /*
2 Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above
10       copyright notice, this list of conditions and the following
11       disclaimer in the documentation and/or other materials provided
12       with the distribution.
13     * Neither the name of The Linux Foundation nor the names of its
14       contributors may be used to endorse or promote products derived
15       from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 
30 #ifndef __MM_CAMERA_H__
31 #define __MM_CAMERA_H__
32 
33 #include <sys/poll.h>
34 #include "mm_camera_interface.h"
35 #include "cam_list.h"
36 
37 /**********************************************************************************
38 * Data structure declare
39 ***********************************************************************************/
40 /* num of streams allowed in a channel obj */
41 #define MM_CAMEAR_STRAEM_NUM_MAX 8
42 /* num of channels allowed in a camera obj */
43 #define MM_CAMERA_CHANNEL_MAX 1
44 /* num of callbacks allowed for an event type */
45 #define MM_CAMERA_EVT_ENTRY_MAX 4
46 /* num of data callbacks allowed in a stream obj */
47 #define MM_CAMERA_STREAM_BUF_CB_MAX 4
48 /* num of data poll threads allowed in a channel obj */
49 #define MM_CAMERA_CHANNEL_POLL_THREAD_MAX 1
50 
51 #define MM_CAMERA_DEV_NAME_LEN 32
52 #define MM_CAMERA_DEV_OPEN_TRIES 2
53 #define MM_CAMERA_DEV_OPEN_RETRY_SLEEP 20
54 
55 struct mm_channel;
56 struct mm_stream;
57 struct mm_camera_obj;
58 
59 /* common use */
60 typedef struct {
61     struct cam_list list;
62     void* data;
63 } mm_camera_q_node_t;
64 
65 typedef struct {
66     mm_camera_q_node_t head; /* dummy head */
67     uint32_t size;
68     pthread_mutex_t lock;
69 } mm_camera_queue_t;
70 
71 typedef enum
72 {
73     MM_CAMERA_ASYNC_CMD_TYPE_STOP,    /* async stop */
74     MM_CAMERA_ASYNC_CMD_TYPE_MAX
75 } mm_camera_async_cmd_type_t;
76 
77 typedef struct {
78     struct mm_channel* ch_obj;
79     uint8_t num_streams;
80     uint32_t stream_ids[MM_CAMEAR_STRAEM_NUM_MAX];
81 } mm_camera_async_stop_cmd_t;
82 
83 typedef struct {
84     mm_camera_async_cmd_type_t cmd_type;
85     union {
86         mm_camera_async_stop_cmd_t stop_cmd;
87     } u;
88 } mm_camera_async_cmd_t;
89 
90 typedef enum
91 {
92     MM_CAMERA_CMD_TYPE_DATA_CB,    /* dataB CMD */
93     MM_CAMERA_CMD_TYPE_EVT_CB,     /* evtCB CMD */
94     MM_CAMERA_CMD_TYPE_ASYNC_CB,   /* asyncCB CMD */
95     MM_CAMERA_CMD_TYPE_EXIT,       /* EXIT */
96     MM_CAMERA_CMD_TYPE_REQ_DATA_CB,/* request data */
97     MM_CAMERA_CMD_TYPE_MAX
98 } mm_camera_cmdcb_type_t;
99 
100 typedef struct {
101     uint32_t stream_id;
102     uint32_t frame_idx;
103     uint8_t need_pp; /* flag if pp needed on this buf */
104     mm_camera_buf_def_t *buf; /* ref to buf */
105 } mm_camera_buf_info_t;
106 
107 typedef struct {
108     mm_camera_cmdcb_type_t cmd_type;
109     union {
110         mm_camera_buf_info_t buf;    /* frame buf if dataCB */
111         mm_camera_event_t evt;       /* evt if evtCB */
112         mm_camera_async_cmd_t async; /* async cmd */
113     } u;
114 } mm_camera_cmdcb_t;
115 
116 typedef void (*mm_camera_cmd_cb_t)(mm_camera_cmdcb_t * cmd_cb, void* user_data);
117 
118 typedef struct {
119     mm_camera_queue_t cmd_queue; /* cmd queue (queuing dataCB, asyncCB, or exitCMD) */
120     pthread_t cmd_pid;           /* cmd thread ID */
121     sem_t cmd_sem;               /* semaphore for cmd thread */
122     mm_camera_cmd_cb_t cb;       /* cb for cmd */
123     void* user_data;             /* user_data for cb */
124 } mm_camera_cmd_thread_t;
125 
126 typedef enum {
127     MM_CAMERA_POLL_TYPE_EVT,
128     MM_CAMERA_POLL_TYPE_CH,
129     MM_CAMERA_POLL_TYPE_MAX
130 } mm_camera_poll_thread_type_t;
131 
132 /* function ptr defined for poll notify CB,
133  * registered at poll thread with poll fd */
134 typedef void (*mm_camera_poll_notify_t)(void *user_data);
135 
136 typedef struct {
137     int32_t fd;
138     mm_camera_poll_notify_t notify_cb;
139     uint32_t handler;
140     void* user_data;
141 } mm_camera_poll_entry_t;
142 
143 typedef struct {
144     mm_camera_poll_thread_type_t poll_type;
145     /* array to store poll fd and cb info
146      * for MM_CAMERA_POLL_TYPE_EVT, only index 0 is valid;
147      * for MM_CAMERA_POLL_TYPE_CH, depends on valid stream fd */
148     mm_camera_poll_entry_t poll_entries[MM_CAMEAR_STRAEM_NUM_MAX];
149     int32_t pfds[2];
150     pthread_t pid;
151     int32_t state;
152     int timeoutms;
153     uint32_t cmd;
154     struct pollfd poll_fds[MM_CAMEAR_STRAEM_NUM_MAX+1];
155     uint8_t num_fds;
156     pthread_mutex_t mutex;
157     pthread_cond_t cond_v;
158     int32_t status;
159     //void *my_obj;
160 } mm_camera_poll_thread_t;
161 
162 /* mm_stream */
163 typedef enum {
164     MM_STREAM_STATE_NOTUSED = 0,      /* not used */
165     MM_STREAM_STATE_INITED,           /* inited  */
166     MM_STREAM_STATE_ACQUIRED,         /* acquired, fd opened  */
167     MM_STREAM_STATE_CFG,              /* fmt & dim configured */
168     MM_STREAM_STATE_BUFFED,           /* buf allocated */
169     MM_STREAM_STATE_REG,              /* buf regged, stream off */
170     MM_STREAM_STATE_ACTIVE_STREAM_ON, /* active with stream on */
171     MM_STREAM_STATE_ACTIVE_STREAM_OFF, /* active with stream off */
172     MM_STREAM_STATE_MAX
173 } mm_stream_state_type_t;
174 
175 typedef enum {
176     MM_STREAM_EVT_ACQUIRE,
177     MM_STREAM_EVT_RELEASE,
178     MM_STREAM_EVT_SET_FMT,
179     MM_STREAM_EVT_GET_BUF,
180     MM_STREAM_EVT_PUT_BUF,
181     MM_STREAM_EVT_REG_BUF,
182     MM_STREAM_EVT_UNREG_BUF,
183     MM_STREAM_EVT_START,
184     MM_STREAM_EVT_STOP,
185     MM_STREAM_EVT_QBUF,
186     MM_STREAM_EVT_SET_PARM,
187     MM_STREAM_EVT_GET_PARM,
188     MM_STREAM_EVT_MAX
189 } mm_stream_evt_type_t;
190 
191 typedef struct {
192     mm_camera_buf_notify_t cb;
193     void *user_data;
194     /* cb_count = -1: infinite
195      * cb_count > 0: register only for required times */
196     int8_t cb_count;
197 } mm_stream_data_cb_t;
198 
199 typedef struct {
200     /* buf reference count */
201     uint8_t buf_refcnt;
202 
203     /* This flag is to indicate if after allocation,
204      * the corresponding buf needs to qbuf into kernel
205      * (e.g. for preview usecase, display needs to hold two bufs,
206      * so no need to qbuf these two bufs initially) */
207     uint8_t initial_reg_flag;
208 
209     /* indicate if buf is in kernel(1) or client(0) */
210     uint8_t in_kernel;
211 } mm_stream_buf_status_t;
212 
213 typedef struct mm_stream {
214     uint32_t my_hdl;
215     uint32_t inst_hdl;
216     int32_t fd;
217     mm_stream_state_type_t state;
218 
219     /* ext_image_mode used as id for stream obj */
220     uint32_t ext_image_mode;
221 
222     /* sensor index used */
223     uint32_t sensor_idx;
224 
225     mm_camera_image_fmt_t fmt;
226 
227     mm_camera_cmd_thread_t cmd_thread;
228 
229     /* dataCB registered on this stream obj */
230     pthread_mutex_t cb_lock; /* cb lock to protect buf_cb */
231     mm_stream_data_cb_t buf_cb[MM_CAMERA_STREAM_BUF_CB_MAX];
232 
233     /* stream buffer management */
234     pthread_mutex_t buf_lock;
235     uint8_t buf_num; /* num of buffers allocated */
236     mm_camera_buf_def_t* buf; /* ptr to buf array */
237     mm_stream_buf_status_t* buf_status; /* ptr to buf status array */
238 
239     /* reference to parent channel_obj */
240     struct mm_channel* ch_obj;
241 
242     uint8_t is_bundled; /* flag if stream is bundled */
243     uint8_t is_pp_needed; /* flag if need to do post processing, set when streamon */
244     uint8_t is_local_buf; /* flag if buf is local copy, no need to qbuf to kernel */
245     uint8_t hal_requested_num_bufs;
246     uint8_t need_stream_on; /* flag if stream need streamon when start */
247 
248     mm_camera_frame_len_offset frame_offset; /*Stream buffer offset information*/
249 } mm_stream_t;
250 
251 /* mm_channel */
252 typedef enum {
253     MM_CHANNEL_STATE_NOTUSED = 0,   /* not used */
254     MM_CHANNEL_STATE_STOPPED,       /* stopped */
255     MM_CHANNEL_STATE_ACTIVE,        /* active, at least one stream active */
256     MM_CHANNEL_STATE_PAUSED,        /* paused */
257     MM_CHANNEL_STATE_MAX
258 } mm_channel_state_type_t;
259 
260 typedef enum {
261     MM_CHANNEL_EVT_ADD_STREAM,
262     MM_CHANNEL_EVT_DEL_STREAM,
263     MM_CHANNEL_EVT_START_STREAM,
264     MM_CHANNEL_EVT_STOP_STREAM,
265     MM_CHANNEL_EVT_TEARDOWN_STREAM,
266     MM_CHANNEL_EVT_CONFIG_STREAM,
267     MM_CHANNEL_EVT_PAUSE,
268     MM_CHANNEL_EVT_RESUME,
269     MM_CHANNEL_EVT_INIT_BUNDLE,
270     MM_CHANNEL_EVT_DESTROY_BUNDLE,
271     MM_CHANNEL_EVT_REQUEST_SUPER_BUF,
272     MM_CHANNEL_EVT_CANCEL_REQUEST_SUPER_BUF,
273     MM_CHANNEL_EVT_START_FOCUS,
274     MM_CHANNEL_EVT_ABORT_FOCUS,
275     MM_CHANNEL_EVT_PREPARE_SNAPSHOT,
276     MM_CHANNEL_EVT_SET_STREAM_PARM,
277     MM_CHANNEL_EVT_GET_STREAM_PARM,
278     MM_CHANNEL_EVT_DELETE,
279     MM_CHANNEL_EVT_MAX
280 } mm_channel_evt_type_t;
281 
282 typedef struct {
283     mm_camera_buf_notify_t buf_cb;
284     void *user_data;
285     uint32_t ext_image_mode;
286     uint32_t sensor_idx;
287 } mm_evt_paylod_add_stream_t;
288 
289 typedef struct {
290     uint32_t stream_id;
291     mm_camera_stream_config_t *config;
292 } mm_evt_paylod_config_stream_t;
293 
294 typedef struct {
295     mm_camera_stream_parm_t parm_type;
296     void *value;
297 } mm_evt_paylod_stream_parm_t;
298 
299 typedef struct {
300     mm_camera_buf_notify_t super_frame_notify_cb;
301     void *user_data;
302     mm_camera_bundle_attr_t *attr;
303     uint8_t num_streams;
304     uint32_t *stream_ids;
305 } mm_evt_payload_bundle_stream_t;
306 
307 typedef struct {
308     uint8_t num_streams;
309     uint32_t *stream_ids;
310 } mm_evt_payload_start_stream_t;
311 
312 typedef struct {
313     uint8_t num_streams;
314     uint32_t *stream_ids;
315 } mm_evt_payload_stop_stream_t;
316 
317 typedef struct {
318     uint32_t sensor_idx;
319     uint32_t focus_mode;
320 } mm_evt_payload_start_focus_t;
321 
322 typedef struct {
323     uint8_t num_of_bufs;
324     mm_camera_buf_info_t super_buf[MM_CAMEAR_MAX_STRAEM_BUNDLE];
325     uint8_t matched;
326 } mm_channel_queue_node_t;
327 
328 typedef struct {
329     mm_camera_queue_t que;
330     uint8_t num_streams;
331     /* container for bundled stream handlers */
332     uint32_t bundled_streams[MM_CAMEAR_MAX_STRAEM_BUNDLE];
333     mm_camera_bundle_attr_t attr;
334     uint32_t expected_frame_id;
335     uint32_t match_cnt;
336 } mm_channel_queue_t;
337 
338 typedef struct {
339     /* queue to store bundled super buffers */
340     mm_channel_queue_t superbuf_queue;
341     mm_camera_buf_notify_t super_buf_notify_cb;
342     void *user_data;
343 } mm_channel_bundle_t;
344 
345 typedef struct mm_channel {
346     uint32_t my_hdl;
347     mm_channel_state_type_t state;
348     pthread_mutex_t ch_lock; /* channel lock */
349 
350     /* stream bundle info in the channel */
351     mm_channel_bundle_t bundle;
352 
353     /* num of pending suferbuffers */
354     uint32_t pending_cnt;
355     uint32_t pending_pp_cnt; /*pending cnt for post processing frames */
356 
357     /* cmd thread for superbuffer dataCB and async stop*/
358     mm_camera_cmd_thread_t cmd_thread;
359 
360     /* data poll thread
361     * currently one data poll thread per channel
362     * could extended to support one data poll thread per stream in the channel */
363     mm_camera_poll_thread_t poll_thread[MM_CAMERA_CHANNEL_POLL_THREAD_MAX];
364 
365     /* container for all streams in channel
366     * stream is indexed by ext_image_mode */
367     mm_stream_t streams[MM_CAMEAR_STRAEM_NUM_MAX];
368 
369     /* reference to parent cam_obj */
370     struct mm_camera_obj* cam_obj;
371 } mm_channel_t;
372 
373 /* struct to store information about pp cookie*/
374 typedef struct {
375     uint32_t cam_hdl;
376     uint32_t ch_hdl;
377     uint32_t stream_hdl;
378     mm_channel_queue_node_t* super_buf;
379 } mm_channel_pp_info_t;
380 
381 /* mm_camera */
382 typedef struct {
383     mm_camera_event_notify_t evt_cb;
384     void *user_data;
385 } mm_camera_evt_entry_t;
386 
387 typedef struct {
388     mm_camera_evt_entry_t evt[MM_CAMERA_EVT_ENTRY_MAX];
389     /* reg_count <=0: infinite
390      * reg_count > 0: register only for required times */
391     int reg_count;
392 } mm_camera_evt_obj_t;
393 
394 typedef struct mm_camera_obj {
395     uint32_t my_hdl;
396     int ref_count;
397     int32_t ctrl_fd;
398     int32_t ds_fd; /* domain socket fd */
399     cam_prop_t properties;
400     mm_camera_2nd_sensor_t second_sensor; /*second sensor info */
401     pthread_mutex_t cam_lock;
402     pthread_mutex_t cb_lock; /* lock for evt cb */
403     mm_channel_t ch[MM_CAMERA_CHANNEL_MAX];
404     mm_camera_evt_obj_t evt[MM_CAMERA_EVT_TYPE_MAX];
405     uint32_t evt_type_mask;
406     mm_camear_mem_vtbl_t *mem_vtbl; /* vtable for memory management */
407     mm_camera_poll_thread_t evt_poll_thread; /* evt poll thread */
408     mm_camera_cmd_thread_t evt_thread;       /* thread for evt CB */
409     mm_camera_cmd_thread_t async_cmd_thread; /* thread for async cmd */
410     mm_camera_vtbl_t vtbl;
411 
412     /* some local variables */
413     uint32_t snap_burst_num_by_user;
414     camera_mode_t current_mode;
415     uint8_t need_pp;
416     uint32_t op_mode;
417     cam_ctrl_dimension_t dim;
418 } mm_camera_obj_t;
419 
420 typedef struct {
421     mm_camera_info_t camera[MSM_MAX_CAMERA_SENSORS];
422     int8_t num_cam;
423     char video_dev_name[MSM_MAX_CAMERA_SENSORS][MM_CAMERA_DEV_NAME_LEN];
424     mm_camera_obj_t *cam_obj[MSM_MAX_CAMERA_SENSORS];
425 } mm_camera_ctrl_t;
426 
427 /**********************************************************************************
428 * external function declare
429 ***********************************************************************************/
430 /* utility functions */
431 /* set int32_t value */
432 extern int32_t mm_camera_util_s_ctrl(int32_t fd,
433                                      uint32_t id,
434                                      int32_t value);
435 
436 extern int32_t mm_camera_util_private_s_ctrl( int32_t fd,
437                                               uint32_t id, void* value);
438 
439 /* get int32_t value */
440 extern int32_t mm_camera_util_g_ctrl(int32_t fd,
441                                      uint32_t id,int32_t *value);
442 
443 /* send msg throught domain socket for fd mapping */
444 extern int32_t mm_camera_util_sendmsg(mm_camera_obj_t *my_obj,
445                                       void *msg,
446                                       uint32_t buf_size,
447                                       int sendfd);
448 
449 /* mm-camera */
450 extern int32_t mm_camera_open(mm_camera_obj_t *my_obj);
451 extern int32_t mm_camera_close(mm_camera_obj_t *my_obj);
452 extern uint8_t mm_camera_is_event_supported(mm_camera_obj_t *my_obj,
453                                             mm_camera_event_type_t evt_type);
454 extern int32_t mm_camera_register_event_notify(mm_camera_obj_t *my_obj,
455                                                mm_camera_event_notify_t evt_cb,
456                                                void * user_data,
457                                                mm_camera_event_type_t evt_type);
458 extern int32_t mm_camera_qbuf(mm_camera_obj_t *my_obj,
459                               uint32_t ch_id,
460                               mm_camera_buf_def_t *buf);
461 extern mm_camera_2nd_sensor_t * mm_camera_query_2nd_sensor_info(mm_camera_obj_t *my_obj);
462 extern int32_t mm_camera_sync(mm_camera_obj_t *my_obj);
463 extern int32_t mm_camera_is_parm_supported(mm_camera_obj_t *my_obj,
464                                            mm_camera_parm_type_t parm_type,
465                                            uint8_t *support_set_parm,
466                                            uint8_t *support_get_parm);
467 extern int32_t mm_camera_set_parm(mm_camera_obj_t *my_obj,
468                                   mm_camera_parm_type_t parm_type,
469                                   void* p_value);
470 extern int32_t mm_camera_get_parm(mm_camera_obj_t *my_obj,
471                                   mm_camera_parm_type_t parm_type,
472                                   void* p_value);
473 extern uint32_t mm_camera_add_channel(mm_camera_obj_t *my_obj);
474 extern void mm_camera_del_channel(mm_camera_obj_t *my_obj,
475                                   uint32_t ch_id);
476 extern uint32_t mm_camera_add_stream(mm_camera_obj_t *my_obj,
477                                      uint32_t ch_id,
478                                      mm_camera_buf_notify_t buf_cb, void *user_data,
479                                      uint32_t ext_image_mode, uint32_t sensor_idx);
480 extern int32_t mm_camera_del_stream(mm_camera_obj_t *my_obj,
481                                     uint32_t ch_id,
482                                     uint32_t stream_id);
483 extern int32_t mm_camera_config_stream(mm_camera_obj_t *my_obj,
484                                        uint32_t ch_id,
485                                        uint32_t stream_id,
486                                        mm_camera_stream_config_t *config);
487 extern int32_t mm_camera_bundle_streams(mm_camera_obj_t *my_obj,
488                                         uint32_t ch_id,
489                                         mm_camera_buf_notify_t super_frame_notify_cb,
490                                         void *user_data,
491                                         mm_camera_bundle_attr_t *attr,
492                                         uint8_t num_streams,
493                                         uint32_t *stream_ids);
494 extern int32_t mm_camera_destroy_bundle(mm_camera_obj_t *my_obj,
495                                         uint32_t ch_id);
496 extern int32_t mm_camera_start_streams(mm_camera_obj_t *my_obj,
497                                        uint32_t ch_id,
498                                        uint8_t num_streams,
499                                        uint32_t *stream_ids);
500 extern int32_t mm_camera_stop_streams(mm_camera_obj_t *my_obj,
501                                       uint32_t ch_id,
502                                       uint8_t num_streams,
503                                       uint32_t *stream_ids);
504 extern int32_t mm_camera_async_teardown_streams(mm_camera_obj_t *my_obj,
505                                                 uint32_t ch_id,
506                                                 uint8_t num_streams,
507                                                 uint32_t *stream_ids);
508 extern int32_t mm_camera_request_super_buf(mm_camera_obj_t *my_obj,
509                                            uint32_t ch_id);
510 extern int32_t mm_camera_cancel_super_buf_request(mm_camera_obj_t *my_obj,
511                                                   uint32_t ch_id);
512 extern int32_t mm_camera_start_focus(mm_camera_obj_t *my_obj,
513                                      uint32_t ch_id,
514                                      uint32_t sensor_idx,
515                                      uint32_t focus_mode);
516 extern int32_t mm_camera_abort_focus(mm_camera_obj_t *my_obj,
517                                      uint32_t ch_id,
518                                      uint32_t sensor_idx);
519 extern int32_t mm_camera_prepare_snapshot(mm_camera_obj_t *my_obj,
520                                           uint32_t ch_id,
521                                           uint32_t sensor_idx);
522 extern int32_t mm_camera_set_stream_parm(mm_camera_obj_t *my_obj,
523                                   uint32_t ch_id,
524                                   uint32_t s_id,
525                                   mm_camera_stream_parm_t parm_type,
526                                   void* p_value);
527 
528 extern int32_t mm_camera_get_stream_parm(mm_camera_obj_t *my_obj,
529                                   uint32_t ch_id,
530                                   uint32_t s_id,
531                                   mm_camera_stream_parm_t parm_type,
532                                   void* p_value);
533 
534 extern int32_t mm_camera_register_event_notify_internal(
535                                    mm_camera_obj_t *my_obj,
536                                    mm_camera_event_notify_t evt_cb,
537                                    void * user_data,
538                                    mm_camera_event_type_t evt_type);
539 extern int32_t mm_camera_map_buf(mm_camera_obj_t *my_obj,
540                                  int ext_mode,
541                                  int idx,
542                                  int fd,
543                                  uint32_t size);
544 extern int32_t mm_camera_unmap_buf(mm_camera_obj_t *my_obj,
545                                    int ext_mode,
546                                    int idx);
547 extern int32_t mm_camera_send_ch_event(mm_camera_obj_t *my_obj,
548                                        uint32_t ch_id,
549                                        uint32_t stream_id,
550                                        mm_camera_ch_event_type_t evt);
551 
552 
553 /* mm_channel */
554 extern int32_t mm_channel_fsm_fn(mm_channel_t *my_obj,
555                                  mm_channel_evt_type_t evt,
556                                  void * in_val,
557                                  void * out_val);
558 
559 /* qbuf is a special case that not going through state machine.
560  * This is to avoid deadlock when trying to aquire ch_lock,
561  * from the context of dataCB, but async stop is holding ch_lock */
562 extern int32_t mm_channel_qbuf(mm_channel_t *my_obj,
563                                mm_camera_buf_def_t *buf);
564 
565 /* Allow other stream to register dataCB at certain stream.
566  * This is for use case of video sized live snapshot,
567  * because snapshot stream need register one time CB at video stream.
568  * ext_image_mode and sensor_idx are used to identify the destinate stream
569  * to be register with dataCB. */
570 extern int32_t mm_channel_reg_stream_cb(mm_channel_t *my_obj,
571                                         mm_stream_data_cb_t *cb,
572                                         uint32_t ext_image_mode,
573                                         uint32_t sensor_idx);
574 
575 /* mm_stream */
576 extern int32_t mm_stream_fsm_fn(mm_stream_t *my_obj,
577                                 mm_stream_evt_type_t evt,
578                                 void * in_val,
579                                 void * out_val);
580 /* Allow other stream to register dataCB at certain stream.
581  * This is for use case of video sized live snapshot,
582  * because snapshot stream need register one time CB at video stream.
583  * ext_image_mode and sensor_idx are used to identify the destinate stream
584  * to be register with dataCB. */
585 extern int32_t mm_stream_reg_buf_cb(mm_stream_t *my_obj,
586                                     mm_stream_data_cb_t *val);
587 
588 /* utiltity fucntion declared in mm-camera-inteface2.c
589  * and need be used by mm-camera and below*/
590 uint32_t mm_camera_util_generate_handler(uint8_t index);
591 const char * mm_camera_util_get_dev_name(uint32_t cam_handler);
592 uint8_t mm_camera_util_get_index_by_handler(uint32_t handler);
593 
594 /* queue functions */
595 extern int32_t mm_camera_queue_init(mm_camera_queue_t* queue);
596 extern int32_t mm_camera_queue_enq(mm_camera_queue_t* queue, void* node);
597 extern void* mm_camera_queue_deq(mm_camera_queue_t* queue);
598 extern int32_t mm_camera_queue_deinit(mm_camera_queue_t* queue);
599 extern int32_t mm_camera_queue_flush(mm_camera_queue_t* queue);
600 
601 /* poll/cmd thread functions */
602 extern int32_t mm_camera_poll_thread_launch(
603                                 mm_camera_poll_thread_t * poll_cb,
604                                 mm_camera_poll_thread_type_t poll_type);
605 extern int32_t mm_camera_poll_thread_release(mm_camera_poll_thread_t *poll_cb);
606 extern int32_t mm_camera_poll_thread_add_poll_fd(
607                                 mm_camera_poll_thread_t * poll_cb,
608                                 uint32_t handler,
609                                 int32_t fd,
610                                 mm_camera_poll_notify_t nofity_cb,
611                                 void *userdata);
612 extern int32_t mm_camera_poll_thread_del_poll_fd(
613                                 mm_camera_poll_thread_t * poll_cb,
614                                 uint32_t handler);
615 extern int32_t mm_camera_cmd_thread_launch(
616                                 mm_camera_cmd_thread_t * cmd_thread,
617                                 mm_camera_cmd_cb_t cb,
618                                 void* user_data);
619 extern int32_t mm_camera_cmd_thread_release(mm_camera_cmd_thread_t * cmd_thread);
620 
621 #endif /* __MM_CAMERA_H__ */
622