1/* Copyright (c) 2012, 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_JPEG_INTERFACE_H_
31#define MM_JPEG_INTERFACE_H_
32#include "QOMX_JpegExtensions.h"
33#include "cam_intf.h"
34
35#define MM_JPEG_MAX_PLANES 3
36#define MM_JPEG_MAX_BUF CAM_MAX_NUM_BUFS_PER_STREAM
37
38typedef enum {
39  MM_JPEG_FMT_YUV,
40  MM_JPEG_FMT_BITSTREAM
41} mm_jpeg_format_t;
42
43typedef struct {
44  cam_ae_params_t ae_params;
45  cam_sensor_params_t sensor_params;
46} mm_jpeg_exif_params_t;
47typedef struct {
48  uint32_t sequence;          /* for jpeg bit streams, assembling is based on sequence. sequence starts from 0 */
49  uint8_t *buf_vaddr;        /* ptr to buf */
50  int fd;                    /* fd of buf */
51  uint32_t buf_size;         /* total size of buf (header + image) */
52  mm_jpeg_format_t format;   /* buffer format*/
53  cam_frame_len_offset_t offset; /* offset of all the planes */
54  int index; /* index used to identify the buffers */
55} mm_jpeg_buf_t;
56
57typedef struct {
58  uint8_t *buf_vaddr;        /* ptr to buf */
59  int fd;                    /* fd of buf */
60  uint32_t buf_filled_len;   /* used for output image. filled by the client */
61} mm_jpeg_output_t;
62
63typedef enum {
64  MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V2,
65  MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V2,
66  MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V1,
67  MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V1,
68  MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V2,
69  MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V2,
70  MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V1,
71  MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V1,
72  MM_JPEG_COLOR_FORMAT_BITSTREAM_H2V2,
73  MM_JPEG_COLOR_FORMAT_BITSTREAM_H2V1,
74  MM_JPEG_COLOR_FORMAT_BITSTREAM_H1V2,
75  MM_JPEG_COLOR_FORMAT_BITSTREAM_H1V1,
76  MM_JPEG_COLOR_FORMAT_MAX
77} mm_jpeg_color_format;
78
79typedef enum {
80  JPEG_JOB_STATUS_DONE = 0,
81  JPEG_JOB_STATUS_ERROR
82} jpeg_job_status_t;
83
84typedef void (*jpeg_encode_callback_t)(jpeg_job_status_t status,
85  uint32_t client_hdl,
86  uint32_t jobId,
87  mm_jpeg_output_t *p_output,
88  void *userData);
89
90typedef struct {
91  /* src img dimension */
92  cam_dimension_t src_dim;
93
94  /* jpeg output dimension */
95  cam_dimension_t dst_dim;
96
97  /* crop information */
98  cam_rect_t crop;
99} mm_jpeg_dim_t;
100
101typedef struct {
102  /* num of buf in src img */
103  uint32_t num_src_bufs;
104
105  /* num of src tmb bufs */
106  uint32_t num_tmb_bufs;
107
108  /* num of buf in src img */
109  uint32_t num_dst_bufs;
110
111  int8_t encode_thumbnail;
112
113  /* src img bufs */
114  mm_jpeg_buf_t src_main_buf[MM_JPEG_MAX_BUF];
115
116  /* this will be used only for bitstream */
117  mm_jpeg_buf_t src_thumb_buf[MM_JPEG_MAX_BUF];
118
119  /* this will be used only for bitstream */
120  mm_jpeg_buf_t dest_buf[MM_JPEG_MAX_BUF];
121
122  /* color format */
123  mm_jpeg_color_format color_format;
124
125  /* jpeg quality: range 0~100 */
126  uint32_t quality;
127
128  /* buf to exif entries, caller needs to
129   * take care of the memory manage with insider ptr */
130  QOMX_EXIF_INFO exif_info;
131
132  jpeg_encode_callback_t jpeg_cb;
133  void* userdata;
134
135} mm_jpeg_encode_params_t;
136
137typedef struct {
138  /* active indices of the buffers for encoding */
139  uint32_t src_index;
140  uint32_t dst_index;
141  uint32_t thumb_index;
142  mm_jpeg_dim_t thumb_dim;
143
144  /* rotation informaiton */
145  int rotation;
146
147  /* main image dimension */
148  mm_jpeg_dim_t main_dim;
149
150  /*session id*/
151  uint32_t session_id;
152
153  /*Metadata from HAl version 1 */
154  cam_metadata_info_t *p_metadata_v1;
155
156  /*Metadata stream from HAL version 3*/
157  metadata_buffer_t *p_metadata_v3;
158
159  /* buf to exif entries, caller needs to
160   * take care of the memory manage with insider ptr */
161  QOMX_EXIF_INFO exif_info;
162  /* 3a parameters */
163  mm_jpeg_exif_params_t cam_exif_params;
164} mm_jpeg_encode_job_t;
165
166typedef enum {
167  JPEG_JOB_TYPE_ENCODE,
168  JPEG_JOB_TYPE_MAX
169} mm_jpeg_job_type_t;
170
171typedef struct {
172  mm_jpeg_job_type_t job_type;
173  union {
174    mm_jpeg_encode_job_t encode_job;
175  };
176} mm_jpeg_job_t;
177
178typedef struct {
179  /* config a job -- async call */
180  int (*start_job)(mm_jpeg_job_t* job, uint32_t* job_id);
181
182  /* abort a job -- sync call */
183  int (*abort_job)(uint32_t job_id);
184
185  /* create a session */
186  int (*create_session)(uint32_t client_hdl,
187    mm_jpeg_encode_params_t *p_params, uint32_t *p_session_id);
188
189  /* destroy session */
190  int (*destroy_session)(uint32_t session_id);
191
192  /* close a jpeg client -- sync call */
193  int (*close) (uint32_t clientHdl);
194} mm_jpeg_ops_t;
195
196/* open a jpeg client -- sync call
197 * returns client_handle.
198 * failed if client_handle=0
199 * jpeg ops tbl will be filled in if open succeeds */
200uint32_t jpeg_open(mm_jpeg_ops_t *ops);
201
202#endif /* MM_JPEG_INTERFACE_H_ */
203