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 #define TRUE 1 34 #define FALSE 0 35 36 typedef enum { 37 MM_CAMERA_STREAM_STATE_NOTUSED, /* not used */ 38 MM_CAMERA_STREAM_STATE_ACQUIRED, /* acquired, fd opened */ 39 MM_CAMERA_STREAM_STATE_CFG, /* fmt & dim configured */ 40 MM_CAMERA_STREAM_STATE_REG, /* buf regged, stream off */ 41 MM_CAMERA_STREAM_STATE_ACTIVE, /* stream on */ 42 MM_CAMERA_STREAM_STATE_MAX 43 } mm_camera_stream_state_type_t; 44 45 typedef enum { 46 MM_CAMERA_STATE_EVT_NOTUSED, 47 MM_CAMERA_STATE_EVT_ACQUIRE, 48 MM_CAMERA_STATE_EVT_ATTR, 49 MM_CAMERA_STATE_EVT_RELEASE, 50 MM_CAMERA_STATE_EVT_REG_BUF_CB, 51 MM_CAMERA_STATE_EVT_SET_FMT, 52 MM_CAMERA_STATE_EVT_SET_DIM, 53 MM_CAMERA_STATE_EVT_REG_BUF, // request amount of buffers and enqueue all buffers to kernel 54 MM_CAMERA_STATE_EVT_UNREG_BUF, 55 MM_CAMERA_STATE_EVT_STREAM_ON, 56 MM_CAMERA_STATE_EVT_STREAM_OFF, 57 MM_CAMERA_STATE_EVT_QBUF, 58 MM_CAMERA_STATE_EVT_GET_CROP, 59 MM_CAMERA_STATE_EVT_DISPATCH_BUFFERED_FRAME, 60 MM_CAMERA_STATE_EVT_REQUEST_BUF, // request amount of buffers to kernel only 61 MM_CAMERA_STATE_EVT_ENQUEUE_BUF, // enqueue some of buffers to kernel only 62 MM_CAMERA_STATE_EVT_MAX 63 } mm_camera_state_evt_type_t; 64 65 typedef struct { 66 mm_camera_event_notify_t evt_cb; 67 void * user_data; 68 } mm_camera_notify_cb_t; 69 70 typedef enum { 71 MM_CAMERA_BUF_CB_ONCE, 72 MM_CAMERA_BUF_CB_COUNT, 73 MM_CAMERA_BUF_CB_INFINITE 74 } mm_camera_buf_cb_type_t; 75 76 typedef struct { 77 mm_camera_buf_notify_t cb; 78 mm_camera_buf_cb_type_t cb_type; 79 uint32_t cb_count; 80 void *user_data; 81 } mm_camera_buf_cb_t; 82 83 typedef enum { 84 MM_CAMERA_STREAM_PIPE, 85 MM_CAMERA_STREAM_PREVIEW, 86 MM_CAMERA_STREAM_VIDEO, 87 MM_CAMERA_STREAM_SNAPSHOT, 88 MM_CAMERA_STREAM_THUMBNAIL, 89 MM_CAMERA_STREAM_RAW, 90 MM_CAMERA_STREAM_VIDEO_MAIN, 91 MM_CAMERA_STREAM_MAX 92 } mm_camera_stream_type_t; 93 94 typedef struct mm_camera_frame_t mm_camera_frame_t; 95 struct mm_camera_frame_t{ 96 struct msm_frame frame; 97 struct v4l2_plane planes[VIDEO_MAX_PLANES]; 98 uint8_t num_planes; 99 int idx; 100 int match; 101 int valid_entry; 102 mm_camera_frame_t *next; 103 }; 104 105 typedef struct { 106 pthread_mutex_t mutex; 107 int cnt; 108 int match_cnt; 109 mm_camera_frame_t *head; 110 mm_camera_frame_t *tail; 111 } mm_camera_frame_queue_t; 112 113 typedef struct { 114 mm_camera_frame_queue_t readyq; 115 int32_t num_frame; 116 uint32_t frame_len; 117 int8_t reg_flag; 118 uint32_t frame_offset[MM_CAMERA_MAX_NUM_FRAMES]; 119 mm_camera_frame_t frame[MM_CAMERA_MAX_NUM_FRAMES]; 120 int8_t ref_count[MM_CAMERA_MAX_NUM_FRAMES]; 121 int32_t use_multi_fd; 122 int qbuf; 123 pthread_mutex_t mutex; 124 } mm_camera_stream_frame_t; 125 126 typedef struct { 127 int32_t fd; 128 mm_camera_stream_state_type_t state; 129 mm_camera_stream_type_t stream_type; 130 struct v4l2_format fmt; 131 cam_format_t cam_fmt; 132 mm_camera_stream_frame_t frame; 133 } mm_camera_stream_t; 134 135 typedef struct { 136 mm_camera_stream_t stream; 137 mm_camera_raw_streaming_type_t mode; 138 } mm_camera_ch_raw_t; 139 140 typedef struct { 141 mm_camera_stream_t stream; 142 } mm_camera_ch_preview_t; 143 144 typedef struct { 145 mm_camera_stream_t thumbnail; 146 mm_camera_stream_t main; 147 int delivered_cnt; 148 int8_t pending_cnt; 149 uint32_t expected_matching_id; 150 } mm_camera_ch_snapshot_t; 151 152 typedef struct { 153 int8_t fifo[MM_CAMERA_MAX_FRAME_NUM]; 154 int8_t low; 155 int8_t high; 156 int8_t len; 157 int8_t water_mark; 158 } mm_camera_circule_fifo_t; 159 160 typedef struct { 161 mm_camera_stream_t video; 162 mm_camera_stream_t main; 163 uint8_t has_main; 164 } mm_camera_ch_video_t; 165 166 #define MM_CAMERA_BUF_CB_MAX 4 167 typedef struct { 168 mm_camera_channel_type_t type; 169 pthread_mutex_t mutex; 170 uint8_t acquired; 171 mm_camera_buf_cb_t buf_cb[MM_CAMERA_BUF_CB_MAX]; 172 mm_camera_channel_attr_buffering_frame_t buffering_frame; 173 union { 174 mm_camera_ch_raw_t raw; 175 mm_camera_ch_preview_t preview; 176 mm_camera_ch_snapshot_t snapshot; 177 mm_camera_ch_video_t video; 178 }; 179 } mm_camera_ch_t; 180 181 #define MM_CAMERA_EVT_ENTRY_MAX 4 182 typedef struct { 183 mm_camera_event_notify_t evt_cb; 184 void *user_data; 185 } mm_camera_evt_entry_t; 186 187 typedef struct { 188 mm_camera_evt_entry_t evt[MM_CAMERA_EVT_ENTRY_MAX]; 189 int reg_count; 190 } mm_camera_evt_obj_t; 191 192 #define MM_CAMERA_CH_STREAM_MAX 2 193 typedef enum { 194 MM_CAMERA_POLL_TYPE_EVT, 195 MM_CAMERA_POLL_TYPE_CH, 196 MM_CAMERA_POLL_TYPE_MAX 197 } mm_camera_poll_thread_type_t; 198 199 typedef struct { 200 mm_camera_poll_thread_type_t poll_type; 201 int32_t pfds[2]; 202 int poll_fd[MM_CAMERA_CH_STREAM_MAX+1]; 203 int num_fds; 204 int used; 205 pthread_t pid; 206 int32_t state; 207 int timeoutms; 208 void *my_obj; 209 mm_camera_channel_type_t ch_type; 210 mm_camera_stream_t *poll_streams[MM_CAMERA_CH_STREAM_MAX]; 211 uint32_t cmd; 212 } mm_camera_poll_thread_data_t; 213 214 typedef struct { 215 pthread_mutex_t mutex; 216 pthread_cond_t cond_v; 217 int32_t status; 218 mm_camera_poll_thread_data_t data; 219 } mm_camera_poll_thread_t; 220 221 typedef struct { 222 int stream_on_count_cfg; 223 int stream_off_count_cfg; 224 int stream_on_count; 225 int stream_off_count; 226 } mm_camera_ch_stream_count_t; 227 #define MM_CAMERA_POLL_THRAED_MAX (MM_CAMERA_CH_MAX+1) 228 229 typedef struct { 230 struct msm_mem_map_info cookie; 231 uint32_t vaddr; 232 } mm_camera_mem_map_entry_t; 233 234 #define MM_CAMERA_MEM_MAP_MAX 8 235 typedef struct { 236 int num; 237 mm_camera_mem_map_entry_t entry[MM_CAMERA_MEM_MAP_MAX]; 238 } mm_camera_mem_map_t; 239 240 typedef struct { 241 int8_t my_id; 242 camera_mode_t current_mode; 243 mm_camera_op_mode_type_t op_mode; 244 mm_camera_notify_cb_t *notify; 245 mm_camera_ch_t ch[MM_CAMERA_CH_MAX]; 246 int ref_count; 247 uint32_t ch_streaming_mask; 248 int32_t ctrl_fd; 249 int32_t ds_fd; // domain socket fd 250 cam_ctrl_dimension_t dim; 251 cam_prop_t properties; 252 pthread_mutex_t mutex; 253 mm_camera_evt_obj_t evt[MM_CAMERA_EVT_TYPE_MAX]; 254 mm_camera_ch_stream_count_t ch_stream_count[MM_CAMERA_CH_MAX]; 255 uint32_t evt_type_mask; 256 mm_camera_poll_thread_t poll_threads[MM_CAMERA_POLL_THRAED_MAX]; 257 mm_camera_mem_map_t hist_mem_map; 258 int full_liveshot; 259 int snap_burst_num_by_user; 260 } mm_camera_obj_t; 261 262 #define MM_CAMERA_DEV_NAME_LEN 32 263 #define MM_CAMERA_DEV_OPEN_TRIES 2 264 #define MM_CAMERA_DEV_OPEN_RETRY_SLEEP 20 265 266 typedef struct { 267 mm_camera_t camera[MSM_MAX_CAMERA_SENSORS]; 268 int8_t num_cam; 269 char video_dev_name[MSM_MAX_CAMERA_SENSORS][MM_CAMERA_DEV_NAME_LEN]; 270 mm_camera_obj_t *cam_obj[MSM_MAX_CAMERA_SENSORS]; 271 } mm_camera_ctrl_t; 272 273 typedef struct { 274 mm_camera_parm_type_t parm_type; 275 void *p_value; 276 } mm_camera_parm_t; 277 278 extern int32_t mm_camera_stream_fsm_fn_vtbl (mm_camera_obj_t * my_obj, 279 mm_camera_stream_t *stream, 280 mm_camera_state_evt_type_t evt, void *val); 281 extern const char *mm_camera_util_get_dev_name(mm_camera_obj_t * my_obj); 282 extern int32_t mm_camera_util_s_ctrl( int32_t fd, 283 uint32_t id, int32_t value); 284 extern int32_t mm_camera_util_private_s_ctrl( int32_t fd, 285 uint32_t id, int32_t value); 286 extern int32_t mm_camera_util_g_ctrl( int32_t fd, 287 uint32_t id, int32_t *value); 288 extern int32_t mm_camera_ch_fn(mm_camera_obj_t * my_obj, 289 mm_camera_channel_type_t ch_type, 290 mm_camera_state_evt_type_t evt, void *val); 291 extern int32_t mm_camera_action(mm_camera_obj_t *my_obj, uint8_t start, 292 mm_camera_ops_type_t opcode, void *parm); 293 extern int32_t mm_camera_open(mm_camera_obj_t *my_obj, 294 mm_camera_op_mode_type_t op_mode); 295 extern int32_t mm_camera_close(mm_camera_obj_t *my_obj); 296 extern int32_t mm_camera_start(mm_camera_obj_t *my_obj, 297 mm_camera_ops_type_t opcode, void *parm); 298 extern int32_t mm_camera_stop(mm_camera_obj_t *my_obj, 299 mm_camera_ops_type_t opcode, void *parm); 300 extern int32_t mm_camera_get_parm(mm_camera_obj_t * my_obj, 301 mm_camera_parm_t *parm); 302 extern int32_t mm_camera_set_parm(mm_camera_obj_t * my_obj, 303 mm_camera_parm_t *parm); 304 extern int32_t mm_camera_request_buf(mm_camera_obj_t * my_obj, mm_camera_reg_buf_t *buf); 305 extern int32_t mm_camera_enqueue_buf(mm_camera_obj_t * my_obj, mm_camera_reg_buf_t *buf); 306 extern int32_t mm_camera_prepare_buf(mm_camera_obj_t * my_obj, mm_camera_reg_buf_t *buf); 307 extern int32_t mm_camera_unprepare_buf(mm_camera_obj_t * my_obj, mm_camera_channel_type_t ch_type); 308 extern int mm_camera_poll_thread_launch(mm_camera_obj_t * my_obj, int ch_type); 309 310 int mm_camera_poll_thread_del_ch(mm_camera_obj_t * my_obj, int ch_type); 311 int mm_camera_poll_thread_add_ch(mm_camera_obj_t * my_obj, int ch_type); 312 extern int32_t mm_camera_poll_dispatch_buffered_frames(mm_camera_obj_t * my_obj, int ch_type); 313 extern int mm_camera_poll_thread_release(mm_camera_obj_t * my_obj, int ch_type); 314 extern void mm_camera_poll_threads_init(mm_camera_obj_t * my_obj); 315 extern void mm_camera_poll_threads_deinit(mm_camera_obj_t * my_obj); 316 extern int mm_camera_poll_busy(mm_camera_obj_t * my_obj); 317 extern void mm_camera_msm_data_notify(mm_camera_obj_t * my_obj, int fd, 318 mm_camera_stream_type_t stream_type); 319 extern void mm_camera_msm_evt_notify(mm_camera_obj_t * my_obj, int fd); 320 extern int mm_camera_read_msm_frame(mm_camera_obj_t * my_obj, 321 mm_camera_stream_t *stream); 322 extern int32_t mm_camera_ch_acquire(mm_camera_obj_t *my_obj, mm_camera_channel_type_t ch_type); 323 extern void mm_camera_ch_release(mm_camera_obj_t *my_obj, mm_camera_channel_type_t ch_type); 324 extern int mm_camera_ch_is_active(mm_camera_obj_t * my_obj, mm_camera_channel_type_t ch_type); 325 extern void mm_camera_ch_util_get_stream_objs(mm_camera_obj_t * my_obj, 326 mm_camera_channel_type_t ch_type, 327 mm_camera_stream_t **stream1, 328 mm_camera_stream_t **stream2); 329 extern int mm_camera_stream_qbuf(mm_camera_obj_t * my_obj, 330 mm_camera_stream_t *stream, 331 int idx); 332 extern int mm_camera_stream_frame_get_q_cnt(mm_camera_frame_queue_t *q); 333 extern mm_camera_frame_t *mm_camera_stream_frame_deq(mm_camera_frame_queue_t *q); 334 extern mm_camera_frame_t *mm_camera_stream_frame_deq_no_lock(mm_camera_frame_queue_t *q); 335 extern void mm_camera_stream_frame_enq(mm_camera_frame_queue_t *q, mm_camera_frame_t *node); 336 extern void mm_camera_stream_frame_enq_no_lock(mm_camera_frame_queue_t *q, mm_camera_frame_t *node); 337 extern void mm_camera_stream_frame_refill_q(mm_camera_frame_queue_t *q, mm_camera_frame_t *node, int num); 338 extern int mm_camera_stream_is_active(mm_camera_stream_t *stream); 339 extern int32_t mm_camera_stream_util_buf_done(mm_camera_obj_t * my_obj, 340 mm_camera_stream_t *stream, 341 mm_camera_notify_frame_t *frame); 342 //extern int mm_camera_poll_add_stream(mm_camera_obj_t * my_obj, mm_camera_stream_t *stream); 343 //extern int mm_camera_poll_del_stream(mm_camera_obj_t * my_obj, mm_camera_stream_t *stream); 344 extern int mm_camera_dev_open(int *fd, char *dev_name); 345 extern int mm_camera_reg_event(mm_camera_obj_t * my_obj, mm_camera_event_notify_t evt_cb, 346 void *user_data, uint32_t evt_type); 347 extern int mm_camera_poll_send_ch_event(mm_camera_obj_t * my_obj, mm_camera_event_t *event); 348 extern void mm_camera_msm_proc_ch_event(mm_camera_obj_t *my_obj, mm_camera_event_t *event); 349 extern void mm_camera_dispatch_app_event(mm_camera_obj_t *my_obj, mm_camera_event_t *event); 350 extern void mm_camera_dispatch_buffered_frames(mm_camera_obj_t *my_obj, mm_camera_channel_type_t ch_type); 351 extern void mm_camera_check_pending_zsl_frames(mm_camera_obj_t *my_obj, 352 mm_camera_channel_type_t ch_type); 353 extern int mm_camera_ch_util_get_num_stream(mm_camera_obj_t * my_obj,mm_camera_channel_type_t ch_type); 354 extern int32_t mm_camera_sendmsg(mm_camera_obj_t *my_obj, void *msg, uint32_t buf_size, int sendfd); 355 #endif /* __MM_CAMERA_H__ */ 356