Add flag to invoke preview callback
[platform/core/api/camera.git] / src / camera.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <unistd.h>
22 #include <mm.h>
23 #include <mm_types.h>
24 #include <mm_camcorder.h>
25 #include <muse_camera_msg.h>
26 #include <camera_private.h>
27 #include <muse_client.h>
28 #include <dlog.h>
29 #include <gio/gio.h>
30 #include <dlfcn.h>
31
32 #ifdef LOG_TAG
33 #undef LOG_TAG
34 #endif
35 #define LOG_TAG         "TIZEN_N_CAMERA"
36 #define MODULE_NAME     "camera"
37 #define LIB_CAMERA_DEVICE_MANAGER PATH_LIBDIR"/libcamera_device_manager.so"
38 #define CAMERA_CHECK_DEVICE_MANAGER \
39         do {\
40                 if (access(LIB_CAMERA_DEVICE_MANAGER, F_OK) != 0) {\
41                         CAM_LOG_ERROR("no camera device maanger[errno:%d]", errno);\
42                         return CAMERA_ERROR_NOT_SUPPORTED;\
43                 }\
44         } while (0)
45
46
47 /* for camera device manager */
48 typedef struct _cdm_symbol_table {
49         void **func_ptr;
50         const char *func_name;
51 } cdm_symbol_table;
52
53 /* for device changed callback */
54 static GMutex g_cam_dev_state_changed_cb_lock;
55 static GList *g_cam_dev_state_changed_cb_list;
56 static int g_cam_dev_state_changed_cb_id;
57 static GDBusConnection *g_cam_dev_state_changed_cb_conn;
58 static guint g_cam_dev_state_changed_cb_subscribe_id;
59 static GMutex g_cam_idle_event_lock;
60
61 /* log level */
62 static int g_camera_log_level = CAMERA_LOG_LEVEL_INFO;
63
64 static bool __camera_import_tbm_fd(tbm_bufmgr bufmgr, int fd, tbm_bo *bo, tbm_bo_handle *bo_handle);
65 static void __camera_release_imported_bo(tbm_bo *bo);
66
67 static int __camera_create_media_packet(camera_cb_info_s *cb_info, MMCamcorderVideoStreamDataType *stream,
68         camera_media_packet_data *mp_data, media_packet_h *packet);
69 static int __camera_create_media_packet_data(int ret_fd, int *tfd, int num_buffer_fd, tbm_bo bo,
70         tbm_bo *buffer_bo, tbm_bo data_bo, camera_media_packet_data **mp_data);
71 static void __camera_release_media_packet_data(camera_media_packet_data *mp_data, camera_cb_info_s *cb_info);
72
73 static gboolean __camera_allocate_preview_buffer(camera_h camera);
74 static void __camera_release_preview_buffer(camera_h camera);
75 static void __camera_release_tfd(int tfd[MUSE_NUM_FD]);
76
77 static bool __create_msg_handler_thread(camera_msg_handler_info_s *handler_info,
78         int type, const char *thread_name, camera_cb_info_s *cb_info);
79 static void __destroy_msg_handler_thread(camera_msg_handler_info_s *handler_info);
80
81
82 //LCOV_EXCL_START
83 static gboolean __camera_allocate_preview_buffer(camera_h camera)
84 {
85         int i = 0;
86         int ret = CAMERA_ERROR_NONE;
87         int format = CAMERA_PIXEL_FORMAT_INVALID;
88         int width = 0;
89         int height = 0;
90         int buffer_size = 0;
91         camera_cli_s *pc = (camera_cli_s *)camera;
92         camera_cb_info_s *cb_info = NULL;
93
94         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, FALSE);
95
96         cb_info = pc->cb_info;
97
98         CAM_LOG_INFO("Enter");
99
100         /* get preview info and calculate size */
101         ret = camera_get_preview_format(camera, &format);
102         if (ret != CAMERA_ERROR_NONE) {
103                 CAM_LOG_ERROR("get preview format failed 0x%x", ret);
104                 return FALSE;
105         }
106
107         ret = camera_get_preview_resolution(camera, &width, &height);
108         if (ret != CAMERA_ERROR_NONE) {
109                 CAM_LOG_ERROR("get preview resolution failed 0x%x", ret);
110                 return FALSE;
111         }
112
113         CAM_LOG_INFO("preview %dx%d, format %d", width, height, format);
114
115         switch (format) {
116         case CAMERA_PIXEL_FORMAT_INVZ:
117                 buffer_size = width * height;
118                 break;
119         case CAMERA_PIXEL_FORMAT_NV12:
120         case CAMERA_PIXEL_FORMAT_I420:
121                 buffer_size = (width * height * 3) >> 1;
122                 break;
123         case CAMERA_PIXEL_FORMAT_YUYV:
124         case CAMERA_PIXEL_FORMAT_UYVY:
125                 buffer_size = width * height * 2;
126                 break;
127         default:
128                 CAM_LOG_ERROR("unhandled format %d", format);
129                 goto _ALLOCATE_PREVIEW_BUFFER_FAILED;
130         }
131
132         CAM_LOG_INFO("buffer size %d, num %d", buffer_size, MUSE_NUM_FD);
133
134         for (i = 0 ; i < MUSE_NUM_FD ; i++) {
135                 cb_info->bos[i] = tbm_bo_alloc(cb_info->bufmgr, buffer_size, TBM_BO_DEFAULT);
136                 if (!cb_info->bos[i]) {
137                         CAM_LOG_ERROR("bo alloc failed [%d,i:%d]", buffer_size, i);
138                         goto _ALLOCATE_PREVIEW_BUFFER_FAILED;
139                 }
140
141                 cb_info->fds[i] = tbm_bo_export_fd(cb_info->bos[i]);
142                 if (cb_info->fds[i] < 0) {
143                         CAM_LOG_ERROR("export fd failed [%d,i:%d] errno %d", buffer_size, i, errno);
144                         goto _ALLOCATE_PREVIEW_BUFFER_FAILED;
145                 }
146
147                 CAM_LOG_INFO("bo %p, fd %d", cb_info->bos[i], cb_info->fds[i]);
148         }
149
150         CAM_LOG_INFO("Done");
151
152         return TRUE;
153
154 _ALLOCATE_PREVIEW_BUFFER_FAILED:
155         __camera_release_preview_buffer(camera);
156         return FALSE;
157 }
158
159
160 static void __camera_release_preview_buffer(camera_h camera)
161 {
162         int i = 0;
163         camera_cli_s *pc = (camera_cli_s *)camera;
164         camera_cb_info_s *cb_info = NULL;
165
166         CAMERA_CHECK_HANDLE_RETURN(pc);
167
168         CAM_LOG_INFO("Enter");
169
170         cb_info = pc->cb_info;
171
172         /* close exported fd and bos */
173         for (i = 0 ; i < MUSE_NUM_FD ; i++) {
174                 CAM_LOG_INFO("unref bo %p, close fd %d", cb_info->bos[i], cb_info->fds[i]);
175
176                 if (cb_info->bos[i]) {
177                         tbm_bo_unref(cb_info->bos[i]);
178                         cb_info->bos[i] = NULL;
179                 } else {
180                         break;
181                 }
182
183                 if (CAMERA_IS_FD_VALID(cb_info->fds[i])) {
184                         close(cb_info->fds[i]);
185                         cb_info->fds[i] = CAMERA_FD_INIT;
186                 }
187         }
188
189         CAM_LOG_INFO("Done");
190 }
191 //LCOV_EXCL_STOP
192
193 static void __camera_release_tfd(int tfd[MUSE_NUM_FD])
194 {
195         int i;
196
197         if (!tfd) {
198                 CAM_LOG_WARNING("NULL tfd");
199                 return;
200         }
201
202         for (i = 0 ; i < MUSE_NUM_FD ; i++) {
203                 if (!CAMERA_IS_FD_VALID(tfd[i]))
204                         break;
205
206                 close(tfd[i]);
207                 tfd[i] = CAMERA_FD_INIT;
208         }
209 }
210
211
212 void _camera_update_api_waiting(camera_cb_info_s *cb_info, int api, int value)
213 {
214         if (!cb_info ||
215                 api < 0 || api >= MUSE_CAMERA_API_MAX) {
216                 CAM_LOG_ERROR("invalid param %p %d", cb_info, api);
217                 return;
218         }
219
220         g_mutex_lock(&(cb_info->api_mutex[api]));
221         cb_info->api_waiting[api] += value;
222         g_mutex_unlock(&(cb_info->api_mutex[api]));
223
224         CAM_LOG_DEBUG("api[%d], value[%d], waiting[%d]",
225                 api, value, cb_info->api_waiting[api]);
226 }
227
228
229 static void __camera_device_state_changed_cb(GDBusConnection *connection,
230         const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
231         const gchar *signal_name, GVariant *param, gpointer user_data)
232 {
233         int value = 0;
234         camera_device_e device = CAMERA_DEVICE_CAMERA0;
235         camera_device_state_e state = CAMERA_DEVICE_STATE_NULL;
236         GList *tmp_list = NULL;
237         camera_cb_info *info = NULL;
238
239         g_mutex_lock(&g_cam_dev_state_changed_cb_lock);
240
241         if (!g_cam_dev_state_changed_cb_list || !param) {
242                 CAM_LOG_WARNING("no callback or NULL param %p", param);
243                 goto _DONE;
244         }
245
246         /* get device and state */
247         g_variant_get(param, "(i)", &value);
248
249         device = value >> 16;
250         state = 0x0000ffff & value;
251
252         CAM_LOG_INFO("device %d, state %d", device, state);
253
254         tmp_list = g_cam_dev_state_changed_cb_list;
255
256         do {
257                 info = (camera_cb_info *)tmp_list->data;
258
259                 if (info) {
260                         if (info->callback) {
261                                 CAM_LOG_INFO("start id[%d] callback", info->id);
262                                 ((camera_device_state_changed_cb)info->callback)(device, state, info->user_data);
263                                 CAM_LOG_INFO("returned id[%d] callback", info->id);
264                         } else {
265                                 CAM_LOG_WARNING("NULL callback for id %d", info->id);
266                         }
267                 }
268
269                 tmp_list = tmp_list->next;
270         } while (tmp_list);
271
272 _DONE:
273         g_mutex_unlock(&g_cam_dev_state_changed_cb_lock);
274 }
275
276
277 static void __camera_event_handler_preview(camera_cb_info_s *cb_info, char *recv_msg, int *tfd)
278 {
279         int i = 0;
280         int ret = 0;
281         int ret_fd = CAMERA_FD_INIT;
282         int preview_fd = CAMERA_FD_INIT;
283         int num_buffer_fd = 0;
284         unsigned char *buf_pos = NULL;
285
286         tbm_bo bo = NULL;
287         tbm_bo buffer_bo[BUFFER_MAX_PLANE_NUM] = {NULL, };
288         tbm_bo_handle bo_handle = {.ptr = NULL};
289         tbm_bo_handle buffer_bo_handle[BUFFER_MAX_PLANE_NUM] = {{.ptr = NULL}, };
290         tbm_bo data_bo = NULL;
291         tbm_bo_handle data_bo_handle = {.ptr = NULL};
292
293         camera_msg_param param;
294         camera_preview_data_s frame;
295         MMCamcorderVideoStreamDataType *stream = NULL;
296         camera_media_packet_data *mp_data = NULL;
297         media_packet_h pkt = NULL;
298
299         /* tfd[0]: MMCamcorderVideoStreamDataType
300            tfd[1]: data_bo or zero copy bo[0]
301            tfd[2]: zero copy bo[1]
302            tfd[3]: zero copy bo[2] */
303
304         if (!cb_info || !recv_msg || !tfd) {
305                 CAM_LOG_ERROR("invalid param %p %p %p", cb_info, recv_msg, tfd);
306                 return;
307         }
308
309         muse_camera_msg_get(preview_fd, recv_msg);
310         muse_camera_msg_get(num_buffer_fd, recv_msg);
311
312         CAM_LOG_DEBUG("preview_fd %d, num_buffer_fd %d", preview_fd, num_buffer_fd);
313
314         memset(&frame, 0x0, sizeof(camera_preview_data_s));
315
316         if (tfd[0] < 0) {
317                 CAM_LOG_ERROR("invalid fd %d", tfd[0]);
318                 return;
319         }
320
321         ret_fd = preview_fd;
322         CAMERA_MSG_PARAM_SET(param, INT, ret_fd);
323
324         if (cb_info->invoke_preview_cb == FALSE) {
325                 CAM_LOG_WARNING("Skip preview callback for fd[%d] due to preview stop.", ret_fd);
326                 goto _PREVIEW_CB_HANDLER_DONE;
327         }
328
329         if (num_buffer_fd < 0 || num_buffer_fd > BUFFER_MAX_PLANE_NUM) {
330                 CAM_LOG_ERROR("invalid num buffer fd %d", num_buffer_fd);
331                 goto _PREVIEW_CB_HANDLER_DONE;
332         }
333
334         /* import tbm bo and get virtual address */
335         if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[0], &bo, &bo_handle)) {
336                 CAM_LOG_ERROR("failed to import fd %d", tfd[0]);
337                 goto _PREVIEW_CB_HANDLER_DONE;
338         }
339
340         buf_pos = (unsigned char *)bo_handle.ptr;
341
342         /* get stream info */
343         stream = (MMCamcorderVideoStreamDataType *)buf_pos;
344
345         if (num_buffer_fd == 0 && CAMERA_IS_FD_VALID(tfd[1])) {
346                 /* import tbm data_bo and get virtual address */
347                 if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[1], &data_bo, &data_bo_handle)) {
348                         CAM_LOG_ERROR("failed to import data fd %d", tfd[1]);
349                         goto _PREVIEW_CB_HANDLER_DONE;
350                 }
351
352                 if (stream->data_type == MM_CAM_STREAM_DATA_ENCODED)
353                         stream->data.encoded.data = data_bo_handle.ptr;
354         } else {
355                 for (i = 0 ; i < num_buffer_fd ; i++) {
356                         /* import buffer bo and get virtual address */
357                         if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[i + 1], &buffer_bo[i], &buffer_bo_handle[i])) {
358                                 CAM_LOG_ERROR("failed to import buffer fd %d", tfd[i + 1]);
359                                 goto _PREVIEW_CB_HANDLER_DONE;
360                         }
361                 }
362
363                 if (stream->data_type == MM_CAM_STREAM_DATA_ENCODED)
364                         stream->data.encoded.data = buffer_bo_handle[0].ptr;
365         }
366
367         /* preview callback */
368         if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] ||
369                 cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]) {
370                 camera_create_preview_frame(stream, num_buffer_fd, buffer_bo_handle, &data_bo_handle, &frame);
371
372                 /* set stream data for camera_get_preview_frame_rotation() */
373                 cb_info->stream_data = stream;
374
375                 if (stream->extra_stream_id < 0) {
376                         if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW])
377                                 ((camera_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW])(&frame,
378                                         cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
379                 } else {
380                         if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW])
381                                 ((camera_extra_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW])(&frame,
382                                         stream->extra_stream_id, cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
383                 }
384
385                 cb_info->stream_data = NULL;
386         }
387
388         if (stream->extra_stream_id >= 0)
389                 goto _PREVIEW_CB_HANDLER_DONE;
390
391         /* make media packet with below cases.
392          * 1. media_packet_preview_cb is set
393          * 2. EVAS display rendering
394          * 3. media bridge is set
395          */
396         if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] ||
397                 cb_info->is_evas_render ||
398                 cb_info->bridge) {
399                 ret = __camera_create_media_packet_data(ret_fd, tfd, num_buffer_fd, bo, buffer_bo, data_bo, &mp_data);
400                 if (ret != CAMERA_ERROR_NONE) {
401                         CAM_LOG_ERROR("__camera_create_media_packet_data failed[0x%x]", ret);
402                         goto _PREVIEW_CB_HANDLER_DONE;
403                 }
404
405                 ret = __camera_create_media_packet(cb_info, stream, mp_data, &pkt);
406                 if (ret != CAMERA_ERROR_NONE) {
407                         CAM_LOG_ERROR("__camera_create_media_packet failed[0x%x]", ret);
408                         __camera_release_media_packet_data(mp_data, cb_info);
409                         mp_data = NULL;
410                         goto _PREVIEW_CB_HANDLER_DONE;
411                 }
412         }
413
414         /* 1. media packet preview callback */
415         if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]) {
416                 media_packet_ref(pkt);
417                 ((camera_media_packet_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW])(pkt,
418                         cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
419         }
420
421         /* 2. call evas renderer */
422         if (cb_info->is_evas_render) {
423                 if (cb_info->run_evas_render) {
424                         media_packet_ref(pkt);
425                         ret = mm_display_interface_evas_render(cb_info->dp_interface, pkt);
426                         if (ret != MM_ERROR_NONE) {
427                                 CAM_LOG_ERROR("mm_display_interface_evas_render failed[0x%x]", ret);
428                                 media_packet_unref(pkt);
429                         }
430                 } else {
431                         CAM_LOG_WARNING("evas renderer is stopped, skip this buffer...");
432                 }
433         }
434
435 //LCOV_EXCL_START
436         /* 3. media bridge */
437         g_mutex_lock(&cb_info->bridge_lock);
438
439         if (cb_info->bridge) {
440                 media_packet_ref(pkt);
441                 ret = media_bridge_push_packet(cb_info->bridge, pkt);
442                 if (ret != MEDIA_BRIDGE_ERROR_NONE) {
443                         CAM_LOG_ERROR("push packet to bridge failed[0x%x]", ret);
444                         media_packet_unref(pkt);
445                 }
446         }
447 //LCOV_EXCL_STOP
448
449         g_mutex_unlock(&cb_info->bridge_lock);
450
451 _PREVIEW_CB_HANDLER_DONE:
452         /* send PREVIEW_CB_RETURN message if zero copy buffer is used(num_buffer_fd is bigger than 0)
453            and preview callback(normal or media packet) is set. */
454         if (num_buffer_fd > 0 &&
455                 (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] ||
456                  cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]))
457                 _camera_msg_send(MUSE_CAMERA_API_PREVIEW_CB_RETURN, NULL, cb_info, NULL, 0);
458
459         if (pkt) {
460                 media_packet_unref(pkt);
461                 return;
462         }
463
464         /* return buffer */
465         _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
466
467         CAM_LOG_DEBUG("return buffer Done[tfd:%d, ret fd:%d]", tfd[0], ret_fd);
468
469         /* release imported bo and fd */
470         __camera_release_imported_bo(&data_bo);
471         __camera_release_imported_bo(&bo);
472
473         for (i = 0 ; i < num_buffer_fd && i < BUFFER_MAX_PLANE_NUM ; i++)
474                 __camera_release_imported_bo(&buffer_bo[i]);
475
476         __camera_release_tfd(tfd);
477 }
478
479
480 static void __camera_event_handler_capture(camera_cb_info_s *cb_info, char *recv_msg, int *tfd)
481 {
482         int tfd_index = 0;
483         int capture_fd_main = 0;
484         int capture_fd_post = 0;
485         int capture_fd_thumb = 0;
486         unsigned char *buf_pos = NULL;
487
488         camera_image_data_s *rImage = NULL;
489         camera_image_data_s *rPostview = NULL;
490         camera_image_data_s *rThumbnail = NULL;
491
492         tbm_bo bo_main = NULL;
493         tbm_bo bo_post = NULL;
494         tbm_bo bo_thumb = NULL;
495         tbm_bo_handle bo_main_handle = {.ptr = NULL};
496         tbm_bo_handle bo_post_handle = {.ptr = NULL};
497         tbm_bo_handle bo_thumb_handle = {.ptr = NULL};
498
499         if (!cb_info || !recv_msg || !tfd) {
500                 CAM_LOG_ERROR("invalid param %p %p %p", cb_info, recv_msg, tfd);
501                 return;
502         }
503
504         muse_camera_msg_get(capture_fd_main, recv_msg);
505         muse_camera_msg_get(capture_fd_post, recv_msg);
506         muse_camera_msg_get(capture_fd_thumb, recv_msg);
507
508         CAM_LOG_INFO("capture fd %d %d %d, received fd %d %d %d",
509                 capture_fd_main, capture_fd_post, capture_fd_thumb,
510                 tfd[0], tfd[1], tfd[2]);
511
512         if (capture_fd_main < 0 || tfd[tfd_index] < 0) {
513                 CAM_LOG_ERROR("invalid main fd %d %d", capture_fd_main, tfd[tfd_index]);
514                 goto _CAPTURE_CB_HANDLER_DONE;
515         }
516
517         if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE] == NULL) {
518                 CAM_LOG_WARNING("NULL callback");
519                 goto _CAPTURE_CB_HANDLER_DONE;
520         }
521
522         /* import tbm bo and get virtual address */
523         if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[tfd_index], &bo_main, &bo_main_handle)) {
524                 CAM_LOG_ERROR("failed to import fd [%d] for main", tfd[tfd_index]);
525                 goto _CAPTURE_CB_HANDLER_DONE;
526         }
527
528         buf_pos = (unsigned char *)bo_main_handle.ptr;
529         rImage = (camera_image_data_s *)buf_pos;
530         rImage->data = buf_pos + sizeof(camera_image_data_s);
531         if (rImage->exif && rImage->exif_size > 0) {
532                 rImage->exif = rImage->data + rImage->size;
533         } else {
534                 rImage->exif = NULL;
535                 rImage->exif_size = 0;
536         }
537
538         CAM_LOG_INFO("image info %dx%d, size %d, EXIF info %p, size %d",
539                 rImage->width, rImage->height, rImage->size, rImage->exif, rImage->exif_size);
540
541 //LCOV_EXCL_START
542         if (CAMERA_IS_FD_VALID(capture_fd_post)) {
543                 /* import tbm bo and get virtual address */
544                 tfd_index++;
545                 if (__camera_import_tbm_fd(cb_info->bufmgr, tfd[tfd_index], &bo_post, &bo_post_handle)) {
546                         buf_pos = (unsigned char *)bo_post_handle.ptr;
547                         rPostview = (camera_image_data_s *)buf_pos;
548                         CAM_LOG_INFO("rPostview->size : %d", rPostview->size);
549                         rPostview->data = buf_pos + sizeof(camera_image_data_s);
550                 } else {
551                         CAM_LOG_ERROR("failed to import fd [i:%d][%d] for postview", tfd_index, tfd[tfd_index]);
552                 }
553         }
554
555         if (CAMERA_IS_FD_VALID(capture_fd_thumb)) {
556                 /* import tbm bo and get virtual address */
557                 tfd_index++;
558                 if (__camera_import_tbm_fd(cb_info->bufmgr, tfd[tfd_index], &bo_thumb, &bo_thumb_handle)) {
559                         buf_pos = (unsigned char *)bo_thumb_handle.ptr;
560                         rThumbnail = (camera_image_data_s *)buf_pos;
561                         CAM_LOG_INFO("rThumbnail->size : %d", rThumbnail->size);
562                         rThumbnail->data = buf_pos + sizeof(camera_image_data_s);
563                 } else {
564                         CAM_LOG_ERROR("failed to import fd [%d] for thumbnail", tfd[tfd_index]);
565                 }
566         }
567 //LCOV_EXCL_STOP
568
569         ((camera_capturing_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE])(rImage,
570                 rPostview, rThumbnail, cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE]);
571
572 _CAPTURE_CB_HANDLER_DONE:
573         /* return buffer */
574         if (CAMERA_IS_FD_VALID(capture_fd_main)) {
575                 __camera_release_imported_bo(&bo_main);
576                 _camera_msg_return_buffer(capture_fd_main, cb_info);
577         }
578
579         if (CAMERA_IS_FD_VALID(capture_fd_post)) {
580                 __camera_release_imported_bo(&bo_post);
581                 _camera_msg_return_buffer(capture_fd_post, cb_info);
582         }
583
584         if (CAMERA_IS_FD_VALID(capture_fd_thumb)) {
585                 __camera_release_imported_bo(&bo_thumb);
586                 _camera_msg_return_buffer(capture_fd_thumb, cb_info);
587         }
588
589         __camera_release_tfd(tfd);
590
591         CAM_LOG_INFO("return buffer done");
592 }
593
594
595 //LCOV_EXCL_START
596 static void __camera_event_handler_face_detection(camera_cb_info_s *cb_info, char *recv_msg, int *tfd)
597 {
598         int count = 0;
599         int face_fd = CAMERA_FD_INIT;
600         camera_detected_face_s *faces = NULL;
601
602         tbm_bo bo = NULL;
603         tbm_bo_handle bo_handle = {.ptr = NULL};
604
605         if (!cb_info || !recv_msg || !tfd) {
606                 CAM_LOG_ERROR("invalid param %p %p %p", cb_info, recv_msg, tfd);
607                 return;
608         }
609
610         muse_camera_msg_get(count, recv_msg);
611         muse_camera_msg_get(face_fd, recv_msg);
612
613         if (count >= 0 && cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]) {
614                 CAM_LOG_INFO("FACE_DETECTION - count %d, fd %d", count, tfd[0]);
615
616                 if (CAMERA_IS_FD_VALID(tfd[0])) {
617                         if (__camera_import_tbm_fd(cb_info->bufmgr, tfd[0], &bo, &bo_handle)) {
618                                 /* set face info */
619                                 faces = bo_handle.ptr;
620                         }
621
622                         close(tfd[0]);
623                         tfd[0] = CAMERA_FD_INIT;
624                 }
625
626                 ((camera_face_detected_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION])(faces,
627                         count, cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
628
629                 /* release bo */
630                 __camera_release_imported_bo(&bo);
631         } else {
632                 CAM_LOG_WARNING("skip face detection message [count %d, fd %d, cb %p]",
633                         count, tfd[0], cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
634         }
635
636         /* return buffer */
637         _camera_msg_return_buffer(face_fd, cb_info);
638 }
639 //LCOV_EXCL_STOP
640
641
642 static bool __camera_import_tbm_fd(tbm_bufmgr bufmgr, int fd, tbm_bo *bo, tbm_bo_handle *bo_handle)
643 {
644         tbm_bo tmp_bo = NULL;
645         tbm_bo_handle tmp_bo_handle = {NULL, };
646
647         if (!bufmgr || !bo || !bo_handle || fd < 0) {
648                 CAM_LOG_ERROR("invalid parameter - %p %p %p, fd %d",
649                      bufmgr, bo, bo_handle, fd);
650                 return false;
651         }
652
653         tmp_bo = tbm_bo_import_fd(bufmgr, (tbm_fd)fd);
654         if (tmp_bo == NULL) {
655                 CAM_LOG_ERROR("import failed - fd %d", fd);
656                 return false;
657         }
658
659         tmp_bo_handle = tbm_bo_get_handle(tmp_bo, TBM_DEVICE_CPU);
660         if (tmp_bo_handle.ptr == NULL) {
661                 CAM_LOG_ERROR("tbm_bo_get_handle() failed %p", tmp_bo);
662                 tbm_bo_unref(tmp_bo);
663                 tmp_bo = NULL;
664                 return false;
665         }
666
667         /* set bo and bo_handle */
668         *bo = tmp_bo;
669         *bo_handle = tmp_bo_handle;
670
671         CAM_LOG_VERBOSE("fd[%d] -> bo[%p]", fd, tmp_bo);
672
673         return true;
674 }
675
676 static void __camera_release_imported_bo(tbm_bo *bo)
677 {
678         if (!bo || !(*bo)) {
679                 CAM_LOG_DEBUG("NULL bo");
680                 return;
681         }
682
683         tbm_bo_unref(*bo);
684         *bo = NULL;
685 }
686
687
688 static bool __is_supported(camera_h camera, muse_camera_api_e api)
689 {
690         int ret = CAMERA_ERROR_NONE;
691         camera_cli_s *pc = (camera_cli_s *)camera;
692
693         if (!pc || !pc->cb_info) {
694                 CAM_LOG_ERROR("api[%d] NULL handle[%p]", api, pc);
695                 set_last_result(CAMERA_ERROR_INVALID_PARAMETER);
696                 return false;
697         }
698
699         CAM_LOG_INFO("Enter - api[%d]", api);
700
701         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
702
703         CAM_LOG_INFO("Leave - api[%d], ret[%d]", api, ret);
704
705         return !!ret;
706 }
707
708
709 static int __set_mode(camera_h camera, muse_camera_api_e api, int set_mode)
710 {
711         int ret = CAMERA_ERROR_NONE;
712         camera_cli_s *pc = (camera_cli_s *)camera;
713         camera_msg_param param;
714
715         if (!pc || !pc->cb_info) {
716                 CAM_LOG_ERROR("api[%d] NULL handle[%p]", api, pc);
717                 return CAMERA_ERROR_INVALID_PARAMETER;
718         }
719
720         CAM_LOG_INFO("Enter - api[%d], mode[%d]", api, set_mode);
721
722         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
723
724         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
725
726         CAM_LOG_INFO("Leave - api[%d], ret[0x%x]", api, ret);
727
728         return ret;
729 }
730
731
732 static int __set_enable(camera_h camera, muse_camera_api_e api, int set_enable)
733 {
734         int ret = CAMERA_ERROR_NONE;
735         camera_cli_s *pc = (camera_cli_s *)camera;
736         camera_msg_param param;
737
738         if (!pc || !pc->cb_info) {
739                 CAM_LOG_ERROR("api[%d] NULL handle[%p]", api, pc);
740                 return CAMERA_ERROR_INVALID_PARAMETER;
741         }
742
743         CAM_LOG_INFO("Enter - api[%d], enable[%d]", api, set_enable);
744
745         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
746
747         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
748
749         CAM_LOG_INFO("Leave - api[%d], ret[0x%x]", api, ret);
750
751         return ret;
752 }
753
754
755 void _camera_send_message_get_return(camera_cb_info_s *cb_info, muse_camera_api_e api, char *msg, int time_out, int *ret)
756 {
757         int send_ret = 0;
758
759         if (!msg) {
760                 CAM_LOG_ERROR("api[%d] message failed", api);
761                 if (ret)
762                         *ret = CAMERA_ERROR_OUT_OF_MEMORY;
763
764                 return;
765         }
766
767         if (api != MUSE_CAMERA_API_RETURN_BUFFER && api != MUSE_CAMERA_API_PREVIEW_CB_RETURN)
768                 CAM_LOG_INFO("api[%d], message[%s]", api, msg);
769         else
770                 CAM_LOG_DEBUG("api[%d], message[%s]", api, msg);
771
772         if (cb_info->is_server_connected) {
773                 _camera_update_api_waiting(cb_info, api, 1);
774
775                 g_mutex_lock(&cb_info->fd_lock);
776                 send_ret = muse_core_msg_send(cb_info->fd, msg);
777                 g_mutex_unlock(&cb_info->fd_lock);
778         }
779
780         if (send_ret < 0) {
781                 CAM_LOG_ERROR("message send failed");
782                 if (ret)
783                         *ret = CAMERA_ERROR_INVALID_OPERATION;
784         } else {
785                 if (ret)
786                         *ret = _camera_client_wait_for_cb_return(api, cb_info, time_out);
787         }
788
789         _camera_update_api_waiting(cb_info, api, -1);
790
791         muse_core_msg_free(msg);
792
793         if (api != MUSE_CAMERA_API_RETURN_BUFFER && api != MUSE_CAMERA_API_PREVIEW_CB_RETURN)
794                 CAM_LOG_INFO("api[%d] ret[0x%x]", api, ret ? *ret : 0x0);
795         else
796                 CAM_LOG_DEBUG("api[%d] ret[0x%x]", api, ret ? *ret : 0x0);
797 }
798
799
800 int _camera_client_wait_for_cb_return(muse_camera_api_e api, camera_cb_info_s *cb_info, int time_out)
801 {
802         int ret = CAMERA_ERROR_NONE;
803         gint64 end_time;
804
805         if (!cb_info->is_server_connected) {
806                 CAM_LOG_ERROR("server is disconnected");
807                 return CAMERA_ERROR_SERVICE_DISCONNECTED;
808         }
809
810         g_mutex_lock(&(cb_info->api_mutex[api]));
811
812         CAM_LOG_INFO("api [%d], timeout [%d sec]", api, time_out);
813
814         end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
815
816         while (!cb_info->api_activating[api]) {
817                 if (time_out == CAMERA_CB_NO_TIMEOUT) {
818                         g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]));
819                         CAM_LOG_WARNING("api %d returned 0x%x", api, cb_info->api_ret[api]);
820                 } else if (!g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
821                         CAM_LOG_ERROR("api %d TIMED OUT!", api);
822                         ret = CAMERA_ERROR_INVALID_OPERATION;
823                         goto _CB_RETURN_END;
824                 }
825
826                 if (!cb_info->is_server_connected) {
827                         ret = CAMERA_ERROR_SERVICE_DISCONNECTED;
828                         goto _CB_RETURN_END;
829                 }
830
831                 if (!cb_info->api_activating[api])
832                         CAM_LOG_WARNING("invalid signal received, wait again...");
833         }
834
835         ret = cb_info->api_ret[api];
836         cb_info->api_activating[api] = FALSE;
837
838 _CB_RETURN_END:
839         g_mutex_unlock(&(cb_info->api_mutex[api]));
840
841         if (ret != CAMERA_ERROR_NONE)
842                 CAM_LOG_ERROR("api %d : error 0x%x", api, ret);
843
844         return ret;
845 }
846
847
848 void _camera_msg_send(int api, int *fds, camera_cb_info_s *cb_info,
849         int *ret, int timeout)
850 {
851         char *msg = NULL;
852
853         if (!cb_info) {
854                 CAM_LOG_ERROR("NULL info - api %d", api);
855
856                 if (ret)
857                         *ret = CAMERA_ERROR_INVALID_PARAMETER;
858
859                 return;
860         }
861
862         msg = muse_core_msg_new(api, NULL);
863
864         _camera_send_message_get_return(cb_info, api, msg, timeout, ret);
865 }
866
867
868 void _camera_msg_send_param1(int api, camera_cb_info_s *cb_info,
869         int *ret, camera_msg_param *param, int timeout)
870 {
871         int array_length;
872         char *msg = NULL;
873
874         if (!cb_info || !param) {
875                 CAM_LOG_ERROR("invalid pointer : api %d - %p %p", api, cb_info, param);
876
877                 if (ret)
878                         *ret = CAMERA_ERROR_INVALID_PARAMETER;
879
880                 return;
881         }
882
883         CAM_LOG_DEBUG("type[%d], name[%s]", param->type, param->name);
884
885         switch (param->type) {
886         case MUSE_TYPE_INT:
887                 msg = muse_core_msg_new(api,
888                         param->type, param->name, param->value.value_INT,
889                         NULL);
890                 break;
891         case MUSE_TYPE_STRING:
892                 msg = muse_core_msg_new(api,
893                         param->type, param->name, param->value.value_STRING,
894                         NULL);
895                 break;
896         case MUSE_TYPE_ARRAY:
897                 array_length = param->value_size / sizeof(int) + \
898                         (param->value_size % sizeof(int) ? 1 : 0);
899
900                 msg = muse_core_msg_new(api,
901                         param->type, param->name, array_length, param->value.value_ARRAY,
902                         NULL);
903                 break;
904         default:
905                 CAM_LOG_ERROR("unknown type %d", param->type);
906                 break;
907         }
908
909         _camera_send_message_get_return(cb_info, api, msg, timeout, ret);
910 }
911
912
913 void _camera_msg_send_param2_int(int api, camera_cb_info_s *cb_info,
914         int *ret, camera_msg_param *param0, camera_msg_param *param1, int timeout)
915 {
916         char *msg = NULL;
917
918         if (!cb_info || !param0 || !param1) {
919                 CAM_LOG_ERROR("invalid ptr %p %p %p : api %d",
920                         cb_info, param0, param1, api);
921
922                 if (ret)
923                         *ret = CAMERA_ERROR_INVALID_PARAMETER;
924
925                 return;
926         }
927
928         CAM_LOG_DEBUG("api[%d], param0[%s:%d], param1[%s:%d]",
929                 api,
930                 param0->name, param0->value.value_INT,
931                 param1->name, param1->value.value_INT);
932
933         msg = muse_core_msg_new(api,
934                 param0->type, param0->name, param0->value.value_INT,
935                 param1->type, param1->name, param1->value.value_INT,
936                 NULL);
937
938         _camera_send_message_get_return(cb_info, api, msg, timeout, ret);
939 }
940
941
942 void _camera_msg_return_buffer(int ret_fd, camera_cb_info_s *cb_info)
943 {
944         camera_msg_param param;
945
946         if (ret_fd < 0) {
947                 CAM_LOG_WARNING("invalid fd %d", ret_fd);
948                 return;
949         }
950
951         CAMERA_MSG_PARAM_SET(param, INT, ret_fd);
952
953         _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
954 }
955
956
957 int _camera_get_tbm_format(int in_format, uint32_t *out_format)
958 {
959         if (in_format <= MM_PIXEL_FORMAT_INVALID ||
960             in_format >= MM_PIXEL_FORMAT_NUM ||
961             out_format == NULL) {
962                 CAM_LOG_ERROR("INVALID_PARAMETER : in_format %d, out_format ptr %p", in_format, out_format);
963                 return CAMERA_ERROR_INVALID_PARAMETER;
964         }
965
966         switch (in_format) {
967         case MM_PIXEL_FORMAT_NV12:
968         case MM_PIXEL_FORMAT_NV12T:
969                 *out_format = TBM_FORMAT_NV12;
970                 break;
971 //LCOV_EXCL_START
972         case MM_PIXEL_FORMAT_NV16:
973                 *out_format = TBM_FORMAT_NV16;
974                 break;
975         case MM_PIXEL_FORMAT_NV21:
976                 *out_format = TBM_FORMAT_NV21;
977                 break;
978         case MM_PIXEL_FORMAT_YUYV:
979                 *out_format = TBM_FORMAT_YUYV;
980                 break;
981         case MM_PIXEL_FORMAT_UYVY:
982         case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
983                 *out_format = TBM_FORMAT_UYVY;
984                 break;
985         case MM_PIXEL_FORMAT_422P:
986                 *out_format = TBM_FORMAT_YUV422;
987                 break;
988         case MM_PIXEL_FORMAT_I420:
989                 *out_format = TBM_FORMAT_YUV420;
990                 break;
991         case MM_PIXEL_FORMAT_YV12:
992                 *out_format = TBM_FORMAT_YVU420;
993                 break;
994         case MM_PIXEL_FORMAT_RGB565:
995                 *out_format = TBM_FORMAT_RGB565;
996                 break;
997         case MM_PIXEL_FORMAT_RGB888:
998                 *out_format = TBM_FORMAT_RGB888;
999                 break;
1000         case MM_PIXEL_FORMAT_RGBA:
1001                 *out_format = TBM_FORMAT_RGBA8888;
1002                 break;
1003         case MM_PIXEL_FORMAT_ARGB:
1004                 *out_format = TBM_FORMAT_ARGB8888;
1005                 break;
1006         default:
1007                 CAM_LOG_ERROR("invalid in_format %d", in_format);
1008                 return CAMERA_ERROR_INVALID_PARAMETER;
1009 //LCOV_EXCL_STOP
1010         }
1011
1012         return CAMERA_ERROR_NONE;
1013 }
1014
1015
1016 int _camera_get_media_packet_mimetype(int in_format, media_format_mimetype_e *mimetype)
1017 {
1018         if (in_format <= MM_PIXEL_FORMAT_INVALID ||
1019             in_format >= MM_PIXEL_FORMAT_NUM ||
1020             mimetype == NULL) {
1021                 CAM_LOG_ERROR("INVALID_PARAMETER : in_format %d, mimetype ptr %p", in_format, mimetype);
1022                 return CAMERA_ERROR_INVALID_PARAMETER;
1023         }
1024
1025         switch (in_format) {
1026         case MM_PIXEL_FORMAT_NV12:
1027         case MM_PIXEL_FORMAT_NV12T:
1028                 *mimetype = MEDIA_FORMAT_NV12;
1029                 break;
1030 //LCOV_EXCL_START
1031         case MM_PIXEL_FORMAT_NV16:
1032                 *mimetype = MEDIA_FORMAT_NV16;
1033                 break;
1034         case MM_PIXEL_FORMAT_NV21:
1035                 *mimetype = MEDIA_FORMAT_NV21;
1036                 break;
1037         case MM_PIXEL_FORMAT_YUYV:
1038                 *mimetype = MEDIA_FORMAT_YUYV;
1039                 break;
1040         case MM_PIXEL_FORMAT_UYVY:
1041         case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
1042                 *mimetype = MEDIA_FORMAT_UYVY;
1043                 break;
1044         case MM_PIXEL_FORMAT_422P:
1045                 *mimetype = MEDIA_FORMAT_422P;
1046                 break;
1047         case MM_PIXEL_FORMAT_I420:
1048                 *mimetype = MEDIA_FORMAT_I420;
1049                 break;
1050         case MM_PIXEL_FORMAT_YV12:
1051                 *mimetype = MEDIA_FORMAT_YV12;
1052                 break;
1053         case MM_PIXEL_FORMAT_RGB565:
1054                 *mimetype = MEDIA_FORMAT_RGB565;
1055                 break;
1056         case MM_PIXEL_FORMAT_RGB888:
1057                 *mimetype = MEDIA_FORMAT_RGB888;
1058                 break;
1059         case MM_PIXEL_FORMAT_RGBA:
1060                 *mimetype = MEDIA_FORMAT_RGBA;
1061                 break;
1062         case MM_PIXEL_FORMAT_ARGB:
1063                 *mimetype = MEDIA_FORMAT_ARGB;
1064                 break;
1065         case MM_PIXEL_FORMAT_ENCODED_H264:
1066                 /* TODO: How can we determine the profile for H.264 format? */
1067                 *mimetype = MEDIA_FORMAT_H264_SP;
1068                 break;
1069         case MM_PIXEL_FORMAT_ENCODED_MJPEG:
1070                 *mimetype = MEDIA_FORMAT_MJPEG;
1071                 break;
1072         case MM_PIXEL_FORMAT_ENCODED_VP8:
1073                 *mimetype = MEDIA_FORMAT_VP8;
1074                 break;
1075         case MM_PIXEL_FORMAT_ENCODED_VP9:
1076                 *mimetype = MEDIA_FORMAT_VP9;
1077                 break;
1078         default:
1079                 CAM_LOG_ERROR("unsupported format[%d]", in_format);
1080                 return CAMERA_ERROR_NOT_SUPPORTED;
1081 //LCOV_EXCL_STOP
1082         }
1083
1084         return CAMERA_ERROR_NONE;
1085 }
1086
1087
1088 static int __camera_create_media_packet_data(int ret_fd, int *tfd, int num_buffer_fd, tbm_bo bo,
1089         tbm_bo *buffer_bo, tbm_bo data_bo, camera_media_packet_data **mp_data)
1090 {
1091         int i = 0;
1092         int ret = CAMERA_ERROR_NONE;
1093         camera_media_packet_data *new_mp_data = NULL;
1094
1095         if (!tfd || !mp_data) {
1096                 CAM_LOG_ERROR("NULL param[%p,%p]", tfd, mp_data);
1097                 return CAMERA_ERROR_INVALID_PARAMETER;
1098         }
1099
1100         new_mp_data = g_new0(camera_media_packet_data, 1);
1101
1102         new_mp_data->ret_fd = ret_fd;
1103         new_mp_data->fd = tfd[0];
1104         new_mp_data->num_buffer_fd = num_buffer_fd;
1105         new_mp_data->bo = bo;
1106
1107         CAM_LOG_VERBOSE("tfd[%d], ret fd[%d]", new_mp_data->fd, new_mp_data->ret_fd);
1108
1109         if (data_bo) {
1110                 /* non-zero copy */
1111                 new_mp_data->data_bo = data_bo;
1112                 new_mp_data->data_fd = tfd[1];
1113
1114                 CAM_LOG_VERBOSE("bo[%p], fd[%d]",
1115                         new_mp_data->data_bo, new_mp_data->data_fd);
1116         } else {
1117                 /* zero copy */
1118                 for (i = 0 ; i < num_buffer_fd ; i++) {
1119                         new_mp_data->buffer_bo[i] = buffer_bo[i];
1120                         new_mp_data->buffer_fd[i] = (tbm_fd)tfd[i + 1];
1121
1122                         CAM_LOG_VERBOSE("    [%d] bo[%p], fd[%d]",
1123                                 i, new_mp_data->buffer_bo[i], new_mp_data->buffer_fd[i]);
1124                 }
1125
1126                 for (i = num_buffer_fd ; i < MUSE_NUM_FD ; i++)
1127                         new_mp_data->buffer_fd[i] = CAMERA_FD_INIT;
1128
1129                 new_mp_data->data_fd = CAMERA_FD_INIT;
1130         }
1131
1132         *mp_data = new_mp_data;
1133
1134         CAM_LOG_DEBUG("mp_data %p", new_mp_data);
1135
1136         return ret;
1137 }
1138
1139 static void __camera_release_media_packet_data(camera_media_packet_data *mp_data, camera_cb_info_s *cb_info)
1140 {
1141         int i = 0;
1142
1143         if (!mp_data || !cb_info) {
1144                 CAM_LOG_ERROR("NULL pointer %p %p", mp_data, cb_info);
1145                 return;
1146         }
1147
1148         CAM_LOG_VERBOSE("tfd[%d], ret fd[%d]", mp_data->fd, mp_data->ret_fd);
1149
1150         /* release imported bo and close fd */
1151         for (i = 0 ; i < mp_data->num_buffer_fd ; i++) {
1152                 CAM_LOG_VERBOSE("    release buffer[%d] fd[%d],bo[%p]",
1153                         i, mp_data->buffer_fd[i], mp_data->buffer_bo[i]);
1154
1155                 tbm_bo_unref(mp_data->buffer_bo[i]);
1156
1157                 if (CAMERA_IS_FD_VALID(mp_data->buffer_fd[i]))
1158                         close(mp_data->buffer_fd[i]);
1159                 else
1160                         CAM_LOG_WARNING("invalid fd[%d] for buffer[%d]", mp_data->buffer_fd[i], i);
1161         }
1162
1163         if (mp_data->data_bo) {
1164                 CAM_LOG_VERBOSE("release data_fd[%d],data_bo[%p]",
1165                         mp_data->data_fd, mp_data->data_bo);
1166
1167                 tbm_bo_unref(mp_data->data_bo);
1168
1169                 if (CAMERA_IS_FD_VALID(mp_data->data_fd))
1170                         close(mp_data->data_fd);
1171                 else
1172                         CAM_LOG_WARNING("invalid data_fd[%d]", mp_data->data_fd);
1173         }
1174
1175         CAM_LOG_VERBOSE("release fd[%d],bo[%p]", mp_data->fd, mp_data->bo);
1176
1177         tbm_bo_unref(mp_data->bo);
1178
1179         if (CAMERA_IS_FD_VALID(mp_data->fd))
1180                 close(mp_data->fd);
1181         else
1182                 CAM_LOG_WARNING("invalid fd[%d]", mp_data->fd);
1183
1184         /* return buffer */
1185         _camera_msg_return_buffer(mp_data->ret_fd, cb_info);
1186
1187         g_free(mp_data);
1188 }
1189
1190
1191 static tbm_surface_h __camera_get_tbm_surface(MMCamcorderVideoStreamDataType *stream, camera_media_packet_data *mp_data)
1192 {
1193         int i = 0;
1194         int ret = CAMERA_ERROR_NONE;
1195         uint32_t tbm_format = 0;
1196         tbm_bo bos[BUFFER_MAX_PLANE_NUM] = {NULL, };
1197         tbm_surface_info_s tsurf_info;
1198
1199         if (!stream || !mp_data) {
1200                 CAM_LOG_ERROR("NULL param [%p,%p]", stream, mp_data);
1201                 return NULL;
1202         }
1203
1204         if (mp_data->num_buffer_fd < 1 && !mp_data->data_bo) {
1205                 CAM_LOG_ERROR("No valid data");
1206                 return NULL;
1207         }
1208
1209         ret = _camera_get_tbm_format(stream->format, &tbm_format);
1210         if (ret != CAMERA_ERROR_NONE)
1211                 return NULL;
1212
1213         memset(&tsurf_info, 0x0, sizeof(tbm_surface_info_s));
1214
1215         if (mp_data->num_buffer_fd > 0) {
1216                 for (i = 0 ; i < mp_data->num_buffer_fd ; i++)
1217                         bos[i] = mp_data->buffer_bo[i];
1218         } else {
1219                 bos[0] = mp_data->data_bo;
1220         }
1221
1222         tsurf_info.width = stream->width;
1223         tsurf_info.height = stream->height;
1224         tsurf_info.format = tbm_format;
1225         tsurf_info.bpp = tbm_surface_internal_get_bpp(tbm_format);
1226         tsurf_info.num_planes = tbm_surface_internal_get_num_planes(tbm_format);
1227
1228         switch (tbm_format) {
1229         case TBM_FORMAT_NV12:   /* fall through */
1230         case TBM_FORMAT_NV21:   /* fall through */
1231         case TBM_FORMAT_YUV420: /* fall through */
1232         case TBM_FORMAT_YVU420: /* fall through */
1233         case TBM_FORMAT_UYVY:   /* fall through */
1234         case TBM_FORMAT_YUYV:
1235                 for (i = 0 ; i < (int)tsurf_info.num_planes ; i++) {
1236                         tsurf_info.planes[i].stride = stream->stride[i];
1237                         tsurf_info.planes[i].size = stream->stride[i] * stream->elevation[i];
1238                         if (i != 0 && mp_data->num_buffer_fd <= 1)
1239                                 tsurf_info.planes[i].offset = tsurf_info.planes[i - 1].offset + tsurf_info.planes[i - 1].size;
1240                         tsurf_info.size += tsurf_info.planes[i].size;
1241
1242                         CAM_LOG_VERBOSE("[plane:%d] st[%d], el[%d], size[%d]",
1243                                 i, stream->stride[i], stream->elevation[i], tsurf_info.planes[i].size);
1244                 }
1245                 break;
1246 //LCOV_EXCL_START
1247         case TBM_FORMAT_RGB565:     /* fall through */
1248         case TBM_FORMAT_RGB888:     /* fall through */
1249         case TBM_FORMAT_RGBA8888:   /* fall through */
1250         case TBM_FORMAT_ARGB8888:
1251                 tsurf_info.planes[0].size = stream->data.rgb.length_data;
1252                 tsurf_info.planes[0].offset = 0;
1253                 tsurf_info.size = stream->data.rgb.length_data;
1254                 break;
1255         default:
1256                 CAM_LOG_ERROR("Not supported format[%d]", stream->format);
1257                 return NULL;
1258 //LCOV_EXCL_STOP
1259         }
1260
1261         return tbm_surface_internal_create_with_bos(&tsurf_info, bos,
1262                 mp_data->num_buffer_fd > 0 ? mp_data->num_buffer_fd : 1);
1263 }
1264
1265
1266 static int __camera_update_media_packet_format(camera_cb_info_s *cb_info, MMCamcorderVideoStreamDataType *stream)
1267 {
1268         int ret = CAMERA_ERROR_NONE;
1269         int pkt_fmt_width = 0;
1270         int pkt_fmt_height = 0;
1271         bool make_pkt_fmt = false;
1272         media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
1273         media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
1274
1275         if (!cb_info || !stream) {
1276                 CAM_LOG_ERROR("invalid parameter - %p, %p", cb_info, stream);
1277                 return CAMERA_ERROR_INVALID_PARAMETER;
1278         }
1279
1280         ret = _camera_get_media_packet_mimetype(stream->format, &mimetype);
1281         if (ret != CAMERA_ERROR_NONE)
1282                 return ret;
1283
1284         /* check media packet format */
1285         if (cb_info->pkt_fmt) {
1286                 media_format_get_video_info(cb_info->pkt_fmt,
1287                         &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
1288
1289                 CAM_LOG_INFO("pkt_fmt %dx%d - stream %dx%d",
1290                         pkt_fmt_width, pkt_fmt_height, stream->width, stream->height);
1291
1292                 if (pkt_fmt_mimetype != mimetype ||
1293                         pkt_fmt_width != stream->width ||
1294                         pkt_fmt_height != stream->height) {
1295                         CAM_LOG_WARNING("change fmt[previous:0x%x,%dx%d]",
1296                                         pkt_fmt_mimetype, pkt_fmt_width, pkt_fmt_height);
1297
1298                         media_format_unref(cb_info->pkt_fmt);
1299                         cb_info->pkt_fmt = NULL;
1300                         make_pkt_fmt = true;
1301                 }
1302         } else {
1303                 make_pkt_fmt = true;
1304         }
1305
1306         /* create packet format */
1307         if (make_pkt_fmt) {
1308                 CAM_LOG_WARNING("make new fmt - 0x%x, %dx%d",
1309                         mimetype, stream->width, stream->height);
1310
1311                 ret = media_format_create(&cb_info->pkt_fmt);
1312                 if (ret != MEDIA_FORMAT_ERROR_NONE) {
1313                         CAM_LOG_ERROR("media_format_create failed 0x%x", ret);
1314                         return CAMERA_ERROR_INVALID_OPERATION;
1315                 }
1316
1317                 ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
1318                 ret |= media_format_set_video_width(cb_info->pkt_fmt, stream->width);
1319                 ret |= media_format_set_video_height(cb_info->pkt_fmt, stream->height);
1320                 if (ret != MEDIA_FORMAT_ERROR_NONE) {
1321                         CAM_LOG_ERROR("media format set failed 0x%x", ret);
1322                         return CAMERA_ERROR_INVALID_OPERATION;
1323                 }
1324         }
1325
1326         return CAMERA_ERROR_NONE;
1327 }
1328
1329
1330 static int __camera_create_media_packet(camera_cb_info_s *cb_info, MMCamcorderVideoStreamDataType *stream,
1331         camera_media_packet_data *mp_data, media_packet_h *packet)
1332 {
1333         media_packet_h pkt = NULL;
1334         tbm_surface_h tsurf = NULL;
1335         int ret = CAMERA_ERROR_NONE;
1336
1337         if (!cb_info || !stream || !mp_data || !packet) {
1338                 CAM_LOG_ERROR("invalid parameter - %p, %p, %p, %p",
1339                         cb_info, stream, mp_data, packet);
1340                 return CAMERA_ERROR_INVALID_PARAMETER;
1341         }
1342
1343         ret = __camera_update_media_packet_format(cb_info, stream);
1344         if (ret != CAMERA_ERROR_NONE)
1345                 return ret;
1346
1347         if (stream->data_type == MM_CAM_STREAM_DATA_ENCODED) {
1348                 ret = media_packet_new_from_external_memory(cb_info->pkt_fmt,
1349                         stream->data.encoded.data, stream->data.encoded.length_data,
1350                         (media_packet_dispose_cb)_camera_media_packet_dispose, (void *)cb_info,
1351                         &pkt);
1352         } else {
1353                 tsurf = __camera_get_tbm_surface(stream, mp_data);
1354                 if (!tsurf) {
1355                         CAM_LOG_ERROR("get tbm surface failed");
1356                         ret = CAMERA_ERROR_INVALID_OPERATION;
1357                         goto _PACKET_CREATE_FAILED;
1358                 }
1359
1360                 ret = media_packet_new_from_tbm_surface(cb_info->pkt_fmt,
1361                         tsurf, (media_packet_dispose_cb)_camera_media_packet_dispose,
1362                         (void *)cb_info, &pkt);
1363         }
1364
1365         if (ret != MEDIA_PACKET_ERROR_NONE) {
1366                 CAM_LOG_ERROR("media_packet_new[t:%d] failed 0x%x", stream->data_type, ret);
1367                 goto _PACKET_CREATE_FAILED;
1368         }
1369
1370         ret = media_packet_set_extra(pkt, (void *)mp_data);
1371         if (ret != MEDIA_PACKET_ERROR_NONE) {
1372                 CAM_LOG_ERROR("media_packet_set_extra failed");
1373                 goto _PACKET_CREATE_FAILED;
1374         }
1375
1376         /* set timestamp : msec -> nsec */
1377         if (media_packet_set_pts(pkt, (uint64_t)(stream->timestamp) * 1000000) != MEDIA_PACKET_ERROR_NONE)
1378                 CAM_LOG_WARNING("media_packet_set_pts failed");
1379
1380         if (media_packet_set_rotate_method(pkt, (media_packet_rotate_method_e)stream->rotation) != MEDIA_PACKET_ERROR_NONE)
1381                 CAM_LOG_WARNING("media_packet_set_rotate_method failed");
1382
1383         CAM_LOG_VERBOSE("new media packet[%p], tbm surface[%p]", pkt, tsurf);
1384
1385         *packet = pkt;
1386
1387         return CAMERA_ERROR_NONE;
1388
1389 _PACKET_CREATE_FAILED:
1390         if (tsurf)
1391                 tbm_surface_destroy(tsurf);
1392         if (pkt)
1393                 media_packet_unref(pkt);
1394
1395         return CAMERA_ERROR_INVALID_OPERATION;
1396 }
1397
1398 void _camera_media_packet_dispose(media_packet_h pkt, void *user_data)
1399 {
1400         int ret = 0;
1401         camera_cb_info_s *cb_info = (camera_cb_info_s *)user_data;
1402         camera_media_packet_data *mp_data = NULL;
1403         tbm_surface_h tsurf = NULL;
1404
1405         if (!pkt || !cb_info) {
1406                 CAM_LOG_ERROR("NULL pointer %p %p", pkt, cb_info);
1407                 return;
1408         }
1409
1410         ret = media_packet_get_extra(pkt, (void **)&mp_data);
1411         if (ret != MEDIA_PACKET_ERROR_NONE || !mp_data) {
1412                 CAM_LOG_ERROR("media_packet_get_extra failed 0x%x", ret);
1413                 return;
1414         }
1415
1416         ret = media_packet_get_tbm_surface(pkt, &tsurf);
1417
1418         CAM_LOG_VERBOSE("media packet[%p] - mp_data[%p],tsurf[%p]",
1419                 pkt, mp_data, tsurf);
1420
1421         if (tsurf)
1422                 tbm_surface_destroy(tsurf);
1423
1424         g_mutex_lock(&cb_info->mp_data_mutex);
1425         __camera_release_media_packet_data(mp_data, cb_info);
1426         g_mutex_unlock(&cb_info->mp_data_mutex);
1427 }
1428
1429 static void __camera_client_user_callback(camera_cb_info_s *cb_info, char *recv_msg, muse_camera_event_e event, int *tfd)
1430 {
1431         int param1 = 0;
1432         int param2 = 0;
1433
1434         if (!recv_msg || event >= MUSE_CAMERA_EVENT_TYPE_NUM) {
1435                 CAM_LOG_ERROR("invalid parameter - camera msg %p, event %d", recv_msg, event);
1436                 return;
1437         }
1438
1439         CAM_LOG_DEBUG("get camera msg[%s], event[%d]", recv_msg, event);
1440
1441         g_mutex_lock(&cb_info->user_cb_mutex[event]);
1442
1443         if (cb_info->user_cb[event] == NULL) {
1444                 if (event != MUSE_CAMERA_EVENT_TYPE_PREVIEW &&
1445                         event != MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW &&
1446                         event != MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION &&
1447                         event != MUSE_CAMERA_EVENT_TYPE_CAPTURE) {
1448                         g_mutex_unlock(&cb_info->user_cb_mutex[event]);
1449                         CAM_LOG_WARNING("NULL callback for event %d, return here", event);
1450                         return;
1451                 }
1452
1453                 /* return buffer message should be sent for some events.
1454                  - MUSE_CAMERA_EVENT_TYPE_PREVIEW
1455                  - MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW
1456                  - MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION
1457                  - MUSE_CAMERA_EVENT_TYPE_CAPTURE
1458                 */
1459         }
1460
1461         switch (event) {
1462         case MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE:
1463                 {
1464                         int previous = 0;
1465                         int current = 0;
1466                         int by_policy = 0;
1467
1468                         muse_camera_msg_get(previous, recv_msg);
1469                         muse_camera_msg_get(current, recv_msg);
1470                         muse_camera_msg_get(by_policy, recv_msg);
1471
1472                         CAM_LOG_INFO("STATE CHANGE - previous %d, current %d, by_policy %d",
1473                                 previous, current, by_policy);
1474
1475                         ((camera_state_changed_cb)cb_info->user_cb[event])((camera_state_e)previous,
1476                                 (camera_state_e)current, (bool)by_policy, cb_info->user_data[event]);
1477                 }
1478                 break;
1479         case MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE:
1480                 {
1481                         int state = 0;
1482
1483                         muse_camera_msg_get(state, recv_msg);
1484
1485                         CAM_LOG_INFO("FOCUS state - %d", state);
1486
1487                         ((camera_focus_changed_cb)cb_info->user_cb[event])((camera_focus_state_e)state, cb_info->user_data[event]);
1488                 }
1489                 break;
1490         case MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE:
1491                 CAM_LOG_INFO("CAPTURE_COMPLETED");
1492                 ((camera_capture_completed_cb)cb_info->user_cb[event])(cb_info->user_data[event]);
1493                 break;
1494         case MUSE_CAMERA_EVENT_TYPE_PREVIEW:
1495         case MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW:
1496                 __camera_event_handler_preview(cb_info, recv_msg, tfd);
1497                 break;
1498 //LCOV_EXCL_START
1499         case MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS:
1500                 {
1501                         int percent = 0;
1502
1503                         muse_camera_msg_get(percent, recv_msg);
1504
1505                         CAM_LOG_INFO("HDR progress - %d %%", percent);
1506
1507                         ((camera_attr_hdr_progress_cb)cb_info->user_cb[event])(percent, cb_info->user_data[event]);
1508                 }
1509                 break;
1510         case MUSE_CAMERA_EVENT_TYPE_INTERRUPTED:
1511                 {
1512                         int policy = 0;
1513                         int previous = 0;
1514                         int current = 0;
1515
1516                         muse_camera_msg_get(policy, recv_msg);
1517                         muse_camera_msg_get(previous, recv_msg);
1518                         muse_camera_msg_get(current, recv_msg);
1519
1520                         CAM_LOG_WARNING("INTERRUPTED - policy %d, state %d -> %d", policy, previous, current);
1521
1522                         ((camera_interrupted_cb)cb_info->user_cb[event])((camera_policy_e)policy,
1523                                 (camera_state_e)previous, (camera_state_e)current, cb_info->user_data[event]);
1524                 }
1525                 break;
1526         case MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED:
1527                 {
1528                         int policy = 0;
1529                         int state = 0;
1530
1531                         muse_camera_msg_get(policy, recv_msg);
1532                         muse_camera_msg_get(state, recv_msg);
1533
1534                         CAM_LOG_WARNING("INTERRUPT_STARTED - policy %d, state %d", policy, state);
1535
1536                         ((camera_interrupt_started_cb)cb_info->user_cb[event])((camera_policy_e)policy,
1537                                 (camera_state_e)state, cb_info->user_data[event]);
1538                 }
1539                 break;
1540         case MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION:
1541                 __camera_event_handler_face_detection(cb_info, recv_msg, tfd);
1542                 break;
1543         case MUSE_CAMERA_EVENT_TYPE_ERROR:
1544                 {
1545                         int error = 0;
1546                         int current_state = 0;
1547
1548                         muse_camera_msg_get(error, recv_msg);
1549                         muse_camera_msg_get(current_state, recv_msg);
1550
1551                         CAM_LOG_ERROR("ERROR - error 0x%x, current_state %d", error, current_state);
1552
1553                         ((camera_error_cb)cb_info->user_cb[event])((camera_error_e)error,
1554                                 (camera_state_e)current_state, cb_info->user_data[event]);
1555                 }
1556                 break;
1557 //LCOV_EXCL_STOP
1558         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION:
1559                 /* fall through */
1560         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION:
1561                 muse_camera_msg_get(param1, recv_msg);
1562                 muse_camera_msg_get(param2, recv_msg);
1563
1564                 CAM_LOG_DEBUG("event[%d] SUPPORTED[%d],[%d]", event, param1, param2);
1565
1566                 if (((camera_supported_cb_param2)cb_info->user_cb[event])(param1, param2, cb_info->user_data[event]) == false) {
1567                         cb_info->user_cb[event] = NULL;
1568                         cb_info->user_data[event] = NULL;
1569                         CAM_LOG_WARNING("stop foreach callback for event %d", event);
1570                 }
1571                 break;
1572         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT:
1573                 /* fall through */
1574         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT:
1575                 /* fall through */
1576         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE:
1577                 /* fall through */
1578         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE:
1579                 /* fall through */
1580         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO:
1581                 /* fall through */
1582         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE:
1583                 /* fall through */
1584         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT:
1585                 /* fall through */
1586         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE:
1587                 /* fall through */
1588         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE:
1589                 /* fall through */
1590         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS:
1591                 /* fall through */
1592         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION:
1593                 /* fall through */
1594         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP:
1595                 /* fall through */
1596         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION:
1597                 /* fall through */
1598 //LCOV_EXCL_START
1599         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE:
1600                 /* fall through */
1601         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE:
1602                 muse_camera_msg_get(param1, recv_msg);
1603
1604                 CAM_LOG_DEBUG("event[%d], SUPPORTED[%d] ", event, param1);
1605
1606                 if (((camera_supported_cb_param1)cb_info->user_cb[event])(param1, cb_info->user_data[event]) == false) {
1607                         cb_info->user_cb[event] = NULL;
1608                         cb_info->user_data[event] = NULL;
1609                         CAM_LOG_WARNING("stop foreach callback for event %d", event);
1610                 }
1611                 break;
1612 //LCOV_EXCL_STOP
1613         case MUSE_CAMERA_EVENT_TYPE_CAPTURE:
1614                 __camera_event_handler_capture(cb_info, recv_msg, tfd);
1615                 break;
1616         default:
1617                 CAM_LOG_WARNING("unhandled event %d", event);
1618                 break;
1619         }
1620
1621         g_mutex_unlock(&cb_info->user_cb_mutex[event]);
1622 }
1623
1624 static gboolean __camera_idle_event_callback(gpointer data)
1625 {
1626         camera_cb_info_s *cb_info = NULL;
1627         camera_idle_event_s *cam_idle_event = (camera_idle_event_s *)data;
1628
1629         if (cam_idle_event == NULL) {
1630                 CAM_LOG_ERROR("cam_idle_event is NULL");
1631                 return FALSE;
1632         }
1633
1634         /* lock event */
1635         g_mutex_lock(&g_cam_idle_event_lock);
1636
1637         cb_info = cam_idle_event->cb_info;
1638         if (cb_info == NULL) {
1639                 CAM_LOG_WARNING("camera cb_info is NULL. event %p %d", cam_idle_event, cam_idle_event->event);
1640                 g_mutex_unlock(&g_cam_idle_event_lock);
1641                 goto IDLE_EVENT_CALLBACK_DONE;
1642         }
1643
1644         /* remove event from list */
1645         if (cb_info->idle_event_list)
1646                 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)cam_idle_event);
1647
1648         g_mutex_unlock(&g_cam_idle_event_lock);
1649
1650         /* user callback */
1651         __camera_client_user_callback(cb_info, cam_idle_event->recv_msg, cam_idle_event->event, cam_idle_event->tfd);
1652
1653 IDLE_EVENT_CALLBACK_DONE:
1654         /* release event */
1655         g_free(cam_idle_event);
1656         cam_idle_event = NULL;
1657
1658         return FALSE;
1659 }
1660
1661 static gpointer __camera_msg_handler_func(gpointer data)
1662 {
1663         int api = 0;
1664         int type = 0;
1665         camera_message_s *cam_msg = NULL;
1666         camera_idle_event_s *cam_idle_event = NULL;
1667         camera_msg_handler_info_s *handler_info = (camera_msg_handler_info_s *)data;
1668         camera_cb_info_s *cb_info = NULL;
1669         GThread *thread = NULL;
1670
1671         if (!handler_info || !handler_info->cb_info) {
1672                 CAM_LOG_ERROR("NULL handler %p", handler_info);
1673                 return NULL;
1674         }
1675
1676         cb_info = (camera_cb_info_s *)handler_info->cb_info;
1677         type = handler_info->type;
1678         thread = handler_info->thread;
1679
1680         CAM_LOG_INFO("t:%d start[thread:%p]", type, thread);
1681
1682         g_mutex_lock(&handler_info->mutex);
1683
1684         while (g_atomic_int_get(&handler_info->running)) {
1685                 if (g_queue_is_empty(handler_info->queue)) {
1686                         CAM_LOG_VERBOSE("t[%d] signal wait...", type);
1687                         g_cond_wait(&handler_info->cond, &handler_info->mutex);
1688                         CAM_LOG_VERBOSE("t[%d] signal received", type);
1689
1690                         if (g_atomic_int_get(&handler_info->running) == 0) {
1691                                 CAM_LOG_INFO("t:%d stop event thread", type);
1692                                 break;
1693                         }
1694                 }
1695
1696                 cam_msg = (camera_message_s *)g_queue_pop_head(handler_info->queue);
1697
1698                 g_mutex_unlock(&handler_info->mutex);
1699
1700                 if (cam_msg == NULL) {
1701                         CAM_LOG_ERROR("t:%d NULL message", type);
1702                         g_mutex_lock(&handler_info->mutex);
1703                         continue;
1704                 }
1705
1706                 api = cam_msg->api;
1707
1708                 if (api < MUSE_CAMERA_API_MAX) {
1709                         int ret = 0;
1710
1711                         g_mutex_lock(&cb_info->api_mutex[api]);
1712
1713                         if (muse_camera_msg_get(ret, cam_msg->recv_msg)) {
1714                                 if (cb_info->api_waiting[api] > 0) {
1715                                         cb_info->api_ret[api] = ret;
1716                                         cb_info->api_activating[api] = TRUE;
1717
1718                                         CAM_LOG_DEBUG("t[%d] camera api[%d] - return[0x%x]", type, api, ret);
1719
1720                                         g_cond_broadcast(&cb_info->api_cond[api]);
1721                                 } else {
1722                                         CAM_LOG_WARNING("no waiting for this api [%d]", api);
1723                                 }
1724                         } else {
1725                                 CAM_LOG_ERROR("t:%d failed to get camera ret for api %d, msg %s", type, api, cam_msg->recv_msg);
1726                         }
1727
1728                         g_mutex_unlock(&cb_info->api_mutex[api]);
1729                 } else if (api == MUSE_CAMERA_CB_EVENT) {
1730                         if (cam_msg->event == MUSE_CAMERA_EVENT_TYPE_INTERRUPTED) {
1731                                 CAM_LOG_WARNING("INTERRUPTED, release thread for preview cb");
1732                                 __destroy_msg_handler_thread(&cb_info->preview_cb_info);
1733                         }
1734
1735                         switch (cam_msg->event_class) {
1736                         case MUSE_CAMERA_EVENT_CLASS_THREAD_SUB:
1737                                 __camera_client_user_callback(cb_info, cam_msg->recv_msg, cam_msg->event, cam_msg->tfd);
1738                                 break;
1739                         case MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN:
1740                                 cam_idle_event = g_new0(camera_idle_event_s, 1);
1741                                 if (cam_idle_event == NULL) {
1742                                         CAM_LOG_ERROR("t:%d cam_idle_event alloc failed", type);
1743                                         break;
1744                                 }
1745
1746                                 cam_idle_event->event = cam_msg->event;
1747                                 cam_idle_event->cb_info = cb_info;
1748
1749                                 strncpy(cam_idle_event->recv_msg, cam_msg->recv_msg, sizeof(cam_idle_event->recv_msg));
1750                                 memcpy(cam_idle_event->tfd, cam_msg->tfd, sizeof(cam_idle_event->tfd));
1751
1752                                 CAM_LOG_DEBUG("t[%d] add camera event[%d, %p] to IDLE",
1753                                         type, cam_msg->event, cam_idle_event);
1754
1755                                 g_mutex_lock(&g_cam_idle_event_lock);
1756                                 cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)cam_idle_event);
1757                                 g_mutex_unlock(&g_cam_idle_event_lock);
1758
1759                                 g_idle_add_full(G_PRIORITY_DEFAULT,
1760                                         (GSourceFunc)__camera_idle_event_callback,
1761                                         (gpointer)cam_idle_event,
1762                                         NULL);
1763                                 break;
1764                         default:
1765                                 CAM_LOG_ERROR("t:%d not handled event class %d", type, cam_msg->event_class);
1766                                 break;
1767                         }
1768                 } else {
1769                         CAM_LOG_ERROR("t:%d unknown camera api[%d] message[%s]", type, api, cam_msg->recv_msg);
1770                 }
1771
1772                 g_free(cam_msg);
1773                 cam_msg = NULL;
1774
1775                 g_mutex_lock(&handler_info->mutex);
1776         }
1777
1778         /* remove remained event */
1779         while (!g_queue_is_empty(handler_info->queue)) {
1780                 cam_msg = (camera_message_s *)g_queue_pop_head(handler_info->queue);
1781                 if (cam_msg) {
1782                         CAM_LOG_INFO("t:%d remove message %p", type, cam_msg);
1783                         __camera_release_tfd(cam_msg->tfd);
1784                         g_free(cam_msg);
1785                 } else {
1786                         CAM_LOG_WARNING("t:%d NULL message", type);
1787                 }
1788         }
1789
1790         g_mutex_unlock(&handler_info->mutex);
1791
1792         CAM_LOG_INFO("t:%d return[thread:%p]", type, thread);
1793
1794         return NULL;
1795 }
1796
1797
1798 static void __camera_deactivate_idle_event_all(camera_cb_info_s *cb_info)
1799 {
1800         camera_idle_event_s *cam_idle_event = NULL;
1801         GList *list = NULL;
1802
1803         if (cb_info == NULL) {
1804                 CAM_LOG_ERROR("cb_info is NULL");
1805                 return;
1806         }
1807
1808         g_mutex_lock(&g_cam_idle_event_lock);
1809
1810         if (cb_info->idle_event_list == NULL) {
1811                 CAM_LOG_INFO("No remained idle event");
1812                 g_mutex_unlock(&g_cam_idle_event_lock);
1813                 return;
1814         }
1815
1816         list = cb_info->idle_event_list;
1817
1818         while (list) {
1819                 cam_idle_event = list->data;
1820                 list = g_list_next(list);
1821
1822                 if (!cam_idle_event) {
1823                         CAM_LOG_WARNING("Fail to remove idle event. The event is NULL");
1824                         continue;
1825                 }
1826
1827                 if (g_idle_remove_by_data(cam_idle_event)) {
1828                         CAM_LOG_WARNING("remove idle event %p done", cam_idle_event);
1829
1830                         cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)cam_idle_event);
1831
1832                         g_free(cam_idle_event);
1833                         cam_idle_event = NULL;
1834
1835                         continue;
1836                 }
1837
1838                 CAM_LOG_WARNING("set NULL cb_info for event %p %d, it will be freed on idle callback",
1839                         cam_idle_event, cam_idle_event->event);
1840
1841                 cam_idle_event->cb_info = NULL;
1842
1843                 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)cam_idle_event);
1844         }
1845
1846         g_list_free(cb_info->idle_event_list);
1847         cb_info->idle_event_list = NULL;
1848
1849         g_mutex_unlock(&g_cam_idle_event_lock);
1850 }
1851
1852
1853 static void __camera_add_msg_to_queue(camera_cb_info_s *cb_info, int api, int event, int event_class, char *msg, int *tfd)
1854 {
1855         camera_message_s *cam_msg = NULL;
1856
1857         if (!cb_info || !msg) {
1858                 CAM_LOG_ERROR("NULL pointer %p %p", cb_info, msg);
1859                 return;
1860         }
1861
1862         cam_msg = g_new0(camera_message_s, 1);
1863         if (!cam_msg) {
1864                 CAM_LOG_ERROR("failed to alloc cam_msg for [%s]", msg);
1865                 return;
1866         }
1867
1868         cam_msg->api = api;
1869         cam_msg->event = event;
1870         cam_msg->event_class = event_class;
1871
1872         if (tfd)
1873                 memcpy(cam_msg->tfd, tfd, sizeof(cam_msg->tfd));
1874
1875         strncpy(cam_msg->recv_msg, msg, sizeof(cam_msg->recv_msg) - 1);
1876
1877         CAM_LOG_DEBUG("add message to queue : api[%d], event[%d], event_class[%d]",
1878                 api, event, event_class);
1879
1880         if (event == MUSE_CAMERA_EVENT_TYPE_PREVIEW) {
1881                 if (!cb_info->preview_cb_info.thread) {
1882                         LOGI("The thread for preview cb is not created yet, create it now");
1883                         if (!__create_msg_handler_thread(&cb_info->preview_cb_info,
1884                                         CAMERA_MESSAGE_HANDLER_TYPE_PREVIEW_CB, "cam:preview_cb", cb_info)) {
1885                                 CAM_LOG_ERROR("failed to create thread for preview cb");
1886                                 g_free(cam_msg);
1887                                 return;
1888                         }
1889                 }
1890
1891                 g_mutex_lock(&cb_info->preview_cb_info.mutex);
1892                 g_queue_push_tail(cb_info->preview_cb_info.queue, (gpointer)cam_msg);
1893                 g_cond_signal(&cb_info->preview_cb_info.cond);
1894                 g_mutex_unlock(&cb_info->preview_cb_info.mutex);
1895         } else if (event == MUSE_CAMERA_EVENT_TYPE_CAPTURE) {
1896                 g_mutex_lock(&cb_info->capture_cb_info.mutex);
1897                 g_queue_push_tail(cb_info->capture_cb_info.queue, (gpointer)cam_msg);
1898                 g_cond_signal(&cb_info->capture_cb_info.cond);
1899                 g_mutex_unlock(&cb_info->capture_cb_info.mutex);
1900         } else {
1901                 g_mutex_lock(&cb_info->msg_handler_info.mutex);
1902                 g_queue_push_tail(cb_info->msg_handler_info.queue, (gpointer)cam_msg);
1903                 g_cond_signal(&cb_info->msg_handler_info.cond);
1904                 g_mutex_unlock(&cb_info->msg_handler_info.mutex);
1905         }
1906
1907         cam_msg = NULL;
1908 }
1909
1910
1911 static void __camera_process_msg(camera_cb_info_s *cb_info, char *msg, int *tfd)
1912 {
1913         int ret = CAMERA_ERROR_NONE;
1914         int api = -1;
1915         int api_class = -1;
1916         int event = -1;
1917         int event_class = -1;
1918         int get_type = -1;
1919         int get_index = -1;
1920
1921         if (!cb_info || !msg) {
1922                 CAM_LOG_ERROR("invalid ptr %p %p", cb_info, msg);
1923                 return;
1924         }
1925
1926         CAM_LOG_DEBUG("msg[%s]", msg);
1927
1928         if (!muse_camera_msg_get(api, msg)) {
1929                 CAM_LOG_ERROR("failed to get camera api");
1930                 return;
1931         }
1932
1933         if (api == MUSE_CAMERA_CB_EVENT) {
1934                 if (!muse_camera_msg_get(event, msg) ||
1935                         !muse_camera_msg_get(event_class, msg)) {
1936                         CAM_LOG_ERROR("failed to get camera event or event_class [%s]", msg);
1937                         return;
1938                 }
1939         } else {
1940                 if (!muse_camera_msg_get(api_class, msg)) {
1941                         CAM_LOG_ERROR("failed to get camera api_class [%s]", msg);
1942                         return;
1943                 }
1944         }
1945
1946         if (api_class == MUSE_CAMERA_API_CLASS_IMMEDIATE) {
1947                 if (api >= MUSE_CAMERA_API_MAX) {
1948                         CAM_LOG_ERROR("invalid api %d", api);
1949                         return;
1950                 }
1951
1952                 if (!muse_camera_msg_get(ret, msg)) {
1953                         CAM_LOG_ERROR("failed to get camera ret");
1954                         return;
1955                 }
1956
1957                 g_mutex_lock(&cb_info->api_mutex[api]);
1958
1959                 switch (api) {
1960                 case MUSE_CAMERA_API_CREATE:
1961                         if (ret != CAMERA_ERROR_NONE) {
1962                                 g_atomic_int_set(&cb_info->msg_recv_running, 0);
1963                                 CAM_LOG_ERROR("camera create error 0x%x. close client cb handler", ret);
1964                         }
1965                         break;
1966                 case MUSE_CAMERA_API_DESTROY:
1967                         if (ret == CAMERA_ERROR_NONE) {
1968                                 g_atomic_int_set(&cb_info->msg_recv_running, 0);
1969                                 CAM_LOG_INFO("camera destroy done. close client cb handler");
1970                         }
1971                         break;
1972                 default:
1973                         muse_camera_msg_get(get_type, msg);
1974                         if (get_type != MUSE_CAMERA_GET_TYPE_NONE) {
1975                                 if (get_type != MUSE_CAMERA_GET_TYPE_ARRAY)
1976                                         muse_camera_msg_get(get_index, msg);
1977
1978                                 switch (get_type) {
1979                                 case MUSE_CAMERA_GET_TYPE_INT:
1980                                         muse_core_msg_deserialize("get_value", msg, NULL, NULL, MUSE_TYPE_INT, &cb_info->get_int[get_index]);
1981                                         break;
1982                                 case MUSE_CAMERA_GET_TYPE_INT_PAIR:
1983                                         muse_core_msg_deserialize("get_value0", msg, NULL, NULL, MUSE_TYPE_INT, &cb_info->get_int_pair[get_index][0]);
1984                                         muse_core_msg_deserialize("get_value1", msg, NULL, NULL, MUSE_TYPE_INT, &cb_info->get_int_pair[get_index][1]);
1985                                         break;
1986                                 case MUSE_CAMERA_GET_TYPE_ARRAY:
1987                                         switch (api) {
1988                                         case MUSE_CAMERA_API_GET_DISPLAY_ROI_AREA:
1989                                                 muse_core_msg_deserialize("get_value",
1990                                                         msg, NULL, NULL, MUSE_TYPE_ARRAY, cb_info->get_display_roi_area);
1991                                                 CAM_LOG_INFO("get display roi %d,%d,%dx%d",
1992                                                         cb_info->get_display_roi_area[0],
1993                                                         cb_info->get_display_roi_area[1],
1994                                                         cb_info->get_display_roi_area[2],
1995                                                         cb_info->get_display_roi_area[3]);
1996                                                 break;
1997                                         case MUSE_CAMERA_API_ATTR_GET_GEOTAG:
1998                                                 muse_core_msg_deserialize("get_value",
1999                                                         msg, NULL, NULL, MUSE_TYPE_ARRAY, cb_info->get_geotag);
2000                                                 CAM_LOG_INFO("get geotag %lf, %lf, %lf",
2001                                                         cb_info->get_geotag[0], cb_info->get_geotag[1], cb_info->get_geotag[2]);
2002                                                 break;
2003                                         case MUSE_CAMERA_API_GET_EXTRA_PREVIEW_STREAM_FORMAT:
2004                                                 muse_core_msg_deserialize("get_value",
2005                                                         msg, NULL, NULL, MUSE_TYPE_ARRAY, cb_info->get_extra_preview_stream_format);
2006                                                 CAM_LOG_INFO("get extra preview stream format %d,%dx%d,%d",
2007                                                         cb_info->get_extra_preview_stream_format[0],
2008                                                         cb_info->get_extra_preview_stream_format[1],
2009                                                         cb_info->get_extra_preview_stream_format[2],
2010                                                         cb_info->get_extra_preview_stream_format[3]);
2011                                                 break;
2012                                         default:
2013                                                 CAM_LOG_WARNING("unknown api[%d]", api);
2014                                                 break;
2015                                         }
2016                                         break;
2017                                 case MUSE_CAMERA_GET_TYPE_STRING:
2018                                         muse_core_msg_deserialize("get_value", msg, NULL, NULL, MUSE_TYPE_STRING, cb_info->get_string[get_index]);
2019                                         break;
2020                                 default:
2021                                         CAM_LOG_WARNING("unknown type %d", get_type);
2022                                         break;
2023                                 }
2024                         }
2025                         break;
2026                 }
2027
2028                 if (cb_info->api_waiting[api] > 0) {
2029                         cb_info->api_ret[api] = ret;
2030                         cb_info->api_activating[api] = TRUE;
2031
2032                         g_cond_broadcast(&cb_info->api_cond[api]);
2033                 } else {
2034                         CAM_LOG_WARNING("no waiting for this api [%d]", api);
2035                 }
2036
2037                 g_mutex_unlock(&cb_info->api_mutex[api]);
2038         } else if (api_class == MUSE_CAMERA_API_CLASS_THREAD_SUB || api == MUSE_CAMERA_CB_EVENT) {
2039                 __camera_add_msg_to_queue(cb_info, api, event, event_class, msg, tfd);
2040         } else {
2041                 CAM_LOG_WARNING("unknown camera api %d, class %d", api, api_class);
2042         }
2043 }
2044
2045
2046 static gpointer __camera_msg_recv_func(gpointer data)
2047 {
2048         int i = 0;
2049         int recv_length = 0;
2050         int tfd[MUSE_NUM_FD] = {CAMERA_FD_INIT, CAMERA_FD_INIT, CAMERA_FD_INIT, CAMERA_FD_INIT};
2051         char *recv_msg = NULL;
2052         camera_cb_info_s *cb_info = (camera_cb_info_s *)data;
2053
2054         if (!cb_info) {
2055                 CAM_LOG_ERROR("cb_info NULL");
2056                 return NULL;
2057         }
2058
2059         CAM_LOG_INFO("start - fd : %d", cb_info->fd);
2060
2061         recv_msg = cb_info->recv_msg;
2062
2063         while (g_atomic_int_get(&cb_info->msg_recv_running)) {
2064                 for (i = 0 ; i < MUSE_NUM_FD ; i++)
2065                         tfd[i] = CAMERA_FD_INIT;
2066
2067                 recv_length = muse_core_msg_recv_fd(cb_info->fd, recv_msg, MUSE_MSG_MAX_LENGTH, tfd);
2068                 if (recv_length <= 0) {
2069                         cb_info->is_server_connected = FALSE;
2070                         CAM_LOG_ERROR("receive msg failed - server disconnected");
2071                         break;
2072                 }
2073
2074                 if (CAMERA_IS_FD_VALID(tfd[0]))
2075                         CAM_LOG_DEBUG("tfd[%d/%d/%d/%d]", tfd[0], tfd[1], tfd[2], tfd[3]);
2076
2077                 recv_msg[recv_length] = '\0';
2078
2079                 CAM_LOG_VERBOSE("recv msg[%s], length[%d]", recv_msg, recv_length);
2080
2081                 __camera_process_msg(cb_info, recv_msg, tfd);
2082         }
2083
2084         CAM_LOG_INFO("client cb exit - server connected %d", cb_info->is_server_connected);
2085
2086 //LCOV_EXCL_START
2087         if (!cb_info->is_server_connected) {
2088                 char *error_msg = NULL;
2089
2090                 if (cb_info->bufmgr == NULL) {
2091                         CAM_LOG_ERROR("No need to send error(handle is not created)");
2092                         return NULL;
2093                 }
2094
2095                 if (cb_info->fd < 0) {
2096                         CAM_LOG_ERROR("fd is closed in client side");
2097                         return NULL;
2098                 }
2099
2100                 /* send error msg for server disconnection */
2101                 error_msg = muse_core_msg_new(MUSE_CAMERA_CB_EVENT,
2102                         MUSE_TYPE_INT, "error", CAMERA_ERROR_SERVICE_DISCONNECTED,
2103                         MUSE_TYPE_INT, "current_state", CAMERA_STATE_NONE,
2104                         NULL);
2105
2106                 if (!error_msg) {
2107                         CAM_LOG_ERROR("error_msg failed");
2108                         return NULL;
2109                 }
2110
2111                 __camera_add_msg_to_queue(cb_info,
2112                         MUSE_CAMERA_CB_EVENT,
2113                         MUSE_CAMERA_EVENT_TYPE_ERROR,
2114                         MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN,
2115                         error_msg,
2116                         NULL);
2117
2118                 muse_core_msg_free(error_msg);
2119                 error_msg = NULL;
2120
2121                 for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
2122                         if (cb_info->api_waiting[i])
2123                                 g_cond_broadcast(&cb_info->api_cond[i]);
2124                 }
2125
2126                 CAM_LOG_ERROR("add error msg for service disconnection done");
2127         }
2128 //LCOV_EXCL_STOP
2129
2130         return NULL;
2131 }
2132
2133
2134 static bool __create_msg_handler_thread(camera_msg_handler_info_s *handler_info,
2135         int type, const char *thread_name, camera_cb_info_s *cb_info)
2136 {
2137         if (!handler_info || !thread_name || !cb_info) {
2138                 CAM_LOG_ERROR("t:%d NULL %p %p %p",
2139                         type, handler_info, thread_name, cb_info);
2140                 return false;
2141         }
2142
2143         g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&handler_info->mutex);
2144
2145         if (handler_info->thread) {
2146                 CAM_LOG_WARNING("t:%d thread[%p] is already created", type, handler_info->thread);
2147                 return true;
2148         }
2149
2150         CAM_LOG_INFO("t:%d [%s]", type, thread_name);
2151
2152         handler_info->type = type;
2153         handler_info->queue = g_queue_new();
2154         if (handler_info->queue == NULL) {
2155                 CAM_LOG_ERROR("t:%d queue failed", type);
2156                 return false;
2157         }
2158
2159         handler_info->cb_info = (void *)cb_info;
2160         g_atomic_int_set(&handler_info->running, 1);
2161
2162         handler_info->thread = g_thread_try_new(thread_name,
2163                 __camera_msg_handler_func, (gpointer)handler_info, NULL);
2164         if (handler_info->thread == NULL) {
2165                 CAM_LOG_ERROR("t:%d thread failed", type);
2166
2167                 g_queue_free(handler_info->queue);
2168                 handler_info->queue = NULL;
2169
2170                 return false;
2171         }
2172
2173         CAM_LOG_INFO("t:%d done[thread:%p]", type, handler_info->thread);
2174
2175         return true;
2176 }
2177
2178
2179 static void __destroy_msg_handler_thread(camera_msg_handler_info_s *handler_info)
2180 {
2181         GThread *thread = NULL;
2182
2183         if (!handler_info) {
2184                 CAM_LOG_ERROR("NULL handler");
2185                 return;
2186         }
2187
2188         g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&handler_info->mutex);
2189
2190         if (!handler_info->thread) {
2191                 CAM_LOG_WARNING("thread[t:%d] is not created", handler_info->type);
2192                 return;
2193         }
2194
2195         thread = handler_info->thread;
2196         handler_info->thread = NULL;
2197
2198         CAM_LOG_INFO("t:%d thread[%p]", handler_info->type, thread);
2199
2200         g_atomic_int_set(&handler_info->running, 0);
2201         g_cond_signal(&handler_info->cond);
2202
2203         g_clear_pointer(&locker, g_mutex_locker_free);
2204
2205         g_thread_join(thread);
2206
2207         g_queue_free(handler_info->queue);
2208         handler_info->queue = NULL;
2209
2210         CAM_LOG_INFO("t:%d done", handler_info->type);
2211 }
2212
2213
2214 static void __camera_mutex_cond_init(camera_cb_info_s *cb_info)
2215 {
2216         int i = 0;
2217
2218         if (!cb_info) {
2219                 CAM_LOG_ERROR("NULL cb_info");
2220                 return;
2221         }
2222
2223         for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
2224                 g_mutex_init(&cb_info->api_mutex[i]);
2225                 g_cond_init(&cb_info->api_cond[i]);
2226         }
2227
2228         for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++)
2229                 g_mutex_init(&cb_info->user_cb_mutex[i]);
2230
2231         g_mutex_init(&cb_info->fd_lock);
2232         g_mutex_init(&cb_info->mp_data_mutex);
2233         g_mutex_init(&cb_info->bridge_lock);
2234
2235         g_mutex_init(&cb_info->msg_handler_info.mutex);
2236         g_mutex_init(&cb_info->preview_cb_info.mutex);
2237         g_mutex_init(&cb_info->capture_cb_info.mutex);
2238         g_cond_init(&cb_info->msg_handler_info.cond);
2239         g_cond_init(&cb_info->preview_cb_info.cond);
2240         g_cond_init(&cb_info->capture_cb_info.cond);
2241
2242         CAM_LOG_INFO("done");
2243 }
2244
2245
2246 static void __camera_mutex_cond_clear(camera_cb_info_s *cb_info)
2247 {
2248         int i = 0;
2249
2250         if (!cb_info) {
2251                 CAM_LOG_ERROR("NULL cb_info");
2252                 return;
2253         }
2254
2255         g_mutex_clear(&cb_info->msg_handler_info.mutex);
2256         g_mutex_clear(&cb_info->preview_cb_info.mutex);
2257         g_mutex_clear(&cb_info->capture_cb_info.mutex);
2258         g_cond_clear(&cb_info->msg_handler_info.cond);
2259         g_cond_clear(&cb_info->preview_cb_info.cond);
2260         g_cond_clear(&cb_info->capture_cb_info.cond);
2261
2262         g_mutex_clear(&cb_info->fd_lock);
2263         g_mutex_clear(&cb_info->mp_data_mutex);
2264         g_mutex_clear(&cb_info->bridge_lock);
2265
2266         for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++)
2267                 g_mutex_clear(&cb_info->user_cb_mutex[i]);
2268
2269         for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
2270                 g_mutex_clear(&cb_info->api_mutex[i]);
2271                 g_cond_clear(&cb_info->api_cond[i]);
2272         }
2273
2274         CAM_LOG_INFO("done");
2275 }
2276
2277
2278 static camera_cb_info_s *__camera_client_callback_new(gint sockfd)
2279 {
2280         camera_cb_info_s *cb_info = NULL;
2281         gint i = 0;
2282
2283         g_return_val_if_fail(sockfd > 0, NULL);
2284
2285         cb_info = g_new0(camera_cb_info_s, 1);
2286         if (!cb_info) {
2287                 CAM_LOG_ERROR("cb_info failed");
2288                 goto ErrorExit;
2289         }
2290
2291         cb_info->api_waiting[MUSE_CAMERA_API_CREATE] = 1;
2292
2293         __camera_mutex_cond_init(cb_info);
2294
2295         /* message handler thread */
2296         if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
2297                         CAMERA_MESSAGE_HANDLER_TYPE_GENERAL, "cam:msg_handler", cb_info)) {
2298                 CAM_LOG_ERROR("msg_handler_info failed");
2299                 goto ErrorExit;
2300         }
2301
2302         /* message handler thread for capture callback */
2303         if (!__create_msg_handler_thread(&cb_info->capture_cb_info,
2304                         CAMERA_MESSAGE_HANDLER_TYPE_CAPTURE_CB, "cam:capture_cb", cb_info)) {
2305                 CAM_LOG_ERROR("capture_cb_info failed");
2306                 goto ErrorExit;
2307         }
2308
2309         cb_info->fd = sockfd;
2310
2311         /* message receive thread */
2312         g_atomic_int_set(&cb_info->msg_recv_running, 1);
2313         cb_info->msg_recv_thread = g_thread_try_new("cam:msg_recv",
2314                 __camera_msg_recv_func, (gpointer)cb_info, NULL);
2315         if (cb_info->msg_recv_thread == NULL) {
2316                 CAM_LOG_ERROR("message receive thread creation failed");
2317                 goto ErrorExit;
2318         }
2319
2320         /* initialize fd */
2321         for (i = 0 ; i < MUSE_NUM_FD ; i++)
2322                 cb_info->fds[i] = CAMERA_FD_INIT;
2323
2324         cb_info->is_server_connected = TRUE;
2325
2326         return cb_info;
2327 //LCOV_EXCL_START
2328 ErrorExit:
2329         if (cb_info) {
2330                 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
2331                 __destroy_msg_handler_thread(&cb_info->capture_cb_info);
2332
2333                 __camera_mutex_cond_clear(cb_info);
2334
2335                 g_free(cb_info);
2336                 cb_info = NULL;
2337         }
2338
2339         return NULL;
2340 //LCOV_EXCL_STOP
2341 }
2342
2343
2344 static void __camera_client_callback_destroy(camera_cb_info_s *cb_info)
2345 {
2346         if (!cb_info) {
2347                 CAM_LOG_ERROR("NULL cb_info");
2348                 return;
2349         }
2350
2351         CAM_LOG_INFO("msg_recv thread[%p] destroy", cb_info->msg_recv_thread);
2352
2353         g_thread_join(cb_info->msg_recv_thread);
2354         cb_info->msg_recv_thread = NULL;
2355
2356         CAM_LOG_INFO("msg_recv thread removed");
2357
2358         /* destroy msg handler threads */
2359         __destroy_msg_handler_thread(&cb_info->preview_cb_info);
2360         __destroy_msg_handler_thread(&cb_info->msg_handler_info);
2361         __destroy_msg_handler_thread(&cb_info->capture_cb_info);
2362
2363         __camera_mutex_cond_clear(cb_info);
2364
2365         if (CAMERA_IS_FD_VALID(cb_info->fd)) {
2366                 muse_client_close(cb_info->fd);
2367                 cb_info->fd = CAMERA_FD_INIT;
2368         }
2369
2370         if (cb_info->bufmgr) {
2371                 tbm_bufmgr_deinit(cb_info->bufmgr);
2372                 cb_info->bufmgr = NULL;
2373         }
2374         if (cb_info->pkt_fmt) {
2375                 media_format_unref(cb_info->pkt_fmt);
2376                 cb_info->pkt_fmt = NULL;
2377         }
2378
2379         if (cb_info->dp_interface) {
2380                 mm_display_interface_deinit(cb_info->dp_interface);
2381                 cb_info->dp_interface = NULL;
2382         }
2383
2384         g_free(cb_info);
2385 }
2386
2387 //LCOV_EXCL_START
2388 int _camera_start_evas_rendering(camera_h camera)
2389 {
2390         camera_cli_s *pc = (camera_cli_s *)camera;
2391
2392         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2393
2394         CAM_LOG_INFO("start");
2395
2396         if (!pc->cb_info->is_evas_render) {
2397                 CAM_LOG_ERROR("EVAS surface is not set");
2398                 return CAMERA_ERROR_NONE;
2399         }
2400
2401         /* set evas render flag as RUN */
2402         pc->cb_info->run_evas_render = true;
2403
2404         return CAMERA_ERROR_NONE;
2405 }
2406
2407
2408 int _camera_stop_evas_rendering(camera_h camera, bool keep_screen)
2409 {
2410         int ret = CAMERA_ERROR_NONE;
2411         camera_cli_s *pc = (camera_cli_s *)camera;
2412
2413         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2414
2415         CAM_LOG_INFO("stop - keep screen %d", keep_screen);
2416
2417         if (!pc->cb_info->is_evas_render) {
2418                 CAM_LOG_ERROR("EVAS surface is not set");
2419                 return CAMERA_ERROR_NONE;
2420         }
2421
2422         /* set evas render flag as STOP and release buffers */
2423         pc->cb_info->run_evas_render = false;
2424
2425         ret = mm_display_interface_evas_flush(pc->cb_info->dp_interface, keep_screen);
2426         if (ret == MM_ERROR_NONE) {
2427                 ret = CAMERA_ERROR_NONE;
2428         } else {
2429                 CAM_LOG_ERROR("mm_evas_renderer_retrieve_all_packets failed 0x%x", ret);
2430                 ret = CAMERA_ERROR_INVALID_OPERATION;
2431         }
2432
2433         return ret;
2434 }
2435 //LCOV_EXCL_STOP
2436
2437 int _camera_independent_request(int api, int device_type, const char *key, int *value)
2438 {
2439         int ret = CAMERA_ERROR_NONE;
2440         int sock_fd = CAMERA_FD_INIT;
2441         int module_index = -1;
2442         char *msg = NULL;
2443         char recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH] = {'\0',};
2444
2445         /* create muse connection */
2446         if (!key || !value) {
2447                 CAM_LOG_ERROR("NULL pointer");
2448                 return CAMERA_ERROR_INVALID_PARAMETER;
2449         }
2450
2451         sock_fd = muse_client_new();
2452         if (sock_fd < 0) {
2453                 CAM_LOG_ERROR("muse_client_new failed");
2454                 return CAMERA_ERROR_INVALID_OPERATION;
2455         }
2456
2457         if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
2458                 CAM_LOG_ERROR("muse client get module index failed");
2459                 ret = CAMERA_ERROR_INVALID_OPERATION;
2460                 goto _REQUEST_EXIT;
2461         }
2462
2463         msg = muse_core_msg_new(api,
2464                 MUSE_TYPE_INT, "module", module_index,
2465                 MUSE_TYPE_INT, PARAM_DEVICE_TYPE, device_type,
2466                 0);
2467         if (!msg) {
2468                 CAM_LOG_ERROR("msg failed");
2469                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
2470                 goto _REQUEST_EXIT;
2471         }
2472
2473         ret = muse_core_msg_send(sock_fd, msg);
2474
2475         muse_core_msg_free(msg);
2476         msg = NULL;
2477
2478         if (ret < 0) {
2479                 CAM_LOG_ERROR("send msg failed");
2480                 ret = CAMERA_ERROR_INVALID_OPERATION;
2481                 goto _REQUEST_EXIT;
2482         }
2483
2484         ret = muse_core_msg_recv(sock_fd, recv_msg, MUSE_CAMERA_MSG_MAX_LENGTH);
2485         if (ret <= 0) {
2486                 CAM_LOG_ERROR("recv msg failed %d", errno);
2487                 ret = CAMERA_ERROR_INVALID_OPERATION;
2488                 goto _REQUEST_EXIT;
2489         }
2490
2491         if (!muse_camera_msg_get(ret, recv_msg)) {
2492                 CAM_LOG_ERROR("failed to get return value from msg [%s]", recv_msg);
2493                 ret = CAMERA_ERROR_INVALID_OPERATION;
2494                 goto _REQUEST_EXIT;
2495         }
2496
2497         if (ret == CAMERA_ERROR_NONE)
2498                 muse_core_msg_deserialize(key, recv_msg, NULL, NULL, MUSE_TYPE_ANY, value);
2499
2500         CAM_LOG_INFO("api %d - value %d", api, *value);
2501
2502 _REQUEST_EXIT:
2503         if (CAMERA_IS_FD_VALID(sock_fd)) {
2504                 muse_client_close(sock_fd);
2505                 sock_fd = CAMERA_FD_INIT;
2506         }
2507
2508         return ret;
2509 }
2510
2511
2512 int _camera_create_private(camera_device_e device, bool is_network, camera_h *camera)
2513 {
2514         int sock_fd = CAMERA_FD_INIT;
2515         char *send_msg = NULL;
2516         int send_ret = 0;
2517         int ret = CAMERA_ERROR_NONE;
2518         camera_cli_s *pc = NULL;
2519         tbm_bufmgr bufmgr = NULL;
2520
2521         muse_camera_api_e api = MUSE_CAMERA_API_CREATE;
2522         int module_index = -1;
2523         int device_type = (int)device;
2524
2525         CAM_LOG_INFO("device %d, is_network %d", device, is_network);
2526
2527         sock_fd = muse_client_new();
2528         if (sock_fd < 0) {
2529                 CAM_LOG_ERROR("muse_client_new failed - returned fd %d", sock_fd);
2530                 ret = CAMERA_ERROR_INVALID_OPERATION;
2531                 goto ErrorExit;
2532         }
2533
2534         if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
2535                 CAM_LOG_ERROR("muse client get module index failed");
2536                 ret = CAMERA_ERROR_INVALID_OPERATION;
2537                 goto ErrorExit;
2538         }
2539
2540         send_msg = muse_core_msg_new(api,
2541                 MUSE_TYPE_INT, "module", module_index,
2542                 MUSE_TYPE_INT, PARAM_DEVICE_TYPE, device_type,
2543                 MUSE_TYPE_INT, "is_network", (int)is_network,
2544                 0);
2545
2546         if (!send_msg) {
2547                 CAM_LOG_ERROR("NULL msg");
2548                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
2549                 goto ErrorExit;
2550         }
2551
2552         send_ret = muse_core_msg_send(sock_fd, send_msg);
2553
2554         muse_core_msg_free(send_msg);
2555         send_msg = NULL;
2556
2557         if (send_ret < 0) {
2558                 CAM_LOG_ERROR("send msg failed %d", errno);
2559                 ret = CAMERA_ERROR_INVALID_OPERATION;
2560                 goto ErrorExit;
2561         }
2562
2563         pc = g_new0(camera_cli_s, 1);
2564         if (pc == NULL) {
2565                 CAM_LOG_ERROR("camera_cli_s alloc failed");
2566                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
2567                 goto ErrorExit;
2568         }
2569
2570         bufmgr = tbm_bufmgr_init(-1);
2571         if (bufmgr == NULL) {
2572                 CAM_LOG_ERROR("get tbm bufmgr failed");
2573                 ret = CAMERA_ERROR_INVALID_OPERATION;
2574                 goto ErrorExit;
2575         }
2576
2577         pc->cb_info = __camera_client_callback_new(sock_fd);
2578         if (pc->cb_info == NULL) {
2579                 CAM_LOG_ERROR("cb_info alloc failed");
2580                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
2581                 goto ErrorExit;
2582         }
2583
2584         sock_fd = CAMERA_FD_INIT;
2585
2586         CAM_LOG_INFO("cb info : %d", pc->cb_info->fd);
2587
2588         ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
2589
2590         pc->cb_info->api_waiting[MUSE_CAMERA_API_CREATE] = 0;
2591
2592         if (ret == CAMERA_ERROR_NONE) {
2593                 int preview_format = CAMERA_PIXEL_FORMAT_INVALID;
2594                 int user_buffer_supported = 0;
2595                 int log_level = CAMERA_LOG_LEVEL_INFO;
2596                 intptr_t handle = 0;
2597
2598                 muse_camera_msg_get_pointer(handle, pc->cb_info->recv_msg);
2599                 if (handle == 0) {
2600                         CAM_LOG_ERROR("Receiving Handle Failed!!");
2601                         ret = CAMERA_ERROR_INVALID_OPERATION;
2602                         goto ErrorExit;
2603                 }
2604
2605                 muse_camera_msg_get(preview_format, pc->cb_info->recv_msg);
2606                 muse_camera_msg_get(user_buffer_supported, pc->cb_info->recv_msg);
2607                 muse_camera_msg_get(log_level, pc->cb_info->recv_msg);
2608
2609                 pc->remote_handle = handle;
2610                 pc->cb_info->bufmgr = bufmgr;
2611                 pc->cb_info->preview_format = preview_format;
2612                 pc->cb_info->dp_info.type = CAMERA_DISPLAY_TYPE_NONE;
2613                 pc->cb_info->user_buffer_supported = (gboolean)user_buffer_supported;
2614                 pc->cb_info->is_network = is_network;
2615                 g_camera_log_level = log_level;
2616
2617                 CAM_LOG_INFO("default preview format %d, user buffer %d, log level %d",
2618                         preview_format, user_buffer_supported, g_camera_log_level);
2619
2620                 if (!camera) {
2621                         CAM_LOG_ERROR("NULL out handle");
2622                         ret= CAMERA_ERROR_INVALID_PARAMETER;
2623                         goto ErrorExit;
2624                 }
2625
2626                 *camera = (camera_h)pc;
2627
2628                 /* get display interface handle */
2629                 if (mm_display_interface_init(&pc->cb_info->dp_interface) != MM_ERROR_NONE)
2630                         CAM_LOG_WARNING("display interface init failed");
2631         } else {
2632                 goto ErrorExit;
2633         }
2634
2635         return ret;
2636 //LCOV_EXCL_START
2637 ErrorExit:
2638         if (bufmgr) {
2639                 tbm_bufmgr_deinit(bufmgr);
2640                 bufmgr = NULL;
2641         }
2642
2643         if (CAMERA_IS_FD_VALID(sock_fd)) {
2644                 muse_client_close(sock_fd);
2645                 sock_fd = CAMERA_FD_INIT;
2646         }
2647
2648         if (pc) {
2649                 if (pc->cb_info) {
2650                         int temp_fd = pc->cb_info->fd;
2651
2652                         /* pc->cb_info->fd should be closed,
2653                            because g_thread_join for msg_recv_thread is not returned
2654                            in __camera_client_callback_destroy. */
2655                         if (CAMERA_IS_FD_VALID(temp_fd)) {
2656                                 pc->cb_info->fd = CAMERA_FD_INIT;
2657                                 muse_client_close(temp_fd);
2658                         }
2659
2660                         __camera_client_callback_destroy(pc->cb_info);
2661                         pc->cb_info = NULL;
2662                 }
2663                 g_free(pc);
2664                 pc = NULL;
2665         }
2666
2667         CAM_LOG_ERROR("camera create error : 0x%x", ret);
2668
2669         return ret;
2670 //LCOV_EXCL_STOP
2671 }
2672
2673
2674 int camera_create(camera_device_e device, camera_h *camera)
2675 {
2676         return _camera_create_private(device, false, camera);
2677 }
2678
2679
2680 int camera_change_device(camera_h camera, camera_device_e device)
2681 {
2682         int i = 0;
2683         int ret = CAMERA_ERROR_NONE;
2684         muse_camera_api_e api = MUSE_CAMERA_API_CHANGE_DEVICE;
2685         camera_cli_s *pc = (camera_cli_s *)camera;
2686         camera_msg_param param;
2687
2688         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2689
2690         CAMERA_MSG_PARAM_SET(param, INT, device);
2691
2692         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
2693
2694         if (ret == CAMERA_ERROR_NONE) {
2695                 /* reset callback and user data */
2696                 for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++) {
2697                         pc->cb_info->user_cb[i] = NULL;
2698                         pc->cb_info->user_data[i] = NULL;
2699                 }
2700         }
2701
2702         return ret;
2703 }
2704
2705
2706 int camera_destroy(camera_h camera)
2707 {
2708         int ret = CAMERA_ERROR_NONE;
2709         muse_camera_api_e api = MUSE_CAMERA_API_DESTROY;
2710         camera_cli_s *pc = (camera_cli_s *)camera;
2711
2712         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2713
2714         CAM_LOG_INFO("Enter");
2715
2716         if (pc->cb_info->is_server_connected)
2717                 _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2718         else
2719                 CAM_LOG_WARNING("server disconnected. release resource without send message.");
2720
2721         if (ret == CAMERA_ERROR_NONE) {
2722                 __camera_deactivate_idle_event_all(pc->cb_info);
2723                 __camera_client_callback_destroy(pc->cb_info);
2724                 pc->cb_info = NULL;
2725
2726                 g_free(pc);
2727                 pc = NULL;
2728         }
2729
2730         CAM_LOG_INFO("ret : 0x%x", ret);
2731
2732         return ret;
2733 }
2734
2735 int camera_start_preview(camera_h camera)
2736 {
2737         int ret = CAMERA_ERROR_NONE;
2738         int *fds = NULL;
2739         muse_camera_api_e api = MUSE_CAMERA_API_START_PREVIEW;
2740         camera_cli_s *pc = (camera_cli_s *)camera;
2741         camera_state_e current_state = CAMERA_STATE_NONE;
2742
2743         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2744
2745         CAM_LOG_INFO("Enter : preview format %d, display type %d",
2746                 pc->cb_info->preview_format, pc->cb_info->dp_info.type);
2747
2748         if (pc->cb_info->preview_format == CAMERA_PIXEL_FORMAT_INVZ &&
2749                 pc->cb_info->dp_info.type != CAMERA_DISPLAY_TYPE_NONE) {
2750                 CAM_LOG_ERROR("CAMERA_DISPLAY_TYPE_NONE[current %d] should be set with INVZ format",
2751                         pc->cb_info->dp_info.type);
2752                 return CAMERA_ERROR_INVALID_OPERATION;
2753         }
2754
2755         ret = camera_get_state(camera, &current_state);
2756         if (ret != CAMERA_ERROR_NONE) {
2757                 CAM_LOG_ERROR("failed to get current state 0x%x", ret);
2758                 return ret;
2759         }
2760
2761         if (current_state == CAMERA_STATE_CREATED) {
2762                 if (!__create_msg_handler_thread(&pc->cb_info->preview_cb_info,
2763                                 CAMERA_MESSAGE_HANDLER_TYPE_PREVIEW_CB, "cam:preview_cb", pc->cb_info)) {
2764                         CAM_LOG_ERROR("preview_cb_info failed");
2765                         return CAMERA_ERROR_INVALID_OPERATION;
2766                 }
2767
2768                 if (pc->cb_info->user_buffer_supported) {
2769                         if (!__camera_allocate_preview_buffer(camera)) {
2770                                 ret = CAMERA_ERROR_INVALID_OPERATION;
2771                                 goto _START_FAILED;
2772                         }
2773
2774                         fds = pc->cb_info->fds;
2775                 }
2776         }
2777
2778         pc->cb_info->invoke_preview_cb = TRUE;
2779
2780         _camera_msg_send(api, fds, pc->cb_info, &ret,
2781 #ifdef TIZEN_FEATURE_NO_TIMEOUT_FOR_PREVIEW
2782                 CAMERA_CB_NO_TIMEOUT);
2783 #else
2784                 (pc->cb_info->is_network ? CAMERA_CB_NETWORK_PREVIEW_TIMEOUT : CAMERA_CB_TIMEOUT));
2785 #endif
2786         if (ret != CAMERA_ERROR_NONE)
2787                 goto _START_FAILED;
2788
2789         if (pc->cb_info->is_evas_render) {
2790                 ret = _camera_start_evas_rendering(camera);
2791                 if (ret != CAMERA_ERROR_NONE) {
2792                         CAM_LOG_ERROR("stop preview because of error");
2793                         _camera_msg_send(MUSE_CAMERA_API_STOP_PREVIEW, NULL, pc->cb_info, NULL, 0);
2794                         goto _START_FAILED;
2795                 }
2796         }
2797
2798         CAM_LOG_INFO("done");
2799
2800         return CAMERA_ERROR_NONE;
2801
2802 _START_FAILED:
2803         if (current_state == CAMERA_STATE_CREATED) {
2804                 if (pc->cb_info->user_buffer_supported)
2805                         __camera_release_preview_buffer(camera);
2806
2807                 __destroy_msg_handler_thread(&pc->cb_info->preview_cb_info);
2808         }
2809
2810         CAM_LOG_ERROR("failed : 0x%x", ret);
2811
2812         return ret;
2813 }
2814
2815
2816 int camera_stop_preview(camera_h camera)
2817 {
2818         int ret = CAMERA_ERROR_NONE;
2819         camera_cli_s *pc = (camera_cli_s *)camera;
2820         muse_camera_api_e api = MUSE_CAMERA_API_STOP_PREVIEW;
2821         camera_state_e current_state = CAMERA_STATE_NONE;
2822
2823         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2824
2825         CAM_LOG_INFO("Enter");
2826
2827 //LCOV_EXCL_START
2828         if (pc->cb_info->is_evas_render) {
2829                 ret = camera_get_state(camera, &current_state);
2830                 if (ret != CAMERA_ERROR_NONE) {
2831                         CAM_LOG_ERROR("failed to get current state 0x%x", ret);
2832                         return ret;
2833                 }
2834
2835                 if (current_state == CAMERA_STATE_PREVIEW) {
2836                         ret = _camera_stop_evas_rendering(camera, false);
2837                         if (ret != CAMERA_ERROR_NONE)
2838                                 return ret;
2839                 }
2840         }
2841 //LCOV_EXCL_STOP
2842
2843         pc->cb_info->invoke_preview_cb = FALSE;
2844
2845         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2846
2847         if (ret == CAMERA_ERROR_NONE) {
2848                 if (pc->cb_info->user_buffer_supported)
2849                         __camera_release_preview_buffer(camera);
2850
2851                 /* release remained message for preview callback */
2852                 __destroy_msg_handler_thread(&pc->cb_info->preview_cb_info);
2853         } else if (current_state == CAMERA_STATE_PREVIEW) {
2854                 CAM_LOG_WARNING("restart evas rendering");
2855                 _camera_start_evas_rendering(camera);
2856         }
2857
2858         CAM_LOG_INFO("ret : 0x%x", ret);
2859
2860         return ret;
2861 }
2862
2863
2864 int camera_start_capture(camera_h camera, camera_capturing_cb capturing_cb, camera_capture_completed_cb completed_cb, void *user_data)
2865 {
2866         int ret = CAMERA_ERROR_NONE;
2867         camera_cli_s *pc = (camera_cli_s *)camera;
2868         muse_camera_api_e api = MUSE_CAMERA_API_START_CAPTURE;
2869
2870         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2871
2872         CAM_LOG_INFO("Enter");
2873
2874         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = capturing_cb;
2875         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = user_data;
2876
2877         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = completed_cb;
2878         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = user_data;
2879
2880         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2881
2882         CAM_LOG_INFO("ret : 0x%x", ret);
2883
2884         return ret;
2885 }
2886
2887
2888 bool camera_is_supported_continuous_capture(camera_h camera)
2889 {
2890         return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_CONTINUOUS_CAPTURE);
2891 }
2892
2893
2894 int camera_start_continuous_capture(camera_h camera, int count, int interval, camera_capturing_cb capturing_cb, camera_capture_completed_cb completed_cb, void *user_data)
2895 {
2896         int ret = CAMERA_ERROR_NONE;
2897         camera_cli_s *pc = (camera_cli_s *)camera;
2898         muse_camera_api_e api = MUSE_CAMERA_API_START_CONTINUOUS_CAPTURE;
2899         camera_msg_param param;
2900         int value = 0;
2901
2902         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2903
2904         CAM_LOG_INFO("Enter");
2905
2906         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = capturing_cb;
2907         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = user_data;
2908
2909         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = completed_cb;
2910         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = user_data;
2911
2912         value = (count << 16) | interval;
2913         CAMERA_MSG_PARAM_SET(param, INT, value);
2914
2915         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
2916
2917         CAM_LOG_INFO("ret : 0x%x", ret);
2918
2919         return ret;
2920 }
2921
2922
2923 int camera_stop_continuous_capture(camera_h camera)
2924 {
2925         int ret = CAMERA_ERROR_NONE;
2926         camera_cli_s *pc = (camera_cli_s *)camera;
2927         muse_camera_api_e api = MUSE_CAMERA_API_STOP_CONTINUOUS_CAPTURE;
2928
2929         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2930
2931         CAM_LOG_INFO("Enter");
2932
2933         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2934
2935         CAM_LOG_INFO("ret : 0x%x", ret);
2936
2937         return ret;
2938 }
2939
2940
2941 bool camera_is_supported_face_detection(camera_h camera)
2942 {
2943         return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_FACE_DETECTION);
2944 }
2945
2946
2947 bool camera_is_supported_zero_shutter_lag(camera_h camera)
2948 {
2949         return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_ZERO_SHUTTER_LAG);
2950 }
2951
2952
2953 bool camera_is_supported_media_packet_preview_cb(camera_h camera)
2954 {
2955         return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_MEDIA_PACKET_PREVIEW_CB);
2956 }
2957
2958
2959 bool camera_is_supported_extra_preview(camera_h camera)
2960 {
2961         return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_EXTRA_PREVIEW);
2962 }
2963
2964
2965 int camera_get_device_count(camera_h camera, int *device_count)
2966 {
2967         int ret = CAMERA_ERROR_NONE;
2968         camera_cli_s *pc = (camera_cli_s *)camera;
2969         muse_camera_api_e api = MUSE_CAMERA_API_GET_DEVICE_COUNT;
2970
2971         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2972
2973         CAM_LOG_INFO("Enter");
2974
2975         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2976
2977         if (ret == CAMERA_ERROR_NONE)
2978                 *device_count = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DEVICE_COUNT];
2979
2980         CAM_LOG_INFO("ret : 0x%x", ret);
2981
2982         return ret;
2983 }
2984
2985 int camera_start_face_detection(camera_h camera, camera_face_detected_cb callback, void *user_data)
2986 {
2987         int ret = CAMERA_ERROR_NONE;
2988         camera_cli_s *pc = (camera_cli_s *)camera;
2989         muse_camera_api_e api = MUSE_CAMERA_API_START_FACE_DETECTION;
2990
2991         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2992
2993         CAM_LOG_INFO("Enter");
2994
2995         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2996
2997         if (ret == CAMERA_ERROR_NONE) {
2998                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
2999
3000                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = callback;
3001                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = user_data;
3002
3003                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
3004         }
3005
3006         CAM_LOG_INFO("ret : 0x%x", ret);
3007
3008         return ret;
3009 }
3010
3011 int camera_stop_face_detection(camera_h camera)
3012 {
3013         int ret = CAMERA_ERROR_NONE;
3014         camera_cli_s *pc = (camera_cli_s *)camera;
3015         muse_camera_api_e api = MUSE_CAMERA_API_STOP_FACE_DETECTION;
3016
3017         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3018
3019         CAM_LOG_INFO("Enter");
3020
3021         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3022
3023         if (ret == CAMERA_ERROR_NONE) {
3024                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
3025
3026                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = NULL;
3027                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = NULL;
3028
3029                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
3030         }
3031
3032         CAM_LOG_INFO("ret : 0x%x", ret);
3033
3034         return ret;
3035 }
3036
3037 int camera_get_state(camera_h camera, camera_state_e *state)
3038 {
3039         int ret = CAMERA_ERROR_NONE;
3040         camera_cli_s *pc = (camera_cli_s *)camera;
3041         muse_camera_api_e api = MUSE_CAMERA_API_GET_STATE;
3042
3043         if (!pc || !pc->cb_info || !state) {
3044                 CAM_LOG_ERROR("NULL pointer %p %p", pc, state);
3045                 return CAMERA_ERROR_INVALID_PARAMETER;
3046         }
3047
3048         CAM_LOG_INFO("Enter");
3049
3050         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3051
3052         if (ret == CAMERA_ERROR_NONE)
3053                 *state = (camera_state_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STATE];
3054
3055         CAM_LOG_INFO("ret : 0x%x", ret);
3056
3057         return ret;
3058 }
3059
3060 int camera_start_focusing(camera_h camera, bool continuous)
3061 {
3062         int ret = CAMERA_ERROR_NONE;
3063         camera_cli_s *pc = (camera_cli_s *)camera;
3064         muse_camera_api_e api = MUSE_CAMERA_API_START_FOCUSING;
3065         camera_msg_param param;
3066         int is_continuous = (int)continuous;
3067
3068         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3069
3070         CAM_LOG_INFO("Enter");
3071
3072         CAMERA_MSG_PARAM_SET(param, INT, is_continuous);
3073
3074         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3075
3076         CAM_LOG_INFO("ret : 0x%x", ret);
3077
3078         return ret;
3079 }
3080
3081 int camera_cancel_focusing(camera_h camera)
3082 {
3083         int ret = CAMERA_ERROR_NONE;
3084         camera_cli_s *pc = (camera_cli_s *)camera;
3085         muse_camera_api_e api = MUSE_CAMERA_API_CANCEL_FOCUSING;
3086
3087         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3088
3089         CAM_LOG_INFO("Enter, remote_handle : %td", pc->remote_handle);
3090
3091         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3092
3093         CAM_LOG_INFO("ret : 0x%x", ret);
3094
3095         return ret;
3096 }
3097
3098
3099 int _camera_set_display(camera_h camera, mm_display_type_e type, void *display)
3100 {
3101         int mm_ret = MM_ERROR_NONE;
3102         int ret = CAMERA_ERROR_NONE;
3103         camera_cli_s *pc = (camera_cli_s *)camera;
3104         camera_cb_info_s *cb_info = NULL;
3105         camera_state_e current_state = CAMERA_STATE_NONE;
3106         camera_msg_param param;
3107         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY;
3108         muse_camera_display_info_s *dp_info = NULL;
3109
3110         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3111
3112         if (type > MM_DISPLAY_TYPE_OVERLAY_EXT) {
3113                 CAM_LOG_ERROR("invalid type %d", type);
3114                 return CAMERA_ERROR_INVALID_PARAMETER;
3115         }
3116
3117         if (type != MM_DISPLAY_TYPE_NONE && display == NULL) {
3118                 CAM_LOG_ERROR("display type[%d] is not NONE, but display handle is NULL", type);
3119                 return CAMERA_ERROR_INVALID_PARAMETER;
3120         }
3121
3122         cb_info = (camera_cb_info_s *)pc->cb_info;
3123         dp_info = &cb_info->dp_info;
3124
3125         ret = camera_get_state(camera, &current_state);
3126         if (ret != CAMERA_ERROR_NONE) {
3127                 CAM_LOG_ERROR("failed to get current state 0x%x", ret);
3128                 return ret;
3129         }
3130
3131         if (current_state != CAMERA_STATE_CREATED) {
3132                 CAM_LOG_ERROR("INVALID_STATE : current %d", current_state);
3133                 return CAMERA_ERROR_INVALID_STATE;
3134         }
3135
3136         CAM_LOG_INFO("Enter - type : %d, display : %p", type, display);
3137
3138         if (type != MM_DISPLAY_TYPE_NONE) {
3139                 /* check display interface handle */
3140                 if (!cb_info->dp_interface) {
3141                         CAM_LOG_ERROR("display interface not supported");
3142                         return CAMERA_ERROR_NOT_SUPPORTED;
3143                 }
3144
3145                 mm_ret = mm_display_interface_set_display(cb_info->dp_interface, type, display, &dp_info->parent_id);
3146                 if (mm_ret == (int)MM_ERROR_NOT_SUPPORT_API) {
3147                         CAM_LOG_ERROR("[NOT_SUPPORTED] type %d", type);
3148                         return CAMERA_ERROR_NOT_SUPPORTED;
3149                 } else if (mm_ret != MM_ERROR_NONE) {
3150                         CAM_LOG_ERROR("[INVALID_OPERATION] set display failed[0x%x]", mm_ret);
3151                         return CAMERA_ERROR_INVALID_OPERATION;
3152                 }
3153
3154                 if (type == MM_DISPLAY_TYPE_OVERLAY || type == MM_DISPLAY_TYPE_OVERLAY_EXT) {
3155                         mm_ret = mm_display_interface_get_window_rect(cb_info->dp_interface, &dp_info->window_rect);
3156
3157                         CAM_LOG_INFO("ret 0x%x, parent_id %d, window rect %d,%d,%dx%d",
3158                                 ret, dp_info->parent_id, dp_info->window_rect.x, dp_info->window_rect.y,
3159                                 dp_info->window_rect.width, dp_info->window_rect.height);
3160                 } else if (type == MM_DISPLAY_TYPE_EVAS) {
3161 //LCOV_EXCL_START
3162                         camera_flip_e flip = CAMERA_FLIP_NONE;
3163                         camera_display_mode_e mode = CAMERA_DISPLAY_MODE_LETTER_BOX;
3164                         camera_rotation_e rotation = CAMERA_ROTATION_NONE;
3165                         bool visible = 0;
3166                         int x = 0;
3167                         int y = 0;
3168                         int width = 0;
3169                         int height = 0;
3170
3171                         camera_get_display_flip(camera, &flip);
3172                         camera_get_display_mode(camera, &mode);
3173                         camera_get_display_rotation(camera, &rotation);
3174                         camera_is_display_visible(camera, &visible);
3175
3176                         CAM_LOG_INFO("current setting : flip %d, mode %d, rotation %d, visible %d",
3177                                 flip, mode, rotation, visible);
3178
3179                         mm_ret = mm_display_interface_evas_set_flip(cb_info->dp_interface, flip);
3180                         mm_ret |= mm_display_interface_evas_set_mode(cb_info->dp_interface, mode);
3181                         mm_ret |= mm_display_interface_evas_set_rotation(cb_info->dp_interface, rotation);
3182                         mm_ret |= mm_display_interface_evas_set_visible(cb_info->dp_interface, visible);
3183
3184                         if (mode == CAMERA_DISPLAY_MODE_CUSTOM_ROI) {
3185                                 camera_attr_get_display_roi_area(camera, &x, &y, &width, &height);
3186                                 CAM_LOG_INFO("current setting : roi %d,%d,%dx%d", x, y, width, height);
3187                                 mm_ret |= mm_display_interface_evas_set_roi_area(cb_info->dp_interface, x, y, width, height);
3188                         }
3189 //LCOV_EXCL_STOP
3190                 }
3191         }
3192
3193         if (mm_ret != MM_ERROR_NONE) {
3194                 CAM_LOG_ERROR("mm_ret 0x%x failed", mm_ret);
3195                 return CAMERA_ERROR_INVALID_OPERATION;
3196         }
3197
3198         dp_info->type = type;
3199
3200         CAMERA_MSG_PARAM_SET_ARRAY(param, ARRAY, dp_info, sizeof(muse_camera_display_info_s));
3201
3202         _camera_msg_send_param1(api, cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3203
3204         if (ret == CAMERA_ERROR_NONE)
3205                 cb_info->is_evas_render = (type == MM_DISPLAY_TYPE_EVAS) ? TRUE : FALSE;
3206
3207         return ret;
3208 }
3209
3210
3211 int camera_set_display(camera_h camera, camera_display_type_e type, camera_display_h display)
3212 {
3213         CAM_LOG_INFO("type %d, display %p", type, display);
3214         return _camera_set_display(camera, (mm_display_type_e)type, display);
3215 }
3216
3217
3218 int camera_set_preview_resolution(camera_h camera, int width, int height)
3219 {
3220         int ret = CAMERA_ERROR_NONE;
3221         camera_state_e current_state = CAMERA_STATE_NONE;
3222         camera_cli_s *pc = (camera_cli_s *)camera;
3223         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_RESOLUTION;
3224         camera_msg_param param;
3225         int value = 0;
3226
3227         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3228
3229         if (pc->cb_info->is_evas_render) {
3230                 ret = camera_get_state(camera, &current_state);
3231                 if (ret != CAMERA_ERROR_NONE) {
3232                         CAM_LOG_ERROR("failed to get current state 0x%x", ret);
3233                         return ret;
3234                 }
3235
3236                 if (current_state == CAMERA_STATE_PREVIEW) {
3237                         ret = _camera_stop_evas_rendering(camera, true);
3238                         if (ret != CAMERA_ERROR_NONE)
3239                                 return ret;
3240                 }
3241         }
3242
3243         value = (width << 16) | height;
3244         CAMERA_MSG_PARAM_SET(param, INT, value);
3245
3246         CAM_LOG_INFO("%dx%d -> 0x%x", width, height, value);
3247
3248         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3249
3250         CAM_LOG_INFO("ret : 0x%x", ret);
3251
3252         if (current_state == CAMERA_STATE_PREVIEW) {
3253                 CAM_LOG_WARNING("restart evas rendering");
3254                 _camera_start_evas_rendering(camera);
3255         }
3256
3257         return ret;
3258 }
3259
3260
3261 int camera_set_capture_resolution(camera_h camera, int width, int height)
3262 {
3263         int ret = CAMERA_ERROR_NONE;
3264         camera_cli_s *pc = (camera_cli_s *)camera;
3265         muse_camera_api_e api = MUSE_CAMERA_API_SET_CAPTURE_RESOLUTION;
3266         camera_msg_param param;
3267         int value = 0;
3268
3269         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3270
3271         CAM_LOG_INFO("Enter");
3272
3273         value = (width << 16) | height;
3274         CAMERA_MSG_PARAM_SET(param, INT, value);
3275
3276         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3277
3278         CAM_LOG_INFO("ret : 0x%x", ret);
3279
3280         return ret;
3281 }
3282
3283
3284 int camera_set_capture_format(camera_h camera, camera_pixel_format_e format)
3285 {
3286         int ret = CAMERA_ERROR_NONE;
3287         int set_format = (int)format;
3288         camera_cli_s *pc = (camera_cli_s *)camera;
3289         muse_camera_api_e api = MUSE_CAMERA_API_SET_CAPTURE_FORMAT;
3290         camera_msg_param param;
3291
3292         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3293
3294         CAM_LOG_INFO("Enter - format %d", set_format);
3295
3296         CAMERA_MSG_PARAM_SET(param, INT, set_format);
3297
3298         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3299
3300         CAM_LOG_INFO("ret : 0x%x", ret);
3301
3302         return ret;
3303 }
3304
3305
3306 int camera_set_preview_format(camera_h camera, camera_pixel_format_e format)
3307 {
3308         int ret = CAMERA_ERROR_NONE;
3309         int set_format = (int)format;
3310         camera_msg_param param;
3311         camera_cli_s *pc = (camera_cli_s *)camera;
3312         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_FORMAT;
3313
3314         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3315
3316         CAM_LOG_INFO("Enter - format %d", set_format);
3317
3318         CAMERA_MSG_PARAM_SET(param, INT, set_format);
3319
3320         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3321
3322         if (ret == CAMERA_ERROR_NONE)
3323                 pc->cb_info->preview_format = set_format;
3324
3325         CAM_LOG_INFO("ret : 0x%x", ret);
3326
3327         return ret;
3328 }
3329
3330
3331 int camera_get_preview_resolution(camera_h camera, int *width, int *height)
3332 {
3333         int ret = CAMERA_ERROR_NONE;
3334         camera_cli_s *pc = (camera_cli_s *)camera;
3335         muse_camera_api_e api = MUSE_CAMERA_API_GET_PREVIEW_RESOLUTION;
3336
3337         if (!pc || !pc->cb_info || !width || !height) {
3338                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, width, height);
3339                 return CAMERA_ERROR_INVALID_PARAMETER;
3340         }
3341
3342         CAM_LOG_INFO("Enter");
3343
3344         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3345
3346         if (ret == CAMERA_ERROR_NONE) {
3347                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_RESOLUTION] >> 16;
3348                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_RESOLUTION];
3349         }
3350
3351         CAM_LOG_INFO("ret : 0x%x", ret);
3352
3353         return ret;
3354 }
3355
3356
3357 int camera_set_display_rotation(camera_h camera, camera_rotation_e rotation)
3358 {
3359         int ret = CAMERA_ERROR_NONE;
3360         int set_rotation = (int)rotation;
3361         camera_cli_s *pc = (camera_cli_s *)camera;
3362         camera_msg_param param;
3363
3364         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3365
3366         if (pc->cb_info->is_evas_render) {
3367                 ret = mm_display_interface_evas_set_rotation(pc->cb_info->dp_interface, rotation);
3368                 if (ret != MM_ERROR_NONE) {
3369                         CAM_LOG_ERROR("failed to set rotation for evas surface 0x%x", ret);
3370                         return CAMERA_ERROR_INVALID_OPERATION;
3371                 }
3372         }
3373
3374         CAMERA_MSG_PARAM_SET(param, INT, set_rotation);
3375
3376         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_ROTATION, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3377
3378         return ret;
3379 }
3380
3381
3382 int camera_get_display_rotation(camera_h camera, camera_rotation_e *rotation)
3383 {
3384         int ret = CAMERA_ERROR_NONE;
3385         camera_cli_s *pc = (camera_cli_s *)camera;
3386
3387         if (!pc || !pc->cb_info || !rotation) {
3388                 CAM_LOG_ERROR("NULL pointer %p %p", pc, rotation);
3389                 return CAMERA_ERROR_INVALID_PARAMETER;
3390         }
3391
3392         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_ROTATION, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3393
3394         if (ret == CAMERA_ERROR_NONE)
3395                 *rotation = (camera_rotation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_ROTATION];
3396
3397         return ret;
3398 }
3399
3400
3401 int camera_set_display_flip(camera_h camera, camera_flip_e flip)
3402 {
3403         int ret = CAMERA_ERROR_NONE;
3404         int set_flip = (int)flip;
3405         camera_cli_s *pc = (camera_cli_s *)camera;
3406         camera_msg_param param;
3407
3408         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3409
3410         if (pc->cb_info->is_evas_render) {
3411                 ret = mm_display_interface_evas_set_flip(pc->cb_info->dp_interface, flip);
3412                 if (ret != MM_ERROR_NONE) {
3413                         CAM_LOG_ERROR("failed to set flip for evas surface 0x%x", ret);
3414                         return CAMERA_ERROR_INVALID_OPERATION;
3415                 }
3416         }
3417
3418         CAMERA_MSG_PARAM_SET(param, INT, set_flip);
3419
3420         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_FLIP, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3421
3422         return ret;
3423 }
3424
3425
3426 int camera_get_display_flip(camera_h camera, camera_flip_e *flip)
3427 {
3428         int ret = CAMERA_ERROR_NONE;
3429         camera_cli_s *pc = (camera_cli_s *)camera;
3430
3431         if (!pc || !pc->cb_info || !flip) {
3432                 CAM_LOG_ERROR("NULL pointer %p %p", pc, flip);
3433                 return CAMERA_ERROR_INVALID_PARAMETER;
3434         }
3435
3436         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_FLIP, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3437
3438         if (ret == CAMERA_ERROR_NONE)
3439                 *flip = (camera_flip_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_FLIP];
3440
3441         return ret;
3442 }
3443
3444
3445 int camera_set_display_visible(camera_h camera, bool visible)
3446 {
3447         int ret = CAMERA_ERROR_NONE;
3448         int set_visible = (int)visible;
3449         camera_cli_s *pc = (camera_cli_s *)camera;
3450         camera_msg_param param;
3451
3452         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3453
3454         if (pc->cb_info->is_evas_render) {
3455                 ret = mm_display_interface_evas_set_visible(pc->cb_info->dp_interface, visible);
3456                 if (ret != MM_ERROR_NONE) {
3457                         CAM_LOG_ERROR("failed to set visible for evas surface 0x%x", ret);
3458                         return CAMERA_ERROR_INVALID_OPERATION;
3459                 }
3460         }
3461
3462         CAMERA_MSG_PARAM_SET(param, INT, set_visible);
3463
3464         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_VISIBLE, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3465
3466         return ret;
3467 }
3468
3469
3470 int camera_is_display_visible(camera_h camera, bool *visible)
3471 {
3472         int ret = CAMERA_ERROR_NONE;
3473         camera_cli_s *pc = (camera_cli_s *)camera;
3474
3475         if (!pc || !pc->cb_info || !visible) {
3476                 CAM_LOG_ERROR("NULL pointer %p %p", pc, visible);
3477                 return CAMERA_ERROR_INVALID_PARAMETER;
3478         }
3479
3480         _camera_msg_send(MUSE_CAMERA_API_IS_DISPLAY_VISIBLE, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3481
3482         if (ret == CAMERA_ERROR_NONE)
3483                 *visible = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_VISIBLE];
3484
3485         return ret;
3486 }
3487
3488
3489 int camera_set_display_mode(camera_h camera, camera_display_mode_e mode)
3490 {
3491         int ret = CAMERA_ERROR_NONE;
3492         int set_mode = (int)mode;
3493         camera_cli_s *pc = (camera_cli_s *)camera;
3494         camera_msg_param param;
3495
3496         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3497
3498         if (pc->cb_info->is_evas_render) {
3499                 ret = mm_display_interface_evas_set_mode(pc->cb_info->dp_interface, mode);
3500                 if (ret != MM_ERROR_NONE) {
3501                         CAM_LOG_ERROR("failed to set geometry for evas surface 0x%x", ret);
3502                         return CAMERA_ERROR_INVALID_OPERATION;
3503                 }
3504         }
3505
3506         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
3507
3508         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_MODE, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3509
3510         return ret;
3511 }
3512
3513
3514 int camera_get_display_mode(camera_h camera, camera_display_mode_e *mode)
3515 {
3516         int ret = CAMERA_ERROR_NONE;
3517         camera_cli_s *pc = (camera_cli_s *)camera;
3518
3519         if (!pc || !pc->cb_info || !mode) {
3520                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
3521                 return CAMERA_ERROR_INVALID_PARAMETER;
3522         }
3523
3524         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_MODE, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3525
3526         if (ret == CAMERA_ERROR_NONE)
3527                 *mode = (camera_display_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_MODE];
3528
3529         return ret;
3530 }
3531
3532
3533 int camera_set_display_reuse_hint(camera_h camera, bool hint)
3534 {
3535         int ret = CAMERA_ERROR_NONE;
3536         int set_hint = (int)hint;
3537         camera_cli_s *pc = (camera_cli_s *)camera;
3538         camera_msg_param param;
3539
3540         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3541
3542         CAM_LOG_INFO("Enter - hint %d", set_hint);
3543
3544         CAMERA_MSG_PARAM_SET(param, INT, set_hint);
3545
3546         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_REUSE_HINT, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3547
3548         return ret;
3549 }
3550
3551
3552 int camera_get_display_reuse_hint(camera_h camera, bool *hint)
3553 {
3554         int ret = CAMERA_ERROR_NONE;
3555         camera_cli_s *pc = (camera_cli_s *)camera;
3556         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_REUSE_HINT;
3557
3558         if (!pc || !pc->cb_info || !hint) {
3559                 CAM_LOG_ERROR("NULL pointer %p %p", pc, hint);
3560                 return CAMERA_ERROR_INVALID_PARAMETER;
3561         }
3562
3563         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3564
3565         if (ret == CAMERA_ERROR_NONE) {
3566                 *hint = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_REUSE_HINT];
3567                 CAM_LOG_INFO("display reuse hint %d", *hint);
3568         }
3569
3570         return ret;
3571 }
3572
3573
3574 int camera_get_capture_resolution(camera_h camera, int *width, int *height)
3575 {
3576         int ret = CAMERA_ERROR_NONE;
3577         camera_cli_s *pc = (camera_cli_s *)camera;
3578         muse_camera_api_e api = MUSE_CAMERA_API_GET_CAPTURE_RESOLUTION;
3579
3580         if (!pc || !pc->cb_info || !width || !height) {
3581                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, width, height);
3582                 return CAMERA_ERROR_INVALID_PARAMETER;
3583         }
3584
3585         CAM_LOG_INFO("Enter");
3586
3587         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3588
3589         if (ret == CAMERA_ERROR_NONE) {
3590                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_RESOLUTION] >> 16;
3591                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_RESOLUTION];
3592         }
3593
3594         CAM_LOG_INFO("ret : 0x%x", ret);
3595
3596         return ret;
3597 }
3598
3599
3600 int camera_get_capture_format(camera_h camera, camera_pixel_format_e *format)
3601 {
3602         int ret = CAMERA_ERROR_NONE;
3603         camera_cli_s *pc = (camera_cli_s *)camera;
3604         muse_camera_api_e api = MUSE_CAMERA_API_GET_CAPTURE_FORMAT;
3605
3606         if (!pc || !pc->cb_info || !format) {
3607                 CAM_LOG_ERROR("NULL pointer %p %p", pc, format);
3608                 return CAMERA_ERROR_INVALID_PARAMETER;
3609         }
3610
3611         CAM_LOG_INFO("Enter");
3612
3613         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3614
3615         if (ret == CAMERA_ERROR_NONE)
3616                 *format = (camera_pixel_format_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_FORMAT];
3617
3618         CAM_LOG_INFO("ret : 0x%x", ret);
3619
3620         return ret;
3621 }
3622
3623
3624 int camera_get_preview_format(camera_h camera, camera_pixel_format_e *format)
3625 {
3626         int ret = CAMERA_ERROR_NONE;
3627         camera_cli_s *pc = (camera_cli_s *)camera;
3628         muse_camera_api_e api = MUSE_CAMERA_API_GET_PREVIEW_FORMAT;
3629
3630         if (!pc || !pc->cb_info || !format) {
3631                 CAM_LOG_ERROR("NULL pointer %p %p", pc, format);
3632                 return CAMERA_ERROR_INVALID_PARAMETER;
3633         }
3634
3635         CAM_LOG_INFO("Enter");
3636
3637         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3638
3639         if (ret == CAMERA_ERROR_NONE)
3640                 *format = (camera_pixel_format_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_FORMAT];
3641
3642         CAM_LOG_INFO("ret : 0x%x", ret);
3643
3644         return ret;
3645 }
3646
3647
3648 int camera_get_facing_direction(camera_h camera, camera_facing_direction_e *facing_direction)
3649 {
3650         int ret = CAMERA_ERROR_NONE;
3651         camera_cli_s *pc = (camera_cli_s *)camera;
3652         muse_camera_api_e api = MUSE_CAMERA_API_GET_FACING_DIRECTION;
3653
3654         if (!pc || !pc->cb_info || !facing_direction) {
3655                 CAM_LOG_ERROR("NULL pointer %p %p", pc, facing_direction);
3656                 return CAMERA_ERROR_INVALID_PARAMETER;
3657         }
3658
3659         CAM_LOG_INFO("Enter");
3660
3661         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3662
3663         if (ret == CAMERA_ERROR_NONE)
3664                 *facing_direction = (camera_facing_direction_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FACING_DIRECTION];
3665
3666         CAM_LOG_INFO("ret : 0x%x", ret);
3667
3668         return ret;
3669 }
3670
3671
3672 int camera_set_preview_cb(camera_h camera, camera_preview_cb callback, void *user_data)
3673 {
3674         int ret = CAMERA_ERROR_NONE;
3675         camera_cli_s *pc = (camera_cli_s *)camera;
3676         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_CB;
3677
3678         if (!pc || !pc->cb_info || !callback) {
3679                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
3680                 return CAMERA_ERROR_INVALID_PARAMETER;
3681         }
3682
3683         CAM_LOG_INFO("Enter");
3684
3685         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3686
3687         if (ret == CAMERA_ERROR_NONE) {
3688                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3689
3690                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = callback;
3691                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = user_data;
3692
3693                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3694         }
3695
3696         CAM_LOG_INFO("ret : 0x%x", ret);
3697
3698         return ret;
3699 }
3700
3701
3702 int camera_unset_preview_cb(camera_h camera)
3703 {
3704         int ret = CAMERA_ERROR_NONE;
3705         camera_cli_s *pc = (camera_cli_s *)camera;
3706         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_PREVIEW_CB;
3707
3708         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3709
3710         CAM_LOG_INFO("Enter");
3711
3712         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3713
3714         if (ret == CAMERA_ERROR_NONE) {
3715                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3716
3717                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
3718                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
3719
3720                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3721         }
3722
3723         CAM_LOG_INFO("ret : 0x%x", ret);
3724
3725         return ret;
3726 }
3727
3728
3729 int camera_set_media_packet_preview_cb(camera_h camera, camera_media_packet_preview_cb callback, void *user_data)
3730 {
3731         int ret = CAMERA_ERROR_NONE;
3732         camera_cli_s *pc = (camera_cli_s *)camera;
3733         muse_camera_api_e api = MUSE_CAMERA_API_SET_MEDIA_PACKET_PREVIEW_CB;
3734
3735         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3736
3737         if (camera_is_supported_media_packet_preview_cb(camera) == false) {
3738                 CAM_LOG_ERROR("NOT SUPPORTED");
3739                 return CAMERA_ERROR_NOT_SUPPORTED;
3740         }
3741
3742         if (callback == NULL) {
3743                 CAM_LOG_ERROR("NULL callback");
3744                 return CAMERA_ERROR_INVALID_PARAMETER;
3745         }
3746
3747         CAM_LOG_INFO("Enter");
3748
3749         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3750
3751         if (ret == CAMERA_ERROR_NONE) {
3752                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3753
3754                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = callback;
3755                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = user_data;
3756
3757                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3758         }
3759
3760         CAM_LOG_INFO("ret : 0x%x", ret);
3761
3762         return ret;
3763 }
3764
3765
3766 int camera_unset_media_packet_preview_cb(camera_h camera)
3767 {
3768         int ret = CAMERA_ERROR_NONE;
3769         camera_cli_s *pc = (camera_cli_s *)camera;
3770         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_MEDIA_PACKET_PREVIEW_CB;
3771
3772         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3773
3774         if (camera_is_supported_media_packet_preview_cb(camera) == false) {
3775                 CAM_LOG_ERROR("NOT SUPPORTED");
3776                 return CAMERA_ERROR_NOT_SUPPORTED;
3777         }
3778
3779         CAM_LOG_INFO("Enter");
3780
3781         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3782
3783         if (ret == CAMERA_ERROR_NONE) {
3784                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3785
3786                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
3787                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
3788
3789                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3790         }
3791
3792         CAM_LOG_INFO("ret : 0x%x", ret);
3793
3794         return ret;
3795 }
3796
3797
3798 int camera_set_state_changed_cb(camera_h camera, camera_state_changed_cb callback, void *user_data)
3799 {
3800         int ret = CAMERA_ERROR_NONE;
3801         camera_cli_s *pc = (camera_cli_s *)camera;
3802         muse_camera_api_e api = MUSE_CAMERA_API_SET_STATE_CHANGED_CB;
3803
3804         if (!pc || !pc->cb_info || !callback) {
3805                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
3806                 return CAMERA_ERROR_INVALID_PARAMETER;
3807         }
3808
3809         CAM_LOG_INFO("Enter");
3810
3811         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3812
3813         if (ret == CAMERA_ERROR_NONE) {
3814                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3815
3816                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = callback;
3817                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = user_data;
3818
3819                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3820         }
3821
3822         CAM_LOG_INFO("ret : 0x%x", ret);
3823
3824         return ret;
3825 }
3826
3827
3828 int camera_unset_state_changed_cb(camera_h camera)
3829 {
3830         int ret = CAMERA_ERROR_NONE;
3831         camera_cli_s *pc = (camera_cli_s *)camera;
3832         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_STATE_CHANGED_CB;
3833
3834         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3835
3836         CAM_LOG_INFO("Enter");
3837
3838         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3839
3840         if (ret == CAMERA_ERROR_NONE) {
3841                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3842
3843                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
3844                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
3845
3846                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3847         }
3848
3849         CAM_LOG_INFO("ret : 0x%x", ret);
3850
3851         return ret;
3852 }
3853
3854
3855 int camera_set_interrupted_cb(camera_h camera, camera_interrupted_cb callback, void *user_data)
3856 {
3857         int ret = CAMERA_ERROR_NONE;
3858         camera_cli_s *pc = (camera_cli_s *)camera;
3859         muse_camera_api_e api = MUSE_CAMERA_API_SET_INTERRUPTED_CB;
3860
3861         if (!pc || !pc->cb_info || !callback) {
3862                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
3863                 return CAMERA_ERROR_INVALID_PARAMETER;
3864         }
3865
3866         CAM_LOG_INFO("Enter");
3867
3868         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3869
3870         if (ret == CAMERA_ERROR_NONE) {
3871                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3872
3873                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = callback;
3874                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = user_data;
3875
3876                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3877         }
3878
3879         CAM_LOG_INFO("ret : 0x%x", ret);
3880
3881         return ret;
3882 }
3883
3884
3885 int camera_unset_interrupted_cb(camera_h camera)
3886 {
3887         int ret = CAMERA_ERROR_NONE;
3888         camera_cli_s *pc = (camera_cli_s *)camera;
3889         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_INTERRUPTED_CB;
3890
3891         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3892
3893         CAM_LOG_INFO("Enter");
3894
3895         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3896
3897         if (ret == CAMERA_ERROR_NONE) {
3898                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3899
3900                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
3901                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
3902
3903                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3904         }
3905
3906         CAM_LOG_INFO("ret : 0x%x", ret);
3907
3908         return ret;
3909 }
3910
3911
3912 int camera_set_interrupt_started_cb(camera_h camera, camera_interrupt_started_cb callback, void *user_data)
3913 {
3914         int ret = CAMERA_ERROR_NONE;
3915         camera_cli_s *pc = (camera_cli_s *)camera;
3916         muse_camera_api_e api = MUSE_CAMERA_API_SET_INTERRUPT_STARTED_CB;
3917
3918         if (!pc || !pc->cb_info || !callback) {
3919                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
3920                 return CAMERA_ERROR_INVALID_PARAMETER;
3921         }
3922
3923         CAM_LOG_INFO("Enter");
3924
3925         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3926
3927         if (ret == CAMERA_ERROR_NONE) {
3928                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3929
3930                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = callback;
3931                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = user_data;
3932
3933                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3934         }
3935
3936         CAM_LOG_INFO("ret : 0x%x", ret);
3937
3938         return ret;
3939 }
3940
3941
3942 int camera_unset_interrupt_started_cb(camera_h camera)
3943 {
3944         int ret = CAMERA_ERROR_NONE;
3945         camera_cli_s *pc = (camera_cli_s *)camera;
3946         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_INTERRUPT_STARTED_CB;
3947
3948         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3949
3950         CAM_LOG_INFO("Enter");
3951
3952         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3953
3954         if (ret == CAMERA_ERROR_NONE) {
3955                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3956
3957                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
3958                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
3959
3960                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3961         }
3962
3963         CAM_LOG_INFO("ret : 0x%x", ret);
3964
3965         return ret;
3966 }
3967
3968
3969 int camera_set_focus_changed_cb(camera_h camera, camera_focus_changed_cb callback, void *user_data)
3970 {
3971         int ret = CAMERA_ERROR_NONE;
3972         camera_cli_s *pc = (camera_cli_s *)camera;
3973         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOCUS_CHANGED_CB;
3974
3975         if (!pc || !pc->cb_info || !callback) {
3976                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
3977                 return CAMERA_ERROR_INVALID_PARAMETER;
3978         }
3979
3980         CAM_LOG_INFO("Enter");
3981
3982         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3983
3984         if (ret == CAMERA_ERROR_NONE) {
3985                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
3986
3987                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = callback;
3988                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = user_data;
3989
3990                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
3991         }
3992
3993         CAM_LOG_INFO("ret : 0x%x", ret);
3994
3995         return ret;
3996 }
3997
3998
3999 int camera_unset_focus_changed_cb(camera_h camera)
4000 {
4001         int ret = CAMERA_ERROR_NONE;
4002         camera_cli_s *pc = (camera_cli_s *)camera;
4003         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_FOCUS_CHANGED_CB;
4004
4005         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4006
4007         CAM_LOG_INFO("Enter");
4008
4009         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4010
4011         if (ret == CAMERA_ERROR_NONE) {
4012                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
4013
4014                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
4015                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
4016
4017                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
4018         }
4019
4020         CAM_LOG_INFO("ret : 0x%x", ret);
4021
4022         return ret;
4023 }
4024
4025
4026 int camera_set_error_cb(camera_h camera, camera_error_cb callback, void *user_data)
4027 {
4028         int ret = CAMERA_ERROR_NONE;
4029         camera_cli_s *pc = (camera_cli_s *)camera;
4030         muse_camera_api_e api = MUSE_CAMERA_API_SET_ERROR_CB;
4031
4032         if (!pc || !pc->cb_info || !callback) {
4033                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
4034                 return CAMERA_ERROR_INVALID_PARAMETER;
4035         }
4036
4037         CAM_LOG_INFO("Enter");
4038
4039         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4040
4041         if (ret == CAMERA_ERROR_NONE) {
4042                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4043
4044                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_ERROR] = callback;
4045                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_ERROR] = user_data;
4046
4047                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4048         }
4049
4050         CAM_LOG_INFO("ret : 0x%x", ret);
4051
4052         return ret;
4053 }
4054
4055
4056 int camera_unset_error_cb(camera_h camera)
4057 {
4058         int ret = CAMERA_ERROR_NONE;
4059         camera_cli_s *pc = (camera_cli_s *)camera;
4060         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_ERROR_CB;
4061
4062         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4063
4064         CAM_LOG_INFO("Enter");
4065
4066         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4067
4068         if (ret == CAMERA_ERROR_NONE) {
4069                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4070
4071                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
4072                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
4073
4074                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4075         }
4076
4077         CAM_LOG_INFO("ret : 0x%x", ret);
4078
4079         return ret;
4080 }
4081
4082
4083 int camera_foreach_supported_preview_resolution(camera_h camera, camera_supported_preview_resolution_cb foreach_cb, void *user_data)
4084 {
4085         int ret = CAMERA_ERROR_NONE;
4086         camera_cli_s *pc = (camera_cli_s *)camera;
4087         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_RESOLUTION;
4088
4089         if (!pc || !pc->cb_info || !foreach_cb) {
4090                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
4091                 return CAMERA_ERROR_INVALID_PARAMETER;
4092         }
4093
4094         CAM_LOG_INFO("Enter");
4095
4096         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION] = foreach_cb;
4097         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION] = user_data;
4098
4099         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4100
4101         CAM_LOG_INFO("ret : 0x%x", ret);
4102
4103         return ret;
4104 }
4105
4106
4107 int camera_foreach_supported_capture_resolution(camera_h camera, camera_supported_capture_resolution_cb foreach_cb, void *user_data)
4108 {
4109         int ret = CAMERA_ERROR_NONE;
4110         camera_cli_s *pc = (camera_cli_s *)camera;
4111         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_RESOLUTION;
4112
4113         if (!pc || !pc->cb_info || !foreach_cb) {
4114                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
4115                 return CAMERA_ERROR_INVALID_PARAMETER;
4116         }
4117
4118         CAM_LOG_INFO("Enter");
4119
4120         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION] = foreach_cb;
4121         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION] = user_data;
4122
4123         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4124
4125         CAM_LOG_INFO("ret : 0x%x", ret);
4126
4127         return ret;
4128 }
4129
4130
4131 int camera_foreach_supported_capture_format(camera_h camera, camera_supported_capture_format_cb foreach_cb, void *user_data)
4132 {
4133         int ret = CAMERA_ERROR_NONE;
4134         camera_cli_s *pc = (camera_cli_s *)camera;
4135         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_FORMAT;
4136
4137         if (!pc || !pc->cb_info || !foreach_cb) {
4138                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
4139                 return CAMERA_ERROR_INVALID_PARAMETER;
4140         }
4141
4142         CAM_LOG_INFO("Enter");
4143
4144         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT] = foreach_cb;
4145         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT] = user_data;
4146
4147         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4148
4149         CAM_LOG_INFO("ret : 0x%x", ret);
4150
4151         return ret;
4152 }
4153
4154
4155 int camera_foreach_supported_preview_format(camera_h camera, camera_supported_preview_format_cb foreach_cb, void *user_data)
4156 {
4157         int ret = CAMERA_ERROR_NONE;
4158         camera_cli_s *pc = (camera_cli_s *)camera;
4159         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_FORMAT;
4160
4161         if (!pc || !pc->cb_info || !foreach_cb) {
4162                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
4163                 return CAMERA_ERROR_INVALID_PARAMETER;
4164         }
4165
4166         CAM_LOG_INFO("Enter");
4167
4168         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT] = foreach_cb;
4169         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT] = user_data;
4170
4171         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4172
4173         CAM_LOG_INFO("ret : 0x%x", ret);
4174
4175         return ret;
4176 }
4177
4178
4179 int camera_get_recommended_preview_resolution(camera_h camera, int *width, int *height)
4180 {
4181         int ret = CAMERA_ERROR_NONE;
4182         camera_cli_s *pc = (camera_cli_s *)camera;
4183         muse_camera_api_e api = MUSE_CAMERA_API_GET_RECOMMENDED_PREVIEW_RESOLUTION;
4184
4185         if (!pc || !pc->cb_info || !width || !height) {
4186                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, width, height);
4187                 return CAMERA_ERROR_INVALID_PARAMETER;
4188         }
4189
4190         CAM_LOG_INFO("Enter");
4191         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4192
4193         if (ret == CAMERA_ERROR_NONE) {
4194                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_RECOMMENDED_PREVIEW_RESOLUTION] >> 16;
4195                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_RECOMMENDED_PREVIEW_RESOLUTION];
4196         }
4197
4198         CAM_LOG_INFO("ret : 0x%x", ret);
4199
4200         return ret;
4201 }
4202
4203
4204 int camera_attr_get_lens_orientation(camera_h camera, int *angle)
4205 {
4206         int ret = CAMERA_ERROR_NONE;
4207         camera_cli_s *pc = (camera_cli_s *)camera;
4208         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_LENS_ORIENTATION;
4209
4210         if (!pc || !pc->cb_info || !angle) {
4211                 CAM_LOG_ERROR("NULL pointer %p %p", pc, angle);
4212                 return CAMERA_ERROR_INVALID_PARAMETER;
4213         }
4214
4215         CAM_LOG_INFO("Enter");
4216
4217         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4218
4219         if (ret == CAMERA_ERROR_NONE)
4220                 *angle = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_LENS_ORIENTATION];
4221
4222         CAM_LOG_INFO("ret : 0x%x", ret);
4223
4224         return ret;
4225 }
4226
4227
4228 int camera_attr_set_theater_mode(camera_h camera, camera_attr_theater_mode_e mode)
4229 {
4230         return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_THEATER_MODE, (int)mode);
4231 }
4232
4233
4234 int camera_attr_get_theater_mode(camera_h camera, camera_attr_theater_mode_e *mode)
4235 {
4236         int ret = CAMERA_ERROR_NONE;
4237         camera_cli_s *pc = (camera_cli_s *)camera;
4238         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_THEATER_MODE;
4239
4240         if (!pc || !pc->cb_info || !mode) {
4241                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
4242                 return CAMERA_ERROR_INVALID_PARAMETER;
4243         }
4244
4245         CAM_LOG_INFO("Enter");
4246
4247         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4248
4249         if (ret == CAMERA_ERROR_NONE)
4250                 *mode = (camera_attr_theater_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_THEATER_MODE];
4251
4252         CAM_LOG_INFO("ret : 0x%x", ret);
4253
4254         return ret;
4255 }
4256
4257
4258 int camera_attr_foreach_supported_theater_mode(camera_h camera, camera_attr_supported_theater_mode_cb foreach_cb, void *user_data)
4259 {
4260         int ret = CAMERA_ERROR_NONE;
4261         camera_cli_s *pc = (camera_cli_s *)camera;
4262         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_THEATER_MODE;
4263
4264         if (!pc || !pc->cb_info || !foreach_cb) {
4265                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
4266                 return CAMERA_ERROR_INVALID_PARAMETER;
4267         }
4268
4269         CAM_LOG_INFO("Enter");
4270
4271         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE] = foreach_cb;
4272         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE] = user_data;
4273
4274         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4275
4276         CAM_LOG_INFO("Finish, return :%x", ret);
4277
4278         return ret;
4279 }
4280
4281
4282 int camera_attr_set_preview_fps(camera_h camera, camera_attr_fps_e fps)
4283 {
4284         int ret = CAMERA_ERROR_NONE;
4285         camera_cli_s *pc = (camera_cli_s *)camera;
4286         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PREVIEW_FPS;
4287         camera_msg_param param;
4288         int set_fps = (int)fps;
4289
4290         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4291
4292         CAM_LOG_INFO("Enter");
4293
4294         CAMERA_MSG_PARAM_SET(param, INT, set_fps);
4295
4296         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4297
4298         CAM_LOG_INFO("ret : 0x%x", ret);
4299
4300         return ret;
4301 }
4302
4303
4304 int camera_attr_set_image_quality(camera_h camera, int quality)
4305 {
4306         int ret = CAMERA_ERROR_NONE;
4307         camera_cli_s *pc = (camera_cli_s *)camera;
4308         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_IMAGE_QUALITY;
4309         camera_msg_param param;
4310
4311         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4312
4313         CAM_LOG_INFO("Enter");
4314
4315         CAMERA_MSG_PARAM_SET(param, INT, quality);
4316
4317         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4318
4319         CAM_LOG_INFO("ret : 0x%x", ret);
4320
4321         return ret;
4322 }
4323
4324
4325 int camera_attr_get_preview_fps(camera_h camera, camera_attr_fps_e *fps)
4326 {
4327         int ret = CAMERA_ERROR_NONE;
4328         camera_cli_s *pc = (camera_cli_s *)camera;
4329         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PREVIEW_FPS;
4330
4331         if (!pc || !pc->cb_info || !fps) {
4332                 CAM_LOG_ERROR("NULL pointer %p %p", pc, fps);
4333                 return CAMERA_ERROR_INVALID_PARAMETER;
4334         }
4335
4336         CAM_LOG_INFO("Enter");
4337
4338         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4339
4340         if (ret == CAMERA_ERROR_NONE)
4341                 *fps = (camera_attr_fps_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_FPS];
4342
4343         CAM_LOG_INFO("ret : 0x%x", ret);
4344
4345         return ret;
4346 }
4347
4348
4349 int camera_attr_get_image_quality(camera_h camera, int *quality)
4350 {
4351         int ret = CAMERA_ERROR_NONE;
4352         camera_cli_s *pc = (camera_cli_s *)camera;
4353         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_IMAGE_QUALITY;
4354
4355         if (!pc || !pc->cb_info || !quality) {
4356                 CAM_LOG_ERROR("NULL pointer %p %p", pc, quality);
4357                 return CAMERA_ERROR_INVALID_PARAMETER;
4358         }
4359
4360         CAM_LOG_INFO("Enter");
4361
4362         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4363
4364         if (ret == CAMERA_ERROR_NONE)
4365                 *quality = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_IMAGE_QUALITY];
4366
4367         CAM_LOG_INFO("ret : 0x%x", ret);
4368
4369         return ret;
4370 }
4371
4372
4373 int camera_attr_get_encoded_preview_bitrate(camera_h camera, int *bitrate)
4374 {
4375         int ret = CAMERA_ERROR_NONE;
4376         camera_cli_s *pc = (camera_cli_s *)camera;
4377         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_BITRATE;
4378
4379         if (!pc || !pc->cb_info || !bitrate) {
4380                 CAM_LOG_ERROR("NULL pointer %p %p", pc, bitrate);
4381                 return CAMERA_ERROR_INVALID_PARAMETER;
4382         }
4383
4384         CAM_LOG_INFO("Enter");
4385
4386         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4387
4388         if (ret == CAMERA_ERROR_NONE)
4389                 *bitrate = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENCODED_PREVIEW_BITRATE];
4390
4391         CAM_LOG_INFO("ret : 0x%x", ret);
4392
4393         return ret;
4394 }
4395
4396
4397 int camera_attr_set_encoded_preview_bitrate(camera_h camera, int bitrate)
4398 {
4399         int ret = CAMERA_ERROR_NONE;
4400         camera_cli_s *pc = (camera_cli_s *)camera;
4401         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_BITRATE;
4402         camera_msg_param param;
4403         int set_bitrate = bitrate;
4404
4405         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4406
4407         CAM_LOG_INFO("Enter");
4408
4409         CAMERA_MSG_PARAM_SET(param, INT, set_bitrate);
4410
4411         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4412
4413         CAM_LOG_INFO("ret : 0x%x", ret);
4414
4415         return ret;
4416 }
4417
4418
4419 int camera_attr_get_encoded_preview_gop_interval(camera_h camera, int *interval)
4420 {
4421         int ret = CAMERA_ERROR_NONE;
4422         camera_cli_s *pc = (camera_cli_s *)camera;
4423         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_GOP_INTERVAL;
4424
4425         if (!pc || !pc->cb_info || !interval) {
4426                 CAM_LOG_ERROR("NULL pointer %p %p", pc, interval);
4427                 return CAMERA_ERROR_INVALID_PARAMETER;
4428         }
4429
4430         CAM_LOG_INFO("Enter");
4431
4432         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4433
4434         if (ret == CAMERA_ERROR_NONE)
4435                 *interval = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENCODED_PREVIEW_GOP_INTERVAL];
4436
4437         CAM_LOG_INFO("ret : 0x%x", ret);
4438
4439         return ret;
4440 }
4441
4442
4443 int camera_attr_set_encoded_preview_gop_interval(camera_h camera, int interval)
4444 {
4445         int ret = CAMERA_ERROR_NONE;
4446         camera_cli_s *pc = (camera_cli_s *)camera;
4447         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_GOP_INTERVAL;
4448         camera_msg_param param;
4449         int set_gop_interval = interval;
4450
4451         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4452
4453         CAM_LOG_INFO("Enter");
4454
4455         CAMERA_MSG_PARAM_SET(param, INT, set_gop_interval);
4456
4457         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4458
4459         CAM_LOG_INFO("ret : 0x%x", ret);
4460
4461         return ret;
4462 }
4463
4464
4465 int camera_attr_set_zoom(camera_h camera, int zoom)
4466 {
4467         int ret = CAMERA_ERROR_NONE;
4468         camera_cli_s *pc = (camera_cli_s *)camera;
4469         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ZOOM;
4470         camera_msg_param param;
4471
4472         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4473
4474         CAM_LOG_INFO("Enter, remote_handle : %td", pc->remote_handle);
4475
4476         CAMERA_MSG_PARAM_SET(param, INT, zoom);
4477
4478         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4479
4480         CAM_LOG_INFO("ret : 0x%x", ret);
4481
4482         return ret;
4483 }
4484
4485
4486 int camera_attr_set_af_mode(camera_h camera, camera_attr_af_mode_e mode)
4487 {
4488         return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_AF_MODE, (int)mode);
4489 }
4490
4491
4492 int camera_attr_set_af_area(camera_h camera, int x, int y)
4493 {
4494         int ret = CAMERA_ERROR_NONE;
4495         camera_cli_s *pc = (camera_cli_s *)camera;
4496         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_AF_AREA;
4497         camera_msg_param param;
4498         int value = 0;
4499
4500         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4501
4502         CAM_LOG_INFO("Enter - %d,%d", x, y);
4503
4504         value = (x << 16) | y;
4505         CAMERA_MSG_PARAM_SET(param, INT, value);
4506
4507         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4508
4509         CAM_LOG_INFO("ret : 0x%x", ret);
4510
4511         return ret;
4512 }
4513
4514
4515 int camera_attr_clear_af_area(camera_h camera)
4516 {
4517         int ret = CAMERA_ERROR_NONE;
4518         camera_cli_s *pc = (camera_cli_s *)camera;
4519         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_CLEAR_AF_AREA;
4520
4521         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4522
4523         CAM_LOG_INFO("Enter");
4524
4525         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4526
4527         CAM_LOG_INFO("ret : 0x%x", ret);
4528
4529         return ret;
4530 }
4531
4532
4533 int camera_attr_set_exposure_mode(camera_h camera, camera_attr_exposure_mode_e mode)
4534 {
4535         return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_EXPOSURE_MODE, (int)mode);
4536 }
4537
4538
4539 int camera_attr_set_exposure(camera_h camera, int value)
4540 {
4541         int ret = CAMERA_ERROR_NONE;
4542         camera_cli_s *pc = (camera_cli_s *)camera;
4543         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXPOSURE;
4544         camera_msg_param param;
4545
4546         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4547
4548         CAM_LOG_INFO("Enter");
4549
4550         CAMERA_MSG_PARAM_SET(param, INT, value);
4551
4552         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4553
4554         CAM_LOG_INFO("ret : 0x%x", ret);
4555
4556         return ret;
4557 }
4558
4559
4560 int camera_attr_set_iso(camera_h camera, camera_attr_iso_e iso)
4561 {
4562         int ret = CAMERA_ERROR_NONE;
4563         camera_cli_s *pc = (camera_cli_s *)camera;
4564         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ISO;
4565         camera_msg_param param;
4566         int set_iso = (int)iso;
4567
4568         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4569
4570         CAM_LOG_INFO("Enter");
4571
4572         CAMERA_MSG_PARAM_SET(param, INT, set_iso);
4573
4574         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4575
4576         CAM_LOG_INFO("ret : 0x%x", ret);
4577
4578         return ret;
4579 }
4580
4581
4582 int camera_attr_set_brightness(camera_h camera, int level)
4583 {
4584         int ret = CAMERA_ERROR_NONE;
4585         camera_cli_s *pc = (camera_cli_s *)camera;
4586         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_BRIGHTNESS;
4587         camera_msg_param param;
4588
4589         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4590
4591         CAM_LOG_INFO("Enter");
4592
4593         CAMERA_MSG_PARAM_SET(param, INT, level);
4594
4595         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4596
4597         CAM_LOG_INFO("ret : 0x%x", ret);
4598
4599         return ret;
4600 }
4601
4602
4603 int camera_attr_set_contrast(camera_h camera, int level)
4604 {
4605         int ret = CAMERA_ERROR_NONE;
4606         camera_cli_s *pc = (camera_cli_s *)camera;
4607         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_CONTRAST;
4608         camera_msg_param param;
4609
4610         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4611
4612         CAM_LOG_INFO("Enter");
4613
4614         CAMERA_MSG_PARAM_SET(param, INT, level);
4615
4616         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4617
4618         CAM_LOG_INFO("ret : 0x%x", ret);
4619
4620         return ret;
4621 }
4622
4623
4624 int camera_attr_set_hue(camera_h camera, int level)
4625 {
4626         int ret = CAMERA_ERROR_NONE;
4627         camera_cli_s *pc = (camera_cli_s *)camera;
4628         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HUE;
4629         camera_msg_param param;
4630
4631         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4632
4633         CAM_LOG_INFO("Enter");
4634
4635         CAMERA_MSG_PARAM_SET(param, INT, level);
4636
4637         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4638
4639         CAM_LOG_INFO("ret : 0x%x", ret);
4640
4641         return ret;
4642 }
4643
4644
4645 int camera_attr_set_whitebalance(camera_h camera, camera_attr_whitebalance_e wb)
4646 {
4647         int ret = CAMERA_ERROR_NONE;
4648         camera_cli_s *pc = (camera_cli_s *)camera;
4649         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_WHITEBALANCE;
4650         camera_msg_param param;
4651         int set_whitebalance = (int)wb;
4652
4653         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4654
4655         CAM_LOG_INFO("Enter");
4656
4657         CAMERA_MSG_PARAM_SET(param, INT, set_whitebalance);
4658
4659         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4660
4661         CAM_LOG_INFO("ret : 0x%x", ret);
4662
4663         return ret;
4664 }
4665
4666
4667 int camera_attr_set_effect(camera_h camera, camera_attr_effect_mode_e effect)
4668 {
4669         int ret = CAMERA_ERROR_NONE;
4670         camera_cli_s *pc = (camera_cli_s *)camera;
4671         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EFFECT;
4672         camera_msg_param param;
4673         int set_effect = (int)effect;
4674
4675         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4676
4677         CAM_LOG_INFO("Enter");
4678
4679         CAMERA_MSG_PARAM_SET(param, INT, set_effect);
4680
4681         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4682
4683         CAM_LOG_INFO("ret : 0x%x", ret);
4684
4685         return ret;
4686 }
4687
4688
4689 int camera_attr_set_scene_mode(camera_h camera, camera_attr_scene_mode_e mode)
4690 {
4691         return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_SCENE_MODE, (int)mode);
4692 }
4693
4694
4695 int camera_attr_enable_tag(camera_h camera, bool enable)
4696 {
4697         return __set_enable(camera, MUSE_CAMERA_API_ATTR_ENABLE_TAG, (int)enable);
4698 }
4699
4700
4701 int camera_attr_set_tag_image_description(camera_h camera, const char *description)
4702 {
4703         int ret = CAMERA_ERROR_NONE;
4704         camera_cli_s *pc = (camera_cli_s *)camera;
4705         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_IMAGE_DESCRIPTION;
4706         camera_msg_param param;
4707
4708         if (!pc || !pc->cb_info || !description) {
4709                 CAM_LOG_ERROR("NULL pointer %p %p", pc, description);
4710                 return CAMERA_ERROR_INVALID_PARAMETER;
4711         }
4712
4713         CAM_LOG_INFO("Enter");
4714
4715         CAMERA_MSG_PARAM_SET(param, STRING, description);
4716
4717         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4718
4719         CAM_LOG_INFO("ret : 0x%x", ret);
4720
4721         return ret;
4722 }
4723
4724
4725 int camera_attr_set_tag_orientation(camera_h camera, camera_attr_tag_orientation_e orientation)
4726 {
4727         int ret = CAMERA_ERROR_NONE;
4728         camera_cli_s *pc = (camera_cli_s *)camera;
4729         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_ORIENTATION;
4730         camera_msg_param param;
4731         int set_orientation = (int)orientation;
4732
4733         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4734
4735         CAM_LOG_INFO("Enter");
4736
4737         CAMERA_MSG_PARAM_SET(param, INT, set_orientation);
4738
4739         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4740
4741         CAM_LOG_INFO("ret : 0x%x", ret);
4742
4743         return ret;
4744 }
4745
4746
4747 int camera_attr_set_tag_software(camera_h camera, const char *software)
4748 {
4749         int ret = CAMERA_ERROR_NONE;
4750         camera_cli_s *pc = (camera_cli_s *)camera;
4751         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_SOFTWARE;
4752         camera_msg_param param;
4753
4754         if (!pc || !pc->cb_info || !software) {
4755                 CAM_LOG_ERROR("NULL pointer %p %p", pc, software);
4756                 return CAMERA_ERROR_INVALID_PARAMETER;
4757         }
4758
4759         CAM_LOG_INFO("Enter, remote_handle : %td", pc->remote_handle);
4760
4761         CAMERA_MSG_PARAM_SET(param, STRING, software);
4762
4763         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4764
4765         CAM_LOG_INFO("ret : 0x%x", ret);
4766
4767         return ret;
4768 }
4769
4770
4771 int camera_attr_set_geotag(camera_h camera, double latitude, double longitude, double altitude)
4772 {
4773         int ret = CAMERA_ERROR_NONE;
4774         camera_cli_s *pc = (camera_cli_s *)camera;
4775         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_GEOTAG;
4776         double set_geotag[3] = {latitude, longitude, altitude};
4777         char *msg = NULL;
4778         int length = 0;
4779
4780         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4781
4782         CAM_LOG_INFO("Enter");
4783
4784         length = sizeof(set_geotag) / sizeof(int) + \
4785                 (sizeof(set_geotag) % sizeof(int) ? 1 : 0);
4786
4787         msg = muse_core_msg_new(api,
4788                 MUSE_TYPE_ARRAY, "set_geotag", length, (int *)set_geotag,
4789                 NULL);
4790
4791         _camera_send_message_get_return(pc->cb_info, api, msg, CAMERA_CB_TIMEOUT, &ret);
4792
4793         return ret;
4794 }
4795
4796
4797 int camera_attr_remove_geotag(camera_h camera)
4798 {
4799         int ret = CAMERA_ERROR_NONE;
4800         camera_cli_s *pc = (camera_cli_s *)camera;
4801         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_REMOVE_GEOTAG;
4802
4803         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4804
4805         CAM_LOG_INFO("Enter");
4806
4807         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4808
4809         CAM_LOG_INFO("ret : 0x%x", ret);
4810
4811         return ret;
4812 }
4813
4814
4815 int camera_attr_set_flash_mode(camera_h camera, camera_attr_flash_mode_e mode)
4816 {
4817         return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_FLASH_MODE, (int)mode);
4818 }
4819
4820
4821 int camera_attr_get_zoom(camera_h camera, int *zoom)
4822 {
4823         int ret = CAMERA_ERROR_NONE;
4824         camera_cli_s *pc = (camera_cli_s *)camera;
4825         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ZOOM;
4826
4827         if (!pc || !pc->cb_info || !zoom) {
4828                 CAM_LOG_ERROR("NULL pointer %p %p", pc, zoom);
4829                 return CAMERA_ERROR_INVALID_PARAMETER;
4830         }
4831
4832         CAM_LOG_INFO("Enter");
4833
4834         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4835
4836         if (ret == CAMERA_ERROR_NONE)
4837                 *zoom = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ZOOM];
4838
4839         CAM_LOG_INFO("ret : 0x%x", ret);
4840
4841         return ret;
4842 }
4843
4844
4845 int camera_attr_get_zoom_range(camera_h camera, int *min, int *max)
4846 {
4847         int ret = CAMERA_ERROR_NONE;
4848         camera_cli_s *pc = (camera_cli_s *)camera;
4849         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ZOOM_RANGE;
4850
4851         if (!pc || !pc->cb_info || !min || !max) {
4852                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
4853                 return CAMERA_ERROR_INVALID_PARAMETER;
4854         }
4855
4856         CAM_LOG_INFO("Enter");
4857
4858         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4859
4860         if (ret == CAMERA_ERROR_NONE) {
4861                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE][0];
4862                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE][1];
4863         }
4864
4865         CAM_LOG_INFO("ret : 0x%x", ret);
4866
4867         return ret;
4868 }
4869
4870
4871 int camera_attr_get_af_mode(camera_h camera, camera_attr_af_mode_e *mode)
4872 {
4873         int ret = CAMERA_ERROR_NONE;
4874         camera_cli_s *pc = (camera_cli_s *)camera;
4875         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_AF_MODE;
4876
4877         if (!pc || !pc->cb_info || !mode) {
4878                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
4879                 return CAMERA_ERROR_INVALID_PARAMETER;
4880         }
4881
4882         CAM_LOG_INFO("Enter");
4883
4884         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4885
4886         if (ret == CAMERA_ERROR_NONE)
4887                 *mode = (camera_attr_af_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_AF_MODE];
4888
4889         CAM_LOG_INFO("ret : 0x%x", ret);
4890
4891         return ret;
4892 }
4893
4894
4895 int camera_attr_get_exposure_mode(camera_h camera, camera_attr_exposure_mode_e *mode)
4896 {
4897         int ret = CAMERA_ERROR_NONE;
4898         camera_cli_s *pc = (camera_cli_s *)camera;
4899         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE_MODE;
4900
4901         if (!pc || !pc->cb_info || !mode) {
4902                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
4903                 return CAMERA_ERROR_INVALID_PARAMETER;
4904         }
4905
4906         CAM_LOG_INFO("Enter");
4907
4908         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4909
4910         if (ret == CAMERA_ERROR_NONE)
4911                 *mode = (camera_attr_exposure_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXPOSURE_MODE];
4912
4913         CAM_LOG_INFO("ret : 0x%x", ret);
4914
4915         return ret;
4916 }
4917
4918
4919 int camera_attr_get_exposure(camera_h camera, int *value)
4920 {
4921         int ret = CAMERA_ERROR_NONE;
4922         camera_cli_s *pc = (camera_cli_s *)camera;
4923         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE;
4924
4925         if (!pc || !pc->cb_info || !value) {
4926                 CAM_LOG_ERROR("NULL pointer %p %p", pc, value);
4927                 return CAMERA_ERROR_INVALID_PARAMETER;
4928         }
4929
4930         CAM_LOG_INFO("Enter");
4931
4932         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4933
4934         if (ret == CAMERA_ERROR_NONE)
4935                 *value = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXPOSURE];
4936
4937         CAM_LOG_INFO("ret : 0x%x", ret);
4938
4939         return ret;
4940 }
4941
4942
4943 int camera_attr_get_exposure_range(camera_h camera, int *min, int *max)
4944 {
4945         int ret = CAMERA_ERROR_NONE;
4946         camera_cli_s *pc = (camera_cli_s *)camera;
4947         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE_RANGE;
4948
4949         if (!pc || !pc->cb_info || !min || !max) {
4950                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
4951                 return CAMERA_ERROR_INVALID_PARAMETER;
4952         }
4953
4954         CAM_LOG_INFO("Enter");
4955
4956         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4957
4958         if (ret == CAMERA_ERROR_NONE) {
4959                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE][0];
4960                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE][1];
4961         }
4962
4963         CAM_LOG_INFO("ret : 0x%x", ret);
4964
4965         return ret;
4966 }
4967
4968
4969 int camera_attr_get_iso(camera_h camera, camera_attr_iso_e *iso)
4970 {
4971         int ret = CAMERA_ERROR_NONE;
4972         camera_cli_s *pc = (camera_cli_s *)camera;
4973         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ISO;
4974
4975         if (!pc || !pc->cb_info || !iso) {
4976                 CAM_LOG_ERROR("NULL pointer %p %p", pc, iso);
4977                 return CAMERA_ERROR_INVALID_PARAMETER;
4978         }
4979
4980         CAM_LOG_INFO("Enter");
4981
4982         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4983
4984         if (ret == CAMERA_ERROR_NONE)
4985                 *iso = (camera_attr_iso_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ISO];
4986
4987         CAM_LOG_INFO("ret : 0x%x", ret);
4988
4989         return ret;
4990 }
4991
4992
4993 int camera_attr_get_brightness(camera_h camera, int *level)
4994 {
4995         int ret = CAMERA_ERROR_NONE;
4996         camera_cli_s *pc = (camera_cli_s *)camera;
4997         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS;
4998
4999         if (!pc || !pc->cb_info || !level) {
5000                 CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
5001                 return CAMERA_ERROR_INVALID_PARAMETER;
5002         }
5003
5004         CAM_LOG_INFO("Enter");
5005
5006         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5007
5008         if (ret == CAMERA_ERROR_NONE)
5009                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_BRIGHTNESS];
5010
5011         CAM_LOG_INFO("ret : 0x%x", ret);
5012
5013         return ret;
5014 }
5015
5016
5017 int camera_attr_get_brightness_range(camera_h camera, int *min, int *max)
5018 {
5019         int ret = CAMERA_ERROR_NONE;
5020         camera_cli_s *pc = (camera_cli_s *)camera;
5021         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS_RANGE;
5022
5023         if (!pc || !pc->cb_info || !min || !max) {
5024                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
5025                 return CAMERA_ERROR_INVALID_PARAMETER;
5026         }
5027
5028         CAM_LOG_INFO("Enter");
5029
5030         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5031
5032         if (ret == CAMERA_ERROR_NONE) {
5033                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE][0];
5034                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE][1];
5035         }
5036
5037         CAM_LOG_INFO("ret : 0x%x", ret);
5038
5039         return ret;
5040 }
5041
5042
5043 int camera_attr_get_contrast(camera_h camera, int *level)
5044 {
5045         int ret = CAMERA_ERROR_NONE;
5046         camera_cli_s *pc = (camera_cli_s *)camera;
5047         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST;
5048
5049         if (!pc || !pc->cb_info || !level) {
5050                 CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
5051                 return CAMERA_ERROR_INVALID_PARAMETER;
5052         }
5053
5054         CAM_LOG_INFO("Enter");
5055
5056         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5057
5058         if (ret == CAMERA_ERROR_NONE)
5059                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CONTRAST];
5060
5061         CAM_LOG_INFO("ret : 0x%x", ret);
5062
5063         return ret;
5064 }
5065
5066
5067 int camera_attr_get_contrast_range(camera_h camera, int *min, int *max)
5068 {
5069         int ret = CAMERA_ERROR_NONE;
5070         camera_cli_s *pc = (camera_cli_s *)camera;
5071         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST_RANGE;
5072
5073         if (!pc || !pc->cb_info || !min || !max) {
5074                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
5075                 return CAMERA_ERROR_INVALID_PARAMETER;
5076         }
5077
5078         CAM_LOG_INFO("Enter");
5079
5080         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5081
5082         if (ret == CAMERA_ERROR_NONE) {
5083                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE][0];
5084                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE][1];
5085                 CAM_LOG_INFO("min %d, max %d", *min, *max);
5086         }
5087
5088         CAM_LOG_INFO("ret : 0x%x", ret);
5089
5090         return ret;
5091 }
5092
5093
5094 int camera_attr_get_hue(camera_h camera, int *level)
5095 {
5096         int ret = CAMERA_ERROR_NONE;
5097         camera_cli_s *pc = (camera_cli_s *)camera;
5098         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HUE;
5099
5100         if (!pc || !pc->cb_info || !level) {
5101                 CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
5102                 return CAMERA_ERROR_INVALID_PARAMETER;
5103         }
5104
5105         CAM_LOG_INFO("Enter");
5106
5107         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5108
5109         if (ret == CAMERA_ERROR_NONE)
5110                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_HUE];
5111
5112         CAM_LOG_INFO("ret : 0x%x", ret);
5113
5114         return ret;
5115 }
5116
5117
5118 int camera_attr_get_hue_range(camera_h camera, int *min, int *max)
5119 {
5120         int ret = CAMERA_ERROR_NONE;
5121         camera_cli_s *pc = (camera_cli_s *)camera;
5122         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HUE_RANGE;
5123
5124         if (!pc || !pc->cb_info || !min || !max) {
5125                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
5126                 return CAMERA_ERROR_INVALID_PARAMETER;
5127         }
5128
5129         CAM_LOG_INFO("Enter");
5130
5131         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5132
5133         if (ret == CAMERA_ERROR_NONE) {
5134                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_HUE_RANGE][0];
5135                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_HUE_RANGE][1];
5136                 CAM_LOG_INFO("min %d, max %d", *min, *max);
5137         }
5138
5139         CAM_LOG_INFO("ret : 0x%x", ret);
5140
5141         return ret;
5142 }
5143
5144
5145 int camera_attr_get_whitebalance(camera_h camera, camera_attr_whitebalance_e *wb)
5146 {
5147         int ret = CAMERA_ERROR_NONE;
5148         camera_cli_s *pc = (camera_cli_s *)camera;
5149         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_WHITEBALANCE;
5150
5151         if (!pc || !pc->cb_info || !wb) {
5152                 CAM_LOG_ERROR("NULL pointer %p %p", pc, wb);
5153                 return CAMERA_ERROR_INVALID_PARAMETER;
5154         }
5155
5156         CAM_LOG_INFO("Enter");
5157
5158         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5159
5160         if (ret == CAMERA_ERROR_NONE)
5161                 *wb = (camera_attr_whitebalance_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_WHITE_BALANCE];
5162
5163         CAM_LOG_INFO("ret : 0x%x", ret);
5164
5165         return ret;
5166 }
5167
5168
5169 int camera_attr_get_effect(camera_h camera, camera_attr_effect_mode_e *effect)
5170 {
5171         int ret = CAMERA_ERROR_NONE;
5172         camera_cli_s *pc = (camera_cli_s *)camera;
5173         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EFFECT;
5174
5175         if (!pc || !pc->cb_info || !effect) {
5176                 CAM_LOG_ERROR("NULL pointer %p %p", pc, effect);
5177                 return CAMERA_ERROR_INVALID_PARAMETER;
5178         }
5179
5180         CAM_LOG_INFO("Enter");
5181
5182         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5183
5184         if (ret == CAMERA_ERROR_NONE)
5185                 *effect = (camera_attr_effect_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EFFECT];
5186
5187         CAM_LOG_INFO("ret : 0x%x", ret);
5188
5189         return ret;
5190 }
5191
5192
5193 int camera_attr_get_scene_mode(camera_h camera, camera_attr_scene_mode_e *mode)
5194 {
5195         int ret = CAMERA_ERROR_NONE;
5196         camera_cli_s *pc = (camera_cli_s *)camera;
5197         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_SCENE_MODE;
5198
5199         if (!pc || !pc->cb_info || !mode) {
5200                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
5201                 return CAMERA_ERROR_INVALID_PARAMETER;
5202         }
5203
5204         CAM_LOG_INFO("Enter");
5205
5206         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5207
5208         if (ret == CAMERA_ERROR_NONE)
5209                 *mode = (camera_attr_scene_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_SCENE_MODE];
5210
5211         CAM_LOG_INFO("ret : 0x%x", ret);
5212
5213         return ret;
5214 }
5215
5216
5217 int camera_attr_is_enabled_tag(camera_h camera, bool *enable)
5218 {
5219         int ret = CAMERA_ERROR_NONE;
5220         camera_cli_s *pc = (camera_cli_s *)camera;
5221         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_TAG;
5222
5223         if (!pc || !pc->cb_info || !enable) {
5224                 CAM_LOG_ERROR("NULL pointer %p %p", pc, enable);
5225                 return CAMERA_ERROR_INVALID_PARAMETER;
5226         }
5227
5228         CAM_LOG_INFO("Enter");
5229
5230         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5231
5232         if (ret == CAMERA_ERROR_NONE)
5233                 *enable = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_TAG];
5234
5235         CAM_LOG_INFO("ret : 0x%x", ret);
5236
5237         return ret;
5238 }
5239
5240
5241 int camera_attr_get_tag_image_description(camera_h camera, char **description)
5242 {
5243         int ret = CAMERA_ERROR_NONE;
5244         camera_cli_s *pc = (camera_cli_s *)camera;
5245         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_IMAGE_DESCRIPTION;
5246
5247         if (!pc || !pc->cb_info || !description) {
5248                 CAM_LOG_ERROR("NULL pointer %p %p", pc, description);
5249                 return CAMERA_ERROR_INVALID_PARAMETER;
5250         }
5251
5252         CAM_LOG_INFO("Enter");
5253
5254         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5255
5256         if (ret == CAMERA_ERROR_NONE)
5257                 *description = strdup(pc->cb_info->get_string[MUSE_CAMERA_GET_STRING_TAG_IMAGE_DESCRIPTION]);
5258
5259         CAM_LOG_INFO("ret : 0x%x", ret);
5260
5261         return ret;
5262 }
5263
5264
5265 int camera_attr_get_tag_orientation(camera_h camera, camera_attr_tag_orientation_e *orientation)
5266 {
5267         int ret = CAMERA_ERROR_NONE;
5268         camera_cli_s *pc = (camera_cli_s *)camera;
5269         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_ORIENTATION;
5270
5271         if (!pc || !pc->cb_info || !orientation) {
5272                 CAM_LOG_ERROR("NULL pointer %p %p", pc, orientation);
5273                 return CAMERA_ERROR_INVALID_PARAMETER;
5274         }
5275
5276         CAM_LOG_INFO("Enter");
5277
5278         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5279
5280         if (ret == CAMERA_ERROR_NONE)
5281                 *orientation = (camera_attr_tag_orientation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_TAG_ORIENTATION];
5282
5283         CAM_LOG_INFO("ret : 0x%x", ret);
5284
5285         return ret;
5286 }
5287
5288
5289 int camera_attr_get_tag_software(camera_h camera, char **software)
5290 {
5291         int ret = CAMERA_ERROR_NONE;
5292         camera_cli_s *pc = (camera_cli_s *)camera;
5293         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_SOFTWARE;
5294
5295         if (!pc || !pc->cb_info || !software) {
5296                 CAM_LOG_ERROR("NULL pointer %p %p", pc, software);
5297                 return CAMERA_ERROR_INVALID_PARAMETER;
5298         }
5299
5300         CAM_LOG_INFO("Enter");
5301
5302         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5303
5304         if (ret == CAMERA_ERROR_NONE)
5305                 *software = strdup(pc->cb_info->get_string[MUSE_CAMERA_GET_STRING_TAG_SOFTWARE]);
5306
5307         CAM_LOG_INFO("ret : 0x%x", ret);
5308
5309         return ret;
5310 }
5311
5312
5313 int camera_attr_get_geotag(camera_h camera, double *latitude, double *longitude, double *altitude)
5314 {
5315         int ret = CAMERA_ERROR_NONE;
5316         camera_cli_s *pc = (camera_cli_s *)camera;
5317         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_GEOTAG;
5318
5319         if (!pc || !pc->cb_info || !latitude || !longitude || !altitude) {
5320                 CAM_LOG_ERROR("NULL pointer %p %p %p %p", pc, latitude, longitude, altitude);
5321                 return CAMERA_ERROR_INVALID_PARAMETER;
5322         }
5323
5324         CAM_LOG_INFO("Enter");
5325
5326         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5327
5328         if (ret == CAMERA_ERROR_NONE) {
5329                 *latitude = pc->cb_info->get_geotag[0];
5330                 *longitude = pc->cb_info->get_geotag[1];
5331                 *altitude = pc->cb_info->get_geotag[2];
5332         }
5333
5334         CAM_LOG_INFO("ret : 0x%x", ret);
5335
5336         return ret;
5337 }
5338
5339
5340 int camera_attr_get_flash_mode(camera_h camera, camera_attr_flash_mode_e *mode)
5341 {
5342         int ret = CAMERA_ERROR_NONE;
5343         camera_cli_s *pc = (camera_cli_s *)camera;
5344         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FLASH_MODE;
5345
5346         if (!pc || !pc->cb_info || !mode) {
5347                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
5348                 return CAMERA_ERROR_INVALID_PARAMETER;
5349         }
5350
5351         CAM_LOG_INFO("Enter");
5352
5353         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5354
5355         if (ret == CAMERA_ERROR_NONE)
5356                 *mode = (camera_attr_flash_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FLASH_MODE];
5357
5358         CAM_LOG_INFO("ret : 0x%x", ret);
5359
5360         return ret;
5361 }
5362
5363
5364 int camera_get_flash_state(camera_device_e device, camera_flash_state_e *state)
5365 {
5366         int ret = CAMERA_ERROR_NONE;
5367         int get_flash_state = 0;
5368
5369         if (!state) {
5370                 CAM_LOG_ERROR("NULL pointer");
5371                 return CAMERA_ERROR_INVALID_PARAMETER;
5372         }
5373
5374         ret = _camera_independent_request(MUSE_CAMERA_API_GET_FLASH_STATE,
5375                 (int)device, "get_flash_state", &get_flash_state);
5376
5377         if (ret == CAMERA_ERROR_NONE) {
5378                 *state = (camera_flash_state_e)get_flash_state;
5379                 CAM_LOG_INFO("flash state %d", *state);
5380         } else {
5381                 CAM_LOG_ERROR("failed 0x%x", ret);
5382         }
5383
5384         return ret;
5385 }
5386
5387
5388 int camera_attr_foreach_supported_af_mode(camera_h camera, camera_attr_supported_af_mode_cb foreach_cb, void *user_data)
5389 {
5390         int ret = CAMERA_ERROR_NONE;
5391         camera_cli_s *pc = (camera_cli_s *)camera;
5392         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_AF_MODE;
5393
5394         if (!pc || !pc->cb_info || !foreach_cb) {
5395                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5396                 return CAMERA_ERROR_INVALID_PARAMETER;
5397         }
5398
5399         CAM_LOG_INFO("Enter");
5400
5401         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE] = foreach_cb;
5402         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE] = user_data;
5403
5404         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5405
5406         CAM_LOG_INFO("ret : 0x%x", ret);
5407
5408         return ret;
5409 }
5410
5411
5412 int camera_attr_foreach_supported_exposure_mode(camera_h camera, camera_attr_supported_exposure_mode_cb foreach_cb, void *user_data)
5413 {
5414         int ret = CAMERA_ERROR_NONE;
5415         camera_cli_s *pc = (camera_cli_s *)camera;
5416         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EXPOSURE_MODE;
5417
5418         if (!pc || !pc->cb_info || !foreach_cb) {
5419                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5420                 return CAMERA_ERROR_INVALID_PARAMETER;
5421         }
5422
5423         CAM_LOG_INFO("Enter");
5424
5425         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE] = foreach_cb;
5426         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE] = user_data;
5427
5428         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5429
5430         CAM_LOG_INFO("ret : 0x%x", ret);
5431
5432         return ret;
5433 }
5434
5435
5436 int camera_attr_foreach_supported_iso(camera_h camera, camera_attr_supported_iso_cb foreach_cb, void *user_data)
5437 {
5438         int ret = CAMERA_ERROR_NONE;
5439         camera_cli_s *pc = (camera_cli_s *)camera;
5440         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_ISO;
5441
5442         if (!pc || !pc->cb_info || !foreach_cb) {
5443                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5444                 return CAMERA_ERROR_INVALID_PARAMETER;
5445         }
5446
5447         CAM_LOG_INFO("Enter");
5448
5449         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO] = foreach_cb;
5450         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO] = user_data;
5451
5452         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5453
5454         CAM_LOG_INFO("ret : 0x%x", ret);
5455
5456         return ret;
5457 }
5458
5459
5460 int camera_attr_foreach_supported_whitebalance(camera_h camera, camera_attr_supported_whitebalance_cb foreach_cb, void *user_data)
5461 {
5462         int ret = CAMERA_ERROR_NONE;
5463         camera_cli_s *pc = (camera_cli_s *)camera;
5464         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_WHITEBALANCE;
5465
5466         if (!pc || !pc->cb_info || !foreach_cb) {
5467                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5468                 return CAMERA_ERROR_INVALID_PARAMETER;
5469         }
5470
5471         CAM_LOG_INFO("Enter");
5472
5473         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE] = foreach_cb;
5474         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE] = user_data;
5475
5476         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5477
5478         CAM_LOG_INFO("ret : 0x%x", ret);
5479
5480         return ret;
5481 }
5482
5483
5484 int camera_attr_foreach_supported_effect(camera_h camera, camera_attr_supported_effect_cb foreach_cb, void *user_data)
5485 {
5486         int ret = CAMERA_ERROR_NONE;
5487         camera_cli_s *pc = (camera_cli_s *)camera;
5488         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EFFECT;
5489
5490         if (!pc || !pc->cb_info || !foreach_cb) {
5491                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5492                 return CAMERA_ERROR_INVALID_PARAMETER;
5493         }
5494
5495         CAM_LOG_INFO("Enter");
5496
5497         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT] = foreach_cb;
5498         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT] = user_data;
5499
5500         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5501
5502         CAM_LOG_INFO("ret : 0x%x", ret);
5503
5504         return ret;
5505 }
5506
5507
5508 int camera_attr_foreach_supported_scene_mode(camera_h camera, camera_attr_supported_scene_mode_cb foreach_cb, void *user_data)
5509 {
5510         int ret = CAMERA_ERROR_NONE;
5511         camera_cli_s *pc = (camera_cli_s *)camera;
5512         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_SCENE_MODE;
5513
5514         if (!pc || !pc->cb_info || !foreach_cb) {
5515                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5516                 return CAMERA_ERROR_INVALID_PARAMETER;
5517         }
5518
5519         CAM_LOG_INFO("Enter");
5520
5521         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE] = foreach_cb;
5522         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE] = user_data;
5523
5524         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5525
5526         CAM_LOG_INFO("ret : 0x%x", ret);
5527
5528         return ret;
5529 }
5530
5531
5532 int camera_attr_foreach_supported_flash_mode(camera_h camera, camera_attr_supported_flash_mode_cb foreach_cb, void *user_data)
5533 {
5534         int ret = CAMERA_ERROR_NONE;
5535         camera_cli_s *pc = (camera_cli_s *)camera;
5536         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FLASH_MODE;
5537
5538         if (!pc || !pc->cb_info || !foreach_cb) {
5539                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5540                 return CAMERA_ERROR_INVALID_PARAMETER;
5541         }
5542
5543         CAM_LOG_INFO("Enter");
5544
5545         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE] = foreach_cb;
5546         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE] = user_data;
5547
5548         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5549
5550         CAM_LOG_INFO("ret : 0x%x", ret);
5551
5552         return ret;
5553 }
5554
5555
5556 int camera_attr_foreach_supported_fps(camera_h camera, camera_attr_supported_fps_cb foreach_cb, void *user_data)
5557 {
5558         int ret = CAMERA_ERROR_NONE;
5559         camera_cli_s *pc = (camera_cli_s *)camera;
5560         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS;
5561
5562         if (!pc || !pc->cb_info || !foreach_cb) {
5563                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5564                 return CAMERA_ERROR_INVALID_PARAMETER;
5565         }
5566
5567         CAM_LOG_INFO("Enter");
5568
5569         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS] = foreach_cb;
5570         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS] = user_data;
5571
5572         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5573
5574         CAM_LOG_INFO("Enter, handle :%td", pc->remote_handle);
5575
5576         return ret;
5577 }
5578
5579
5580 int camera_attr_foreach_supported_fps_by_resolution(camera_h camera, int width, int height, camera_attr_supported_fps_cb foreach_cb, void *user_data)
5581 {
5582         int ret = CAMERA_ERROR_NONE;
5583         camera_cli_s *pc = (camera_cli_s *)camera;
5584         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS_BY_RESOLUTION;
5585         camera_msg_param param;
5586         int value = 0;
5587
5588         if (!pc || !pc->cb_info || !foreach_cb) {
5589                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5590                 return CAMERA_ERROR_INVALID_PARAMETER;
5591         }
5592
5593         CAM_LOG_INFO("Enter");
5594
5595         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION] = foreach_cb;
5596         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION] = user_data;
5597
5598         value = (width << 16) | height;
5599         CAMERA_MSG_PARAM_SET(param, INT, value);
5600
5601         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5602
5603         CAM_LOG_INFO("ret : 0x%x", ret);
5604
5605         return ret;
5606 }
5607
5608
5609 int camera_attr_foreach_supported_stream_flip(camera_h camera, camera_attr_supported_stream_flip_cb foreach_cb, void *user_data)
5610 {
5611         int ret = CAMERA_ERROR_NONE;
5612         camera_cli_s *pc = (camera_cli_s *)camera;
5613         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_FLIP;
5614
5615         if (!pc || !pc->cb_info || !foreach_cb) {
5616                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5617                 return CAMERA_ERROR_INVALID_PARAMETER;
5618         }
5619
5620         CAM_LOG_INFO("Enter");
5621
5622         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP] = foreach_cb;
5623         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP] = user_data;
5624
5625         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5626
5627         CAM_LOG_INFO("ret : 0x%x", ret);
5628
5629         return ret;
5630 }
5631
5632
5633 int camera_attr_foreach_supported_stream_rotation(camera_h camera, camera_attr_supported_stream_rotation_cb foreach_cb, void *user_data)
5634 {
5635         int ret = CAMERA_ERROR_NONE;
5636         camera_cli_s *pc = (camera_cli_s *)camera;
5637         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_ROTATION;
5638
5639         if (!pc || !pc->cb_info || !foreach_cb) {
5640                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5641                 return CAMERA_ERROR_INVALID_PARAMETER;
5642         }
5643
5644         CAM_LOG_INFO("Enter");
5645
5646         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION] = foreach_cb;
5647         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION] = user_data;
5648
5649         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5650
5651         CAM_LOG_INFO("ret : 0x%x", ret);
5652
5653         return ret;
5654 }
5655
5656
5657 int camera_attr_set_stream_rotation(camera_h camera, camera_rotation_e rotation)
5658 {
5659         int ret = CAMERA_ERROR_NONE;
5660         camera_cli_s *pc = (camera_cli_s *)camera;
5661         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_STREAM_ROTATION;
5662         camera_msg_param param;
5663         int set_rotation = (int)rotation;
5664
5665         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
5666
5667         CAM_LOG_INFO("Enter");
5668
5669         CAMERA_MSG_PARAM_SET(param, INT, set_rotation);
5670
5671         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5672
5673         CAM_LOG_INFO("ret : 0x%x", ret);
5674
5675         return ret;
5676 }
5677
5678
5679 int camera_attr_get_stream_rotation(camera_h camera, camera_rotation_e *rotation)
5680 {
5681         int ret = CAMERA_ERROR_NONE;
5682         camera_cli_s *pc = (camera_cli_s *)camera;
5683         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_STREAM_ROTATION;
5684
5685         if (!pc || !pc->cb_info || !rotation) {
5686                 CAM_LOG_ERROR("NULL pointer %p %p", pc, rotation);
5687                 return CAMERA_ERROR_INVALID_PARAMETER;
5688         }
5689
5690         CAM_LOG_INFO("Enter");
5691
5692         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5693
5694         if (ret == CAMERA_ERROR_NONE)
5695                 *rotation = (camera_rotation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STREAM_ROTATION];
5696
5697         CAM_LOG_INFO("ret : 0x%x", ret);
5698
5699         return ret;
5700 }
5701
5702
5703 int camera_attr_set_stream_flip(camera_h camera, camera_flip_e flip)
5704 {
5705         int ret = CAMERA_ERROR_NONE;
5706         camera_cli_s *pc = (camera_cli_s *)camera;
5707         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_STREAM_FLIP;
5708         camera_msg_param param;
5709         int set_flip = (int)flip;
5710
5711         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
5712
5713         CAM_LOG_INFO("Enter");
5714
5715         CAMERA_MSG_PARAM_SET(param, INT, set_flip);
5716
5717         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5718
5719         CAM_LOG_INFO("ret : 0x%x", ret);
5720
5721         return ret;
5722 }
5723
5724
5725 int camera_attr_get_stream_flip(camera_h camera, camera_flip_e *flip)
5726 {
5727         int ret = CAMERA_ERROR_NONE;
5728         camera_cli_s *pc = (camera_cli_s *)camera;
5729         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_STREAM_FLIP;
5730
5731         if (!pc || !pc->cb_info || !flip) {
5732                 CAM_LOG_ERROR("NULL pointer %p %p", pc, flip);
5733                 return CAMERA_ERROR_INVALID_PARAMETER;
5734         }
5735
5736         CAM_LOG_INFO("Enter");
5737
5738         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5739
5740         if (ret == CAMERA_ERROR_NONE)
5741                 *flip = (camera_flip_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STREAM_FLIP];
5742
5743         CAM_LOG_INFO("ret : 0x%x", ret);
5744
5745         return ret;
5746 }
5747
5748 int camera_attr_set_hdr_mode(camera_h camera, camera_attr_hdr_mode_e mode)
5749 {
5750         return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_HDR_MODE, (int)mode);
5751 }
5752
5753
5754 int camera_attr_get_hdr_mode(camera_h camera, camera_attr_hdr_mode_e *mode)
5755 {
5756         int ret = CAMERA_ERROR_NONE;
5757         camera_cli_s *pc = (camera_cli_s *)camera;
5758         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HDR_MODE;
5759
5760         if (!pc || !pc->cb_info || !mode) {
5761                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
5762                 return CAMERA_ERROR_INVALID_PARAMETER;
5763         }
5764
5765         CAM_LOG_INFO("Enter");
5766
5767         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5768
5769         if (ret == CAMERA_ERROR_NONE)
5770                 *mode = (camera_attr_hdr_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_HDR_MODE];
5771
5772         CAM_LOG_INFO("ret : 0x%x", ret);
5773
5774         return ret;
5775 }
5776
5777
5778 bool camera_attr_is_supported_hdr_capture(camera_h camera)
5779 {
5780         return __is_supported(camera, MUSE_CAMERA_API_ATTR_IS_SUPPORTED_HDR_CAPTURE);
5781 }
5782
5783
5784 int camera_attr_set_hdr_capture_progress_cb(camera_h camera, camera_attr_hdr_progress_cb callback, void *user_data)
5785 {
5786         int ret = CAMERA_ERROR_NONE;
5787         camera_cli_s *pc = (camera_cli_s *)camera;
5788         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HDR_CAPTURE_PROGRESS_CB;
5789
5790         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
5791
5792         CAM_LOG_INFO("Enter");
5793
5794         if (!camera_attr_is_supported_hdr_capture(camera)) {
5795                 CAM_LOG_ERROR("HDR not supported");
5796                 return CAMERA_ERROR_NOT_SUPPORTED;
5797         }
5798
5799         if (!callback) {
5800                 CAM_LOG_ERROR("NULL callback");
5801                 return CAMERA_ERROR_INVALID_PARAMETER;
5802         }
5803
5804         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5805
5806         if (ret == CAMERA_ERROR_NONE) {
5807                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
5808
5809                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = callback;
5810                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = user_data;
5811
5812                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
5813         }
5814
5815         CAM_LOG_INFO("ret : 0x%x", ret);
5816
5817         return ret;
5818 }
5819
5820
5821 int camera_attr_unset_hdr_capture_progress_cb(camera_h camera)
5822 {
5823         int ret = CAMERA_ERROR_NONE;
5824         camera_cli_s *pc = (camera_cli_s *)camera;
5825         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_UNSET_HDR_CAPTURE_PROGRESS_CB;
5826
5827         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
5828
5829         CAM_LOG_INFO("Enter");
5830
5831         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5832
5833         if (ret == CAMERA_ERROR_NONE) {
5834                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
5835
5836                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
5837                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
5838
5839                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
5840         }
5841
5842         CAM_LOG_INFO("ret : 0x%x", ret);
5843
5844         return ret;
5845 }
5846
5847
5848 int camera_attr_enable_anti_shake(camera_h camera, bool enable)
5849 {
5850         return __set_enable(camera, MUSE_CAMERA_API_ATTR_ENABLE_ANTI_SHAKE, (int)enable);
5851 }
5852
5853
5854 int camera_attr_is_enabled_anti_shake(camera_h camera, bool *enabled)
5855 {
5856         int ret = CAMERA_ERROR_NONE;
5857         camera_cli_s *pc = (camera_cli_s *)camera;
5858         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_ANTI_SHAKE;
5859
5860         if (!pc || !pc->cb_info || !enabled) {
5861                 CAM_LOG_ERROR("NULL pointer %p %p", pc, enabled);
5862                 return CAMERA_ERROR_INVALID_PARAMETER;
5863         }
5864
5865         CAM_LOG_INFO("Enter");
5866
5867         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5868
5869         if (ret == CAMERA_ERROR_NONE)
5870                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_ANTI_SHAKE];
5871
5872         CAM_LOG_INFO("ret : 0x%x", ret);
5873
5874         return ret;
5875 }
5876
5877
5878 bool camera_attr_is_supported_anti_shake(camera_h camera)
5879 {
5880         return __is_supported(camera, MUSE_CAMERA_API_ATTR_IS_SUPPORTED_ANTI_SHAKE);
5881 }
5882
5883
5884 int camera_attr_enable_video_stabilization(camera_h camera, bool enable)
5885 {
5886         return __set_enable(camera, MUSE_CAMERA_API_ATTR_ENABLE_VIDEO_STABILIZATION, (int)enable);
5887 }
5888
5889
5890 int camera_attr_is_enabled_video_stabilization(camera_h camera, bool *enabled)
5891 {
5892         int ret = CAMERA_ERROR_NONE;
5893         camera_cli_s *pc = (camera_cli_s *)camera;
5894         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_VIDEO_STABILIZATION;
5895
5896         if (!pc || !pc->cb_info || !enabled) {
5897                 CAM_LOG_ERROR("NULL pointer %p %p", pc, enabled);
5898                 return CAMERA_ERROR_INVALID_PARAMETER;
5899         }
5900
5901         CAM_LOG_INFO("Enter");
5902
5903         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5904
5905         if (ret == CAMERA_ERROR_NONE)
5906                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_VIDEO_STABILIZATION];
5907
5908         CAM_LOG_INFO("ret : 0x%x", ret);
5909
5910         return ret;
5911 }
5912
5913
5914 bool camera_attr_is_supported_video_stabilization(camera_h camera)
5915 {
5916         return __is_supported(camera, MUSE_CAMERA_API_ATTR_IS_SUPPORTED_VIDEO_STABILIZATION);
5917 }
5918
5919
5920 int camera_attr_enable_auto_contrast(camera_h camera, bool enable)
5921 {
5922         return __set_enable(camera, MUSE_CAMERA_API_ATTR_ENABLE_AUTO_CONTRAST, (int)enable);
5923 }
5924
5925
5926 int camera_attr_is_enabled_auto_contrast(camera_h camera, bool *enabled)
5927 {
5928         int ret = CAMERA_ERROR_NONE;
5929         camera_cli_s *pc = (camera_cli_s *)camera;
5930         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_AUTO_CONTRAST;
5931
5932         if (!pc || !pc->cb_info || !enabled) {
5933                 CAM_LOG_ERROR("NULL pointer %p %p", pc, enabled);
5934                 return CAMERA_ERROR_INVALID_PARAMETER;
5935         }
5936
5937         CAM_LOG_INFO("Enter");
5938
5939         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5940
5941         if (ret == CAMERA_ERROR_NONE)
5942                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_AUTO_CONTRAST];
5943
5944         CAM_LOG_INFO("ret : 0x%x", ret);
5945
5946         return ret;
5947 }
5948
5949
5950 bool camera_attr_is_supported_auto_contrast(camera_h camera)
5951 {
5952         return __is_supported(camera, MUSE_CAMERA_API_ATTR_IS_SUPPORTED_AUTO_CONTRAST);
5953 }
5954
5955
5956 int camera_attr_disable_shutter_sound(camera_h camera, bool disable)
5957 {
5958         int ret = CAMERA_ERROR_NONE;
5959         camera_cli_s *pc = (camera_cli_s *)camera;
5960         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_DISABLE_SHUTTER_SOUND;
5961         camera_msg_param param;
5962         int set_disable = (int)disable;
5963
5964         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
5965
5966         CAM_LOG_INFO("Enter");
5967
5968         CAMERA_MSG_PARAM_SET(param, INT, set_disable);
5969
5970         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5971
5972         CAM_LOG_INFO("ret : 0x%x", ret);
5973
5974         return ret;
5975 }
5976
5977
5978 int camera_attr_set_pan(camera_h camera, camera_attr_ptz_move_type_e move_type, int pan_step)
5979 {
5980         int ret = CAMERA_ERROR_NONE;
5981         camera_cli_s *pc = (camera_cli_s *)camera;
5982         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PAN;
5983         camera_msg_param param0;
5984         camera_msg_param param1;
5985
5986         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
5987
5988         CAM_LOG_INFO("Enter");
5989
5990         CAMERA_MSG_PARAM_SET(param0, INT, move_type);
5991         CAMERA_MSG_PARAM_SET(param1, INT, pan_step);
5992
5993         _camera_msg_send_param2_int(api, pc->cb_info, &ret,
5994                 &param0, &param1, CAMERA_CB_TIMEOUT);
5995
5996         CAM_LOG_INFO("ret : 0x%x", ret);
5997
5998         return ret;
5999 }
6000
6001
6002 int camera_attr_get_pan(camera_h camera, int *pan_step)
6003 {
6004         int ret = CAMERA_ERROR_NONE;
6005         camera_cli_s *pc = (camera_cli_s *)camera;
6006         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN;
6007
6008         if (!pc || !pc->cb_info || !pan_step) {
6009                 CAM_LOG_ERROR("NULL pointer %p %p", pc, pan_step);
6010                 return CAMERA_ERROR_INVALID_PARAMETER;
6011         }
6012
6013         CAM_LOG_INFO("Enter");
6014
6015         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6016
6017         if (ret == CAMERA_ERROR_NONE)
6018                 *pan_step = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PAN];
6019
6020         CAM_LOG_INFO("ret : 0x%x", ret);
6021
6022         return ret;
6023 }
6024
6025
6026 int camera_attr_get_pan_range(camera_h camera, int *min, int *max)
6027 {
6028         int ret = CAMERA_ERROR_NONE;
6029         camera_cli_s *pc = (camera_cli_s *)camera;
6030         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN_RANGE;
6031
6032         if (!pc || !pc->cb_info || !min || !max) {
6033                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
6034                 return CAMERA_ERROR_INVALID_PARAMETER;
6035         }
6036
6037         CAM_LOG_INFO("Enter");
6038
6039         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6040
6041         if (ret == CAMERA_ERROR_NONE) {
6042                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE][0];
6043                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE][1];
6044         }
6045
6046         CAM_LOG_INFO("ret : 0x%x", ret);
6047
6048         return ret;
6049 }
6050
6051
6052 int camera_attr_set_tilt(camera_h camera, camera_attr_ptz_move_type_e move_type, int tilt_step)
6053 {
6054         int ret = CAMERA_ERROR_NONE;
6055         camera_cli_s *pc = (camera_cli_s *)camera;
6056         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TILT;
6057         camera_msg_param param0;
6058         camera_msg_param param1;
6059
6060         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6061
6062         CAM_LOG_INFO("Enter");
6063
6064         CAMERA_MSG_PARAM_SET(param0, INT, move_type);
6065         CAMERA_MSG_PARAM_SET(param1, INT, tilt_step);
6066
6067         _camera_msg_send_param2_int(api, pc->cb_info, &ret,
6068                 &param0, &param1, CAMERA_CB_TIMEOUT);
6069
6070         CAM_LOG_INFO("ret : 0x%x", ret);
6071
6072         return ret;
6073 }
6074
6075
6076 int camera_attr_get_tilt(camera_h camera, int *tilt_step)
6077 {
6078         int ret = CAMERA_ERROR_NONE;
6079         camera_cli_s *pc = (camera_cli_s *)camera;
6080         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TILT;
6081
6082         if (!pc || !pc->cb_info || !tilt_step) {
6083                 CAM_LOG_ERROR("NULL pointer %p %p", pc, tilt_step);
6084                 return CAMERA_ERROR_INVALID_PARAMETER;
6085         }
6086
6087         CAM_LOG_INFO("Enter");
6088
6089         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6090
6091         if (ret == CAMERA_ERROR_NONE)
6092                 *tilt_step = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_TILT];
6093
6094         CAM_LOG_INFO("ret : 0x%x", ret);
6095
6096         return ret;
6097 }
6098
6099
6100 int camera_attr_get_tilt_range(camera_h camera, int *min, int *max)
6101 {
6102         int ret = CAMERA_ERROR_NONE;
6103         camera_cli_s *pc = (camera_cli_s *)camera;
6104         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TILT_RANGE;
6105
6106         if (!pc || !pc->cb_info || !min || !max) {
6107                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
6108                 return CAMERA_ERROR_INVALID_PARAMETER;
6109         }
6110
6111         CAM_LOG_INFO("Enter");
6112
6113         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6114
6115         if (ret == CAMERA_ERROR_NONE) {
6116                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE][0];
6117                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE][1];
6118         }
6119
6120         CAM_LOG_INFO("ret : 0x%x", ret);
6121
6122         return ret;
6123 }
6124
6125
6126 int camera_attr_set_ptz_type(camera_h camera, camera_attr_ptz_type_e ptz_type)
6127 {
6128         int ret = CAMERA_ERROR_NONE;
6129         camera_cli_s *pc = (camera_cli_s *)camera;
6130         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PTZ_TYPE;
6131         camera_msg_param param;
6132         int set_ptz_type = (int)ptz_type;
6133
6134         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6135
6136         CAM_LOG_INFO("Enter");
6137
6138         CAMERA_MSG_PARAM_SET(param, INT, set_ptz_type);
6139
6140         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6141
6142         CAM_LOG_INFO("ret : 0x%x", ret);
6143
6144         return ret;
6145 }
6146
6147
6148 int camera_attr_foreach_supported_ptz_type(camera_h camera, camera_attr_supported_ptz_type_cb foreach_cb, void *user_data)
6149 {
6150         int ret = CAMERA_ERROR_NONE;
6151         camera_cli_s *pc = (camera_cli_s *)camera;
6152         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_PTZ_TYPE;
6153
6154         if (!pc || !pc->cb_info || !foreach_cb) {
6155                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
6156                 return CAMERA_ERROR_INVALID_PARAMETER;
6157         }
6158
6159         CAM_LOG_INFO("Enter");
6160
6161         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE] = foreach_cb;
6162         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE] = user_data;
6163
6164         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6165
6166         CAM_LOG_INFO("ret : 0x%x", ret);
6167
6168         return ret;
6169 }
6170
6171
6172 int camera_attr_set_display_roi_area(camera_h camera, int x, int y, int width, int height)
6173 {
6174         int ret = CAMERA_ERROR_NONE;
6175         camera_cli_s *pc = (camera_cli_s *)camera;
6176         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY_ROI_AREA;
6177         int set_display_roi_area[4] = {x, y, width, height};
6178         char *msg = NULL;
6179         int length = 0;
6180
6181         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6182
6183         CAM_LOG_INFO("Enter");
6184
6185         if (pc->cb_info->is_evas_render) {
6186                 ret = mm_display_interface_evas_set_roi_area(pc->cb_info->dp_interface, x, y, width, height);
6187                 if (ret != MM_ERROR_NONE) {
6188                         CAM_LOG_ERROR("mm_evas_renderer_set_roi_area error 0x%x", ret);
6189                         return CAMERA_ERROR_INVALID_OPERATION;
6190                 }
6191         }
6192
6193         length = sizeof(set_display_roi_area) / sizeof(int) + \
6194                 (sizeof(set_display_roi_area) % sizeof(int) ? 1 : 0);
6195
6196         msg = muse_core_msg_new(api,
6197                 MUSE_TYPE_ARRAY, "set_display_roi_area", length, (int *)set_display_roi_area,
6198                 NULL);
6199
6200         _camera_send_message_get_return(pc->cb_info, api, msg, CAMERA_CB_TIMEOUT, &ret);
6201
6202         return ret;
6203 }
6204
6205
6206 int camera_attr_get_display_roi_area(camera_h camera, int *x, int *y, int *width, int *height)
6207 {
6208         camera_cli_s *pc = (camera_cli_s *)camera;
6209         int ret = CAMERA_ERROR_NONE;
6210         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_ROI_AREA;
6211
6212         if (!pc || !pc->cb_info || !x || !y || !width || !height) {
6213                 CAM_LOG_ERROR("NULL pointer %p %p %p %p %p", pc, x, y, width, height);
6214                 return CAMERA_ERROR_INVALID_PARAMETER;
6215         }
6216
6217         CAM_LOG_INFO("Enter");
6218
6219         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6220
6221         if (ret == CAMERA_ERROR_NONE) {
6222                 *x = pc->cb_info->get_display_roi_area[0];
6223                 *y = pc->cb_info->get_display_roi_area[1];
6224                 *width = pc->cb_info->get_display_roi_area[2];
6225                 *height = pc->cb_info->get_display_roi_area[3];
6226         }
6227
6228         CAM_LOG_INFO("ret : 0x%x", ret);
6229
6230         return ret;
6231 }
6232
6233
6234 int camera_get_device_state(camera_device_e device, camera_device_state_e *state)
6235 {
6236         int ret = CAMERA_ERROR_NONE;
6237         int get_device_state = 0;
6238
6239         if (!state) {
6240                 CAM_LOG_ERROR("NULL pointer");
6241                 return CAMERA_ERROR_INVALID_PARAMETER;
6242         }
6243
6244         ret = _camera_independent_request(MUSE_CAMERA_API_GET_DEVICE_STATE,
6245                 (int)device, "get_device_state", &get_device_state);
6246
6247         if (ret == CAMERA_ERROR_NONE) {
6248                 *state = (camera_device_state_e)get_device_state;
6249                 CAM_LOG_INFO("device state %d", *state);
6250         } else {
6251                 CAM_LOG_ERROR("failed 0x%x", ret);
6252         }
6253
6254         return ret;
6255 }
6256
6257
6258 int camera_add_device_state_changed_cb(camera_device_state_changed_cb callback, void *user_data, int *cb_id)
6259 {
6260         int ret = CAMERA_ERROR_NONE;
6261         camera_device_state_e state = CAMERA_DEVICE_STATE_NULL;
6262         camera_cb_info *info = NULL;
6263
6264         if (!callback || !cb_id) {
6265                 CAM_LOG_ERROR("invalid pointer %p %p", callback, cb_id);
6266                 return CAMERA_ERROR_INVALID_PARAMETER;
6267         }
6268
6269         /* check camera support */
6270         ret = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &state);
6271         if (ret != CAMERA_ERROR_NONE) {
6272                 CAM_LOG_ERROR("get device state failed");
6273                 return ret;
6274         }
6275
6276         g_mutex_lock(&g_cam_dev_state_changed_cb_lock);
6277
6278         info = g_new0(camera_cb_info, 1);
6279         if (!info) {
6280                 CAM_LOG_ERROR("info failed");
6281                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
6282                 goto _DONE;
6283         }
6284
6285         info->id = ++g_cam_dev_state_changed_cb_id;
6286         info->callback = (void *)callback;
6287         info->user_data = user_data;
6288
6289         *cb_id = info->id;
6290
6291         /* subscribe dbus signal for camera state change */
6292         if (!g_cam_dev_state_changed_cb_conn) {
6293                 g_cam_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
6294                 if (!g_cam_dev_state_changed_cb_conn) {
6295                         CAM_LOG_ERROR("failed to get gdbus connection");
6296                         ret = CAMERA_ERROR_INVALID_OPERATION;
6297                         goto _DONE;
6298                 }
6299
6300                 CAM_LOG_INFO("subscribe signal %s - %s - %s",
6301                         MM_CAMCORDER_DBUS_OBJECT,
6302                         MM_CAMCORDER_DBUS_INTERFACE_CAMERA,
6303                         MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
6304
6305                 g_cam_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_cam_dev_state_changed_cb_conn,
6306                         NULL, MM_CAMCORDER_DBUS_INTERFACE_CAMERA, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
6307                         G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__camera_device_state_changed_cb, NULL, NULL);
6308                 if (!g_cam_dev_state_changed_cb_subscribe_id) {
6309                         CAM_LOG_ERROR("failed to get gdbus connection");
6310                         ret = CAMERA_ERROR_INVALID_OPERATION;
6311                         goto _DONE;
6312                 }
6313
6314                 CAM_LOG_INFO("signal subscribe id %u", g_cam_dev_state_changed_cb_subscribe_id);
6315         }
6316
6317         g_cam_dev_state_changed_cb_list = g_list_prepend(g_cam_dev_state_changed_cb_list, (gpointer)info);
6318
6319         CAM_LOG_INFO("callback id %d", info->id);
6320
6321 _DONE:
6322         if (ret != CAMERA_ERROR_NONE) {
6323                 if (info) {
6324                         g_free(info);
6325                         info = NULL;
6326                 }
6327
6328                 if (g_cam_dev_state_changed_cb_conn) {
6329                         g_object_unref(g_cam_dev_state_changed_cb_conn);
6330                         g_cam_dev_state_changed_cb_conn = NULL;
6331                 }
6332         }
6333
6334         g_mutex_unlock(&g_cam_dev_state_changed_cb_lock);
6335
6336         return ret;
6337 }
6338
6339
6340 int camera_remove_device_state_changed_cb(int cb_id)
6341 {
6342         int ret = CAMERA_ERROR_NONE;
6343         camera_device_state_e state = CAMERA_DEVICE_STATE_NULL;
6344         GList *tmp_list = NULL;
6345         camera_cb_info *info = NULL;
6346
6347         /* check camera support */
6348         ret = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &state);
6349         if (ret != CAMERA_ERROR_NONE) {
6350                 CAM_LOG_ERROR("get device state failed");
6351                 return ret;
6352         }
6353
6354         g_mutex_lock(&g_cam_dev_state_changed_cb_lock);
6355
6356         if (!g_cam_dev_state_changed_cb_list) {
6357                 CAM_LOG_ERROR("there is no callback info");
6358                 ret = CAMERA_ERROR_INVALID_OPERATION;
6359                 goto _DONE;
6360         }
6361
6362         tmp_list = g_cam_dev_state_changed_cb_list;
6363
6364         do {
6365                 info = tmp_list->data;
6366                 tmp_list = tmp_list->next;
6367
6368                 if (!info) {
6369                         CAM_LOG_WARNING("NULL info");
6370                         continue;
6371                 }
6372
6373                 if (info->id == cb_id) {
6374                         g_cam_dev_state_changed_cb_list = g_list_remove(g_cam_dev_state_changed_cb_list, info);
6375
6376                         g_free(info);
6377                         info = NULL;
6378
6379                         if (!g_cam_dev_state_changed_cb_list) {
6380                                 /* no remained callback */
6381                                 if (g_cam_dev_state_changed_cb_conn) {
6382                                         /* unsubscribe signal */
6383                                         g_dbus_connection_signal_unsubscribe(g_cam_dev_state_changed_cb_conn, g_cam_dev_state_changed_cb_subscribe_id);
6384                                         g_cam_dev_state_changed_cb_subscribe_id = 0;
6385
6386                                         /* unref connection */
6387                                         g_object_unref(g_cam_dev_state_changed_cb_conn);
6388                                         g_cam_dev_state_changed_cb_conn = NULL;
6389                                 }
6390                         }
6391
6392                         CAM_LOG_INFO("id %d callback removed", cb_id);
6393                         ret = CAMERA_ERROR_NONE;
6394
6395                         goto _DONE;
6396                 }
6397         } while (tmp_list);
6398
6399         CAM_LOG_ERROR("id %d callback not found", cb_id);
6400         ret = CAMERA_ERROR_INVALID_PARAMETER;
6401
6402 _DONE:
6403         g_mutex_unlock(&g_cam_dev_state_changed_cb_lock);
6404
6405         return ret;
6406 }
6407
6408
6409 //LCOV_EXCL_START
6410 int camera_media_bridge_set_bridge(camera_h camera, media_bridge_h bridge)
6411 {
6412         int ret = CAMERA_ERROR_NONE;
6413         camera_cli_s *pc = (camera_cli_s *)camera;
6414         muse_camera_api_e api = MUSE_CAMERA_API_SET_MEDIA_BRIDGE;
6415
6416         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6417
6418         g_mutex_lock(&pc->cb_info->bridge_lock);
6419
6420         if (pc->cb_info->bridge) {
6421                 CAM_LOG_ERROR("media bridge[%p] is already set", pc->cb_info->bridge);
6422                 ret = CAMERA_ERROR_INVALID_OPERATION;
6423                 goto _SET_MEDIA_BRIDGE_DONE;
6424         }
6425
6426         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6427         if (ret != CAMERA_ERROR_NONE) {
6428                 CAM_LOG_ERROR("set media bridge failed[0x%x]", ret);
6429                 goto _SET_MEDIA_BRIDGE_DONE;
6430         }
6431
6432         pc->cb_info->bridge = bridge;
6433
6434         CAM_LOG_INFO("[%p] set media bridge[%p]", camera, bridge);
6435
6436 _SET_MEDIA_BRIDGE_DONE:
6437         g_mutex_unlock(&pc->cb_info->bridge_lock);
6438
6439         return ret;
6440 }
6441
6442
6443 int camera_media_bridge_unset_bridge(camera_h camera)
6444 {
6445         int ret = CAMERA_ERROR_NONE;
6446         camera_cli_s *pc = (camera_cli_s *)camera;
6447         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_MEDIA_BRIDGE;
6448
6449         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6450
6451         g_mutex_lock(&pc->cb_info->bridge_lock);
6452
6453         if (!pc->cb_info->bridge) {
6454                 CAM_LOG_ERROR("no media bridge");
6455                 ret = CAMERA_ERROR_INVALID_OPERATION;
6456                 goto _UNSET_MEDIA_BRIDGE_DONE;
6457         }
6458
6459         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6460         if (ret != CAMERA_ERROR_NONE) {
6461                 CAM_LOG_ERROR("unset media bridge failed[0x%x]", ret);
6462                 goto _UNSET_MEDIA_BRIDGE_DONE;
6463         }
6464
6465         CAM_LOG_INFO("[%p] unset media bridge[%p]", camera, pc->cb_info->bridge);
6466
6467         pc->cb_info->bridge = NULL;
6468
6469 _UNSET_MEDIA_BRIDGE_DONE:
6470         g_mutex_unlock(&pc->cb_info->bridge_lock);
6471
6472         return ret;
6473 }
6474 //LCOV_EXCL_STOP
6475
6476
6477 int camera_create_network(camera_device_e device, camera_h *camera)
6478 {
6479         return _camera_create_private(device, true, camera);
6480 }
6481
6482
6483 int camera_device_manager_initialize(camera_device_manager_h *manager)
6484 {
6485         unsigned int i = 0;
6486         int ret = CAMERA_ERROR_NONE;
6487         void *dl_handle = NULL;
6488         g_autofree camera_device_manager *new_manager = g_new0(camera_device_manager, 1);
6489         cdm_symbol_table sym_table[] = {
6490                 {(void **)&new_manager->initialize, "cdm_initialize"},
6491                 {(void **)&new_manager->deinitialize, "cdm_deinitialize"},
6492                 {(void **)&new_manager->get_device_list, "cdm_get_device_list"},
6493                 {(void **)&new_manager->add_device_connection_changed_cb, "cdm_add_device_connection_changed_cb"},
6494                 {(void **)&new_manager->remove_device_connection_changed_cb, "cdm_remove_device_connection_changed_cb"},
6495         };
6496
6497         CAMERA_CHECK_DEVICE_MANAGER;
6498
6499         if (!manager) {
6500                 CAM_LOG_ERROR("NULL manager");
6501                 ret = CAMERA_ERROR_INVALID_PARAMETER;
6502                 goto _INITIALIZE_FAILED;
6503         }
6504
6505         dl_handle = dlopen(LIB_CAMERA_DEVICE_MANAGER, RTLD_NOW);
6506         if (!dl_handle) {
6507                 CAM_LOG_ERROR("dlopen[%s] failed[%s]", LIB_CAMERA_DEVICE_MANAGER, dlerror());
6508                 ret = CAMERA_ERROR_INVALID_OPERATION;
6509                 goto _INITIALIZE_FAILED;
6510         }
6511
6512         /* get symbols */
6513         for (i = 0 ; i < G_N_ELEMENTS(sym_table) ; i++) {
6514                 *sym_table[i].func_ptr = dlsym(dl_handle, sym_table[i].func_name);
6515                 if (*sym_table[i].func_ptr == NULL) {
6516                         CAM_LOG_ERROR("symbol failed[%s]", sym_table[i].func_name);
6517                         ret = CAMERA_ERROR_INVALID_OPERATION;
6518                         goto _INITIALIZE_FAILED;
6519                 }
6520         }
6521
6522         ret = new_manager->initialize();
6523         if (ret != CAMERA_ERROR_NONE) {
6524                 CAM_LOG_ERROR("failed[0x%x]", ret);
6525                 goto _INITIALIZE_FAILED;
6526         }
6527
6528         new_manager->dl_handle = dl_handle;
6529         *manager = (camera_device_manager_h)g_steal_pointer(&new_manager);
6530
6531         CAM_LOG_INFO("camera device manager[%p](dl handle[%p]) initialized",
6532                 *manager, dl_handle);
6533
6534         return CAMERA_ERROR_NONE;
6535
6536 _INITIALIZE_FAILED:
6537         if (dl_handle)
6538                 dlclose(dl_handle);
6539
6540         return ret;
6541 }
6542
6543
6544 //LCOV_EXCL_START
6545 int camera_device_manager_deinitialize(camera_device_manager_h manager)
6546 {
6547         int ret = CAMERA_ERROR_NONE;
6548         camera_device_manager *m = (camera_device_manager *)manager;
6549
6550         CAMERA_CHECK_DEVICE_MANAGER;
6551
6552         if (!m) {
6553                 CAM_LOG_ERROR("NULL manager");
6554                 return CAMERA_ERROR_INVALID_PARAMETER;
6555         }
6556
6557         CAM_LOG_INFO("deinitialize camera device manager[%p]", m);
6558
6559         ret = m->deinitialize();
6560         if (ret != CAMERA_ERROR_NONE) {
6561                 CAM_LOG_ERROR("failed[0x%x]", ret);
6562                 return ret;
6563         }
6564
6565         CAM_LOG_INFO("close dl handle[%p]", m->dl_handle);
6566
6567         dlclose(m->dl_handle);
6568
6569         memset(m, 0x0, sizeof(camera_device_manager));
6570         g_free(m);
6571
6572         return CAMERA_ERROR_NONE;
6573 }
6574
6575
6576 int camera_device_manager_foreach_supported_device(camera_device_manager_h manager, camera_supported_device_cb callback, void *user_data)
6577 {
6578         int ret = CAMERA_ERROR_NONE;
6579         unsigned int i = 0;
6580         camera_device_list_s device_list;
6581         camera_device_s *device = NULL;
6582         camera_device_manager *m = (camera_device_manager *)manager;
6583
6584         CAMERA_CHECK_DEVICE_MANAGER;
6585
6586         if (!m || !callback) {
6587                 CAM_LOG_ERROR("NULL parameter[%p,%p]", m, callback);
6588                 return CAMERA_ERROR_INVALID_PARAMETER;
6589         }
6590
6591         CAM_LOG_INFO("enter");
6592
6593         memset(&device_list, 0x0, sizeof(camera_device_list_s));
6594
6595         ret = m->get_device_list(&device_list);
6596         if (ret != CAMERA_ERROR_NONE) {
6597                 CAM_LOG_ERROR("failed[0x%x]", ret);
6598                 return ret;
6599         }
6600
6601         CAM_LOG_INFO("device count[%d]", device_list.count);
6602
6603         for (i = 0 ; i < device_list.count ; i++) {
6604                 device = &device_list.device[i];
6605
6606                 CAM_LOG_INFO("    [%d] : type[%d], index[%d], name[%s], id[%s], ex-stream[%d]",
6607                         i, device->type, device->index,
6608                         device->name, device->id, device->extra_stream_num);
6609
6610                 if (!callback(device, user_data)) {
6611                         CAM_LOG_WARNING("callback is stopped[called:%u,total:%u]",
6612                                 i + 1, device_list.count);
6613                         break;
6614                 }
6615         }
6616
6617         return CAMERA_ERROR_NONE;
6618 }
6619
6620
6621 int camera_device_manager_add_device_connection_changed_cb(camera_device_manager_h manager,
6622         camera_device_connection_changed_cb callback, void *user_data, int *cb_id)
6623 {
6624         int ret = CAMERA_ERROR_NONE;
6625         camera_device_manager *m = (camera_device_manager *)manager;
6626
6627         CAMERA_CHECK_DEVICE_MANAGER;
6628
6629         if (!m || !callback || !cb_id) {
6630                 CAM_LOG_ERROR("NULL parameter[%p,%p,%p]", m, callback, cb_id);
6631                 return CAMERA_ERROR_INVALID_PARAMETER;
6632         }
6633
6634         CAM_LOG_INFO("enter");
6635
6636         ret = m->add_device_connection_changed_cb(callback, user_data, cb_id);
6637         if (ret != CAMERA_ERROR_NONE) {
6638                 CAM_LOG_ERROR("failed[0x%x]", ret);
6639                 return ret;
6640         }
6641
6642         CAM_LOG_INFO("cb_id[%d] added", *cb_id);
6643
6644         return CAMERA_ERROR_NONE;
6645 }
6646
6647
6648 int camera_device_manager_remove_device_connection_changed_cb(camera_device_manager_h manager, int cb_id)
6649 {
6650         int ret = CAMERA_ERROR_NONE;
6651         camera_device_manager *m = (camera_device_manager *)manager;
6652
6653         CAMERA_CHECK_DEVICE_MANAGER;
6654
6655         if (!m) {
6656                 CAM_LOG_ERROR("NULL manager");
6657                 return CAMERA_ERROR_INVALID_PARAMETER;
6658         }
6659
6660         CAM_LOG_INFO("enter - cb_id[%d]", cb_id);
6661
6662         ret = m->remove_device_connection_changed_cb(cb_id);
6663         if (ret != CAMERA_ERROR_NONE) {
6664                 CAM_LOG_ERROR("failed[0x%x]", ret);
6665                 return ret;
6666         }
6667
6668         CAM_LOG_INFO("cb_id[%d] removed", cb_id);
6669
6670         return CAMERA_ERROR_NONE;
6671 }
6672 //LCOV_EXCL_STOP
6673
6674
6675 int camera_set_extra_preview_cb(camera_h camera, camera_extra_preview_cb callback, void *user_data)
6676 {
6677         int ret = CAMERA_ERROR_NONE;
6678         camera_cli_s *pc = (camera_cli_s *)camera;
6679         muse_camera_api_e api = MUSE_CAMERA_API_SET_EXTRA_PREVIEW_CB;
6680
6681         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6682
6683         if (!camera_is_supported_extra_preview(camera)) {
6684                 CAM_LOG_ERROR("extra preview is not supported");
6685                 return CAMERA_ERROR_NOT_SUPPORTED;
6686         }
6687
6688         if (!callback) {
6689                 CAM_LOG_ERROR("NULL callback");
6690                 return CAMERA_ERROR_INVALID_PARAMETER;
6691         }
6692
6693         CAM_LOG_INFO("Enter");
6694
6695         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6696
6697         if (ret == CAMERA_ERROR_NONE) {
6698                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
6699
6700                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = callback;
6701                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = user_data;
6702
6703                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
6704         }
6705
6706         CAM_LOG_INFO("ret : 0x%x", ret);
6707
6708         return ret;
6709 }
6710
6711
6712 int camera_unset_extra_preview_cb(camera_h camera)
6713 {
6714         int ret = CAMERA_ERROR_NONE;
6715         camera_cli_s *pc = (camera_cli_s *)camera;
6716         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_EXTRA_PREVIEW_CB;
6717
6718         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6719
6720         if (!camera_is_supported_extra_preview(camera)) {
6721                 CAM_LOG_ERROR("extra preview is not supported");
6722                 return CAMERA_ERROR_NOT_SUPPORTED;
6723         }
6724
6725         CAM_LOG_INFO("Enter");
6726
6727         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6728
6729         if (ret == CAMERA_ERROR_NONE) {
6730                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
6731
6732                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = NULL;
6733                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = NULL;
6734
6735                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
6736         }
6737
6738         CAM_LOG_INFO("ret : 0x%x", ret);
6739
6740         return ret;
6741 }
6742
6743
6744 int camera_set_extra_preview_stream_format(camera_h camera, int stream_id, camera_pixel_format_e pixel_format, int width, int height, int fps)
6745 {
6746         int ret = CAMERA_ERROR_NONE;
6747         int stream_format[4] = {pixel_format, width, height, fps};
6748         char *msg = NULL;
6749         camera_cli_s *pc = (camera_cli_s *)camera;
6750         muse_camera_api_e api = MUSE_CAMERA_API_SET_EXTRA_PREVIEW_STREAM_FORMAT;
6751
6752         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6753
6754         CAM_LOG_INFO("Enter - stream[%d],[%d,%dx%d,%d]",
6755                 stream_id, pixel_format, width, height, fps);
6756
6757         msg = muse_core_msg_new(api,
6758                 MUSE_TYPE_INT, "stream_id", stream_id,
6759                 MUSE_TYPE_ARRAY, "stream_format", 4, stream_format,
6760                 NULL);
6761
6762         _camera_send_message_get_return(pc->cb_info, api, msg, CAMERA_CB_TIMEOUT, &ret);
6763
6764         return ret;
6765 }
6766
6767
6768 int camera_get_extra_preview_stream_format(camera_h camera, int stream_id, camera_pixel_format_e *pixel_format, int *width, int *height, int *fps)
6769 {
6770         int ret = CAMERA_ERROR_NONE;
6771         camera_cli_s *pc = (camera_cli_s *)camera;
6772         camera_msg_param param;
6773         muse_camera_api_e api = MUSE_CAMERA_API_GET_EXTRA_PREVIEW_STREAM_FORMAT;
6774
6775         if (!pc || !pc->cb_info || !pixel_format || !width || !height || !fps) {
6776                 CAM_LOG_ERROR("NULL pointer %p %p %p %p %p", pc, pixel_format, width, height, fps);
6777                 return CAMERA_ERROR_INVALID_PARAMETER;
6778         }
6779
6780         CAM_LOG_INFO("Enter - stream[%d]", stream_id);
6781
6782         CAMERA_MSG_PARAM_SET(param, INT, stream_id);
6783
6784         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6785
6786         if (ret == CAMERA_ERROR_NONE) {
6787                 *pixel_format = (camera_pixel_format_e)pc->cb_info->get_extra_preview_stream_format[0];
6788                 *width = pc->cb_info->get_extra_preview_stream_format[1];
6789                 *height = pc->cb_info->get_extra_preview_stream_format[2];
6790                 *fps = pc->cb_info->get_extra_preview_stream_format[3];
6791         }
6792
6793         CAM_LOG_INFO("ret : 0x%x", ret);
6794
6795         return ret;
6796 }
6797
6798
6799 int camera_attr_set_extra_preview_bitrate(camera_h camera, int stream_id, int bitrate)
6800 {
6801         int ret = CAMERA_ERROR_NONE;
6802         camera_cli_s *pc = (camera_cli_s *)camera;
6803         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXTRA_PREVIEW_BITRATE;
6804         camera_msg_param param0;
6805         camera_msg_param param1;
6806
6807         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6808
6809         CAM_LOG_INFO("Enter - stream[%d], bitrate[%d]", stream_id, bitrate);
6810
6811         CAMERA_MSG_PARAM_SET(param0, INT, stream_id);
6812         CAMERA_MSG_PARAM_SET(param1, INT, bitrate);
6813
6814         _camera_msg_send_param2_int(api, pc->cb_info, &ret,
6815                 &param0, &param1, CAMERA_CB_TIMEOUT);
6816
6817         CAM_LOG_INFO("ret : 0x%x", ret);
6818
6819         return ret;
6820 }
6821
6822
6823 int camera_attr_get_extra_preview_bitrate(camera_h camera, int stream_id, int *bitrate)
6824 {
6825         int ret = CAMERA_ERROR_NONE;
6826         camera_cli_s *pc = (camera_cli_s *)camera;
6827         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXTRA_PREVIEW_BITRATE;
6828         camera_msg_param param;
6829
6830         if (!pc || !pc->cb_info || !bitrate) {
6831                 CAM_LOG_ERROR("NULL pointer %p %p", pc, bitrate);
6832                 return CAMERA_ERROR_INVALID_PARAMETER;
6833         }
6834
6835         CAM_LOG_INFO("Enter - stream[%d]", stream_id);
6836
6837         CAMERA_MSG_PARAM_SET(param, INT, stream_id);
6838
6839         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6840
6841         if (ret == CAMERA_ERROR_NONE) {
6842                 *bitrate = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXTRA_PREVIEW_BITRATE];
6843                 CAM_LOG_INFO("get bitrate[%d] for stream[%d]", *bitrate, stream_id);
6844         } else {
6845                 CAM_LOG_ERROR("get bitrate failed for stream[%d] : 0x%x", stream_id, ret);
6846         }
6847
6848         return ret;
6849 }
6850
6851
6852 int camera_attr_set_extra_preview_gop_interval(camera_h camera, int stream_id, int interval)
6853 {
6854         int ret = CAMERA_ERROR_NONE;
6855         camera_cli_s *pc = (camera_cli_s *)camera;
6856         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXTRA_PREVIEW_GOP_INTERVAL;
6857         camera_msg_param param0;
6858         camera_msg_param param1;
6859
6860         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6861
6862         CAM_LOG_INFO("Enter - stream[%d], GOP interval[%d]", stream_id, interval);
6863
6864         CAMERA_MSG_PARAM_SET(param0, INT, stream_id);
6865         CAMERA_MSG_PARAM_SET(param1, INT, interval);
6866
6867         _camera_msg_send_param2_int(api, pc->cb_info, &ret,
6868                 &param0, &param1, CAMERA_CB_TIMEOUT);
6869
6870         CAM_LOG_INFO("ret : 0x%x", ret);
6871
6872         return ret;
6873 }
6874
6875
6876 int camera_attr_get_extra_preview_gop_interval(camera_h camera, int stream_id, int *interval)
6877 {
6878         int ret = CAMERA_ERROR_NONE;
6879         camera_cli_s *pc = (camera_cli_s *)camera;
6880         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXTRA_PREVIEW_GOP_INTERVAL;
6881         camera_msg_param param;
6882
6883         if (!pc || !pc->cb_info || !interval) {
6884                 CAM_LOG_ERROR("NULL pointer %p %p", pc, interval);
6885                 return CAMERA_ERROR_INVALID_PARAMETER;
6886         }
6887
6888         CAM_LOG_INFO("Enter - stream[%d]", stream_id);
6889
6890         CAMERA_MSG_PARAM_SET(param, INT, stream_id);
6891
6892         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6893
6894         if (ret == CAMERA_ERROR_NONE) {
6895                 *interval = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXTRA_PREVIEW_GOP_INTERVAL];
6896                 CAM_LOG_INFO("get GOP interval[%d] for stream[%d]", *interval, stream_id);
6897         } else {
6898                 CAM_LOG_ERROR("get GOP interval failed for stream[%d] : 0x%x", stream_id, ret);
6899         }
6900
6901         return ret;
6902 }
6903
6904
6905 int camera_attr_get_preview_frame_rotation(camera_h camera, camera_rotation_e *rotation)
6906 {
6907         camera_cli_s *pc = (camera_cli_s *)camera;
6908
6909         if (!pc || !pc->cb_info || !rotation) {
6910                 CAM_LOG_ERROR("NULL pointer %p %p", pc, rotation);
6911                 return CAMERA_ERROR_INVALID_PARAMETER;
6912         }
6913
6914         if (!pc->cb_info->stream_data) {
6915                 CAM_LOG_ERROR("no stream data, maybe it's not in preview callback");
6916                 return CAMERA_ERROR_INVALID_OPERATION;
6917         }
6918
6919         *rotation = pc->cb_info->stream_data->rotation;
6920
6921         CAM_LOG_DEBUG("frame rotation[%d]", *rotation);
6922
6923         return CAMERA_ERROR_NONE;
6924 }
6925
6926
6927 int _camera_get_log_level(void)
6928 {
6929         return g_camera_log_level;
6930 }
6931