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_JPEG_INTERFACE_H_
31#define MM_JPEG_INTERFACE_H_
32
33// System dependencies
34#include <stdbool.h>
35
36// Camera dependencies
37#include "QOMX_JpegExtensions.h"
38#include "cam_intf.h"
39
40#define MM_JPEG_MAX_PLANES 3
41#define MM_JPEG_MAX_BUF CAM_MAX_NUM_BUFS_PER_STREAM
42#define QUANT_SIZE 64
43#define QTABLE_MAX 2
44#define MM_JPEG_MAX_MPO_IMAGES 2
45
46typedef enum {
47  MM_JPEG_FMT_YUV,
48  MM_JPEG_FMT_BITSTREAM
49} mm_jpeg_format_t;
50
51typedef enum {
52  MM_JPEG_TYPE_JPEG,
53  MM_JPEG_TYPE_MPO
54} mm_jpeg_image_type_t;
55
56typedef struct {
57  cam_ae_exif_debug_t ae_debug_params;
58  cam_awb_exif_debug_t awb_debug_params;
59  cam_af_exif_debug_t af_debug_params;
60  cam_asd_exif_debug_t asd_debug_params;
61  cam_stats_buffer_exif_debug_t stats_debug_params;
62  uint8_t ae_debug_params_valid;
63  uint8_t awb_debug_params_valid;
64  uint8_t af_debug_params_valid;
65  uint8_t asd_debug_params_valid;
66  uint8_t stats_debug_params_valid;
67} mm_jpeg_debug_exif_params_t;
68
69typedef struct {
70  cam_3a_params_t cam_3a_params;
71  uint8_t cam_3a_params_valid;
72  cam_sensor_params_t sensor_params;
73  mm_jpeg_debug_exif_params_t *debug_params;
74} mm_jpeg_exif_params_t;
75
76typedef struct {
77  /* Indicates if it is a single jpeg or part of a multi picture sequence*/
78  mm_jpeg_image_type_t type;
79
80  /*Indicates if image is the primary image in a sequence of images.
81  Applicable only to multi picture formats*/
82  uint8_t is_primary;
83
84  /*Number of images in the sequence*/
85  uint32_t num_of_images;
86} mm_jpeg_multi_image_t;
87
88typedef struct {
89  uint32_t sequence;          /* for jpeg bit streams, assembling is based on sequence. sequence starts from 0 */
90  uint8_t *buf_vaddr;        /* ptr to buf */
91  int fd;                    /* fd of buf */
92  size_t buf_size;         /* total size of buf (header + image) */
93  mm_jpeg_format_t format;   /* buffer format*/
94  cam_frame_len_offset_t offset; /* offset of all the planes */
95  uint32_t index; /* index used to identify the buffers */
96} mm_jpeg_buf_t;
97
98typedef struct {
99  uint8_t *buf_vaddr;        /* ptr to buf */
100  int fd;                    /* fd of buf */
101  size_t buf_filled_len;   /* used for output image. filled by the client */
102} mm_jpeg_output_t;
103
104typedef enum {
105  MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V2,
106  MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V2,
107  MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V1,
108  MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V1,
109  MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V2,
110  MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V2,
111  MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V1,
112  MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V1,
113  MM_JPEG_COLOR_FORMAT_MONOCHROME,
114  MM_JPEG_COLOR_FORMAT_BITSTREAM_H2V2,
115  MM_JPEG_COLOR_FORMAT_BITSTREAM_H2V1,
116  MM_JPEG_COLOR_FORMAT_BITSTREAM_H1V2,
117  MM_JPEG_COLOR_FORMAT_BITSTREAM_H1V1,
118  MM_JPEG_COLOR_FORMAT_MAX
119} mm_jpeg_color_format;
120
121typedef enum {
122  JPEG_JOB_STATUS_DONE = 0,
123  JPEG_JOB_STATUS_ERROR
124} jpeg_job_status_t;
125
126typedef void (*jpeg_encode_callback_t)(jpeg_job_status_t status,
127  uint32_t client_hdl,
128  uint32_t jobId,
129  mm_jpeg_output_t *p_output,
130  void *userData);
131
132typedef struct {
133  /* src img dimension */
134  cam_dimension_t src_dim;
135
136  /* jpeg output dimension */
137  cam_dimension_t dst_dim;
138
139  /* crop information */
140  cam_rect_t crop;
141} mm_jpeg_dim_t;
142
143typedef struct {
144  /* num of buf in src img */
145  uint32_t num_src_bufs;
146
147  /* num of src tmb bufs */
148  uint32_t num_tmb_bufs;
149
150  /* num of buf in src img */
151  uint32_t num_dst_bufs;
152
153  /* should create thumbnail from main image or not */
154  uint32_t encode_thumbnail;
155
156  /* src img bufs */
157  mm_jpeg_buf_t src_main_buf[MM_JPEG_MAX_BUF];
158
159  /* this will be used only for bitstream */
160  mm_jpeg_buf_t src_thumb_buf[MM_JPEG_MAX_BUF];
161
162  /* this will be used only for bitstream */
163  mm_jpeg_buf_t dest_buf[MM_JPEG_MAX_BUF];
164
165  /* mainimage color format */
166  mm_jpeg_color_format color_format;
167
168  /* thumbnail color format */
169  mm_jpeg_color_format thumb_color_format;
170
171  /* jpeg quality: range 0~100 */
172  uint32_t quality;
173
174  /* jpeg thumbnail quality: range 0~100 */
175  uint32_t thumb_quality;
176
177  /* buf to exif entries, caller needs to
178   * take care of the memory manage with insider ptr */
179  QOMX_EXIF_INFO exif_info;
180
181  /*Callback registered to be called after encode*/
182  jpeg_encode_callback_t jpeg_cb;
183
184  /*Appdata passed by the user*/
185  void* userdata;
186
187  /* thumbnail dimension */
188  mm_jpeg_dim_t thumb_dim;
189
190  /* rotation informaiton */
191  uint32_t rotation;
192
193  /* thumb rotation informaiton */
194  uint32_t thumb_rotation;
195
196  /* main image dimension */
197  mm_jpeg_dim_t main_dim;
198
199  /* enable encoder burst mode */
200  uint32_t burst_mode;
201
202  /* get memory function ptr */
203  int (*get_memory)( omx_jpeg_ouput_buf_t *p_out_buf);
204
205  /* release memory function ptr */
206  int (*put_memory)( omx_jpeg_ouput_buf_t *p_out_buf);
207
208  /* Flag to indicate whether to generate thumbnail from postview */
209  bool thumb_from_postview;
210} mm_jpeg_encode_params_t;
211
212typedef struct {
213  /* num of buf in src img */
214  uint32_t num_src_bufs;
215
216  /* num of buf in src img */
217  uint32_t num_dst_bufs;
218
219  /* src img bufs */
220  mm_jpeg_buf_t src_main_buf[MM_JPEG_MAX_BUF];
221
222  /* this will be used only for bitstream */
223  mm_jpeg_buf_t dest_buf[MM_JPEG_MAX_BUF];
224
225  /* color format */
226  mm_jpeg_color_format color_format;
227
228  jpeg_encode_callback_t jpeg_cb;
229
230  void* userdata;
231
232} mm_jpeg_decode_params_t;
233
234typedef struct {
235  /* active indices of the buffers for encoding */
236  int32_t src_index;
237  int32_t dst_index;
238  uint32_t thumb_index;
239  mm_jpeg_dim_t thumb_dim;
240
241  /* rotation informaiton */
242  uint32_t rotation;
243
244  /* main image dimension */
245  mm_jpeg_dim_t main_dim;
246
247  /*session id*/
248  uint32_t session_id;
249
250  /* jpeg output buffer ref count */
251  int32_t ref_count;
252
253  /* allocated jpeg output buffer */
254  void *alloc_out_buffer;
255
256  /*Metadata stream*/
257  metadata_buffer_t *p_metadata;
258
259  /*HAL version*/
260  cam_hal_version_t hal_version;
261
262  /* buf to exif entries, caller needs to
263   * take care of the memory manage with insider ptr */
264  QOMX_EXIF_INFO exif_info;
265
266  /* 3a parameters */
267  mm_jpeg_exif_params_t cam_exif_params;
268
269  /* jpeg encoder QTable */
270  uint8_t qtable_set[QTABLE_MAX];
271
272  OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE qtable[QTABLE_MAX];
273
274  /* flag to enable/disable mobicat */
275  uint8_t mobicat_mask;
276
277  /*Info associated with multiple image sequence*/
278  mm_jpeg_multi_image_t multi_image_info;
279
280  /* work buf */
281  mm_jpeg_buf_t work_buf;
282} mm_jpeg_encode_job_t;
283
284typedef struct {
285  /* active indices of the buffers for encoding */
286  int32_t src_index;
287  int32_t dst_index;
288  uint32_t tmb_dst_index;
289
290  /* rotation informaiton */
291  uint32_t rotation;
292
293  /* main image  */
294  mm_jpeg_dim_t main_dim;
295
296  /*session id*/
297  uint32_t session_id;
298} mm_jpeg_decode_job_t;
299
300typedef enum {
301  JPEG_JOB_TYPE_ENCODE,
302  JPEG_JOB_TYPE_DECODE,
303  JPEG_JOB_TYPE_MAX
304} mm_jpeg_job_type_t;
305
306typedef struct {
307  mm_jpeg_job_type_t job_type;
308  union {
309    mm_jpeg_encode_job_t encode_job;
310    mm_jpeg_decode_job_t decode_job;
311  };
312} mm_jpeg_job_t;
313
314typedef struct {
315  uint32_t w;
316  uint32_t h;
317} mm_dimension;
318
319typedef struct {
320  /*Primary image in the MPO sequence*/
321  mm_jpeg_output_t primary_image;
322
323  /*All auxillary images in the sequence*/
324  mm_jpeg_output_t aux_images[MM_JPEG_MAX_MPO_IMAGES - 1];
325
326  /*Total number of images in the MPO sequence*/
327  int num_of_images;
328
329  /*Output MPO buffer*/
330  mm_jpeg_output_t output_buff;
331
332  /*Size of the allocated output buffer*/
333  size_t output_buff_size;
334} mm_jpeg_mpo_info_t;
335
336typedef struct {
337  /* config a job -- async call */
338  int (*start_job)(mm_jpeg_job_t* job, uint32_t* job_id);
339
340  /* abort a job -- sync call */
341  int (*abort_job)(uint32_t job_id);
342
343  /* create a session */
344  int (*create_session)(uint32_t client_hdl,
345    mm_jpeg_encode_params_t *p_params, uint32_t *p_session_id);
346
347  /* destroy session */
348  int (*destroy_session)(uint32_t session_id);
349
350  /* close a jpeg client -- sync call */
351  int (*close) (uint32_t clientHdl);
352
353} mm_jpeg_ops_t;
354
355typedef struct {
356  /* config a job -- async call */
357  int (*start_job)(mm_jpeg_job_t* job, uint32_t* job_id);
358
359  /* abort a job -- sync call */
360  int (*abort_job)(uint32_t job_id);
361
362  /* create a session */
363  int (*create_session)(uint32_t client_hdl,
364    mm_jpeg_decode_params_t *p_params, uint32_t *p_session_id);
365
366  /* destroy session */
367  int (*destroy_session)(uint32_t session_id);
368
369  /* close a jpeg client -- sync call */
370  int (*close) (uint32_t clientHdl);
371} mm_jpegdec_ops_t;
372
373typedef struct {
374
375  /* Get Mpo size*/
376  int (*get_mpo_size)(mm_jpeg_output_t jpeg_buffer[MM_JPEG_MAX_MPO_IMAGES],
377    int num_of_images);
378
379  /* Compose MPO*/
380  int (*compose_mpo)(mm_jpeg_mpo_info_t *mpo_info);
381
382} mm_jpeg_mpo_ops_t;
383
384/* open a jpeg client -- sync call
385 * returns client_handle.
386 * failed if client_handle=0
387 * jpeg ops tbl and mpo ops tbl will be filled in if open succeeds
388 * and jpeg meta data will be cached */
389uint32_t jpeg_open(mm_jpeg_ops_t *ops, mm_jpeg_mpo_ops_t *mpo_ops,
390  mm_dimension picture_size,
391  cam_jpeg_metadata_t *jpeg_metadata);
392
393/* open a jpeg client -- sync call
394 * returns client_handle.
395 * failed if client_handle=0
396 * jpeg ops tbl will be filled in if open succeeds */
397uint32_t jpegdec_open(mm_jpegdec_ops_t *ops);
398
399#endif /* MM_JPEG_INTERFACE_H_ */
400