1 /* Copyright (c) 2013-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 #include "mm_jpeg_interface.h" 31 #include "mm_jpeg_ionbuf.h" 32 #include <sys/time.h> 33 #include <stdlib.h> 34 35 #define MAX_NUM_BUFS (12) 36 37 /** DUMP_TO_FILE: 38 * @filename: file name 39 * @p_addr: address of the buffer 40 * @len: buffer length 41 * 42 * dump the image to the file 43 **/ 44 #define DUMP_TO_FILE(filename, p_addr, len) ({ \ 45 int rc = 0; \ 46 FILE *fp = fopen(filename, "w+"); \ 47 if (fp) { \ 48 rc = fwrite(p_addr, 1, len, fp); \ 49 fclose(fp); \ 50 } else { \ 51 CDBG_ERROR("%s:%d] cannot dump image", __func__, __LINE__); \ 52 } \ 53 }) 54 55 static int g_count = 1, g_i; 56 57 typedef struct { 58 mm_jpeg_color_format fmt; 59 float mult; 60 const char *str; 61 } mm_jpeg_intf_test_colfmt_t; 62 63 typedef struct { 64 char *filename; 65 int width; 66 int height; 67 char *out_filename; 68 int burst_mode; 69 int min_out_bufs; 70 mm_jpeg_intf_test_colfmt_t col_fmt; 71 int encode_thumbnail; 72 int tmb_width; 73 int tmb_height; 74 int main_quality; 75 int thumb_quality; 76 } jpeg_test_input_t; 77 78 /* Static constants */ 79 /* default Luma Qtable */ 80 const uint8_t DEFAULT_QTABLE_0[QUANT_SIZE] = { 81 16, 11, 10, 16, 24, 40, 51, 61, 82 12, 12, 14, 19, 26, 58, 60, 55, 83 14, 13, 16, 24, 40, 57, 69, 56, 84 14, 17, 22, 29, 51, 87, 80, 62, 85 18, 22, 37, 56, 68, 109, 103, 77, 86 24, 35, 55, 64, 81, 104, 113, 92, 87 49, 64, 78, 87, 103, 121, 120, 101, 88 72, 92, 95, 98, 112, 100, 103, 99 89 }; 90 91 /* default Chroma Qtable */ 92 const uint8_t DEFAULT_QTABLE_1[QUANT_SIZE] = { 93 17, 18, 24, 47, 99, 99, 99, 99, 94 18, 21, 26, 66, 99, 99, 99, 99, 95 24, 26, 56, 99, 99, 99, 99, 99, 96 47, 66, 99, 99, 99, 99, 99, 99, 97 99, 99, 99, 99, 99, 99, 99, 99, 98 99, 99, 99, 99, 99, 99, 99, 99, 99 99, 99, 99, 99, 99, 99, 99, 99, 100 99, 99, 99, 99, 99, 99, 99, 99 101 }; 102 103 typedef struct { 104 char *filename[MAX_NUM_BUFS]; 105 int width; 106 int height; 107 char *out_filename[MAX_NUM_BUFS]; 108 pthread_mutex_t lock; 109 pthread_cond_t cond; 110 buffer_t input[MAX_NUM_BUFS]; 111 buffer_t output[MAX_NUM_BUFS]; 112 int use_ion; 113 uint32_t handle; 114 mm_jpeg_ops_t ops; 115 uint32_t job_id[MAX_NUM_BUFS]; 116 mm_jpeg_encode_params_t params; 117 mm_jpeg_job_t job; 118 uint32_t session_id; 119 uint32_t num_bufs; 120 int min_out_bufs; 121 uint32_t buf_filled_len[MAX_NUM_BUFS]; 122 } mm_jpeg_intf_test_t; 123 124 125 126 static const mm_jpeg_intf_test_colfmt_t color_formats[] = 127 { 128 { MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V2, 1.5, "YCRCBLP_H2V2" }, 129 { MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V2, 1.5, "YCBCRLP_H2V2" }, 130 { MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V1, 2.0, "YCRCBLP_H2V1" }, 131 { MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V1, 2.0, "YCBCRLP_H2V1" }, 132 { MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V2, 2.0, "YCRCBLP_H1V2" }, 133 { MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V2, 2.0, "YCBCRLP_H1V2" }, 134 { MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V1, 3.0, "YCRCBLP_H1V1" }, 135 { MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V1, 3.0, "YCBCRLP_H1V1" } 136 }; 137 138 static jpeg_test_input_t jpeg_input[] = { 139 {"/data/test_1.yuv", 4000, 3008, "/data/test_1.jpg", 0, 0, 140 { MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V2, 1.5, "YCRCBLP_H2V2" }, 0, 320, 240, 80, 80} 141 }; 142 143 static void mm_jpeg_encode_callback(jpeg_job_status_t status, 144 uint32_t client_hdl, 145 uint32_t jobId, 146 mm_jpeg_output_t *p_output, 147 void *userData) 148 { 149 mm_jpeg_intf_test_t *p_obj = (mm_jpeg_intf_test_t *)userData; 150 151 pthread_mutex_lock(&p_obj->lock); 152 153 if (status == JPEG_JOB_STATUS_ERROR) { 154 CDBG_ERROR("%s:%d] Encode error", __func__, __LINE__); 155 } else { 156 int i = 0; 157 for (i = 0; p_obj->job_id[i] && (jobId != p_obj->job_id[i]); i++) 158 ; 159 if (!p_obj->job_id[i]) { 160 CDBG_ERROR("%s:%d] Cannot find job ID!!!", __func__, __LINE__); 161 goto error; 162 } 163 CDBG_ERROR("%s:%d] Encode success addr %p len %d idx %d", 164 __func__, __LINE__, p_output->buf_vaddr, p_output->buf_filled_len, i); 165 166 p_obj->buf_filled_len[i] = p_output->buf_filled_len; 167 if (p_obj->min_out_bufs) { 168 CDBG_ERROR("%s:%d] Saving file%s addr %p len %d", 169 __func__, __LINE__, p_obj->out_filename[i], 170 p_output->buf_vaddr, p_output->buf_filled_len); 171 172 DUMP_TO_FILE(p_obj->out_filename[i], p_output->buf_vaddr, 173 p_output->buf_filled_len); 174 } 175 } 176 g_i++; 177 178 error: 179 180 if (g_i >= g_count) { 181 CDBG_ERROR("%s:%d] Signal the thread", __func__, __LINE__); 182 pthread_cond_signal(&p_obj->cond); 183 } 184 pthread_mutex_unlock(&p_obj->lock); 185 } 186 187 int mm_jpeg_test_alloc(buffer_t *p_buffer, int use_pmem) 188 { 189 int ret = 0; 190 /*Allocate buffers*/ 191 if (use_pmem) { 192 p_buffer->addr = (uint8_t *)buffer_allocate(p_buffer, 0); 193 if (NULL == p_buffer->addr) { 194 CDBG_ERROR("%s:%d] Error",__func__, __LINE__); 195 return -1; 196 } 197 } else { 198 /* Allocate heap memory */ 199 p_buffer->addr = (uint8_t *)malloc(p_buffer->size); 200 if (NULL == p_buffer->addr) { 201 CDBG_ERROR("%s:%d] Error",__func__, __LINE__); 202 return -1; 203 } 204 } 205 return ret; 206 } 207 208 void mm_jpeg_test_free(buffer_t *p_buffer) 209 { 210 if (p_buffer->addr == NULL) 211 return; 212 213 if (p_buffer->p_pmem_fd > 0) 214 buffer_deallocate(p_buffer); 215 else 216 free(p_buffer->addr); 217 218 memset(p_buffer, 0x0, sizeof(buffer_t)); 219 } 220 221 int mm_jpeg_test_read(mm_jpeg_intf_test_t *p_obj, int idx) 222 { 223 int rc = 0; 224 FILE *fp = NULL; 225 int file_size = 0; 226 fp = fopen(p_obj->filename[idx], "rb"); 227 if (!fp) { 228 CDBG_ERROR("%s:%d] error", __func__, __LINE__); 229 return -1; 230 } 231 fseek(fp, 0, SEEK_END); 232 file_size = ftell(fp); 233 fseek(fp, 0, SEEK_SET); 234 CDBG_ERROR("%s:%d] input file size is %d buf_size %ld", 235 __func__, __LINE__, file_size, p_obj->input[idx].size); 236 237 if (p_obj->input[idx].size > file_size) { 238 CDBG_ERROR("%s:%d] error", __func__, __LINE__); 239 fclose(fp); 240 return -1; 241 } 242 fread(p_obj->input[idx].addr, 1, p_obj->input[idx].size, fp); 243 fclose(fp); 244 return 0; 245 } 246 247 static int encode_init(jpeg_test_input_t *p_input, mm_jpeg_intf_test_t *p_obj) 248 { 249 int rc = -1; 250 int size = p_input->width * p_input->height; 251 mm_jpeg_encode_params_t *p_params = &p_obj->params; 252 mm_jpeg_encode_job_t *p_job_params = &p_obj->job.encode_job; 253 int i = 0; 254 int burst_mode = p_input->burst_mode; 255 jpeg_test_input_t *p_in = p_input; 256 do { 257 p_obj->filename[i] = p_in->filename; 258 p_obj->width = p_input->width; 259 p_obj->height = p_input->height; 260 p_obj->out_filename[i] = p_in->out_filename; 261 p_obj->use_ion = 1; 262 p_obj->min_out_bufs = p_input->min_out_bufs; 263 264 /* allocate buffers */ 265 p_obj->input[i].size = size * p_input->col_fmt.mult; 266 rc = mm_jpeg_test_alloc(&p_obj->input[i], p_obj->use_ion); 267 if (rc) { 268 CDBG_ERROR("%s:%d] Error",__func__, __LINE__); 269 return -1; 270 } 271 272 273 rc = mm_jpeg_test_read(p_obj, i); 274 if (rc) { 275 CDBG_ERROR("%s:%d] Error",__func__, __LINE__); 276 return -1; 277 } 278 279 /* src buffer config*/ 280 p_params->src_main_buf[i].buf_size = p_obj->input[i].size; 281 p_params->src_main_buf[i].buf_vaddr = p_obj->input[i].addr; 282 p_params->src_main_buf[i].fd = p_obj->input[i].p_pmem_fd; 283 p_params->src_main_buf[i].index = i; 284 p_params->src_main_buf[i].format = MM_JPEG_FMT_YUV; 285 p_params->src_main_buf[i].offset.mp[0].len = size; 286 p_params->src_main_buf[i].offset.mp[0].stride = p_input->width; 287 p_params->src_main_buf[i].offset.mp[0].scanline = p_input->height; 288 p_params->src_main_buf[i].offset.mp[1].len = size >> 1; 289 290 /* src buffer config*/ 291 p_params->src_thumb_buf[i].buf_size = p_obj->input[i].size; 292 p_params->src_thumb_buf[i].buf_vaddr = p_obj->input[i].addr; 293 p_params->src_thumb_buf[i].fd = p_obj->input[i].p_pmem_fd; 294 p_params->src_thumb_buf[i].index = i; 295 p_params->src_thumb_buf[i].format = MM_JPEG_FMT_YUV; 296 p_params->src_thumb_buf[i].offset.mp[0].len = size; 297 p_params->src_thumb_buf[i].offset.mp[0].stride = p_input->width; 298 p_params->src_thumb_buf[i].offset.mp[0].scanline = p_input->height; 299 p_params->src_thumb_buf[i].offset.mp[1].len = size >> 1; 300 301 302 i++; 303 } while((++p_in)->filename); 304 305 p_obj->num_bufs = i; 306 307 pthread_mutex_init(&p_obj->lock, NULL); 308 pthread_cond_init(&p_obj->cond, NULL); 309 310 311 /* set encode parameters */ 312 p_params->jpeg_cb = mm_jpeg_encode_callback; 313 p_params->userdata = p_obj; 314 p_params->color_format = p_input->col_fmt.fmt; 315 p_params->thumb_color_format = p_input->col_fmt.fmt; 316 317 if (p_obj->min_out_bufs) { 318 p_params->num_dst_bufs = 2; 319 } else { 320 p_params->num_dst_bufs = p_obj->num_bufs; 321 } 322 323 for (i = 0; i < (int)p_params->num_dst_bufs; i++) { 324 p_obj->output[i].size = size * 3/2; 325 rc = mm_jpeg_test_alloc(&p_obj->output[i], 0); 326 if (rc) { 327 CDBG_ERROR("%s:%d] Error",__func__, __LINE__); 328 return -1; 329 } 330 /* dest buffer config */ 331 p_params->dest_buf[i].buf_size = p_obj->output[i].size; 332 p_params->dest_buf[i].buf_vaddr = p_obj->output[i].addr; 333 p_params->dest_buf[i].fd = p_obj->output[i].p_pmem_fd; 334 p_params->dest_buf[i].index = i; 335 } 336 337 338 p_params->num_src_bufs = p_obj->num_bufs; 339 p_params->num_tmb_bufs = 0; 340 g_count = p_params->num_src_bufs; 341 342 p_params->encode_thumbnail = p_input->encode_thumbnail; 343 if (p_params->encode_thumbnail) { 344 p_params->num_tmb_bufs = p_obj->num_bufs; 345 } 346 p_params->quality = p_input->main_quality; 347 p_params->thumb_quality = p_input->thumb_quality; 348 349 p_job_params->dst_index = 0; 350 p_job_params->src_index = 0; 351 p_job_params->rotation = 0; 352 353 /* main dimension */ 354 p_job_params->main_dim.src_dim.width = p_obj->width; 355 p_job_params->main_dim.src_dim.height = p_obj->height; 356 p_job_params->main_dim.dst_dim.width = p_obj->width; 357 p_job_params->main_dim.dst_dim.height = p_obj->height; 358 p_job_params->main_dim.crop.top = 0; 359 p_job_params->main_dim.crop.left = 0; 360 p_job_params->main_dim.crop.width = p_obj->width; 361 p_job_params->main_dim.crop.height = p_obj->height; 362 363 p_params->main_dim = p_job_params->main_dim; 364 365 /* thumb dimension */ 366 p_job_params->thumb_dim.src_dim.width = p_obj->width; 367 p_job_params->thumb_dim.src_dim.height = p_obj->height; 368 p_job_params->thumb_dim.dst_dim.width = p_input->tmb_width; 369 p_job_params->thumb_dim.dst_dim.height = p_input->tmb_height; 370 p_job_params->thumb_dim.crop.top = 0; 371 p_job_params->thumb_dim.crop.left = 0; 372 p_job_params->thumb_dim.crop.width = 0; 373 p_job_params->thumb_dim.crop.height = 0; 374 375 p_params->thumb_dim = p_job_params->thumb_dim; 376 377 p_job_params->exif_info.numOfEntries = 0; 378 p_params->burst_mode = burst_mode; 379 380 /* Qtable */ 381 p_job_params->qtable[0].eQuantizationTable = 382 OMX_IMAGE_QuantizationTableLuma; 383 p_job_params->qtable[1].eQuantizationTable = 384 OMX_IMAGE_QuantizationTableChroma; 385 p_job_params->qtable_set[0] = 1; 386 p_job_params->qtable_set[1] = 1; 387 388 for (i = 0; i < QUANT_SIZE; i++) { 389 p_job_params->qtable[0].nQuantizationMatrix[i] = DEFAULT_QTABLE_0[i]; 390 p_job_params->qtable[1].nQuantizationMatrix[i] = DEFAULT_QTABLE_1[i]; 391 } 392 393 return 0; 394 } 395 396 static int encode_test(jpeg_test_input_t *p_input) 397 { 398 int rc = 0; 399 mm_jpeg_intf_test_t jpeg_obj; 400 unsigned int i = 0; 401 402 memset(&jpeg_obj, 0x0, sizeof(jpeg_obj)); 403 rc = encode_init(p_input, &jpeg_obj); 404 if (rc) { 405 CDBG_ERROR("%s:%d] Error",__func__, __LINE__); 406 return -1; 407 } 408 409 mm_dimension pic_size; 410 memset(&pic_size, 0, sizeof(mm_dimension)); 411 pic_size.w = p_input->width; 412 pic_size.h = p_input->height; 413 414 jpeg_obj.handle = jpeg_open(&jpeg_obj.ops, pic_size); 415 if (jpeg_obj.handle == 0) { 416 CDBG_ERROR("%s:%d] Error",__func__, __LINE__); 417 goto end; 418 } 419 420 rc = jpeg_obj.ops.create_session(jpeg_obj.handle, &jpeg_obj.params, 421 &jpeg_obj.job.encode_job.session_id); 422 if (jpeg_obj.job.encode_job.session_id == 0) { 423 CDBG_ERROR("%s:%d] Error",__func__, __LINE__); 424 goto end; 425 } 426 427 for (i = 0; i < jpeg_obj.num_bufs; i++) { 428 jpeg_obj.job.job_type = JPEG_JOB_TYPE_ENCODE; 429 jpeg_obj.job.encode_job.src_index = i; 430 jpeg_obj.job.encode_job.dst_index = i; 431 jpeg_obj.job.encode_job.thumb_index = i; 432 433 if (jpeg_obj.params.burst_mode && jpeg_obj.min_out_bufs) { 434 jpeg_obj.job.encode_job.dst_index = -1; 435 } 436 437 rc = jpeg_obj.ops.start_job(&jpeg_obj.job, &jpeg_obj.job_id[i]); 438 439 if (rc) { 440 CDBG_ERROR("%s:%d] Error",__func__, __LINE__); 441 goto end; 442 } 443 } 444 jpeg_obj.job_id[i] = 0; 445 446 /* 447 usleep(5); 448 jpeg_obj.ops.abort_job(jpeg_obj.job_id[0]); 449 */ 450 pthread_mutex_lock(&jpeg_obj.lock); 451 pthread_cond_wait(&jpeg_obj.cond, &jpeg_obj.lock); 452 pthread_mutex_unlock(&jpeg_obj.lock); 453 454 455 jpeg_obj.ops.destroy_session(jpeg_obj.job.encode_job.session_id); 456 jpeg_obj.ops.close(jpeg_obj.handle); 457 458 end: 459 for (i = 0; i < jpeg_obj.num_bufs; i++) { 460 if (!jpeg_obj.min_out_bufs) { 461 // Save output files 462 CDBG_ERROR("%s:%d] Saving file%s addr %p len %d", 463 __func__, __LINE__,jpeg_obj.out_filename[i], 464 jpeg_obj.output[i].addr, jpeg_obj.buf_filled_len[i]); 465 466 DUMP_TO_FILE(jpeg_obj.out_filename[i], jpeg_obj.output[i].addr, 467 jpeg_obj.buf_filled_len[i]); 468 } 469 mm_jpeg_test_free(&jpeg_obj.input[i]); 470 mm_jpeg_test_free(&jpeg_obj.output[i]); 471 } 472 return 0; 473 } 474 475 #define MAX_FILE_CNT (20) 476 static int mm_jpeg_test_get_input(int argc, char *argv[], 477 jpeg_test_input_t *p_test) 478 { 479 int c, in_file_cnt = 0, out_file_cnt = 0, i; 480 int idx = 0; 481 jpeg_test_input_t *p_test_base = p_test; 482 483 char *in_files[MAX_FILE_CNT]; 484 char *out_files[MAX_FILE_CNT]; 485 486 while ((c = getopt(argc, argv, "-I:O:W:H:F:BTx:y:Q:q:")) != -1) { 487 switch (c) { 488 case 'B': 489 fprintf(stderr, "%-25s\n", "Using burst mode"); 490 p_test->burst_mode = 1; 491 break; 492 case 'I': 493 for (idx = optind - 1; idx < argc; idx++) { 494 if (argv[idx][0] == '-') { 495 break; 496 } 497 in_files[in_file_cnt++] = argv[idx]; 498 } 499 optind = idx -1; 500 501 break; 502 case 'O': 503 for (idx = optind - 1; idx < argc; idx++) { 504 if (argv[idx][0] == '-') { 505 break; 506 } 507 out_files[out_file_cnt++] = argv[idx]; 508 } 509 optind = idx -1; 510 511 break; 512 case 'W': 513 p_test->width = atoi(optarg); 514 fprintf(stderr, "%-25s%d\n", "Width: ", p_test->width); 515 break; 516 case 'H': 517 p_test->height = atoi(optarg); 518 fprintf(stderr, "%-25s%d\n", "Height: ", p_test->height); 519 break; 520 case 'F': 521 p_test->col_fmt = color_formats[atoi(optarg)]; 522 fprintf(stderr, "%-25s%s\n", "Format: ", p_test->col_fmt.str); 523 break; 524 case 'M': 525 p_test->min_out_bufs = 1; 526 fprintf(stderr, "%-25s\n", "Using minimum number of output buffers"); 527 break; 528 case 'T': 529 p_test->encode_thumbnail = 1; 530 fprintf(stderr, "%-25s\n", "Encode thumbnail"); 531 break; 532 case 'x': 533 p_test->tmb_width = atoi(optarg); 534 fprintf(stderr, "%-25s%d\n", "Tmb Width: ", p_test->tmb_width); 535 break; 536 case 'y': 537 p_test->tmb_height = atoi(optarg); 538 fprintf(stderr, "%-25s%d\n", "Tmb Height: ", p_test->tmb_height); 539 break; 540 case 'Q': 541 p_test->main_quality = atoi(optarg); 542 fprintf(stderr, "%-25s%d\n", "Main quality: ", p_test->main_quality); 543 break; 544 case 'q': 545 p_test->thumb_quality = atoi(optarg); 546 fprintf(stderr, "%-25s%d\n", "Thumb quality: ", p_test->thumb_quality); 547 break; 548 default:; 549 } 550 } 551 fprintf(stderr, "Infiles: %d Outfiles: %d\n", in_file_cnt, out_file_cnt); 552 553 if (in_file_cnt > out_file_cnt) { 554 fprintf(stderr, "%-25s\n", "Insufficient number of output files!"); 555 return 1; 556 } 557 558 // Discard the extra out files 559 out_file_cnt = in_file_cnt; 560 561 p_test = realloc(p_test, (in_file_cnt + 1) * sizeof(*p_test)); 562 if (!p_test) { 563 CDBG_ERROR("%s:%d] Error",__func__, __LINE__); 564 return 1; 565 } 566 memset(p_test+1, 0, (in_file_cnt) * sizeof(*p_test)); 567 568 for (i = 0; i < in_file_cnt; i++, p_test++) { 569 memcpy(p_test, p_test_base, sizeof(*p_test)); 570 p_test->filename = in_files[i]; 571 p_test->out_filename = out_files[i]; 572 fprintf(stderr, "Inf: %s Outf: %s\n", in_files[i], out_files[i]); 573 } 574 575 576 return 0; 577 } 578 579 static void mm_jpeg_test_print_usage() 580 { 581 fprintf(stderr, "Usage: program_name [options]\n"); 582 fprintf(stderr, "Mandatory options:\n"); 583 fprintf(stderr, " -I FILE1 [FILE2] [FILEN]\tList of input files\n"); 584 fprintf(stderr, " -O FILE1 [FILE2] [FILEN]\tList of output files\n"); 585 fprintf(stderr, " -W WIDTH\t\tOutput image width\n"); 586 fprintf(stderr, " -H HEIGHT\t\tOutput image height\n"); 587 fprintf(stderr, " -F \t\tColor format: \n"); 588 fprintf(stderr, "\t\t\t\t%s (0), %s (1), %s (2) %s (3)\n" 589 "\t\t\t\t%s (4), %s (5), %s (6) %s (7)\n ", 590 color_formats[0].str, color_formats[1].str, 591 color_formats[2].str, color_formats[3].str, 592 color_formats[4].str, color_formats[5].str, 593 color_formats[6].str, color_formats[7].str); 594 fprintf(stderr, "Optional:\n"); 595 fprintf(stderr, " -T \t\Encode thumbnail\n"); 596 fprintf(stderr, " -x TMB_WIDTH\t\tThumbnail width\n"); 597 fprintf(stderr, " -y TMB_HEIGHT\t\tThumbnail height\n"); 598 fprintf(stderr, " -Q MAIN_QUALITY\t\tMain image quality\n"); 599 fprintf(stderr, " -q TMB_QUALITY\t\tThumbnail image quality\n"); 600 fprintf(stderr, " -B \t\tBurst mode. Utilize both encoder engines on" 601 "supported targets\n"); 602 fprintf(stderr, " -M \t\tUse minimum number of output buffers \n"); 603 fprintf(stderr, "\n"); 604 } 605 606 /** main: 607 * 608 * Arguments: 609 * @argc 610 * @argv 611 * 612 * Return: 613 * 0 or -ve values 614 * 615 * Description: 616 * main function 617 * 618 **/ 619 int main(int argc, char* argv[]) 620 { 621 jpeg_test_input_t *p_test_input; 622 int ret = 0; 623 if (argc > 1) { 624 p_test_input = calloc(2, sizeof(*p_test_input)); 625 if (!p_test_input) { 626 CDBG_ERROR("%s:%d] Error",__func__, __LINE__); 627 goto exit; 628 } 629 memcpy(p_test_input, &jpeg_input[0], sizeof(*p_test_input)); 630 ret = mm_jpeg_test_get_input(argc, argv, p_test_input); 631 if (ret) { 632 CDBG_ERROR("%s:%d] Error",__func__, __LINE__); 633 goto exit; 634 } 635 } else { 636 mm_jpeg_test_print_usage(); 637 return 1; 638 } 639 ret = encode_test(p_test_input); 640 641 exit: 642 if (!ret) { 643 fprintf(stderr, "%-25s\n", "Success!"); 644 } else { 645 fprintf(stderr, "%-25s\n", "Fail!"); 646 } 647 648 if (argc > 1) { 649 if (p_test_input) { 650 free(p_test_input); 651 p_test_input = NULL; 652 } 653 } 654 655 return ret; 656 } 657 658 659