1 /* Copyright (c) 2012-2014, 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 #define QUANT_SIZE 64 38 #define QTABLE_MAX 2 39 40 typedef enum { 41 MM_JPEG_FMT_YUV, 42 MM_JPEG_FMT_BITSTREAM 43 } mm_jpeg_format_t; 44 45 typedef struct { 46 cam_3a_params_t cam_3a_params; 47 uint8_t cam_3a_params_valid; 48 cam_sensor_params_t sensor_params; 49 cam_ae_exif_debug_t ae_debug_params; 50 cam_awb_exif_debug_t awb_debug_params; 51 cam_af_exif_debug_t af_debug_params; 52 cam_asd_exif_debug_t asd_debug_params; 53 cam_stats_buffer_exif_debug_t stats_debug_params; 54 uint8_t ae_debug_params_valid; 55 uint8_t awb_debug_params_valid; 56 uint8_t af_debug_params_valid; 57 uint8_t asd_debug_params_valid; 58 uint8_t stats_debug_params_valid; 59 } mm_jpeg_exif_params_t; 60 61 typedef struct { 62 uint32_t sequence; /* for jpeg bit streams, assembling is based on sequence. sequence starts from 0 */ 63 uint8_t *buf_vaddr; /* ptr to buf */ 64 int fd; /* fd of buf */ 65 size_t buf_size; /* total size of buf (header + image) */ 66 mm_jpeg_format_t format; /* buffer format*/ 67 cam_frame_len_offset_t offset; /* offset of all the planes */ 68 uint32_t index; /* index used to identify the buffers */ 69 } mm_jpeg_buf_t; 70 71 typedef struct { 72 uint8_t *buf_vaddr; /* ptr to buf */ 73 int fd; /* fd of buf */ 74 size_t buf_filled_len; /* used for output image. filled by the client */ 75 } mm_jpeg_output_t; 76 77 typedef enum { 78 MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V2, 79 MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V2, 80 MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V1, 81 MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V1, 82 MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V2, 83 MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V2, 84 MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V1, 85 MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V1, 86 MM_JPEG_COLOR_FORMAT_MONOCHROME, 87 MM_JPEG_COLOR_FORMAT_BITSTREAM_H2V2, 88 MM_JPEG_COLOR_FORMAT_BITSTREAM_H2V1, 89 MM_JPEG_COLOR_FORMAT_BITSTREAM_H1V2, 90 MM_JPEG_COLOR_FORMAT_BITSTREAM_H1V1, 91 MM_JPEG_COLOR_FORMAT_MAX 92 } mm_jpeg_color_format; 93 94 typedef enum { 95 JPEG_JOB_STATUS_DONE = 0, 96 JPEG_JOB_STATUS_ERROR 97 } jpeg_job_status_t; 98 99 typedef void (*jpeg_encode_callback_t)(jpeg_job_status_t status, 100 uint32_t client_hdl, 101 uint32_t jobId, 102 mm_jpeg_output_t *p_output, 103 void *userData); 104 105 typedef struct { 106 /* src img dimension */ 107 cam_dimension_t src_dim; 108 109 /* jpeg output dimension */ 110 cam_dimension_t dst_dim; 111 112 /* crop information */ 113 cam_rect_t crop; 114 } mm_jpeg_dim_t; 115 116 typedef struct { 117 /* num of buf in src img */ 118 uint32_t num_src_bufs; 119 120 /* num of src tmb bufs */ 121 uint32_t num_tmb_bufs; 122 123 /* num of buf in src img */ 124 uint32_t num_dst_bufs; 125 126 /* should create thumbnail from main image or not */ 127 uint32_t encode_thumbnail; 128 129 /* src img bufs */ 130 mm_jpeg_buf_t src_main_buf[MM_JPEG_MAX_BUF]; 131 132 /* this will be used only for bitstream */ 133 mm_jpeg_buf_t src_thumb_buf[MM_JPEG_MAX_BUF]; 134 135 /* this will be used only for bitstream */ 136 mm_jpeg_buf_t dest_buf[MM_JPEG_MAX_BUF]; 137 138 /* mainimage color format */ 139 mm_jpeg_color_format color_format; 140 141 /* thumbnail color format */ 142 mm_jpeg_color_format thumb_color_format; 143 144 /* jpeg quality: range 0~100 */ 145 uint32_t quality; 146 147 /* jpeg thumbnail quality: range 0~100 */ 148 uint32_t thumb_quality; 149 150 /* buf to exif entries, caller needs to 151 * take care of the memory manage with insider ptr */ 152 QOMX_EXIF_INFO exif_info; 153 154 /*Callback registered to be called after encode*/ 155 jpeg_encode_callback_t jpeg_cb; 156 157 /*Appdata passed by the user*/ 158 void* userdata; 159 160 /* thumbnail dimension */ 161 mm_jpeg_dim_t thumb_dim; 162 163 /* rotation informaiton */ 164 uint32_t rotation; 165 166 /* thumb rotation informaiton */ 167 uint32_t thumb_rotation; 168 169 /* main image dimension */ 170 mm_jpeg_dim_t main_dim; 171 172 /* enable encoder burst mode */ 173 uint32_t burst_mode; 174 175 /* get memory function ptr */ 176 int (*get_memory)( omx_jpeg_ouput_buf_t *p_out_buf); 177 } mm_jpeg_encode_params_t; 178 179 typedef struct { 180 /* num of buf in src img */ 181 uint32_t num_src_bufs; 182 183 /* num of buf in src img */ 184 uint32_t num_dst_bufs; 185 186 /* src img bufs */ 187 mm_jpeg_buf_t src_main_buf[MM_JPEG_MAX_BUF]; 188 189 /* this will be used only for bitstream */ 190 mm_jpeg_buf_t dest_buf[MM_JPEG_MAX_BUF]; 191 192 /* color format */ 193 mm_jpeg_color_format color_format; 194 195 jpeg_encode_callback_t jpeg_cb; 196 void* userdata; 197 198 } mm_jpeg_decode_params_t; 199 200 typedef struct { 201 /* active indices of the buffers for encoding */ 202 int32_t src_index; 203 int32_t dst_index; 204 uint32_t thumb_index; 205 mm_jpeg_dim_t thumb_dim; 206 207 /* rotation informaiton */ 208 uint32_t rotation; 209 210 /* main image dimension */ 211 mm_jpeg_dim_t main_dim; 212 213 /*session id*/ 214 uint32_t session_id; 215 216 /*Metadata stream*/ 217 metadata_buffer_t *p_metadata; 218 219 /*HAL version*/ 220 cam_hal_version_t hal_version; 221 222 /* buf to exif entries, caller needs to 223 * take care of the memory manage with insider ptr */ 224 QOMX_EXIF_INFO exif_info; 225 226 /* 3a parameters */ 227 mm_jpeg_exif_params_t cam_exif_params; 228 229 /* jpeg encoder QTable */ 230 uint8_t qtable_set[QTABLE_MAX]; 231 OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE qtable[QTABLE_MAX]; 232 233 /* flag to enable/disable mobicat */ 234 uint8_t mobicat_mask; 235 236 } mm_jpeg_encode_job_t; 237 238 typedef struct { 239 /* active indices of the buffers for encoding */ 240 int32_t src_index; 241 int32_t dst_index; 242 uint32_t tmb_dst_index; 243 244 /* rotation informaiton */ 245 uint32_t rotation; 246 247 /* main image */ 248 mm_jpeg_dim_t main_dim; 249 250 /*session id*/ 251 uint32_t session_id; 252 } mm_jpeg_decode_job_t; 253 254 typedef enum { 255 JPEG_JOB_TYPE_ENCODE, 256 JPEG_JOB_TYPE_DECODE, 257 JPEG_JOB_TYPE_MAX 258 } mm_jpeg_job_type_t; 259 260 typedef struct { 261 mm_jpeg_job_type_t job_type; 262 union { 263 mm_jpeg_encode_job_t encode_job; 264 mm_jpeg_decode_job_t decode_job; 265 }; 266 } mm_jpeg_job_t; 267 268 typedef struct { 269 uint32_t w; 270 uint32_t h; 271 } mm_dimension; 272 273 typedef struct { 274 /* config a job -- async call */ 275 int (*start_job)(mm_jpeg_job_t* job, uint32_t* job_id); 276 277 /* abort a job -- sync call */ 278 int (*abort_job)(uint32_t job_id); 279 280 /* create a session */ 281 int (*create_session)(uint32_t client_hdl, 282 mm_jpeg_encode_params_t *p_params, uint32_t *p_session_id); 283 284 /* destroy session */ 285 int (*destroy_session)(uint32_t session_id); 286 287 /* close a jpeg client -- sync call */ 288 int (*close) (uint32_t clientHdl); 289 } mm_jpeg_ops_t; 290 291 typedef struct { 292 /* config a job -- async call */ 293 int (*start_job)(mm_jpeg_job_t* job, uint32_t* job_id); 294 295 /* abort a job -- sync call */ 296 int (*abort_job)(uint32_t job_id); 297 298 /* create a session */ 299 int (*create_session)(uint32_t client_hdl, 300 mm_jpeg_decode_params_t *p_params, uint32_t *p_session_id); 301 302 /* destroy session */ 303 int (*destroy_session)(uint32_t session_id); 304 305 /* close a jpeg client -- sync call */ 306 int (*close) (uint32_t clientHdl); 307 } mm_jpegdec_ops_t; 308 309 /* open a jpeg client -- sync call 310 * returns client_handle. 311 * failed if client_handle=0 312 * jpeg ops tbl will be filled in if open succeeds */ 313 uint32_t jpeg_open(mm_jpeg_ops_t *ops, mm_dimension picture_size); 314 315 /* open a jpeg client -- sync call 316 * returns client_handle. 317 * failed if client_handle=0 318 * jpeg ops tbl will be filled in if open succeeds */ 319 uint32_t jpegdec_open(mm_jpegdec_ops_t *ops); 320 321 #endif /* MM_JPEG_INTERFACE_H_ */ 322