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