1 /* Copyright (c) 2012-2017, 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 // To remove 31 #include <cutils/properties.h> 32 33 // System dependencies 34 #include <dlfcn.h> 35 #include <errno.h> 36 #include <fcntl.h> 37 #include <linux/msm_ion.h> 38 #define MMAN_H <SYSTEM_HEADER_PREFIX/mman.h> 39 #include MMAN_H 40 41 // Camera dependencies 42 #include "mm_qcamera_dbg.h" 43 #include "mm_qcamera_app.h" 44 45 static pthread_mutex_t app_mutex; 46 static int thread_status = 0; 47 static pthread_cond_t app_cond_v; 48 49 #define MM_QCAMERA_APP_NANOSEC_SCALE 1000000000 50 51 int mm_camera_app_timedwait(uint8_t seconds) 52 { 53 int rc = 0; 54 pthread_mutex_lock(&app_mutex); 55 if(FALSE == thread_status) { 56 struct timespec tw; 57 memset(&tw, 0, sizeof tw); 58 tw.tv_sec = 0; 59 tw.tv_nsec = time(0) + seconds * MM_QCAMERA_APP_NANOSEC_SCALE; 60 61 rc = pthread_cond_timedwait(&app_cond_v, &app_mutex,&tw); 62 thread_status = FALSE; 63 } 64 pthread_mutex_unlock(&app_mutex); 65 return rc; 66 } 67 68 int mm_camera_app_wait() 69 { 70 int rc = 0; 71 pthread_mutex_lock(&app_mutex); 72 if(FALSE == thread_status){ 73 pthread_cond_wait(&app_cond_v, &app_mutex); 74 } 75 thread_status = FALSE; 76 pthread_mutex_unlock(&app_mutex); 77 return rc; 78 } 79 80 void mm_camera_app_done() 81 { 82 pthread_mutex_lock(&app_mutex); 83 thread_status = TRUE; 84 pthread_cond_signal(&app_cond_v); 85 pthread_mutex_unlock(&app_mutex); 86 } 87 88 int mm_app_load_hal(mm_camera_app_t *my_cam_app) 89 { 90 memset(&my_cam_app->hal_lib, 0, sizeof(hal_interface_lib_t)); 91 my_cam_app->hal_lib.ptr = dlopen("libmmcamera_interface.so", RTLD_NOW); 92 my_cam_app->hal_lib.ptr_jpeg = dlopen("libmmjpeg_interface.so", RTLD_NOW); 93 if (!my_cam_app->hal_lib.ptr || !my_cam_app->hal_lib.ptr_jpeg) { 94 LOGE("Error opening HAL library %s\n", dlerror()); 95 return -MM_CAMERA_E_GENERAL; 96 } 97 *(void **)&(my_cam_app->hal_lib.get_num_of_cameras) = 98 dlsym(my_cam_app->hal_lib.ptr, "get_num_of_cameras"); 99 *(void **)&(my_cam_app->hal_lib.mm_camera_open) = 100 dlsym(my_cam_app->hal_lib.ptr, "camera_open"); 101 *(void **)&(my_cam_app->hal_lib.jpeg_open) = 102 dlsym(my_cam_app->hal_lib.ptr_jpeg, "jpeg_open"); 103 104 if (my_cam_app->hal_lib.get_num_of_cameras == NULL || 105 my_cam_app->hal_lib.mm_camera_open == NULL || 106 my_cam_app->hal_lib.jpeg_open == NULL) { 107 LOGE("Error loading HAL sym %s\n", dlerror()); 108 return -MM_CAMERA_E_GENERAL; 109 } 110 111 if (my_cam_app->num_cameras == 0) { 112 my_cam_app->num_cameras = my_cam_app->hal_lib.get_num_of_cameras(); 113 } 114 LOGD("num_cameras = %d\n", my_cam_app->num_cameras); 115 116 return MM_CAMERA_OK; 117 } 118 119 int mm_app_allocate_ion_memory(mm_camera_app_buf_t *buf, 120 __unused unsigned int ion_type) 121 { 122 int rc = MM_CAMERA_OK; 123 struct ion_handle_data handle_data; 124 struct ion_allocation_data alloc; 125 struct ion_fd_data ion_info_fd; 126 int main_ion_fd = -1; 127 void *data = NULL; 128 129 main_ion_fd = open("/dev/ion", O_RDONLY); 130 if (main_ion_fd <= 0) { 131 LOGE("Ion dev open failed %s\n", strerror(errno)); 132 goto ION_OPEN_FAILED; 133 } 134 135 memset(&alloc, 0, sizeof(alloc)); 136 alloc.len = buf->mem_info.size; 137 /* to make it page size aligned */ 138 alloc.len = (alloc.len + 4095U) & (~4095U); 139 alloc.align = 4096; 140 alloc.flags = ION_FLAG_CACHED; 141 alloc.heap_id_mask = ION_HEAP(ION_SYSTEM_HEAP_ID); 142 rc = ioctl(main_ion_fd, ION_IOC_ALLOC, &alloc); 143 if (rc < 0) { 144 LOGE("ION allocation failed %s with rc = %d \n",strerror(errno), rc); 145 goto ION_ALLOC_FAILED; 146 } 147 148 memset(&ion_info_fd, 0, sizeof(ion_info_fd)); 149 ion_info_fd.handle = alloc.handle; 150 rc = ioctl(main_ion_fd, ION_IOC_SHARE, &ion_info_fd); 151 if (rc < 0) { 152 LOGE("ION map failed %s\n", strerror(errno)); 153 goto ION_MAP_FAILED; 154 } 155 156 data = mmap(NULL, 157 alloc.len, 158 PROT_READ | PROT_WRITE, 159 MAP_SHARED, 160 ion_info_fd.fd, 161 0); 162 163 if (data == MAP_FAILED) { 164 LOGE("ION_MMAP_FAILED: %s (%d)\n", strerror(errno), errno); 165 goto ION_MAP_FAILED; 166 } 167 buf->mem_info.main_ion_fd = main_ion_fd; 168 buf->mem_info.fd = ion_info_fd.fd; 169 buf->mem_info.handle = ion_info_fd.handle; 170 buf->mem_info.size = alloc.len; 171 buf->mem_info.data = data; 172 return MM_CAMERA_OK; 173 174 ION_MAP_FAILED: 175 memset(&handle_data, 0, sizeof(handle_data)); 176 handle_data.handle = ion_info_fd.handle; 177 ioctl(main_ion_fd, ION_IOC_FREE, &handle_data); 178 ION_ALLOC_FAILED: 179 close(main_ion_fd); 180 ION_OPEN_FAILED: 181 return -MM_CAMERA_E_GENERAL; 182 } 183 184 int mm_app_deallocate_ion_memory(mm_camera_app_buf_t *buf) 185 { 186 struct ion_handle_data handle_data; 187 int rc = 0; 188 189 rc = munmap(buf->mem_info.data, buf->mem_info.size); 190 191 if (buf->mem_info.fd >= 0) { 192 close(buf->mem_info.fd); 193 buf->mem_info.fd = -1; 194 } 195 196 if (buf->mem_info.main_ion_fd >= 0) { 197 memset(&handle_data, 0, sizeof(handle_data)); 198 handle_data.handle = buf->mem_info.handle; 199 ioctl(buf->mem_info.main_ion_fd, ION_IOC_FREE, &handle_data); 200 close(buf->mem_info.main_ion_fd); 201 buf->mem_info.main_ion_fd = -1; 202 } 203 return rc; 204 } 205 206 /* cmd = ION_IOC_CLEAN_CACHES, ION_IOC_INV_CACHES, ION_IOC_CLEAN_INV_CACHES */ 207 int mm_app_cache_ops(mm_camera_app_meminfo_t *mem_info, 208 int cmd) 209 { 210 struct ion_flush_data cache_inv_data; 211 struct ion_custom_data custom_data; 212 int ret = MM_CAMERA_OK; 213 214 #ifdef USE_ION 215 if (NULL == mem_info) { 216 LOGE("mem_info is NULL, return here"); 217 return -MM_CAMERA_E_GENERAL; 218 } 219 220 memset(&cache_inv_data, 0, sizeof(cache_inv_data)); 221 memset(&custom_data, 0, sizeof(custom_data)); 222 cache_inv_data.vaddr = mem_info->data; 223 cache_inv_data.fd = mem_info->fd; 224 cache_inv_data.handle = mem_info->handle; 225 cache_inv_data.length = (unsigned int)mem_info->size; 226 custom_data.cmd = (unsigned int)cmd; 227 custom_data.arg = (unsigned long)&cache_inv_data; 228 229 LOGD("addr = %p, fd = %d, handle = %lx length = %d, ION Fd = %d", 230 cache_inv_data.vaddr, cache_inv_data.fd, 231 (unsigned long)cache_inv_data.handle, cache_inv_data.length, 232 mem_info->main_ion_fd); 233 if(mem_info->main_ion_fd >= 0) { 234 if(ioctl(mem_info->main_ion_fd, ION_IOC_CUSTOM, &custom_data) < 0) { 235 LOGE("Cache Invalidate failed\n"); 236 ret = -MM_CAMERA_E_GENERAL; 237 } 238 } 239 #endif 240 241 return ret; 242 } 243 244 void mm_app_dump_frame(mm_camera_buf_def_t *frame, 245 char *name, 246 char *ext, 247 uint32_t frame_idx) 248 { 249 char file_name[FILENAME_MAX]; 250 int file_fd; 251 int i; 252 int offset = 0; 253 if ( frame != NULL) { 254 snprintf(file_name, sizeof(file_name), 255 QCAMERA_DUMP_FRM_LOCATION"%s_%04d.%s", name, frame_idx, ext); 256 file_fd = open(file_name, O_RDWR | O_CREAT, 0777); 257 if (file_fd < 0) { 258 LOGE("cannot open file %s \n", file_name); 259 } else { 260 for (i = 0; i < frame->planes_buf.num_planes; i++) { 261 LOGD("saving file from address: %p, data offset: %d, " 262 "length: %d \n", frame->buffer, 263 frame->planes_buf.planes[i].data_offset, frame->planes_buf.planes[i].length); 264 write(file_fd, 265 (uint8_t *)frame->buffer + offset, 266 frame->planes_buf.planes[i].length); 267 offset += (int)frame->planes_buf.planes[i].length; 268 } 269 270 close(file_fd); 271 LOGD("dump %s", file_name); 272 } 273 } 274 } 275 276 void mm_app_dump_jpeg_frame(const void * data, size_t size, char* name, 277 char* ext, uint32_t index) 278 { 279 char buf[FILENAME_MAX]; 280 int file_fd; 281 if ( data != NULL) { 282 snprintf(buf, sizeof(buf), 283 QCAMERA_DUMP_FRM_LOCATION"test/%s_%u.%s", name, index, ext); 284 LOGD("%s size =%zu, jobId=%u", buf, size, index); 285 file_fd = open(buf, O_RDWR | O_CREAT, 0777); 286 write(file_fd, data, size); 287 close(file_fd); 288 } 289 } 290 291 int mm_app_alloc_bufs(mm_camera_app_buf_t* app_bufs, 292 cam_frame_len_offset_t *frame_offset_info, 293 uint8_t num_bufs, 294 uint8_t is_streambuf, 295 size_t multipleOf) 296 { 297 uint32_t i, j; 298 unsigned int ion_type = 0x1 << CAMERA_ION_FALLBACK_HEAP_ID; 299 300 if (is_streambuf) { 301 ion_type |= 0x1 << CAMERA_ION_HEAP_ID; 302 } 303 304 for (i = 0; i < num_bufs ; i++) { 305 if ( 0 < multipleOf ) { 306 size_t m = frame_offset_info->frame_len / multipleOf; 307 if ( ( frame_offset_info->frame_len % multipleOf ) != 0 ) { 308 m++; 309 } 310 app_bufs[i].mem_info.size = m * multipleOf; 311 } else { 312 app_bufs[i].mem_info.size = frame_offset_info->frame_len; 313 } 314 mm_app_allocate_ion_memory(&app_bufs[i], ion_type); 315 316 app_bufs[i].buf.buf_idx = i; 317 app_bufs[i].buf.planes_buf.num_planes = (int8_t)frame_offset_info->num_planes; 318 app_bufs[i].buf.fd = app_bufs[i].mem_info.fd; 319 app_bufs[i].buf.frame_len = app_bufs[i].mem_info.size; 320 app_bufs[i].buf.buffer = app_bufs[i].mem_info.data; 321 app_bufs[i].buf.mem_info = (void *)&app_bufs[i].mem_info; 322 323 /* Plane 0 needs to be set seperately. Set other planes 324 * in a loop. */ 325 app_bufs[i].buf.planes_buf.planes[0].length = frame_offset_info->mp[0].len; 326 app_bufs[i].buf.planes_buf.planes[0].m.userptr = 327 (long unsigned int)app_bufs[i].buf.fd; 328 app_bufs[i].buf.planes_buf.planes[0].data_offset = frame_offset_info->mp[0].offset; 329 app_bufs[i].buf.planes_buf.planes[0].reserved[0] = 0; 330 for (j = 1; j < (uint8_t)frame_offset_info->num_planes; j++) { 331 app_bufs[i].buf.planes_buf.planes[j].length = frame_offset_info->mp[j].len; 332 app_bufs[i].buf.planes_buf.planes[j].m.userptr = 333 (long unsigned int)app_bufs[i].buf.fd; 334 app_bufs[i].buf.planes_buf.planes[j].data_offset = frame_offset_info->mp[j].offset; 335 app_bufs[i].buf.planes_buf.planes[j].reserved[0] = 336 app_bufs[i].buf.planes_buf.planes[j-1].reserved[0] + 337 app_bufs[i].buf.planes_buf.planes[j-1].length; 338 } 339 } 340 LOGD("X"); 341 return MM_CAMERA_OK; 342 } 343 344 int mm_app_release_bufs(uint8_t num_bufs, 345 mm_camera_app_buf_t* app_bufs) 346 { 347 int i, rc = MM_CAMERA_OK; 348 349 LOGD("E"); 350 351 for (i = 0; i < num_bufs; i++) { 352 rc = mm_app_deallocate_ion_memory(&app_bufs[i]); 353 } 354 memset(app_bufs, 0, num_bufs * sizeof(mm_camera_app_buf_t)); 355 LOGD("X"); 356 return rc; 357 } 358 359 int mm_app_stream_initbuf(cam_frame_len_offset_t *frame_offset_info, 360 uint8_t *num_bufs, 361 uint8_t **initial_reg_flag, 362 mm_camera_buf_def_t **bufs, 363 mm_camera_map_unmap_ops_tbl_t *ops_tbl, 364 void *user_data) 365 { 366 mm_camera_stream_t *stream = (mm_camera_stream_t *)user_data; 367 mm_camera_buf_def_t *pBufs = NULL; 368 uint8_t *reg_flags = NULL; 369 int i, rc; 370 371 stream->offset = *frame_offset_info; 372 373 LOGD("alloc buf for stream_id %d, len=%d, num planes: %d, offset: %d", 374 stream->s_id, 375 frame_offset_info->frame_len, 376 frame_offset_info->num_planes, 377 frame_offset_info->mp[1].offset); 378 379 if (stream->num_of_bufs > CAM_MAX_NUM_BUFS_PER_STREAM) 380 stream->num_of_bufs = CAM_MAX_NUM_BUFS_PER_STREAM; 381 382 pBufs = (mm_camera_buf_def_t *)malloc(sizeof(mm_camera_buf_def_t) * stream->num_of_bufs); 383 reg_flags = (uint8_t *)malloc(sizeof(uint8_t) * stream->num_of_bufs); 384 if (pBufs == NULL || reg_flags == NULL) { 385 LOGE("No mem for bufs"); 386 if (pBufs != NULL) { 387 free(pBufs); 388 } 389 if (reg_flags != NULL) { 390 free(reg_flags); 391 } 392 return -1; 393 } 394 395 rc = mm_app_alloc_bufs(&stream->s_bufs[0], 396 frame_offset_info, 397 stream->num_of_bufs, 398 1, 399 stream->multipleOf); 400 401 if (rc != MM_CAMERA_OK) { 402 LOGE("mm_stream_alloc_bufs err = %d", rc); 403 free(pBufs); 404 free(reg_flags); 405 return rc; 406 } 407 408 for (i = 0; i < stream->num_of_bufs; i++) { 409 /* mapping stream bufs first */ 410 pBufs[i] = stream->s_bufs[i].buf; 411 reg_flags[i] = 1; 412 rc = ops_tbl->map_ops(pBufs[i].buf_idx, 413 -1, 414 pBufs[i].fd, 415 (uint32_t)pBufs[i].frame_len, 416 pBufs[i].buffer, 417 CAM_MAPPING_BUF_TYPE_STREAM_BUF, ops_tbl->userdata); 418 if (rc != MM_CAMERA_OK) { 419 LOGE("mapping buf[%d] err = %d", i, rc); 420 break; 421 } 422 } 423 424 if (rc != MM_CAMERA_OK) { 425 int j; 426 for (j=0; j>i; j++) { 427 ops_tbl->unmap_ops(pBufs[j].buf_idx, -1, 428 CAM_MAPPING_BUF_TYPE_STREAM_BUF, ops_tbl->userdata); 429 } 430 mm_app_release_bufs(stream->num_of_bufs, &stream->s_bufs[0]); 431 free(pBufs); 432 free(reg_flags); 433 return rc; 434 } 435 436 *num_bufs = stream->num_of_bufs; 437 *bufs = pBufs; 438 *initial_reg_flag = reg_flags; 439 440 LOGD("X"); 441 return rc; 442 } 443 444 int32_t mm_app_stream_deinitbuf(mm_camera_map_unmap_ops_tbl_t *ops_tbl, 445 void *user_data) 446 { 447 mm_camera_stream_t *stream = (mm_camera_stream_t *)user_data; 448 int i; 449 450 for (i = 0; i < stream->num_of_bufs ; i++) { 451 /* mapping stream bufs first */ 452 ops_tbl->unmap_ops(stream->s_bufs[i].buf.buf_idx, -1, 453 CAM_MAPPING_BUF_TYPE_STREAM_BUF, ops_tbl->userdata); 454 } 455 456 mm_app_release_bufs(stream->num_of_bufs, &stream->s_bufs[0]); 457 458 LOGD("X"); 459 return 0; 460 } 461 462 int32_t mm_app_stream_clean_invalidate_buf(uint32_t index, void *user_data) 463 { 464 mm_camera_stream_t *stream = (mm_camera_stream_t *)user_data; 465 return mm_app_cache_ops(&stream->s_bufs[index].mem_info, 466 ION_IOC_CLEAN_INV_CACHES); 467 } 468 469 int32_t mm_app_stream_invalidate_buf(uint32_t index, void *user_data) 470 { 471 mm_camera_stream_t *stream = (mm_camera_stream_t *)user_data; 472 return mm_app_cache_ops(&stream->s_bufs[index].mem_info, ION_IOC_INV_CACHES); 473 } 474 475 int32_t mm_app_stream_clean_buf(uint32_t index, void *user_data) 476 { 477 mm_camera_stream_t *stream = (mm_camera_stream_t *)user_data; 478 return mm_app_cache_ops(&stream->s_bufs[index].mem_info, ION_IOC_CLEAN_CACHES); 479 } 480 481 static void notify_evt_cb(uint32_t camera_handle, 482 mm_camera_event_t *evt, 483 void *user_data) 484 { 485 mm_camera_test_obj_t *test_obj = 486 (mm_camera_test_obj_t *)user_data; 487 if (test_obj == NULL || test_obj->cam->camera_handle != camera_handle) { 488 LOGE("Not a valid test obj"); 489 return; 490 } 491 492 LOGD("E evt = %d", evt->server_event_type); 493 switch (evt->server_event_type) { 494 case CAM_EVENT_TYPE_AUTO_FOCUS_DONE: 495 LOGD("rcvd auto focus done evt"); 496 break; 497 case CAM_EVENT_TYPE_ZOOM_DONE: 498 LOGD("rcvd zoom done evt"); 499 break; 500 default: 501 break; 502 } 503 504 LOGD("X"); 505 } 506 507 int mm_app_open(mm_camera_app_t *cam_app, 508 int cam_id, 509 mm_camera_test_obj_t *test_obj) 510 { 511 int32_t rc = 0; 512 cam_frame_len_offset_t offset_info; 513 514 LOGD("BEGIN\n"); 515 516 rc = cam_app->hal_lib.mm_camera_open((uint8_t)cam_id, &(test_obj->cam)); 517 if(rc || !test_obj->cam) { 518 LOGE("dev open error. rc = %d, vtbl = %p\n", rc, test_obj->cam); 519 return -MM_CAMERA_E_GENERAL; 520 } 521 522 LOGD("Open Camera id = %d handle = %d", cam_id, test_obj->cam->camera_handle); 523 524 /* alloc ion mem for capability buf */ 525 memset(&offset_info, 0, sizeof(offset_info)); 526 offset_info.frame_len = sizeof(cam_capability_t); 527 528 rc = mm_app_alloc_bufs(&test_obj->cap_buf, 529 &offset_info, 530 1, 531 0, 532 0); 533 if (rc != MM_CAMERA_OK) { 534 LOGE("alloc buf for capability error\n"); 535 goto error_after_cam_open; 536 } 537 538 /* mapping capability buf */ 539 rc = test_obj->cam->ops->map_buf(test_obj->cam->camera_handle, 540 CAM_MAPPING_BUF_TYPE_CAPABILITY, 541 test_obj->cap_buf.mem_info.fd, 542 test_obj->cap_buf.mem_info.size, 543 test_obj->cap_buf.buf.buffer); 544 if (rc != MM_CAMERA_OK) { 545 LOGE("map for capability error\n"); 546 goto error_after_cap_buf_alloc; 547 } 548 549 /* alloc ion mem for getparm buf */ 550 memset(&offset_info, 0, sizeof(offset_info)); 551 offset_info.frame_len = sizeof(parm_buffer_t); 552 rc = mm_app_alloc_bufs(&test_obj->parm_buf, 553 &offset_info, 554 1, 555 0, 556 0); 557 if (rc != MM_CAMERA_OK) { 558 LOGE("alloc buf for getparm_buf error\n"); 559 goto error_after_cap_buf_map; 560 } 561 562 /* mapping getparm buf */ 563 rc = test_obj->cam->ops->map_buf(test_obj->cam->camera_handle, 564 CAM_MAPPING_BUF_TYPE_PARM_BUF, 565 test_obj->parm_buf.mem_info.fd, 566 test_obj->parm_buf.mem_info.size, 567 test_obj->parm_buf.buf.buffer); 568 if (rc != MM_CAMERA_OK) { 569 LOGE("map getparm_buf error\n"); 570 goto error_after_getparm_buf_alloc; 571 } 572 test_obj->params_buffer = (parm_buffer_t*) test_obj->parm_buf.mem_info.data; 573 LOGH("\n%s params_buffer=%p\n",test_obj->params_buffer); 574 575 rc = test_obj->cam->ops->register_event_notify(test_obj->cam->camera_handle, 576 notify_evt_cb, 577 test_obj); 578 if (rc != MM_CAMERA_OK) { 579 LOGE("failed register_event_notify"); 580 rc = -MM_CAMERA_E_GENERAL; 581 goto error_after_getparm_buf_map; 582 } 583 584 rc = test_obj->cam->ops->query_capability(test_obj->cam->camera_handle); 585 if (rc != MM_CAMERA_OK) { 586 LOGE("failed query_capability"); 587 rc = -MM_CAMERA_E_GENERAL; 588 goto error_after_getparm_buf_map; 589 } 590 memset(&test_obj->jpeg_ops, 0, sizeof(mm_jpeg_ops_t)); 591 test_obj->mExifParams.debug_params = \ 592 (mm_jpeg_debug_exif_params_t *) malloc (sizeof(mm_jpeg_debug_exif_params_t)); 593 if (test_obj->mExifParams.debug_params != NULL) { 594 memset(test_obj->mExifParams.debug_params, 0, 595 sizeof(mm_jpeg_debug_exif_params_t)); 596 } else { 597 LOGE("debug params alloc fail"); 598 rc = -MM_CAMERA_E_GENERAL; 599 goto error_after_getparm_buf_map; 600 } 601 mm_dimension pic_size; 602 memset(&pic_size, 0, sizeof(mm_dimension)); 603 pic_size.w = 4000; 604 pic_size.h = 3000; 605 test_obj->jpeg_hdl = cam_app->hal_lib.jpeg_open(&test_obj->jpeg_ops, NULL, pic_size, NULL); 606 if (test_obj->jpeg_hdl == 0) { 607 LOGE("jpeg lib open err"); 608 rc = -MM_CAMERA_E_GENERAL; 609 goto error_after_getparm_buf_map; 610 } 611 612 return rc; 613 614 error_after_getparm_buf_map: 615 test_obj->cam->ops->unmap_buf(test_obj->cam->camera_handle, 616 CAM_MAPPING_BUF_TYPE_PARM_BUF); 617 error_after_getparm_buf_alloc: 618 mm_app_release_bufs(1, &test_obj->parm_buf); 619 error_after_cap_buf_map: 620 test_obj->cam->ops->unmap_buf(test_obj->cam->camera_handle, 621 CAM_MAPPING_BUF_TYPE_CAPABILITY); 622 error_after_cap_buf_alloc: 623 mm_app_release_bufs(1, &test_obj->cap_buf); 624 error_after_cam_open: 625 test_obj->cam->ops->close_camera(test_obj->cam->camera_handle); 626 test_obj->cam = NULL; 627 return rc; 628 } 629 630 int init_batch_update(parm_buffer_t *p_table) 631 { 632 int rc = MM_CAMERA_OK; 633 LOGH("\nEnter %s\n"); 634 int32_t hal_version = CAM_HAL_V1; 635 636 memset(p_table, 0, sizeof(parm_buffer_t)); 637 if(ADD_SET_PARAM_ENTRY_TO_BATCH(p_table, CAM_INTF_PARM_HAL_VERSION, hal_version)) { 638 rc = -1; 639 } 640 641 return rc; 642 } 643 644 int commit_set_batch(mm_camera_test_obj_t *test_obj) 645 { 646 int rc = MM_CAMERA_OK; 647 int i = 0; 648 649 for(i = 0; i < CAM_INTF_PARM_MAX; i++){ 650 if(test_obj->params_buffer->is_valid[i]) 651 break; 652 } 653 if (i < CAM_INTF_PARM_MAX) { 654 LOGH("\n set_param p_buffer =%p\n",test_obj->params_buffer); 655 rc = test_obj->cam->ops->set_parms(test_obj->cam->camera_handle, test_obj->params_buffer); 656 } 657 if (rc != MM_CAMERA_OK) { 658 LOGE("cam->ops->set_parms failed !!"); 659 } 660 return rc; 661 } 662 663 int mm_app_close(mm_camera_test_obj_t *test_obj) 664 { 665 int32_t rc = MM_CAMERA_OK; 666 667 if (test_obj == NULL || test_obj->cam ==NULL) { 668 LOGE("cam not opened"); 669 return -MM_CAMERA_E_GENERAL; 670 } 671 672 /* unmap capability buf */ 673 rc = test_obj->cam->ops->unmap_buf(test_obj->cam->camera_handle, 674 CAM_MAPPING_BUF_TYPE_CAPABILITY); 675 if (rc != MM_CAMERA_OK) { 676 LOGE("unmap capability buf failed, rc=%d", rc); 677 } 678 679 /* unmap parm buf */ 680 rc = test_obj->cam->ops->unmap_buf(test_obj->cam->camera_handle, 681 CAM_MAPPING_BUF_TYPE_PARM_BUF); 682 if (rc != MM_CAMERA_OK) { 683 LOGE("unmap setparm buf failed, rc=%d", rc); 684 } 685 686 rc = test_obj->cam->ops->close_camera(test_obj->cam->camera_handle); 687 if (rc != MM_CAMERA_OK) { 688 LOGE("close camera failed, rc=%d", rc); 689 } 690 test_obj->cam = NULL; 691 692 /* close jpeg client */ 693 if (test_obj->jpeg_hdl && test_obj->jpeg_ops.close) { 694 rc = test_obj->jpeg_ops.close(test_obj->jpeg_hdl); 695 test_obj->jpeg_hdl = 0; 696 if (rc != MM_CAMERA_OK) { 697 LOGE("close jpeg failed, rc=%d", rc); 698 } 699 } 700 701 /* dealloc capability buf */ 702 rc = mm_app_release_bufs(1, &test_obj->cap_buf); 703 if (rc != MM_CAMERA_OK) { 704 LOGE("release capability buf failed, rc=%d", rc); 705 } 706 707 /* dealloc parm buf */ 708 rc = mm_app_release_bufs(1, &test_obj->parm_buf); 709 if (rc != MM_CAMERA_OK) { 710 LOGE("release setparm buf failed, rc=%d", rc); 711 } 712 713 if (test_obj->mExifParams.debug_params) { 714 free(test_obj->mExifParams.debug_params); 715 test_obj->mExifParams.debug_params = NULL; 716 } 717 718 return MM_CAMERA_OK; 719 } 720 721 mm_camera_channel_t * mm_app_add_channel(mm_camera_test_obj_t *test_obj, 722 mm_camera_channel_type_t ch_type, 723 mm_camera_channel_attr_t *attr, 724 mm_camera_buf_notify_t channel_cb, 725 void *userdata) 726 { 727 uint32_t ch_id = 0; 728 mm_camera_channel_t *channel = NULL; 729 730 ch_id = test_obj->cam->ops->add_channel(test_obj->cam->camera_handle, 731 attr, 732 channel_cb, 733 userdata); 734 if (ch_id == 0) { 735 LOGE("add channel failed"); 736 return NULL; 737 } 738 channel = &test_obj->channels[ch_type]; 739 channel->ch_id = ch_id; 740 return channel; 741 } 742 743 int mm_app_del_channel(mm_camera_test_obj_t *test_obj, 744 mm_camera_channel_t *channel) 745 { 746 test_obj->cam->ops->delete_channel(test_obj->cam->camera_handle, 747 channel->ch_id); 748 memset(channel, 0, sizeof(mm_camera_channel_t)); 749 return MM_CAMERA_OK; 750 } 751 752 mm_camera_stream_t * mm_app_add_stream(mm_camera_test_obj_t *test_obj, 753 mm_camera_channel_t *channel) 754 { 755 mm_camera_stream_t *stream = NULL; 756 int rc = MM_CAMERA_OK; 757 cam_frame_len_offset_t offset_info; 758 759 stream = &(channel->streams[channel->num_streams++]); 760 stream->s_id = test_obj->cam->ops->add_stream(test_obj->cam->camera_handle, 761 channel->ch_id); 762 if (stream->s_id == 0) { 763 LOGE("add stream failed"); 764 return NULL; 765 } 766 767 stream->multipleOf = test_obj->slice_size; 768 769 /* alloc ion mem for stream_info buf */ 770 memset(&offset_info, 0, sizeof(offset_info)); 771 offset_info.frame_len = sizeof(cam_stream_info_t); 772 773 rc = mm_app_alloc_bufs(&stream->s_info_buf, 774 &offset_info, 775 1, 776 0, 777 0); 778 if (rc != MM_CAMERA_OK) { 779 LOGE("alloc buf for stream_info error\n"); 780 test_obj->cam->ops->delete_stream(test_obj->cam->camera_handle, 781 channel->ch_id, 782 stream->s_id); 783 stream->s_id = 0; 784 return NULL; 785 } 786 787 /* mapping streaminfo buf */ 788 rc = test_obj->cam->ops->map_stream_buf(test_obj->cam->camera_handle, 789 channel->ch_id, 790 stream->s_id, 791 CAM_MAPPING_BUF_TYPE_STREAM_INFO, 792 0, 793 -1, 794 stream->s_info_buf.mem_info.fd, 795 (uint32_t)stream->s_info_buf.mem_info.size, stream->s_info_buf.buf.buffer); 796 if (rc != MM_CAMERA_OK) { 797 LOGE("map setparm_buf error\n"); 798 mm_app_deallocate_ion_memory(&stream->s_info_buf); 799 test_obj->cam->ops->delete_stream(test_obj->cam->camera_handle, 800 channel->ch_id, 801 stream->s_id); 802 stream->s_id = 0; 803 return NULL; 804 } 805 806 return stream; 807 } 808 809 int mm_app_del_stream(mm_camera_test_obj_t *test_obj, 810 mm_camera_channel_t *channel, 811 mm_camera_stream_t *stream) 812 { 813 test_obj->cam->ops->unmap_stream_buf(test_obj->cam->camera_handle, 814 channel->ch_id, 815 stream->s_id, 816 CAM_MAPPING_BUF_TYPE_STREAM_INFO, 817 0, 818 -1); 819 mm_app_deallocate_ion_memory(&stream->s_info_buf); 820 test_obj->cam->ops->delete_stream(test_obj->cam->camera_handle, 821 channel->ch_id, 822 stream->s_id); 823 memset(stream, 0, sizeof(mm_camera_stream_t)); 824 return MM_CAMERA_OK; 825 } 826 827 mm_camera_channel_t *mm_app_get_channel_by_type(mm_camera_test_obj_t *test_obj, 828 mm_camera_channel_type_t ch_type) 829 { 830 return &test_obj->channels[ch_type]; 831 } 832 833 int mm_app_config_stream(mm_camera_test_obj_t *test_obj, 834 mm_camera_channel_t *channel, 835 mm_camera_stream_t *stream, 836 mm_camera_stream_config_t *config) 837 { 838 return test_obj->cam->ops->config_stream(test_obj->cam->camera_handle, 839 channel->ch_id, 840 stream->s_id, 841 config); 842 } 843 844 int mm_app_start_channel(mm_camera_test_obj_t *test_obj, 845 mm_camera_channel_t *channel) 846 { 847 return test_obj->cam->ops->start_channel(test_obj->cam->camera_handle, 848 channel->ch_id, 849 /*start_sensor_streaming*/true); 850 } 851 852 int mm_app_stop_channel(mm_camera_test_obj_t *test_obj, 853 mm_camera_channel_t *channel) 854 { 855 return test_obj->cam->ops->stop_channel(test_obj->cam->camera_handle, 856 channel->ch_id, /*stop_immediately*/false); 857 } 858 859 int initBatchUpdate(mm_camera_test_obj_t *test_obj) 860 { 861 int32_t hal_version = CAM_HAL_V1; 862 863 parm_buffer_t *parm_buf = ( parm_buffer_t * ) test_obj->parm_buf.mem_info.data; 864 memset(parm_buf, 0, sizeof(parm_buffer_t)); 865 ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 866 CAM_INTF_PARM_HAL_VERSION, hal_version); 867 868 return MM_CAMERA_OK; 869 } 870 871 int commitSetBatch(mm_camera_test_obj_t *test_obj) 872 { 873 int rc = MM_CAMERA_OK; 874 int i = 0; 875 876 parm_buffer_t *p_table = ( parm_buffer_t * ) test_obj->parm_buf.mem_info.data; 877 for(i = 0; i < CAM_INTF_PARM_MAX; i++){ 878 if(p_table->is_valid[i]) 879 break; 880 } 881 if (i < CAM_INTF_PARM_MAX) { 882 rc = test_obj->cam->ops->set_parms(test_obj->cam->camera_handle, p_table); 883 } 884 return rc; 885 } 886 887 888 int commitGetBatch(mm_camera_test_obj_t *test_obj) 889 { 890 int rc = MM_CAMERA_OK; 891 int i = 0; 892 parm_buffer_t *p_table = ( parm_buffer_t * ) test_obj->parm_buf.mem_info.data; 893 for(i = 0; i < CAM_INTF_PARM_MAX; i++){ 894 if(p_table->is_valid[i]) 895 break; 896 } 897 if (i < CAM_INTF_PARM_MAX) { 898 rc = test_obj->cam->ops->get_parms(test_obj->cam->camera_handle, p_table); 899 } 900 return rc; 901 } 902 903 int setAecLock(mm_camera_test_obj_t *test_obj, int value) 904 { 905 int rc = MM_CAMERA_OK; 906 907 rc = initBatchUpdate(test_obj); 908 if (rc != MM_CAMERA_OK) { 909 LOGE("Batch camera parameter update failed\n"); 910 goto ERROR; 911 } 912 913 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 914 CAM_INTF_PARM_AEC_LOCK, (uint32_t)value)) { 915 LOGE("AEC Lock parameter not added to batch\n"); 916 rc = -1; 917 goto ERROR; 918 } 919 920 rc = commitSetBatch(test_obj); 921 if (rc != MM_CAMERA_OK) { 922 LOGE("Batch parameters commit failed\n"); 923 goto ERROR; 924 } 925 926 ERROR: 927 return rc; 928 } 929 930 int setAwbLock(mm_camera_test_obj_t *test_obj, int value) 931 { 932 int rc = MM_CAMERA_OK; 933 934 rc = initBatchUpdate(test_obj); 935 if (rc != MM_CAMERA_OK) { 936 LOGE("Batch camera parameter update failed\n"); 937 goto ERROR; 938 } 939 940 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 941 CAM_INTF_PARM_AWB_LOCK, (uint32_t)value)) { 942 LOGE("AWB Lock parameter not added to batch\n"); 943 rc = -1; 944 goto ERROR; 945 } 946 947 rc = commitSetBatch(test_obj); 948 if (rc != MM_CAMERA_OK) { 949 LOGE("Batch parameters commit failed\n"); 950 goto ERROR; 951 } 952 953 ERROR: 954 return rc; 955 } 956 957 958 int set3Acommand(mm_camera_test_obj_t *test_obj, cam_eztune_cmd_data_t *value) 959 { 960 int rc = MM_CAMERA_OK; 961 962 rc = initBatchUpdate(test_obj); 963 if (rc != MM_CAMERA_OK) { 964 LOGE("Batch camera parameter update failed\n"); 965 goto ERROR; 966 } 967 968 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 969 CAM_INTF_PARM_EZTUNE_CMD, *value)) { 970 LOGE("CAM_INTF_PARM_EZTUNE_CMD parameter not added to batch\n"); 971 rc = -1; 972 goto ERROR; 973 } 974 975 rc = commitSetBatch(test_obj); 976 if (rc != MM_CAMERA_OK) { 977 LOGE("Batch parameters commit failed\n"); 978 goto ERROR; 979 } 980 981 ERROR: 982 return rc; 983 } 984 985 int setAutoFocusTuning(mm_camera_test_obj_t *test_obj, tune_actuator_t *value) 986 { 987 int rc = MM_CAMERA_OK; 988 989 rc = initBatchUpdate(test_obj); 990 if (rc != MM_CAMERA_OK) { 991 LOGE("Batch camera parameter update failed\n"); 992 goto ERROR; 993 } 994 995 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 996 CAM_INTF_PARM_SET_AUTOFOCUSTUNING, *value)) { 997 LOGE("AutoFocus Tuning not added to batch\n"); 998 rc = -1; 999 goto ERROR; 1000 } 1001 1002 rc = commitSetBatch(test_obj); 1003 if (rc != MM_CAMERA_OK) { 1004 LOGE("Batch parameters commit failed\n"); 1005 goto ERROR; 1006 } 1007 1008 ERROR: 1009 return rc; 1010 } 1011 1012 int setVfeCommand(mm_camera_test_obj_t *test_obj, tune_cmd_t *value) 1013 { 1014 int rc = MM_CAMERA_OK; 1015 1016 rc = initBatchUpdate(test_obj); 1017 if (rc != MM_CAMERA_OK) { 1018 LOGE("Batch camera parameter update failed\n"); 1019 goto ERROR; 1020 } 1021 1022 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1023 CAM_INTF_PARM_SET_VFE_COMMAND, *value)) { 1024 LOGE("VFE Command not added to batch\n"); 1025 rc = -1; 1026 goto ERROR; 1027 } 1028 1029 rc = commitSetBatch(test_obj); 1030 if (rc != MM_CAMERA_OK) { 1031 LOGE("Batch parameters commit failed\n"); 1032 goto ERROR; 1033 } 1034 1035 ERROR: 1036 return rc; 1037 } 1038 1039 int setmetainfoCommand(mm_camera_test_obj_t *test_obj, cam_stream_size_info_t *value) 1040 { 1041 int rc = MM_CAMERA_OK; 1042 1043 rc = initBatchUpdate(test_obj); 1044 if (rc != MM_CAMERA_OK) { 1045 LOGE("Batch camera parameter update failed\n"); 1046 goto ERROR; 1047 } 1048 1049 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1050 CAM_INTF_META_STREAM_INFO, *value)) { 1051 LOGE("PP Command not added to batch\n"); 1052 rc = -1; 1053 goto ERROR; 1054 } 1055 1056 rc = commitSetBatch(test_obj); 1057 if (rc != MM_CAMERA_OK) { 1058 LOGE("Batch parameters commit failed\n"); 1059 goto ERROR; 1060 } 1061 1062 ERROR: 1063 return rc; 1064 } 1065 1066 1067 int setPPCommand(mm_camera_test_obj_t *test_obj, tune_cmd_t *value) 1068 { 1069 int rc = MM_CAMERA_OK; 1070 1071 rc = initBatchUpdate(test_obj); 1072 if (rc != MM_CAMERA_OK) { 1073 LOGE("Batch camera parameter update failed\n"); 1074 goto ERROR; 1075 } 1076 1077 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1078 CAM_INTF_PARM_SET_PP_COMMAND, *value)) { 1079 LOGE("PP Command not added to batch\n"); 1080 rc = -1; 1081 goto ERROR; 1082 } 1083 1084 rc = commitSetBatch(test_obj); 1085 if (rc != MM_CAMERA_OK) { 1086 LOGE("Batch parameters commit failed\n"); 1087 goto ERROR; 1088 } 1089 1090 ERROR: 1091 return rc; 1092 } 1093 1094 int setFocusMode(mm_camera_test_obj_t *test_obj, cam_focus_mode_type mode) 1095 { 1096 int rc = MM_CAMERA_OK; 1097 1098 rc = initBatchUpdate(test_obj); 1099 if (rc != MM_CAMERA_OK) { 1100 LOGE("Batch camera parameter update failed\n"); 1101 goto ERROR; 1102 } 1103 1104 uint32_t value = mode; 1105 1106 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1107 CAM_INTF_PARM_FOCUS_MODE, value)) { 1108 LOGE("Focus mode parameter not added to batch\n"); 1109 rc = -1; 1110 goto ERROR; 1111 } 1112 1113 rc = commitSetBatch(test_obj); 1114 if (rc != MM_CAMERA_OK) { 1115 LOGE("Batch parameters commit failed\n"); 1116 goto ERROR; 1117 } 1118 1119 ERROR: 1120 return rc; 1121 } 1122 1123 int updateDebuglevel(mm_camera_test_obj_t *test_obj) 1124 { 1125 1126 int rc = MM_CAMERA_OK; 1127 1128 rc = initBatchUpdate(test_obj); 1129 if ( rc != MM_CAMERA_OK ) { 1130 LOGE("Failed to initialize group update table"); 1131 return rc; 1132 } 1133 1134 uint32_t dummyDebugLevel = 0; 1135 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, CAM_INTF_PARM_UPDATE_DEBUG_LEVEL, dummyDebugLevel)) { 1136 LOGE("Parameters batch failed"); 1137 rc = -1; 1138 goto ERROR; 1139 } 1140 1141 rc = commitSetBatch(test_obj); 1142 if ( rc != MM_CAMERA_OK ) { 1143 LOGE("Failed to commit batch parameters"); 1144 return rc; 1145 } 1146 ERROR: 1147 return rc; 1148 } 1149 1150 int setEVCompensation(mm_camera_test_obj_t *test_obj, int ev) 1151 { 1152 int rc = MM_CAMERA_OK; 1153 1154 cam_capability_t *camera_cap = NULL; 1155 1156 camera_cap = (cam_capability_t *) test_obj->cap_buf.mem_info.data; 1157 if ( (ev >= camera_cap->exposure_compensation_min) && 1158 (ev <= camera_cap->exposure_compensation_max) ) { 1159 1160 rc = initBatchUpdate(test_obj); 1161 if (rc != MM_CAMERA_OK) { 1162 LOGE("Batch camera parameter update failed\n"); 1163 goto ERROR; 1164 } 1165 1166 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1167 CAM_INTF_PARM_EXPOSURE_COMPENSATION, ev)) { 1168 LOGE("EV compensation parameter not added to batch\n"); 1169 rc = -1; 1170 goto ERROR; 1171 } 1172 1173 rc = commitSetBatch(test_obj); 1174 if (rc != MM_CAMERA_OK) { 1175 LOGE("Batch parameters commit failed\n"); 1176 goto ERROR; 1177 } 1178 1179 LOGE("EV compensation set to: %d", ev); 1180 } else { 1181 LOGE("Invalid EV compensation"); 1182 return -EINVAL; 1183 } 1184 1185 ERROR: 1186 return rc; 1187 } 1188 1189 int setAntibanding(mm_camera_test_obj_t *test_obj, cam_antibanding_mode_type antibanding) 1190 { 1191 int rc = MM_CAMERA_OK; 1192 1193 rc = initBatchUpdate(test_obj); 1194 if (rc != MM_CAMERA_OK) { 1195 LOGE("Batch camera parameter update failed\n"); 1196 goto ERROR; 1197 } 1198 1199 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1200 CAM_INTF_PARM_ANTIBANDING, antibanding)) { 1201 LOGE("Antibanding parameter not added to batch\n"); 1202 rc = -1; 1203 goto ERROR; 1204 } 1205 1206 rc = commitSetBatch(test_obj); 1207 if (rc != MM_CAMERA_OK) { 1208 LOGE("Batch parameters commit failed\n"); 1209 goto ERROR; 1210 } 1211 1212 LOGE("Antibanding set to: %d", (int)antibanding); 1213 1214 ERROR: 1215 return rc; 1216 } 1217 int setFlipMode(mm_camera_test_obj_t *test_obj, cam_flip_t mode) 1218 { 1219 int rc = MM_CAMERA_OK; 1220 uint32_t i = 0; 1221 mm_camera_channel_t *channel = NULL; 1222 mm_camera_stream_t *snapshot_stream = NULL; 1223 mm_camera_stream_t *preview_stream = NULL; 1224 cam_stream_parm_buffer_t param; 1225 cam_stream_parm_buffer_t param2; 1226 1227 test_obj->flip_mode = mode; 1228 1229 memset(¶m, 0, sizeof(cam_stream_parm_buffer_t)); 1230 memset(¶m2, 0, sizeof(cam_stream_parm_buffer_t)); 1231 1232 if (test_obj->zsl_enabled) 1233 channel = &test_obj->channels[MM_CHANNEL_TYPE_ZSL]; 1234 else 1235 channel = &test_obj->channels[MM_CHANNEL_TYPE_PREVIEW]; 1236 1237 /* find snapshot stream */ 1238 for (i = 0; i < channel->num_streams; i++) { 1239 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_SNAPSHOT) { 1240 snapshot_stream = &channel->streams[i]; 1241 break; 1242 } 1243 } 1244 1245 /* find preview stream */ 1246 for (i = 0; i < channel->num_streams; i++) { 1247 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_PREVIEW) { 1248 preview_stream = &channel->streams[i]; 1249 break; 1250 } 1251 } 1252 1253 param.type = CAM_STREAM_PARAM_TYPE_SET_FLIP; 1254 param.flipInfo.flip_mask = mode; 1255 param2.type = CAM_STREAM_PARAM_TYPE_SET_FLIP; 1256 param2.flipInfo.flip_mask = mode; 1257 1258 if (preview_stream != NULL) { 1259 preview_stream->s_config.stream_info->parm_buf = param; 1260 rc = test_obj->cam->ops->set_stream_parms(test_obj->cam->camera_handle, 1261 channel->ch_id, 1262 preview_stream->s_id, 1263 &preview_stream->s_config.stream_info->parm_buf ); 1264 } 1265 1266 if (snapshot_stream != NULL){ 1267 snapshot_stream->s_config.stream_info->parm_buf = param2; 1268 rc = test_obj->cam->ops->set_stream_parms(test_obj->cam->camera_handle, 1269 channel->ch_id, 1270 snapshot_stream->s_id, 1271 &snapshot_stream->s_config.stream_info->parm_buf ); 1272 } 1273 1274 if (rc != MM_CAMERA_OK) { 1275 LOGE("Batch parameters commit failed\n"); 1276 goto ERROR; 1277 } 1278 1279 LOGE("Flip Mode set to: %d", (int)mode); 1280 1281 ERROR: 1282 return rc; 1283 } 1284 1285 int setManualWhiteBalance(mm_camera_test_obj_t *test_obj, cam_manual_wb_parm_t *manual_info){ 1286 1287 int rc = MM_CAMERA_OK; 1288 cam_manual_wb_parm_t param; 1289 1290 rc = initBatchUpdate(test_obj); 1291 if (rc != MM_CAMERA_OK) { 1292 LOGE("Batch camera parameter update failed\n"); 1293 goto ERROR; 1294 } 1295 1296 memset(¶m, 0, sizeof(cam_manual_wb_parm_t)); 1297 if (manual_info->type == CAM_MANUAL_WB_MODE_GAIN){ 1298 param.type = CAM_MANUAL_WB_MODE_GAIN; 1299 param.gains.r_gain = manual_info->gains.r_gain; 1300 param.gains.g_gain = manual_info->gains.g_gain; 1301 param.gains.b_gain = manual_info->gains.b_gain; 1302 }else { 1303 param.type = CAM_MANUAL_WB_MODE_CCT; 1304 param.cct = manual_info->cct; 1305 } 1306 1307 1308 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1309 CAM_INTF_PARM_WB_MANUAL, param)) { 1310 LOGE("Manual White balance parameter not added to batch\n"); 1311 rc = -1; 1312 goto ERROR; 1313 } 1314 1315 rc = commitSetBatch(test_obj); 1316 if (rc != MM_CAMERA_OK) { 1317 LOGE("Batch parameters commit failed\n"); 1318 goto ERROR; 1319 } 1320 1321 ERROR: 1322 return rc; 1323 } 1324 int setWhiteBalance(mm_camera_test_obj_t *test_obj, cam_wb_mode_type mode) 1325 { 1326 int rc = MM_CAMERA_OK; 1327 1328 rc = initBatchUpdate(test_obj); 1329 if (rc != MM_CAMERA_OK) { 1330 LOGE("Batch camera parameter update failed\n"); 1331 goto ERROR; 1332 } 1333 1334 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1335 CAM_INTF_PARM_WHITE_BALANCE, mode)) { 1336 LOGE("White balance parameter not added to batch\n"); 1337 rc = -1; 1338 goto ERROR; 1339 } 1340 1341 rc = commitSetBatch(test_obj); 1342 if (rc != MM_CAMERA_OK) { 1343 LOGE("Batch parameters commit failed\n"); 1344 goto ERROR; 1345 } 1346 1347 LOGE("White balance set to: %d", (int)mode); 1348 1349 ERROR: 1350 return rc; 1351 } 1352 1353 int setExposureMetering(mm_camera_test_obj_t *test_obj, cam_auto_exposure_mode_type mode) 1354 { 1355 int rc = MM_CAMERA_OK; 1356 1357 rc = initBatchUpdate(test_obj); 1358 if (rc != MM_CAMERA_OK) { 1359 LOGE("Batch camera parameter update failed\n"); 1360 goto ERROR; 1361 } 1362 1363 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1364 CAM_INTF_PARM_EXPOSURE, mode)) { 1365 LOGE("Exposure metering parameter not added to batch\n"); 1366 rc = -1; 1367 goto ERROR; 1368 } 1369 1370 rc = commitSetBatch(test_obj); 1371 if (rc != MM_CAMERA_OK) { 1372 LOGE("Batch parameters commit failed\n"); 1373 goto ERROR; 1374 } 1375 1376 LOGE("Exposure metering set to: %d", (int)mode); 1377 1378 ERROR: 1379 return rc; 1380 } 1381 1382 int setBrightness(mm_camera_test_obj_t *test_obj, int brightness) 1383 { 1384 int rc = MM_CAMERA_OK; 1385 1386 rc = initBatchUpdate(test_obj); 1387 if (rc != MM_CAMERA_OK) { 1388 LOGE("Batch camera parameter update failed\n"); 1389 goto ERROR; 1390 } 1391 1392 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1393 CAM_INTF_PARM_BRIGHTNESS, brightness)) { 1394 LOGE("Brightness parameter not added to batch\n"); 1395 rc = -1; 1396 goto ERROR; 1397 } 1398 1399 rc = commitSetBatch(test_obj); 1400 if (rc != MM_CAMERA_OK) { 1401 LOGE("Batch parameters commit failed\n"); 1402 goto ERROR; 1403 } 1404 1405 LOGE("Brightness set to: %d", brightness); 1406 1407 ERROR: 1408 return rc; 1409 } 1410 1411 int setContrast(mm_camera_test_obj_t *test_obj, int contrast) 1412 { 1413 int rc = MM_CAMERA_OK; 1414 1415 rc = initBatchUpdate(test_obj); 1416 if (rc != MM_CAMERA_OK) { 1417 LOGE("Batch camera parameter update failed\n"); 1418 goto ERROR; 1419 } 1420 1421 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1422 CAM_INTF_PARM_CONTRAST, contrast)) { 1423 LOGE("Contrast parameter not added to batch\n"); 1424 rc = -1; 1425 goto ERROR; 1426 } 1427 1428 rc = commitSetBatch(test_obj); 1429 if (rc != MM_CAMERA_OK) { 1430 LOGE("Batch parameters commit failed\n"); 1431 goto ERROR; 1432 } 1433 1434 LOGE("Contrast set to: %d", contrast); 1435 1436 ERROR: 1437 return rc; 1438 } 1439 1440 int setTintless(mm_camera_test_obj_t *test_obj, int tintless) 1441 { 1442 int rc = MM_CAMERA_OK; 1443 1444 rc = initBatchUpdate(test_obj); 1445 if (rc != MM_CAMERA_OK) { 1446 LOGE("Batch camera parameter update failed\n"); 1447 goto ERROR; 1448 } 1449 1450 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1451 CAM_INTF_PARM_TINTLESS, tintless)) { 1452 LOGE("Tintless parameter not added to batch\n"); 1453 rc = -1; 1454 goto ERROR; 1455 } 1456 1457 rc = commitSetBatch(test_obj); 1458 if (rc != MM_CAMERA_OK) { 1459 LOGE("Batch parameters commit failed\n"); 1460 goto ERROR; 1461 } 1462 1463 LOGE("set Tintless to: %d", tintless); 1464 1465 ERROR: 1466 return rc; 1467 } 1468 1469 int setSaturation(mm_camera_test_obj_t *test_obj, int saturation) 1470 { 1471 int rc = MM_CAMERA_OK; 1472 1473 rc = initBatchUpdate(test_obj); 1474 if (rc != MM_CAMERA_OK) { 1475 LOGE("Batch camera parameter update failed\n"); 1476 goto ERROR; 1477 } 1478 1479 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1480 CAM_INTF_PARM_SATURATION, saturation)) { 1481 LOGE("Saturation parameter not added to batch\n"); 1482 rc = -1; 1483 goto ERROR; 1484 } 1485 1486 rc = commitSetBatch(test_obj); 1487 if (rc != MM_CAMERA_OK) { 1488 LOGE("Batch parameters commit failed\n"); 1489 goto ERROR; 1490 } 1491 1492 LOGE("Saturation set to: %d", saturation); 1493 1494 ERROR: 1495 return rc; 1496 } 1497 1498 int setSharpness(mm_camera_test_obj_t *test_obj, int sharpness) 1499 { 1500 int rc = MM_CAMERA_OK; 1501 1502 rc = initBatchUpdate(test_obj); 1503 if (rc != MM_CAMERA_OK) { 1504 LOGE("Batch camera parameter update failed\n"); 1505 goto ERROR; 1506 } 1507 1508 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1509 CAM_INTF_PARM_SHARPNESS, sharpness)) { 1510 LOGE("Sharpness parameter not added to batch\n"); 1511 rc = -1; 1512 goto ERROR; 1513 } 1514 1515 rc = commitSetBatch(test_obj); 1516 if (rc != MM_CAMERA_OK) { 1517 LOGE("Batch parameters commit failed\n"); 1518 goto ERROR; 1519 } 1520 1521 test_obj->reproc_sharpness = sharpness; 1522 LOGE("Sharpness set to: %d", sharpness); 1523 1524 ERROR: 1525 return rc; 1526 } 1527 1528 int setISO(mm_camera_test_obj_t *test_obj, cam_iso_mode_type iso) 1529 { 1530 int rc = MM_CAMERA_OK; 1531 1532 rc = initBatchUpdate(test_obj); 1533 if (rc != MM_CAMERA_OK) { 1534 LOGE("Batch camera parameter update failed\n"); 1535 goto ERROR; 1536 } 1537 1538 cam_intf_parm_manual_3a_t iso_settings; 1539 memset(&iso_settings, 0, sizeof(cam_intf_parm_manual_3a_t)); 1540 iso_settings.previewOnly = FALSE; 1541 iso_settings.value = (uint64_t)iso; 1542 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1543 CAM_INTF_PARM_ISO, iso_settings)) { 1544 LOGE("ISO parameter not added to batch\n"); 1545 rc = -1; 1546 goto ERROR; 1547 } 1548 1549 rc = commitSetBatch(test_obj); 1550 if (rc != MM_CAMERA_OK) { 1551 LOGE("Batch parameters commit failed\n"); 1552 goto ERROR; 1553 } 1554 1555 LOGE("ISO set to: %d", (int)iso); 1556 1557 ERROR: 1558 return rc; 1559 } 1560 1561 int setZoom(mm_camera_test_obj_t *test_obj, int zoom) 1562 { 1563 int rc = MM_CAMERA_OK; 1564 1565 rc = initBatchUpdate(test_obj); 1566 if (rc != MM_CAMERA_OK) { 1567 LOGE("Batch camera parameter update failed\n"); 1568 goto ERROR; 1569 } 1570 1571 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1572 CAM_INTF_PARM_ZOOM, zoom)) { 1573 LOGE("Zoom parameter not added to batch\n"); 1574 rc = -1; 1575 goto ERROR; 1576 } 1577 1578 rc = commitSetBatch(test_obj); 1579 if (rc != MM_CAMERA_OK) { 1580 LOGE("Batch parameters commit failed\n"); 1581 goto ERROR; 1582 } 1583 1584 LOGE("Zoom set to: %d", zoom); 1585 1586 ERROR: 1587 return rc; 1588 } 1589 1590 int setFPSRange(mm_camera_test_obj_t *test_obj, cam_fps_range_t range) 1591 { 1592 int rc = MM_CAMERA_OK; 1593 1594 rc = initBatchUpdate(test_obj); 1595 if (rc != MM_CAMERA_OK) { 1596 LOGE("Batch camera parameter update failed\n"); 1597 goto ERROR; 1598 } 1599 1600 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1601 CAM_INTF_PARM_FPS_RANGE, range)) { 1602 LOGE("FPS range parameter not added to batch\n"); 1603 rc = -1; 1604 goto ERROR; 1605 } 1606 1607 rc = commitSetBatch(test_obj); 1608 if (rc != MM_CAMERA_OK) { 1609 LOGE("Batch parameters commit failed\n"); 1610 goto ERROR; 1611 } 1612 1613 LOGE("FPS Range set to: [%5.2f:%5.2f]", 1614 range.min_fps, 1615 range.max_fps); 1616 1617 ERROR: 1618 return rc; 1619 } 1620 1621 int setEffect(mm_camera_test_obj_t *test_obj, cam_effect_mode_type effect) 1622 { 1623 int rc = MM_CAMERA_OK; 1624 1625 rc = initBatchUpdate(test_obj); 1626 if (rc != MM_CAMERA_OK) { 1627 LOGE("Batch camera parameter update failed\n"); 1628 goto ERROR; 1629 } 1630 1631 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1632 CAM_INTF_PARM_EFFECT, effect)) { 1633 LOGE("Scene parameter not added to batch\n"); 1634 rc = -1; 1635 goto ERROR; 1636 } 1637 1638 rc = commitSetBatch(test_obj); 1639 if (rc != MM_CAMERA_OK) { 1640 LOGE("Batch parameters commit failed\n"); 1641 goto ERROR; 1642 } 1643 1644 LOGE("Scene set to: %d", (int)effect); 1645 1646 ERROR: 1647 return rc; 1648 } 1649 int setScene(mm_camera_test_obj_t *test_obj, cam_scene_mode_type scene) 1650 { 1651 int rc = MM_CAMERA_OK; 1652 1653 rc = initBatchUpdate(test_obj); 1654 if (rc != MM_CAMERA_OK) { 1655 LOGE("Batch camera parameter update failed\n"); 1656 goto ERROR; 1657 } 1658 1659 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1660 CAM_INTF_PARM_BESTSHOT_MODE, scene)) { 1661 LOGE("Scene parameter not added to batch\n"); 1662 rc = -1; 1663 goto ERROR; 1664 } 1665 1666 rc = commitSetBatch(test_obj); 1667 if (rc != MM_CAMERA_OK) { 1668 LOGE("Batch parameters commit failed\n"); 1669 goto ERROR; 1670 } 1671 1672 LOGE("Scene set to: %d", (int)scene); 1673 1674 ERROR: 1675 return rc; 1676 } 1677 1678 int setFlash(mm_camera_test_obj_t *test_obj, cam_flash_mode_t flash) 1679 { 1680 int rc = MM_CAMERA_OK; 1681 1682 rc = initBatchUpdate(test_obj); 1683 if (rc != MM_CAMERA_OK) { 1684 LOGE("Batch camera parameter update failed\n"); 1685 goto ERROR; 1686 } 1687 1688 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1689 CAM_INTF_PARM_LED_MODE, flash)) { 1690 LOGE("Flash parameter not added to batch\n"); 1691 rc = -1; 1692 goto ERROR; 1693 } 1694 1695 rc = commitSetBatch(test_obj); 1696 if (rc != MM_CAMERA_OK) { 1697 LOGE("Batch parameters commit failed\n"); 1698 goto ERROR; 1699 } 1700 1701 LOGE("Flash set to: %d", (int)flash); 1702 1703 ERROR: 1704 return rc; 1705 } 1706 1707 int setWNR(mm_camera_test_obj_t *test_obj, uint8_t enable) 1708 { 1709 int rc = MM_CAMERA_OK; 1710 1711 rc = initBatchUpdate(test_obj); 1712 if (rc != MM_CAMERA_OK) { 1713 LOGE("Batch camera parameter update failed\n"); 1714 goto ERROR; 1715 } 1716 1717 cam_denoise_param_t param; 1718 memset(¶m, 0, sizeof(cam_denoise_param_t)); 1719 param.denoise_enable = enable; 1720 param.process_plates = CAM_WAVELET_DENOISE_YCBCR_PLANE; 1721 1722 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1723 CAM_INTF_PARM_WAVELET_DENOISE, param)) { 1724 LOGE("WNR enabled parameter not added to batch\n"); 1725 rc = -1; 1726 goto ERROR; 1727 } 1728 1729 rc = commitSetBatch(test_obj); 1730 if (rc != MM_CAMERA_OK) { 1731 LOGE("Batch parameters commit failed\n"); 1732 goto ERROR; 1733 } 1734 1735 1736 test_obj->reproc_wnr = param; 1737 LOGE("WNR enabled: %d", enable); 1738 ERROR: 1739 return rc; 1740 } 1741 1742 1743 int setIRMode(mm_camera_test_obj_t *test_obj, cam_ir_mode_type_t ir_mode) 1744 { 1745 int rc = MM_CAMERA_OK; 1746 1747 rc = initBatchUpdate(test_obj); 1748 if (rc != MM_CAMERA_OK) { 1749 LOGE("Batch camera parameter update failed\n"); 1750 goto ERROR; 1751 } 1752 1753 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1754 CAM_INTF_META_IR_MODE, ir_mode)) { 1755 LOGE("Flash parameter not added to batch\n"); 1756 rc = -1; 1757 goto ERROR; 1758 } 1759 1760 rc = commitSetBatch(test_obj); 1761 if (rc != MM_CAMERA_OK) { 1762 LOGE("Batch parameters commit failed\n"); 1763 goto ERROR; 1764 } 1765 1766 LOGE("IR LED set to: %d", (int)ir_mode); 1767 1768 ERROR: 1769 return rc; 1770 } 1771 1772 int setsHDRMode(mm_camera_test_obj_t *test_obj, uint8_t shdr_mode) 1773 { 1774 int rc = MM_CAMERA_OK; 1775 cam_sensor_hdr_type_t vhdr_type = CAM_SENSOR_HDR_MAX; 1776 1777 rc = initBatchUpdate(test_obj); 1778 if (rc != MM_CAMERA_OK) { 1779 LOGE("Batch camera parameter update failed\n"); 1780 goto ERROR; 1781 } 1782 1783 if (shdr_mode) { 1784 vhdr_type = CAM_SENSOR_HDR_STAGGERED; 1785 } else { 1786 vhdr_type = CAM_SENSOR_HDR_OFF; 1787 } 1788 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 1789 CAM_INTF_PARM_SENSOR_HDR, vhdr_type)) { 1790 LOGE("Flash parameter not added to batch\n"); 1791 rc = -1; 1792 goto ERROR; 1793 } 1794 1795 rc = commitSetBatch(test_obj); 1796 if (rc != MM_CAMERA_OK) { 1797 LOGE("Batch parameters commit failed\n"); 1798 goto ERROR; 1799 } 1800 1801 LOGE("sHDR set to: %d", (int)shdr_mode); 1802 1803 ERROR: 1804 return rc; 1805 } 1806 1807 1808 1809 int setEZTune(mm_camera_test_obj_t *test_obj, uint8_t enable) 1810 { 1811 test_obj->enable_EZTune = enable; 1812 return 0; 1813 } 1814 /** tuneserver_capture 1815 * @lib_handle: the camera handle object 1816 * @dim: snapshot dimensions 1817 * 1818 * makes JPEG capture 1819 * 1820 * Return: >=0 on success, -1 on failure. 1821 **/ 1822 int tuneserver_capture(mm_camera_lib_handle *lib_handle, 1823 mm_camera_lib_snapshot_params *dim) 1824 { 1825 int rc = 0; 1826 1827 printf("Take jpeg snapshot\n"); 1828 if ( lib_handle->stream_running ) { 1829 1830 if ( lib_handle->test_obj.zsl_enabled) { 1831 if ( NULL != dim) { 1832 if ( ( lib_handle->test_obj.buffer_width != dim->width) || 1833 ( lib_handle->test_obj.buffer_height = dim->height ) ) { 1834 1835 lib_handle->test_obj.buffer_width = dim->width; 1836 lib_handle->test_obj.buffer_height = dim->height; 1837 1838 rc = mm_camera_lib_stop_stream(lib_handle); 1839 if (rc != MM_CAMERA_OK) { 1840 LOGE("mm_camera_lib_stop_stream() err=%d\n", 1841 rc); 1842 goto EXIT; 1843 } 1844 1845 rc = mm_camera_lib_start_stream(lib_handle); 1846 if (rc != MM_CAMERA_OK) { 1847 LOGE("mm_camera_lib_start_stream() err=%d\n", 1848 rc); 1849 goto EXIT; 1850 } 1851 } 1852 1853 } 1854 1855 lib_handle->test_obj.encodeJpeg = 1; 1856 1857 mm_camera_app_wait(); 1858 } else { 1859 // For standard 2D capture streaming has to be disabled first 1860 rc = mm_camera_lib_stop_stream(lib_handle); 1861 if (rc != MM_CAMERA_OK) { 1862 LOGE("mm_camera_lib_stop_stream() err=%d\n", 1863 rc); 1864 goto EXIT; 1865 } 1866 1867 if ( NULL != dim ) { 1868 lib_handle->test_obj.buffer_width = dim->width; 1869 lib_handle->test_obj.buffer_height = dim->height; 1870 } 1871 rc = mm_app_start_capture(&lib_handle->test_obj, 1); 1872 if (rc != MM_CAMERA_OK) { 1873 LOGE("mm_app_start_capture() err=%d\n", 1874 rc); 1875 goto EXIT; 1876 } 1877 1878 mm_camera_app_wait(); 1879 1880 rc = mm_app_stop_capture(&lib_handle->test_obj); 1881 if (rc != MM_CAMERA_OK) { 1882 LOGE("mm_app_stop_capture() err=%d\n", 1883 rc); 1884 goto EXIT; 1885 } 1886 1887 // Restart streaming after capture is done 1888 rc = mm_camera_lib_start_stream(lib_handle); 1889 if (rc != MM_CAMERA_OK) { 1890 LOGE("mm_camera_lib_start_stream() err=%d\n", 1891 rc); 1892 goto EXIT; 1893 } 1894 } 1895 } 1896 1897 EXIT: 1898 1899 return rc; 1900 } 1901 1902 int mm_app_start_regression_test(int run_tc) 1903 { 1904 int rc = MM_CAMERA_OK; 1905 mm_camera_app_t my_cam_app; 1906 1907 LOGD("\nCamera Test Application\n"); 1908 memset(&my_cam_app, 0, sizeof(mm_camera_app_t)); 1909 1910 rc = mm_app_load_hal(&my_cam_app); 1911 if (rc != MM_CAMERA_OK) { 1912 LOGE("mm_app_load_hal failed !!"); 1913 return rc; 1914 } 1915 1916 if(run_tc) { 1917 rc = mm_app_unit_test_entry(&my_cam_app); 1918 return rc; 1919 } 1920 #if 0 1921 if(run_dual_tc) { 1922 printf("\tRunning Dual camera test engine only\n"); 1923 rc = mm_app_dual_test_entry(&my_cam_app); 1924 printf("\t Dual camera engine. EXIT(%d)!!!\n", rc); 1925 exit(rc); 1926 } 1927 #endif 1928 return rc; 1929 } 1930 1931 int32_t mm_camera_load_tuninglibrary(mm_camera_tuning_lib_params_t *tuning_param) 1932 { 1933 void *(*tuning_open_lib)(void) = NULL; 1934 1935 LOGD("E"); 1936 tuning_param->lib_handle = dlopen("libmmcamera_tuning.so", RTLD_NOW); 1937 if (!tuning_param->lib_handle) { 1938 LOGE("Failed opening libmmcamera_tuning.so\n"); 1939 return -EINVAL; 1940 } 1941 1942 *(void **)&tuning_open_lib = dlsym(tuning_param->lib_handle, 1943 "open_tuning_lib"); 1944 if (!tuning_open_lib) { 1945 LOGE("Failed symbol libmmcamera_tuning.so\n"); 1946 return -EINVAL; 1947 } 1948 1949 if (tuning_param->func_tbl) { 1950 LOGE("already loaded tuninglib.."); 1951 return 0; 1952 } 1953 1954 tuning_param->func_tbl = (mm_camera_tune_func_t *)tuning_open_lib(); 1955 if (!tuning_param->func_tbl) { 1956 LOGE("Failed opening library func table ptr\n"); 1957 return -EINVAL; 1958 } 1959 1960 LOGD("X"); 1961 return 0; 1962 } 1963 1964 int mm_camera_lib_open(mm_camera_lib_handle *handle, int cam_id) 1965 { 1966 int rc = MM_CAMERA_OK; 1967 1968 if ( NULL == handle ) { 1969 LOGE(" Invalid handle"); 1970 rc = MM_CAMERA_E_INVALID_INPUT; 1971 goto EXIT; 1972 } 1973 1974 handle->test_obj.buffer_width = DEFAULT_PREVIEW_WIDTH; 1975 handle->test_obj.buffer_height = DEFAULT_PREVIEW_HEIGHT; 1976 handle->test_obj.buffer_format = DEFAULT_SNAPSHOT_FORMAT; 1977 handle->current_params.stream_width = DEFAULT_SNAPSHOT_WIDTH; 1978 handle->current_params.stream_height = DEFAULT_SNAPSHOT_HEIGHT; 1979 handle->current_params.af_mode = CAM_FOCUS_MODE_AUTO; // Default to auto focus mode 1980 rc = mm_app_open(&handle->app_ctx, (uint8_t)cam_id, &handle->test_obj); 1981 if (rc != MM_CAMERA_OK) { 1982 LOGE("mm_app_open() cam_idx=%d, err=%d\n", 1983 cam_id, rc); 1984 goto EXIT; 1985 } 1986 1987 //rc = mm_app_initialize_fb(&handle->test_obj); 1988 rc = MM_CAMERA_OK; 1989 if (rc != MM_CAMERA_OK) { 1990 LOGE("mm_app_initialize_fb() cam_idx=%d, err=%d\n", 1991 cam_id, rc); 1992 goto EXIT; 1993 } 1994 1995 EXIT: 1996 1997 return rc; 1998 } 1999 2000 int mm_camera_lib_start_stream(mm_camera_lib_handle *handle) 2001 { 2002 int rc = MM_CAMERA_OK; 2003 cam_capability_t camera_cap; 2004 2005 if ( NULL == handle ) { 2006 LOGE(" Invalid handle"); 2007 rc = MM_CAMERA_E_INVALID_INPUT; 2008 goto EXIT; 2009 } 2010 2011 if ( handle->test_obj.zsl_enabled ) { 2012 rc = mm_app_start_preview_zsl(&handle->test_obj); 2013 if (rc != MM_CAMERA_OK) { 2014 LOGE("mm_app_start_preview_zsl() err=%d\n", 2015 rc); 2016 goto EXIT; 2017 } 2018 } else { 2019 handle->test_obj.enable_reproc = ENABLE_REPROCESSING; 2020 rc = mm_app_start_preview(&handle->test_obj); 2021 if (rc != MM_CAMERA_OK) { 2022 LOGE("mm_app_start_preview() err=%d\n", 2023 rc); 2024 goto EXIT; 2025 } 2026 } 2027 2028 // Configure focus mode after stream starts 2029 rc = mm_camera_lib_get_caps(handle, &camera_cap); 2030 if ( MM_CAMERA_OK != rc ) { 2031 LOGE("mm_camera_lib_get_caps() err=%d\n", rc); 2032 return -1; 2033 } 2034 if (camera_cap.supported_focus_modes_cnt == 1 && 2035 camera_cap.supported_focus_modes[0] == CAM_FOCUS_MODE_FIXED) { 2036 LOGD("focus not supported"); 2037 handle->test_obj.focus_supported = 0; 2038 handle->current_params.af_mode = CAM_FOCUS_MODE_FIXED; 2039 } else { 2040 handle->test_obj.focus_supported = 1; 2041 } 2042 rc = setFocusMode(&handle->test_obj, handle->current_params.af_mode); 2043 if (rc != MM_CAMERA_OK) { 2044 LOGE("autofocus error\n"); 2045 goto EXIT; 2046 } 2047 2048 rc = updateDebuglevel(&handle->test_obj); 2049 2050 if (rc != MM_CAMERA_OK) { 2051 LOGE("autofocus error\n"); 2052 goto EXIT; 2053 } 2054 handle->stream_running = 1; 2055 2056 EXIT: 2057 return rc; 2058 } 2059 2060 int mm_camera_lib_stop_stream(mm_camera_lib_handle *handle) 2061 { 2062 int rc = MM_CAMERA_OK; 2063 2064 if ( NULL == handle ) { 2065 LOGE(" Invalid handle"); 2066 rc = MM_CAMERA_E_INVALID_INPUT; 2067 goto EXIT; 2068 } 2069 2070 if ( handle->test_obj.zsl_enabled ) { 2071 rc = mm_app_stop_preview_zsl(&handle->test_obj); 2072 if (rc != MM_CAMERA_OK) { 2073 LOGE("mm_app_stop_preview_zsl() err=%d\n", 2074 rc); 2075 goto EXIT; 2076 } 2077 } else { 2078 rc = mm_app_stop_preview(&handle->test_obj); 2079 if (rc != MM_CAMERA_OK) { 2080 LOGE("mm_app_stop_preview() err=%d\n", 2081 rc); 2082 goto EXIT; 2083 } 2084 } 2085 2086 handle->stream_running = 0; 2087 2088 EXIT: 2089 return rc; 2090 } 2091 2092 int mm_camera_lib_get_caps(mm_camera_lib_handle *handle, 2093 cam_capability_t *caps) 2094 { 2095 int rc = MM_CAMERA_OK; 2096 2097 if ( NULL == handle ) { 2098 LOGE(" Invalid handle"); 2099 rc = MM_CAMERA_E_INVALID_INPUT; 2100 goto EXIT; 2101 } 2102 2103 if ( NULL == caps ) { 2104 LOGE(" Invalid capabilities structure"); 2105 rc = MM_CAMERA_E_INVALID_INPUT; 2106 goto EXIT; 2107 } 2108 2109 *caps = *( (cam_capability_t *) handle->test_obj.cap_buf.mem_info.data ); 2110 2111 EXIT: 2112 2113 return rc; 2114 } 2115 2116 2117 int mm_camera_lib_send_command(mm_camera_lib_handle *handle, 2118 mm_camera_lib_commands cmd, 2119 void *in_data, 2120 __unused void *out_data) 2121 { 2122 uint32_t width, height; 2123 int rc = MM_CAMERA_OK; 2124 cam_capability_t *camera_cap = NULL; 2125 mm_camera_lib_snapshot_params *dim = NULL; 2126 2127 if ( NULL == handle ) { 2128 LOGE(" Invalid handle"); 2129 rc = MM_CAMERA_E_INVALID_INPUT; 2130 goto EXIT; 2131 } 2132 2133 camera_cap = (cam_capability_t *) handle->test_obj.cap_buf.mem_info.data; 2134 2135 switch(cmd) { 2136 case MM_CAMERA_LIB_FPS_RANGE: 2137 if ( NULL != in_data ) { 2138 cam_fps_range_t range = *(( cam_fps_range_t * )in_data); 2139 rc = setFPSRange(&handle->test_obj, range); 2140 if (rc != MM_CAMERA_OK) { 2141 LOGE("setFPSRange() err=%d\n", 2142 rc); 2143 goto EXIT; 2144 } 2145 } 2146 break; 2147 case MM_CAMERA_LIB_EZTUNE_ENABLE: 2148 if ( NULL != in_data) { 2149 int enable_eztune = *(( int * )in_data); 2150 if ( ( enable_eztune != handle->test_obj.enable_EZTune) && 2151 handle->stream_running ) { 2152 rc = mm_camera_lib_stop_stream(handle); 2153 if (rc != MM_CAMERA_OK) { 2154 LOGE("mm_camera_lib_stop_stream() err=%d\n", 2155 rc); 2156 goto EXIT; 2157 } 2158 handle->test_obj.enable_EZTune= enable_eztune; 2159 rc = mm_camera_lib_start_stream(handle); 2160 if (rc != MM_CAMERA_OK) { 2161 LOGE("mm_camera_lib_start_stream() err=%d\n", 2162 rc); 2163 goto EXIT; 2164 } 2165 } else { 2166 handle->test_obj.enable_EZTune= enable_eztune; 2167 } 2168 } 2169 break; 2170 case MM_CAMERA_LIB_IRMODE: 2171 if ( NULL != in_data) { 2172 int enable_ir = *(( int * )in_data); 2173 if (enable_ir != handle->test_obj.enable_ir) { 2174 handle->test_obj.enable_ir = enable_ir; 2175 rc = setIRMode(&handle->test_obj, enable_ir); 2176 if (rc != MM_CAMERA_OK) { 2177 LOGE("setZoom() err=%d\n", 2178 rc); 2179 goto EXIT; 2180 } 2181 } 2182 } 2183 break; 2184 case MM_CAMERA_LIB_SHDR_MODE: 2185 if ( NULL != in_data) { 2186 int enable_shdr= *(( int * )in_data); 2187 if (enable_shdr != handle->test_obj.enable_ir) { 2188 handle->test_obj.enable_ir = enable_shdr; 2189 rc = setsHDRMode(&handle->test_obj, enable_shdr); 2190 if (rc != MM_CAMERA_OK) { 2191 LOGE("setHDR() err=%d\n", 2192 rc); 2193 goto EXIT; 2194 } 2195 } 2196 } 2197 break; 2198 case MM_CAMERA_LIB_FLASH: 2199 if ( NULL != in_data ) { 2200 cam_flash_mode_t flash = *(( int * )in_data); 2201 rc = setFlash(&handle->test_obj, flash); 2202 if (rc != MM_CAMERA_OK) { 2203 LOGE("setFlash() err=%d\n", 2204 rc); 2205 goto EXIT; 2206 } 2207 } 2208 break; 2209 case MM_CAMERA_LIB_SPL_EFFECT: 2210 if (NULL != in_data) { 2211 cam_effect_mode_type effect = *(( int * )in_data); 2212 rc = setEffect(&handle->test_obj, effect); 2213 2214 if (rc != MM_CAMERA_OK) { 2215 LOGE("setEffect() err=%d\n", 2216 rc); 2217 goto EXIT; 2218 } 2219 } 2220 break; 2221 case MM_CAMERA_LIB_BESTSHOT: 2222 if ( NULL != in_data ) { 2223 cam_scene_mode_type scene = *(( int * )in_data); 2224 rc = setScene(&handle->test_obj, scene); 2225 if (rc != MM_CAMERA_OK) { 2226 LOGE("setScene() err=%d\n", 2227 rc); 2228 goto EXIT; 2229 } 2230 } 2231 break; 2232 case MM_CAMERA_LIB_ZOOM: 2233 if ( NULL != in_data ) { 2234 int zoom = *(( int * )in_data); 2235 rc = setZoom(&handle->test_obj, zoom); 2236 if (rc != MM_CAMERA_OK) { 2237 LOGE("setZoom() err=%d\n", 2238 rc); 2239 goto EXIT; 2240 } 2241 } 2242 break; 2243 case MM_CAMERA_LIB_ISO: 2244 if ( NULL != in_data ) { 2245 cam_iso_mode_type iso = *(( int * )in_data); 2246 rc = setISO(&handle->test_obj, iso); 2247 if (rc != MM_CAMERA_OK) { 2248 LOGE("setISO() err=%d\n", 2249 rc); 2250 goto EXIT; 2251 } 2252 } 2253 break; 2254 case MM_CAMERA_LIB_SHARPNESS: 2255 if ( NULL != in_data ) { 2256 int sharpness = *(( int * )in_data); 2257 rc = setSharpness(&handle->test_obj, sharpness); 2258 if (rc != MM_CAMERA_OK) { 2259 LOGE("setSharpness() err=%d\n", 2260 rc); 2261 goto EXIT; 2262 } 2263 } 2264 break; 2265 case MM_CAMERA_LIB_SATURATION: 2266 if ( NULL != in_data ) { 2267 int saturation = *(( int * )in_data); 2268 rc = setSaturation(&handle->test_obj, saturation); 2269 if (rc != MM_CAMERA_OK) { 2270 LOGE("setSaturation() err=%d\n", 2271 rc); 2272 goto EXIT; 2273 } 2274 } 2275 break; 2276 case MM_CAMERA_LIB_CONTRAST: 2277 if ( NULL != in_data ) { 2278 int contrast = *(( int * )in_data); 2279 rc = setContrast(&handle->test_obj, contrast); 2280 if (rc != MM_CAMERA_OK) { 2281 LOGE("setContrast() err=%d\n", 2282 rc); 2283 goto EXIT; 2284 } 2285 } 2286 break; 2287 case MM_CAMERA_LIB_SET_TINTLESS: 2288 if ( NULL != in_data ) { 2289 int tintless = *(( int * )in_data); 2290 rc = setTintless(&handle->test_obj, tintless); 2291 if (rc != MM_CAMERA_OK) { 2292 LOGE("enlabe/disable:%d tintless() err=%d\n", 2293 tintless, rc); 2294 goto EXIT; 2295 } 2296 } 2297 break; 2298 case MM_CAMERA_LIB_BRIGHTNESS: 2299 if ( NULL != in_data ) { 2300 int brightness = *(( int * )in_data); 2301 rc = setBrightness(&handle->test_obj, brightness); 2302 if (rc != MM_CAMERA_OK) { 2303 LOGE("setBrightness() err=%d\n", 2304 rc); 2305 goto EXIT; 2306 } 2307 } 2308 break; 2309 case MM_CAMERA_LIB_EXPOSURE_METERING: 2310 if ( NULL != in_data ) { 2311 cam_auto_exposure_mode_type exp = *(( int * )in_data); 2312 rc = setExposureMetering(&handle->test_obj, exp); 2313 if (rc != MM_CAMERA_OK) { 2314 LOGE("setExposureMetering() err=%d\n", 2315 rc); 2316 goto EXIT; 2317 } 2318 } 2319 break; 2320 case MM_CAMERA_LIB_MN_WB: 2321 if ( NULL != in_data ) { 2322 cam_manual_wb_parm_t *manual_info = (( cam_manual_wb_parm_t* )in_data); 2323 2324 rc = setManualWhiteBalance(&handle->test_obj, manual_info); 2325 if (rc != MM_CAMERA_OK) { 2326 LOGE("etManualWhiteBalance() err=%d\n", 2327 rc); 2328 goto EXIT; 2329 } 2330 } 2331 break; 2332 case MM_CAMERA_LIB_WB: 2333 if ( NULL != in_data ) { 2334 cam_wb_mode_type wb = *(( int * )in_data); 2335 2336 rc = setWhiteBalance(&handle->test_obj, wb); 2337 if (rc != MM_CAMERA_OK) { 2338 LOGE("setWhiteBalance() err=%d\n", 2339 rc); 2340 goto EXIT; 2341 } 2342 } 2343 break; 2344 case MM_CAMERA_LIB_ANTIBANDING: 2345 if ( NULL != in_data ) { 2346 int antibanding = *(( int * )in_data); 2347 rc = setAntibanding(&handle->test_obj, antibanding); 2348 if (rc != MM_CAMERA_OK) { 2349 LOGE("setAntibanding() err=%d\n", 2350 rc); 2351 goto EXIT; 2352 } 2353 } 2354 break; 2355 case MM_CAMERA_LIB_FLIP: 2356 if ( NULL != in_data ) { 2357 int mode = *(( int * )in_data); 2358 rc = setFlipMode(&handle->test_obj, mode); 2359 if (rc != MM_CAMERA_OK) { 2360 LOGE("setFlipMode() err=%d\n", 2361 rc); 2362 goto EXIT; 2363 } 2364 } 2365 break; 2366 case MM_CAMERA_LIB_EV: 2367 if ( NULL != in_data ) { 2368 int ev = *(( int * )in_data); 2369 rc = setEVCompensation(&handle->test_obj, ev); 2370 if (rc != MM_CAMERA_OK) { 2371 LOGE("setEVCompensation() err=%d\n", 2372 rc); 2373 goto EXIT; 2374 } 2375 } 2376 break; 2377 case MM_CAMERA_LIB_ZSL_ENABLE: 2378 if ( NULL != in_data) { 2379 dim = ( mm_camera_lib_snapshot_params * ) in_data; 2380 if ( ( dim->isZSL!= handle->test_obj.zsl_enabled ) && 2381 handle->stream_running ) { 2382 rc = mm_camera_lib_stop_stream(handle); 2383 if (rc != MM_CAMERA_OK) { 2384 LOGE("mm_camera_lib_stop_stream() err=%d\n", 2385 rc); 2386 goto EXIT; 2387 } 2388 handle->test_obj.zsl_enabled = dim->isZSL; 2389 handle->test_obj.buffer_width = dim->width; 2390 handle->test_obj.buffer_height = dim->height; 2391 2392 rc = mm_camera_lib_start_stream(handle); 2393 if (rc != MM_CAMERA_OK) { 2394 LOGE("mm_camera_lib_start_stream() err=%d\n", 2395 rc); 2396 goto EXIT; 2397 } 2398 } else { 2399 handle->test_obj.zsl_enabled = dim->isZSL; 2400 } 2401 } 2402 break; 2403 case MM_CAMERA_LIB_RAW_CAPTURE: 2404 2405 if ( 0 == handle->stream_running ) { 2406 LOGE(" Streaming is not enabled!"); 2407 rc = MM_CAMERA_E_INVALID_OPERATION; 2408 goto EXIT; 2409 } 2410 2411 rc = mm_camera_lib_stop_stream(handle); 2412 if (rc != MM_CAMERA_OK) { 2413 LOGE("mm_camera_lib_stop_stream() err=%d\n", 2414 rc); 2415 goto EXIT; 2416 } 2417 2418 width = handle->test_obj.buffer_width; 2419 height = handle->test_obj.buffer_height; 2420 handle->test_obj.buffer_width = 2421 (uint32_t)camera_cap->raw_dim[0].width; 2422 handle->test_obj.buffer_height = 2423 (uint32_t)camera_cap->raw_dim[0].height; 2424 handle->test_obj.buffer_format = DEFAULT_RAW_FORMAT; 2425 LOGE("MM_CAMERA_LIB_RAW_CAPTURE %dx%d\n", 2426 camera_cap->raw_dim[0].width, 2427 camera_cap->raw_dim[0].height); 2428 rc = mm_app_start_capture_raw(&handle->test_obj, 1); 2429 if (rc != MM_CAMERA_OK) { 2430 LOGE("mm_app_start_capture() err=%d\n", 2431 rc); 2432 goto EXIT; 2433 } 2434 2435 mm_camera_app_wait(); 2436 rc = mm_app_stop_capture_raw(&handle->test_obj); 2437 if (rc != MM_CAMERA_OK) { 2438 LOGE("mm_app_stop_capture() err=%d\n", 2439 rc); 2440 goto EXIT; 2441 } 2442 2443 handle->test_obj.buffer_width = width; 2444 handle->test_obj.buffer_height = height; 2445 handle->test_obj.buffer_format = DEFAULT_SNAPSHOT_FORMAT; 2446 rc = mm_camera_lib_start_stream(handle); 2447 if (rc != MM_CAMERA_OK) { 2448 LOGE("mm_camera_lib_start_stream() err=%d\n", 2449 rc); 2450 goto EXIT; 2451 } 2452 2453 break; 2454 2455 case MM_CAMERA_LIB_JPEG_CAPTURE: 2456 if ( 0 == handle->stream_running ) { 2457 LOGE(" Streaming is not enabled!"); 2458 rc = MM_CAMERA_E_INVALID_OPERATION; 2459 goto EXIT; 2460 } 2461 2462 if ( NULL != in_data ) { 2463 dim = ( mm_camera_lib_snapshot_params * ) in_data; 2464 } 2465 2466 rc = tuneserver_capture(handle, dim); 2467 if (rc != MM_CAMERA_OK) { 2468 LOGE("capture error %d\n", rc); 2469 goto EXIT; 2470 } 2471 break; 2472 2473 case MM_CAMERA_LIB_SET_FOCUS_MODE: { 2474 cam_focus_mode_type mode = *((cam_focus_mode_type *)in_data); 2475 handle->current_params.af_mode = mode; 2476 rc = setFocusMode(&handle->test_obj, mode); 2477 if (rc != MM_CAMERA_OK) { 2478 LOGE("autofocus error\n"); 2479 goto EXIT; 2480 } 2481 break; 2482 } 2483 2484 case MM_CAMERA_LIB_DO_AF: 2485 if (handle->test_obj.focus_supported) { 2486 rc = handle->test_obj.cam->ops->do_auto_focus(handle->test_obj.cam->camera_handle); 2487 if (rc != MM_CAMERA_OK) { 2488 LOGE("autofocus error\n"); 2489 goto EXIT; 2490 } 2491 /*Waiting for Auto Focus Done Call Back*/ 2492 mm_camera_app_wait(); 2493 } 2494 break; 2495 2496 case MM_CAMERA_LIB_CANCEL_AF: 2497 rc = handle->test_obj.cam->ops->cancel_auto_focus(handle->test_obj.cam->camera_handle); 2498 if (rc != MM_CAMERA_OK) { 2499 LOGE("autofocus error\n"); 2500 goto EXIT; 2501 } 2502 2503 break; 2504 2505 case MM_CAMERA_LIB_LOCK_AWB: 2506 rc = setAwbLock(&handle->test_obj, 1); 2507 if (rc != MM_CAMERA_OK) { 2508 LOGE("AWB locking failed\n"); 2509 goto EXIT; 2510 } 2511 break; 2512 2513 case MM_CAMERA_LIB_UNLOCK_AWB: 2514 rc = setAwbLock(&handle->test_obj, 0); 2515 if (rc != MM_CAMERA_OK) { 2516 LOGE("AE unlocking failed\n"); 2517 goto EXIT; 2518 } 2519 break; 2520 2521 case MM_CAMERA_LIB_LOCK_AE: 2522 rc = setAecLock(&handle->test_obj, 1); 2523 if (rc != MM_CAMERA_OK) { 2524 LOGE("AE locking failed\n"); 2525 goto EXIT; 2526 } 2527 break; 2528 2529 case MM_CAMERA_LIB_UNLOCK_AE: 2530 rc = setAecLock(&handle->test_obj, 0); 2531 if (rc != MM_CAMERA_OK) { 2532 LOGE("AE unlocking failed\n"); 2533 goto EXIT; 2534 } 2535 break; 2536 2537 case MM_CAMERA_LIB_SET_3A_COMMAND: { 2538 rc = set3Acommand(&handle->test_obj, (cam_eztune_cmd_data_t *)in_data); 2539 if (rc != MM_CAMERA_OK) { 2540 LOGE("3A set command error\n"); 2541 goto EXIT; 2542 } 2543 break; 2544 } 2545 2546 case MM_CAMERA_LIB_SET_AUTOFOCUS_TUNING: { 2547 rc = setAutoFocusTuning(&handle->test_obj, in_data); 2548 if (rc != MM_CAMERA_OK) { 2549 LOGE("Set AF tuning failed\n"); 2550 goto EXIT; 2551 } 2552 break; 2553 } 2554 2555 case MM_CAMERA_LIB_SET_VFE_COMMAND: { 2556 rc = setVfeCommand(&handle->test_obj, in_data); 2557 if (rc != MM_CAMERA_OK) { 2558 LOGE("Set vfe command failed\n"); 2559 goto EXIT; 2560 } 2561 break; 2562 } 2563 2564 case MM_CAMERA_LIB_SET_POSTPROC_COMMAND: { 2565 rc = setPPCommand(&handle->test_obj, in_data); 2566 if (rc != MM_CAMERA_OK) { 2567 LOGE("Set pp command failed\n"); 2568 goto EXIT; 2569 } 2570 break; 2571 } 2572 2573 case MM_CAMERA_LIB_WNR_ENABLE: { 2574 rc = setWNR(&handle->test_obj, *((uint8_t *)in_data)); 2575 if ( rc != MM_CAMERA_OK) { 2576 LOGE("Set wnr enable failed\n"); 2577 goto EXIT; 2578 } 2579 } 2580 2581 case MM_CAMERA_LIB_NO_ACTION: 2582 default: 2583 break; 2584 }; 2585 2586 EXIT: 2587 2588 return rc; 2589 } 2590 int mm_camera_lib_number_of_cameras(mm_camera_lib_handle *handle) 2591 { 2592 int rc = 0; 2593 2594 if ( NULL == handle ) { 2595 LOGE(" Invalid handle"); 2596 goto EXIT; 2597 } 2598 2599 rc = handle->app_ctx.num_cameras; 2600 2601 EXIT: 2602 2603 return rc; 2604 } 2605 2606 int mm_camera_lib_close(mm_camera_lib_handle *handle) 2607 { 2608 int rc = MM_CAMERA_OK; 2609 2610 if ( NULL == handle ) { 2611 LOGE(" Invalid handle"); 2612 rc = MM_CAMERA_E_INVALID_INPUT; 2613 goto EXIT; 2614 } 2615 2616 //rc = mm_app_close_fb(&handle->test_obj); 2617 rc = MM_CAMERA_OK; 2618 if (rc != MM_CAMERA_OK) { 2619 LOGE("mm_app_close_fb() err=%d\n", 2620 rc); 2621 goto EXIT; 2622 } 2623 2624 rc = mm_app_close(&handle->test_obj); 2625 if (rc != MM_CAMERA_OK) { 2626 LOGE("mm_app_close() err=%d\n", 2627 rc); 2628 goto EXIT; 2629 } 2630 2631 EXIT: 2632 return rc; 2633 } 2634 2635 int mm_camera_lib_set_preview_usercb( 2636 mm_camera_lib_handle *handle, cam_stream_user_cb cb) 2637 { 2638 if (handle->test_obj.user_preview_cb != NULL) { 2639 LOGE(" already set preview callbacks\n"); 2640 return -1; 2641 } 2642 handle->test_obj.user_preview_cb = *cb; 2643 return 0; 2644 } 2645 2646 int mm_app_set_preview_fps_range(mm_camera_test_obj_t *test_obj, 2647 cam_fps_range_t *fpsRange) 2648 { 2649 int rc = MM_CAMERA_OK; 2650 LOGH("preview fps range: min=%f, max=%f.", 2651 fpsRange->min_fps, fpsRange->max_fps); 2652 rc = setFPSRange(test_obj, *fpsRange); 2653 2654 if (rc != MM_CAMERA_OK) { 2655 LOGE("add_parm_entry_tobatch failed !!"); 2656 return rc; 2657 } 2658 2659 return rc; 2660 } 2661 2662 int mm_app_set_face_detection(mm_camera_test_obj_t *test_obj, 2663 cam_fd_set_parm_t *fd_set_parm) 2664 { 2665 int rc = MM_CAMERA_OK; 2666 2667 if (test_obj == NULL || fd_set_parm == NULL) { 2668 LOGE(" invalid params!"); 2669 return MM_CAMERA_E_INVALID_INPUT; 2670 } 2671 2672 LOGH("mode = %d, num_fd = %d", 2673 fd_set_parm->fd_mode, fd_set_parm->num_fd); 2674 2675 rc = initBatchUpdate(test_obj); 2676 if (rc != MM_CAMERA_OK) { 2677 LOGE("Batch camera parameter update failed\n"); 2678 goto ERROR; 2679 } 2680 2681 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 2682 CAM_INTF_PARM_FD, *fd_set_parm)) { 2683 LOGE("FD parameter not added to batch\n"); 2684 rc = -1; 2685 goto ERROR; 2686 } 2687 2688 rc = commitSetBatch(test_obj); 2689 if (rc != MM_CAMERA_OK) { 2690 LOGE("Batch parameters commit failed\n"); 2691 goto ERROR; 2692 } 2693 2694 ERROR: 2695 return rc; 2696 } 2697 2698 int mm_app_set_flash_mode(mm_camera_test_obj_t *test_obj, 2699 cam_flash_mode_t flashMode) 2700 { 2701 int rc = MM_CAMERA_OK; 2702 2703 if (test_obj == NULL) { 2704 LOGE(" invalid params!"); 2705 return MM_CAMERA_E_INVALID_INPUT; 2706 } 2707 2708 LOGH("mode = %d", (int)flashMode); 2709 2710 rc = initBatchUpdate(test_obj); 2711 if (rc != MM_CAMERA_OK) { 2712 LOGE("Batch camera parameter update failed\n"); 2713 goto ERROR; 2714 } 2715 2716 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data, 2717 CAM_INTF_PARM_LED_MODE, flashMode)) { 2718 LOGE("Flash mode parameter not added to batch\n"); 2719 rc = -1; 2720 goto ERROR; 2721 } 2722 2723 rc = commitSetBatch(test_obj); 2724 if (rc != MM_CAMERA_OK) { 2725 LOGE("Batch parameters commit failed\n"); 2726 goto ERROR; 2727 } 2728 2729 ERROR: 2730 return rc; 2731 } 2732 2733 int mm_app_set_metadata_usercb(mm_camera_test_obj_t *test_obj, 2734 cam_stream_user_cb usercb) 2735 { 2736 if (test_obj == NULL || usercb == NULL) { 2737 LOGE(" invalid params!"); 2738 return MM_CAMERA_E_INVALID_INPUT; 2739 } 2740 2741 LOGH("%s, set user metadata callback, addr: %p\n", usercb); 2742 2743 if (test_obj->user_metadata_cb != NULL) { 2744 LOGH("%s, already set user metadata callback"); 2745 } 2746 test_obj->user_metadata_cb = usercb; 2747 2748 return 0; 2749 } 2750 2751 2752