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