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 NULL,
415 CAM_MAPPING_BUF_TYPE_STREAM_BUF, ops_tbl->userdata);
416 if (rc != MM_CAMERA_OK) {
417 LOGE("mapping buf[%d] err = %d", i, rc);
418 break;
419 }
420 }
421
422 if (rc != MM_CAMERA_OK) {
423 int j;
424 for (j=0; j>i; j++) {
425 ops_tbl->unmap_ops(pBufs[j].buf_idx, -1,
426 CAM_MAPPING_BUF_TYPE_STREAM_BUF, ops_tbl->userdata);
427 }
428 mm_app_release_bufs(stream->num_of_bufs, &stream->s_bufs[0]);
429 free(pBufs);
430 free(reg_flags);
431 return rc;
432 }
433
434 *num_bufs = stream->num_of_bufs;
435 *bufs = pBufs;
436 *initial_reg_flag = reg_flags;
437
438 LOGD("X");
439 return rc;
440 }
441
mm_app_stream_deinitbuf(mm_camera_map_unmap_ops_tbl_t * ops_tbl,void * user_data)442 int32_t mm_app_stream_deinitbuf(mm_camera_map_unmap_ops_tbl_t *ops_tbl,
443 void *user_data)
444 {
445 mm_camera_stream_t *stream = (mm_camera_stream_t *)user_data;
446 int i;
447
448 for (i = 0; i < stream->num_of_bufs ; i++) {
449 /* mapping stream bufs first */
450 ops_tbl->unmap_ops(stream->s_bufs[i].buf.buf_idx, -1,
451 CAM_MAPPING_BUF_TYPE_STREAM_BUF, ops_tbl->userdata);
452 }
453
454 mm_app_release_bufs(stream->num_of_bufs, &stream->s_bufs[0]);
455
456 LOGD("X");
457 return 0;
458 }
459
mm_app_stream_clean_invalidate_buf(uint32_t index,void * user_data)460 int32_t mm_app_stream_clean_invalidate_buf(uint32_t index, void *user_data)
461 {
462 mm_camera_stream_t *stream = (mm_camera_stream_t *)user_data;
463 return mm_app_cache_ops(&stream->s_bufs[index].mem_info,
464 ION_IOC_CLEAN_INV_CACHES);
465 }
466
mm_app_stream_invalidate_buf(uint32_t index,void * user_data)467 int32_t mm_app_stream_invalidate_buf(uint32_t index, void *user_data)
468 {
469 mm_camera_stream_t *stream = (mm_camera_stream_t *)user_data;
470 return mm_app_cache_ops(&stream->s_bufs[index].mem_info, ION_IOC_INV_CACHES);
471 }
472
notify_evt_cb(uint32_t camera_handle,mm_camera_event_t * evt,void * user_data)473 static void notify_evt_cb(uint32_t camera_handle,
474 mm_camera_event_t *evt,
475 void *user_data)
476 {
477 mm_camera_test_obj_t *test_obj =
478 (mm_camera_test_obj_t *)user_data;
479 if (test_obj == NULL || test_obj->cam->camera_handle != camera_handle) {
480 LOGE("Not a valid test obj");
481 return;
482 }
483
484 LOGD("E evt = %d", evt->server_event_type);
485 switch (evt->server_event_type) {
486 case CAM_EVENT_TYPE_AUTO_FOCUS_DONE:
487 LOGD("rcvd auto focus done evt");
488 break;
489 case CAM_EVENT_TYPE_ZOOM_DONE:
490 LOGD("rcvd zoom done evt");
491 break;
492 default:
493 break;
494 }
495
496 LOGD("X");
497 }
498
mm_app_open(mm_camera_app_t * cam_app,int cam_id,mm_camera_test_obj_t * test_obj)499 int mm_app_open(mm_camera_app_t *cam_app,
500 int cam_id,
501 mm_camera_test_obj_t *test_obj)
502 {
503 int32_t rc = 0;
504 cam_frame_len_offset_t offset_info;
505
506 LOGD("BEGIN\n");
507
508 rc = cam_app->hal_lib.mm_camera_open((uint8_t)cam_id, &(test_obj->cam));
509 if(rc || !test_obj->cam) {
510 LOGE("dev open error. rc = %d, vtbl = %p\n", rc, test_obj->cam);
511 return -MM_CAMERA_E_GENERAL;
512 }
513
514 LOGD("Open Camera id = %d handle = %d", cam_id, test_obj->cam->camera_handle);
515
516 /* alloc ion mem for capability buf */
517 memset(&offset_info, 0, sizeof(offset_info));
518 offset_info.frame_len = sizeof(cam_capability_t);
519
520 rc = mm_app_alloc_bufs(&test_obj->cap_buf,
521 &offset_info,
522 1,
523 0,
524 0);
525 if (rc != MM_CAMERA_OK) {
526 LOGE("alloc buf for capability error\n");
527 goto error_after_cam_open;
528 }
529
530 /* mapping capability buf */
531 rc = test_obj->cam->ops->map_buf(test_obj->cam->camera_handle,
532 CAM_MAPPING_BUF_TYPE_CAPABILITY,
533 test_obj->cap_buf.mem_info.fd,
534 test_obj->cap_buf.mem_info.size,
535 NULL);
536 if (rc != MM_CAMERA_OK) {
537 LOGE("map for capability error\n");
538 goto error_after_cap_buf_alloc;
539 }
540
541 /* alloc ion mem for getparm buf */
542 memset(&offset_info, 0, sizeof(offset_info));
543 offset_info.frame_len = sizeof(parm_buffer_t);
544 rc = mm_app_alloc_bufs(&test_obj->parm_buf,
545 &offset_info,
546 1,
547 0,
548 0);
549 if (rc != MM_CAMERA_OK) {
550 LOGE("alloc buf for getparm_buf error\n");
551 goto error_after_cap_buf_map;
552 }
553
554 /* mapping getparm buf */
555 rc = test_obj->cam->ops->map_buf(test_obj->cam->camera_handle,
556 CAM_MAPPING_BUF_TYPE_PARM_BUF,
557 test_obj->parm_buf.mem_info.fd,
558 test_obj->parm_buf.mem_info.size,
559 NULL);
560 if (rc != MM_CAMERA_OK) {
561 LOGE("map getparm_buf error\n");
562 goto error_after_getparm_buf_alloc;
563 }
564 test_obj->params_buffer = (parm_buffer_t*) test_obj->parm_buf.mem_info.data;
565 LOGH("\n%s params_buffer=%p\n",test_obj->params_buffer);
566
567 rc = test_obj->cam->ops->register_event_notify(test_obj->cam->camera_handle,
568 notify_evt_cb,
569 test_obj);
570 if (rc != MM_CAMERA_OK) {
571 LOGE("failed register_event_notify");
572 rc = -MM_CAMERA_E_GENERAL;
573 goto error_after_getparm_buf_map;
574 }
575
576 rc = test_obj->cam->ops->query_capability(test_obj->cam->camera_handle);
577 if (rc != MM_CAMERA_OK) {
578 LOGE("failed query_capability");
579 rc = -MM_CAMERA_E_GENERAL;
580 goto error_after_getparm_buf_map;
581 }
582 memset(&test_obj->jpeg_ops, 0, sizeof(mm_jpeg_ops_t));
583 mm_dimension pic_size;
584 memset(&pic_size, 0, sizeof(mm_dimension));
585 pic_size.w = 4000;
586 pic_size.h = 3000;
587 test_obj->jpeg_hdl = cam_app->hal_lib.jpeg_open(&test_obj->jpeg_ops, NULL, pic_size, NULL);
588 if (test_obj->jpeg_hdl == 0) {
589 LOGE("jpeg lib open err");
590 rc = -MM_CAMERA_E_GENERAL;
591 goto error_after_getparm_buf_map;
592 }
593
594 return rc;
595
596 error_after_getparm_buf_map:
597 test_obj->cam->ops->unmap_buf(test_obj->cam->camera_handle,
598 CAM_MAPPING_BUF_TYPE_PARM_BUF);
599 error_after_getparm_buf_alloc:
600 mm_app_release_bufs(1, &test_obj->parm_buf);
601 error_after_cap_buf_map:
602 test_obj->cam->ops->unmap_buf(test_obj->cam->camera_handle,
603 CAM_MAPPING_BUF_TYPE_CAPABILITY);
604 error_after_cap_buf_alloc:
605 mm_app_release_bufs(1, &test_obj->cap_buf);
606 error_after_cam_open:
607 test_obj->cam->ops->close_camera(test_obj->cam->camera_handle);
608 test_obj->cam = NULL;
609 return rc;
610 }
611
init_batch_update(parm_buffer_t * p_table)612 int init_batch_update(parm_buffer_t *p_table)
613 {
614 int rc = MM_CAMERA_OK;
615 LOGH("\nEnter %s\n");
616 int32_t hal_version = CAM_HAL_V1;
617
618 memset(p_table, 0, sizeof(parm_buffer_t));
619 if(ADD_SET_PARAM_ENTRY_TO_BATCH(p_table, CAM_INTF_PARM_HAL_VERSION, hal_version)) {
620 rc = -1;
621 }
622
623 return rc;
624 }
625
commit_set_batch(mm_camera_test_obj_t * test_obj)626 int commit_set_batch(mm_camera_test_obj_t *test_obj)
627 {
628 int rc = MM_CAMERA_OK;
629 int i = 0;
630
631 for(i = 0; i < CAM_INTF_PARM_MAX; i++){
632 if(test_obj->params_buffer->is_valid[i])
633 break;
634 }
635 if (i < CAM_INTF_PARM_MAX) {
636 LOGH("\n set_param p_buffer =%p\n",test_obj->params_buffer);
637 rc = test_obj->cam->ops->set_parms(test_obj->cam->camera_handle, test_obj->params_buffer);
638 }
639 if (rc != MM_CAMERA_OK) {
640 LOGE("cam->ops->set_parms failed !!");
641 }
642 return rc;
643 }
644
mm_app_close(mm_camera_test_obj_t * test_obj)645 int mm_app_close(mm_camera_test_obj_t *test_obj)
646 {
647 int32_t rc = MM_CAMERA_OK;
648
649 if (test_obj == NULL || test_obj->cam ==NULL) {
650 LOGE("cam not opened");
651 return -MM_CAMERA_E_GENERAL;
652 }
653
654 /* unmap capability buf */
655 rc = test_obj->cam->ops->unmap_buf(test_obj->cam->camera_handle,
656 CAM_MAPPING_BUF_TYPE_CAPABILITY);
657 if (rc != MM_CAMERA_OK) {
658 LOGE("unmap capability buf failed, rc=%d", rc);
659 }
660
661 /* unmap parm buf */
662 rc = test_obj->cam->ops->unmap_buf(test_obj->cam->camera_handle,
663 CAM_MAPPING_BUF_TYPE_PARM_BUF);
664 if (rc != MM_CAMERA_OK) {
665 LOGE("unmap setparm buf failed, rc=%d", rc);
666 }
667
668 rc = test_obj->cam->ops->close_camera(test_obj->cam->camera_handle);
669 if (rc != MM_CAMERA_OK) {
670 LOGE("close camera failed, rc=%d", rc);
671 }
672 test_obj->cam = NULL;
673
674 /* close jpeg client */
675 if (test_obj->jpeg_hdl && test_obj->jpeg_ops.close) {
676 rc = test_obj->jpeg_ops.close(test_obj->jpeg_hdl);
677 test_obj->jpeg_hdl = 0;
678 if (rc != MM_CAMERA_OK) {
679 LOGE("close jpeg failed, rc=%d", rc);
680 }
681 }
682
683 /* dealloc capability buf */
684 rc = mm_app_release_bufs(1, &test_obj->cap_buf);
685 if (rc != MM_CAMERA_OK) {
686 LOGE("release capability buf failed, rc=%d", rc);
687 }
688
689 /* dealloc parm buf */
690 rc = mm_app_release_bufs(1, &test_obj->parm_buf);
691 if (rc != MM_CAMERA_OK) {
692 LOGE("release setparm buf failed, rc=%d", rc);
693 }
694
695 return MM_CAMERA_OK;
696 }
697
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)698 mm_camera_channel_t * mm_app_add_channel(mm_camera_test_obj_t *test_obj,
699 mm_camera_channel_type_t ch_type,
700 mm_camera_channel_attr_t *attr,
701 mm_camera_buf_notify_t channel_cb,
702 void *userdata)
703 {
704 uint32_t ch_id = 0;
705 mm_camera_channel_t *channel = NULL;
706
707 ch_id = test_obj->cam->ops->add_channel(test_obj->cam->camera_handle,
708 attr,
709 channel_cb,
710 userdata);
711 if (ch_id == 0) {
712 LOGE("add channel failed");
713 return NULL;
714 }
715 channel = &test_obj->channels[ch_type];
716 channel->ch_id = ch_id;
717 return channel;
718 }
719
mm_app_del_channel(mm_camera_test_obj_t * test_obj,mm_camera_channel_t * channel)720 int mm_app_del_channel(mm_camera_test_obj_t *test_obj,
721 mm_camera_channel_t *channel)
722 {
723 test_obj->cam->ops->delete_channel(test_obj->cam->camera_handle,
724 channel->ch_id);
725 memset(channel, 0, sizeof(mm_camera_channel_t));
726 return MM_CAMERA_OK;
727 }
728
mm_app_add_stream(mm_camera_test_obj_t * test_obj,mm_camera_channel_t * channel)729 mm_camera_stream_t * mm_app_add_stream(mm_camera_test_obj_t *test_obj,
730 mm_camera_channel_t *channel)
731 {
732 mm_camera_stream_t *stream = NULL;
733 int rc = MM_CAMERA_OK;
734 cam_frame_len_offset_t offset_info;
735
736 stream = &(channel->streams[channel->num_streams++]);
737 stream->s_id = test_obj->cam->ops->add_stream(test_obj->cam->camera_handle,
738 channel->ch_id);
739 if (stream->s_id == 0) {
740 LOGE("add stream failed");
741 return NULL;
742 }
743
744 stream->multipleOf = test_obj->slice_size;
745
746 /* alloc ion mem for stream_info buf */
747 memset(&offset_info, 0, sizeof(offset_info));
748 offset_info.frame_len = sizeof(cam_stream_info_t);
749
750 rc = mm_app_alloc_bufs(&stream->s_info_buf,
751 &offset_info,
752 1,
753 0,
754 0);
755 if (rc != MM_CAMERA_OK) {
756 LOGE("alloc buf for stream_info error\n");
757 test_obj->cam->ops->delete_stream(test_obj->cam->camera_handle,
758 channel->ch_id,
759 stream->s_id);
760 stream->s_id = 0;
761 return NULL;
762 }
763
764 /* mapping streaminfo buf */
765 rc = test_obj->cam->ops->map_stream_buf(test_obj->cam->camera_handle,
766 channel->ch_id,
767 stream->s_id,
768 CAM_MAPPING_BUF_TYPE_STREAM_INFO,
769 0,
770 -1,
771 stream->s_info_buf.mem_info.fd,
772 (uint32_t)stream->s_info_buf.mem_info.size, NULL);
773 if (rc != MM_CAMERA_OK) {
774 LOGE("map setparm_buf error\n");
775 mm_app_deallocate_ion_memory(&stream->s_info_buf);
776 test_obj->cam->ops->delete_stream(test_obj->cam->camera_handle,
777 channel->ch_id,
778 stream->s_id);
779 stream->s_id = 0;
780 return NULL;
781 }
782
783 return stream;
784 }
785
mm_app_del_stream(mm_camera_test_obj_t * test_obj,mm_camera_channel_t * channel,mm_camera_stream_t * stream)786 int mm_app_del_stream(mm_camera_test_obj_t *test_obj,
787 mm_camera_channel_t *channel,
788 mm_camera_stream_t *stream)
789 {
790 test_obj->cam->ops->unmap_stream_buf(test_obj->cam->camera_handle,
791 channel->ch_id,
792 stream->s_id,
793 CAM_MAPPING_BUF_TYPE_STREAM_INFO,
794 0,
795 -1);
796 mm_app_deallocate_ion_memory(&stream->s_info_buf);
797 test_obj->cam->ops->delete_stream(test_obj->cam->camera_handle,
798 channel->ch_id,
799 stream->s_id);
800 memset(stream, 0, sizeof(mm_camera_stream_t));
801 return MM_CAMERA_OK;
802 }
803
mm_app_get_channel_by_type(mm_camera_test_obj_t * test_obj,mm_camera_channel_type_t ch_type)804 mm_camera_channel_t *mm_app_get_channel_by_type(mm_camera_test_obj_t *test_obj,
805 mm_camera_channel_type_t ch_type)
806 {
807 return &test_obj->channels[ch_type];
808 }
809
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)810 int mm_app_config_stream(mm_camera_test_obj_t *test_obj,
811 mm_camera_channel_t *channel,
812 mm_camera_stream_t *stream,
813 mm_camera_stream_config_t *config)
814 {
815 return test_obj->cam->ops->config_stream(test_obj->cam->camera_handle,
816 channel->ch_id,
817 stream->s_id,
818 config);
819 }
820
mm_app_start_channel(mm_camera_test_obj_t * test_obj,mm_camera_channel_t * channel)821 int mm_app_start_channel(mm_camera_test_obj_t *test_obj,
822 mm_camera_channel_t *channel)
823 {
824 return test_obj->cam->ops->start_channel(test_obj->cam->camera_handle,
825 channel->ch_id);
826 }
827
mm_app_stop_channel(mm_camera_test_obj_t * test_obj,mm_camera_channel_t * channel)828 int mm_app_stop_channel(mm_camera_test_obj_t *test_obj,
829 mm_camera_channel_t *channel)
830 {
831 return test_obj->cam->ops->stop_channel(test_obj->cam->camera_handle,
832 channel->ch_id);
833 }
834
initBatchUpdate(mm_camera_test_obj_t * test_obj)835 int initBatchUpdate(mm_camera_test_obj_t *test_obj)
836 {
837 int32_t hal_version = CAM_HAL_V1;
838
839 parm_buffer_t *parm_buf = ( parm_buffer_t * ) test_obj->parm_buf.mem_info.data;
840 memset(parm_buf, 0, sizeof(parm_buffer_t));
841 ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
842 CAM_INTF_PARM_HAL_VERSION, hal_version);
843
844 return MM_CAMERA_OK;
845 }
846
commitSetBatch(mm_camera_test_obj_t * test_obj)847 int commitSetBatch(mm_camera_test_obj_t *test_obj)
848 {
849 int rc = MM_CAMERA_OK;
850 int i = 0;
851
852 parm_buffer_t *p_table = ( parm_buffer_t * ) test_obj->parm_buf.mem_info.data;
853 for(i = 0; i < CAM_INTF_PARM_MAX; i++){
854 if(p_table->is_valid[i])
855 break;
856 }
857 if (i < CAM_INTF_PARM_MAX) {
858 rc = test_obj->cam->ops->set_parms(test_obj->cam->camera_handle, p_table);
859 }
860 return rc;
861 }
862
863
commitGetBatch(mm_camera_test_obj_t * test_obj)864 int commitGetBatch(mm_camera_test_obj_t *test_obj)
865 {
866 int rc = MM_CAMERA_OK;
867 int i = 0;
868 parm_buffer_t *p_table = ( parm_buffer_t * ) test_obj->parm_buf.mem_info.data;
869 for(i = 0; i < CAM_INTF_PARM_MAX; i++){
870 if(p_table->is_valid[i])
871 break;
872 }
873 if (i < CAM_INTF_PARM_MAX) {
874 rc = test_obj->cam->ops->get_parms(test_obj->cam->camera_handle, p_table);
875 }
876 return rc;
877 }
878
setAecLock(mm_camera_test_obj_t * test_obj,int value)879 int setAecLock(mm_camera_test_obj_t *test_obj, int value)
880 {
881 int rc = MM_CAMERA_OK;
882
883 rc = initBatchUpdate(test_obj);
884 if (rc != MM_CAMERA_OK) {
885 LOGE("Batch camera parameter update failed\n");
886 goto ERROR;
887 }
888
889 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
890 CAM_INTF_PARM_AEC_LOCK, (uint32_t)value)) {
891 LOGE("AEC Lock parameter not added to batch\n");
892 rc = -1;
893 goto ERROR;
894 }
895
896 rc = commitSetBatch(test_obj);
897 if (rc != MM_CAMERA_OK) {
898 LOGE("Batch parameters commit failed\n");
899 goto ERROR;
900 }
901
902 ERROR:
903 return rc;
904 }
905
setAwbLock(mm_camera_test_obj_t * test_obj,int value)906 int setAwbLock(mm_camera_test_obj_t *test_obj, int value)
907 {
908 int rc = MM_CAMERA_OK;
909
910 rc = initBatchUpdate(test_obj);
911 if (rc != MM_CAMERA_OK) {
912 LOGE("Batch camera parameter update failed\n");
913 goto ERROR;
914 }
915
916 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
917 CAM_INTF_PARM_AWB_LOCK, (uint32_t)value)) {
918 LOGE("AWB Lock parameter not added to batch\n");
919 rc = -1;
920 goto ERROR;
921 }
922
923 rc = commitSetBatch(test_obj);
924 if (rc != MM_CAMERA_OK) {
925 LOGE("Batch parameters commit failed\n");
926 goto ERROR;
927 }
928
929 ERROR:
930 return rc;
931 }
932
933
set3Acommand(mm_camera_test_obj_t * test_obj,cam_eztune_cmd_data_t * value)934 int set3Acommand(mm_camera_test_obj_t *test_obj, cam_eztune_cmd_data_t *value)
935 {
936 int rc = MM_CAMERA_OK;
937
938 rc = initBatchUpdate(test_obj);
939 if (rc != MM_CAMERA_OK) {
940 LOGE("Batch camera parameter update failed\n");
941 goto ERROR;
942 }
943
944 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
945 CAM_INTF_PARM_EZTUNE_CMD, *value)) {
946 LOGE("CAM_INTF_PARM_EZTUNE_CMD parameter not added to batch\n");
947 rc = -1;
948 goto ERROR;
949 }
950
951 rc = commitSetBatch(test_obj);
952 if (rc != MM_CAMERA_OK) {
953 LOGE("Batch parameters commit failed\n");
954 goto ERROR;
955 }
956
957 ERROR:
958 return rc;
959 }
960
setAutoFocusTuning(mm_camera_test_obj_t * test_obj,tune_actuator_t * value)961 int setAutoFocusTuning(mm_camera_test_obj_t *test_obj, tune_actuator_t *value)
962 {
963 int rc = MM_CAMERA_OK;
964
965 rc = initBatchUpdate(test_obj);
966 if (rc != MM_CAMERA_OK) {
967 LOGE("Batch camera parameter update failed\n");
968 goto ERROR;
969 }
970
971 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
972 CAM_INTF_PARM_SET_AUTOFOCUSTUNING, *value)) {
973 LOGE("AutoFocus Tuning not added to batch\n");
974 rc = -1;
975 goto ERROR;
976 }
977
978 rc = commitSetBatch(test_obj);
979 if (rc != MM_CAMERA_OK) {
980 LOGE("Batch parameters commit failed\n");
981 goto ERROR;
982 }
983
984 ERROR:
985 return rc;
986 }
987
setVfeCommand(mm_camera_test_obj_t * test_obj,tune_cmd_t * value)988 int setVfeCommand(mm_camera_test_obj_t *test_obj, tune_cmd_t *value)
989 {
990 int rc = MM_CAMERA_OK;
991
992 rc = initBatchUpdate(test_obj);
993 if (rc != MM_CAMERA_OK) {
994 LOGE("Batch camera parameter update failed\n");
995 goto ERROR;
996 }
997
998 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
999 CAM_INTF_PARM_SET_VFE_COMMAND, *value)) {
1000 LOGE("VFE Command not added to batch\n");
1001 rc = -1;
1002 goto ERROR;
1003 }
1004
1005 rc = commitSetBatch(test_obj);
1006 if (rc != MM_CAMERA_OK) {
1007 LOGE("Batch parameters commit failed\n");
1008 goto ERROR;
1009 }
1010
1011 ERROR:
1012 return rc;
1013 }
1014
setmetainfoCommand(mm_camera_test_obj_t * test_obj,cam_stream_size_info_t * value)1015 int setmetainfoCommand(mm_camera_test_obj_t *test_obj, cam_stream_size_info_t *value)
1016 {
1017 int rc = MM_CAMERA_OK;
1018
1019 rc = initBatchUpdate(test_obj);
1020 if (rc != MM_CAMERA_OK) {
1021 LOGE("Batch camera parameter update failed\n");
1022 goto ERROR;
1023 }
1024
1025 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1026 CAM_INTF_META_STREAM_INFO, *value)) {
1027 LOGE("PP Command not added to batch\n");
1028 rc = -1;
1029 goto ERROR;
1030 }
1031
1032 rc = commitSetBatch(test_obj);
1033 if (rc != MM_CAMERA_OK) {
1034 LOGE("Batch parameters commit failed\n");
1035 goto ERROR;
1036 }
1037
1038 ERROR:
1039 return rc;
1040 }
1041
1042
setPPCommand(mm_camera_test_obj_t * test_obj,tune_cmd_t * value)1043 int setPPCommand(mm_camera_test_obj_t *test_obj, tune_cmd_t *value)
1044 {
1045 int rc = MM_CAMERA_OK;
1046
1047 rc = initBatchUpdate(test_obj);
1048 if (rc != MM_CAMERA_OK) {
1049 LOGE("Batch camera parameter update failed\n");
1050 goto ERROR;
1051 }
1052
1053 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1054 CAM_INTF_PARM_SET_PP_COMMAND, *value)) {
1055 LOGE("PP Command not added to batch\n");
1056 rc = -1;
1057 goto ERROR;
1058 }
1059
1060 rc = commitSetBatch(test_obj);
1061 if (rc != MM_CAMERA_OK) {
1062 LOGE("Batch parameters commit failed\n");
1063 goto ERROR;
1064 }
1065
1066 ERROR:
1067 return rc;
1068 }
1069
setFocusMode(mm_camera_test_obj_t * test_obj,cam_focus_mode_type mode)1070 int setFocusMode(mm_camera_test_obj_t *test_obj, cam_focus_mode_type mode)
1071 {
1072 int rc = MM_CAMERA_OK;
1073
1074 rc = initBatchUpdate(test_obj);
1075 if (rc != MM_CAMERA_OK) {
1076 LOGE("Batch camera parameter update failed\n");
1077 goto ERROR;
1078 }
1079
1080 uint32_t value = mode;
1081
1082 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1083 CAM_INTF_PARM_FOCUS_MODE, value)) {
1084 LOGE("Focus mode parameter not added to batch\n");
1085 rc = -1;
1086 goto ERROR;
1087 }
1088
1089 rc = commitSetBatch(test_obj);
1090 if (rc != MM_CAMERA_OK) {
1091 LOGE("Batch parameters commit failed\n");
1092 goto ERROR;
1093 }
1094
1095 ERROR:
1096 return rc;
1097 }
1098
setEVCompensation(mm_camera_test_obj_t * test_obj,int ev)1099 int setEVCompensation(mm_camera_test_obj_t *test_obj, int ev)
1100 {
1101 int rc = MM_CAMERA_OK;
1102
1103 cam_capability_t *camera_cap = NULL;
1104
1105 camera_cap = (cam_capability_t *) test_obj->cap_buf.mem_info.data;
1106 if ( (ev >= camera_cap->exposure_compensation_min) &&
1107 (ev <= camera_cap->exposure_compensation_max) ) {
1108
1109 rc = initBatchUpdate(test_obj);
1110 if (rc != MM_CAMERA_OK) {
1111 LOGE("Batch camera parameter update failed\n");
1112 goto ERROR;
1113 }
1114
1115 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1116 CAM_INTF_PARM_EXPOSURE_COMPENSATION, ev)) {
1117 LOGE("EV compensation parameter not added to batch\n");
1118 rc = -1;
1119 goto ERROR;
1120 }
1121
1122 rc = commitSetBatch(test_obj);
1123 if (rc != MM_CAMERA_OK) {
1124 LOGE("Batch parameters commit failed\n");
1125 goto ERROR;
1126 }
1127
1128 LOGE("EV compensation set to: %d", ev);
1129 } else {
1130 LOGE("Invalid EV compensation");
1131 return -EINVAL;
1132 }
1133
1134 ERROR:
1135 return rc;
1136 }
1137
setAntibanding(mm_camera_test_obj_t * test_obj,cam_antibanding_mode_type antibanding)1138 int setAntibanding(mm_camera_test_obj_t *test_obj, cam_antibanding_mode_type antibanding)
1139 {
1140 int rc = MM_CAMERA_OK;
1141
1142 rc = initBatchUpdate(test_obj);
1143 if (rc != MM_CAMERA_OK) {
1144 LOGE("Batch camera parameter update failed\n");
1145 goto ERROR;
1146 }
1147
1148 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1149 CAM_INTF_PARM_ANTIBANDING, antibanding)) {
1150 LOGE("Antibanding parameter not added to batch\n");
1151 rc = -1;
1152 goto ERROR;
1153 }
1154
1155 rc = commitSetBatch(test_obj);
1156 if (rc != MM_CAMERA_OK) {
1157 LOGE("Batch parameters commit failed\n");
1158 goto ERROR;
1159 }
1160
1161 LOGE("Antibanding set to: %d", (int)antibanding);
1162
1163 ERROR:
1164 return rc;
1165 }
1166
setWhiteBalance(mm_camera_test_obj_t * test_obj,cam_wb_mode_type mode)1167 int setWhiteBalance(mm_camera_test_obj_t *test_obj, cam_wb_mode_type mode)
1168 {
1169 int rc = MM_CAMERA_OK;
1170
1171 rc = initBatchUpdate(test_obj);
1172 if (rc != MM_CAMERA_OK) {
1173 LOGE("Batch camera parameter update failed\n");
1174 goto ERROR;
1175 }
1176
1177 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1178 CAM_INTF_PARM_WHITE_BALANCE, mode)) {
1179 LOGE("White balance parameter not added to batch\n");
1180 rc = -1;
1181 goto ERROR;
1182 }
1183
1184 rc = commitSetBatch(test_obj);
1185 if (rc != MM_CAMERA_OK) {
1186 LOGE("Batch parameters commit failed\n");
1187 goto ERROR;
1188 }
1189
1190 LOGE("White balance set to: %d", (int)mode);
1191
1192 ERROR:
1193 return rc;
1194 }
1195
setExposureMetering(mm_camera_test_obj_t * test_obj,cam_auto_exposure_mode_type mode)1196 int setExposureMetering(mm_camera_test_obj_t *test_obj, cam_auto_exposure_mode_type mode)
1197 {
1198 int rc = MM_CAMERA_OK;
1199
1200 rc = initBatchUpdate(test_obj);
1201 if (rc != MM_CAMERA_OK) {
1202 LOGE("Batch camera parameter update failed\n");
1203 goto ERROR;
1204 }
1205
1206 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1207 CAM_INTF_PARM_EXPOSURE, mode)) {
1208 LOGE("Exposure metering parameter not added to batch\n");
1209 rc = -1;
1210 goto ERROR;
1211 }
1212
1213 rc = commitSetBatch(test_obj);
1214 if (rc != MM_CAMERA_OK) {
1215 LOGE("Batch parameters commit failed\n");
1216 goto ERROR;
1217 }
1218
1219 LOGE("Exposure metering set to: %d", (int)mode);
1220
1221 ERROR:
1222 return rc;
1223 }
1224
setBrightness(mm_camera_test_obj_t * test_obj,int brightness)1225 int setBrightness(mm_camera_test_obj_t *test_obj, int brightness)
1226 {
1227 int rc = MM_CAMERA_OK;
1228
1229 rc = initBatchUpdate(test_obj);
1230 if (rc != MM_CAMERA_OK) {
1231 LOGE("Batch camera parameter update failed\n");
1232 goto ERROR;
1233 }
1234
1235 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1236 CAM_INTF_PARM_BRIGHTNESS, brightness)) {
1237 LOGE("Brightness parameter not added to batch\n");
1238 rc = -1;
1239 goto ERROR;
1240 }
1241
1242 rc = commitSetBatch(test_obj);
1243 if (rc != MM_CAMERA_OK) {
1244 LOGE("Batch parameters commit failed\n");
1245 goto ERROR;
1246 }
1247
1248 LOGE("Brightness set to: %d", brightness);
1249
1250 ERROR:
1251 return rc;
1252 }
1253
setContrast(mm_camera_test_obj_t * test_obj,int contrast)1254 int setContrast(mm_camera_test_obj_t *test_obj, int contrast)
1255 {
1256 int rc = MM_CAMERA_OK;
1257
1258 rc = initBatchUpdate(test_obj);
1259 if (rc != MM_CAMERA_OK) {
1260 LOGE("Batch camera parameter update failed\n");
1261 goto ERROR;
1262 }
1263
1264 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1265 CAM_INTF_PARM_CONTRAST, contrast)) {
1266 LOGE("Contrast parameter not added to batch\n");
1267 rc = -1;
1268 goto ERROR;
1269 }
1270
1271 rc = commitSetBatch(test_obj);
1272 if (rc != MM_CAMERA_OK) {
1273 LOGE("Batch parameters commit failed\n");
1274 goto ERROR;
1275 }
1276
1277 LOGE("Contrast set to: %d", contrast);
1278
1279 ERROR:
1280 return rc;
1281 }
1282
setTintless(mm_camera_test_obj_t * test_obj,int tintless)1283 int setTintless(mm_camera_test_obj_t *test_obj, int tintless)
1284 {
1285 int rc = MM_CAMERA_OK;
1286
1287 rc = initBatchUpdate(test_obj);
1288 if (rc != MM_CAMERA_OK) {
1289 LOGE("Batch camera parameter update failed\n");
1290 goto ERROR;
1291 }
1292
1293 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1294 CAM_INTF_PARM_TINTLESS, tintless)) {
1295 LOGE("Tintless parameter not added to batch\n");
1296 rc = -1;
1297 goto ERROR;
1298 }
1299
1300 rc = commitSetBatch(test_obj);
1301 if (rc != MM_CAMERA_OK) {
1302 LOGE("Batch parameters commit failed\n");
1303 goto ERROR;
1304 }
1305
1306 LOGE("set Tintless to: %d", tintless);
1307
1308 ERROR:
1309 return rc;
1310 }
1311
setSaturation(mm_camera_test_obj_t * test_obj,int saturation)1312 int setSaturation(mm_camera_test_obj_t *test_obj, int saturation)
1313 {
1314 int rc = MM_CAMERA_OK;
1315
1316 rc = initBatchUpdate(test_obj);
1317 if (rc != MM_CAMERA_OK) {
1318 LOGE("Batch camera parameter update failed\n");
1319 goto ERROR;
1320 }
1321
1322 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1323 CAM_INTF_PARM_SATURATION, saturation)) {
1324 LOGE("Saturation parameter not added to batch\n");
1325 rc = -1;
1326 goto ERROR;
1327 }
1328
1329 rc = commitSetBatch(test_obj);
1330 if (rc != MM_CAMERA_OK) {
1331 LOGE("Batch parameters commit failed\n");
1332 goto ERROR;
1333 }
1334
1335 LOGE("Saturation set to: %d", saturation);
1336
1337 ERROR:
1338 return rc;
1339 }
1340
setSharpness(mm_camera_test_obj_t * test_obj,int sharpness)1341 int setSharpness(mm_camera_test_obj_t *test_obj, int sharpness)
1342 {
1343 int rc = MM_CAMERA_OK;
1344
1345 rc = initBatchUpdate(test_obj);
1346 if (rc != MM_CAMERA_OK) {
1347 LOGE("Batch camera parameter update failed\n");
1348 goto ERROR;
1349 }
1350
1351 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1352 CAM_INTF_PARM_SHARPNESS, sharpness)) {
1353 LOGE("Sharpness parameter not added to batch\n");
1354 rc = -1;
1355 goto ERROR;
1356 }
1357
1358 rc = commitSetBatch(test_obj);
1359 if (rc != MM_CAMERA_OK) {
1360 LOGE("Batch parameters commit failed\n");
1361 goto ERROR;
1362 }
1363
1364 test_obj->reproc_sharpness = sharpness;
1365 LOGE("Sharpness set to: %d", sharpness);
1366
1367 ERROR:
1368 return rc;
1369 }
1370
setISO(mm_camera_test_obj_t * test_obj,cam_iso_mode_type iso)1371 int setISO(mm_camera_test_obj_t *test_obj, cam_iso_mode_type iso)
1372 {
1373 int rc = MM_CAMERA_OK;
1374
1375 rc = initBatchUpdate(test_obj);
1376 if (rc != MM_CAMERA_OK) {
1377 LOGE("Batch camera parameter update failed\n");
1378 goto ERROR;
1379 }
1380
1381 cam_intf_parm_manual_3a_t iso_settings;
1382 memset(&iso_settings, 0, sizeof(cam_intf_parm_manual_3a_t));
1383 iso_settings.previewOnly = FALSE;
1384 iso_settings.value = (uint64_t)iso;
1385 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1386 CAM_INTF_PARM_ISO, iso_settings)) {
1387 LOGE("ISO parameter not added to batch\n");
1388 rc = -1;
1389 goto ERROR;
1390 }
1391
1392 rc = commitSetBatch(test_obj);
1393 if (rc != MM_CAMERA_OK) {
1394 LOGE("Batch parameters commit failed\n");
1395 goto ERROR;
1396 }
1397
1398 LOGE("ISO set to: %d", (int)iso);
1399
1400 ERROR:
1401 return rc;
1402 }
1403
setZoom(mm_camera_test_obj_t * test_obj,int zoom)1404 int setZoom(mm_camera_test_obj_t *test_obj, int zoom)
1405 {
1406 int rc = MM_CAMERA_OK;
1407
1408 rc = initBatchUpdate(test_obj);
1409 if (rc != MM_CAMERA_OK) {
1410 LOGE("Batch camera parameter update failed\n");
1411 goto ERROR;
1412 }
1413
1414 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1415 CAM_INTF_PARM_ZOOM, zoom)) {
1416 LOGE("Zoom parameter not added to batch\n");
1417 rc = -1;
1418 goto ERROR;
1419 }
1420
1421 rc = commitSetBatch(test_obj);
1422 if (rc != MM_CAMERA_OK) {
1423 LOGE("Batch parameters commit failed\n");
1424 goto ERROR;
1425 }
1426
1427 LOGE("Zoom set to: %d", zoom);
1428
1429 ERROR:
1430 return rc;
1431 }
1432
setFPSRange(mm_camera_test_obj_t * test_obj,cam_fps_range_t range)1433 int setFPSRange(mm_camera_test_obj_t *test_obj, cam_fps_range_t range)
1434 {
1435 int rc = MM_CAMERA_OK;
1436
1437 rc = initBatchUpdate(test_obj);
1438 if (rc != MM_CAMERA_OK) {
1439 LOGE("Batch camera parameter update failed\n");
1440 goto ERROR;
1441 }
1442
1443 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1444 CAM_INTF_PARM_FPS_RANGE, range)) {
1445 LOGE("FPS range parameter not added to batch\n");
1446 rc = -1;
1447 goto ERROR;
1448 }
1449
1450 rc = commitSetBatch(test_obj);
1451 if (rc != MM_CAMERA_OK) {
1452 LOGE("Batch parameters commit failed\n");
1453 goto ERROR;
1454 }
1455
1456 LOGE("FPS Range set to: [%5.2f:%5.2f]",
1457 range.min_fps,
1458 range.max_fps);
1459
1460 ERROR:
1461 return rc;
1462 }
1463
setScene(mm_camera_test_obj_t * test_obj,cam_scene_mode_type scene)1464 int setScene(mm_camera_test_obj_t *test_obj, cam_scene_mode_type scene)
1465 {
1466 int rc = MM_CAMERA_OK;
1467
1468 rc = initBatchUpdate(test_obj);
1469 if (rc != MM_CAMERA_OK) {
1470 LOGE("Batch camera parameter update failed\n");
1471 goto ERROR;
1472 }
1473
1474 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1475 CAM_INTF_PARM_BESTSHOT_MODE, scene)) {
1476 LOGE("Scene parameter not added to batch\n");
1477 rc = -1;
1478 goto ERROR;
1479 }
1480
1481 rc = commitSetBatch(test_obj);
1482 if (rc != MM_CAMERA_OK) {
1483 LOGE("Batch parameters commit failed\n");
1484 goto ERROR;
1485 }
1486
1487 LOGE("Scene set to: %d", (int)scene);
1488
1489 ERROR:
1490 return rc;
1491 }
1492
setFlash(mm_camera_test_obj_t * test_obj,cam_flash_mode_t flash)1493 int setFlash(mm_camera_test_obj_t *test_obj, cam_flash_mode_t flash)
1494 {
1495 int rc = MM_CAMERA_OK;
1496
1497 rc = initBatchUpdate(test_obj);
1498 if (rc != MM_CAMERA_OK) {
1499 LOGE("Batch camera parameter update failed\n");
1500 goto ERROR;
1501 }
1502
1503 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1504 CAM_INTF_PARM_LED_MODE, flash)) {
1505 LOGE("Flash parameter not added to batch\n");
1506 rc = -1;
1507 goto ERROR;
1508 }
1509
1510 rc = commitSetBatch(test_obj);
1511 if (rc != MM_CAMERA_OK) {
1512 LOGE("Batch parameters commit failed\n");
1513 goto ERROR;
1514 }
1515
1516 LOGE("Flash set to: %d", (int)flash);
1517
1518 ERROR:
1519 return rc;
1520 }
1521
setWNR(mm_camera_test_obj_t * test_obj,uint8_t enable)1522 int setWNR(mm_camera_test_obj_t *test_obj, uint8_t enable)
1523 {
1524 int rc = MM_CAMERA_OK;
1525
1526 rc = initBatchUpdate(test_obj);
1527 if (rc != MM_CAMERA_OK) {
1528 LOGE("Batch camera parameter update failed\n");
1529 goto ERROR;
1530 }
1531
1532 cam_denoise_param_t param;
1533 memset(¶m, 0, sizeof(cam_denoise_param_t));
1534 param.denoise_enable = enable;
1535 param.process_plates = CAM_WAVELET_DENOISE_YCBCR_PLANE;
1536
1537 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
1538 CAM_INTF_PARM_WAVELET_DENOISE, param)) {
1539 LOGE("WNR enabled parameter not added to batch\n");
1540 rc = -1;
1541 goto ERROR;
1542 }
1543
1544 rc = commitSetBatch(test_obj);
1545 if (rc != MM_CAMERA_OK) {
1546 LOGE("Batch parameters commit failed\n");
1547 goto ERROR;
1548 }
1549
1550
1551 test_obj->reproc_wnr = param;
1552 LOGE("WNR enabled: %d", enable);
1553
1554 ERROR:
1555 return rc;
1556 }
1557
1558
1559 /** tuneserver_capture
1560 * @lib_handle: the camera handle object
1561 * @dim: snapshot dimensions
1562 *
1563 * makes JPEG capture
1564 *
1565 * Return: >=0 on success, -1 on failure.
1566 **/
tuneserver_capture(mm_camera_lib_handle * lib_handle,mm_camera_lib_snapshot_params * dim)1567 int tuneserver_capture(mm_camera_lib_handle *lib_handle,
1568 mm_camera_lib_snapshot_params *dim)
1569 {
1570 int rc = 0;
1571
1572 printf("Take jpeg snapshot\n");
1573 if ( lib_handle->stream_running ) {
1574
1575 if ( lib_handle->test_obj.zsl_enabled) {
1576 if ( NULL != dim) {
1577 if ( ( lib_handle->test_obj.buffer_width != dim->width) ||
1578 ( lib_handle->test_obj.buffer_height = dim->height ) ) {
1579
1580 lib_handle->test_obj.buffer_width = dim->width;
1581 lib_handle->test_obj.buffer_height = dim->height;
1582
1583 rc = mm_camera_lib_stop_stream(lib_handle);
1584 if (rc != MM_CAMERA_OK) {
1585 LOGE("mm_camera_lib_stop_stream() err=%d\n",
1586 rc);
1587 goto EXIT;
1588 }
1589
1590 rc = mm_camera_lib_start_stream(lib_handle);
1591 if (rc != MM_CAMERA_OK) {
1592 LOGE("mm_camera_lib_start_stream() err=%d\n",
1593 rc);
1594 goto EXIT;
1595 }
1596 }
1597
1598 }
1599
1600 lib_handle->test_obj.encodeJpeg = 1;
1601
1602 mm_camera_app_wait();
1603 } else {
1604 // For standard 2D capture streaming has to be disabled first
1605 rc = mm_camera_lib_stop_stream(lib_handle);
1606 if (rc != MM_CAMERA_OK) {
1607 LOGE("mm_camera_lib_stop_stream() err=%d\n",
1608 rc);
1609 goto EXIT;
1610 }
1611
1612 if ( NULL != dim ) {
1613 lib_handle->test_obj.buffer_width = dim->width;
1614 lib_handle->test_obj.buffer_height = dim->height;
1615 }
1616 rc = mm_app_start_capture(&lib_handle->test_obj, 1);
1617 if (rc != MM_CAMERA_OK) {
1618 LOGE("mm_app_start_capture() err=%d\n",
1619 rc);
1620 goto EXIT;
1621 }
1622
1623 mm_camera_app_wait();
1624
1625 rc = mm_app_stop_capture(&lib_handle->test_obj);
1626 if (rc != MM_CAMERA_OK) {
1627 LOGE("mm_app_stop_capture() err=%d\n",
1628 rc);
1629 goto EXIT;
1630 }
1631
1632 // Restart streaming after capture is done
1633 rc = mm_camera_lib_start_stream(lib_handle);
1634 if (rc != MM_CAMERA_OK) {
1635 LOGE("mm_camera_lib_start_stream() err=%d\n",
1636 rc);
1637 goto EXIT;
1638 }
1639 }
1640 }
1641
1642 EXIT:
1643
1644 return rc;
1645 }
1646
mm_app_start_regression_test(int run_tc)1647 int mm_app_start_regression_test(int run_tc)
1648 {
1649 int rc = MM_CAMERA_OK;
1650 mm_camera_app_t my_cam_app;
1651
1652 LOGD("\nCamera Test Application\n");
1653 memset(&my_cam_app, 0, sizeof(mm_camera_app_t));
1654
1655 rc = mm_app_load_hal(&my_cam_app);
1656 if (rc != MM_CAMERA_OK) {
1657 LOGE("mm_app_load_hal failed !!");
1658 return rc;
1659 }
1660
1661 if(run_tc) {
1662 rc = mm_app_unit_test_entry(&my_cam_app);
1663 return rc;
1664 }
1665 #if 0
1666 if(run_dual_tc) {
1667 printf("\tRunning Dual camera test engine only\n");
1668 rc = mm_app_dual_test_entry(&my_cam_app);
1669 printf("\t Dual camera engine. EXIT(%d)!!!\n", rc);
1670 exit(rc);
1671 }
1672 #endif
1673 return rc;
1674 }
1675
mm_camera_load_tuninglibrary(mm_camera_tuning_lib_params_t * tuning_param)1676 int32_t mm_camera_load_tuninglibrary(mm_camera_tuning_lib_params_t *tuning_param)
1677 {
1678 void *(*tuning_open_lib)(void) = NULL;
1679
1680 LOGD("E");
1681 tuning_param->lib_handle = dlopen("libmmcamera_tuning.so", RTLD_NOW);
1682 if (!tuning_param->lib_handle) {
1683 LOGE("Failed opening libmmcamera_tuning.so\n");
1684 return -EINVAL;
1685 }
1686
1687 *(void **)&tuning_open_lib = dlsym(tuning_param->lib_handle,
1688 "open_tuning_lib");
1689 if (!tuning_open_lib) {
1690 LOGE("Failed symbol libmmcamera_tuning.so\n");
1691 return -EINVAL;
1692 }
1693
1694 if (tuning_param->func_tbl) {
1695 LOGE("already loaded tuninglib..");
1696 return 0;
1697 }
1698
1699 tuning_param->func_tbl = (mm_camera_tune_func_t *)tuning_open_lib();
1700 if (!tuning_param->func_tbl) {
1701 LOGE("Failed opening library func table ptr\n");
1702 return -EINVAL;
1703 }
1704
1705 LOGD("X");
1706 return 0;
1707 }
1708
mm_camera_lib_open(mm_camera_lib_handle * handle,int cam_id)1709 int mm_camera_lib_open(mm_camera_lib_handle *handle, int cam_id)
1710 {
1711 int rc = MM_CAMERA_OK;
1712
1713 if ( NULL == handle ) {
1714 LOGE(" Invalid handle");
1715 rc = MM_CAMERA_E_INVALID_INPUT;
1716 goto EXIT;
1717 }
1718
1719 memset(handle, 0, sizeof(mm_camera_lib_handle));
1720 rc = mm_app_load_hal(&handle->app_ctx);
1721 if( MM_CAMERA_OK != rc ) {
1722 LOGE("mm_app_init err\n");
1723 goto EXIT;
1724 }
1725
1726 handle->test_obj.buffer_width = DEFAULT_PREVIEW_WIDTH;
1727 handle->test_obj.buffer_height = DEFAULT_PREVIEW_HEIGHT;
1728 handle->test_obj.buffer_format = DEFAULT_SNAPSHOT_FORMAT;
1729 handle->current_params.stream_width = DEFAULT_SNAPSHOT_WIDTH;
1730 handle->current_params.stream_height = DEFAULT_SNAPSHOT_HEIGHT;
1731 handle->current_params.af_mode = CAM_FOCUS_MODE_AUTO; // Default to auto focus mode
1732 rc = mm_app_open(&handle->app_ctx, (uint8_t)cam_id, &handle->test_obj);
1733 if (rc != MM_CAMERA_OK) {
1734 LOGE("mm_app_open() cam_idx=%d, err=%d\n",
1735 cam_id, rc);
1736 goto EXIT;
1737 }
1738
1739 //rc = mm_app_initialize_fb(&handle->test_obj);
1740 rc = MM_CAMERA_OK;
1741 if (rc != MM_CAMERA_OK) {
1742 LOGE("mm_app_initialize_fb() cam_idx=%d, err=%d\n",
1743 cam_id, rc);
1744 goto EXIT;
1745 }
1746
1747 EXIT:
1748
1749 return rc;
1750 }
1751
mm_camera_lib_start_stream(mm_camera_lib_handle * handle)1752 int mm_camera_lib_start_stream(mm_camera_lib_handle *handle)
1753 {
1754 int rc = MM_CAMERA_OK;
1755 cam_capability_t camera_cap;
1756
1757 if ( NULL == handle ) {
1758 LOGE(" Invalid handle");
1759 rc = MM_CAMERA_E_INVALID_INPUT;
1760 goto EXIT;
1761 }
1762
1763 if ( handle->test_obj.zsl_enabled ) {
1764 rc = mm_app_start_preview_zsl(&handle->test_obj);
1765 if (rc != MM_CAMERA_OK) {
1766 LOGE("mm_app_start_preview_zsl() err=%d\n",
1767 rc);
1768 goto EXIT;
1769 }
1770 } else {
1771 handle->test_obj.enable_reproc = ENABLE_REPROCESSING;
1772 rc = mm_app_start_preview(&handle->test_obj);
1773 if (rc != MM_CAMERA_OK) {
1774 LOGE("mm_app_start_preview() err=%d\n",
1775 rc);
1776 goto EXIT;
1777 }
1778 }
1779
1780 // Configure focus mode after stream starts
1781 rc = mm_camera_lib_get_caps(handle, &camera_cap);
1782 if ( MM_CAMERA_OK != rc ) {
1783 LOGE("mm_camera_lib_get_caps() err=%d\n", rc);
1784 return -1;
1785 }
1786 if (camera_cap.supported_focus_modes_cnt == 1 &&
1787 camera_cap.supported_focus_modes[0] == CAM_FOCUS_MODE_FIXED) {
1788 LOGD("focus not supported");
1789 handle->test_obj.focus_supported = 0;
1790 handle->current_params.af_mode = CAM_FOCUS_MODE_FIXED;
1791 } else {
1792 handle->test_obj.focus_supported = 1;
1793 }
1794 rc = setFocusMode(&handle->test_obj, handle->current_params.af_mode);
1795 if (rc != MM_CAMERA_OK) {
1796 LOGE("autofocus error\n");
1797 goto EXIT;
1798 }
1799 handle->stream_running = 1;
1800
1801 EXIT:
1802 return rc;
1803 }
1804
mm_camera_lib_stop_stream(mm_camera_lib_handle * handle)1805 int mm_camera_lib_stop_stream(mm_camera_lib_handle *handle)
1806 {
1807 int rc = MM_CAMERA_OK;
1808
1809 if ( NULL == handle ) {
1810 LOGE(" Invalid handle");
1811 rc = MM_CAMERA_E_INVALID_INPUT;
1812 goto EXIT;
1813 }
1814
1815 if ( handle->test_obj.zsl_enabled ) {
1816 rc = mm_app_stop_preview_zsl(&handle->test_obj);
1817 if (rc != MM_CAMERA_OK) {
1818 LOGE("mm_app_stop_preview_zsl() err=%d\n",
1819 rc);
1820 goto EXIT;
1821 }
1822 } else {
1823 rc = mm_app_stop_preview(&handle->test_obj);
1824 if (rc != MM_CAMERA_OK) {
1825 LOGE("mm_app_stop_preview() err=%d\n",
1826 rc);
1827 goto EXIT;
1828 }
1829 }
1830
1831 handle->stream_running = 0;
1832
1833 EXIT:
1834 return rc;
1835 }
1836
mm_camera_lib_get_caps(mm_camera_lib_handle * handle,cam_capability_t * caps)1837 int mm_camera_lib_get_caps(mm_camera_lib_handle *handle,
1838 cam_capability_t *caps)
1839 {
1840 int rc = MM_CAMERA_OK;
1841
1842 if ( NULL == handle ) {
1843 LOGE(" Invalid handle");
1844 rc = MM_CAMERA_E_INVALID_INPUT;
1845 goto EXIT;
1846 }
1847
1848 if ( NULL == caps ) {
1849 LOGE(" Invalid capabilities structure");
1850 rc = MM_CAMERA_E_INVALID_INPUT;
1851 goto EXIT;
1852 }
1853
1854 *caps = *( (cam_capability_t *) handle->test_obj.cap_buf.mem_info.data );
1855
1856 EXIT:
1857
1858 return rc;
1859 }
1860
1861
mm_camera_lib_send_command(mm_camera_lib_handle * handle,mm_camera_lib_commands cmd,void * in_data,__unused void * out_data)1862 int mm_camera_lib_send_command(mm_camera_lib_handle *handle,
1863 mm_camera_lib_commands cmd,
1864 void *in_data,
1865 __unused void *out_data)
1866 {
1867 uint32_t width, height;
1868 int rc = MM_CAMERA_OK;
1869 cam_capability_t *camera_cap = NULL;
1870 mm_camera_lib_snapshot_params *dim = NULL;
1871
1872 if ( NULL == handle ) {
1873 LOGE(" Invalid handle");
1874 rc = MM_CAMERA_E_INVALID_INPUT;
1875 goto EXIT;
1876 }
1877
1878 camera_cap = (cam_capability_t *) handle->test_obj.cap_buf.mem_info.data;
1879
1880 switch(cmd) {
1881 case MM_CAMERA_LIB_FPS_RANGE:
1882 if ( NULL != in_data ) {
1883 cam_fps_range_t range = *(( cam_fps_range_t * )in_data);
1884 rc = setFPSRange(&handle->test_obj, range);
1885 if (rc != MM_CAMERA_OK) {
1886 LOGE("setFPSRange() err=%d\n",
1887 rc);
1888 goto EXIT;
1889 }
1890 }
1891 break;
1892 case MM_CAMERA_LIB_FLASH:
1893 if ( NULL != in_data ) {
1894 cam_flash_mode_t flash = *(( int * )in_data);
1895 rc = setFlash(&handle->test_obj, flash);
1896 if (rc != MM_CAMERA_OK) {
1897 LOGE("setFlash() err=%d\n",
1898 rc);
1899 goto EXIT;
1900 }
1901 }
1902 break;
1903 case MM_CAMERA_LIB_BESTSHOT:
1904 if ( NULL != in_data ) {
1905 cam_scene_mode_type scene = *(( int * )in_data);
1906 rc = setScene(&handle->test_obj, scene);
1907 if (rc != MM_CAMERA_OK) {
1908 LOGE("setScene() err=%d\n",
1909 rc);
1910 goto EXIT;
1911 }
1912 }
1913 break;
1914 case MM_CAMERA_LIB_ZOOM:
1915 if ( NULL != in_data ) {
1916 int zoom = *(( int * )in_data);
1917 rc = setZoom(&handle->test_obj, zoom);
1918 if (rc != MM_CAMERA_OK) {
1919 LOGE("setZoom() err=%d\n",
1920 rc);
1921 goto EXIT;
1922 }
1923 }
1924 break;
1925 case MM_CAMERA_LIB_ISO:
1926 if ( NULL != in_data ) {
1927 cam_iso_mode_type iso = *(( int * )in_data);
1928 rc = setISO(&handle->test_obj, iso);
1929 if (rc != MM_CAMERA_OK) {
1930 LOGE("setISO() err=%d\n",
1931 rc);
1932 goto EXIT;
1933 }
1934 }
1935 break;
1936 case MM_CAMERA_LIB_SHARPNESS:
1937 if ( NULL != in_data ) {
1938 int sharpness = *(( int * )in_data);
1939 rc = setSharpness(&handle->test_obj, sharpness);
1940 if (rc != MM_CAMERA_OK) {
1941 LOGE("setSharpness() err=%d\n",
1942 rc);
1943 goto EXIT;
1944 }
1945 }
1946 break;
1947 case MM_CAMERA_LIB_SATURATION:
1948 if ( NULL != in_data ) {
1949 int saturation = *(( int * )in_data);
1950 rc = setSaturation(&handle->test_obj, saturation);
1951 if (rc != MM_CAMERA_OK) {
1952 LOGE("setSaturation() err=%d\n",
1953 rc);
1954 goto EXIT;
1955 }
1956 }
1957 break;
1958 case MM_CAMERA_LIB_CONTRAST:
1959 if ( NULL != in_data ) {
1960 int contrast = *(( int * )in_data);
1961 rc = setContrast(&handle->test_obj, contrast);
1962 if (rc != MM_CAMERA_OK) {
1963 LOGE("setContrast() err=%d\n",
1964 rc);
1965 goto EXIT;
1966 }
1967 }
1968 break;
1969 case MM_CAMERA_LIB_SET_TINTLESS:
1970 if ( NULL != in_data ) {
1971 int tintless = *(( int * )in_data);
1972 rc = setTintless(&handle->test_obj, tintless);
1973 if (rc != MM_CAMERA_OK) {
1974 LOGE("enlabe/disable:%d tintless() err=%d\n",
1975 tintless, rc);
1976 goto EXIT;
1977 }
1978 }
1979 break;
1980 case MM_CAMERA_LIB_BRIGHTNESS:
1981 if ( NULL != in_data ) {
1982 int brightness = *(( int * )in_data);
1983 rc = setBrightness(&handle->test_obj, brightness);
1984 if (rc != MM_CAMERA_OK) {
1985 LOGE("setBrightness() err=%d\n",
1986 rc);
1987 goto EXIT;
1988 }
1989 }
1990 break;
1991 case MM_CAMERA_LIB_EXPOSURE_METERING:
1992 if ( NULL != in_data ) {
1993 cam_auto_exposure_mode_type exp = *(( int * )in_data);
1994 rc = setExposureMetering(&handle->test_obj, exp);
1995 if (rc != MM_CAMERA_OK) {
1996 LOGE("setExposureMetering() err=%d\n",
1997 rc);
1998 goto EXIT;
1999 }
2000 }
2001 break;
2002 case MM_CAMERA_LIB_WB:
2003 if ( NULL != in_data ) {
2004 cam_wb_mode_type wb = *(( int * )in_data);
2005 rc = setWhiteBalance(&handle->test_obj, wb);
2006 if (rc != MM_CAMERA_OK) {
2007 LOGE("setWhiteBalance() err=%d\n",
2008 rc);
2009 goto EXIT;
2010 }
2011 }
2012 break;
2013 case MM_CAMERA_LIB_ANTIBANDING:
2014 if ( NULL != in_data ) {
2015 int antibanding = *(( int * )in_data);
2016 rc = setAntibanding(&handle->test_obj, antibanding);
2017 if (rc != MM_CAMERA_OK) {
2018 LOGE("setAntibanding() err=%d\n",
2019 rc);
2020 goto EXIT;
2021 }
2022 }
2023 break;
2024 case MM_CAMERA_LIB_EV:
2025 if ( NULL != in_data ) {
2026 int ev = *(( int * )in_data);
2027 rc = setEVCompensation(&handle->test_obj, ev);
2028 if (rc != MM_CAMERA_OK) {
2029 LOGE("setEVCompensation() err=%d\n",
2030 rc);
2031 goto EXIT;
2032 }
2033 }
2034 break;
2035 case MM_CAMERA_LIB_ZSL_ENABLE:
2036 if ( NULL != in_data) {
2037 int enable_zsl = *(( int * )in_data);
2038 if ( ( enable_zsl != handle->test_obj.zsl_enabled ) &&
2039 handle->stream_running ) {
2040 rc = mm_camera_lib_stop_stream(handle);
2041 if (rc != MM_CAMERA_OK) {
2042 LOGE("mm_camera_lib_stop_stream() err=%d\n",
2043 rc);
2044 goto EXIT;
2045 }
2046 handle->test_obj.zsl_enabled = enable_zsl;
2047 rc = mm_camera_lib_start_stream(handle);
2048 if (rc != MM_CAMERA_OK) {
2049 LOGE("mm_camera_lib_start_stream() err=%d\n",
2050 rc);
2051 goto EXIT;
2052 }
2053 } else {
2054 handle->test_obj.zsl_enabled = enable_zsl;
2055 }
2056 }
2057 break;
2058 case MM_CAMERA_LIB_RAW_CAPTURE:
2059
2060 if ( 0 == handle->stream_running ) {
2061 LOGE(" Streaming is not enabled!");
2062 rc = MM_CAMERA_E_INVALID_OPERATION;
2063 goto EXIT;
2064 }
2065
2066 rc = mm_camera_lib_stop_stream(handle);
2067 if (rc != MM_CAMERA_OK) {
2068 LOGE("mm_camera_lib_stop_stream() err=%d\n",
2069 rc);
2070 goto EXIT;
2071 }
2072
2073 width = handle->test_obj.buffer_width;
2074 height = handle->test_obj.buffer_height;
2075 handle->test_obj.buffer_width =
2076 (uint32_t)camera_cap->raw_dim[0].width;
2077 handle->test_obj.buffer_height =
2078 (uint32_t)camera_cap->raw_dim[0].height;
2079 handle->test_obj.buffer_format = DEFAULT_RAW_FORMAT;
2080 LOGE("MM_CAMERA_LIB_RAW_CAPTURE %dx%d\n",
2081 camera_cap->raw_dim[0].width,
2082 camera_cap->raw_dim[0].height);
2083 rc = mm_app_start_capture_raw(&handle->test_obj, 1);
2084 if (rc != MM_CAMERA_OK) {
2085 LOGE("mm_app_start_capture() err=%d\n",
2086 rc);
2087 goto EXIT;
2088 }
2089
2090 mm_camera_app_wait();
2091
2092 rc = mm_app_stop_capture_raw(&handle->test_obj);
2093 if (rc != MM_CAMERA_OK) {
2094 LOGE("mm_app_stop_capture() err=%d\n",
2095 rc);
2096 goto EXIT;
2097 }
2098
2099 handle->test_obj.buffer_width = width;
2100 handle->test_obj.buffer_height = height;
2101 handle->test_obj.buffer_format = DEFAULT_SNAPSHOT_FORMAT;
2102 rc = mm_camera_lib_start_stream(handle);
2103 if (rc != MM_CAMERA_OK) {
2104 LOGE("mm_camera_lib_start_stream() err=%d\n",
2105 rc);
2106 goto EXIT;
2107 }
2108
2109 break;
2110
2111 case MM_CAMERA_LIB_JPEG_CAPTURE:
2112 if ( 0 == handle->stream_running ) {
2113 LOGE(" Streaming is not enabled!");
2114 rc = MM_CAMERA_E_INVALID_OPERATION;
2115 goto EXIT;
2116 }
2117
2118 if ( NULL != in_data ) {
2119 dim = ( mm_camera_lib_snapshot_params * ) in_data;
2120 }
2121
2122 rc = tuneserver_capture(handle, dim);
2123 if (rc != MM_CAMERA_OK) {
2124 LOGE("capture error %d\n", rc);
2125 goto EXIT;
2126 }
2127 break;
2128
2129 case MM_CAMERA_LIB_SET_FOCUS_MODE: {
2130 cam_focus_mode_type mode = *((cam_focus_mode_type *)in_data);
2131 handle->current_params.af_mode = mode;
2132 rc = setFocusMode(&handle->test_obj, mode);
2133 if (rc != MM_CAMERA_OK) {
2134 LOGE("autofocus error\n");
2135 goto EXIT;
2136 }
2137 break;
2138 }
2139
2140 case MM_CAMERA_LIB_DO_AF:
2141 if (handle->test_obj.focus_supported) {
2142 rc = handle->test_obj.cam->ops->do_auto_focus(handle->test_obj.cam->camera_handle);
2143 if (rc != MM_CAMERA_OK) {
2144 LOGE("autofocus error\n");
2145 goto EXIT;
2146 }
2147 /*Waiting for Auto Focus Done Call Back*/
2148 mm_camera_app_wait();
2149 }
2150 break;
2151
2152 case MM_CAMERA_LIB_CANCEL_AF:
2153 rc = handle->test_obj.cam->ops->cancel_auto_focus(handle->test_obj.cam->camera_handle);
2154 if (rc != MM_CAMERA_OK) {
2155 LOGE("autofocus error\n");
2156 goto EXIT;
2157 }
2158
2159 break;
2160
2161 case MM_CAMERA_LIB_LOCK_AWB:
2162 rc = setAwbLock(&handle->test_obj, 1);
2163 if (rc != MM_CAMERA_OK) {
2164 LOGE("AWB locking failed\n");
2165 goto EXIT;
2166 }
2167 break;
2168
2169 case MM_CAMERA_LIB_UNLOCK_AWB:
2170 rc = setAwbLock(&handle->test_obj, 0);
2171 if (rc != MM_CAMERA_OK) {
2172 LOGE("AE unlocking failed\n");
2173 goto EXIT;
2174 }
2175 break;
2176
2177 case MM_CAMERA_LIB_LOCK_AE:
2178 rc = setAecLock(&handle->test_obj, 1);
2179 if (rc != MM_CAMERA_OK) {
2180 LOGE("AE locking failed\n");
2181 goto EXIT;
2182 }
2183 break;
2184
2185 case MM_CAMERA_LIB_UNLOCK_AE:
2186 rc = setAecLock(&handle->test_obj, 0);
2187 if (rc != MM_CAMERA_OK) {
2188 LOGE("AE unlocking failed\n");
2189 goto EXIT;
2190 }
2191 break;
2192
2193 case MM_CAMERA_LIB_SET_3A_COMMAND: {
2194 rc = set3Acommand(&handle->test_obj, (cam_eztune_cmd_data_t *)in_data);
2195 if (rc != MM_CAMERA_OK) {
2196 LOGE("3A set command error\n");
2197 goto EXIT;
2198 }
2199 break;
2200 }
2201
2202 case MM_CAMERA_LIB_SET_AUTOFOCUS_TUNING: {
2203 rc = setAutoFocusTuning(&handle->test_obj, in_data);
2204 if (rc != MM_CAMERA_OK) {
2205 LOGE("Set AF tuning failed\n");
2206 goto EXIT;
2207 }
2208 break;
2209 }
2210
2211 case MM_CAMERA_LIB_SET_VFE_COMMAND: {
2212 rc = setVfeCommand(&handle->test_obj, in_data);
2213 if (rc != MM_CAMERA_OK) {
2214 LOGE("Set vfe command failed\n");
2215 goto EXIT;
2216 }
2217 break;
2218 }
2219
2220 case MM_CAMERA_LIB_SET_POSTPROC_COMMAND: {
2221 rc = setPPCommand(&handle->test_obj, in_data);
2222 if (rc != MM_CAMERA_OK) {
2223 LOGE("Set pp command failed\n");
2224 goto EXIT;
2225 }
2226 break;
2227 }
2228
2229 case MM_CAMERA_LIB_WNR_ENABLE: {
2230 rc = setWNR(&handle->test_obj, *((uint8_t *)in_data));
2231 if ( rc != MM_CAMERA_OK) {
2232 LOGE("Set wnr enable failed\n");
2233 goto EXIT;
2234 }
2235 }
2236
2237 case MM_CAMERA_LIB_NO_ACTION:
2238 default:
2239 break;
2240 };
2241
2242 EXIT:
2243
2244 return rc;
2245 }
mm_camera_lib_number_of_cameras(mm_camera_lib_handle * handle)2246 int mm_camera_lib_number_of_cameras(mm_camera_lib_handle *handle)
2247 {
2248 int rc = 0;
2249
2250 if ( NULL == handle ) {
2251 LOGE(" Invalid handle");
2252 goto EXIT;
2253 }
2254
2255 rc = handle->app_ctx.num_cameras;
2256
2257 EXIT:
2258
2259 return rc;
2260 }
2261
mm_camera_lib_close(mm_camera_lib_handle * handle)2262 int mm_camera_lib_close(mm_camera_lib_handle *handle)
2263 {
2264 int rc = MM_CAMERA_OK;
2265
2266 if ( NULL == handle ) {
2267 LOGE(" Invalid handle");
2268 rc = MM_CAMERA_E_INVALID_INPUT;
2269 goto EXIT;
2270 }
2271
2272 //rc = mm_app_close_fb(&handle->test_obj);
2273 rc = MM_CAMERA_OK;
2274 if (rc != MM_CAMERA_OK) {
2275 LOGE("mm_app_close_fb() err=%d\n",
2276 rc);
2277 goto EXIT;
2278 }
2279
2280 rc = mm_app_close(&handle->test_obj);
2281 if (rc != MM_CAMERA_OK) {
2282 LOGE("mm_app_close() err=%d\n",
2283 rc);
2284 goto EXIT;
2285 }
2286
2287 EXIT:
2288 return rc;
2289 }
2290
mm_camera_lib_set_preview_usercb(mm_camera_lib_handle * handle,cam_stream_user_cb cb)2291 int mm_camera_lib_set_preview_usercb(
2292 mm_camera_lib_handle *handle, cam_stream_user_cb cb)
2293 {
2294 if (handle->test_obj.user_preview_cb != NULL) {
2295 LOGE(" already set preview callbacks\n");
2296 return -1;
2297 }
2298 handle->test_obj.user_preview_cb = *cb;
2299 return 0;
2300 }
2301
mm_app_set_preview_fps_range(mm_camera_test_obj_t * test_obj,cam_fps_range_t * fpsRange)2302 int mm_app_set_preview_fps_range(mm_camera_test_obj_t *test_obj,
2303 cam_fps_range_t *fpsRange)
2304 {
2305 int rc = MM_CAMERA_OK;
2306 LOGH("preview fps range: min=%f, max=%f.",
2307 fpsRange->min_fps, fpsRange->max_fps);
2308 rc = setFPSRange(test_obj, *fpsRange);
2309
2310 if (rc != MM_CAMERA_OK) {
2311 LOGE("add_parm_entry_tobatch failed !!");
2312 return rc;
2313 }
2314
2315 return rc;
2316 }
2317
mm_app_set_face_detection(mm_camera_test_obj_t * test_obj,cam_fd_set_parm_t * fd_set_parm)2318 int mm_app_set_face_detection(mm_camera_test_obj_t *test_obj,
2319 cam_fd_set_parm_t *fd_set_parm)
2320 {
2321 int rc = MM_CAMERA_OK;
2322
2323 if (test_obj == NULL || fd_set_parm == NULL) {
2324 LOGE(" invalid params!");
2325 return MM_CAMERA_E_INVALID_INPUT;
2326 }
2327
2328 LOGH("mode = %d, num_fd = %d",
2329 fd_set_parm->fd_mode, fd_set_parm->num_fd);
2330
2331 rc = initBatchUpdate(test_obj);
2332 if (rc != MM_CAMERA_OK) {
2333 LOGE("Batch camera parameter update failed\n");
2334 goto ERROR;
2335 }
2336
2337 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
2338 CAM_INTF_PARM_FD, *fd_set_parm)) {
2339 LOGE("FD parameter not added to batch\n");
2340 rc = -1;
2341 goto ERROR;
2342 }
2343
2344 rc = commitSetBatch(test_obj);
2345 if (rc != MM_CAMERA_OK) {
2346 LOGE("Batch parameters commit failed\n");
2347 goto ERROR;
2348 }
2349
2350 ERROR:
2351 return rc;
2352 }
2353
mm_app_set_flash_mode(mm_camera_test_obj_t * test_obj,cam_flash_mode_t flashMode)2354 int mm_app_set_flash_mode(mm_camera_test_obj_t *test_obj,
2355 cam_flash_mode_t flashMode)
2356 {
2357 int rc = MM_CAMERA_OK;
2358
2359 if (test_obj == NULL) {
2360 LOGE(" invalid params!");
2361 return MM_CAMERA_E_INVALID_INPUT;
2362 }
2363
2364 LOGH("mode = %d", (int)flashMode);
2365
2366 rc = initBatchUpdate(test_obj);
2367 if (rc != MM_CAMERA_OK) {
2368 LOGE("Batch camera parameter update failed\n");
2369 goto ERROR;
2370 }
2371
2372 if (ADD_SET_PARAM_ENTRY_TO_BATCH(test_obj->parm_buf.mem_info.data,
2373 CAM_INTF_PARM_LED_MODE, flashMode)) {
2374 LOGE("Flash mode parameter not added to batch\n");
2375 rc = -1;
2376 goto ERROR;
2377 }
2378
2379 rc = commitSetBatch(test_obj);
2380 if (rc != MM_CAMERA_OK) {
2381 LOGE("Batch parameters commit failed\n");
2382 goto ERROR;
2383 }
2384
2385 ERROR:
2386 return rc;
2387 }
2388
mm_app_set_metadata_usercb(mm_camera_test_obj_t * test_obj,cam_stream_user_cb usercb)2389 int mm_app_set_metadata_usercb(mm_camera_test_obj_t *test_obj,
2390 cam_stream_user_cb usercb)
2391 {
2392 if (test_obj == NULL || usercb == NULL) {
2393 LOGE(" invalid params!");
2394 return MM_CAMERA_E_INVALID_INPUT;
2395 }
2396
2397 LOGH("%s, set user metadata callback, addr: %p\n", usercb);
2398
2399 if (test_obj->user_metadata_cb != NULL) {
2400 LOGH("%s, already set user metadata callback");
2401 }
2402 test_obj->user_metadata_cb = usercb;
2403
2404 return 0;
2405 }
2406
2407
2408