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