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