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 */
79struct 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**/
87typedef 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**/
98typedef 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**/
124typedef 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**/
153typedef 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**/
165typedef 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**/
178typedef 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/** mm_camera_event_t: structure for event
186*    @server_event_type : event type from serer
187*    @status : status of an event, value could be
188*              CAM_STATUS_SUCCESS
189*              CAM_STATUS_FAILED
190**/
191typedef struct {
192    cam_event_type_t server_event_type;
193    uint32_t status;
194} mm_camera_event_t;
195
196/** mm_camera_event_notify_t: function definition for event
197*   notify handling
198*    @camera_handle : camera handler
199*    @evt : pointer to an event struct
200*    @user_data: user data pointer
201**/
202typedef void (*mm_camera_event_notify_t)(uint32_t camera_handle,
203                                         mm_camera_event_t *evt,
204                                         void *user_data);
205
206/** mm_camera_buf_notify_t: function definition for frame notify
207*   handling
208*    @mm_camera_super_buf_t : received frame buffers
209*    @user_data: user data pointer
210**/
211typedef void (*mm_camera_buf_notify_t) (mm_camera_super_buf_t *bufs,
212                                        void *user_data);
213
214/** map_stream_buf_op_t: function definition for operation of
215*   mapping stream buffers via domain socket
216*    @frame_idx : buffer index within stream buffers
217*    @plane_idx    : plane index. If all planes share the same
218*                   fd, plane_idx = -1; otherwise, plean_idx is
219*                   the index to plane (0..num_of_planes)
220*    @fd : file descriptor of the stream buffer
221*    @size: size of the stream buffer
222*    @userdata : user data pointer
223**/
224typedef int32_t (*map_stream_buf_op_t) (uint32_t frame_idx,
225                                        int32_t plane_idx,
226                                        int fd,
227                                        size_t size,
228                                        cam_mapping_buf_type type,
229                                        void *userdata);
230
231typedef int32_t (*map_stream_bufs_op_t) (const cam_buf_map_type_list *buf_map_list,
232                                         void *userdata);
233
234/** unmap_stream_buf_op_t: function definition for operation of
235*                          unmapping stream buffers via domain
236*                          socket
237*    @frame_idx : buffer index within stream buffers
238*    @plane_idx : plane index. If all planes share the same
239*                 fd, plane_idx = -1; otherwise, plean_idx is
240*                 the index to plane (0..num_of_planes)
241*    @userdata : user data pointer
242**/
243typedef int32_t (*unmap_stream_buf_op_t) (uint32_t frame_idx,
244                                          int32_t plane_idx,
245                                          cam_mapping_buf_type type,
246                                          void *userdata);
247
248/** mm_camera_map_unmap_ops_tbl_t: virtual table
249*                      for mapping/unmapping stream buffers via
250*                      domain socket
251*    @map_ops : operation for mapping
252*    @unmap_ops : operation for unmapping
253*    @userdata: user data pointer
254**/
255typedef struct {
256    map_stream_buf_op_t map_ops;
257    map_stream_bufs_op_t bundled_map_ops;
258    unmap_stream_buf_op_t unmap_ops;
259    void *userdata;
260} mm_camera_map_unmap_ops_tbl_t;
261
262/** mm_camera_stream_mem_vtbl_t: virtual table for stream
263*                      memory allocation and deallocation
264*    @get_bufs : function definition for allocating
265*                stream buffers
266*    @put_bufs : function definition for deallocating
267*                stream buffers
268*    @user_data: user data pointer
269**/
270typedef struct {
271  void *user_data;
272  int32_t (*set_config_ops) (mm_camera_map_unmap_ops_tbl_t *ops_tbl,
273          void *user_data);
274  int32_t (*get_bufs) (cam_frame_len_offset_t *offset,
275                       uint8_t *num_bufs,
276                       uint8_t **initial_reg_flag,
277                       mm_camera_buf_def_t **bufs,
278                       mm_camera_map_unmap_ops_tbl_t *ops_tbl,
279                       void *user_data);
280  int32_t (*put_bufs) (mm_camera_map_unmap_ops_tbl_t *ops_tbl,
281                       void *user_data);
282  int32_t (*invalidate_buf)(uint32_t index, void *user_data);
283  int32_t (*clean_invalidate_buf)(uint32_t index, void *user_data);
284} mm_camera_stream_mem_vtbl_t;
285
286/** mm_camera_stream_config_t: structure for stream
287*                              configuration
288*    @stream_info : pointer to a stream info structure
289*    @padding_info: padding info obtained from querycapability
290*    @mem_tbl : memory operation table for
291*              allocating/deallocating stream buffers
292*    @stream_cb_sync : SYNC callback handling stream frame notify
293*    @stream_cb : ASYNC callback handling stream frame notify
294*    @userdata : user data pointer
295**/
296typedef struct {
297    cam_stream_info_t *stream_info;
298    cam_padding_info_t padding_info;
299    mm_camera_stream_mem_vtbl_t mem_vtbl;
300    mm_camera_buf_notify_t stream_cb_sync;
301    mm_camera_buf_notify_t stream_cb;
302    void *userdata;
303} mm_camera_stream_config_t;
304
305/** mm_camera_super_buf_notify_mode_t: enum for super uffer
306*                                      notification mode
307*    @MM_CAMERA_SUPER_BUF_NOTIFY_BURST :
308*       ZSL use case: get burst of frames
309*    @MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS :
310*       get continuous frames: when the super buf is ready
311*       dispatch it to HAL
312**/
313typedef enum {
314    MM_CAMERA_SUPER_BUF_NOTIFY_BURST = 0,
315    MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS,
316    MM_CAMERA_SUPER_BUF_NOTIFY_MAX
317} mm_camera_super_buf_notify_mode_t;
318
319/** mm_camera_super_buf_priority_t: enum for super buffer
320*                                   matching priority
321*    @MM_CAMERA_SUPER_BUF_PRIORITY_NORMAL :
322*       Save the frame no matter focused or not. Currently only
323*       this type is supported.
324*    @MM_CAMERA_SUPER_BUF_PRIORITY_FOCUS :
325*       only queue the frame that is focused. Will enable meta
326*       data header to carry focus info
327*    @MM_CAMERA_SUPER_BUF_PRIORITY_EXPOSURE_BRACKETING :
328*       after shutter, only queue matched exposure index
329**/
330typedef enum {
331    MM_CAMERA_SUPER_BUF_PRIORITY_NORMAL = 0,
332    MM_CAMERA_SUPER_BUF_PRIORITY_FOCUS,
333    MM_CAMERA_SUPER_BUF_PRIORITY_EXPOSURE_BRACKETING,
334    MM_CAMERA_SUPER_BUF_PRIORITY_LOW,/* Bundled metadata frame may not match*/
335    MM_CAMERA_SUPER_BUF_PRIORITY_MAX
336} mm_camera_super_buf_priority_t;
337
338/** mm_camera_advanced_capture_t: enum for advanced capture type.
339*    @MM_CAMERA_AF_BRACKETING :
340*       to enable AF Bracketig.
341*    @MM_CAMERA_AE_BRACKETING :
342*       to enable AF Bracketing.
343*    @MM_CAMERA_FLASH_BRACKETING :
344*       to enable Flash Bracketing.
345*    @MM_CAMERA_ZOOM_1X :
346*       to enable zoom 1x capture request
347**/
348typedef enum {
349   MM_CAMERA_AF_BRACKETING = 0,
350   MM_CAMERA_AE_BRACKETING,
351   MM_CAMERA_FLASH_BRACKETING,
352   MM_CAMERA_ZOOM_1X,
353   MM_CAMERA_FRAME_CAPTURE,
354} mm_camera_advanced_capture_t;
355
356/** mm_camera_stream_cb_type: enum for stream buffer callback type.
357*    @MM_CAMERA_STREAM_CB_TYPE_ASYNC :
358*       callback is async type. buffer process done in client thread context
359*    @MM_CAMERA_STREAM_CB_TYPE_SYNC :
360*       callback is sync type. buffer process done interface thread context
361**/
362typedef enum {
363    MM_CAMERA_STREAM_CB_TYPE_ASYNC,
364    MM_CAMERA_STREAM_CB_TYPE_SYNC,
365} mm_camera_stream_cb_type;
366
367
368/** mm_camera_channel_attr_t: structure for defining channel
369*                             attributes
370*    @notify_mode : notify mode: burst or continuous
371*    @water_mark : queue depth. Only valid for burst mode
372*    @look_back : look back how many frames from last buf.
373*                 Only valid for burst mode
374*    @post_frame_skip : after send first frame to HAL, how many
375*                     frames needing to be skipped for next
376*                     delivery. Only valid for burst mode
377*    @max_unmatched_frames : max number of unmatched frames in
378*                     queue
379*    @enable_frame_sync: Enables frame sync for dual camera
380*    @priority : save matched priority frames only
381*    @user_expected_frame_id : Number of frames, camera interface
382*                     will wait for getting the instant capture frame.
383**/
384typedef struct {
385    mm_camera_super_buf_notify_mode_t notify_mode;
386    uint8_t water_mark;
387    uint8_t look_back;
388    uint8_t post_frame_skip;
389    uint8_t max_unmatched_frames;
390    uint8_t enable_frame_sync;
391    mm_camera_super_buf_priority_t priority;
392    uint8_t user_expected_frame_id;
393} mm_camera_channel_attr_t;
394
395typedef struct {
396    /** query_capability: fucntion definition for querying static
397     *                    camera capabilities
398     *    @camera_handle : camer handler
399     *  Return value: 0 -- success
400     *                -1 -- failure
401     *  Note: would assume cam_capability_t is already mapped
402     **/
403    int32_t (*query_capability) (uint32_t camera_handle);
404
405    /** register_event_notify: fucntion definition for registering
406     *                         for event notification
407     *    @camera_handle : camer handler
408     *    @evt_cb : callback for event notify
409     *    @user_data : user data poiner
410     *  Return value: 0 -- success
411     *                -1 -- failure
412     **/
413    int32_t (*register_event_notify) (uint32_t camera_handle,
414                                      mm_camera_event_notify_t evt_cb,
415                                      void *user_data);
416
417    /** close_camera: fucntion definition for closing a camera
418     *    @camera_handle : camer handler
419     *  Return value: 0 -- success
420     *                -1 -- failure
421     **/
422    int32_t (*close_camera) (uint32_t camera_handle);
423
424    /** map_buf: fucntion definition for mapping a camera buffer
425     *           via domain socket
426     *    @camera_handle : camer handler
427     *    @buf_type : type of mapping buffers, can be value of
428     *                CAM_MAPPING_BUF_TYPE_CAPABILITY
429     *                CAM_MAPPING_BUF_TYPE_SETPARM_BUF
430     *                CAM_MAPPING_BUF_TYPE_GETPARM_BUF
431     *    @fd : file descriptor of the stream buffer
432     *    @size :  size of the stream buffer
433     *  Return value: 0 -- success
434     *                -1 -- failure
435     **/
436    int32_t (*map_buf) (uint32_t camera_handle,
437                        uint8_t buf_type,
438                        int fd,
439                        size_t size);
440
441    /** map_bufs: function definition for mapping multiple camera buffers
442     *           via domain socket
443     *    @camera_handle : camera handler
444     *    @buf_map_list : list of buffers to map
445     *  Return value: 0 -- success
446     *                -1 -- failure
447     **/
448    int32_t (*map_bufs) (uint32_t camera_handle,
449                         const cam_buf_map_type_list *buf_map_list);
450
451    /** unmap_buf: fucntion definition for unmapping a camera buffer
452     *           via domain socket
453     *    @camera_handle : camer handler
454     *    @buf_type : type of mapping buffers, can be value of
455     *                CAM_MAPPING_BUF_TYPE_CAPABILITY
456     *                CAM_MAPPING_BUF_TYPE_SETPARM_BUF
457     *                CAM_MAPPING_BUF_TYPE_GETPARM_BUF
458     *  Return value: 0 -- success
459     *                -1 -- failure
460     **/
461    int32_t (*unmap_buf) (uint32_t camera_handle,
462                          uint8_t buf_type);
463
464    /** set_parms: fucntion definition for setting camera
465     *             based parameters to server
466     *    @camera_handle : camer handler
467     *    @parms : batch for parameters to be set, stored in
468     *               parm_buffer_t
469     *  Return value: 0 -- success
470     *                -1 -- failure
471     *  Note: would assume parm_buffer_t is already mapped, and
472     *       according parameter entries to be set are filled in the
473     *       buf before this call
474     **/
475    int32_t (*set_parms) (uint32_t camera_handle,
476                          parm_buffer_t *parms);
477
478    /** get_parms: fucntion definition for querying camera
479     *             based parameters from server
480     *    @camera_handle : camer handler
481     *    @parms : batch for parameters to be queried, stored in
482     *               parm_buffer_t
483     *  Return value: 0 -- success
484     *                -1 -- failure
485     *  Note: would assume parm_buffer_t is already mapped, and
486     *       according parameter entries to be queried are filled in
487     *       the buf before this call
488     **/
489    int32_t (*get_parms) (uint32_t camera_handle,
490                          parm_buffer_t *parms);
491
492    /** do_auto_focus: fucntion definition for performing auto focus
493     *    @camera_handle : camer handler
494     *  Return value: 0 -- success
495     *                -1 -- failure
496     *  Note: if this call success, we will always assume there will
497     *        be an auto_focus event following up.
498     **/
499    int32_t (*do_auto_focus) (uint32_t camera_handle);
500
501    /** cancel_auto_focus: fucntion definition for cancelling
502     *                     previous auto focus request
503     *    @camera_handle : camer handler
504    *  Return value: 0 -- success
505    *                -1 -- failure
506     **/
507    int32_t (*cancel_auto_focus) (uint32_t camera_handle);
508
509    /** prepare_snapshot: fucntion definition for preparing hardware
510     *                    for snapshot.
511     *    @camera_handle : camer handler
512     *    @do_af_flag    : flag indicating if AF needs to be done
513     *                     0 -- no AF needed
514     *                     1 -- AF needed
515     *  Return value: 0 -- success
516     *                -1 -- failure
517     **/
518    int32_t (*prepare_snapshot) (uint32_t camera_handle,
519                                 int32_t do_af_flag);
520
521    /** start_zsl_snapshot: function definition for starting
522     *                    zsl snapshot.
523     *    @camera_handle : camer handler
524     *    @ch_id         : channel id
525     *  Return value: 0 -- success
526     *                -1 -- failure
527     **/
528    int32_t (*start_zsl_snapshot) (uint32_t camera_handle, uint32_t ch_id);
529
530    /** stop_zsl_snapshot: function definition for stopping
531     *                    zsl snapshot.
532     *    @camera_handle : camer handler
533     *    @ch_id         : channel id
534     *  Return value: 0 -- success
535     *                -1 -- failure
536     **/
537    int32_t (*stop_zsl_snapshot) (uint32_t camera_handle, uint32_t ch_id);
538
539    /** add_channel: fucntion definition for adding a channel
540     *    @camera_handle : camer handler
541     *    @ch_id : channel handler
542     *    @attr : pointer to channel attribute structure
543     *    @channel_cb : callbak to handle bundled super buffer
544     *    @userdata : user data pointer
545     *  Return value: channel id, zero is invalid ch_id
546     * Note: attr, channel_cb, and userdata can be NULL if no
547     *       superbufCB is needed
548     **/
549    uint32_t (*add_channel) (uint32_t camera_handle,
550                             mm_camera_channel_attr_t *attr,
551                             mm_camera_buf_notify_t channel_cb,
552                             void *userdata);
553
554    /** delete_channel: fucntion definition for deleting a channel
555     *    @camera_handle : camer handler
556     *    @ch_id : channel handler
557     *  Return value: 0 -- success
558     *                -1 -- failure
559     **/
560    int32_t (*delete_channel) (uint32_t camera_handle,
561                               uint32_t ch_id);
562
563    /** get_bundle_info: function definition for querying bundle
564     *  info of the channel
565     *    @camera_handle : camera handler
566     *    @ch_id         : channel handler
567     *    @bundle_info   : bundle info to be filled in
568     *  Return value: 0 -- success
569     *                -1 -- failure
570     **/
571    int32_t (*get_bundle_info) (uint32_t camera_handle,
572                                uint32_t ch_id,
573                                cam_bundle_config_t *bundle_info);
574
575    /** add_stream: fucntion definition for adding a stream
576     *    @camera_handle : camer handler
577     *    @ch_id : channel handler
578     *  Return value: stream_id. zero is invalid stream_id
579     **/
580    uint32_t (*add_stream) (uint32_t camera_handle,
581                            uint32_t ch_id);
582
583    /** delete_stream: fucntion definition for deleting a stream
584     *    @camera_handle : camer handler
585     *    @ch_id : channel handler
586     *    @stream_id : stream handler
587     *  Return value: 0 -- success
588     *                -1 -- failure
589     **/
590    int32_t (*delete_stream) (uint32_t camera_handle,
591                              uint32_t ch_id,
592                              uint32_t stream_id);
593
594    /** link_stream: function definition for linking a stream
595     *    @camera_handle : camera handle
596     *    @ch_id : channel handle from which the stream originates
597     *    @stream_id : stream handle
598     *    @linked_ch_id: channel handle in which the stream will be linked
599     *  Return value: 0 -- success
600     *                -1 -- failure
601     **/
602    int32_t (*link_stream) (uint32_t camera_handle,
603          uint32_t ch_id,
604          uint32_t stream_id,
605          uint32_t linked_ch_id);
606
607    /** config_stream: fucntion definition for configuring a stream
608     *    @camera_handle : camer handler
609     *    @ch_id : channel handler
610     *    @stream_id : stream handler
611     *    @confid : pointer to a stream configuration structure
612     *  Return value: 0 -- success
613     *                -1 -- failure
614     **/
615    int32_t (*config_stream) (uint32_t camera_handle,
616                              uint32_t ch_id,
617                              uint32_t stream_id,
618                              mm_camera_stream_config_t *config);
619
620    /** map_stream_buf: fucntion definition for mapping
621     *                 stream buffer via domain socket
622     *    @camera_handle : camer handler
623     *    @ch_id : channel handler
624     *    @stream_id : stream handler
625     *    @buf_type : type of mapping buffers, can be value of
626     *             CAM_MAPPING_BUF_TYPE_STREAM_BUF
627     *             CAM_MAPPING_BUF_TYPE_STREAM_INFO
628     *             CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF
629     *    @buf_idx : buffer index within the stream buffers
630     *    @plane_idx : plane index. If all planes share the same fd,
631     *               plane_idx = -1; otherwise, plean_idx is the
632     *               index to plane (0..num_of_planes)
633     *    @fd : file descriptor of the stream buffer
634     *    @size :  size of the stream buffer
635     *  Return value: 0 -- success
636     *                -1 -- failure
637     **/
638    int32_t (*map_stream_buf) (uint32_t camera_handle,
639                               uint32_t ch_id,
640                               uint32_t stream_id,
641                               uint8_t buf_type,
642                               uint32_t buf_idx,
643                               int32_t plane_idx,
644                               int fd,
645                               size_t size);
646
647    /** map_stream_bufs: function definition for mapping multiple
648     *                 stream buffers via domain socket
649     *    @camera_handle : camera handler
650     *    @ch_id : channel handler
651     *    @buf_map_list : list of buffers to map
652     *  Return value: 0 -- success
653     *                -1 -- failure
654     **/
655    int32_t (*map_stream_bufs) (uint32_t camera_handle,
656                                uint32_t ch_id,
657                                const cam_buf_map_type_list *buf_map_list);
658
659    /** unmap_stream_buf: fucntion definition for unmapping
660     *                 stream buffer via domain socket
661     *    @camera_handle : camer handler
662     *    @ch_id : channel handler
663     *    @stream_id : stream handler
664     *    @buf_type : type of mapping buffers, can be value of
665     *             CAM_MAPPING_BUF_TYPE_STREAM_BUF
666     *             CAM_MAPPING_BUF_TYPE_STREAM_INFO
667     *             CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF
668     *    @buf_idx : buffer index within the stream buffers
669     *    @plane_idx : plane index. If all planes share the same fd,
670     *               plane_idx = -1; otherwise, plean_idx is the
671     *               index to plane (0..num_of_planes)
672     *  Return value: 0 -- success
673     *                -1 -- failure
674     **/
675    int32_t (*unmap_stream_buf) (uint32_t camera_handle,
676                                 uint32_t ch_id,
677                                 uint32_t stream_id,
678                                 uint8_t buf_type,
679                                 uint32_t buf_idx,
680                                 int32_t plane_idx);
681
682    /** set_stream_parms: fucntion definition for setting stream
683     *                    specific parameters to server
684     *    @camera_handle : camer handler
685     *    @ch_id : channel handler
686     *    @stream_id : stream handler
687     *    @parms : batch for parameters to be set
688     *  Return value: 0 -- success
689     *                -1 -- failure
690     *  Note: would assume parm buffer is already mapped, and
691     *       according parameter entries to be set are filled in the
692     *       buf before this call
693     **/
694    int32_t (*set_stream_parms) (uint32_t camera_handle,
695                                 uint32_t ch_id,
696                                 uint32_t s_id,
697                                 cam_stream_parm_buffer_t *parms);
698
699    /** get_stream_parms: fucntion definition for querying stream
700     *                    specific parameters from server
701     *    @camera_handle : camer handler
702     *    @ch_id : channel handler
703     *    @stream_id : stream handler
704     *    @parms : batch for parameters to be queried
705     *  Return value: 0 -- success
706     *                -1 -- failure
707     *  Note: would assume parm buffer is already mapped, and
708     *       according parameter entries to be queried are filled in
709     *       the buf before this call
710     **/
711    int32_t (*get_stream_parms) (uint32_t camera_handle,
712                                 uint32_t ch_id,
713                                 uint32_t s_id,
714                                 cam_stream_parm_buffer_t *parms);
715
716    /** start_channel: fucntion definition for starting a channel
717     *    @camera_handle : camer handler
718     *    @ch_id : channel handler
719     *  Return value: 0 -- success
720     *                -1 -- failure
721     * This call will start all streams belongs to the channel
722     **/
723    int32_t (*start_channel) (uint32_t camera_handle,
724                              uint32_t ch_id);
725
726    /** stop_channel: fucntion definition for stopping a channel
727     *    @camera_handle : camer handler
728     *    @ch_id : channel handler
729     *  Return value: 0 -- success
730     *                -1 -- failure
731     * This call will stop all streams belongs to the channel
732     **/
733    int32_t (*stop_channel) (uint32_t camera_handle,
734                             uint32_t ch_id);
735
736    /** qbuf: fucntion definition for queuing a frame buffer back to
737     *        kernel for reuse
738     *    @camera_handle : camer handler
739     *    @ch_id : channel handler
740     *    @buf : a frame buffer to be queued back to kernel
741     *  Return value: 0 -- success
742     *                -1 -- failure
743     **/
744    int32_t (*qbuf) (uint32_t camera_handle,
745                     uint32_t ch_id,
746                     mm_camera_buf_def_t *buf);
747
748    /** get_queued_buf_count: fucntion definition for querying queued buf count
749     *    @camera_handle : camer handler
750     *    @ch_id : channel handler
751     *    @stream_id : stream handler
752     *  Return value: queued buf count
753     **/
754    int32_t (*get_queued_buf_count) (uint32_t camera_handle,
755            uint32_t ch_id,
756            uint32_t stream_id);
757
758    /** request_super_buf: fucntion definition for requesting frames
759     *                     from superbuf queue in burst mode
760     *    @camera_handle : camer handler
761     *    @ch_id : channel handler
762     *    @buf : provides info related to the super buf request
763     *  Return value: 0 -- success
764     *                -1 -- failure
765     **/
766    int32_t (*request_super_buf) (uint32_t camera_handle,
767                                  uint32_t ch_id,
768                                  mm_camera_req_buf_t *buf);
769
770    /** cancel_super_buf_request: fucntion definition for canceling
771     *                     frames dispatched from superbuf queue in
772     *                     burst mode
773     *    @camera_handle : camer handler
774     *    @ch_id : channel handler
775     *  Return value: 0 -- success
776     *                -1 -- failure
777     **/
778    int32_t (*cancel_super_buf_request) (uint32_t camera_handle,
779                                         uint32_t ch_id);
780
781    /** flush_super_buf_queue: function definition for flushing out
782     *                     all frames in the superbuf queue up to frame_idx,
783     *                     even if frames with frame_idx come in later than
784     *                     this call.
785     *    @camera_handle : camer handler
786     *    @ch_id : channel handler
787     *    @frame_idx : frame index up until which all superbufs are flushed
788     *  Return value: 0 -- success
789     *                -1 -- failure
790     **/
791    int32_t (*flush_super_buf_queue) (uint32_t camera_handle,
792                                      uint32_t ch_id, uint32_t frame_idx);
793
794    /** configure_notify_mode: function definition for configuring the
795     *                         notification mode of channel
796     *    @camera_handle : camera handler
797     *    @ch_id : channel handler
798     *    @notify_mode : notification mode
799     *  Return value: 0 -- success
800     *                -1 -- failure
801     **/
802    int32_t (*configure_notify_mode) (uint32_t camera_handle,
803                                      uint32_t ch_id,
804                                      mm_camera_super_buf_notify_mode_t notify_mode);
805
806   /** process_advanced_capture: function definition for start/stop advanced capture
807     *                    for snapshot.
808     *    @camera_handle : camera handle
809     *    @ch_id : channel handler
810     *    @type :  advanced capture type.
811     *    @trigger    : flag indicating if advanced capture needs to be done
812     *                     0 -- stop advanced capture
813     *                     1 -- start advanced capture
814     *    @in_value: Input value. Configaration
815     *  Return value: 0 -- success
816     *                -1 -- failure
817     **/
818    int32_t (*process_advanced_capture) (uint32_t camera_handle,
819             uint32_t ch_id, mm_camera_advanced_capture_t type,
820             int8_t start_flag, void *in_value);
821
822   /** get_session_id: gets the backend session id from the kernel
823     *    @camera_handle : camera handle
824     *    @sessionid : session id to be retrieved
825     *     Return value: 0 -- success
826     *                -1 -- failure
827     *  Note: if this call succeeds, we will get a valid session id
828     **/
829    int32_t (*get_session_id) (uint32_t camera_handle,
830            uint32_t* sessionid);
831
832    /** sync_related_sensors: sends sync cmd
833      *    @camera_handle : camera handle
834      *    @related_cam_info : related cam info to be sent to server
835      *     Return value: 0 -- success
836      *                -1 -- failure
837      *  Note: if this call succeeds, we will get linking established in back end
838      **/
839     int32_t (*sync_related_sensors) (uint32_t camera_handle,
840            cam_sync_related_sensors_event_info_t*
841            related_cam_info);
842    /** flush: function definition for flush
843     *  @camera_handle: camera handler
844     *  Return value: 0 -- success
845     *               -1 -- failure
846     **/
847    int32_t (*flush) (uint32_t camera_handle);
848
849   /** register_stream_buf_cb: fucntion definition for registering special stream callbacks
850     *    @camera_handle : camer handler
851     *    @ch_id : channel handler
852     *    @stream_id : stream handler
853     *    @buf_cb : callback function pointer
854     *    @cb_type : Callback type SYNC/ASYNC
855     *    @userdata : user data pointer
856     *    Return value: 0 -- success
857     *                -       1 -- failure
858     **/
859    int32_t (*register_stream_buf_cb) (uint32_t camera_handle,
860            uint32_t ch_id, uint32_t stream_id, mm_camera_buf_notify_t buf_cb,
861            mm_camera_stream_cb_type cb_type, void *userdata);
862} mm_camera_ops_t;
863
864/** mm_camera_vtbl_t: virtual table for camera operations
865*    @camera_handle : camera handler which uniquely identifies a
866*                   camera object
867*    @ops : API call table
868**/
869typedef struct {
870    uint32_t camera_handle;
871    mm_camera_ops_t *ops;
872} mm_camera_vtbl_t;
873
874/* return number of cameras */
875uint8_t get_num_of_cameras();
876
877/* return reference pointer of camera vtbl */
878int32_t camera_open(uint8_t camera_idx, mm_camera_vtbl_t **camera_obj);
879
880/* helper functions */
881int32_t mm_stream_calc_offset_preview(cam_stream_info_t *stream_info,
882        cam_dimension_t *dim,
883        cam_padding_info_t *padding,
884        cam_stream_buf_plane_info_t *buf_planes);
885
886int32_t mm_stream_calc_offset_post_view(cam_format_t fmt,
887        cam_dimension_t *dim,
888        cam_stream_buf_plane_info_t *buf_planes);
889
890int32_t mm_stream_calc_offset_snapshot(cam_format_t fmt,
891        cam_dimension_t *dim,
892        cam_padding_info_t *padding,
893        cam_stream_buf_plane_info_t *buf_planes);
894
895int32_t mm_stream_calc_offset_raw(cam_format_t fmt,
896        cam_dimension_t *dim,
897        cam_padding_info_t *padding,
898        cam_stream_buf_plane_info_t *buf_planes);
899
900int32_t mm_stream_calc_offset_video(cam_format_t fmt,
901        cam_dimension_t *dim,
902        cam_stream_buf_plane_info_t *buf_planes);
903
904int32_t mm_stream_calc_offset_metadata(cam_dimension_t *dim,
905        cam_padding_info_t *padding,
906        cam_stream_buf_plane_info_t *buf_planes);
907
908int32_t mm_stream_calc_offset_postproc(cam_stream_info_t *stream_info,
909        cam_padding_info_t *padding,
910        cam_stream_buf_plane_info_t *buf_planes);
911
912int32_t mm_stream_calc_offset_analysis(cam_format_t fmt,
913        cam_dimension_t *dim,
914        cam_padding_info_t *padding,
915        cam_stream_buf_plane_info_t *buf_planes);
916
917uint32_t mm_stream_calc_lcm (int32_t num1, int32_t num2);
918
919struct camera_info *get_cam_info(uint32_t camera_id, cam_sync_type_t *pCamType);
920
921uint8_t is_yuv_sensor(uint32_t camera_id);
922
923#endif /*__MM_CAMERA_INTERFACE_H__*/
924