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