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