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