mm_camera_interface.h revision 27d6d35f0459d0d1d409588a85c3c65ac0c422ff
1/* Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 *     * Redistributions of source code must retain the above copyright
7 *       notice, this list of conditions and the following disclaimer.
8 *     * Redistributions in binary form must reproduce the above
9 *       copyright notice, this list of conditions and the following
10 *       disclaimer in the documentation and/or other materials provided
11 *       with the distribution.
12 *     * Neither the name of The Linux Foundation nor the names of its
13 *       contributors may be used to endorse or promote products derived
14 *       from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30#ifndef __MM_CAMERA_INTERFACE_H__
31#define __MM_CAMERA_INTERFACE_H__
32#include <linux/msm_ion.h>
33#include <linux/videodev2.h>
34#include <media/msmb_camera.h>
35#include "cam_intf.h"
36#include "cam_queue.h"
37
38#define MM_CAMERA_MAX_NUM_SENSORS MSM_MAX_CAMERA_SENSORS
39#define MM_CAMERA_MAX_NUM_FRAMES CAM_MAX_NUM_BUFS_PER_STREAM
40/* num of channels allowed in a camera obj */
41#define MM_CAMERA_CHANNEL_MAX 16
42
43#define PAD_TO_SIZE(size, padding) \
44        ((size + (typeof(size))(padding - 1)) & \
45        (typeof(size))(~(padding - 1)))
46
47/** CAM_DUMP_TO_FILE:
48 *  @filename: file name
49 *  @name:filename
50 *  @index: index of the file
51 *  @extn: file extension
52 *  @p_addr: address of the buffer
53 *  @len: buffer length
54 *
55 *  dump the image to the file
56 **/
57#define CAM_DUMP_TO_FILE(path, name, index, extn, p_addr, len) ({ \
58  size_t rc = 0; \
59  char filename[FILENAME_MAX]; \
60  if (index >= 0) \
61    snprintf(filename, FILENAME_MAX, "%s/%s%d.%s", path, name, index, extn); \
62  else \
63    snprintf(filename, FILENAME_MAX, "%s/%s.%s", path, name, extn); \
64  FILE *fp = fopen(filename, "w+"); \
65  if (fp) { \
66    rc = fwrite(p_addr, 1, len, fp); \
67    ALOGE("%s:%d] written size %d", __func__, __LINE__, len); \
68    fclose(fp); \
69  } else { \
70    ALOGE("%s:%d] open %s failed", __func__, __LINE__, filename); \
71  } \
72})
73
74/* Declaring Buffer structure */
75struct mm_camera_buf_def;
76
77/** mm_camera_plane_def_t : structure for frame plane info
78*    @num_planes : num of planes for the frame buffer, to be
79*               filled during mem allocation
80*    @planes : plane info for the frame buffer, to be filled
81*               during mem allocation
82**/
83typedef struct {
84    int8_t num_planes;
85    struct v4l2_plane planes[VIDEO_MAX_PLANES];
86} mm_camera_plane_buf_def_t;
87
88/** mm_camera_user_buf_def_t : structure for frame plane info
89*    @num_buffers : num of buffers in this user defined structure
90*    @bufs_used : actual number of buffer filled
91*    @buf_in_use : flag to notify buffer usage status.
92*    @plane_buf : Plane buffer array pointer.
93**/
94typedef struct {
95    uint8_t num_buffers;
96    uint8_t bufs_used;     /*Num of Buffer filled by Kernel*/
97    uint8_t buf_in_use;  /* Container buffer is freed to fill*/
98    int32_t buf_idx[MSM_CAMERA_MAX_USER_BUFF_CNT];
99    struct mm_camera_buf_def *plane_buf;
100} mm_camera_user_buf_def_t;
101
102/** mm_camera_buf_def_t: structure for stream frame buf
103*    @stream_id : stream handler to uniquely identify a stream
104*               object
105*    @buf_idx : index of the buf within the stream bufs, to be
106*               filled during mem allocation
107*    @timespec_ts : time stamp, to be filled when DQBUF is
108*                 called
109*    @frame_idx : frame sequence num, to be filled when DQBUF
110*    @plane_buf  : Frame plane definition
111*    @fd : file descriptor of the frame buffer, to be filled
112*        during mem allocation
113*    @buffer : pointer to the frame buffer, to be filled during
114*            mem allocation
115*    @frame_len : length of the whole frame, to be filled during
116*               mem allocation
117*    @mem_info : user specific pointer to additional mem info
118*    @flags:  v4l2_buffer flags, used to report error in data buffers
119**/
120typedef struct mm_camera_buf_def {
121    uint32_t stream_id;
122    cam_stream_type_t stream_type;
123    cam_stream_buf_type buf_type;
124    uint32_t buf_idx;
125    uint8_t is_uv_subsampled;
126    struct timespec ts;
127    uint32_t frame_idx;
128    union {
129        mm_camera_plane_buf_def_t planes_buf;
130        mm_camera_user_buf_def_t user_buf;
131    };
132    int fd;
133    void *buffer;
134    size_t frame_len;
135    void *mem_info;
136    uint32_t flags;
137} mm_camera_buf_def_t;
138
139/** mm_camera_super_buf_t: super buf structure for bundled
140*   stream frames
141*    @camera_handle : camera handler to uniquely identify
142*              a camera object
143*    @ch_id : channel handler to uniquely ideentify a channel
144*           object
145*    @num_bufs : number of buffers in the super buf, should not
146*              exceeds MAX_STREAM_NUM_IN_BUNDLE
147*    @bufs : array of buffers in the bundle
148**/
149typedef struct {
150    uint32_t camera_handle;
151    uint32_t ch_id;
152    uint32_t num_bufs;
153    uint8_t bUnlockAEC;
154    uint8_t bReadyForPrepareSnapshot;
155    mm_camera_buf_def_t* bufs[MAX_STREAM_NUM_IN_BUNDLE];
156} mm_camera_super_buf_t;
157
158/** mm_camera_event_t: structure for event
159*    @server_event_type : event type from serer
160*    @status : status of an event, value could be
161*              CAM_STATUS_SUCCESS
162*              CAM_STATUS_FAILED
163**/
164typedef struct {
165    cam_event_type_t server_event_type;
166    uint32_t status;
167} mm_camera_event_t;
168
169/** mm_camera_event_notify_t: function definition for event
170*   notify handling
171*    @camera_handle : camera handler
172*    @evt : pointer to an event struct
173*    @user_data: user data pointer
174**/
175typedef void (*mm_camera_event_notify_t)(uint32_t camera_handle,
176                                         mm_camera_event_t *evt,
177                                         void *user_data);
178
179/** mm_camera_buf_notify_t: function definition for frame notify
180*   handling
181*    @mm_camera_super_buf_t : received frame buffers
182*    @user_data: user data pointer
183**/
184typedef void (*mm_camera_buf_notify_t) (mm_camera_super_buf_t *bufs,
185                                        void *user_data);
186
187/** map_stream_buf_op_t: function definition for operation of
188*   mapping stream buffers via domain socket
189*    @frame_idx : buffer index within stream buffers
190*    @plane_idx    : plane index. If all planes share the same
191*                   fd, plane_idx = -1; otherwise, plean_idx is
192*                   the index to plane (0..num_of_planes)
193*    @fd : file descriptor of the stream buffer
194*    @size: size of the stream buffer
195*    @userdata : user data pointer
196**/
197typedef int32_t (*map_stream_buf_op_t) (uint32_t frame_idx,
198                                        int32_t plane_idx,
199                                        int fd,
200                                        size_t size,
201                                        cam_mapping_buf_type type,
202                                        void *userdata);
203
204/** unmap_stream_buf_op_t: function definition for operation of
205*                          unmapping stream buffers via domain
206*                          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*    @userdata : user data pointer
212**/
213typedef int32_t (*unmap_stream_buf_op_t) (uint32_t frame_idx,
214                                          int32_t plane_idx,
215                                          cam_mapping_buf_type type,
216                                          void *userdata);
217
218/** mm_camera_map_unmap_ops_tbl_t: virtual table
219*                      for mapping/unmapping stream buffers via
220*                      domain socket
221*    @map_ops : operation for mapping
222*    @unmap_ops : operation for unmapping
223*    @userdata: user data pointer
224**/
225typedef struct {
226    map_stream_buf_op_t map_ops;
227    unmap_stream_buf_op_t unmap_ops;
228    void *userdata;
229} mm_camera_map_unmap_ops_tbl_t;
230
231/** mm_camera_stream_mem_vtbl_t: virtual table for stream
232*                      memory allocation and deallocation
233*    @get_bufs : function definition for allocating
234*                stream buffers
235*    @put_bufs : function definition for deallocating
236*                stream buffers
237*    @user_data: user data pointer
238**/
239typedef struct {
240  void *user_data;
241  int32_t (*get_bufs) (cam_frame_len_offset_t *offset,
242                       uint8_t *num_bufs,
243                       uint8_t **initial_reg_flag,
244                       mm_camera_buf_def_t **bufs,
245                       mm_camera_map_unmap_ops_tbl_t *ops_tbl,
246                       void *user_data);
247  int32_t (*put_bufs) (mm_camera_map_unmap_ops_tbl_t *ops_tbl,
248                       void *user_data);
249  int32_t (*invalidate_buf)(uint32_t index, void *user_data);
250  int32_t (*clean_invalidate_buf)(uint32_t index, void *user_data);
251} mm_camera_stream_mem_vtbl_t;
252
253/** mm_camera_stream_config_t: structure for stream
254*                              configuration
255*    @stream_info : pointer to a stream info structure
256*    @padding_info: padding info obtained from querycapability
257*    @mem_tbl : memory operation table for
258*              allocating/deallocating stream buffers
259*    @stream_cb : callback handling stream frame notify
260*    @userdata : user data pointer
261**/
262typedef struct {
263    cam_stream_info_t *stream_info;
264    cam_padding_info_t padding_info;
265    mm_camera_stream_mem_vtbl_t mem_vtbl;
266    mm_camera_buf_notify_t stream_cb;
267    void *userdata;
268} mm_camera_stream_config_t;
269
270/** mm_camera_super_buf_notify_mode_t: enum for super uffer
271*                                      notification mode
272*    @MM_CAMERA_SUPER_BUF_NOTIFY_BURST :
273*       ZSL use case: get burst of frames
274*    @MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS :
275*       get continuous frames: when the super buf is ready
276*       dispatch it to HAL
277**/
278typedef enum {
279    MM_CAMERA_SUPER_BUF_NOTIFY_BURST = 0,
280    MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS,
281    MM_CAMERA_SUPER_BUF_NOTIFY_MAX
282} mm_camera_super_buf_notify_mode_t;
283
284/** mm_camera_super_buf_priority_t: enum for super buffer
285*                                   matching priority
286*    @MM_CAMERA_SUPER_BUF_PRIORITY_NORMAL :
287*       Save the frame no matter focused or not. Currently only
288*       this type is supported.
289*    @MM_CAMERA_SUPER_BUF_PRIORITY_FOCUS :
290*       only queue the frame that is focused. Will enable meta
291*       data header to carry focus info
292*    @MM_CAMERA_SUPER_BUF_PRIORITY_EXPOSURE_BRACKETING :
293*       after shutter, only queue matched exposure index
294**/
295typedef enum {
296    MM_CAMERA_SUPER_BUF_PRIORITY_NORMAL = 0,
297    MM_CAMERA_SUPER_BUF_PRIORITY_FOCUS,
298    MM_CAMERA_SUPER_BUF_PRIORITY_EXPOSURE_BRACKETING,
299    MM_CAMERA_SUPER_BUF_PRIORITY_LOW,/* Bundled metadata frame may not match*/
300    MM_CAMERA_SUPER_BUF_PRIORITY_MAX
301} mm_camera_super_buf_priority_t;
302
303/** mm_camera_advanced_capture_t: enum for advanced capture type.
304*    @MM_CAMERA_AF_BRACKETING :
305*       to enable AF Bracketig.
306*    @MM_CAMERA_AE_BRACKETING :
307*       to enable AF Bracketing.
308*    @MM_CAMERA_FLASH_BRACKETING :
309*       to enable Flash Bracketing.
310*    @MM_CAMERA_ZOOM_1X :
311*       to enable zoom 1x capture request
312**/
313typedef enum {
314   MM_CAMERA_AF_BRACKETING = 0,
315   MM_CAMERA_AE_BRACKETING,
316   MM_CAMERA_FLASH_BRACKETING,
317   MM_CAMERA_ZOOM_1X,
318   MM_CAMERA_FRAME_CAPTURE,
319} mm_camera_advanced_capture_t;
320
321/** mm_camera_channel_attr_t: structure for defining channel
322*                             attributes
323*    @notify_mode : notify mode: burst or continuous
324*    @water_mark : queue depth. Only valid for burst mode
325*    @look_back : look back how many frames from last buf.
326*                 Only valid for burst mode
327*    @post_frame_skip : after send first frame to HAL, how many
328*                     frames needing to be skipped for next
329*                     delivery. Only valid for burst mode
330*    @max_unmatched_frames : max number of unmatched frames in
331*                     queue
332*    @priority : save matched priority frames only
333**/
334typedef struct {
335    mm_camera_super_buf_notify_mode_t notify_mode;
336    uint8_t water_mark;
337    uint8_t look_back;
338    uint8_t post_frame_skip;
339    uint8_t max_unmatched_frames;
340    mm_camera_super_buf_priority_t priority;
341} mm_camera_channel_attr_t;
342
343typedef struct {
344    /** query_capability: fucntion definition for querying static
345     *                    camera capabilities
346     *    @camera_handle : camer handler
347     *  Return value: 0 -- success
348     *                -1 -- failure
349     *  Note: would assume cam_capability_t is already mapped
350     **/
351    int32_t (*query_capability) (uint32_t camera_handle);
352
353    /** register_event_notify: fucntion definition for registering
354     *                         for event notification
355     *    @camera_handle : camer handler
356     *    @evt_cb : callback for event notify
357     *    @user_data : user data poiner
358     *  Return value: 0 -- success
359     *                -1 -- failure
360     **/
361    int32_t (*register_event_notify) (uint32_t camera_handle,
362                                      mm_camera_event_notify_t evt_cb,
363                                      void *user_data);
364
365    /** close_camera: fucntion definition for closing a camera
366     *    @camera_handle : camer handler
367     *  Return value: 0 -- success
368     *                -1 -- failure
369     **/
370    int32_t (*close_camera) (uint32_t camera_handle);
371
372
373    /** error_close_camera: function definition for closing
374     *                      the camera backend on an unrecoverable
375     *                      error
376     *    @camera_handle : camera handler
377     *  Return value: 0 -- success
378     *                -1 -- failure
379     **/
380    int32_t (*error_close_camera) (uint32_t camera_handle);
381
382    /** map_buf: fucntion definition for mapping a camera buffer
383     *           via domain socket
384     *    @camera_handle : camer handler
385     *    @buf_type : type of mapping buffers, can be value of
386     *                CAM_MAPPING_BUF_TYPE_CAPABILITY
387     *                CAM_MAPPING_BUF_TYPE_SETPARM_BUF
388     *                CAM_MAPPING_BUF_TYPE_GETPARM_BUF
389     *    @fd : file descriptor of the stream buffer
390     *    @size :  size of the stream buffer
391     *  Return value: 0 -- success
392     *                -1 -- failure
393     **/
394    int32_t (*map_buf) (uint32_t camera_handle,
395                        uint8_t buf_type,
396                        int fd,
397                        size_t size);
398
399    /** unmap_buf: fucntion definition for unmapping a camera buffer
400     *           via domain socket
401     *    @camera_handle : camer handler
402     *    @buf_type : type of mapping buffers, can be value of
403     *                CAM_MAPPING_BUF_TYPE_CAPABILITY
404     *                CAM_MAPPING_BUF_TYPE_SETPARM_BUF
405     *                CAM_MAPPING_BUF_TYPE_GETPARM_BUF
406     *  Return value: 0 -- success
407     *                -1 -- failure
408     **/
409    int32_t (*unmap_buf) (uint32_t camera_handle,
410                          uint8_t buf_type);
411
412    /** set_parms: fucntion definition for setting camera
413     *             based parameters to server
414     *    @camera_handle : camer handler
415     *    @parms : batch for parameters to be set, stored in
416     *               parm_buffer_t
417     *  Return value: 0 -- success
418     *                -1 -- failure
419     *  Note: would assume parm_buffer_t is already mapped, and
420     *       according parameter entries to be set are filled in the
421     *       buf before this call
422     **/
423    int32_t (*set_parms) (uint32_t camera_handle,
424                          parm_buffer_t *parms);
425
426    /** get_parms: fucntion definition for querying camera
427     *             based parameters from server
428     *    @camera_handle : camer handler
429     *    @parms : batch for parameters to be queried, stored in
430     *               parm_buffer_t
431     *  Return value: 0 -- success
432     *                -1 -- failure
433     *  Note: would assume parm_buffer_t is already mapped, and
434     *       according parameter entries to be queried are filled in
435     *       the buf before this call
436     **/
437    int32_t (*get_parms) (uint32_t camera_handle,
438                          parm_buffer_t *parms);
439
440    /** do_auto_focus: fucntion definition for performing auto focus
441     *    @camera_handle : camer handler
442     *  Return value: 0 -- success
443     *                -1 -- failure
444     *  Note: if this call success, we will always assume there will
445     *        be an auto_focus event following up.
446     **/
447    int32_t (*do_auto_focus) (uint32_t camera_handle);
448
449    /** cancel_auto_focus: fucntion definition for cancelling
450     *                     previous auto focus request
451     *    @camera_handle : camer handler
452    *  Return value: 0 -- success
453    *                -1 -- failure
454     **/
455    int32_t (*cancel_auto_focus) (uint32_t camera_handle);
456
457    /** prepare_snapshot: fucntion definition for preparing hardware
458     *                    for snapshot.
459     *    @camera_handle : camer handler
460     *    @do_af_flag    : flag indicating if AF needs to be done
461     *                     0 -- no AF needed
462     *                     1 -- AF needed
463     *  Return value: 0 -- success
464     *                -1 -- failure
465     **/
466    int32_t (*prepare_snapshot) (uint32_t camera_handle,
467                                 int32_t do_af_flag);
468
469    /** start_zsl_snapshot: function definition for starting
470     *                    zsl snapshot.
471     *    @camera_handle : camer handler
472     *    @ch_id         : channel id
473     *  Return value: 0 -- success
474     *                -1 -- failure
475     **/
476    int32_t (*start_zsl_snapshot) (uint32_t camera_handle, uint32_t ch_id);
477
478    /** stop_zsl_snapshot: function definition for stopping
479     *                    zsl snapshot.
480     *    @camera_handle : camer handler
481     *    @ch_id         : channel id
482     *  Return value: 0 -- success
483     *                -1 -- failure
484     **/
485    int32_t (*stop_zsl_snapshot) (uint32_t camera_handle, uint32_t ch_id);
486
487    /** add_channel: fucntion definition for adding a channel
488     *    @camera_handle : camer handler
489     *    @ch_id : channel handler
490     *    @attr : pointer to channel attribute structure
491     *    @channel_cb : callbak to handle bundled super buffer
492     *    @userdata : user data pointer
493     *  Return value: channel id, zero is invalid ch_id
494     * Note: attr, channel_cb, and userdata can be NULL if no
495     *       superbufCB is needed
496     **/
497    uint32_t (*add_channel) (uint32_t camera_handle,
498                             mm_camera_channel_attr_t *attr,
499                             mm_camera_buf_notify_t channel_cb,
500                             void *userdata);
501
502    /** delete_channel: fucntion definition for deleting a channel
503     *    @camera_handle : camer handler
504     *    @ch_id : channel handler
505     *  Return value: 0 -- success
506     *                -1 -- failure
507     **/
508    int32_t (*delete_channel) (uint32_t camera_handle,
509                               uint32_t ch_id);
510
511    /** get_bundle_info: function definition for querying bundle
512     *  info of the channel
513     *    @camera_handle : camera handler
514     *    @ch_id         : channel handler
515     *    @bundle_info   : bundle info to be filled in
516     *  Return value: 0 -- success
517     *                -1 -- failure
518     **/
519    int32_t (*get_bundle_info) (uint32_t camera_handle,
520                                uint32_t ch_id,
521                                cam_bundle_config_t *bundle_info);
522
523    /** add_stream: fucntion definition for adding a stream
524     *    @camera_handle : camer handler
525     *    @ch_id : channel handler
526     *  Return value: stream_id. zero is invalid stream_id
527     **/
528    uint32_t (*add_stream) (uint32_t camera_handle,
529                            uint32_t ch_id);
530
531    /** delete_stream: fucntion definition for deleting a stream
532     *    @camera_handle : camer handler
533     *    @ch_id : channel handler
534     *    @stream_id : stream handler
535     *  Return value: 0 -- success
536     *                -1 -- failure
537     **/
538    int32_t (*delete_stream) (uint32_t camera_handle,
539                              uint32_t ch_id,
540                              uint32_t stream_id);
541
542    /** link_stream: function definition for linking a stream
543     *    @camera_handle : camera handle
544     *    @ch_id : channel handle from which the stream originates
545     *    @stream_id : stream handle
546     *    @linked_ch_id: channel handle in which the stream will be linked
547     *  Return value: 0 -- success
548     *                -1 -- failure
549     **/
550    int32_t (*link_stream) (uint32_t camera_handle,
551          uint32_t ch_id,
552          uint32_t stream_id,
553          uint32_t linked_ch_id);
554
555    /** config_stream: fucntion definition for configuring a stream
556     *    @camera_handle : camer handler
557     *    @ch_id : channel handler
558     *    @stream_id : stream handler
559     *    @confid : pointer to a stream configuration structure
560     *  Return value: 0 -- success
561     *                -1 -- failure
562     **/
563    int32_t (*config_stream) (uint32_t camera_handle,
564                              uint32_t ch_id,
565                              uint32_t stream_id,
566                              mm_camera_stream_config_t *config);
567
568    /** map_stream_buf: fucntion definition for mapping
569     *                 stream buffer via domain socket
570     *    @camera_handle : camer handler
571     *    @ch_id : channel handler
572     *    @stream_id : stream handler
573     *    @buf_type : type of mapping buffers, can be value of
574     *             CAM_MAPPING_BUF_TYPE_STREAM_BUF
575     *             CAM_MAPPING_BUF_TYPE_STREAM_INFO
576     *             CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF
577     *    @buf_idx : buffer index within the stream buffers
578     *    @plane_idx : plane index. If all planes share the same fd,
579     *               plane_idx = -1; otherwise, plean_idx is the
580     *               index to plane (0..num_of_planes)
581     *    @fd : file descriptor of the stream buffer
582     *    @size :  size of the stream buffer
583     *  Return value: 0 -- success
584     *                -1 -- failure
585     **/
586    int32_t (*map_stream_buf) (uint32_t camera_handle,
587                               uint32_t ch_id,
588                               uint32_t stream_id,
589                               uint8_t buf_type,
590                               uint32_t buf_idx,
591                               int32_t plane_idx,
592                               int fd,
593                               size_t size);
594
595    /** unmap_stream_buf: fucntion definition for unmapping
596     *                 stream buffer via domain socket
597     *    @camera_handle : camer handler
598     *    @ch_id : channel handler
599     *    @stream_id : stream handler
600     *    @buf_type : type of mapping buffers, can be value of
601     *             CAM_MAPPING_BUF_TYPE_STREAM_BUF
602     *             CAM_MAPPING_BUF_TYPE_STREAM_INFO
603     *             CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF
604     *    @buf_idx : buffer index within the stream buffers
605     *    @plane_idx : plane index. If all planes share the same fd,
606     *               plane_idx = -1; otherwise, plean_idx is the
607     *               index to plane (0..num_of_planes)
608     *  Return value: 0 -- success
609     *                -1 -- failure
610     **/
611    int32_t (*unmap_stream_buf) (uint32_t camera_handle,
612                                 uint32_t ch_id,
613                                 uint32_t stream_id,
614                                 uint8_t buf_type,
615                                 uint32_t buf_idx,
616                                 int32_t plane_idx);
617
618    /** set_stream_parms: fucntion definition for setting stream
619     *                    specific parameters to server
620     *    @camera_handle : camer handler
621     *    @ch_id : channel handler
622     *    @stream_id : stream handler
623     *    @parms : batch for parameters to be set
624     *  Return value: 0 -- success
625     *                -1 -- failure
626     *  Note: would assume parm buffer is already mapped, and
627     *       according parameter entries to be set are filled in the
628     *       buf before this call
629     **/
630    int32_t (*set_stream_parms) (uint32_t camera_handle,
631                                 uint32_t ch_id,
632                                 uint32_t s_id,
633                                 cam_stream_parm_buffer_t *parms);
634
635    /** get_stream_parms: fucntion definition for querying stream
636     *                    specific parameters from server
637     *    @camera_handle : camer handler
638     *    @ch_id : channel handler
639     *    @stream_id : stream handler
640     *    @parms : batch for parameters to be queried
641     *  Return value: 0 -- success
642     *                -1 -- failure
643     *  Note: would assume parm buffer is already mapped, and
644     *       according parameter entries to be queried are filled in
645     *       the buf before this call
646     **/
647    int32_t (*get_stream_parms) (uint32_t camera_handle,
648                                 uint32_t ch_id,
649                                 uint32_t s_id,
650                                 cam_stream_parm_buffer_t *parms);
651
652    /** start_channel: fucntion definition for starting a channel
653     *    @camera_handle : camer handler
654     *    @ch_id : channel handler
655     *  Return value: 0 -- success
656     *                -1 -- failure
657     * This call will start all streams belongs to the channel
658     **/
659    int32_t (*start_channel) (uint32_t camera_handle,
660                              uint32_t ch_id);
661
662    /** stop_channel: fucntion definition for stopping a channel
663     *    @camera_handle : camer handler
664     *    @ch_id : channel handler
665     *  Return value: 0 -- success
666     *                -1 -- failure
667     * This call will stop all streams belongs to the channel
668     **/
669    int32_t (*stop_channel) (uint32_t camera_handle,
670                             uint32_t ch_id);
671
672    /** qbuf: fucntion definition for queuing a frame buffer back to
673     *        kernel for reuse
674     *    @camera_handle : camer handler
675     *    @ch_id : channel handler
676     *    @buf : a frame buffer to be queued back to kernel
677     *  Return value: 0 -- success
678     *                -1 -- failure
679     **/
680    int32_t (*qbuf) (uint32_t camera_handle,
681                     uint32_t ch_id,
682                     mm_camera_buf_def_t *buf);
683
684    /** get_queued_buf_count: fucntion definition for querying queued buf count
685     *    @camera_handle : camer handler
686     *    @ch_id : channel handler
687     *    @stream_id : stream handler
688     *  Return value: queued buf count
689     **/
690    int32_t (*get_queued_buf_count) (uint32_t camera_handle,
691            uint32_t ch_id,
692            uint32_t stream_id);
693
694    /** request_super_buf: fucntion definition for requesting frames
695     *                     from superbuf queue in burst mode
696     *    @camera_handle : camer handler
697     *    @ch_id : channel handler
698     *    @num_buf_requested : number of super buffers requested
699     *    @num_retro_buf_requested : number of retro buffers requested
700     *  Return value: 0 -- success
701     *                -1 -- failure
702     **/
703    int32_t (*request_super_buf) (uint32_t camera_handle,
704                                  uint32_t ch_id,
705                                  uint32_t num_buf_requested,
706                                  uint32_t num_retro_buf_requested);
707
708    /** cancel_super_buf_request: fucntion definition for canceling
709     *                     frames dispatched from superbuf queue in
710     *                     burst mode
711     *    @camera_handle : camer handler
712     *    @ch_id : channel handler
713     *  Return value: 0 -- success
714     *                -1 -- failure
715     **/
716    int32_t (*cancel_super_buf_request) (uint32_t camera_handle,
717                                         uint32_t ch_id);
718
719    /** flush_super_buf_queue: function definition for flushing out
720     *                     all frames in the superbuf queue up to frame_idx,
721     *                     even if frames with frame_idx come in later than
722     *                     this call.
723     *    @camera_handle : camer handler
724     *    @ch_id : channel handler
725     *    @frame_idx : frame index up until which all superbufs are flushed
726     *  Return value: 0 -- success
727     *                -1 -- failure
728     **/
729    int32_t (*flush_super_buf_queue) (uint32_t camera_handle,
730                                      uint32_t ch_id, uint32_t frame_idx);
731
732    /** configure_notify_mode: function definition for configuring the
733     *                         notification mode of channel
734     *    @camera_handle : camera handler
735     *    @ch_id : channel handler
736     *    @notify_mode : notification mode
737     *  Return value: 0 -- success
738     *                -1 -- failure
739     **/
740    int32_t (*configure_notify_mode) (uint32_t camera_handle,
741                                      uint32_t ch_id,
742                                      mm_camera_super_buf_notify_mode_t notify_mode);
743
744   /** process_advanced_capture: function definition for start/stop advanced capture
745     *                    for snapshot.
746     *    @camera_handle : camera handle
747     *    @ch_id : channel handler
748     *    @type :  advanced capture type.
749     *    @trigger    : flag indicating if advanced capture needs to be done
750     *                     0 -- stop advanced capture
751     *                     1 -- start advanced capture
752     *    @in_value: Input value. Configaration
753     *  Return value: 0 -- success
754     *                -1 -- failure
755     **/
756    int32_t (*process_advanced_capture) (uint32_t camera_handle,
757             uint32_t ch_id, mm_camera_advanced_capture_t type,
758             int8_t start_flag, void *in_value);
759} mm_camera_ops_t;
760
761/** mm_camera_vtbl_t: virtual table for camera operations
762*    @camera_handle : camera handler which uniquely identifies a
763*                   camera object
764*    @ops : API call table
765**/
766typedef struct {
767    uint32_t camera_handle;
768    mm_camera_ops_t *ops;
769} mm_camera_vtbl_t;
770
771/* return number of cameras */
772uint8_t get_num_of_cameras();
773
774/* return reference pointer of camera vtbl */
775int32_t camera_open(uint8_t camera_idx, mm_camera_vtbl_t **camera_obj);
776
777/* helper functions */
778int32_t mm_stream_calc_offset_preview(cam_format_t fmt,
779        cam_dimension_t *dim,
780        cam_stream_buf_plane_info_t *buf_planes);
781
782int32_t mm_stream_calc_offset_post_view(cam_format_t fmt,
783        cam_dimension_t *dim,
784        cam_stream_buf_plane_info_t *buf_planes);
785
786int32_t mm_stream_calc_offset_snapshot(cam_format_t fmt,
787        cam_dimension_t *dim,
788        cam_padding_info_t *padding,
789        cam_stream_buf_plane_info_t *buf_planes);
790
791int32_t mm_stream_calc_offset_raw(cam_format_t fmt,
792        cam_dimension_t *dim,
793        cam_padding_info_t *padding,
794        cam_stream_buf_plane_info_t *buf_planes);
795
796int32_t mm_stream_calc_offset_video(cam_dimension_t *dim,
797        cam_stream_buf_plane_info_t *buf_planes);
798
799int32_t mm_stream_calc_offset_metadata(cam_dimension_t *dim,
800        cam_padding_info_t *padding,
801        cam_stream_buf_plane_info_t *buf_planes);
802
803int32_t mm_stream_calc_offset_postproc(cam_stream_info_t *stream_info,
804        cam_padding_info_t *padding,
805        cam_stream_buf_plane_info_t *buf_planes);
806
807int32_t mm_stream_calc_offset_analysis(cam_format_t fmt,
808        cam_dimension_t *dim,
809        cam_padding_info_t *padding,
810        cam_stream_buf_plane_info_t *buf_planes);
811
812struct camera_info *get_cam_info(uint32_t camera_id);
813#endif /*__MM_CAMERA_INTERFACE_H__*/
814